2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file GuiView.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:29:47 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
2008-11-14 15:29:47 +00:00
|
|
|
* \author Peter Kümmel
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-18 00:01:14 +00:00
|
|
|
#include "GuiView.h"
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
#include "Dialog.h"
|
2010-01-29 10:42:39 +00:00
|
|
|
#include "DispatchResult.h"
|
2008-02-07 00:05:18 +00:00
|
|
|
#include "FileDialog.h"
|
2009-04-04 09:14:38 +00:00
|
|
|
#include "FontLoader.h"
|
2007-11-17 22:37:33 +00:00
|
|
|
#include "GuiApplication.h"
|
2008-05-27 16:15:56 +00:00
|
|
|
#include "GuiCommandBuffer.h"
|
2008-04-21 19:12:15 +00:00
|
|
|
#include "GuiCompleter.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiKeySymbol.h"
|
2009-04-08 21:06:58 +00:00
|
|
|
#include "GuiToc.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToolbar.h"
|
2010-01-07 14:25:15 +00:00
|
|
|
#include "GuiWorkArea.h"
|
2010-10-23 10:49:45 +00:00
|
|
|
#include "GuiProgress.h"
|
2009-08-12 21:51:10 +00:00
|
|
|
#include "LayoutBox.h"
|
2007-12-26 10:55:43 +00:00
|
|
|
#include "Menus.h"
|
2008-05-02 12:09:51 +00:00
|
|
|
#include "TocModel.h"
|
2010-07-17 16:09:26 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
#include "Buffer.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "BufferList.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
#include "BufferParams.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
#include "BufferView.h"
|
2010-02-22 02:01:04 +00:00
|
|
|
#include "Compare.h"
|
2008-02-06 23:54:13 +00:00
|
|
|
#include "Converter.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "Cursor.h"
|
2009-08-09 14:27:50 +00:00
|
|
|
#include "CutAndPaste.h"
|
2008-03-20 00:00:53 +00:00
|
|
|
#include "Encoding.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "ErrorList.h"
|
2008-02-06 23:54:13 +00:00
|
|
|
#include "Format.h"
|
2008-03-08 15:33:52 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "Intl.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
#include "Layout.h"
|
2007-11-19 20:56:05 +00:00
|
|
|
#include "Lexer.h"
|
2009-09-23 09:07:24 +00:00
|
|
|
#include "LyXAction.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "LyX.h"
|
2007-08-14 13:14:47 +00:00
|
|
|
#include "LyXRC.h"
|
2007-11-19 20:56:05 +00:00
|
|
|
#include "LyXVC.h"
|
2007-10-01 20:45:50 +00:00
|
|
|
#include "Paragraph.h"
|
2009-08-01 17:34:44 +00:00
|
|
|
#include "SpellChecker.h"
|
2010-04-15 13:19:48 +00:00
|
|
|
#include "TexRow.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "Text.h"
|
2008-05-25 08:30:06 +00:00
|
|
|
#include "Toolbars.h"
|
2007-08-21 07:33:46 +00:00
|
|
|
#include "version.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
|
2009-04-04 09:14:38 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-06 23:54:13 +00:00
|
|
|
#include "support/debug.h"
|
2008-08-13 14:25:56 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2007-11-19 20:56:05 +00:00
|
|
|
#include "support/FileName.h"
|
2007-12-02 17:50:08 +00:00
|
|
|
#include "support/filetools.h"
|
2008-03-20 00:00:53 +00:00
|
|
|
#include "support/gettext.h"
|
2009-09-19 16:49:31 +00:00
|
|
|
#include "support/filetools.h"
|
2008-01-15 18:26:53 +00:00
|
|
|
#include "support/ForkedCalls.h"
|
2009-04-04 09:14:38 +00:00
|
|
|
#include "support/lassert.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-11-19 12:03:38 +00:00
|
|
|
#include "support/os.h"
|
2007-12-02 17:50:08 +00:00
|
|
|
#include "support/Package.h"
|
2013-02-06 10:36:58 +00:00
|
|
|
#include "support/PathChanger.h"
|
2009-09-12 20:41:24 +00:00
|
|
|
#include "support/Systemcall.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
#include "support/Timeout.h"
|
2009-12-20 14:26:55 +00:00
|
|
|
#include "support/ProgressInterface.h"
|
2007-11-12 23:23:19 +00:00
|
|
|
|
2006-10-22 14:37:32 +00:00
|
|
|
#include <QAction>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QApplication>
|
2006-10-22 14:37:32 +00:00
|
|
|
#include <QCloseEvent>
|
2007-11-22 23:47:13 +00:00
|
|
|
#include <QDebug>
|
2007-08-14 13:14:47 +00:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QDropEvent>
|
2012-11-04 00:26:11 +00:00
|
|
|
#include <QFuture>
|
|
|
|
#include <QFutureWatcher>
|
2011-01-23 09:17:52 +00:00
|
|
|
#include <QLabel>
|
2007-08-14 13:14:47 +00:00
|
|
|
#include <QList>
|
2007-09-28 23:26:59 +00:00
|
|
|
#include <QMenu>
|
2008-02-07 00:10:34 +00:00
|
|
|
#include <QMenuBar>
|
2012-11-10 12:36:40 +00:00
|
|
|
#include <QMimeData>
|
2011-01-23 09:17:52 +00:00
|
|
|
#include <QMovie>
|
2007-08-21 07:33:46 +00:00
|
|
|
#include <QPainter>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QPixmap>
|
2009-04-04 10:15:06 +00:00
|
|
|
#include <QPixmapCache>
|
2007-11-16 21:52:04 +00:00
|
|
|
#include <QPoint>
|
2007-08-14 13:14:47 +00:00
|
|
|
#include <QPushButton>
|
2012-11-04 00:26:11 +00:00
|
|
|
#include <QScrollBar>
|
2007-11-15 12:58:44 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QShowEvent>
|
2007-11-11 10:09:48 +00:00
|
|
|
#include <QSplitter>
|
2007-08-21 07:33:46 +00:00
|
|
|
#include <QStackedWidget>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QStatusBar>
|
2012-11-04 00:26:11 +00:00
|
|
|
#include <QtConcurrentRun>
|
2009-12-21 15:07:51 +00:00
|
|
|
#include <QTime>
|
2007-11-18 23:49:52 +00:00
|
|
|
#include <QTimer>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QToolBar>
|
2007-08-14 13:14:47 +00:00
|
|
|
#include <QUrl>
|
2010-07-17 16:09:26 +00:00
|
|
|
|
|
|
|
|
2010-04-05 13:04:52 +00:00
|
|
|
|
2009-12-19 15:46:45 +00:00
|
|
|
#define EXPORT_in_THREAD 1
|
2009-12-18 22:51:06 +00:00
|
|
|
|
2009-12-13 21:00:46 +00:00
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
#include "support/bind.h"
|
2007-10-18 09:24:16 +00:00
|
|
|
|
2009-09-24 07:20:18 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 00:37:58 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2011-02-12 20:24:09 +00:00
|
|
|
|
|
|
|
using support::addExtension;
|
|
|
|
using support::changeExtension;
|
|
|
|
using support::removeExtension;
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
class BackgroundWidget : public QWidget
|
2006-10-31 14:12:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-11-22 23:47:13 +00:00
|
|
|
BackgroundWidget()
|
2007-06-11 14:53:36 +00:00
|
|
|
{
|
2007-11-22 23:47:13 +00:00
|
|
|
LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
|
2010-03-15 12:18:21 +00:00
|
|
|
if (!lyxrc.show_banner)
|
|
|
|
return;
|
2007-11-22 23:47:13 +00:00
|
|
|
/// The text to be written on top of the pixmap
|
2008-04-07 15:51:35 +00:00
|
|
|
QString const text = lyx_version ?
|
|
|
|
qt_("version ") + lyx_version : qt_("unknown version");
|
2009-04-03 17:00:09 +00:00
|
|
|
splash_ = getPixmap("images/", "banner", "png");
|
2007-11-22 23:47:13 +00:00
|
|
|
|
2007-11-22 23:29:53 +00:00
|
|
|
QPainter pain(&splash_);
|
2008-04-07 12:50:54 +00:00
|
|
|
pain.setPen(QColor(0, 0, 0));
|
2007-08-21 07:33:46 +00:00
|
|
|
QFont font;
|
|
|
|
// The font used to display the version info
|
|
|
|
font.setStyleHint(QFont::SansSerif);
|
|
|
|
font.setWeight(QFont::Bold);
|
2007-11-22 23:47:13 +00:00
|
|
|
font.setPointSize(int(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble()));
|
2007-08-21 07:33:46 +00:00
|
|
|
pain.setFont(font);
|
2011-03-01 23:49:39 +00:00
|
|
|
pain.drawText(190, 225, text);
|
2010-01-08 20:08:48 +00:00
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2007-06-11 14:53:36 +00:00
|
|
|
}
|
2007-02-01 18:48:58 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void paintEvent(QPaintEvent *)
|
2006-10-31 14:12:46 +00:00
|
|
|
{
|
2007-11-22 23:29:53 +00:00
|
|
|
int x = (width() - splash_.width()) / 2;
|
|
|
|
int y = (height() - splash_.height()) / 2;
|
2007-08-21 07:33:46 +00:00
|
|
|
QPainter pain(this);
|
2007-11-22 23:29:53 +00:00
|
|
|
pain.drawPixmap(x, y, splash_);
|
2007-02-01 18:48:58 +00:00
|
|
|
}
|
|
|
|
|
2010-01-08 20:08:48 +00:00
|
|
|
void keyPressEvent(QKeyEvent * ev)
|
|
|
|
{
|
|
|
|
KeySymbol sym;
|
|
|
|
setKeySymbol(&sym, ev);
|
|
|
|
if (sym.isOK()) {
|
|
|
|
guiApp->processKeySym(sym, q_key_state(ev->modifiers()));
|
|
|
|
ev->accept();
|
|
|
|
} else {
|
|
|
|
ev->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
private:
|
2007-11-22 23:29:53 +00:00
|
|
|
QPixmap splash_;
|
2006-10-31 14:12:46 +00:00
|
|
|
};
|
|
|
|
|
2008-11-15 16:29:58 +00:00
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
/// Toolbar store providing access to individual toolbars by name.
|
2009-12-20 15:07:15 +00:00
|
|
|
typedef map<string, GuiToolbar *> ToolbarMap;
|
2007-08-23 08:56:13 +00:00
|
|
|
|
2010-04-22 11:37:32 +00:00
|
|
|
typedef shared_ptr<Dialog> DialogPtr;
|
2007-11-18 00:01:14 +00:00
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
struct GuiView::GuiViewPrivate
|
2006-10-31 14:12:46 +00:00
|
|
|
{
|
2009-12-19 12:24:44 +00:00
|
|
|
GuiViewPrivate(GuiView * gv)
|
|
|
|
: gv_(gv), current_work_area_(0), current_main_work_area_(0),
|
2008-11-16 01:20:34 +00:00
|
|
|
layout_(0), autosave_timeout_(5000),
|
2008-02-27 10:35:28 +00:00
|
|
|
in_show_(false)
|
2007-11-18 23:30:41 +00:00
|
|
|
{
|
|
|
|
// hardcode here the platform specific icon size
|
2011-02-22 00:40:47 +00:00
|
|
|
smallIconSize = 16; // scaling problems
|
2011-03-29 21:07:46 +00:00
|
|
|
normalIconSize = 20; // ok, default if iconsize.png is missing
|
2010-03-05 18:07:05 +00:00
|
|
|
bigIconSize = 26; // better for some math icons
|
2007-11-18 23:30:41 +00:00
|
|
|
|
2011-03-22 23:41:26 +00:00
|
|
|
// if it exists, use width of iconsize.png as normal size
|
2011-03-25 01:59:34 +00:00
|
|
|
QString const dir = toqstr(addPath("images", lyxrc.icon_set));
|
|
|
|
FileName const fn = lyx::libFileSearch(dir, "iconsize.png");
|
2011-03-22 23:41:26 +00:00
|
|
|
if (!fn.empty()) {
|
|
|
|
QImage image(toqstr(fn.absFileName()));
|
|
|
|
if (image.width() < int(smallIconSize))
|
|
|
|
normalIconSize = smallIconSize;
|
|
|
|
else if (image.width() > int(bigIconSize))
|
|
|
|
normalIconSize = bigIconSize;
|
|
|
|
else
|
|
|
|
normalIconSize = image.width();
|
|
|
|
}
|
|
|
|
|
2007-11-18 23:30:41 +00:00
|
|
|
splitter_ = new QSplitter;
|
2007-11-22 23:47:13 +00:00
|
|
|
bg_widget_ = new BackgroundWidget;
|
2007-11-18 23:30:41 +00:00
|
|
|
stack_widget_ = new QStackedWidget;
|
|
|
|
stack_widget_->addWidget(bg_widget_);
|
|
|
|
stack_widget_->addWidget(splitter_);
|
|
|
|
setBackground();
|
2010-03-05 18:07:05 +00:00
|
|
|
|
|
|
|
// TODO cleanup, remove the singleton, handle multiple Windows?
|
|
|
|
progress_ = ProgressInterface::instance();
|
2010-09-07 14:11:28 +00:00
|
|
|
if (!dynamic_cast<GuiProgress*>(progress_)) {
|
2012-10-26 00:42:27 +00:00
|
|
|
progress_ = new GuiProgress; // TODO who deletes it
|
2010-09-07 14:11:28 +00:00
|
|
|
ProgressInterface::setInstance(progress_);
|
2010-03-05 18:07:05 +00:00
|
|
|
}
|
|
|
|
QObject::connect(
|
2010-09-07 14:11:28 +00:00
|
|
|
dynamic_cast<GuiProgress*>(progress_),
|
|
|
|
SIGNAL(updateStatusBarMessage(QString const&)),
|
2010-03-05 18:07:05 +00:00
|
|
|
gv, SLOT(updateStatusBarMessage(QString const&)));
|
|
|
|
QObject::connect(
|
2010-09-07 14:11:28 +00:00
|
|
|
dynamic_cast<GuiProgress*>(progress_),
|
|
|
|
SIGNAL(clearMessageText()),
|
2010-03-05 18:07:05 +00:00
|
|
|
gv, SLOT(clearMessageText()));
|
2007-11-18 23:30:41 +00:00
|
|
|
}
|
2007-11-11 10:09:48 +00:00
|
|
|
|
|
|
|
~GuiViewPrivate()
|
|
|
|
{
|
|
|
|
delete splitter_;
|
2007-11-22 23:47:13 +00:00
|
|
|
delete bg_widget_;
|
2007-11-23 11:19:42 +00:00
|
|
|
delete stack_widget_;
|
2007-11-11 10:09:48 +00:00
|
|
|
}
|
2006-11-27 23:35:43 +00:00
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
QMenu * toolBarPopup(GuiView * parent)
|
2006-11-29 10:04:35 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
// FIXME: translation
|
2007-08-31 05:53:55 +00:00
|
|
|
QMenu * menu = new QMenu(parent);
|
|
|
|
QActionGroup * iconSizeGroup = new QActionGroup(parent);
|
2006-11-29 10:04:35 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QAction * smallIcons = new QAction(iconSizeGroup);
|
2007-01-27 14:42:45 +00:00
|
|
|
smallIcons->setText(qt_("Small-sized icons"));
|
2006-11-29 10:04:35 +00:00
|
|
|
smallIcons->setCheckable(true);
|
2007-11-12 23:23:19 +00:00
|
|
|
QObject::connect(smallIcons, SIGNAL(triggered()),
|
|
|
|
parent, SLOT(smallSizedIcons()));
|
2006-11-29 10:04:35 +00:00
|
|
|
menu->addAction(smallIcons);
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QAction * normalIcons = new QAction(iconSizeGroup);
|
2007-01-27 14:42:45 +00:00
|
|
|
normalIcons->setText(qt_("Normal-sized icons"));
|
2006-11-29 10:04:35 +00:00
|
|
|
normalIcons->setCheckable(true);
|
2007-11-12 23:23:19 +00:00
|
|
|
QObject::connect(normalIcons, SIGNAL(triggered()),
|
|
|
|
parent, SLOT(normalSizedIcons()));
|
2006-11-29 10:04:35 +00:00
|
|
|
menu->addAction(normalIcons);
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QAction * bigIcons = new QAction(iconSizeGroup);
|
2007-01-27 14:42:45 +00:00
|
|
|
bigIcons->setText(qt_("Big-sized icons"));
|
2006-11-29 10:04:35 +00:00
|
|
|
bigIcons->setCheckable(true);
|
2007-11-12 23:23:19 +00:00
|
|
|
QObject::connect(bigIcons, SIGNAL(triggered()),
|
|
|
|
parent, SLOT(bigSizedIcons()));
|
2006-11-29 10:04:35 +00:00
|
|
|
menu->addAction(bigIcons);
|
|
|
|
|
2006-11-29 21:52:56 +00:00
|
|
|
unsigned int cur = parent->iconSize().width();
|
2006-11-29 10:04:35 +00:00
|
|
|
if ( cur == parent->d.smallIconSize)
|
|
|
|
smallIcons->setChecked(true);
|
|
|
|
else if (cur == parent->d.normalIconSize)
|
|
|
|
normalIcons->setChecked(true);
|
|
|
|
else if (cur == parent->d.bigIconSize)
|
|
|
|
bigIcons->setChecked(true);
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
|
|
|
void setBackground()
|
|
|
|
{
|
|
|
|
stack_widget_->setCurrentWidget(bg_widget_);
|
|
|
|
bg_widget_->setUpdatesEnabled(true);
|
2010-01-08 20:08:48 +00:00
|
|
|
bg_widget_->setFocus();
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
2007-11-11 10:09:48 +00:00
|
|
|
|
2010-10-23 10:49:45 +00:00
|
|
|
int tabWorkAreaCount()
|
|
|
|
{
|
|
|
|
return splitter_->count();
|
|
|
|
}
|
2010-10-27 17:02:42 +00:00
|
|
|
|
2007-11-11 10:09:48 +00:00
|
|
|
TabWorkArea * tabWorkArea(int i)
|
|
|
|
{
|
|
|
|
return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
TabWorkArea * currentTabWorkArea()
|
|
|
|
{
|
2010-10-23 10:49:45 +00:00
|
|
|
int areas = tabWorkAreaCount();
|
|
|
|
if (areas == 1)
|
2007-11-11 10:09:48 +00:00
|
|
|
// The first TabWorkArea is always the first one, if any.
|
|
|
|
return tabWorkArea(0);
|
|
|
|
|
2010-10-23 10:49:45 +00:00
|
|
|
for (int i = 0; i != areas; ++i) {
|
2008-02-21 11:48:31 +00:00
|
|
|
TabWorkArea * twa = tabWorkArea(i);
|
2008-11-16 01:20:34 +00:00
|
|
|
if (current_main_work_area_ == twa->currentWorkArea())
|
2008-02-21 11:48:31 +00:00
|
|
|
return twa;
|
2007-11-11 10:09:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 20:05:01 +00:00
|
|
|
// None has the focus so we just take the first one.
|
|
|
|
return tabWorkArea(0);
|
2007-11-11 10:09:48 +00:00
|
|
|
}
|
2007-11-12 23:23:19 +00:00
|
|
|
|
2012-09-15 22:37:55 +00:00
|
|
|
int countWorkAreasOf(Buffer & buf)
|
|
|
|
{
|
|
|
|
int areas = tabWorkAreaCount();
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i != areas; ++i) {
|
|
|
|
TabWorkArea * twa = tabWorkArea(i);
|
|
|
|
if (twa->workArea(buf))
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-10-27 20:00:11 +00:00
|
|
|
void setPreviewFuture(QFuture<Buffer::ExportStatus> const & f)
|
2009-12-19 12:24:44 +00:00
|
|
|
{
|
2010-10-23 10:49:45 +00:00
|
|
|
if (processing_thread_watcher_.isRunning()) {
|
2010-01-05 13:33:29 +00:00
|
|
|
// we prefer to cancel this preview in order to keep a snappy
|
|
|
|
// interface.
|
|
|
|
return;
|
|
|
|
}
|
2010-10-23 10:49:45 +00:00
|
|
|
processing_thread_watcher_.setFuture(f);
|
2009-12-19 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
public:
|
2009-12-19 12:24:44 +00:00
|
|
|
GuiView * gv_;
|
2007-11-12 23:23:19 +00:00
|
|
|
GuiWorkArea * current_work_area_;
|
2008-11-16 01:20:34 +00:00
|
|
|
GuiWorkArea * current_main_work_area_;
|
2007-11-12 23:23:19 +00:00
|
|
|
QSplitter * splitter_;
|
|
|
|
QStackedWidget * stack_widget_;
|
|
|
|
BackgroundWidget * bg_widget_;
|
|
|
|
/// view's toolbars
|
2008-05-27 11:15:17 +00:00
|
|
|
ToolbarMap toolbars_;
|
2009-12-21 13:11:17 +00:00
|
|
|
ProgressInterface* progress_;
|
2007-11-20 22:03:56 +00:00
|
|
|
/// The main layout box.
|
2010-09-07 14:11:28 +00:00
|
|
|
/**
|
2007-11-20 22:03:56 +00:00
|
|
|
* \warning Don't Delete! The layout box is actually owned by
|
|
|
|
* whichever toolbar contains it. All the GuiView class needs is a
|
|
|
|
* means of accessing it.
|
|
|
|
*
|
|
|
|
* FIXME: replace that with a proper model so that we are not limited
|
|
|
|
* to only one dialog.
|
|
|
|
*/
|
2009-08-12 21:51:10 +00:00
|
|
|
LayoutBox * layout_;
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
///
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr> dialogs_;
|
2007-11-18 23:30:41 +00:00
|
|
|
|
|
|
|
unsigned int smallIconSize;
|
|
|
|
unsigned int normalIconSize;
|
|
|
|
unsigned int bigIconSize;
|
|
|
|
///
|
|
|
|
QTimer statusbar_timer_;
|
|
|
|
/// auto-saving of buffers
|
2007-11-22 23:29:53 +00:00
|
|
|
Timeout autosave_timeout_;
|
2007-11-22 23:47:13 +00:00
|
|
|
/// flag against a race condition due to multiclicks, see bug #1119
|
2007-11-18 00:01:14 +00:00
|
|
|
bool in_show_;
|
2008-05-02 12:09:51 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
TocModels toc_models_;
|
2009-12-13 21:00:46 +00:00
|
|
|
|
|
|
|
///
|
2009-12-18 22:51:06 +00:00
|
|
|
QFutureWatcher<docstring> autosave_watcher_;
|
2011-10-27 20:00:11 +00:00
|
|
|
QFutureWatcher<Buffer::ExportStatus> processing_thread_watcher_;
|
2010-03-13 11:39:50 +00:00
|
|
|
///
|
|
|
|
string last_export_format;
|
2011-10-27 20:00:11 +00:00
|
|
|
string processing_format;
|
2010-04-05 13:04:52 +00:00
|
|
|
|
|
|
|
static QSet<Buffer const *> busyBuffers;
|
2011-10-27 20:00:11 +00:00
|
|
|
static Buffer::ExportStatus previewAndDestroy(Buffer const * orig, Buffer * buffer, string const & format);
|
|
|
|
static Buffer::ExportStatus exportAndDestroy(Buffer const * orig, Buffer * buffer, string const & format);
|
|
|
|
static Buffer::ExportStatus compileAndDestroy(Buffer const * orig, Buffer * buffer, string const & format);
|
2010-11-17 02:23:39 +00:00
|
|
|
static docstring autosaveAndDestroy(Buffer const * orig, Buffer * buffer);
|
2010-04-05 13:04:52 +00:00
|
|
|
|
2010-10-20 01:45:51 +00:00
|
|
|
template<class T>
|
2011-10-30 08:53:22 +00:00
|
|
|
static Buffer::ExportStatus runAndDestroy(const T& func, Buffer const * orig, Buffer * buffer, string const & format);
|
2010-10-27 17:02:42 +00:00
|
|
|
|
2010-10-18 09:31:50 +00:00
|
|
|
// TODO syncFunc/previewFunc: use bind
|
2010-10-18 10:59:23 +00:00
|
|
|
bool asyncBufferProcessing(string const & argument,
|
2010-10-27 17:02:42 +00:00
|
|
|
Buffer const * used_buffer,
|
|
|
|
docstring const & msg,
|
2011-10-27 20:00:11 +00:00
|
|
|
Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
|
|
|
|
Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
|
|
|
|
Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const);
|
2010-10-18 09:31:50 +00:00
|
|
|
|
2010-10-23 10:49:45 +00:00
|
|
|
QVector<GuiWorkArea*> guiWorkAreas();
|
2006-10-31 14:12:46 +00:00
|
|
|
};
|
|
|
|
|
2010-04-05 13:04:52 +00:00
|
|
|
QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiView::GuiView(int id)
|
2010-11-05 20:24:58 +00:00
|
|
|
: d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-12-26 10:55:43 +00:00
|
|
|
// GuiToolbars *must* be initialised before the menu bar.
|
2008-10-27 09:06:50 +00:00
|
|
|
normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
|
2008-05-27 11:15:17 +00:00
|
|
|
constructToolbars();
|
2007-12-26 10:55:43 +00:00
|
|
|
|
2008-03-14 23:29:11 +00:00
|
|
|
// set ourself as the current view. This is needed for the menu bar
|
|
|
|
// filling, at least for the static special menu item on Mac. Otherwise
|
|
|
|
// they are greyed out.
|
2009-09-22 21:25:32 +00:00
|
|
|
guiApp->setCurrentView(this);
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2007-12-26 10:55:43 +00:00
|
|
|
// Fill up the menu bar.
|
2008-03-15 02:58:05 +00:00
|
|
|
guiApp->menus().fillMenuBar(menuBar(), this, true);
|
2007-11-18 23:30:41 +00:00
|
|
|
|
|
|
|
setCentralWidget(d.stack_widget_);
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
// Start autosave timer
|
|
|
|
if (lyxrc.autosave) {
|
2010-04-22 11:16:58 +00:00
|
|
|
d.autosave_timeout_.timeout.connect(bind(&GuiView::autoSave, this));
|
2007-11-22 23:29:53 +00:00
|
|
|
d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
|
|
|
|
d.autosave_timeout_.start();
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
2007-11-22 23:29:53 +00:00
|
|
|
connect(&d.statusbar_timer_, SIGNAL(timeout()),
|
2007-11-18 23:30:41 +00:00
|
|
|
this, SLOT(clearMessage()));
|
2007-11-12 23:23:19 +00:00
|
|
|
|
2008-02-27 11:35:12 +00:00
|
|
|
// We don't want to keep the window in memory if it is closed.
|
2008-02-27 11:56:36 +00:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2008-02-27 11:35:12 +00:00
|
|
|
|
2008-04-07 15:51:35 +00:00
|
|
|
#if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX))
|
2011-12-07 16:47:43 +00:00
|
|
|
// QIcon::fromTheme was introduced in Qt 4.6
|
|
|
|
#if (QT_VERSION >= 0x040600)
|
2008-04-07 12:50:54 +00:00
|
|
|
// assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
|
2011-12-07 16:47:43 +00:00
|
|
|
// since the icon is provided in the application bundle. We use a themed
|
|
|
|
// version when available and use the bundled one as fallback.
|
|
|
|
setWindowIcon(QIcon::fromTheme("lyx", getPixmap("images/", "lyx", "png")));
|
|
|
|
#else
|
2009-04-03 17:00:09 +00:00
|
|
|
setWindowIcon(getPixmap("images/", "lyx", "png"));
|
2006-03-05 17:24:44 +00:00
|
|
|
#endif
|
2007-08-14 13:14:47 +00:00
|
|
|
|
2011-12-07 16:47:43 +00:00
|
|
|
#endif
|
2012-12-05 21:45:42 +00:00
|
|
|
resetWindowTitleAndIconText();
|
2011-12-07 16:47:43 +00:00
|
|
|
|
2010-01-29 08:19:45 +00:00
|
|
|
// use tabbed dock area for multiple docks
|
|
|
|
// (such as "source" and "messages")
|
|
|
|
setDockOptions(QMainWindow::ForceTabbedDocks);
|
|
|
|
|
2007-08-14 13:14:47 +00:00
|
|
|
// For Drag&Drop.
|
|
|
|
setAcceptDrops(true);
|
2007-11-18 22:29:58 +00:00
|
|
|
|
2011-01-23 09:17:52 +00:00
|
|
|
// add busy indicator to statusbar
|
|
|
|
QLabel * busylabel = new QLabel(statusBar());
|
|
|
|
statusBar()->addPermanentWidget(busylabel);
|
|
|
|
QString fn = toqstr(lyx::libFileSearch("images", "busy.gif").absFileName());
|
|
|
|
QMovie * busyanim = new QMovie(fn, QByteArray(), busylabel);
|
|
|
|
busylabel->setMovie(busyanim);
|
|
|
|
busyanim->start();
|
|
|
|
busylabel->hide();
|
2011-01-24 11:38:13 +00:00
|
|
|
|
2011-01-23 09:17:52 +00:00
|
|
|
connect(&d.processing_thread_watcher_, SIGNAL(started()),
|
|
|
|
busylabel, SLOT(show()));
|
|
|
|
connect(&d.processing_thread_watcher_, SIGNAL(finished()),
|
|
|
|
busylabel, SLOT(hide()));
|
|
|
|
|
2007-11-18 22:51:58 +00:00
|
|
|
statusBar()->setSizeGripEnabled(true);
|
2009-12-26 23:58:24 +00:00
|
|
|
updateStatusBar();
|
2007-11-18 22:51:58 +00:00
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
connect(&d.autosave_watcher_, SIGNAL(finished()), this,
|
2010-12-07 00:13:14 +00:00
|
|
|
SLOT(autoSaveThreadFinished()));
|
2011-01-24 11:38:13 +00:00
|
|
|
|
2011-01-24 15:06:39 +00:00
|
|
|
connect(&d.processing_thread_watcher_, SIGNAL(started()), this,
|
|
|
|
SLOT(processingThreadStarted()));
|
2010-10-23 10:49:45 +00:00
|
|
|
connect(&d.processing_thread_watcher_, SIGNAL(finished()), this,
|
|
|
|
SLOT(processingThreadFinished()));
|
|
|
|
|
2009-12-22 10:04:30 +00:00
|
|
|
connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
|
|
|
|
SLOT(doShowDialog(QString const &, QString const &, Inset *)));
|
|
|
|
|
2007-11-18 23:30:41 +00:00
|
|
|
// Forbid too small unresizable window because it can happen
|
|
|
|
// with some window manager under X11.
|
|
|
|
setMinimumSize(300, 200);
|
2007-11-18 22:51:58 +00:00
|
|
|
|
2008-05-27 13:16:50 +00:00
|
|
|
if (lyxrc.allow_geometry_session) {
|
|
|
|
// Now take care of session management.
|
2013-03-20 12:59:25 +00:00
|
|
|
if (restoreLayout(true))
|
2008-06-19 17:30:30 +00:00
|
|
|
return;
|
2008-05-27 11:15:17 +00:00
|
|
|
}
|
2007-11-18 22:51:58 +00:00
|
|
|
|
2008-11-05 14:04:37 +00:00
|
|
|
// no session handling, default to a sane size.
|
2008-05-27 13:16:50 +00:00
|
|
|
setGeometry(50, 50, 690, 510);
|
|
|
|
initToolbars();
|
2008-11-05 14:04:37 +00:00
|
|
|
|
|
|
|
// clear session data if any.
|
2008-05-27 13:16:50 +00:00
|
|
|
QSettings settings;
|
2008-09-21 21:28:37 +00:00
|
|
|
settings.remove("views");
|
2008-05-27 13:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiView::~GuiView()
|
|
|
|
{
|
|
|
|
delete &d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-23 10:49:45 +00:00
|
|
|
QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
|
|
|
|
{
|
|
|
|
QVector<GuiWorkArea*> areas;
|
|
|
|
for (int i = 0; i < tabWorkAreaCount(); i++) {
|
|
|
|
TabWorkArea* ta = tabWorkArea(i);
|
|
|
|
for (int u = 0; u < ta->count(); u++) {
|
|
|
|
areas << ta->workArea(u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return areas;
|
|
|
|
}
|
|
|
|
|
2011-10-29 11:14:47 +00:00
|
|
|
static void handleExportStatus(GuiView * view, Buffer::ExportStatus status,
|
|
|
|
string const & format)
|
2009-12-13 21:00:46 +00:00
|
|
|
{
|
2011-10-30 19:52:33 +00:00
|
|
|
docstring const fmt = formats.prettyName(format);
|
2011-10-27 20:00:11 +00:00
|
|
|
docstring msg;
|
|
|
|
switch (status) {
|
|
|
|
case Buffer::ExportSuccess:
|
2011-10-30 19:52:33 +00:00
|
|
|
msg = bformat(_("Successful export to format: %1$s"), fmt);
|
2011-10-30 19:52:27 +00:00
|
|
|
break;
|
|
|
|
case Buffer::ExportCancel:
|
|
|
|
msg = _("Document export cancelled.");
|
2011-10-27 20:00:11 +00:00
|
|
|
break;
|
|
|
|
case Buffer::ExportError:
|
|
|
|
case Buffer::ExportNoPathToFormat:
|
|
|
|
case Buffer::ExportTexPathHasSpaces:
|
|
|
|
case Buffer::ExportConverterError:
|
2011-10-30 19:52:33 +00:00
|
|
|
msg = bformat(_("Error while exporting format: %1$s"), fmt);
|
2011-10-27 20:00:11 +00:00
|
|
|
break;
|
|
|
|
case Buffer::PreviewSuccess:
|
2011-10-30 19:52:33 +00:00
|
|
|
msg = bformat(_("Successful preview of format: %1$s"), fmt);
|
2011-10-27 20:00:11 +00:00
|
|
|
break;
|
|
|
|
case Buffer::PreviewError:
|
2011-10-30 19:52:33 +00:00
|
|
|
msg = bformat(_("Error while previewing format: %1$s"), fmt);
|
2011-10-27 20:00:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-30 19:52:27 +00:00
|
|
|
view->message(msg);
|
2011-10-29 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::processingThreadStarted()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-30 21:34:12 +00:00
|
|
|
void GuiView::processingThreadFinished()
|
2011-10-29 11:14:47 +00:00
|
|
|
{
|
|
|
|
QFutureWatcher<Buffer::ExportStatus> const * watcher =
|
|
|
|
static_cast<QFutureWatcher<Buffer::ExportStatus> const *>(sender());
|
|
|
|
|
|
|
|
Buffer::ExportStatus const status = watcher->result();
|
|
|
|
handleExportStatus(this, status, d.processing_format);
|
2011-10-27 20:00:11 +00:00
|
|
|
|
2010-04-28 04:51:05 +00:00
|
|
|
updateToolbars();
|
2011-10-30 21:34:12 +00:00
|
|
|
BufferView const * const bv = currentBufferView();
|
|
|
|
if (bv && !bv->buffer().errorList("Export").empty()) {
|
|
|
|
errors("Export");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
errors(d.last_export_format);
|
2010-12-07 00:13:14 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 11:38:13 +00:00
|
|
|
|
2010-12-07 00:13:14 +00:00
|
|
|
void GuiView::autoSaveThreadFinished()
|
|
|
|
{
|
2011-10-30 21:34:12 +00:00
|
|
|
QFutureWatcher<docstring> const * watcher =
|
|
|
|
static_cast<QFutureWatcher<docstring> const *>(sender());
|
|
|
|
message(watcher->result());
|
|
|
|
updateToolbars();
|
2010-12-07 00:13:14 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:35:56 +00:00
|
|
|
|
2008-05-27 13:16:50 +00:00
|
|
|
void GuiView::saveLayout() const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2008-09-22 06:50:35 +00:00
|
|
|
settings.beginGroup("views");
|
|
|
|
settings.beginGroup(QString::number(id_));
|
2008-05-27 13:16:50 +00:00
|
|
|
#ifdef Q_WS_X11
|
2008-09-22 06:50:35 +00:00
|
|
|
settings.setValue("pos", pos());
|
|
|
|
settings.setValue("size", size());
|
2008-05-27 13:16:50 +00:00
|
|
|
#else
|
2008-09-22 06:50:35 +00:00
|
|
|
settings.setValue("geometry", saveGeometry());
|
2008-05-27 13:16:50 +00:00
|
|
|
#endif
|
2008-09-22 06:50:35 +00:00
|
|
|
settings.setValue("layout", saveState(0));
|
|
|
|
settings.setValue("icon_size", iconSize());
|
2008-05-27 13:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-03 16:49:15 +00:00
|
|
|
void GuiView::saveUISettings() const
|
|
|
|
{
|
|
|
|
// Save the toolbar private states
|
|
|
|
ToolbarMap::iterator end = d.toolbars_.end();
|
|
|
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
|
|
|
it->second->saveSession();
|
|
|
|
// Now take care of all other dialogs
|
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
|
|
|
|
for (; it!= d.dialogs_.end(); ++it)
|
|
|
|
it->second->saveSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 12:59:25 +00:00
|
|
|
bool GuiView::restoreLayout(bool force_inittoolbars)
|
2008-05-27 13:16:50 +00:00
|
|
|
{
|
|
|
|
QSettings settings;
|
2008-09-21 22:34:19 +00:00
|
|
|
settings.beginGroup("views");
|
|
|
|
settings.beginGroup(QString::number(id_));
|
|
|
|
QString const icon_key = "icon_size";
|
2008-06-19 20:48:49 +00:00
|
|
|
if (!settings.contains(icon_key))
|
2008-06-19 17:30:30 +00:00
|
|
|
return false;
|
|
|
|
|
2009-06-16 17:22:43 +00:00
|
|
|
//code below is skipped when when ~/.config/LyX is (re)created
|
2011-03-27 19:07:09 +00:00
|
|
|
QSize icon_size = settings.value(icon_key).toSize();
|
|
|
|
// Check whether session size changed.
|
2011-03-28 05:49:35 +00:00
|
|
|
if (icon_size.width() != int(d.smallIconSize) &&
|
|
|
|
icon_size.width() != int(d.normalIconSize) &&
|
|
|
|
icon_size.width() != int(d.bigIconSize)) {
|
2011-03-27 19:07:09 +00:00
|
|
|
icon_size.setWidth(d.normalIconSize);
|
|
|
|
icon_size.setHeight(d.normalIconSize);
|
|
|
|
}
|
|
|
|
setIconSize(icon_size);
|
|
|
|
|
2007-11-18 22:51:58 +00:00
|
|
|
#ifdef Q_WS_X11
|
2008-09-22 06:48:08 +00:00
|
|
|
QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
|
|
|
|
QSize size = settings.value("size", QSize(690, 510)).toSize();
|
2007-11-18 22:51:58 +00:00
|
|
|
resize(size);
|
|
|
|
move(pos);
|
|
|
|
#else
|
2009-08-07 12:49:03 +00:00
|
|
|
// Work-around for bug #6034: the window ends up in an undetermined
|
|
|
|
// state when trying to restore a maximized window when it is
|
|
|
|
// already maximized.
|
|
|
|
if (!(windowState() & Qt::WindowMaximized))
|
|
|
|
if (!restoreGeometry(settings.value("geometry").toByteArray()))
|
|
|
|
setGeometry(50, 50, 690, 510);
|
2007-11-18 22:51:58 +00:00
|
|
|
#endif
|
2008-09-21 21:28:37 +00:00
|
|
|
// Make sure layout is correctly oriented.
|
|
|
|
setLayoutDirection(qApp->layoutDirection());
|
|
|
|
|
2008-06-09 15:01:45 +00:00
|
|
|
// Allow the toc and view-source dock widget to be restored if needed.
|
2009-06-22 22:08:04 +00:00
|
|
|
Dialog * dialog;
|
2009-06-23 08:20:10 +00:00
|
|
|
if ((dialog = findOrBuild("toc", true)))
|
2009-06-16 17:22:43 +00:00
|
|
|
// see bug 5082. At least setup title and enabled state.
|
|
|
|
// Visibility will be adjusted by restoreState below.
|
2009-06-22 22:08:04 +00:00
|
|
|
dialog->prepareView();
|
2009-06-23 08:20:10 +00:00
|
|
|
if ((dialog = findOrBuild("view-source", true)))
|
2009-06-22 22:08:04 +00:00
|
|
|
dialog->prepareView();
|
2009-12-28 21:55:50 +00:00
|
|
|
if ((dialog = findOrBuild("progress", true)))
|
|
|
|
dialog->prepareView();
|
2011-01-06 00:52:46 +00:00
|
|
|
if ((dialog = findOrBuild("findreplaceadv", true)))
|
|
|
|
dialog->prepareView();
|
2008-09-12 02:21:14 +00:00
|
|
|
|
2013-03-20 12:59:25 +00:00
|
|
|
if (!restoreState(settings.value("layout").toByteArray(), 0)
|
|
|
|
|| force_inittoolbars)
|
2008-05-27 11:15:17 +00:00
|
|
|
initToolbars();
|
2008-06-20 06:43:43 +00:00
|
|
|
updateDialogs();
|
2008-06-19 17:30:30 +00:00
|
|
|
return true;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
GuiToolbar * GuiView::toolbar(string const & name)
|
|
|
|
{
|
|
|
|
ToolbarMap::iterator it = d.toolbars_.find(name);
|
|
|
|
if (it != d.toolbars_.end())
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::constructToolbars()
|
|
|
|
{
|
|
|
|
ToolbarMap::iterator it = d.toolbars_.begin();
|
|
|
|
for (; it != d.toolbars_.end(); ++it)
|
|
|
|
delete it->second;
|
|
|
|
d.toolbars_.clear();
|
|
|
|
|
2009-08-15 14:34:00 +00:00
|
|
|
// I don't like doing this here, but the standard toolbar
|
|
|
|
// destroys this object when it's destroyed itself (vfr)
|
|
|
|
d.layout_ = new LayoutBox(*this);
|
|
|
|
d.stack_widget_->addWidget(d.layout_);
|
|
|
|
d.layout_->move(0,0);
|
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
// extracts the toolbars from the backend
|
|
|
|
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
|
|
|
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
d.toolbars_[cit->name] = new GuiToolbar(*cit, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::initToolbars()
|
|
|
|
{
|
|
|
|
// extracts the toolbars from the backend
|
|
|
|
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
|
|
|
|
Toolbars::Infos::iterator end = guiApp->toolbars().end();
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
GuiToolbar * tb = toolbar(cit->name);
|
|
|
|
if (!tb)
|
|
|
|
continue;
|
|
|
|
int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
|
2010-01-27 17:19:14 +00:00
|
|
|
bool newline = !(visibility & Toolbars::SAMEROW);
|
2008-05-27 11:15:17 +00:00
|
|
|
tb->setVisible(false);
|
|
|
|
tb->setVisibility(visibility);
|
|
|
|
|
|
|
|
if (visibility & Toolbars::TOP) {
|
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::TopToolBarArea);
|
|
|
|
addToolBar(Qt::TopToolBarArea, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility & Toolbars::BOTTOM) {
|
2010-01-27 17:23:40 +00:00
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::BottomToolBarArea);
|
2008-05-27 11:15:17 +00:00
|
|
|
addToolBar(Qt::BottomToolBarArea, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility & Toolbars::LEFT) {
|
2010-01-27 17:23:40 +00:00
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::LeftToolBarArea);
|
2008-05-27 11:15:17 +00:00
|
|
|
addToolBar(Qt::LeftToolBarArea, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility & Toolbars::RIGHT) {
|
2010-01-27 17:23:40 +00:00
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::RightToolBarArea);
|
2008-05-27 11:15:17 +00:00
|
|
|
addToolBar(Qt::RightToolBarArea, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility & Toolbars::ON)
|
|
|
|
tb->setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-02 12:09:51 +00:00
|
|
|
TocModels & GuiView::tocModels()
|
|
|
|
{
|
|
|
|
return d.toc_models_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::setFocus()
|
2006-12-23 17:09:50 +00:00
|
|
|
{
|
2008-11-16 01:20:34 +00:00
|
|
|
LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this);
|
2010-01-10 19:08:41 +00:00
|
|
|
QMainWindow::setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::focusInEvent(QFocusEvent * e)
|
|
|
|
{
|
|
|
|
LYXERR(Debug::DEBUG, "GuiView::focusInEvent()" << this);
|
|
|
|
QMainWindow::focusInEvent(e);
|
2010-02-09 16:11:13 +00:00
|
|
|
// Make sure guiApp points to the correct view.
|
2008-10-03 07:54:32 +00:00
|
|
|
guiApp->setCurrentView(this);
|
2011-01-26 23:18:36 +00:00
|
|
|
if (currentWorkArea())
|
2010-01-10 19:08:41 +00:00
|
|
|
currentWorkArea()->setFocus();
|
2011-01-26 23:18:36 +00:00
|
|
|
else if (currentMainWorkArea())
|
|
|
|
currentMainWorkArea()->setFocus();
|
2010-01-08 20:08:48 +00:00
|
|
|
else
|
|
|
|
d.bg_widget_->setFocus();
|
2006-12-23 17:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-22 23:47:13 +00:00
|
|
|
QMenu * GuiView::createPopupMenu()
|
2006-11-08 23:10:46 +00:00
|
|
|
{
|
2006-11-29 10:04:35 +00:00
|
|
|
return d.toolBarPopup(this);
|
2006-11-08 23:10:46 +00:00
|
|
|
}
|
2006-10-23 16:29:24 +00:00
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
2007-11-16 21:52:04 +00:00
|
|
|
void GuiView::showEvent(QShowEvent * e)
|
|
|
|
{
|
|
|
|
LYXERR(Debug::GUI, "Passed Geometry "
|
|
|
|
<< size().height() << "x" << size().width()
|
|
|
|
<< "+" << pos().x() << "+" << pos().y());
|
2007-11-15 12:58:44 +00:00
|
|
|
|
|
|
|
if (d.splitter_->count() == 0)
|
|
|
|
// No work area, switch to the background widget.
|
|
|
|
d.setBackground();
|
|
|
|
|
2011-09-17 10:58:01 +00:00
|
|
|
updateToolbars();
|
2007-11-15 12:58:44 +00:00
|
|
|
QMainWindow::showEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 22:07:38 +00:00
|
|
|
bool GuiView::closeScheduled()
|
|
|
|
{
|
|
|
|
closing_ = true;
|
|
|
|
return close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-16 01:20:34 +00:00
|
|
|
/** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
|
|
|
|
** is responsibility of the container (e.g., dialog)
|
|
|
|
**/
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::closeEvent(QCloseEvent * close_event)
|
2006-12-02 17:39:31 +00:00
|
|
|
{
|
2008-11-16 01:20:34 +00:00
|
|
|
LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
|
2010-04-05 13:04:52 +00:00
|
|
|
|
|
|
|
if (!GuiViewPrivate::busyBuffers.isEmpty()) {
|
2010-11-18 23:12:46 +00:00
|
|
|
Alert::warning(_("Exit LyX"),
|
|
|
|
_("LyX could not be closed because documents are being processed by LyX."));
|
2010-04-05 13:04:52 +00:00
|
|
|
close_event->setAccepted(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-07 22:07:38 +00:00
|
|
|
// If the user pressed the x (so we didn't call closeView
|
|
|
|
// programmatically), we want to clear all existing entries.
|
|
|
|
if (!closing_)
|
|
|
|
theSession().lastOpened().clear();
|
2008-06-19 15:39:15 +00:00
|
|
|
closing_ = true;
|
|
|
|
|
2009-08-19 20:06:57 +00:00
|
|
|
writeSession();
|
|
|
|
|
2008-03-14 23:25:56 +00:00
|
|
|
// it can happen that this event arrives without selecting the view,
|
|
|
|
// e.g. when clicking the close button on a background window.
|
2008-10-03 07:54:32 +00:00
|
|
|
setFocus();
|
2009-08-18 20:48:15 +00:00
|
|
|
if (!closeWorkAreaAll()) {
|
2009-08-06 23:17:16 +00:00
|
|
|
closing_ = false;
|
|
|
|
close_event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-15 16:03:11 +00:00
|
|
|
// Make sure that nothing will use this to be closed View.
|
2009-08-06 23:17:16 +00:00
|
|
|
guiApp->unregisterView(this);
|
|
|
|
|
|
|
|
if (isFullScreen()) {
|
|
|
|
// Switch off fullscreen before closing.
|
|
|
|
toggleFullScreen();
|
|
|
|
updateDialogs();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the timer time out will not trigger a statusbar update.
|
|
|
|
d.statusbar_timer_.stop();
|
|
|
|
|
|
|
|
// Saving fullscreen requires additional tweaks in the toolbar code.
|
|
|
|
// It wouldn't also work under linux natively.
|
|
|
|
if (lyxrc.allow_geometry_session) {
|
|
|
|
saveLayout();
|
2011-01-03 16:49:15 +00:00
|
|
|
saveUISettings();
|
2009-08-06 23:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close_event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::dragEnterEvent(QDragEnterEvent * event)
|
2007-08-14 13:14:47 +00:00
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls())
|
|
|
|
event->accept();
|
|
|
|
/// \todo Ask lyx-devel is this is enough:
|
|
|
|
/// if (event->mimeData()->hasFormat("text/plain"))
|
|
|
|
/// event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-15 16:29:58 +00:00
|
|
|
void GuiView::dropEvent(QDropEvent * event)
|
2007-08-14 13:14:47 +00:00
|
|
|
{
|
|
|
|
QList<QUrl> files = event->mimeData()->urls();
|
|
|
|
if (files.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2007-11-22 23:34:57 +00:00
|
|
|
LYXERR(Debug::GUI, "GuiView::dropEvent: got URLs!");
|
2007-08-31 05:53:55 +00:00
|
|
|
for (int i = 0; i != files.size(); ++i) {
|
2007-12-12 19:57:42 +00:00
|
|
|
string const file = os::internal_path(fromqstr(
|
2007-08-14 13:14:47 +00:00
|
|
|
files.at(i).toLocalFile()));
|
2009-12-12 15:25:45 +00:00
|
|
|
if (file.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
string const ext = support::getExtension(file);
|
|
|
|
vector<const Format *> found_formats;
|
|
|
|
|
|
|
|
// Find all formats that have the correct extension.
|
2010-09-07 14:11:28 +00:00
|
|
|
vector<const Format *> const & import_formats
|
2009-12-12 15:25:45 +00:00
|
|
|
= theConverters().importableFormats();
|
|
|
|
vector<const Format *>::const_iterator it = import_formats.begin();
|
|
|
|
for (; it != import_formats.end(); ++it)
|
2011-09-17 11:04:55 +00:00
|
|
|
if ((*it)->hasExtension(ext))
|
2009-12-12 15:25:45 +00:00
|
|
|
found_formats.push_back(*it);
|
|
|
|
|
|
|
|
FuncRequest cmd;
|
|
|
|
if (found_formats.size() >= 1) {
|
|
|
|
if (found_formats.size() > 1) {
|
|
|
|
//FIXME: show a dialog to choose the correct importable format
|
|
|
|
LYXERR(Debug::FILES,
|
|
|
|
"Multiple importable formats found, selecting first");
|
|
|
|
}
|
|
|
|
string const arg = found_formats[0]->name() + " " + file;
|
|
|
|
cmd = FuncRequest(LFUN_BUFFER_IMPORT, arg);
|
2010-09-07 14:11:28 +00:00
|
|
|
}
|
2009-12-12 15:25:45 +00:00
|
|
|
else {
|
|
|
|
//FIXME: do we have to explicitly check whether it's a lyx file?
|
|
|
|
LYXERR(Debug::FILES,
|
|
|
|
"No formats found, trying to open it as a lyx file");
|
|
|
|
cmd = FuncRequest(LFUN_FILE_OPEN, file);
|
2008-11-15 16:29:58 +00:00
|
|
|
}
|
2010-10-22 15:46:46 +00:00
|
|
|
// add the functions to the queue
|
2010-10-22 18:08:21 +00:00
|
|
|
guiApp->addToFuncRequestQueue(cmd);
|
2009-12-12 15:25:45 +00:00
|
|
|
event->accept();
|
2007-08-14 13:14:47 +00:00
|
|
|
}
|
2010-10-22 18:08:21 +00:00
|
|
|
// now process the collected functions. We perform the events
|
|
|
|
// asynchronously. This prevents potential problems in case the
|
|
|
|
// BufferView is closed within an event.
|
2010-10-22 15:46:46 +00:00
|
|
|
guiApp->processFuncRequestQueueAsync();
|
2007-08-14 13:14:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::message(docstring const & str)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-01-15 18:26:53 +00:00
|
|
|
if (ForkedProcess::iAmAChild())
|
|
|
|
return;
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2009-12-21 13:11:17 +00:00
|
|
|
// call is moved to GUI-thread by GuiProgress
|
|
|
|
d.progress_->appendMessage(toqstr(str));
|
|
|
|
}
|
2008-01-15 18:26:53 +00:00
|
|
|
|
2009-12-21 13:11:17 +00:00
|
|
|
|
2010-03-05 18:07:05 +00:00
|
|
|
void GuiView::clearMessageText()
|
|
|
|
{
|
|
|
|
message(docstring());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::updateStatusBarMessage(QString const & str)
|
2009-12-21 13:11:17 +00:00
|
|
|
{
|
|
|
|
statusBar()->showMessage(str);
|
2007-11-18 23:30:41 +00:00
|
|
|
d.statusbar_timer_.stop();
|
2007-11-22 23:29:53 +00:00
|
|
|
d.statusbar_timer_.start(3000);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::smallSizedIcons()
|
2006-11-29 10:04:35 +00:00
|
|
|
{
|
2007-11-15 12:58:44 +00:00
|
|
|
setIconSize(QSize(d.smallIconSize, d.smallIconSize));
|
2006-11-29 10:04:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::normalSizedIcons()
|
2006-11-29 10:04:35 +00:00
|
|
|
{
|
2007-11-15 12:58:44 +00:00
|
|
|
setIconSize(QSize(d.normalIconSize, d.normalIconSize));
|
2006-11-29 10:04:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::bigSizedIcons()
|
2006-11-29 10:04:35 +00:00
|
|
|
{
|
2007-11-15 12:58:44 +00:00
|
|
|
setIconSize(QSize(d.bigIconSize, d.bigIconSize));
|
2006-11-29 10:04:35 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-11-13 13:23:44 +00:00
|
|
|
void GuiView::clearMessage()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2009-12-25 23:29:07 +00:00
|
|
|
// FIXME: This code was introduced in r19643 to fix bug #4123. However,
|
|
|
|
// the hasFocus function mostly returns false, even if the focus is on
|
|
|
|
// a workarea in this view.
|
|
|
|
//if (!hasFocus())
|
|
|
|
// return;
|
2009-09-30 07:40:27 +00:00
|
|
|
showMessage();
|
2007-11-18 23:30:41 +00:00
|
|
|
d.statusbar_timer_.stop();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-12-03 13:17:35 +00:00
|
|
|
|
2007-11-11 22:30:21 +00:00
|
|
|
void GuiView::updateWindowTitle(GuiWorkArea * wa)
|
|
|
|
{
|
2010-01-07 19:54:42 +00:00
|
|
|
if (wa != d.current_work_area_
|
2010-03-05 18:07:05 +00:00
|
|
|
|| wa->bufferView().buffer().isInternal())
|
2007-11-11 22:30:21 +00:00
|
|
|
return;
|
|
|
|
setWindowTitle(qt_("LyX: ") + wa->windowTitle());
|
|
|
|
setWindowIconText(wa->windowIconText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
|
2006-10-31 14:12:46 +00:00
|
|
|
{
|
2012-09-11 03:18:22 +00:00
|
|
|
if (d.current_work_area_)
|
|
|
|
QObject::disconnect(d.current_work_area_, SIGNAL(busy(bool)),
|
|
|
|
this, SLOT(setBusy(bool)));
|
2007-08-21 07:33:46 +00:00
|
|
|
disconnectBuffer();
|
|
|
|
disconnectBufferView();
|
2007-10-06 15:48:58 +00:00
|
|
|
connectBufferView(wa->bufferView());
|
|
|
|
connectBuffer(wa->bufferView().buffer());
|
2007-11-11 22:30:21 +00:00
|
|
|
d.current_work_area_ = wa;
|
|
|
|
QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
|
|
|
|
this, SLOT(updateWindowTitle(GuiWorkArea *)));
|
2011-10-23 20:21:01 +00:00
|
|
|
QObject::connect(wa, SIGNAL(busy(bool)), this, SLOT(setBusy(bool)));
|
2007-11-11 22:30:21 +00:00
|
|
|
updateWindowTitle(wa);
|
2007-08-21 07:33:46 +00:00
|
|
|
|
2008-04-27 22:24:20 +00:00
|
|
|
structureChanged();
|
|
|
|
|
2008-05-04 07:50:00 +00:00
|
|
|
// The document settings needs to be reinitialised.
|
|
|
|
updateDialog("document", "");
|
|
|
|
|
2008-04-27 22:24:20 +00:00
|
|
|
// Buffer-dependent dialogs must be updated. This is done here because
|
|
|
|
// some dialogs require buffer()->text.
|
|
|
|
updateDialogs();
|
2006-10-31 14:12:46 +00:00
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-14 23:24:59 +00:00
|
|
|
void GuiView::on_lastWorkAreaRemoved()
|
|
|
|
{
|
2008-06-19 15:39:15 +00:00
|
|
|
if (closing_)
|
|
|
|
// We already are in a close event. Nothing more to do.
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d.splitter_->count() > 1)
|
|
|
|
// We have a splitter so don't close anything.
|
|
|
|
return;
|
|
|
|
|
2008-06-20 06:35:42 +00:00
|
|
|
// Reset and updates the dialogs.
|
|
|
|
d.toc_models_.reset(0);
|
|
|
|
updateDialog("document", "");
|
|
|
|
updateDialogs();
|
|
|
|
|
2008-08-11 12:57:02 +00:00
|
|
|
resetWindowTitleAndIconText();
|
2009-12-26 23:58:24 +00:00
|
|
|
updateStatusBar();
|
2008-08-11 12:57:02 +00:00
|
|
|
|
2008-06-20 06:35:42 +00:00
|
|
|
if (lyxrc.open_buffers_in_tabs)
|
|
|
|
// Nothing more to do, the window should stay open.
|
2008-06-19 15:39:15 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-20 06:35:42 +00:00
|
|
|
if (guiApp->viewIds().size() > 1) {
|
|
|
|
close();
|
|
|
|
return;
|
2008-06-19 15:39:15 +00:00
|
|
|
}
|
2008-06-20 06:35:42 +00:00
|
|
|
|
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// On Mac we also close the last window because the application stay
|
|
|
|
// resident in memory. On other platforms we don't close the last
|
|
|
|
// window because this would quit the application.
|
2008-06-19 15:55:34 +00:00
|
|
|
close();
|
2008-06-20 06:35:42 +00:00
|
|
|
#endif
|
2008-03-14 23:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::updateStatusBar()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
// let the user see the explicit message
|
2007-11-18 23:30:41 +00:00
|
|
|
if (d.statusbar_timer_.isActive())
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
|
2009-09-30 07:40:27 +00:00
|
|
|
showMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::showMessage()
|
|
|
|
{
|
2013-03-08 23:09:28 +00:00
|
|
|
if (busy_)
|
|
|
|
return;
|
2009-10-04 20:58:20 +00:00
|
|
|
QString msg = toqstr(theGuiApp()->viewStatusMessage());
|
2009-09-30 07:40:27 +00:00
|
|
|
if (msg.isEmpty()) {
|
|
|
|
BufferView const * bv = currentBufferView();
|
|
|
|
if (bv)
|
|
|
|
msg = toqstr(bv->cursor().currentState());
|
|
|
|
else
|
|
|
|
msg = qt_("Welcome to LyX!");
|
|
|
|
}
|
|
|
|
statusBar()->showMessage(msg);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
bool GuiView::event(QEvent * e)
|
2006-12-20 21:28:05 +00:00
|
|
|
{
|
|
|
|
switch (e->type())
|
|
|
|
{
|
2007-08-15 08:29:10 +00:00
|
|
|
// Useful debug code:
|
|
|
|
//case QEvent::ActivationChange:
|
|
|
|
//case QEvent::WindowDeactivate:
|
|
|
|
//case QEvent::Paint:
|
|
|
|
//case QEvent::Enter:
|
|
|
|
//case QEvent::Leave:
|
|
|
|
//case QEvent::HoverEnter:
|
|
|
|
//case QEvent::HoverLeave:
|
|
|
|
//case QEvent::HoverMove:
|
|
|
|
//case QEvent::StatusTip:
|
|
|
|
//case QEvent::DragEnter:
|
|
|
|
//case QEvent::DragLeave:
|
|
|
|
//case QEvent::Drop:
|
|
|
|
// break;
|
|
|
|
|
2007-10-16 06:50:09 +00:00
|
|
|
case QEvent::WindowActivate: {
|
2009-09-22 21:25:32 +00:00
|
|
|
GuiView * old_view = guiApp->currentView();
|
|
|
|
if (this == old_view) {
|
2008-03-04 10:43:35 +00:00
|
|
|
setFocus();
|
|
|
|
return QMainWindow::event(e);
|
|
|
|
}
|
2009-09-23 07:14:20 +00:00
|
|
|
if (old_view && old_view->currentBufferView()) {
|
2009-09-22 21:25:32 +00:00
|
|
|
// save current selection to the selection buffer to allow
|
|
|
|
// middle-button paste in this window.
|
|
|
|
cap::saveSelection(old_view->currentBufferView()->cursor());
|
|
|
|
}
|
2008-03-15 02:42:59 +00:00
|
|
|
guiApp->setCurrentView(this);
|
2007-11-11 10:09:48 +00:00
|
|
|
if (d.current_work_area_) {
|
|
|
|
BufferView & bv = d.current_work_area_->bufferView();
|
2007-10-03 07:17:58 +00:00
|
|
|
connectBufferView(bv);
|
|
|
|
connectBuffer(bv.buffer());
|
2007-10-03 08:03:01 +00:00
|
|
|
// The document structure, name and dialogs might have
|
|
|
|
// changed in another view.
|
2008-04-27 22:24:20 +00:00
|
|
|
structureChanged();
|
2008-05-04 07:50:00 +00:00
|
|
|
// The document settings needs to be reinitialised.
|
|
|
|
updateDialog("document", "");
|
2008-04-27 22:24:20 +00:00
|
|
|
updateDialogs();
|
2007-11-11 22:30:21 +00:00
|
|
|
} else {
|
2008-08-11 12:57:02 +00:00
|
|
|
resetWindowTitleAndIconText();
|
2007-10-03 07:17:58 +00:00
|
|
|
}
|
2008-02-12 15:44:45 +00:00
|
|
|
setFocus();
|
2007-10-03 07:12:28 +00:00
|
|
|
return QMainWindow::event(e);
|
2007-10-16 06:50:09 +00:00
|
|
|
}
|
2008-01-10 09:04:30 +00:00
|
|
|
|
2007-08-15 08:29:10 +00:00
|
|
|
case QEvent::ShortcutOverride: {
|
2012-11-04 00:18:16 +00:00
|
|
|
// See bug 4888
|
2008-05-15 09:42:28 +00:00
|
|
|
if (isFullScreen() && menuBar()->isHidden()) {
|
|
|
|
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
|
2008-05-15 23:26:31 +00:00
|
|
|
// FIXME: we should also try to detect special LyX shortcut such as
|
2008-05-16 08:11:37 +00:00
|
|
|
// Alt-P and Alt-M. Right now there is a hack in
|
|
|
|
// GuiWorkArea::processKeySym() that hides again the menubar for
|
|
|
|
// those cases.
|
2008-11-29 17:29:13 +00:00
|
|
|
if (ke->modifiers() & Qt::AltModifier && ke->key() != Qt::Key_Alt) {
|
2008-05-15 23:26:31 +00:00
|
|
|
menuBar()->show();
|
2008-11-29 17:29:13 +00:00
|
|
|
return QMainWindow::event(e);
|
|
|
|
}
|
2008-05-15 09:14:09 +00:00
|
|
|
}
|
2010-01-08 20:08:48 +00:00
|
|
|
return QMainWindow::event(e);
|
2006-12-20 21:28:05 +00:00
|
|
|
}
|
2008-01-10 09:04:30 +00:00
|
|
|
|
2007-08-15 08:29:10 +00:00
|
|
|
default:
|
|
|
|
return QMainWindow::event(e);
|
|
|
|
}
|
2006-12-20 21:28:05 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 12:57:02 +00:00
|
|
|
void GuiView::resetWindowTitleAndIconText()
|
|
|
|
{
|
2010-03-05 18:07:05 +00:00
|
|
|
setWindowTitle(qt_("LyX"));
|
|
|
|
setWindowIconText(qt_("LyX"));
|
2008-08-11 12:57:02 +00:00
|
|
|
}
|
2006-12-20 21:28:05 +00:00
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
bool GuiView::focusNextPrevChild(bool /*next*/)
|
2006-12-22 16:13:19 +00:00
|
|
|
{
|
2006-12-23 17:09:50 +00:00
|
|
|
setFocus();
|
2006-12-22 16:13:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-07 22:09:59 +00:00
|
|
|
bool GuiView::busy() const
|
2010-06-04 13:24:03 +00:00
|
|
|
{
|
2010-11-05 20:24:58 +00:00
|
|
|
return busy_ > 0;
|
2010-06-04 13:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-02 23:50:42 +00:00
|
|
|
void GuiView::setBusy(bool busy)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-11-05 20:24:58 +00:00
|
|
|
bool const busy_before = busy_ > 0;
|
|
|
|
busy ? ++busy_ : --busy_;
|
|
|
|
if ((busy_ > 0) == busy_before)
|
|
|
|
// busy state didn't change
|
|
|
|
return;
|
|
|
|
|
2011-10-23 20:21:01 +00:00
|
|
|
if (busy) {
|
2006-06-04 20:49:09 +00:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2011-10-23 20:21:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
updateLayoutList();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
2010-11-30 13:03:46 +00:00
|
|
|
GuiWorkArea * GuiView::workArea(int index)
|
|
|
|
{
|
|
|
|
if (TabWorkArea * twa = d.currentTabWorkArea())
|
|
|
|
if (index < twa->count())
|
|
|
|
return dynamic_cast<GuiWorkArea *>(twa->widget(index));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-13 09:52:28 +00:00
|
|
|
GuiWorkArea * GuiView::workArea(Buffer & buffer)
|
2007-08-21 07:33:46 +00:00
|
|
|
{
|
2008-11-16 01:20:34 +00:00
|
|
|
if (currentWorkArea()
|
2010-03-05 18:07:05 +00:00
|
|
|
&& ¤tWorkArea()->bufferView().buffer() == &buffer)
|
2008-11-16 01:20:34 +00:00
|
|
|
return (GuiWorkArea *) currentWorkArea();
|
2008-02-21 11:48:31 +00:00
|
|
|
if (TabWorkArea * twa = d.currentTabWorkArea())
|
|
|
|
return twa->workArea(buffer);
|
2007-11-11 10:09:48 +00:00
|
|
|
return 0;
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-13 09:52:28 +00:00
|
|
|
GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
|
2007-08-21 07:33:46 +00:00
|
|
|
{
|
2007-11-11 10:09:48 +00:00
|
|
|
// Automatically create a TabWorkArea if there are none yet.
|
2010-09-07 14:11:28 +00:00
|
|
|
TabWorkArea * tab_widget = d.splitter_->count()
|
2008-02-20 21:46:49 +00:00
|
|
|
? d.currentTabWorkArea() : addTabWorkArea();
|
2007-11-19 10:04:14 +00:00
|
|
|
return tab_widget->addWorkArea(buffer, *this);
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 21:46:49 +00:00
|
|
|
TabWorkArea * GuiView::addTabWorkArea()
|
2007-11-11 10:09:48 +00:00
|
|
|
{
|
|
|
|
TabWorkArea * twa = new TabWorkArea;
|
|
|
|
QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
|
|
|
|
this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
|
2008-03-14 23:24:59 +00:00
|
|
|
QObject::connect(twa, SIGNAL(lastWorkAreaRemoved()),
|
|
|
|
this, SLOT(on_lastWorkAreaRemoved()));
|
|
|
|
|
2007-11-11 10:09:48 +00:00
|
|
|
d.splitter_->addWidget(twa);
|
|
|
|
d.stack_widget_->setCurrentWidget(d.splitter_);
|
2008-02-20 21:46:49 +00:00
|
|
|
return twa;
|
2007-11-11 10:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-13 09:52:28 +00:00
|
|
|
GuiWorkArea const * GuiView::currentWorkArea() const
|
2007-08-21 07:33:46 +00:00
|
|
|
{
|
2007-11-11 10:09:48 +00:00
|
|
|
return d.current_work_area_;
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-16 01:20:34 +00:00
|
|
|
GuiWorkArea * GuiView::currentWorkArea()
|
|
|
|
{
|
|
|
|
return d.current_work_area_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiWorkArea const * GuiView::currentMainWorkArea() const
|
|
|
|
{
|
2010-02-26 14:07:21 +00:00
|
|
|
if (!d.currentTabWorkArea())
|
|
|
|
return 0;
|
2008-11-16 01:20:34 +00:00
|
|
|
return d.currentTabWorkArea()->currentWorkArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GuiWorkArea * GuiView::currentMainWorkArea()
|
|
|
|
{
|
2010-02-26 14:07:21 +00:00
|
|
|
if (!d.currentTabWorkArea())
|
|
|
|
return 0;
|
2008-11-16 01:20:34 +00:00
|
|
|
return d.currentTabWorkArea()->currentWorkArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 23:55:16 +00:00
|
|
|
void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
|
2007-08-21 07:33:46 +00:00
|
|
|
{
|
2008-11-16 01:20:34 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
|
2010-02-26 14:07:21 +00:00
|
|
|
if (!wa) {
|
|
|
|
d.current_work_area_ = 0;
|
2008-11-16 01:20:34 +00:00
|
|
|
d.setBackground();
|
|
|
|
return;
|
2007-11-11 10:09:48 +00:00
|
|
|
}
|
2010-02-26 14:07:21 +00:00
|
|
|
|
|
|
|
// FIXME: I've no clue why this is here and why it accesses
|
|
|
|
// theGuiApp()->currentView, which might be 0 (bug 6464).
|
|
|
|
// See also 27525 (vfr).
|
2010-09-07 14:11:28 +00:00
|
|
|
if (theGuiApp()->currentView() == this
|
|
|
|
&& theGuiApp()->currentView()->currentWorkArea() == wa)
|
2008-11-16 15:32:11 +00:00
|
|
|
return;
|
|
|
|
|
2009-09-05 14:29:11 +00:00
|
|
|
if (currentBufferView())
|
|
|
|
cap::saveSelection(currentBufferView()->cursor());
|
2009-08-09 14:27:50 +00:00
|
|
|
|
2008-11-16 15:32:11 +00:00
|
|
|
theGuiApp()->setCurrentView(this);
|
|
|
|
d.current_work_area_ = wa;
|
2010-11-02 15:33:52 +00:00
|
|
|
|
|
|
|
// We need to reset this now, because it will need to be
|
|
|
|
// right if the tabWorkArea gets reset in the for loop. We
|
|
|
|
// will change it back if we aren't in that case.
|
|
|
|
GuiWorkArea * const old_cmwa = d.current_main_work_area_;
|
|
|
|
d.current_main_work_area_ = wa;
|
|
|
|
|
2008-11-16 15:32:11 +00:00
|
|
|
for (int i = 0; i != d.splitter_->count(); ++i) {
|
|
|
|
if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
|
2010-11-02 15:33:52 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea()
|
|
|
|
<< ", Current main wa: " << currentMainWorkArea());
|
2008-11-16 15:32:11 +00:00
|
|
|
return;
|
2008-11-16 01:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-02 15:33:52 +00:00
|
|
|
|
|
|
|
d.current_main_work_area_ = old_cmwa;
|
|
|
|
|
2008-11-16 15:32:11 +00:00
|
|
|
LYXERR(Debug::DEBUG, "This is not a tabbed wa");
|
|
|
|
on_currentWorkAreaChanged(wa);
|
|
|
|
BufferView & bv = wa->bufferView();
|
|
|
|
bv.cursor().fixIfBroken();
|
|
|
|
bv.updateMetrics();
|
|
|
|
wa->setUpdatesEnabled(true);
|
2008-11-16 01:20:34 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 23:55:16 +00:00
|
|
|
void GuiView::removeWorkArea(GuiWorkArea * wa)
|
2007-08-21 07:33:46 +00:00
|
|
|
{
|
2008-09-29 08:42:18 +00:00
|
|
|
LASSERT(wa, return);
|
2007-11-26 23:55:16 +00:00
|
|
|
if (wa == d.current_work_area_) {
|
2007-08-21 07:33:46 +00:00
|
|
|
disconnectBuffer();
|
|
|
|
disconnectBufferView();
|
2007-11-11 10:09:48 +00:00
|
|
|
d.current_work_area_ = 0;
|
2008-11-16 01:20:34 +00:00
|
|
|
d.current_main_work_area_ = 0;
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-16 01:20:34 +00:00
|
|
|
bool found_twa = false;
|
2007-11-11 10:09:48 +00:00
|
|
|
for (int i = 0; i != d.splitter_->count(); ++i) {
|
|
|
|
TabWorkArea * twa = d.tabWorkArea(i);
|
2008-11-16 01:20:34 +00:00
|
|
|
if (twa->removeWorkArea(wa)) {
|
|
|
|
// Found in this tab group, and deleted the GuiWorkArea.
|
|
|
|
found_twa = true;
|
|
|
|
if (twa->count() != 0) {
|
|
|
|
if (d.current_work_area_ == 0)
|
|
|
|
// This means that we are closing the current GuiWorkArea, so
|
|
|
|
// switch to the next GuiWorkArea in the found TabWorkArea.
|
|
|
|
setCurrentWorkArea(twa->currentWorkArea());
|
|
|
|
} else {
|
|
|
|
// No more WorkAreas in this tab group, so delete it.
|
|
|
|
delete twa;
|
|
|
|
}
|
2007-11-11 10:09:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-16 01:20:34 +00:00
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
2008-11-16 01:20:34 +00:00
|
|
|
// It is not a tabbed work area (i.e., the search work area), so it
|
|
|
|
// should be deleted by other means.
|
|
|
|
LASSERT(found_twa, /* */);
|
2007-11-11 10:09:48 +00:00
|
|
|
|
2008-11-16 01:20:34 +00:00
|
|
|
if (d.current_work_area_ == 0) {
|
|
|
|
if (d.splitter_->count() != 0) {
|
|
|
|
TabWorkArea * twa = d.currentTabWorkArea();
|
|
|
|
setCurrentWorkArea(twa->currentWorkArea());
|
|
|
|
} else {
|
|
|
|
// No more work areas, switch to the background widget.
|
|
|
|
setCurrentWorkArea(0);
|
|
|
|
}
|
2007-11-11 10:09:48 +00:00
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-14 22:58:57 +00:00
|
|
|
LayoutBox * GuiView::getLayoutDialog() const
|
2007-10-01 20:45:50 +00:00
|
|
|
{
|
2009-08-14 22:58:57 +00:00
|
|
|
return d.layout_;
|
2007-11-20 22:03:56 +00:00
|
|
|
}
|
2007-10-01 20:45:50 +00:00
|
|
|
|
|
|
|
|
2007-11-20 22:03:56 +00:00
|
|
|
void GuiView::updateLayoutList()
|
|
|
|
{
|
|
|
|
if (d.layout_)
|
|
|
|
d.layout_->updateContents(false);
|
2007-10-01 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
void GuiView::updateToolbars()
|
2007-10-01 20:45:50 +00:00
|
|
|
{
|
2008-05-27 11:15:17 +00:00
|
|
|
ToolbarMap::iterator end = d.toolbars_.end();
|
2007-11-11 10:09:48 +00:00
|
|
|
if (d.current_work_area_) {
|
2007-10-01 20:45:50 +00:00
|
|
|
bool const math =
|
2010-03-17 13:37:15 +00:00
|
|
|
d.current_work_area_->bufferView().cursor().inMathed()
|
|
|
|
&& !d.current_work_area_->bufferView().cursor().inRegexped();
|
2007-10-01 20:45:50 +00:00
|
|
|
bool const table =
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
|
|
|
|
bool const review =
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
|
2010-04-16 10:51:20 +00:00
|
|
|
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onOff(true);
|
2007-12-23 00:47:37 +00:00
|
|
|
bool const mathmacrotemplate =
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
|
2012-08-21 12:56:34 +00:00
|
|
|
bool const ipa =
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_IN_IPA)).enabled();
|
2007-12-23 00:49:18 +00:00
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
2012-08-21 12:56:34 +00:00
|
|
|
it->second->update(math, table, review, mathmacrotemplate, ipa);
|
2007-10-01 20:45:50 +00:00
|
|
|
} else
|
2008-05-27 11:15:17 +00:00
|
|
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
2012-08-21 12:56:34 +00:00
|
|
|
it->second->update(false, false, false, false, false);
|
2007-10-01 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
void GuiView::setBuffer(Buffer * newBuffer)
|
|
|
|
{
|
2009-12-20 15:07:15 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl);
|
2008-09-29 08:42:18 +00:00
|
|
|
LASSERT(newBuffer, return);
|
2011-03-19 19:20:42 +00:00
|
|
|
|
2007-11-13 09:52:28 +00:00
|
|
|
GuiWorkArea * wa = workArea(*newBuffer);
|
2007-11-12 23:23:19 +00:00
|
|
|
if (wa == 0) {
|
2011-03-19 19:20:42 +00:00
|
|
|
setBusy(true);
|
2010-03-03 22:13:45 +00:00
|
|
|
newBuffer->masterBuffer()->updateBuffer();
|
2011-03-19 19:20:42 +00:00
|
|
|
setBusy(false);
|
2007-11-12 23:23:19 +00:00
|
|
|
wa = addWorkArea(*newBuffer);
|
2010-10-26 12:34:04 +00:00
|
|
|
// scroll to the position when the BufferView was last closed
|
2010-10-24 23:41:15 +00:00
|
|
|
if (lyxrc.use_lastfilepos) {
|
|
|
|
LastFilePosSection::FilePos filepos =
|
|
|
|
theSession().lastFilePos().load(newBuffer->fileName());
|
|
|
|
wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
|
|
|
|
}
|
2007-11-12 23:23:19 +00:00
|
|
|
} else {
|
|
|
|
//Disconnect the old buffer...there's no new one.
|
|
|
|
disconnectBuffer();
|
|
|
|
}
|
|
|
|
connectBuffer(*newBuffer);
|
|
|
|
connectBufferView(wa->bufferView());
|
|
|
|
setCurrentWorkArea(wa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::connectBuffer(Buffer & buf)
|
|
|
|
{
|
|
|
|
buf.setGuiDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::disconnectBuffer()
|
|
|
|
{
|
2007-11-13 09:52:28 +00:00
|
|
|
if (d.current_work_area_)
|
2009-08-19 20:55:02 +00:00
|
|
|
d.current_work_area_->bufferView().buffer().setGuiDelegate(0);
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::connectBufferView(BufferView & bv)
|
|
|
|
{
|
|
|
|
bv.setGuiDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::disconnectBufferView()
|
|
|
|
{
|
2007-11-13 09:52:28 +00:00
|
|
|
if (d.current_work_area_)
|
|
|
|
d.current_work_area_->bufferView().setGuiDelegate(0);
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-21 12:26:41 +00:00
|
|
|
void GuiView::errors(string const & error_type, bool from_master)
|
2007-11-12 23:23:19 +00:00
|
|
|
{
|
2010-12-08 20:55:24 +00:00
|
|
|
BufferView const * const bv = currentBufferView();
|
|
|
|
if (!bv)
|
2010-12-08 21:02:28 +00:00
|
|
|
return;
|
2010-12-08 20:55:24 +00:00
|
|
|
|
2012-11-04 00:18:16 +00:00
|
|
|
#if EXPORT_in_THREAD
|
2011-03-03 16:00:40 +00:00
|
|
|
// We are called with from_master == false by default, so we
|
|
|
|
// have to figure out whether that is the case or not.
|
2011-06-12 18:03:32 +00:00
|
|
|
ErrorList & el = bv->buffer().errorList(error_type);
|
2011-03-03 16:00:40 +00:00
|
|
|
if (el.empty()) {
|
|
|
|
el = bv->buffer().masterBuffer()->errorList(error_type);
|
|
|
|
from_master = true;
|
|
|
|
}
|
|
|
|
#else
|
2011-06-08 00:12:52 +00:00
|
|
|
ErrorList const & el = from_master ?
|
2010-12-08 20:55:24 +00:00
|
|
|
bv->buffer().masterBuffer()->errorList(error_type) :
|
|
|
|
bv->buffer().errorList(error_type);
|
2011-03-03 16:00:40 +00:00
|
|
|
#endif
|
|
|
|
|
2010-12-08 20:55:24 +00:00
|
|
|
if (el.empty())
|
|
|
|
return;
|
|
|
|
|
2009-06-21 12:26:41 +00:00
|
|
|
string data = error_type;
|
|
|
|
if (from_master)
|
|
|
|
data = "from_master|" + error_type;
|
2010-12-08 20:55:24 +00:00
|
|
|
showDialog("errorlist", data);
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-20 15:07:15 +00:00
|
|
|
void GuiView::updateTocItem(string const & type, DocIterator const & dit)
|
2008-09-30 09:50:54 +00:00
|
|
|
{
|
|
|
|
d.toc_models_.updateItem(toqstr(type), dit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-28 04:57:31 +00:00
|
|
|
void GuiView::structureChanged()
|
|
|
|
{
|
2009-08-22 16:16:56 +00:00
|
|
|
d.toc_models_.reset(documentBufferView());
|
2008-05-03 08:24:05 +00:00
|
|
|
// Navigator needs more than a simple update in this case. It needs to be
|
|
|
|
// rebuilt.
|
2008-04-28 04:57:31 +00:00
|
|
|
updateDialog("toc", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
void GuiView::updateDialog(string const & name, string const & data)
|
|
|
|
{
|
2007-11-18 00:01:14 +00:00
|
|
|
if (!isDialogVisible(name))
|
|
|
|
return;
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (it == d.dialogs_.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Dialog * const dialog = it->second.get();
|
|
|
|
if (dialog->isVisibleView())
|
2008-05-02 21:38:23 +00:00
|
|
|
dialog->initialiseParams(data);
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-22 16:16:56 +00:00
|
|
|
BufferView * GuiView::documentBufferView()
|
|
|
|
{
|
|
|
|
return currentMainWorkArea()
|
|
|
|
? ¤tMainWorkArea()->bufferView()
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 14:11:28 +00:00
|
|
|
BufferView const * GuiView::documentBufferView() const
|
2009-09-05 14:29:11 +00:00
|
|
|
{
|
|
|
|
return currentMainWorkArea()
|
|
|
|
? ¤tMainWorkArea()->bufferView()
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * GuiView::currentBufferView()
|
|
|
|
{
|
|
|
|
return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BufferView const * GuiView::currentBufferView() const
|
2007-11-12 23:23:19 +00:00
|
|
|
{
|
2007-11-13 09:52:28 +00:00
|
|
|
return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-17 02:23:39 +00:00
|
|
|
docstring GuiView::GuiViewPrivate::autosaveAndDestroy(
|
2011-11-16 00:38:06 +00:00
|
|
|
Buffer const * orig, Buffer * clone)
|
2009-12-13 21:00:46 +00:00
|
|
|
{
|
2011-11-16 00:38:06 +00:00
|
|
|
bool const success = clone->autoSave();
|
|
|
|
delete clone;
|
2010-04-05 13:04:52 +00:00
|
|
|
busyBuffers.remove(orig);
|
2010-11-17 02:23:39 +00:00
|
|
|
return success
|
|
|
|
? _("Automatic save done.")
|
|
|
|
: _("Automatic save failed!");
|
2009-12-13 21:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
void GuiView::autoSave()
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::INFO, "Running autoSave()");
|
2007-11-12 23:23:19 +00:00
|
|
|
|
2009-12-13 21:00:46 +00:00
|
|
|
Buffer * buffer = documentBufferView()
|
|
|
|
? &documentBufferView()->buffer() : 0;
|
2011-02-15 17:07:01 +00:00
|
|
|
if (!buffer) {
|
|
|
|
resetAutosaveTimers();
|
2009-12-13 21:00:46 +00:00
|
|
|
return;
|
2011-02-15 17:07:01 +00:00
|
|
|
}
|
2009-12-13 21:00:46 +00:00
|
|
|
|
2010-04-05 13:04:52 +00:00
|
|
|
GuiViewPrivate::busyBuffers.insert(buffer);
|
2010-11-17 02:07:54 +00:00
|
|
|
QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::autosaveAndDestroy,
|
2011-12-03 23:20:18 +00:00
|
|
|
buffer, buffer->cloneBufferOnly());
|
2009-12-13 21:00:46 +00:00
|
|
|
d.autosave_watcher_.setFuture(f);
|
2010-11-17 02:27:02 +00:00
|
|
|
resetAutosaveTimers();
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-13 09:52:28 +00:00
|
|
|
void GuiView::resetAutosaveTimers()
|
2007-11-12 23:23:19 +00:00
|
|
|
{
|
|
|
|
if (lyxrc.autosave)
|
2007-11-22 23:29:53 +00:00
|
|
|
d.autosave_timeout_.restart();
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-22 15:01:36 +00:00
|
|
|
bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
2007-11-19 20:56:05 +00:00
|
|
|
{
|
|
|
|
bool enable = true;
|
2009-09-05 15:09:45 +00:00
|
|
|
Buffer * buf = currentBufferView()
|
|
|
|
? ¤tBufferView()->buffer() : 0;
|
2009-09-12 20:41:24 +00:00
|
|
|
Buffer * doc_buffer = documentBufferView()
|
|
|
|
? &(documentBufferView()->buffer()) : 0;
|
2007-11-19 20:56:05 +00:00
|
|
|
|
2009-09-23 09:07:24 +00:00
|
|
|
// Check whether we need a buffer
|
2010-04-09 19:00:42 +00:00
|
|
|
if (!lyxaction.funcHasFlag(cmd.action(), LyXAction::NoBuffer) && !buf) {
|
2009-09-23 09:07:24 +00:00
|
|
|
// no, exit directly
|
|
|
|
flag.message(from_utf8(N_("Command not allowed with"
|
2010-03-05 18:07:05 +00:00
|
|
|
"out any document open")));
|
2009-09-23 09:07:24 +00:00
|
|
|
flag.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
if (cmd.origin() == FuncRequest::TOC) {
|
2009-04-11 11:43:13 +00:00
|
|
|
GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
|
2010-04-16 12:49:27 +00:00
|
|
|
if (!toc || !toc->getStatus(documentBufferView()->cursor(), cmd, flag))
|
2009-04-11 11:43:13 +00:00
|
|
|
flag.setEnabled(false);
|
2009-04-08 21:06:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch(cmd.action()) {
|
2009-09-19 14:05:52 +00:00
|
|
|
case LFUN_BUFFER_IMPORT:
|
|
|
|
break;
|
|
|
|
|
2009-12-18 22:51:06 +00:00
|
|
|
case LFUN_MASTER_BUFFER_UPDATE:
|
2010-09-07 14:11:28 +00:00
|
|
|
case LFUN_MASTER_BUFFER_VIEW:
|
2009-12-20 15:43:52 +00:00
|
|
|
enable = doc_buffer && doc_buffer->parent() != 0
|
2010-10-23 10:49:45 +00:00
|
|
|
&& !d.processing_thread_watcher_.isRunning();
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_UPDATE:
|
|
|
|
case LFUN_BUFFER_VIEW: {
|
2010-10-23 10:49:45 +00:00
|
|
|
if (!doc_buffer || d.processing_thread_watcher_.isRunning()) {
|
2009-12-18 22:51:06 +00:00
|
|
|
enable = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
string format = to_utf8(cmd.argument());
|
|
|
|
if (cmd.argument().empty())
|
2011-05-13 19:39:56 +00:00
|
|
|
format = doc_buffer->params().getDefaultOutputFormat();
|
|
|
|
enable = doc_buffer->params().isExportableFormat(format);
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_BUFFER_RELOAD:
|
|
|
|
enable = doc_buffer && !doc_buffer->isUnnamed()
|
|
|
|
&& doc_buffer->fileName().exists()
|
|
|
|
&& (!doc_buffer->isClean()
|
|
|
|
|| doc_buffer->isExternallyModified(Buffer::timestamp_method));
|
|
|
|
break;
|
|
|
|
|
2009-09-19 16:49:31 +00:00
|
|
|
case LFUN_BUFFER_CHILD_OPEN:
|
|
|
|
enable = doc_buffer;
|
|
|
|
break;
|
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
case LFUN_BUFFER_WRITE:
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
|
2007-12-04 22:21:25 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-22 21:46:16 +00:00
|
|
|
//FIXME: This LFUN should be moved to GuiApplication.
|
|
|
|
case LFUN_BUFFER_WRITE_ALL: {
|
|
|
|
// We enable the command only if there are some modified buffers
|
|
|
|
Buffer * first = theBufferList().first();
|
|
|
|
enable = false;
|
|
|
|
if (!first)
|
|
|
|
break;
|
|
|
|
Buffer * b = first;
|
|
|
|
// We cannot use a for loop as the buffer list is a cycle.
|
|
|
|
do {
|
|
|
|
if (!b->isClean()) {
|
|
|
|
enable = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
b = theBufferList().next(b);
|
2010-09-07 14:11:28 +00:00
|
|
|
} while (b != first);
|
2009-09-22 21:46:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
case LFUN_BUFFER_WRITE_AS:
|
2011-10-06 13:47:42 +00:00
|
|
|
case LFUN_BUFFER_EXPORT_AS:
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer;
|
2007-12-04 22:21:25 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-19 14:34:46 +00:00
|
|
|
case LFUN_BUFFER_CLOSE:
|
2012-09-15 22:37:55 +00:00
|
|
|
case LFUN_VIEW_CLOSE:
|
2009-09-19 14:34:46 +00:00
|
|
|
enable = doc_buffer;
|
|
|
|
break;
|
|
|
|
|
2009-08-19 21:12:53 +00:00
|
|
|
case LFUN_BUFFER_CLOSE_ALL:
|
|
|
|
enable = theBufferList().last() != theBufferList().first();
|
2009-08-07 00:41:39 +00:00
|
|
|
break;
|
|
|
|
|
2012-09-29 15:33:46 +00:00
|
|
|
case LFUN_VIEW_SPLIT:
|
2008-07-19 13:17:46 +00:00
|
|
|
if (cmd.getArg(0) == "vertical")
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer && (d.splitter_->count() == 1 ||
|
2008-07-19 13:17:46 +00:00
|
|
|
d.splitter_->orientation() == Qt::Vertical);
|
|
|
|
else
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer && (d.splitter_->count() == 1 ||
|
2008-07-19 13:17:46 +00:00
|
|
|
d.splitter_->orientation() == Qt::Horizontal);
|
2008-02-20 21:46:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-09-29 15:16:52 +00:00
|
|
|
case LFUN_TAB_GROUP_CLOSE:
|
2012-07-15 02:13:40 +00:00
|
|
|
enable = d.tabWorkAreaCount() > 1;
|
2008-02-21 14:53:09 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-30 16:07:53 +00:00
|
|
|
case LFUN_TOOLBAR_TOGGLE: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
if (GuiToolbar * t = toolbar(name))
|
2008-05-27 11:15:17 +00:00
|
|
|
flag.setOnOff(t->isVisible());
|
2010-01-30 16:07:53 +00:00
|
|
|
else {
|
|
|
|
enable = false;
|
2010-09-07 14:11:28 +00:00
|
|
|
docstring const msg =
|
2010-01-30 16:07:53 +00:00
|
|
|
bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
|
|
|
|
flag.message(msg);
|
|
|
|
}
|
2007-11-19 20:56:05 +00:00
|
|
|
break;
|
2010-01-30 16:07:53 +00:00
|
|
|
}
|
2007-11-19 20:56:05 +00:00
|
|
|
|
2009-10-04 21:03:37 +00:00
|
|
|
case LFUN_DROP_LAYOUTS_CHOICE:
|
2010-09-07 14:11:28 +00:00
|
|
|
enable = buf;
|
2009-10-04 21:03:37 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-17 14:22:30 +00:00
|
|
|
case LFUN_UI_TOGGLE:
|
|
|
|
flag.setOnOff(isFullScreen());
|
|
|
|
break;
|
|
|
|
|
2009-09-12 21:12:24 +00:00
|
|
|
case LFUN_DIALOG_DISCONNECT_INSET:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_DIALOG_HIDE:
|
|
|
|
// FIXME: should we check if the dialog is shown?
|
|
|
|
break;
|
|
|
|
|
2007-11-19 20:56:05 +00:00
|
|
|
case LFUN_DIALOG_TOGGLE:
|
|
|
|
flag.setOnOff(isDialogVisible(cmd.getArg(0)));
|
|
|
|
// fall through to set "enable"
|
|
|
|
case LFUN_DIALOG_SHOW: {
|
|
|
|
string const name = cmd.getArg(0);
|
2009-09-12 20:55:35 +00:00
|
|
|
if (!doc_buffer)
|
2007-11-19 20:56:05 +00:00
|
|
|
enable = name == "aboutlyx"
|
|
|
|
|| name == "file" //FIXME: should be removed.
|
|
|
|
|| name == "prefs"
|
2009-10-24 15:47:05 +00:00
|
|
|
|| name == "texinfo"
|
2009-12-22 10:04:30 +00:00
|
|
|
|| name == "progress"
|
2009-10-24 15:47:05 +00:00
|
|
|
|| name == "compare";
|
2007-11-19 20:56:05 +00:00
|
|
|
else if (name == "print")
|
2011-05-13 19:39:56 +00:00
|
|
|
enable = doc_buffer->params().isExportable("dvi")
|
2007-11-19 20:56:05 +00:00
|
|
|
&& lyxrc.print_command != "none";
|
2009-08-01 16:55:15 +00:00
|
|
|
else if (name == "character" || name == "symbols") {
|
2010-04-30 08:27:03 +00:00
|
|
|
if (!buf || buf->isReadonly())
|
2007-11-19 20:56:05 +00:00
|
|
|
enable = false;
|
|
|
|
else {
|
2011-01-26 11:04:42 +00:00
|
|
|
Cursor const & cur = currentBufferView()->cursor();
|
|
|
|
enable = !(cur.inTexted() && cur.paragraph().isPassThru());
|
2007-11-19 20:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "latexlog")
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = FileName(doc_buffer->logName()).isReadableFile();
|
2007-11-19 20:56:05 +00:00
|
|
|
else if (name == "spellchecker")
|
2011-12-31 16:29:27 +00:00
|
|
|
enable = theSpellChecker()
|
|
|
|
&& !doc_buffer->isReadonly()
|
|
|
|
&& !doc_buffer->text().empty();
|
2007-11-19 20:56:05 +00:00
|
|
|
else if (name == "vclog")
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer->lyxvc().inUse();
|
2007-11-19 20:56:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_DIALOG_UPDATE: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
if (!buf)
|
|
|
|
enable = name == "prefs";
|
|
|
|
break;
|
|
|
|
}
|
2009-09-19 11:54:23 +00:00
|
|
|
|
|
|
|
case LFUN_COMMAND_EXECUTE:
|
|
|
|
case LFUN_MESSAGE:
|
2009-09-12 21:12:24 +00:00
|
|
|
case LFUN_MENU_OPEN:
|
|
|
|
// Nothing to check.
|
|
|
|
break;
|
2007-11-19 20:56:05 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
case LFUN_COMPLETION_INLINE:
|
|
|
|
if (!d.current_work_area_
|
2010-03-05 18:07:05 +00:00
|
|
|
|| !d.current_work_area_->completer().inlinePossible(
|
2009-09-05 14:29:11 +00:00
|
|
|
currentBufferView()->cursor()))
|
2010-03-05 18:07:05 +00:00
|
|
|
enable = false;
|
2008-02-21 19:42:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_COMPLETION_POPUP:
|
|
|
|
if (!d.current_work_area_
|
2010-03-05 18:07:05 +00:00
|
|
|
|| !d.current_work_area_->completer().popupPossible(
|
2009-09-05 14:29:11 +00:00
|
|
|
currentBufferView()->cursor()))
|
2010-03-05 18:07:05 +00:00
|
|
|
enable = false;
|
2008-02-21 19:42:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_COMPLETION_COMPLETE:
|
|
|
|
if (!d.current_work_area_
|
2009-09-05 14:29:11 +00:00
|
|
|
|| !d.current_work_area_->completer().inlinePossible(
|
|
|
|
currentBufferView()->cursor()))
|
2010-03-05 18:07:05 +00:00
|
|
|
enable = false;
|
2008-02-21 19:42:34 +00:00
|
|
|
break;
|
|
|
|
|
2008-09-08 00:24:47 +00:00
|
|
|
case LFUN_COMPLETION_ACCEPT:
|
2008-11-16 16:34:16 +00:00
|
|
|
if (!d.current_work_area_
|
2010-03-05 18:07:05 +00:00
|
|
|
|| (!d.current_work_area_->completer().popupVisible()
|
2008-11-16 16:34:16 +00:00
|
|
|
&& !d.current_work_area_->completer().inlineVisible()
|
|
|
|
&& !d.current_work_area_->completer().completionAvailable()))
|
|
|
|
enable = false;
|
|
|
|
break;
|
|
|
|
|
2009-04-04 09:14:38 +00:00
|
|
|
case LFUN_COMPLETION_CANCEL:
|
2008-09-08 00:13:55 +00:00
|
|
|
if (!d.current_work_area_
|
2010-03-05 18:07:05 +00:00
|
|
|
|| (!d.current_work_area_->completer().popupVisible()
|
2008-09-08 00:13:55 +00:00
|
|
|
&& !d.current_work_area_->completer().inlineVisible()))
|
|
|
|
enable = false;
|
|
|
|
break;
|
|
|
|
|
2009-04-04 09:14:38 +00:00
|
|
|
case LFUN_BUFFER_ZOOM_OUT:
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer && lyxrc.zoom > 10;
|
2009-04-04 09:14:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_ZOOM_IN:
|
2009-09-12 20:55:35 +00:00
|
|
|
enable = doc_buffer;
|
2009-04-04 09:14:38 +00:00
|
|
|
break;
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2009-09-12 21:12:24 +00:00
|
|
|
case LFUN_BUFFER_NEXT:
|
|
|
|
case LFUN_BUFFER_PREVIOUS:
|
|
|
|
// FIXME: should we check is there is an previous or next buffer?
|
|
|
|
break;
|
2009-09-09 05:49:51 +00:00
|
|
|
case LFUN_BUFFER_SWITCH:
|
|
|
|
// toggle on the current buffer, but do not toggle off
|
|
|
|
// the other ones (is that a good idea?)
|
2009-09-12 20:41:24 +00:00
|
|
|
if (doc_buffer
|
|
|
|
&& to_utf8(cmd.argument()) == doc_buffer->absFileName())
|
2009-09-09 05:49:51 +00:00
|
|
|
flag.setOnOff(true);
|
|
|
|
break;
|
2009-04-04 09:14:38 +00:00
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_REGISTER:
|
|
|
|
enable = doc_buffer && !doc_buffer->lyxvc().inUse();
|
|
|
|
break;
|
2013-02-05 20:31:58 +00:00
|
|
|
case LFUN_VC_RENAME:
|
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().renameEnabled();
|
|
|
|
break;
|
|
|
|
case LFUN_VC_COPY:
|
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().copyEnabled();
|
|
|
|
break;
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_CHECK_IN:
|
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().checkInEnabled();
|
|
|
|
break;
|
|
|
|
case LFUN_VC_CHECK_OUT:
|
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().checkOutEnabled();
|
|
|
|
break;
|
|
|
|
case LFUN_VC_LOCKING_TOGGLE:
|
|
|
|
enable = doc_buffer && !doc_buffer->isReadonly()
|
|
|
|
&& doc_buffer->lyxvc().lockingToggleEnabled();
|
2010-02-12 07:21:11 +00:00
|
|
|
flag.setOnOff(enable && doc_buffer->lyxvc().locking());
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
case LFUN_VC_REVERT:
|
2010-10-08 05:30:07 +00:00
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().inUse() && !doc_buffer->isReadonly();
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
case LFUN_VC_UNDO_LAST:
|
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
|
|
|
|
break;
|
2009-10-14 19:18:06 +00:00
|
|
|
case LFUN_VC_REPO_UPDATE:
|
2010-10-08 05:30:07 +00:00
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().repoUpdateEnabled();
|
2009-10-06 23:20:52 +00:00
|
|
|
break;
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_COMMAND: {
|
|
|
|
if (cmd.argument().empty())
|
|
|
|
enable = false;
|
|
|
|
if (!doc_buffer && contains(cmd.getArg(0), 'D'))
|
|
|
|
enable = false;
|
|
|
|
break;
|
|
|
|
}
|
2010-02-12 14:09:44 +00:00
|
|
|
case LFUN_VC_COMPARE:
|
2010-09-07 11:28:57 +00:00
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().prepareFileRevisionEnabled();
|
2010-02-12 14:09:44 +00:00
|
|
|
break;
|
2009-09-12 20:41:24 +00:00
|
|
|
|
2009-09-23 13:45:58 +00:00
|
|
|
case LFUN_SERVER_GOTO_FILE_ROW:
|
2010-04-16 08:09:07 +00:00
|
|
|
break;
|
2010-04-15 13:19:48 +00:00
|
|
|
case LFUN_FORWARD_SEARCH:
|
2010-04-16 08:09:07 +00:00
|
|
|
enable = !(lyxrc.forward_search_dvi.empty() && lyxrc.forward_search_pdf.empty());
|
2009-09-23 13:45:58 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-05 13:12:57 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2011-12-05 13:41:15 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
|
|
|
enable = documentBufferView() && documentBufferView()->cursor().inTexted();
|
2011-12-05 13:12:57 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-19 20:56:05 +00:00
|
|
|
default:
|
2008-05-22 15:01:36 +00:00
|
|
|
return false;
|
2007-11-19 20:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!enable)
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(false);
|
2007-11-19 20:56:05 +00:00
|
|
|
|
2008-05-22 15:01:36 +00:00
|
|
|
return true;
|
2007-11-19 20:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-07 11:57:13 +00:00
|
|
|
static FileName selectTemplateFile()
|
|
|
|
{
|
2008-03-05 23:10:53 +00:00
|
|
|
FileDialog dlg(qt_("Select template file"));
|
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
2010-10-08 05:34:48 +00:00
|
|
|
dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
|
2007-12-07 11:57:13 +00:00
|
|
|
|
2008-04-20 19:56:01 +00:00
|
|
|
FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
|
2010-03-05 18:07:05 +00:00
|
|
|
QStringList(qt_("LyX Documents (*.lyx)")));
|
2007-12-07 11:57:13 +00:00
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
return FileName();
|
2008-03-05 23:10:53 +00:00
|
|
|
if (result.second.isEmpty())
|
2007-12-07 11:57:13 +00:00
|
|
|
return FileName();
|
2008-03-05 23:10:53 +00:00
|
|
|
return FileName(fromqstr(result.second));
|
2007-12-07 11:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-17 16:09:26 +00:00
|
|
|
Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
|
2008-02-06 23:02:57 +00:00
|
|
|
{
|
|
|
|
setBusy(true);
|
|
|
|
|
2010-10-19 10:42:54 +00:00
|
|
|
Buffer * newBuffer = 0;
|
|
|
|
try {
|
|
|
|
newBuffer = checkAndLoadLyXFile(filename);
|
|
|
|
} catch (ExceptionMessage const & e) {
|
|
|
|
setBusy(false);
|
|
|
|
throw(e);
|
|
|
|
}
|
2011-03-19 19:20:42 +00:00
|
|
|
setBusy(false);
|
2008-02-06 23:02:57 +00:00
|
|
|
|
|
|
|
if (!newBuffer) {
|
|
|
|
message(_("Document not loaded."));
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2008-02-06 23:02:57 +00:00
|
|
|
setBuffer(newBuffer);
|
2011-06-08 13:04:30 +00:00
|
|
|
newBuffer->errors("Parse");
|
2008-02-06 23:02:57 +00:00
|
|
|
|
|
|
|
if (tolastfiles)
|
2008-07-14 08:35:00 +00:00
|
|
|
theSession().lastFiles().add(filename);
|
2008-02-06 23:02:57 +00:00
|
|
|
|
|
|
|
return newBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::openDocument(string const & fname)
|
|
|
|
{
|
|
|
|
string initpath = lyxrc.document_path;
|
|
|
|
|
2009-09-05 15:09:45 +00:00
|
|
|
if (documentBufferView()) {
|
|
|
|
string const trypath = documentBufferView()->buffer().filePath();
|
2008-02-06 23:02:57 +00:00
|
|
|
// If directory is writeable, use this as default.
|
|
|
|
if (FileName(trypath).isDirWritable())
|
|
|
|
initpath = trypath;
|
|
|
|
}
|
|
|
|
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
if (fname.empty()) {
|
2008-03-05 23:10:53 +00:00
|
|
|
FileDialog dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
|
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
|
|
|
dlg.setButton2(qt_("Examples|#E#e"),
|
2010-04-21 01:19:09 +00:00
|
|
|
toqstr(addPath(package().system_support().absFileName(), "examples")));
|
2008-02-06 23:02:57 +00:00
|
|
|
|
2008-07-10 12:44:50 +00:00
|
|
|
QStringList filter(qt_("LyX Documents (*.lyx)"));
|
|
|
|
filter << qt_("LyX-1.3.x Documents (*.lyx13)")
|
|
|
|
<< qt_("LyX-1.4.x Documents (*.lyx14)")
|
2008-11-30 19:14:34 +00:00
|
|
|
<< qt_("LyX-1.5.x Documents (*.lyx15)")
|
|
|
|
<< qt_("LyX-1.6.x Documents (*.lyx16)");
|
2008-02-06 23:02:57 +00:00
|
|
|
FileDialog::Result result =
|
2008-07-10 12:44:50 +00:00
|
|
|
dlg.open(toqstr(initpath), filter);
|
2008-02-06 23:02:57 +00:00
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
return;
|
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
filename = fromqstr(result.second);
|
2008-02-06 23:02:57 +00:00
|
|
|
|
|
|
|
// check selected filename
|
|
|
|
if (filename.empty()) {
|
|
|
|
message(_("Canceled."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
filename = fname;
|
|
|
|
|
|
|
|
// get absolute path of file and add ".lyx" to the filename if
|
2010-09-07 14:11:28 +00:00
|
|
|
// necessary.
|
|
|
|
FileName const fullname =
|
2008-02-06 23:02:57 +00:00
|
|
|
fileSearch(string(), filename, "lyx", support::may_not_exist);
|
|
|
|
if (!fullname.empty())
|
2010-04-21 01:19:09 +00:00
|
|
|
filename = fullname.absFileName();
|
2008-02-06 23:02:57 +00:00
|
|
|
|
2008-09-08 15:46:23 +00:00
|
|
|
if (!fullname.onlyPath().isDirectory()) {
|
|
|
|
Alert::warning(_("Invalid filename"),
|
2009-05-02 08:43:22 +00:00
|
|
|
bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
|
2010-04-21 01:19:09 +00:00
|
|
|
from_utf8(fullname.absFileName())));
|
2008-09-08 15:46:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-04-09 19:38:28 +00:00
|
|
|
|
2010-09-07 14:11:28 +00:00
|
|
|
// if the file doesn't exist and isn't already open (bug 6645),
|
2010-04-09 19:38:28 +00:00
|
|
|
// let the user create one
|
2012-11-15 21:01:19 +00:00
|
|
|
if (!fullname.exists() && !theBufferList().exists(fullname) &&
|
|
|
|
!LyXVC::file_not_found_hook(fullname)) {
|
2008-02-06 23:02:57 +00:00
|
|
|
// the user specifically chose this name. Believe him.
|
|
|
|
Buffer * const b = newFile(filename, string(), true);
|
|
|
|
if (b)
|
|
|
|
setBuffer(b);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
docstring const disp_fn = makeDisplayPath(filename);
|
|
|
|
message(bformat(_("Opening document %1$s..."), disp_fn));
|
|
|
|
|
|
|
|
docstring str2;
|
|
|
|
Buffer * buf = loadDocument(fullname);
|
|
|
|
if (buf) {
|
|
|
|
str2 = bformat(_("Document %1$s opened."), disp_fn);
|
2008-07-29 11:55:27 +00:00
|
|
|
if (buf->lyxvc().inUse())
|
2008-07-29 13:25:07 +00:00
|
|
|
str2 += " " + from_utf8(buf->lyxvc().versionString()) +
|
|
|
|
" " + _("Version control detected.");
|
2008-02-06 23:02:57 +00:00
|
|
|
} else {
|
|
|
|
str2 = bformat(_("Could not open document %1$s"), disp_fn);
|
|
|
|
}
|
|
|
|
message(str2);
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:54:13 +00:00
|
|
|
// FIXME: clean that
|
2008-02-07 09:51:49 +00:00
|
|
|
static bool import(GuiView * lv, FileName const & filename,
|
|
|
|
string const & format, ErrorList & errorList)
|
2008-02-06 23:54:13 +00:00
|
|
|
{
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const lyxfile(support::changeExtension(filename.absFileName(), ".lyx"));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
|
|
|
string loader_format;
|
|
|
|
vector<string> loaders = theConverters().loaders();
|
|
|
|
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
|
2012-05-23 12:53:14 +00:00
|
|
|
vector<string>::const_iterator it = loaders.begin();
|
|
|
|
vector<string>::const_iterator en = loaders.end();
|
|
|
|
for (; it != en; ++it) {
|
2008-02-07 09:51:49 +00:00
|
|
|
if (!theConverters().isReachable(format, *it))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
string const tofile =
|
2010-04-21 01:19:09 +00:00
|
|
|
support::changeExtension(filename.absFileName(),
|
2008-02-07 09:51:49 +00:00
|
|
|
formats.extension(*it));
|
|
|
|
if (!theConverters().convert(0, filename, FileName(tofile),
|
|
|
|
filename, format, *it, errorList))
|
|
|
|
return false;
|
|
|
|
loader_format = *it;
|
|
|
|
break;
|
2008-02-06 23:54:13 +00:00
|
|
|
}
|
|
|
|
if (loader_format.empty()) {
|
|
|
|
frontend::Alert::error(_("Couldn't import file"),
|
2010-03-05 18:07:05 +00:00
|
|
|
bformat(_("No information for importing the format %1$s."),
|
2008-02-06 23:54:13 +00:00
|
|
|
formats.prettyName(format)));
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-07 09:51:49 +00:00
|
|
|
} else
|
2008-02-06 23:54:13 +00:00
|
|
|
loader_format = format;
|
|
|
|
|
|
|
|
if (loader_format == "lyx") {
|
|
|
|
Buffer * buf = lv->loadDocument(lyxfile);
|
2008-02-07 09:51:49 +00:00
|
|
|
if (!buf)
|
2008-02-06 23:54:13 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2010-04-21 01:19:09 +00:00
|
|
|
Buffer * const b = newFile(lyxfile.absFileName(), string(), true);
|
2008-02-07 09:51:49 +00:00
|
|
|
if (!b)
|
2008-02-06 23:54:13 +00:00
|
|
|
return false;
|
2008-02-07 09:51:49 +00:00
|
|
|
lv->setBuffer(b);
|
2008-02-06 23:54:13 +00:00
|
|
|
bool as_paragraphs = loader_format == "textparagraph";
|
2010-04-21 01:19:09 +00:00
|
|
|
string filename2 = (loader_format == format) ? filename.absFileName()
|
|
|
|
: support::changeExtension(filename.absFileName(),
|
2008-02-06 23:54:13 +00:00
|
|
|
formats.extension(loader_format));
|
2009-09-05 14:29:11 +00:00
|
|
|
lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
|
|
|
|
as_paragraphs);
|
2009-09-22 21:25:32 +00:00
|
|
|
guiApp->setCurrentView(lv);
|
2008-02-06 23:54:13 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::importDocument(string const & argument)
|
|
|
|
{
|
|
|
|
string format;
|
|
|
|
string filename = split(argument, format, ' ');
|
|
|
|
|
|
|
|
LYXERR(Debug::INFO, format << " file: " << filename);
|
|
|
|
|
|
|
|
// need user interaction
|
|
|
|
if (filename.empty()) {
|
|
|
|
string initpath = lyxrc.document_path;
|
2009-09-05 15:09:45 +00:00
|
|
|
if (documentBufferView()) {
|
|
|
|
string const trypath = documentBufferView()->buffer().filePath();
|
2008-02-06 23:54:13 +00:00
|
|
|
// If directory is writeable, use this as default.
|
|
|
|
if (FileName(trypath).isDirWritable())
|
|
|
|
initpath = trypath;
|
|
|
|
}
|
|
|
|
|
|
|
|
docstring const text = bformat(_("Select %1$s file to import"),
|
|
|
|
formats.prettyName(format));
|
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
|
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
|
|
|
dlg.setButton2(qt_("Examples|#E#e"),
|
2010-04-21 01:19:09 +00:00
|
|
|
toqstr(addPath(package().system_support().absFileName(), "examples")));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
|
|
|
docstring filter = formats.prettyName(format);
|
2011-09-17 11:04:55 +00:00
|
|
|
filter += " (*.{";
|
2008-02-06 23:54:13 +00:00
|
|
|
// FIXME UNICODE
|
2011-09-17 11:04:55 +00:00
|
|
|
filter += from_utf8(formats.extensions(format));
|
|
|
|
filter += "})";
|
2008-02-06 23:54:13 +00:00
|
|
|
|
|
|
|
FileDialog::Result result =
|
2008-04-20 19:56:01 +00:00
|
|
|
dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
return;
|
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
filename = fromqstr(result.second);
|
2008-02-06 23:54:13 +00:00
|
|
|
|
|
|
|
// check selected filename
|
|
|
|
if (filename.empty())
|
|
|
|
message(_("Canceled."));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// get absolute path of file
|
2008-04-21 06:53:00 +00:00
|
|
|
FileName const fullname(support::makeAbsPath(filename));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const lyxfile(support::changeExtension(fullname.absFileName(), ".lyx"));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
|
|
|
// Check if the document already is open
|
2008-07-29 08:16:09 +00:00
|
|
|
Buffer * buf = theBufferList().getBuffer(lyxfile);
|
2008-02-06 23:54:13 +00:00
|
|
|
if (buf) {
|
|
|
|
setBuffer(buf);
|
|
|
|
if (!closeBuffer()) {
|
|
|
|
message(_("Canceled."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
docstring const displaypath = makeDisplayPath(lyxfile.absFileName(), 30);
|
2008-02-07 09:51:49 +00:00
|
|
|
|
2008-02-06 23:54:13 +00:00
|
|
|
// if the file exists already, and we didn't do
|
|
|
|
// -i lyx thefile.lyx, warn
|
|
|
|
if (lyxfile.exists() && fullname != lyxfile) {
|
|
|
|
|
|
|
|
docstring text = bformat(_("The document %1$s already exists.\n\n"
|
2008-02-07 09:51:49 +00:00
|
|
|
"Do you want to overwrite that document?"), displaypath);
|
2008-02-06 23:54:13 +00:00
|
|
|
int const ret = Alert::prompt(_("Overwrite document?"),
|
|
|
|
text, 0, 1, _("&Overwrite"), _("&Cancel"));
|
|
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
message(_("Canceled."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-07 09:51:49 +00:00
|
|
|
message(bformat(_("Importing %1$s..."), displaypath));
|
2008-02-06 23:54:13 +00:00
|
|
|
ErrorList errorList;
|
2008-02-07 09:51:49 +00:00
|
|
|
if (import(this, fullname, format, errorList))
|
|
|
|
message(_("imported."));
|
|
|
|
else
|
|
|
|
message(_("file not imported!"));
|
|
|
|
|
2008-02-06 23:54:13 +00:00
|
|
|
// FIXME (Abdel 12/08/06): Is there a need to display the error list here?
|
|
|
|
}
|
|
|
|
|
2008-02-06 23:02:57 +00:00
|
|
|
|
2007-12-07 11:57:13 +00:00
|
|
|
void GuiView::newDocument(string const & filename, bool from_template)
|
|
|
|
{
|
2007-12-07 22:28:03 +00:00
|
|
|
FileName initpath(lyxrc.document_path);
|
2009-09-05 15:09:45 +00:00
|
|
|
if (documentBufferView()) {
|
|
|
|
FileName const trypath(documentBufferView()->buffer().filePath());
|
2007-12-07 11:57:13 +00:00
|
|
|
// If directory is writeable, use this as default.
|
|
|
|
if (trypath.isDirWritable())
|
|
|
|
initpath = trypath;
|
2007-12-07 22:28:03 +00:00
|
|
|
}
|
2007-12-07 11:57:13 +00:00
|
|
|
|
2009-01-08 00:29:06 +00:00
|
|
|
string templatefile;
|
|
|
|
if (from_template) {
|
2010-04-21 01:19:09 +00:00
|
|
|
templatefile = selectTemplateFile().absFileName();
|
2009-01-08 00:29:06 +00:00
|
|
|
if (templatefile.empty())
|
|
|
|
return;
|
|
|
|
}
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2007-12-07 11:57:13 +00:00
|
|
|
Buffer * b;
|
|
|
|
if (filename.empty())
|
2009-10-24 14:20:00 +00:00
|
|
|
b = newUnnamedFile(initpath, to_utf8(_("newfile")), templatefile);
|
2007-12-07 11:57:13 +00:00
|
|
|
else
|
|
|
|
b = newFile(filename, templatefile, true);
|
|
|
|
|
|
|
|
if (b)
|
|
|
|
setBuffer(b);
|
2009-01-05 09:56:37 +00:00
|
|
|
|
2010-09-07 14:11:28 +00:00
|
|
|
// If no new document could be created, it is unsure
|
2009-01-05 09:56:37 +00:00
|
|
|
// whether there is a valid BufferView.
|
2009-09-05 14:29:11 +00:00
|
|
|
if (currentBufferView())
|
2009-01-05 09:56:37 +00:00
|
|
|
// Ensure the cursor is correctly positioned on screen.
|
2009-09-05 14:29:11 +00:00
|
|
|
currentBufferView()->showCursor();
|
2007-12-07 11:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
void GuiView::insertLyXFile(docstring const & fname)
|
|
|
|
{
|
2009-09-05 14:29:11 +00:00
|
|
|
BufferView * bv = documentBufferView();
|
2007-12-02 17:50:08 +00:00
|
|
|
if (!bv)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
FileName filename(to_utf8(fname));
|
2010-10-29 16:51:50 +00:00
|
|
|
if (filename.empty()) {
|
|
|
|
// Launch a file browser
|
|
|
|
// FIXME UNICODE
|
|
|
|
string initpath = lyxrc.document_path;
|
|
|
|
string const trypath = bv->buffer().filePath();
|
|
|
|
// If directory is writeable, use this as default.
|
|
|
|
if (FileName(trypath).isDirWritable())
|
|
|
|
initpath = trypath;
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2010-10-29 16:51:50 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
|
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
|
|
|
dlg.setButton2(qt_("Examples|#E#e"),
|
|
|
|
toqstr(addPath(package().system_support().absFileName(),
|
|
|
|
"examples")));
|
2007-12-02 17:50:08 +00:00
|
|
|
|
2010-10-29 16:51:50 +00:00
|
|
|
FileDialog::Result result = dlg.open(toqstr(initpath),
|
|
|
|
QStringList(qt_("LyX Documents (*.lyx)")));
|
2007-12-02 17:50:08 +00:00
|
|
|
|
2010-10-29 16:51:50 +00:00
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
return;
|
2007-12-02 17:50:08 +00:00
|
|
|
|
2010-10-29 16:51:50 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
filename.set(fromqstr(result.second));
|
2007-12-02 17:50:08 +00:00
|
|
|
|
2010-10-29 16:51:50 +00:00
|
|
|
// check selected filename
|
|
|
|
if (filename.empty()) {
|
|
|
|
// emit message signal.
|
|
|
|
message(_("Canceled."));
|
|
|
|
return;
|
|
|
|
}
|
2007-12-02 17:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bv->insertLyXFile(filename);
|
2010-10-29 16:51:50 +00:00
|
|
|
bv->buffer().errors("Parse");
|
2007-12-02 17:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-05 20:31:58 +00:00
|
|
|
bool GuiView::renameBuffer(Buffer & b, docstring const & newname, RenameKind kind)
|
2007-12-04 22:21:25 +00:00
|
|
|
{
|
|
|
|
FileName fname = b.fileName();
|
|
|
|
FileName const oldname = fname;
|
|
|
|
|
|
|
|
if (!newname.empty()) {
|
|
|
|
// FIXME UNICODE
|
2010-04-21 01:19:09 +00:00
|
|
|
fname = support::makeAbsPath(to_utf8(newname), oldname.onlyPath().absFileName());
|
2007-12-04 22:21:25 +00:00
|
|
|
} else {
|
|
|
|
// Switch to this Buffer.
|
|
|
|
setBuffer(&b);
|
|
|
|
|
2009-04-04 03:10:54 +00:00
|
|
|
// No argument? Ask user through dialog.
|
2007-12-04 22:21:25 +00:00
|
|
|
// FIXME UNICODE
|
2008-03-05 23:10:53 +00:00
|
|
|
FileDialog dlg(qt_("Choose a filename to save document as"),
|
2007-12-04 22:21:25 +00:00
|
|
|
LFUN_BUFFER_WRITE_AS);
|
2008-03-05 23:10:53 +00:00
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
|
|
|
dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
|
2007-12-04 22:21:25 +00:00
|
|
|
|
2010-04-21 01:19:31 +00:00
|
|
|
if (!isLyXFileName(fname.absFileName()))
|
2007-12-04 22:21:25 +00:00
|
|
|
fname.changeExtension(".lyx");
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2010-04-21 01:19:09 +00:00
|
|
|
dlg.save(toqstr(fname.onlyPath().absFileName()),
|
2010-03-05 18:07:05 +00:00
|
|
|
QStringList(qt_("LyX Documents (*.lyx)")),
|
|
|
|
toqstr(fname.onlyFileName()));
|
2007-12-04 22:21:25 +00:00
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
return false;
|
|
|
|
|
2008-03-05 23:10:53 +00:00
|
|
|
fname.set(fromqstr(result.second));
|
2007-12-04 22:21:25 +00:00
|
|
|
|
|
|
|
if (fname.empty())
|
|
|
|
return false;
|
|
|
|
|
2010-04-21 01:19:31 +00:00
|
|
|
if (!isLyXFileName(fname.absFileName()))
|
2007-12-04 22:21:25 +00:00
|
|
|
fname.changeExtension(".lyx");
|
|
|
|
}
|
|
|
|
|
2010-03-09 03:25:47 +00:00
|
|
|
// fname is now the new Buffer location.
|
2011-12-07 20:35:29 +00:00
|
|
|
|
|
|
|
// if there is already a Buffer open with this name, we do not want
|
2011-12-13 19:18:09 +00:00
|
|
|
// to have another one. (the second test makes sure we're not just
|
|
|
|
// trying to overwrite ourselves, which is fine.)
|
2012-05-14 13:26:51 +00:00
|
|
|
if (theBufferList().exists(fname) && fname != oldname
|
|
|
|
&& theBufferList().getBuffer(fname) != &b) {
|
2013-02-04 20:40:28 +00:00
|
|
|
docstring const text =
|
2011-12-07 20:35:29 +00:00
|
|
|
bformat(_("The file\n%1$s\nis already open in your current session.\n"
|
|
|
|
"Please close it before attempting to overwrite it.\n"
|
|
|
|
"Do you want to choose a new filename?"),
|
|
|
|
from_utf8(fname.absFileName()));
|
|
|
|
int const ret = Alert::prompt(_("Chosen File Already Open"),
|
|
|
|
text, 0, 1, _("&Rename"), _("&Cancel"));
|
|
|
|
switch (ret) {
|
2013-02-05 20:31:58 +00:00
|
|
|
case 0: return renameBuffer(b, docstring(), kind);
|
2011-12-07 20:35:29 +00:00
|
|
|
case 1: return false;
|
|
|
|
}
|
|
|
|
//return false;
|
|
|
|
}
|
2013-02-05 20:31:58 +00:00
|
|
|
|
|
|
|
bool const existsLocal = fname.exists();
|
|
|
|
bool const existsInVC = LyXVC::fileInVC(fname);
|
|
|
|
if (existsLocal || existsInVC) {
|
2010-04-21 01:19:09 +00:00
|
|
|
docstring const file = makeDisplayPath(fname.absFileName(), 30);
|
2013-02-05 20:31:58 +00:00
|
|
|
if (kind != LV_WRITE_AS && existsInVC) {
|
|
|
|
// renaming to a name that is already in VC
|
|
|
|
// would not work
|
|
|
|
docstring text = bformat(_("The document %1$s "
|
|
|
|
"is already registered.\n\n"
|
|
|
|
"Do you want to choose a new name?"),
|
|
|
|
file);
|
|
|
|
docstring const title = (kind == LV_VC_RENAME) ?
|
|
|
|
_("Rename document?") : _("Copy document?");
|
|
|
|
docstring const button = (kind == LV_VC_RENAME) ?
|
|
|
|
_("&Rename") : _("&Copy");
|
|
|
|
int const ret = Alert::prompt(title, text, 0, 1,
|
|
|
|
button, _("&Cancel"));
|
|
|
|
switch (ret) {
|
|
|
|
case 0: return renameBuffer(b, docstring(), kind);
|
|
|
|
case 1: return false;
|
|
|
|
}
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
2013-02-05 20:31:58 +00:00
|
|
|
|
|
|
|
if (existsLocal) {
|
|
|
|
docstring text = bformat(_("The document %1$s "
|
|
|
|
"already exists.\n\n"
|
|
|
|
"Do you want to overwrite that document?"),
|
|
|
|
file);
|
|
|
|
int const ret = Alert::prompt(_("Overwrite document?"),
|
|
|
|
text, 0, 2, _("&Overwrite"),
|
|
|
|
_("&Rename"), _("&Cancel"));
|
|
|
|
switch (ret) {
|
|
|
|
case 0: break;
|
|
|
|
case 1: return renameBuffer(b, docstring(), kind);
|
|
|
|
case 2: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (kind) {
|
|
|
|
case LV_VC_RENAME: {
|
|
|
|
string msg = b.lyxvc().rename(fname);
|
|
|
|
if (msg.empty())
|
|
|
|
return false;
|
|
|
|
message(from_utf8(msg));
|
|
|
|
break;
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
2013-02-05 20:31:58 +00:00
|
|
|
case LV_VC_COPY: {
|
|
|
|
string msg = b.lyxvc().copy(fname);
|
|
|
|
if (msg.empty())
|
|
|
|
return false;
|
|
|
|
message(from_utf8(msg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LV_WRITE_AS:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// LyXVC created the file already in case of LV_VC_RENAME or
|
|
|
|
// LV_VC_COPY, but call saveBuffer() nevertheless to get
|
|
|
|
// relative paths of included stuff right if we moved e.g. from
|
|
|
|
// /a/b.lyx to /a/c/b.lyx.
|
2007-12-04 22:21:25 +00:00
|
|
|
|
2012-01-13 03:31:01 +00:00
|
|
|
bool const saved = saveBuffer(b, fname);
|
|
|
|
if (saved)
|
2012-07-18 08:31:47 +00:00
|
|
|
b.reload(false);
|
2012-01-13 03:31:01 +00:00
|
|
|
return saved;
|
2010-11-07 21:26:02 +00:00
|
|
|
}
|
2010-10-24 17:14:10 +00:00
|
|
|
|
2010-03-09 03:25:47 +00:00
|
|
|
|
2011-10-07 08:21:31 +00:00
|
|
|
struct PrettyNameComparator
|
|
|
|
{
|
|
|
|
bool operator()(Format const *first, Format const *second) const {
|
|
|
|
return compare_ascii_no_case(first->prettyname(), second->prettyname()) <= 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-10-06 13:47:42 +00:00
|
|
|
bool GuiView::exportBufferAs(Buffer & b)
|
|
|
|
{
|
|
|
|
FileName fname = b.fileName();
|
|
|
|
|
|
|
|
FileDialog dlg(qt_("Choose a filename to export the document as"));
|
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
|
|
|
|
|
|
|
QStringList types;
|
|
|
|
types << "Any supported format (*.*)";
|
|
|
|
Formats::const_iterator it = formats.begin();
|
2011-10-07 08:21:31 +00:00
|
|
|
vector<Format const *> export_formats;
|
2011-10-06 13:47:42 +00:00
|
|
|
for (; it != formats.end(); ++it)
|
2011-10-07 08:21:31 +00:00
|
|
|
if (it->documentFormat() && it->inExportMenu())
|
|
|
|
export_formats.push_back(&(*it));
|
|
|
|
PrettyNameComparator cmp;
|
|
|
|
sort(export_formats.begin(), export_formats.end(), cmp);
|
|
|
|
vector<Format const *>::const_iterator fit = export_formats.begin();
|
|
|
|
for (; fit != export_formats.end(); ++fit)
|
|
|
|
types << toqstr((*fit)->prettyname() + " (*." + (*fit)->extension() + ")");
|
2011-10-06 13:47:42 +00:00
|
|
|
QString filter;
|
|
|
|
FileDialog::Result result =
|
|
|
|
dlg.save(toqstr(fname.onlyPath().absFileName()),
|
|
|
|
types,
|
|
|
|
toqstr(fname.onlyFileName()),
|
2011-10-15 13:41:15 +00:00
|
|
|
&filter);
|
2011-10-06 13:47:42 +00:00
|
|
|
if (result.first != FileDialog::Chosen)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string s = fromqstr(filter);
|
2011-10-07 08:21:31 +00:00
|
|
|
size_t pos = s.find(" (*.");
|
2011-10-06 13:47:42 +00:00
|
|
|
LASSERT(pos != string::npos, /**/);
|
2011-10-07 08:21:31 +00:00
|
|
|
string fmt_prettyname = s.substr(0, pos);
|
|
|
|
string fmt_name;
|
2011-10-06 13:47:42 +00:00
|
|
|
fname.set(fromqstr(result.second));
|
2011-10-07 08:21:31 +00:00
|
|
|
if (fmt_prettyname == "Any supported format")
|
2011-10-06 13:47:42 +00:00
|
|
|
fmt_name = formats.getFormatFromExtension(fname.extension());
|
2011-10-07 08:21:31 +00:00
|
|
|
else
|
|
|
|
fmt_name = formats.getFormatFromPrettyName(fmt_prettyname);
|
|
|
|
LYXERR(Debug::FILES, "fmt_prettyname=" << fmt_prettyname
|
|
|
|
<< ", fmt_name=" << fmt_name << ", fname=" << fname.absFileName());
|
2011-10-06 13:47:42 +00:00
|
|
|
|
2011-10-07 08:21:31 +00:00
|
|
|
if (fmt_name.empty() || fname.empty())
|
2011-10-06 13:47:42 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// fname is now the new Buffer location.
|
|
|
|
if (FileName(fname).exists()) {
|
|
|
|
docstring const file = makeDisplayPath(fname.absFileName(), 30);
|
|
|
|
docstring text = bformat(_("The document %1$s already "
|
|
|
|
"exists.\n\nDo you want to "
|
|
|
|
"overwrite that document?"),
|
|
|
|
file);
|
|
|
|
int const ret = Alert::prompt(_("Overwrite document?"),
|
|
|
|
text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
|
|
|
|
switch (ret) {
|
|
|
|
case 0: break;
|
|
|
|
case 1: return exportBufferAs(b);
|
|
|
|
case 2: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FuncRequest cmd(LFUN_BUFFER_EXPORT, fmt_name + " " + fname.absFileName());
|
|
|
|
DispatchResult dr;
|
|
|
|
dispatch(cmd, dr);
|
|
|
|
return dr.dispatched();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 20:40:28 +00:00
|
|
|
bool GuiView::saveBuffer(Buffer & b)
|
|
|
|
{
|
2010-11-07 21:26:02 +00:00
|
|
|
return saveBuffer(b, FileName());
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-07 21:26:02 +00:00
|
|
|
bool GuiView::saveBuffer(Buffer & b, FileName const & fn)
|
2007-12-04 22:21:25 +00:00
|
|
|
{
|
2008-11-16 01:20:34 +00:00
|
|
|
if (workArea(b) && workArea(b)->inDialogMode())
|
|
|
|
return true;
|
|
|
|
|
2010-11-07 21:26:02 +00:00
|
|
|
if (fn.empty() && b.isUnnamed())
|
2013-02-04 20:40:28 +00:00
|
|
|
return renameBuffer(b, docstring());
|
2007-12-04 22:21:25 +00:00
|
|
|
|
2013-03-18 21:01:09 +00:00
|
|
|
bool const success = (fn.empty() ? b.save() : b.saveAs(fn));
|
2010-11-07 21:26:02 +00:00
|
|
|
if (success) {
|
2008-07-14 08:35:00 +00:00
|
|
|
theSession().lastFiles().add(b.fileName());
|
2007-12-04 22:21:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switch to this Buffer.
|
|
|
|
setBuffer(&b);
|
|
|
|
|
|
|
|
// FIXME: we don't tell the user *WHY* the save failed !!
|
|
|
|
docstring const file = makeDisplayPath(b.absFileName(), 30);
|
|
|
|
docstring text = bformat(_("The document %1$s could not be saved.\n\n"
|
|
|
|
"Do you want to rename the document and "
|
|
|
|
"try again?"), file);
|
|
|
|
int const ret = Alert::prompt(_("Rename and save?"),
|
|
|
|
text, 0, 2, _("&Rename"), _("&Retry"), _("&Cancel"));
|
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
|
|
|
if (!renameBuffer(b, docstring()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
2008-01-17 19:01:01 +00:00
|
|
|
case 2:
|
|
|
|
return false;
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
2013-02-05 20:31:58 +00:00
|
|
|
return saveBuffer(b, fn);
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-15 14:07:05 +00:00
|
|
|
bool GuiView::hideWorkArea(GuiWorkArea * wa)
|
2009-08-14 23:12:21 +00:00
|
|
|
{
|
2009-08-15 21:29:14 +00:00
|
|
|
return closeWorkArea(wa, false);
|
2009-08-14 23:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-15 22:37:55 +00:00
|
|
|
// We only want to close the buffer if it is not visible in other workareas
|
|
|
|
// of the same view, nor in other views, and if this is not a child
|
2009-08-17 22:33:49 +00:00
|
|
|
bool GuiView::closeWorkArea(GuiWorkArea * wa)
|
|
|
|
{
|
2009-08-18 00:04:19 +00:00
|
|
|
Buffer & buf = wa->bufferView().buffer();
|
2012-09-15 22:37:55 +00:00
|
|
|
|
|
|
|
bool last_wa = d.countWorkAreasOf(buf) == 1
|
|
|
|
&& !inOtherView(buf) && !buf.parent();
|
|
|
|
|
|
|
|
bool close_buffer = last_wa;
|
|
|
|
|
|
|
|
if (last_wa) {
|
|
|
|
if (lyxrc.close_buffer_with_last_view == "yes")
|
|
|
|
; // Nothing to do
|
|
|
|
else if (lyxrc.close_buffer_with_last_view == "no")
|
|
|
|
close_buffer = false;
|
|
|
|
else {
|
|
|
|
docstring file;
|
|
|
|
if (buf.isUnnamed())
|
|
|
|
file = from_utf8(buf.fileName().onlyFileName());
|
|
|
|
else
|
|
|
|
file = buf.fileName().displayName(30);
|
|
|
|
docstring const text = bformat(
|
|
|
|
_("Last view on document %1$s is being closed.\n"
|
|
|
|
"Would you like to close or hide the document?\n"
|
|
|
|
"\n"
|
|
|
|
"Hidden documents can be displayed back through\n"
|
|
|
|
"the menu: View->Hidden->...\n"
|
|
|
|
"\n"
|
|
|
|
"To remove this question, set your preference in:\n"
|
|
|
|
" Tools->Preferences->Look&Feel->UserInterface\n"
|
|
|
|
), file);
|
|
|
|
int ret = Alert::prompt(_("Close or hide document?"),
|
|
|
|
text, 0, 1, _("&Close"), _("&Hide"));
|
|
|
|
close_buffer = (ret == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closeWorkArea(wa, close_buffer);
|
2009-08-17 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
bool GuiView::closeBuffer()
|
|
|
|
{
|
2009-08-15 21:29:14 +00:00
|
|
|
GuiWorkArea * wa = currentMainWorkArea();
|
2010-01-08 09:29:17 +00:00
|
|
|
setCurrentWorkArea(wa);
|
2009-08-15 21:29:14 +00:00
|
|
|
Buffer & buf = wa->bufferView().buffer();
|
|
|
|
return wa && closeWorkArea(wa, !buf.parent());
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 20:06:57 +00:00
|
|
|
void GuiView::writeSession() const {
|
|
|
|
GuiWorkArea const * active_wa = currentMainWorkArea();
|
|
|
|
for (int i = 0; i < d.splitter_->count(); ++i) {
|
|
|
|
TabWorkArea * twa = d.tabWorkArea(i);
|
|
|
|
for (int j = 0; j < twa->count(); ++j) {
|
|
|
|
GuiWorkArea * wa = static_cast<GuiWorkArea *>(twa->widget(j));
|
|
|
|
Buffer & buf = wa->bufferView().buffer();
|
|
|
|
theSession().lastOpened().add(buf.fileName(), wa == active_wa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-18 20:48:15 +00:00
|
|
|
bool GuiView::closeBufferAll()
|
2009-08-18 20:12:34 +00:00
|
|
|
{
|
2009-08-19 21:12:53 +00:00
|
|
|
// Close the workareas in all other views
|
|
|
|
QList<int> const ids = guiApp->viewIds();
|
|
|
|
for (int i = 0; i != ids.size(); ++i) {
|
|
|
|
if (id_ != ids[i] && !guiApp->view(ids[i]).closeWorkAreaAll())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close our own workareas
|
2009-08-18 20:48:15 +00:00
|
|
|
if (!closeWorkAreaAll())
|
2009-08-18 20:12:34 +00:00
|
|
|
return false;
|
|
|
|
|
2009-08-18 20:48:15 +00:00
|
|
|
// Now close the hidden buffers. We prevent hidden buffers from being
|
|
|
|
// dirty, so we can just close them.
|
2009-08-18 20:12:34 +00:00
|
|
|
theBufferList().closeAll();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-18 20:48:15 +00:00
|
|
|
bool GuiView::closeWorkAreaAll()
|
2009-08-18 20:12:34 +00:00
|
|
|
{
|
2009-08-21 20:29:40 +00:00
|
|
|
setCurrentWorkArea(currentMainWorkArea());
|
2009-08-18 20:12:34 +00:00
|
|
|
|
|
|
|
// We might be in a situation that there is still a tabWorkArea, but
|
2010-09-07 14:11:28 +00:00
|
|
|
// there are no tabs anymore. This can happen when we get here after a
|
2009-08-18 20:12:34 +00:00
|
|
|
// TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
|
|
|
|
// many TabWorkArea's have no documents anymore.
|
|
|
|
int empty_twa = 0;
|
|
|
|
|
|
|
|
// We have to call count() each time, because it can happen that
|
|
|
|
// more than one splitter will disappear in one iteration (bug 5998).
|
|
|
|
for (; d.splitter_->count() > empty_twa; ) {
|
|
|
|
TabWorkArea * twa = d.tabWorkArea(empty_twa);
|
2009-08-18 20:48:15 +00:00
|
|
|
|
2009-08-18 20:12:34 +00:00
|
|
|
if (twa->count() == 0)
|
|
|
|
++empty_twa;
|
|
|
|
else {
|
|
|
|
setCurrentWorkArea(twa->currentWorkArea());
|
2009-08-21 20:29:40 +00:00
|
|
|
if (!closeTabWorkArea(twa))
|
2009-08-18 20:12:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-21 20:29:40 +00:00
|
|
|
bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer)
|
2007-12-04 22:21:25 +00:00
|
|
|
{
|
2009-10-29 23:22:50 +00:00
|
|
|
if (!wa)
|
|
|
|
return false;
|
|
|
|
|
2009-08-17 21:25:27 +00:00
|
|
|
Buffer & buf = wa->bufferView().buffer();
|
|
|
|
|
2010-04-05 13:04:52 +00:00
|
|
|
if (close_buffer && GuiViewPrivate::busyBuffers.contains(&buf)) {
|
2010-11-18 23:12:46 +00:00
|
|
|
Alert::warning(_("Close document"),
|
|
|
|
_("Document could not be closed because it is being processed by LyX."));
|
2010-04-05 13:04:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-29 23:22:50 +00:00
|
|
|
if (close_buffer)
|
|
|
|
return closeBuffer(buf);
|
|
|
|
else {
|
|
|
|
if (!inMultiTabs(wa))
|
|
|
|
if (!saveBufferIfNeeded(buf, true))
|
|
|
|
return false;
|
|
|
|
removeWorkArea(wa);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiView::closeBuffer(Buffer & buf)
|
|
|
|
{
|
2009-08-18 21:18:21 +00:00
|
|
|
// If we are in a close_event all children will be closed in some time,
|
|
|
|
// so no need to do it here. This will ensure that the children end up
|
|
|
|
// in the session file in the correct order. If we close the master
|
|
|
|
// buffer, we can close or release the child buffers here too.
|
2010-12-09 21:35:39 +00:00
|
|
|
bool success = true;
|
2009-10-29 23:22:50 +00:00
|
|
|
if (!closing_) {
|
2010-09-29 13:05:57 +00:00
|
|
|
ListOfBuffers clist = buf.getChildren();
|
2010-09-29 12:19:57 +00:00
|
|
|
ListOfBuffers::const_iterator it = clist.begin();
|
2010-09-29 11:55:10 +00:00
|
|
|
ListOfBuffers::const_iterator const bend = clist.end();
|
2010-09-29 12:19:57 +00:00
|
|
|
for (; it != bend; ++it) {
|
2009-08-17 21:25:27 +00:00
|
|
|
// If a child is dirty, do not close
|
|
|
|
// without user intervention
|
|
|
|
//FIXME: should we look in other tabworkareas?
|
2009-08-18 21:18:21 +00:00
|
|
|
Buffer * child_buf = *it;
|
|
|
|
GuiWorkArea * child_wa = workArea(*child_buf);
|
|
|
|
if (child_wa) {
|
2010-12-09 21:35:39 +00:00
|
|
|
if (!closeWorkArea(child_wa, true)) {
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-18 21:18:21 +00:00
|
|
|
} else
|
|
|
|
theBufferList().releaseChild(&buf, child_buf);
|
2009-08-17 21:25:27 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-09 21:35:39 +00:00
|
|
|
if (success) {
|
|
|
|
// goto bookmark to update bookmark pit.
|
|
|
|
//FIXME: we should update only the bookmarks related to this buffer!
|
|
|
|
LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
|
|
|
|
for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
|
|
|
|
guiApp->gotoBookmark(i+1, false, false);
|
|
|
|
|
|
|
|
if (saveBufferIfNeeded(buf, false)) {
|
|
|
|
buf.removeAutosaveFile();
|
|
|
|
theBufferList().release(&buf);
|
|
|
|
return true;
|
|
|
|
}
|
2007-12-04 22:21:25 +00:00
|
|
|
}
|
2010-12-09 22:35:44 +00:00
|
|
|
// open all children again to avoid a crash because of dangling
|
|
|
|
// pointers (bug 6603)
|
|
|
|
buf.updateBuffer();
|
2009-08-12 18:50:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-21 20:29:40 +00:00
|
|
|
bool GuiView::closeTabWorkArea(TabWorkArea * twa)
|
2009-08-18 19:04:39 +00:00
|
|
|
{
|
|
|
|
while (twa == d.currentTabWorkArea()) {
|
|
|
|
twa->setCurrentIndex(twa->count()-1);
|
|
|
|
|
|
|
|
GuiWorkArea * wa = twa->currentWorkArea();
|
|
|
|
Buffer & b = wa->bufferView().buffer();
|
|
|
|
|
|
|
|
// We only want to close the buffer if the same buffer is not visible
|
|
|
|
// in another view, and if this is not a child and if we are closing
|
|
|
|
// a view (not a tabgroup).
|
2010-09-07 14:11:28 +00:00
|
|
|
bool const close_buffer =
|
2010-12-09 22:29:12 +00:00
|
|
|
!inOtherView(b) && !b.parent() && closing_;
|
2009-08-18 19:04:39 +00:00
|
|
|
|
2009-08-21 20:29:40 +00:00
|
|
|
if (!closeWorkArea(wa, close_buffer))
|
2009-08-18 19:04:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-14 23:12:21 +00:00
|
|
|
bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
|
2009-08-12 18:50:09 +00:00
|
|
|
{
|
|
|
|
if (buf.isClean() || buf.paragraphs().empty())
|
|
|
|
return true;
|
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
// Switch to this Buffer.
|
|
|
|
setBuffer(&buf);
|
|
|
|
|
|
|
|
docstring file;
|
|
|
|
// FIXME: Unicode?
|
|
|
|
if (buf.isUnnamed())
|
|
|
|
file = from_utf8(buf.fileName().onlyFileName());
|
|
|
|
else
|
|
|
|
file = buf.fileName().displayName(30);
|
|
|
|
|
2008-02-27 10:35:28 +00:00
|
|
|
// Bring this window to top before asking questions.
|
|
|
|
raise();
|
|
|
|
activateWindow();
|
|
|
|
|
2009-08-14 23:12:21 +00:00
|
|
|
int ret;
|
|
|
|
if (hiding && buf.isUnnamed()) {
|
|
|
|
docstring const text = bformat(_("The document %1$s has not been "
|
2010-03-05 18:07:05 +00:00
|
|
|
"saved yet.\n\nDo you want to save "
|
|
|
|
"the document?"), file);
|
2010-09-07 14:11:28 +00:00
|
|
|
ret = Alert::prompt(_("Save new document?"),
|
2009-08-14 23:12:21 +00:00
|
|
|
text, 0, 1, _("&Save"), _("&Cancel"));
|
|
|
|
if (ret == 1)
|
|
|
|
++ret;
|
|
|
|
} else {
|
|
|
|
docstring const text = bformat(_("The document %1$s has unsaved changes."
|
|
|
|
"\n\nDo you want to save the document or discard the changes?"), file);
|
|
|
|
ret = Alert::prompt(_("Save changed document?"),
|
|
|
|
text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
|
|
|
|
}
|
2007-12-04 22:21:25 +00:00
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 0:
|
|
|
|
if (!saveBuffer(buf))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 1:
|
2010-11-17 03:22:37 +00:00
|
|
|
// If we crash after this we could have no autosave file
|
|
|
|
// but I guess this is really improbable (Jug).
|
|
|
|
// Sometimes improbable things happen:
|
|
|
|
// - see bug http://www.lyx.org/trac/ticket/6587 (ps)
|
2010-03-26 23:15:37 +00:00
|
|
|
// buf.removeAutosaveFile();
|
2009-08-16 00:26:14 +00:00
|
|
|
if (hiding)
|
2009-08-14 23:12:21 +00:00
|
|
|
// revert all changes
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(buf);
|
2009-08-16 00:26:14 +00:00
|
|
|
buf.markClean();
|
2007-12-04 22:21:25 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-15 21:46:39 +00:00
|
|
|
bool GuiView::inMultiTabs(GuiWorkArea * wa)
|
|
|
|
{
|
|
|
|
Buffer & buf = wa->bufferView().buffer();
|
|
|
|
|
|
|
|
for (int i = 0; i != d.splitter_->count(); ++i) {
|
|
|
|
GuiWorkArea * wa_ = d.tabWorkArea(i)->workArea(buf);
|
|
|
|
if (wa_ && wa_ != wa)
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-09 22:29:12 +00:00
|
|
|
return inOtherView(buf);
|
2009-08-15 21:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-09 22:29:12 +00:00
|
|
|
bool GuiView::inOtherView(Buffer & buf)
|
2009-08-15 18:13:21 +00:00
|
|
|
{
|
|
|
|
QList<int> const ids = guiApp->viewIds();
|
|
|
|
|
2010-12-09 22:29:12 +00:00
|
|
|
for (int i = 0; i != ids.size(); ++i) {
|
2009-08-15 18:13:21 +00:00
|
|
|
if (id_ == ids[i])
|
|
|
|
continue;
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2009-08-15 18:13:21 +00:00
|
|
|
if (guiApp->view(ids[i]).workArea(buf))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-25 14:34:42 +00:00
|
|
|
void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
|
|
|
|
{
|
2010-11-30 13:03:46 +00:00
|
|
|
if (!documentBufferView())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (TabWorkArea * twa = d.currentTabWorkArea()) {
|
|
|
|
Buffer * const curbuf = &documentBufferView()->buffer();
|
|
|
|
int nwa = twa->count();
|
|
|
|
for (int i = 0; i < nwa; ++i) {
|
|
|
|
if (&workArea(i)->bufferView().buffer() == curbuf) {
|
|
|
|
int next_index;
|
|
|
|
if (np == NEXTBUFFER)
|
|
|
|
next_index = (i == nwa - 1 ? 0 : i + 1);
|
|
|
|
else
|
|
|
|
next_index = (i == 0 ? nwa - 1 : i - 1);
|
|
|
|
setBuffer(&workArea(next_index)->bufferView().buffer());
|
|
|
|
break;
|
|
|
|
}
|
2009-03-25 14:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
/// make sure the document is saved
|
|
|
|
static bool ensureBufferClean(Buffer * buffer)
|
|
|
|
{
|
|
|
|
LASSERT(buffer, return false);
|
|
|
|
if (buffer->isClean() && !buffer->isUnnamed())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
docstring const file = buffer->fileName().displayName(30);
|
|
|
|
docstring title;
|
|
|
|
docstring text;
|
|
|
|
if (!buffer->isUnnamed()) {
|
|
|
|
text = bformat(_("The document %1$s has unsaved "
|
2010-03-05 18:07:05 +00:00
|
|
|
"changes.\n\nDo you want to save "
|
|
|
|
"the document?"), file);
|
2009-09-12 20:41:24 +00:00
|
|
|
title = _("Save changed document?");
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
} else {
|
|
|
|
text = bformat(_("The document %1$s has not been "
|
2010-03-05 18:07:05 +00:00
|
|
|
"saved yet.\n\nDo you want to save "
|
|
|
|
"the document?"), file);
|
2009-09-12 20:41:24 +00:00
|
|
|
title = _("Save new document?");
|
|
|
|
}
|
|
|
|
int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
dispatch(FuncRequest(LFUN_BUFFER_WRITE));
|
|
|
|
|
|
|
|
return buffer->isClean() && !buffer->isUnnamed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-29 18:50:48 +00:00
|
|
|
bool GuiView::reloadBuffer(Buffer & buf)
|
2009-09-12 20:41:24 +00:00
|
|
|
{
|
2010-10-29 18:50:48 +00:00
|
|
|
Buffer::ReadStatus status = buf.reload();
|
|
|
|
return status == Buffer::ReadSuccess;
|
2009-09-12 20:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-24 18:47:43 +00:00
|
|
|
void GuiView::checkExternallyModifiedBuffers()
|
|
|
|
{
|
|
|
|
BufferList::iterator bit = theBufferList().begin();
|
|
|
|
BufferList::iterator const bend = theBufferList().end();
|
|
|
|
for (; bit != bend; ++bit) {
|
2010-10-29 18:50:48 +00:00
|
|
|
Buffer * buf = *bit;
|
|
|
|
if (buf->fileName().exists()
|
|
|
|
&& buf->isExternallyModified(Buffer::checksum_method)) {
|
2009-11-24 18:47:43 +00:00
|
|
|
docstring text = bformat(_("Document \n%1$s\n has been externally modified."
|
|
|
|
" Reload now? Any local changes will be lost."),
|
2010-10-29 18:50:48 +00:00
|
|
|
from_utf8(buf->absFileName()));
|
2009-11-24 18:47:43 +00:00
|
|
|
int const ret = Alert::prompt(_("Reload externally changed document?"),
|
|
|
|
text, 0, 1, _("&Reload"), _("&Cancel"));
|
|
|
|
if (!ret)
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buf);
|
2009-11-24 18:47:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-17 10:44:53 +00:00
|
|
|
void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
|
2009-09-12 20:41:24 +00:00
|
|
|
{
|
|
|
|
Buffer * buffer = documentBufferView()
|
|
|
|
? &(documentBufferView()->buffer()) : 0;
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_REGISTER:
|
|
|
|
if (!buffer || !ensureBufferClean(buffer))
|
|
|
|
break;
|
|
|
|
if (!buffer->lyxvc().inUse()) {
|
2010-10-17 10:44:53 +00:00
|
|
|
if (buffer->lyxvc().registrer()) {
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buffer);
|
2010-10-17 10:44:53 +00:00
|
|
|
dr.suppressMessageUpdate();
|
|
|
|
}
|
2009-09-12 20:41:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-02-05 20:31:58 +00:00
|
|
|
case LFUN_VC_RENAME:
|
|
|
|
case LFUN_VC_COPY: {
|
|
|
|
if (!buffer || !ensureBufferClean(buffer))
|
|
|
|
break;
|
|
|
|
if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
|
|
|
|
if (buffer->lyxvc().isCheckInWithConfirmation()) {
|
|
|
|
// Some changes are not yet committed.
|
|
|
|
// We test here and not in getStatus(), since
|
|
|
|
// this test is expensive.
|
|
|
|
string log;
|
|
|
|
LyXVC::CommandResult ret =
|
|
|
|
buffer->lyxvc().checkIn(log);
|
|
|
|
dr.setMessage(log);
|
|
|
|
if (ret == LyXVC::ErrorCommand ||
|
2013-03-18 19:42:20 +00:00
|
|
|
ret == LyXVC::VCSuccess)
|
2013-02-05 20:31:58 +00:00
|
|
|
reloadBuffer(*buffer);
|
|
|
|
if (buffer->lyxvc().isCheckInWithConfirmation()) {
|
|
|
|
frontend::Alert::error(
|
|
|
|
_("Revision control error."),
|
|
|
|
_("Document could not be checked in."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RenameKind const kind = (cmd.action() == LFUN_VC_RENAME) ?
|
|
|
|
LV_VC_RENAME : LV_VC_COPY;
|
|
|
|
renameBuffer(*buffer, cmd.argument(), kind);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_CHECK_IN:
|
|
|
|
if (!buffer || !ensureBufferClean(buffer))
|
|
|
|
break;
|
|
|
|
if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
|
2013-02-04 20:40:28 +00:00
|
|
|
string log;
|
|
|
|
LyXVC::CommandResult ret = buffer->lyxvc().checkIn(log);
|
|
|
|
dr.setMessage(log);
|
|
|
|
// Only skip reloading if the checkin was cancelled or
|
|
|
|
// an error occured before the real checkin VCS command
|
|
|
|
// was executed, since the VCS might have changed the
|
|
|
|
// file even if it could not checkin successfully.
|
2013-03-18 19:42:20 +00:00
|
|
|
if (ret == LyXVC::ErrorCommand || ret == LyXVC::VCSuccess)
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buffer);
|
2009-09-12 20:41:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_VC_CHECK_OUT:
|
|
|
|
if (!buffer || !ensureBufferClean(buffer))
|
|
|
|
break;
|
|
|
|
if (buffer->lyxvc().inUse()) {
|
2010-10-17 10:44:53 +00:00
|
|
|
dr.setMessage(buffer->lyxvc().checkOut());
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buffer);
|
2009-09-12 20:41:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_VC_LOCKING_TOGGLE:
|
|
|
|
LASSERT(buffer, return);
|
|
|
|
if (!ensureBufferClean(buffer) || buffer->isReadonly())
|
|
|
|
break;
|
|
|
|
if (buffer->lyxvc().inUse()) {
|
|
|
|
string res = buffer->lyxvc().lockingToggle();
|
|
|
|
if (res.empty()) {
|
|
|
|
frontend::Alert::error(_("Revision control error."),
|
|
|
|
_("Error when setting the locking property."));
|
|
|
|
} else {
|
2010-10-17 10:44:53 +00:00
|
|
|
dr.setMessage(res);
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buffer);
|
2009-09-12 20:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_VC_REVERT:
|
|
|
|
LASSERT(buffer, return);
|
2010-11-06 11:54:08 +00:00
|
|
|
if (buffer->lyxvc().revert()) {
|
|
|
|
reloadBuffer(*buffer);
|
|
|
|
dr.suppressMessageUpdate();
|
|
|
|
}
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_VC_UNDO_LAST:
|
|
|
|
LASSERT(buffer, return);
|
|
|
|
buffer->lyxvc().undoLast();
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buffer);
|
2010-10-17 10:44:53 +00:00
|
|
|
dr.suppressMessageUpdate();
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-14 19:18:06 +00:00
|
|
|
case LFUN_VC_REPO_UPDATE:
|
2009-10-06 23:20:52 +00:00
|
|
|
LASSERT(buffer, return);
|
|
|
|
if (ensureBufferClean(buffer)) {
|
2010-10-17 10:44:53 +00:00
|
|
|
dr.setMessage(buffer->lyxvc().repoUpdate());
|
2009-11-24 18:47:43 +00:00
|
|
|
checkExternallyModifiedBuffers();
|
2009-10-06 23:20:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_COMMAND: {
|
|
|
|
string flag = cmd.getArg(0);
|
|
|
|
if (buffer && contains(flag, 'R') && !ensureBufferClean(buffer))
|
|
|
|
break;
|
|
|
|
docstring message;
|
|
|
|
if (contains(flag, 'M')) {
|
|
|
|
if (!Alert::askForText(message, _("LyX VC: Log Message")))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
string path = cmd.getArg(1);
|
|
|
|
if (contains(path, "$$p") && buffer)
|
|
|
|
path = subst(path, "$$p", buffer->filePath());
|
|
|
|
LYXERR(Debug::LYXVC, "Directory: " << path);
|
|
|
|
FileName pp(path);
|
|
|
|
if (!pp.isReadableDirectory()) {
|
|
|
|
lyxerr << _("Directory is not accessible.") << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
support::PathChanger p(pp);
|
|
|
|
|
|
|
|
string command = cmd.getArg(2);
|
|
|
|
if (command.empty())
|
|
|
|
break;
|
|
|
|
if (buffer) {
|
|
|
|
command = subst(command, "$$i", buffer->absFileName());
|
|
|
|
command = subst(command, "$$p", buffer->filePath());
|
|
|
|
}
|
|
|
|
command = subst(command, "$$m", to_utf8(message));
|
|
|
|
LYXERR(Debug::LYXVC, "Command: " << command);
|
|
|
|
Systemcall one;
|
|
|
|
one.startscript(Systemcall::Wait, command);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
break;
|
|
|
|
if (contains(flag, 'I'))
|
|
|
|
buffer->markDirty();
|
|
|
|
if (contains(flag, 'R'))
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*buffer);
|
2009-09-12 20:41:24 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2010-02-12 14:09:44 +00:00
|
|
|
|
|
|
|
case LFUN_VC_COMPARE: {
|
2010-02-15 07:10:59 +00:00
|
|
|
|
2010-09-07 11:28:57 +00:00
|
|
|
if (cmd.argument().empty()) {
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "comparehistory"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-15 07:10:59 +00:00
|
|
|
string rev1 = cmd.getArg(0);
|
2010-02-12 14:09:44 +00:00
|
|
|
string f1, f2;
|
|
|
|
|
|
|
|
// f1
|
|
|
|
if (!buffer->lyxvc().prepareFileRevision(rev1, f1))
|
|
|
|
break;
|
|
|
|
|
2010-02-15 07:10:59 +00:00
|
|
|
if (isStrInt(rev1) && convert<int>(rev1) <= 0) {
|
2010-02-12 14:09:44 +00:00
|
|
|
f2 = buffer->absFileName();
|
|
|
|
} else {
|
2010-02-15 07:10:59 +00:00
|
|
|
string rev2 = cmd.getArg(1);
|
2010-02-15 09:05:16 +00:00
|
|
|
if (rev2.empty())
|
2010-02-12 14:09:44 +00:00
|
|
|
break;
|
|
|
|
// f2
|
|
|
|
if (!buffer->lyxvc().prepareFileRevision(rev2, f2))
|
|
|
|
break;
|
|
|
|
}
|
2010-09-07 11:29:11 +00:00
|
|
|
|
2010-09-07 11:58:42 +00:00
|
|
|
LYXERR(Debug::LYXVC, "Launching comparison for fetched revisions:\n" <<
|
2010-09-07 11:29:11 +00:00
|
|
|
f1 << "\n" << f2 << "\n" );
|
2010-09-07 19:03:28 +00:00
|
|
|
string par = "compare run " + quoteName(f1) + " " + quoteName(f2);
|
2010-09-07 11:29:02 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, par));
|
2010-02-15 09:05:16 +00:00
|
|
|
break;
|
2010-02-12 14:09:44 +00:00
|
|
|
}
|
|
|
|
|
2009-09-21 08:20:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-09-12 20:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-19 16:49:31 +00:00
|
|
|
void GuiView::openChildDocument(string const & fname)
|
|
|
|
{
|
|
|
|
LASSERT(documentBufferView(), return);
|
|
|
|
Buffer & buffer = documentBufferView()->buffer();
|
|
|
|
FileName const filename = support::makeAbsPath(fname, buffer.filePath());
|
|
|
|
documentBufferView()->saveBookmark(false);
|
|
|
|
Buffer * child = 0;
|
|
|
|
if (theBufferList().exists(filename)) {
|
|
|
|
child = theBufferList().getBuffer(filename);
|
2010-10-29 18:57:40 +00:00
|
|
|
setBuffer(child);
|
2009-09-19 16:49:31 +00:00
|
|
|
} else {
|
|
|
|
message(bformat(_("Opening child document %1$s..."),
|
2010-10-29 18:57:40 +00:00
|
|
|
makeDisplayPath(filename.absFileName())));
|
2009-09-19 16:49:31 +00:00
|
|
|
child = loadDocument(filename, false);
|
|
|
|
}
|
|
|
|
// Set the parent name of the child document.
|
|
|
|
// This makes insertion of citations and references in the child work,
|
|
|
|
// when the target is in the parent or another child document.
|
2010-10-29 18:57:40 +00:00
|
|
|
if (child)
|
|
|
|
child->setParent(&buffer);
|
2009-09-19 16:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-23 13:45:58 +00:00
|
|
|
bool GuiView::goToFileRow(string const & argument)
|
|
|
|
{
|
|
|
|
string file_name;
|
|
|
|
int row;
|
2009-12-22 21:44:14 +00:00
|
|
|
size_t i = argument.find_last_of(' ');
|
|
|
|
if (i != string::npos) {
|
|
|
|
file_name = os::internal_path(trim(argument.substr(0, i)));
|
|
|
|
istringstream is(argument.substr(i + 1));
|
|
|
|
is >> row;
|
|
|
|
if (is.fail())
|
|
|
|
i = string::npos;
|
|
|
|
}
|
|
|
|
if (i == string::npos) {
|
|
|
|
LYXERR0("Wrong argument: " << argument);
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-23 13:45:58 +00:00
|
|
|
Buffer * buf = 0;
|
2010-04-21 01:19:09 +00:00
|
|
|
string const abstmp = package().temp_dir().absFileName();
|
2009-09-23 13:45:58 +00:00
|
|
|
string const realtmp = package().temp_dir().realPath();
|
|
|
|
// We have to use os::path_prefix_is() here, instead of
|
|
|
|
// simply prefixIs(), because the file name comes from
|
|
|
|
// an external application and may need case adjustment.
|
|
|
|
if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
|
|
|
|
|| os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
|
|
|
|
// Needed by inverse dvi search. If it is a file
|
|
|
|
// in tmpdir, call the apropriated function.
|
|
|
|
// If tmpdir is a symlink, we may have the real
|
|
|
|
// path passed back, so we correct for that.
|
|
|
|
if (!prefixIs(file_name, abstmp))
|
|
|
|
file_name = subst(file_name, realtmp, abstmp);
|
|
|
|
buf = theBufferList().getBufferFromTmp(file_name);
|
|
|
|
} else {
|
|
|
|
// Must replace extension of the file to be .lyx
|
|
|
|
// and get full path
|
|
|
|
FileName const s = fileSearch(string(),
|
2010-03-05 18:07:05 +00:00
|
|
|
support::changeExtension(file_name, ".lyx"), "lyx");
|
2009-09-23 13:45:58 +00:00
|
|
|
// Either change buffer or load the file
|
|
|
|
if (theBufferList().exists(s))
|
|
|
|
buf = theBufferList().getBuffer(s);
|
|
|
|
else if (s.exists()) {
|
|
|
|
buf = loadDocument(s);
|
2010-07-09 14:37:00 +00:00
|
|
|
if (!buf)
|
|
|
|
return false;
|
2009-09-23 13:45:58 +00:00
|
|
|
} else {
|
|
|
|
message(bformat(
|
|
|
|
_("File does not exist: %1$s"),
|
|
|
|
makeDisplayPath(file_name)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-05-27 19:47:10 +00:00
|
|
|
if (!buf) {
|
|
|
|
message(bformat(
|
2011-05-29 13:43:04 +00:00
|
|
|
_("No buffer for file: %1$s."),
|
2011-05-27 19:47:10 +00:00
|
|
|
makeDisplayPath(file_name))
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-23 13:45:58 +00:00
|
|
|
setBuffer(buf);
|
|
|
|
documentBufferView()->setCursorFromRow(row);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-20 01:45:51 +00:00
|
|
|
template<class T>
|
2011-11-16 00:38:06 +00:00
|
|
|
Buffer::ExportStatus GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffer const * orig, Buffer * clone, string const & format)
|
2010-10-19 15:10:13 +00:00
|
|
|
{
|
2011-10-27 20:00:11 +00:00
|
|
|
Buffer::ExportStatus const status = func(format);
|
2011-05-26 13:20:11 +00:00
|
|
|
|
|
|
|
// the cloning operation will have produced a clone of the entire set of
|
|
|
|
// documents, starting from the master. so we must delete those.
|
2011-11-16 00:38:06 +00:00
|
|
|
Buffer * mbuf = const_cast<Buffer *>(clone->masterBuffer());
|
2011-05-26 13:20:11 +00:00
|
|
|
delete mbuf;
|
2010-10-19 15:10:13 +00:00
|
|
|
busyBuffers.remove(orig);
|
2011-10-27 20:00:11 +00:00
|
|
|
return status;
|
2010-10-19 15:34:13 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:36:35 +00:00
|
|
|
|
2011-11-16 00:38:06 +00:00
|
|
|
Buffer::ExportStatus GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
|
2010-10-20 01:45:51 +00:00
|
|
|
{
|
2011-10-27 20:00:11 +00:00
|
|
|
Buffer::ExportStatus (Buffer::* mem_func)(std::string const &, bool) const = &Buffer::doExport;
|
2012-10-08 19:28:55 +00:00
|
|
|
return runAndDestroy(lyx::bind(mem_func, clone, _1, true), orig, clone, format);
|
2010-10-20 01:45:51 +00:00
|
|
|
}
|
2010-10-19 15:34:13 +00:00
|
|
|
|
2010-11-10 14:36:35 +00:00
|
|
|
|
2011-11-16 00:38:06 +00:00
|
|
|
Buffer::ExportStatus GuiView::GuiViewPrivate::exportAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
|
2010-10-19 15:34:13 +00:00
|
|
|
{
|
2011-10-27 20:00:11 +00:00
|
|
|
Buffer::ExportStatus (Buffer::* mem_func)(std::string const &, bool) const = &Buffer::doExport;
|
2012-10-08 19:28:55 +00:00
|
|
|
return runAndDestroy(lyx::bind(mem_func, clone, _1, false), orig, clone, format);
|
2010-10-20 01:45:51 +00:00
|
|
|
}
|
2009-12-18 22:51:06 +00:00
|
|
|
|
2010-11-10 14:36:35 +00:00
|
|
|
|
2011-11-16 00:38:06 +00:00
|
|
|
Buffer::ExportStatus GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
|
2009-12-18 22:51:06 +00:00
|
|
|
{
|
2011-10-27 20:00:11 +00:00
|
|
|
Buffer::ExportStatus (Buffer::* mem_func)(std::string const &) const = &Buffer::preview;
|
2012-10-08 19:28:55 +00:00
|
|
|
return runAndDestroy(lyx::bind(mem_func, clone, _1), orig, clone, format);
|
2009-12-18 22:51:06 +00:00
|
|
|
}
|
2010-11-08 00:37:58 +00:00
|
|
|
|
2009-12-18 22:51:06 +00:00
|
|
|
|
2010-10-18 10:16:32 +00:00
|
|
|
bool GuiView::GuiViewPrivate::asyncBufferProcessing(
|
2010-10-27 17:02:42 +00:00
|
|
|
string const & argument,
|
|
|
|
Buffer const * used_buffer,
|
|
|
|
docstring const & msg,
|
2011-10-27 20:00:11 +00:00
|
|
|
Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
|
|
|
|
Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
|
|
|
|
Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const)
|
2010-10-18 09:31:50 +00:00
|
|
|
{
|
2010-11-10 14:36:35 +00:00
|
|
|
if (!used_buffer)
|
2010-10-18 10:16:32 +00:00
|
|
|
return false;
|
2010-11-10 14:36:35 +00:00
|
|
|
|
2010-10-18 09:31:50 +00:00
|
|
|
string format = argument;
|
2010-11-10 14:36:35 +00:00
|
|
|
if (format.empty())
|
2011-05-13 19:39:56 +00:00
|
|
|
format = used_buffer->params().getDefaultOutputFormat();
|
2011-10-29 11:14:47 +00:00
|
|
|
processing_format = format;
|
2012-11-04 00:18:16 +00:00
|
|
|
#if EXPORT_in_THREAD
|
2010-10-18 09:31:50 +00:00
|
|
|
if (!msg.empty()) {
|
|
|
|
progress_->clearMessages();
|
|
|
|
gv_->message(msg);
|
|
|
|
}
|
|
|
|
GuiViewPrivate::busyBuffers.insert(used_buffer);
|
2012-01-22 22:20:50 +00:00
|
|
|
Buffer * cloned_buffer = used_buffer->cloneFromMaster();
|
|
|
|
if (!cloned_buffer) {
|
|
|
|
Alert::error(_("Export Error"),
|
|
|
|
_("Error cloning the Buffer."));
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-27 20:00:11 +00:00
|
|
|
QFuture<Buffer::ExportStatus> f = QtConcurrent::run(
|
2010-10-18 09:31:50 +00:00
|
|
|
asyncFunc,
|
|
|
|
used_buffer,
|
2012-01-12 02:09:08 +00:00
|
|
|
cloned_buffer,
|
2010-10-18 09:31:50 +00:00
|
|
|
format);
|
|
|
|
setPreviewFuture(f);
|
2011-05-13 19:39:56 +00:00
|
|
|
last_export_format = used_buffer->params().bufferFormat();
|
2010-10-18 09:31:50 +00:00
|
|
|
(void) syncFunc;
|
|
|
|
(void) previewFunc;
|
2010-10-18 10:16:32 +00:00
|
|
|
// We are asynchronous, so we don't know here anything about the success
|
|
|
|
return true;
|
2010-10-18 09:31:50 +00:00
|
|
|
#else
|
2011-10-29 11:14:47 +00:00
|
|
|
Buffer::ExportStatus status;
|
2010-10-18 09:31:50 +00:00
|
|
|
if (syncFunc) {
|
2010-11-08 08:40:12 +00:00
|
|
|
// TODO check here if it breaks exporting with Qt < 4.4
|
2011-10-29 11:14:47 +00:00
|
|
|
status = (used_buffer->*syncFunc)(format, true);
|
2010-10-18 09:31:50 +00:00
|
|
|
} else if (previewFunc) {
|
2011-10-29 11:14:47 +00:00
|
|
|
status = (used_buffer->*previewFunc)(format);
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
handleExportStatus(gv_, status, format);
|
2010-10-18 09:31:50 +00:00
|
|
|
(void) asyncFunc;
|
2011-10-29 11:14:47 +00:00
|
|
|
return (status == Buffer::ExportSuccess
|
|
|
|
|| status == Buffer::PreviewSuccess);
|
2010-10-18 09:31:50 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-10-18 08:18:56 +00:00
|
|
|
|
2010-12-04 22:48:08 +00:00
|
|
|
void GuiView::dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr)
|
|
|
|
{
|
|
|
|
BufferView * bv = currentBufferView();
|
|
|
|
LASSERT(bv, /**/);
|
|
|
|
|
|
|
|
// Let the current BufferView dispatch its own actions.
|
|
|
|
bv->dispatch(cmd, dr);
|
2010-12-05 00:57:04 +00:00
|
|
|
if (dr.dispatched())
|
|
|
|
return;
|
2010-12-04 22:48:08 +00:00
|
|
|
|
|
|
|
// Try with the document BufferView dispatch if any.
|
|
|
|
BufferView * doc_bv = documentBufferView();
|
2011-04-14 21:39:47 +00:00
|
|
|
if (doc_bv && doc_bv != bv) {
|
2010-12-05 00:57:04 +00:00
|
|
|
doc_bv->dispatch(cmd, dr);
|
|
|
|
if (dr.dispatched())
|
|
|
|
return;
|
|
|
|
}
|
2010-12-04 22:48:08 +00:00
|
|
|
|
|
|
|
// Then let the current Cursor dispatch its own actions.
|
2010-12-05 00:57:04 +00:00
|
|
|
bv->cursor().dispatch(cmd);
|
|
|
|
|
|
|
|
// update completion. We do it here and not in
|
|
|
|
// processKeySym to avoid another redraw just for a
|
|
|
|
// changed inline completion
|
|
|
|
if (cmd.origin() == FuncRequest::KEYBOARD) {
|
|
|
|
if (cmd.action() == LFUN_SELF_INSERT
|
|
|
|
|| (cmd.action() == LFUN_ERT_INSERT && bv->cursor().inMathed()))
|
|
|
|
updateCompletion(bv->cursor(), true, true);
|
|
|
|
else if (cmd.action() == LFUN_CHAR_DELETE_BACKWARD)
|
|
|
|
updateCompletion(bv->cursor(), false, true);
|
|
|
|
else
|
|
|
|
updateCompletion(bv->cursor(), false, false);
|
2010-12-04 22:48:08 +00:00
|
|
|
}
|
2010-12-05 00:57:04 +00:00
|
|
|
|
|
|
|
dr = bv->cursor().result();
|
2010-12-04 22:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-29 10:42:39 +00:00
|
|
|
void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
2007-11-12 23:23:19 +00:00
|
|
|
{
|
2009-09-05 14:29:11 +00:00
|
|
|
BufferView * bv = currentBufferView();
|
2007-11-23 11:45:20 +00:00
|
|
|
// By default we won't need any update.
|
2010-10-13 17:28:55 +00:00
|
|
|
dr.screenUpdate(Update::None);
|
2010-01-29 10:42:39 +00:00
|
|
|
// assume cmd will be dispatched
|
|
|
|
dr.dispatched(true);
|
2009-09-12 20:41:24 +00:00
|
|
|
|
|
|
|
Buffer * doc_buffer = documentBufferView()
|
|
|
|
? &(documentBufferView()->buffer()) : 0;
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
if (cmd.origin() == FuncRequest::TOC) {
|
2009-04-08 21:06:58 +00:00
|
|
|
GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
|
2010-01-29 10:42:39 +00:00
|
|
|
// FIXME: do we need to pass a DispatchResult object here?
|
2009-04-08 21:06:58 +00:00
|
|
|
toc->doDispatch(bv->cursor(), cmd);
|
2010-01-29 10:42:39 +00:00
|
|
|
return;
|
2009-04-08 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 22:51:06 +00:00
|
|
|
string const argument = to_utf8(cmd.argument());
|
|
|
|
|
2010-04-09 19:00:42 +00:00
|
|
|
switch(cmd.action()) {
|
2009-09-19 16:49:31 +00:00
|
|
|
case LFUN_BUFFER_CHILD_OPEN:
|
|
|
|
openChildDocument(to_utf8(cmd.argument()));
|
|
|
|
break;
|
|
|
|
|
2008-02-06 23:54:13 +00:00
|
|
|
case LFUN_BUFFER_IMPORT:
|
|
|
|
importDocument(to_utf8(cmd.argument()));
|
|
|
|
break;
|
|
|
|
|
2009-12-18 22:51:06 +00:00
|
|
|
case LFUN_BUFFER_EXPORT: {
|
|
|
|
if (!doc_buffer)
|
|
|
|
break;
|
2010-01-30 11:34:28 +00:00
|
|
|
// GCC only sees strfwd.h when building merged
|
|
|
|
if (::lyx::operator==(cmd.argument(), "custom")) {
|
2010-10-18 10:16:32 +00:00
|
|
|
dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"), dr);
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-10-18 10:55:01 +00:00
|
|
|
/* TODO/Review: Is it a problem to also export the children?
|
2010-10-27 17:02:42 +00:00
|
|
|
See the update_unincluded flag */
|
2010-10-18 10:16:32 +00:00
|
|
|
d.asyncBufferProcessing(argument,
|
2010-10-27 17:02:42 +00:00
|
|
|
doc_buffer,
|
|
|
|
_("Exporting ..."),
|
|
|
|
&GuiViewPrivate::exportAndDestroy,
|
|
|
|
&Buffer::doExport,
|
|
|
|
0);
|
2010-10-18 10:16:32 +00:00
|
|
|
// TODO Inform user about success
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-06 13:47:42 +00:00
|
|
|
case LFUN_BUFFER_EXPORT_AS:
|
|
|
|
LASSERT(doc_buffer, break);
|
|
|
|
exportBufferAs(*doc_buffer);
|
|
|
|
break;
|
|
|
|
|
2009-12-18 22:51:06 +00:00
|
|
|
case LFUN_BUFFER_UPDATE: {
|
2010-10-18 09:31:50 +00:00
|
|
|
d.asyncBufferProcessing(argument,
|
2010-10-27 17:02:42 +00:00
|
|
|
doc_buffer,
|
|
|
|
_("Exporting ..."),
|
|
|
|
&GuiViewPrivate::compileAndDestroy,
|
|
|
|
&Buffer::doExport,
|
|
|
|
0);
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_BUFFER_VIEW: {
|
2010-10-18 09:31:50 +00:00
|
|
|
d.asyncBufferProcessing(argument,
|
2010-10-27 17:02:42 +00:00
|
|
|
doc_buffer,
|
|
|
|
_("Previewing ..."),
|
|
|
|
&GuiViewPrivate::previewAndDestroy,
|
|
|
|
0,
|
|
|
|
&Buffer::preview);
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_MASTER_BUFFER_UPDATE: {
|
2010-10-18 09:31:50 +00:00
|
|
|
d.asyncBufferProcessing(argument,
|
2010-10-27 17:02:42 +00:00
|
|
|
(doc_buffer ? doc_buffer->masterBuffer() : 0),
|
|
|
|
docstring(),
|
|
|
|
&GuiViewPrivate::compileAndDestroy,
|
|
|
|
&Buffer::doExport,
|
|
|
|
0);
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_MASTER_BUFFER_VIEW: {
|
2010-10-18 09:31:50 +00:00
|
|
|
d.asyncBufferProcessing(argument,
|
2010-10-27 17:02:42 +00:00
|
|
|
(doc_buffer ? doc_buffer->masterBuffer() : 0),
|
|
|
|
docstring(),
|
|
|
|
&GuiViewPrivate::previewAndDestroy,
|
|
|
|
0, &Buffer::preview);
|
2009-12-18 22:51:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-07 21:57:37 +00:00
|
|
|
case LFUN_BUFFER_SWITCH: {
|
2010-06-17 21:18:08 +00:00
|
|
|
string const file_name = to_utf8(cmd.argument());
|
|
|
|
if (!FileName::isAbsolute(file_name)) {
|
|
|
|
dr.setError(true);
|
|
|
|
dr.setMessage(_("Absolute filename expected."));
|
2010-06-07 21:57:37 +00:00
|
|
|
break;
|
2010-06-17 21:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Buffer * buffer = theBufferList().getBuffer(FileName(file_name));
|
2010-06-07 21:57:37 +00:00
|
|
|
if (!buffer) {
|
|
|
|
dr.setError(true);
|
|
|
|
dr.setMessage(_("Document not loaded"));
|
|
|
|
break;
|
2010-09-07 14:11:28 +00:00
|
|
|
}
|
2010-06-17 21:18:08 +00:00
|
|
|
|
|
|
|
// Do we open or switch to the buffer in this view ?
|
2010-09-07 14:11:28 +00:00
|
|
|
if (workArea(*buffer)
|
2010-06-17 21:18:08 +00:00
|
|
|
|| lyxrc.open_buffers_in_tabs || !documentBufferView()) {
|
2010-06-07 21:57:37 +00:00
|
|
|
setBuffer(buffer);
|
|
|
|
break;
|
2010-09-07 14:11:28 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 21:18:08 +00:00
|
|
|
// Look for the buffer in other views
|
2010-06-07 21:57:37 +00:00
|
|
|
QList<int> const ids = guiApp->viewIds();
|
|
|
|
int i = 0;
|
|
|
|
for (; i != ids.size(); ++i) {
|
|
|
|
GuiView & gv = guiApp->view(ids[i]);
|
|
|
|
if (gv.workArea(*buffer)) {
|
|
|
|
gv.activateWindow();
|
|
|
|
gv.setBuffer(buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-17 21:18:08 +00:00
|
|
|
|
|
|
|
// If necessary, open a new window as a last resort
|
2010-06-07 21:57:37 +00:00
|
|
|
if (i == ids.size()) {
|
2010-06-17 21:18:08 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_WINDOW_NEW));
|
|
|
|
lyx::dispatch(cmd);
|
2009-05-11 23:53:50 +00:00
|
|
|
}
|
2007-11-12 23:23:19 +00:00
|
|
|
break;
|
2010-06-07 21:57:37 +00:00
|
|
|
}
|
2007-11-13 14:04:32 +00:00
|
|
|
|
2007-11-23 12:37:09 +00:00
|
|
|
case LFUN_BUFFER_NEXT:
|
2009-03-25 14:34:42 +00:00
|
|
|
gotoNextOrPreviousBuffer(NEXTBUFFER);
|
2007-11-23 12:37:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_PREVIOUS:
|
2009-03-25 14:34:42 +00:00
|
|
|
gotoNextOrPreviousBuffer(PREVBUFFER);
|
2007-11-23 12:37:09 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-14 11:14:06 +00:00
|
|
|
case LFUN_COMMAND_EXECUTE: {
|
|
|
|
bool const show_it = cmd.argument() != "off";
|
2008-05-27 11:15:17 +00:00
|
|
|
// FIXME: this is a hack, "minibuffer" should not be
|
|
|
|
// hardcoded.
|
2008-05-27 16:15:56 +00:00
|
|
|
if (GuiToolbar * t = toolbar("minibuffer")) {
|
2008-05-27 11:15:17 +00:00
|
|
|
t->setVisible(show_it);
|
2008-05-27 17:29:36 +00:00
|
|
|
if (show_it && t->commandBuffer())
|
|
|
|
t->commandBuffer()->setFocus();
|
2008-05-27 16:15:56 +00:00
|
|
|
}
|
2007-11-13 14:04:32 +00:00
|
|
|
break;
|
2007-11-14 11:14:06 +00:00
|
|
|
}
|
2007-11-13 14:49:50 +00:00
|
|
|
case LFUN_DROP_LAYOUTS_CHOICE:
|
2009-08-14 22:58:57 +00:00
|
|
|
d.layout_->showPopup();
|
2007-11-13 14:49:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_MENU_OPEN:
|
2008-03-09 11:22:39 +00:00
|
|
|
if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument()), *this))
|
2007-12-26 12:40:58 +00:00
|
|
|
menu->exec(QCursor::pos());
|
2007-11-13 14:49:50 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-02 17:50:08 +00:00
|
|
|
case LFUN_FILE_INSERT:
|
|
|
|
insertLyXFile(cmd.argument());
|
|
|
|
break;
|
2010-10-18 14:20:03 +00:00
|
|
|
|
2007-12-02 20:05:17 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2011-12-05 13:12:57 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA: {
|
|
|
|
bool const as_paragraph = (cmd.action() == LFUN_FILE_INSERT_PLAINTEXT_PARA);
|
|
|
|
string const fname = to_utf8(cmd.argument());
|
|
|
|
if (!fname.empty() && !FileName::isAbsolute(fname)) {
|
|
|
|
dr.setMessage(_("Absolute filename expected."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileName filename(fname);
|
|
|
|
if (fname.empty()) {
|
|
|
|
FileDialog dlg(qt_("Select file to insert"), (as_paragraph ?
|
|
|
|
LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
|
|
|
|
|
|
|
|
FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
|
|
|
|
QStringList(qt_("All Files (*)")));
|
|
|
|
|
|
|
|
if (result.first == FileDialog::Later || result.second.isEmpty()) {
|
|
|
|
dr.setMessage(_("Canceled."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
filename.set(fromqstr(result.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bv) {
|
|
|
|
FuncRequest const new_cmd(cmd, filename.absoluteFilePath());
|
|
|
|
bv->dispatch(new_cmd, dr);
|
|
|
|
}
|
2007-12-02 20:05:17 +00:00
|
|
|
break;
|
2011-12-05 13:12:57 +00:00
|
|
|
}
|
2007-12-02 20:05:17 +00:00
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_BUFFER_RELOAD: {
|
2009-09-12 20:55:35 +00:00
|
|
|
LASSERT(doc_buffer, break);
|
2010-10-25 16:10:01 +00:00
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
if (!doc_buffer->isClean()) {
|
2010-10-27 17:02:42 +00:00
|
|
|
docstring const file =
|
2010-10-25 16:10:01 +00:00
|
|
|
makeDisplayPath(doc_buffer->absFileName(), 20);
|
|
|
|
docstring text = bformat(_("Any changes will be lost. "
|
|
|
|
"Are you sure you want to revert to the saved version "
|
|
|
|
"of the document %1$s?"), file);
|
|
|
|
ret = Alert::prompt(_("Revert to saved document?"),
|
|
|
|
text, 1, 1, _("&Revert"), _("&Cancel"));
|
|
|
|
}
|
2009-09-12 20:41:24 +00:00
|
|
|
|
2009-11-23 22:40:59 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
doc_buffer->markClean();
|
2010-10-29 18:50:48 +00:00
|
|
|
reloadBuffer(*doc_buffer);
|
2010-07-09 14:37:00 +00:00
|
|
|
dr.forceBufferUpdate();
|
2009-11-23 22:40:59 +00:00
|
|
|
}
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
case LFUN_BUFFER_WRITE:
|
2009-09-12 20:55:35 +00:00
|
|
|
LASSERT(doc_buffer, break);
|
|
|
|
saveBuffer(*doc_buffer);
|
2007-12-04 22:21:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_WRITE_AS:
|
2009-09-12 20:55:35 +00:00
|
|
|
LASSERT(doc_buffer, break);
|
|
|
|
renameBuffer(*doc_buffer, cmd.argument());
|
2007-12-04 22:21:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_WRITE_ALL: {
|
|
|
|
Buffer * first = theBufferList().first();
|
|
|
|
if (!first)
|
|
|
|
break;
|
|
|
|
message(_("Saving all documents..."));
|
|
|
|
// We cannot use a for loop as the buffer list cycles.
|
|
|
|
Buffer * b = first;
|
|
|
|
do {
|
2008-03-26 10:32:20 +00:00
|
|
|
if (!b->isClean()) {
|
|
|
|
saveBuffer(*b);
|
|
|
|
LYXERR(Debug::ACTION, "Saved " << b->absFileName());
|
|
|
|
}
|
2007-12-04 22:21:25 +00:00
|
|
|
b = theBufferList().next(b);
|
2010-09-07 14:11:28 +00:00
|
|
|
} while (b != first);
|
2010-01-30 15:40:18 +00:00
|
|
|
dr.setMessage(_("All documents saved."));
|
2007-12-04 22:21:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-02 17:50:08 +00:00
|
|
|
|
2009-09-19 14:34:46 +00:00
|
|
|
case LFUN_BUFFER_CLOSE:
|
|
|
|
closeBuffer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_CLOSE_ALL:
|
|
|
|
closeBufferAll();
|
|
|
|
break;
|
|
|
|
|
2007-11-13 14:49:50 +00:00
|
|
|
case LFUN_TOOLBAR_TOGGLE: {
|
|
|
|
string const name = cmd.getArg(0);
|
2008-05-27 11:15:17 +00:00
|
|
|
if (GuiToolbar * t = toolbar(name))
|
|
|
|
t->toggle();
|
2007-11-13 14:49:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-19 20:56:05 +00:00
|
|
|
case LFUN_DIALOG_UPDATE: {
|
|
|
|
string const name = to_utf8(cmd.argument());
|
2010-10-21 18:20:12 +00:00
|
|
|
if (name == "prefs" || name == "document")
|
|
|
|
updateDialog(name, string());
|
|
|
|
else if (name == "paragraph")
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
|
|
|
|
else if (currentBufferView()) {
|
2009-09-27 10:29:13 +00:00
|
|
|
Inset * inset = currentBufferView()->editedInset(name);
|
|
|
|
// Can only update a dialog connected to an existing inset
|
2010-10-21 18:20:12 +00:00
|
|
|
if (inset) {
|
|
|
|
// FIXME: get rid of this indirection; GuiView ask the inset
|
|
|
|
// if he is kind enough to update itself...
|
|
|
|
FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
|
|
|
|
//FIXME: pass DispatchResult here?
|
|
|
|
inset->dispatch(currentBufferView()->cursor(), fr);
|
|
|
|
}
|
2010-10-27 17:02:42 +00:00
|
|
|
}
|
2007-11-19 20:56:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_DIALOG_TOGGLE: {
|
2011-02-13 10:00:42 +00:00
|
|
|
FuncCode const func_code = isDialogVisible(cmd.getArg(0))
|
|
|
|
? LFUN_DIALOG_HIDE : LFUN_DIALOG_SHOW;
|
|
|
|
dispatch(FuncRequest(func_code, cmd.argument()), dr);
|
2007-11-19 20:56:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_DIALOG_DISCONNECT_INSET:
|
|
|
|
disconnectDialog(to_utf8(cmd.argument()));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_DIALOG_HIDE: {
|
|
|
|
guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_DIALOG_SHOW: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
string data = trim(to_utf8(cmd.argument()).substr(name.size()));
|
|
|
|
|
|
|
|
if (name == "character") {
|
|
|
|
data = freefont2string();
|
|
|
|
if (!data.empty())
|
|
|
|
showDialog("character", data);
|
|
|
|
} else if (name == "latexlog") {
|
2010-09-07 14:11:28 +00:00
|
|
|
Buffer::LogType type;
|
2009-09-12 20:55:35 +00:00
|
|
|
string const logfile = doc_buffer->logName(&type);
|
2007-11-19 20:56:05 +00:00
|
|
|
switch (type) {
|
|
|
|
case Buffer::latexlog:
|
|
|
|
data = "latex ";
|
|
|
|
break;
|
|
|
|
case Buffer::buildlog:
|
|
|
|
data = "literate ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
data += Lexer::quoteString(logfile);
|
|
|
|
showDialog("log", data);
|
|
|
|
} else if (name == "vclog") {
|
|
|
|
string const data = "vc " +
|
2009-09-12 20:55:35 +00:00
|
|
|
Lexer::quoteString(doc_buffer->lyxvc().getLogFile());
|
2007-11-19 20:56:05 +00:00
|
|
|
showDialog("log", data);
|
2008-02-07 13:18:07 +00:00
|
|
|
} else if (name == "symbols") {
|
|
|
|
data = bv->cursor().getEncoding()->name();
|
|
|
|
if (!data.empty())
|
|
|
|
showDialog("symbols", data);
|
2008-11-15 16:33:02 +00:00
|
|
|
// bug 5274
|
|
|
|
} else if (name == "prefs" && isFullScreen()) {
|
2010-01-30 16:41:28 +00:00
|
|
|
lfunUiToggle("fullscreen");
|
2008-11-15 16:33:02 +00:00
|
|
|
showDialog("prefs", data);
|
2007-11-19 20:56:05 +00:00
|
|
|
} else
|
|
|
|
showDialog(name, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-19 11:54:23 +00:00
|
|
|
case LFUN_MESSAGE:
|
2010-01-30 15:40:18 +00:00
|
|
|
dr.setMessage(cmd.argument());
|
2009-09-19 11:54:23 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-30 16:41:28 +00:00
|
|
|
case LFUN_UI_TOGGLE: {
|
|
|
|
string arg = cmd.getArg(0);
|
|
|
|
if (!lfunUiToggle(arg)) {
|
|
|
|
docstring const msg = "ui-toggle " + _("%1$s unknown command!");
|
|
|
|
dr.setMessage(bformat(msg, from_utf8(arg)));
|
|
|
|
}
|
2008-02-20 15:11:47 +00:00
|
|
|
// Make sure the keyboard focus stays in the work area.
|
|
|
|
setFocus();
|
2008-02-07 00:12:48 +00:00
|
|
|
break;
|
2010-01-30 16:41:28 +00:00
|
|
|
}
|
2008-02-07 00:12:48 +00:00
|
|
|
|
2012-09-29 15:33:46 +00:00
|
|
|
case LFUN_VIEW_SPLIT: {
|
2009-09-12 20:55:35 +00:00
|
|
|
LASSERT(doc_buffer, break);
|
|
|
|
string const orientation = cmd.getArg(0);
|
|
|
|
d.splitter_->setOrientation(orientation == "vertical"
|
|
|
|
? Qt::Vertical : Qt::Horizontal);
|
|
|
|
TabWorkArea * twa = addTabWorkArea();
|
|
|
|
GuiWorkArea * wa = twa->addWorkArea(*doc_buffer, *this);
|
|
|
|
setCurrentWorkArea(wa);
|
2008-02-22 17:36:40 +00:00
|
|
|
break;
|
2009-09-12 20:55:35 +00:00
|
|
|
}
|
2012-09-29 15:16:52 +00:00
|
|
|
case LFUN_TAB_GROUP_CLOSE:
|
2008-02-21 15:09:10 +00:00
|
|
|
if (TabWorkArea * twa = d.currentTabWorkArea()) {
|
2009-08-21 20:29:40 +00:00
|
|
|
closeTabWorkArea(twa);
|
2009-08-15 15:47:12 +00:00
|
|
|
d.current_work_area_ = 0;
|
2008-02-21 15:09:10 +00:00
|
|
|
twa = d.currentTabWorkArea();
|
|
|
|
// Switch to the next GuiWorkArea in the found TabWorkArea.
|
2008-07-10 12:44:50 +00:00
|
|
|
if (twa) {
|
|
|
|
// Make sure the work area is up to date.
|
2008-11-16 01:20:34 +00:00
|
|
|
setCurrentWorkArea(twa->currentWorkArea());
|
2008-07-10 12:44:50 +00:00
|
|
|
} else {
|
2008-11-16 01:20:34 +00:00
|
|
|
setCurrentWorkArea(0);
|
2008-07-10 12:44:50 +00:00
|
|
|
}
|
2008-02-21 15:09:10 +00:00
|
|
|
}
|
2008-02-22 17:36:40 +00:00
|
|
|
break;
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2012-09-15 22:37:55 +00:00
|
|
|
case LFUN_VIEW_CLOSE:
|
|
|
|
if (TabWorkArea * twa = d.currentTabWorkArea()) {
|
|
|
|
closeWorkArea(twa->currentWorkArea());
|
|
|
|
d.current_work_area_ = 0;
|
|
|
|
twa = d.currentTabWorkArea();
|
|
|
|
// Switch to the next GuiWorkArea in the found TabWorkArea.
|
|
|
|
if (twa) {
|
|
|
|
// Make sure the work area is up to date.
|
|
|
|
setCurrentWorkArea(twa->currentWorkArea());
|
|
|
|
} else {
|
|
|
|
setCurrentWorkArea(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-09-08 00:27:07 +00:00
|
|
|
case LFUN_COMPLETION_INLINE:
|
|
|
|
if (d.current_work_area_)
|
|
|
|
d.current_work_area_->completer().showInline();
|
|
|
|
break;
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
case LFUN_COMPLETION_POPUP:
|
|
|
|
if (d.current_work_area_)
|
|
|
|
d.current_work_area_->completer().showPopup();
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LFUN_COMPLETION_COMPLETE:
|
|
|
|
if (d.current_work_area_)
|
|
|
|
d.current_work_area_->completer().tab();
|
2008-02-21 14:53:09 +00:00
|
|
|
break;
|
|
|
|
|
2008-09-08 00:13:55 +00:00
|
|
|
case LFUN_COMPLETION_CANCEL:
|
|
|
|
if (d.current_work_area_) {
|
|
|
|
if (d.current_work_area_->completer().popupVisible())
|
|
|
|
d.current_work_area_->completer().hidePopup();
|
|
|
|
else
|
|
|
|
d.current_work_area_->completer().hideInline();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-09-08 00:24:47 +00:00
|
|
|
case LFUN_COMPLETION_ACCEPT:
|
|
|
|
if (d.current_work_area_)
|
|
|
|
d.current_work_area_->completer().activate();
|
|
|
|
break;
|
|
|
|
|
2009-04-04 09:14:38 +00:00
|
|
|
case LFUN_BUFFER_ZOOM_IN:
|
|
|
|
case LFUN_BUFFER_ZOOM_OUT:
|
|
|
|
if (cmd.argument().empty()) {
|
2010-04-09 19:00:42 +00:00
|
|
|
if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
|
2009-04-04 09:14:38 +00:00
|
|
|
lyxrc.zoom += 20;
|
|
|
|
else
|
|
|
|
lyxrc.zoom -= 20;
|
|
|
|
} else
|
|
|
|
lyxrc.zoom += convert<int>(cmd.argument());
|
|
|
|
|
|
|
|
if (lyxrc.zoom < 10)
|
|
|
|
lyxrc.zoom = 10;
|
2010-09-07 14:11:28 +00:00
|
|
|
|
2009-04-04 09:14:38 +00:00
|
|
|
// The global QPixmapCache is used in GuiPainter to cache text
|
|
|
|
// painting so we must reset it.
|
|
|
|
QPixmapCache::clear();
|
|
|
|
guiApp->fontLoader().update();
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
|
|
|
|
break;
|
2008-09-08 00:24:47 +00:00
|
|
|
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_REGISTER:
|
2013-02-05 20:31:58 +00:00
|
|
|
case LFUN_VC_RENAME:
|
|
|
|
case LFUN_VC_COPY:
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_CHECK_IN:
|
|
|
|
case LFUN_VC_CHECK_OUT:
|
2009-10-14 19:18:06 +00:00
|
|
|
case LFUN_VC_REPO_UPDATE:
|
2009-09-12 20:41:24 +00:00
|
|
|
case LFUN_VC_LOCKING_TOGGLE:
|
|
|
|
case LFUN_VC_REVERT:
|
|
|
|
case LFUN_VC_UNDO_LAST:
|
|
|
|
case LFUN_VC_COMMAND:
|
2010-02-15 09:05:16 +00:00
|
|
|
case LFUN_VC_COMPARE:
|
2010-10-17 10:44:53 +00:00
|
|
|
dispatchVC(cmd, dr);
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-23 13:45:58 +00:00
|
|
|
case LFUN_SERVER_GOTO_FILE_ROW:
|
|
|
|
goToFileRow(to_utf8(cmd.argument()));
|
|
|
|
break;
|
|
|
|
|
2010-04-15 13:19:48 +00:00
|
|
|
case LFUN_FORWARD_SEARCH: {
|
2011-02-12 20:24:09 +00:00
|
|
|
Buffer const * doc_master = doc_buffer->masterBuffer();
|
|
|
|
FileName const path(doc_master->temppath());
|
|
|
|
string const texname = doc_master->isChild(doc_buffer)
|
|
|
|
? DocFileName(changeExtension(
|
|
|
|
doc_buffer->absFileName(),
|
|
|
|
"tex")).mangledFileName()
|
|
|
|
: doc_buffer->latexName();
|
2012-08-26 09:42:43 +00:00
|
|
|
string const fulltexname =
|
|
|
|
support::makeAbsPath(texname, doc_master->temppath()).absFileName();
|
2011-02-12 20:24:09 +00:00
|
|
|
string const mastername =
|
|
|
|
removeExtension(doc_master->latexName());
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const dviname(addName(path.absFileName(),
|
2011-02-12 20:24:09 +00:00
|
|
|
addExtension(mastername, "dvi")));
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const pdfname(addName(path.absFileName(),
|
2011-02-12 20:24:09 +00:00
|
|
|
addExtension(mastername, "pdf")));
|
2011-05-25 13:06:33 +00:00
|
|
|
bool const have_dvi = dviname.exists();
|
|
|
|
bool const have_pdf = pdfname.exists();
|
|
|
|
if (!have_dvi && !have_pdf) {
|
2010-04-18 10:54:43 +00:00
|
|
|
dr.setMessage(_("Please, preview the document first."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
string outname = dviname.onlyFileName();
|
|
|
|
string command = lyxrc.forward_search_dvi;
|
2011-05-25 13:06:33 +00:00
|
|
|
if (!have_dvi || (have_pdf &&
|
|
|
|
pdfname.lastModified() > dviname.lastModified())) {
|
2010-04-18 10:54:43 +00:00
|
|
|
outname = pdfname.onlyFileName();
|
2010-04-15 23:32:52 +00:00
|
|
|
command = lyxrc.forward_search_pdf;
|
|
|
|
}
|
2010-04-15 13:19:48 +00:00
|
|
|
|
2012-01-20 10:44:07 +00:00
|
|
|
DocIterator tmpcur = bv->cursor();
|
|
|
|
// Leave math first
|
|
|
|
while (tmpcur.inMathed())
|
|
|
|
tmpcur.pop_back();
|
|
|
|
int row = tmpcur.inMathed() ? 0 : doc_buffer->texrow().getRowFromIdPos(
|
|
|
|
tmpcur.paragraph().id(), tmpcur.pos());
|
2010-04-16 18:30:52 +00:00
|
|
|
LYXERR(Debug::ACTION, "Forward search: row:" << row
|
2012-01-20 10:44:07 +00:00
|
|
|
<< " id:" << tmpcur.paragraph().id());
|
2010-04-16 08:18:28 +00:00
|
|
|
if (!row || command.empty()) {
|
|
|
|
dr.setMessage(_("Couldn't proceed."));
|
2010-04-15 13:19:48 +00:00
|
|
|
break;
|
2010-04-16 08:18:28 +00:00
|
|
|
}
|
2010-04-15 13:19:48 +00:00
|
|
|
string texrow = convert<string>(row);
|
|
|
|
|
|
|
|
command = subst(command, "$$n", texrow);
|
2012-08-26 09:42:43 +00:00
|
|
|
command = subst(command, "$$f", fulltexname);
|
2010-04-15 13:19:48 +00:00
|
|
|
command = subst(command, "$$t", texname);
|
|
|
|
command = subst(command, "$$o", outname);
|
|
|
|
|
2010-04-15 23:32:52 +00:00
|
|
|
PathChanger p(path);
|
2010-04-15 13:19:48 +00:00
|
|
|
Systemcall one;
|
2010-04-16 16:22:08 +00:00
|
|
|
one.startscript(Systemcall::DontWait, command);
|
2010-04-15 13:19:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-12 23:23:19 +00:00
|
|
|
default:
|
2010-12-04 22:48:08 +00:00
|
|
|
// The LFUN must be for one of BufferView, Buffer or Cursor;
|
|
|
|
// let's try that:
|
|
|
|
dispatchToBufferView(cmd, dr);
|
2008-05-15 09:14:09 +00:00
|
|
|
break;
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
2007-11-23 09:44:02 +00:00
|
|
|
|
2008-08-05 13:03:31 +00:00
|
|
|
// Part of automatic menu appearance feature.
|
2008-05-15 11:02:23 +00:00
|
|
|
if (isFullScreen()) {
|
2009-05-26 21:41:45 +00:00
|
|
|
if (menuBar()->isVisible() && lyxrc.full_screen_menubar)
|
2008-05-15 11:02:23 +00:00
|
|
|
menuBar()->hide();
|
|
|
|
if (statusBar()->isVisible())
|
|
|
|
statusBar()->hide();
|
|
|
|
}
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 16:41:28 +00:00
|
|
|
bool GuiView::lfunUiToggle(string const & ui_component)
|
2008-02-09 17:54:28 +00:00
|
|
|
{
|
2010-01-30 16:41:28 +00:00
|
|
|
if (ui_component == "scrollbar") {
|
2008-02-11 23:52:25 +00:00
|
|
|
// hide() is of no help
|
|
|
|
if (d.current_work_area_->verticalScrollBarPolicy() ==
|
|
|
|
Qt::ScrollBarAlwaysOff)
|
|
|
|
|
|
|
|
d.current_work_area_->setVerticalScrollBarPolicy(
|
|
|
|
Qt::ScrollBarAsNeeded);
|
|
|
|
else
|
|
|
|
d.current_work_area_->setVerticalScrollBarPolicy(
|
|
|
|
Qt::ScrollBarAlwaysOff);
|
2010-01-30 16:41:28 +00:00
|
|
|
} else if (ui_component == "statusbar") {
|
2008-02-09 17:54:28 +00:00
|
|
|
statusBar()->setVisible(!statusBar()->isVisible());
|
2010-01-30 16:41:28 +00:00
|
|
|
} else if (ui_component == "menubar") {
|
2008-02-09 17:54:28 +00:00
|
|
|
menuBar()->setVisible(!menuBar()->isVisible());
|
2010-01-30 16:41:28 +00:00
|
|
|
} else
|
|
|
|
if (ui_component == "frame") {
|
2008-02-09 17:54:28 +00:00
|
|
|
int l, t, r, b;
|
|
|
|
getContentsMargins(&l, &t, &r, &b);
|
|
|
|
//are the frames in default state?
|
2008-03-04 18:53:44 +00:00
|
|
|
d.current_work_area_->setFrameStyle(QFrame::NoFrame);
|
2008-02-09 17:54:28 +00:00
|
|
|
if (l == 0) {
|
|
|
|
setContentsMargins(-2, -2, -2, -2);
|
|
|
|
} else {
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
|
|
|
}
|
2010-01-30 16:41:28 +00:00
|
|
|
} else
|
|
|
|
if (ui_component == "fullscreen") {
|
2008-05-27 12:01:50 +00:00
|
|
|
toggleFullScreen();
|
2010-01-30 16:41:28 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
return true;
|
2008-05-27 12:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::toggleFullScreen()
|
|
|
|
{
|
2008-02-09 17:54:28 +00:00
|
|
|
if (isFullScreen()) {
|
2008-02-20 14:27:52 +00:00
|
|
|
for (int i = 0; i != d.splitter_->count(); ++i)
|
|
|
|
d.tabWorkArea(i)->setFullScreen(false);
|
2008-02-09 17:54:28 +00:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2008-03-30 22:27:17 +00:00
|
|
|
setWindowState(windowState() ^ Qt::WindowFullScreen);
|
2008-05-27 13:30:40 +00:00
|
|
|
restoreLayout();
|
2008-02-09 17:54:28 +00:00
|
|
|
menuBar()->show();
|
|
|
|
statusBar()->show();
|
|
|
|
} else {
|
2008-11-15 16:33:02 +00:00
|
|
|
// bug 5274
|
|
|
|
hideDialogs("prefs", 0);
|
2008-02-09 18:29:15 +00:00
|
|
|
for (int i = 0; i != d.splitter_->count(); ++i)
|
|
|
|
d.tabWorkArea(i)->setFullScreen(true);
|
2008-02-09 17:54:28 +00:00
|
|
|
setContentsMargins(-2, -2, -2, -2);
|
2008-05-27 13:16:50 +00:00
|
|
|
saveLayout();
|
2008-03-30 22:27:17 +00:00
|
|
|
setWindowState(windowState() ^ Qt::WindowFullScreen);
|
2008-02-20 14:27:52 +00:00
|
|
|
statusBar()->hide();
|
2009-05-26 21:41:45 +00:00
|
|
|
if (lyxrc.full_screen_menubar)
|
|
|
|
menuBar()->hide();
|
2008-05-27 11:34:59 +00:00
|
|
|
if (lyxrc.full_screen_toolbars) {
|
|
|
|
ToolbarMap::iterator end = d.toolbars_.end();
|
|
|
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
|
|
|
it->second->hide();
|
|
|
|
}
|
2008-02-09 17:54:28 +00:00
|
|
|
}
|
2008-10-23 20:46:53 +00:00
|
|
|
|
|
|
|
// give dialogs like the TOC a chance to adapt
|
|
|
|
updateDialogs();
|
2008-02-09 17:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-12 23:23:19 +00:00
|
|
|
Buffer const * GuiView::updateInset(Inset const * inset)
|
|
|
|
{
|
2010-04-05 14:24:27 +00:00
|
|
|
if (!inset)
|
2007-11-12 23:23:19 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-04-05 14:24:27 +00:00
|
|
|
Buffer const * inset_buffer = &(inset->buffer());
|
2007-11-13 09:52:28 +00:00
|
|
|
|
2010-04-05 14:24:27 +00:00
|
|
|
for (int i = 0; i != d.splitter_->count(); ++i) {
|
|
|
|
GuiWorkArea * wa = d.tabWorkArea(i)->currentWorkArea();
|
|
|
|
if (!wa)
|
|
|
|
continue;
|
|
|
|
Buffer const * buffer = &(wa->bufferView().buffer());
|
|
|
|
if (inset_buffer == buffer)
|
|
|
|
wa->scheduleRedraw();
|
|
|
|
}
|
|
|
|
return inset_buffer;
|
2007-11-13 09:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::restartCursor()
|
|
|
|
{
|
|
|
|
/* When we move around, or type, it's nice to be able to see
|
|
|
|
* the cursor immediately after the keypress.
|
|
|
|
*/
|
|
|
|
if (d.current_work_area_)
|
|
|
|
d.current_work_area_->startBlinkingCursor();
|
2007-11-20 22:23:06 +00:00
|
|
|
|
2008-02-27 11:23:41 +00:00
|
|
|
// Take this occasion to update the other GUI elements.
|
2008-05-02 20:58:25 +00:00
|
|
|
updateDialogs();
|
2008-06-12 16:00:36 +00:00
|
|
|
updateStatusBar();
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
2008-02-29 09:18:46 +00:00
|
|
|
void GuiView::updateCompletion(Cursor & cur, bool start, bool keep)
|
2008-02-21 19:42:34 +00:00
|
|
|
{
|
|
|
|
if (d.current_work_area_)
|
2008-02-29 09:18:46 +00:00
|
|
|
d.current_work_area_->completer().updateVisibility(cur, start, keep);
|
2008-02-21 19:42:34 +00:00
|
|
|
}
|
|
|
|
|
2007-11-18 23:49:52 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// This list should be kept in sync with the list of insets in
|
|
|
|
// src/insets/Inset.cpp. I.e., if a dialog goes with an inset, the
|
|
|
|
// dialog should have the same name as the inset.
|
2008-06-24 23:07:38 +00:00
|
|
|
// Changes should be also recorded in LFUN_DIALOG_SHOW doxygen
|
|
|
|
// docs in LyXAction.cpp.
|
2007-11-18 23:49:52 +00:00
|
|
|
|
|
|
|
char const * const dialognames[] = {
|
2010-09-07 11:28:57 +00:00
|
|
|
|
2007-11-18 23:49:52 +00:00
|
|
|
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
|
2010-09-07 11:28:57 +00:00
|
|
|
"citation", "compare", "comparehistory", "document", "errorlist", "ert",
|
|
|
|
"external", "file", "findreplace", "findreplaceadv", "float", "graphics",
|
|
|
|
"href", "include", "index", "index_print", "info", "listings", "label", "line",
|
2010-09-07 00:41:00 +00:00
|
|
|
"log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
|
|
|
|
"nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref",
|
|
|
|
"sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate",
|
2010-09-07 11:28:57 +00:00
|
|
|
"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", "progress"};
|
2007-11-18 23:49:52 +00:00
|
|
|
|
|
|
|
char const * const * const end_dialognames =
|
|
|
|
dialognames + (sizeof(dialognames) / sizeof(char *));
|
|
|
|
|
|
|
|
class cmpCStr {
|
|
|
|
public:
|
|
|
|
cmpCStr(char const * name) : name_(name) {}
|
|
|
|
bool operator()(char const * other) {
|
|
|
|
return strcmp(other, name_) == 0;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
char const * name_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool isValidName(string const & name)
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
return find_if(dialognames, end_dialognames,
|
2010-03-05 18:07:05 +00:00
|
|
|
cmpCStr(name.c_str())) != end_dialognames;
|
2007-11-18 23:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2007-11-18 00:01:14 +00:00
|
|
|
|
2007-11-21 15:12:47 +00:00
|
|
|
void GuiView::resetDialogs()
|
|
|
|
{
|
2010-02-09 17:06:40 +00:00
|
|
|
// Make sure that no LFUN uses any GuiView.
|
2009-09-22 21:25:32 +00:00
|
|
|
guiApp->setCurrentView(0);
|
2008-06-25 18:03:38 +00:00
|
|
|
saveLayout();
|
2011-01-03 16:49:15 +00:00
|
|
|
saveUISettings();
|
2008-06-25 18:03:38 +00:00
|
|
|
menuBar()->clear();
|
|
|
|
constructToolbars();
|
2008-10-22 18:02:09 +00:00
|
|
|
guiApp->menus().fillMenuBar(menuBar(), this, false);
|
2009-08-14 22:58:57 +00:00
|
|
|
d.layout_->updateContents(true);
|
2007-11-22 07:33:18 +00:00
|
|
|
// Now update controls with current buffer.
|
2009-09-22 21:25:32 +00:00
|
|
|
guiApp->setCurrentView(this);
|
2008-06-25 18:03:38 +00:00
|
|
|
restoreLayout();
|
2007-11-22 07:33:18 +00:00
|
|
|
restartCursor();
|
2007-11-21 15:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-25 07:23:30 +00:00
|
|
|
Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
|
2007-11-18 00:01:14 +00:00
|
|
|
{
|
|
|
|
if (!isValidName(name))
|
|
|
|
return 0;
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
|
2007-11-18 00:01:14 +00:00
|
|
|
|
2008-10-03 13:17:22 +00:00
|
|
|
if (it != d.dialogs_.end()) {
|
|
|
|
if (hide_it)
|
|
|
|
it->second->hideView();
|
2007-11-18 00:01:14 +00:00
|
|
|
return it->second.get();
|
2008-10-03 13:17:22 +00:00
|
|
|
}
|
2007-11-18 00:01:14 +00:00
|
|
|
|
2007-12-10 13:05:00 +00:00
|
|
|
Dialog * dialog = build(name);
|
|
|
|
d.dialogs_[name].reset(dialog);
|
|
|
|
if (lyxrc.allow_geometry_session)
|
|
|
|
dialog->restoreSession();
|
2008-06-25 07:23:30 +00:00
|
|
|
if (hide_it)
|
|
|
|
dialog->hideView();
|
2007-12-10 13:05:00 +00:00
|
|
|
return dialog;
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::showDialog(string const & name, string const & data,
|
|
|
|
Inset * inset)
|
2009-12-21 13:11:17 +00:00
|
|
|
{
|
|
|
|
triggerShowDialog(toqstr(name), toqstr(data), inset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::doShowDialog(QString const & qname, QString const & qdata,
|
|
|
|
Inset * inset)
|
2007-11-18 00:01:14 +00:00
|
|
|
{
|
2007-11-18 23:30:41 +00:00
|
|
|
if (d.in_show_)
|
2007-11-18 00:01:14 +00:00
|
|
|
return;
|
|
|
|
|
2009-12-21 13:11:17 +00:00
|
|
|
const string name = fromqstr(qname);
|
|
|
|
const string data = fromqstr(qdata);
|
|
|
|
|
2007-11-18 23:30:41 +00:00
|
|
|
d.in_show_ = true;
|
2008-08-13 14:25:56 +00:00
|
|
|
try {
|
|
|
|
Dialog * dialog = findOrBuild(name, false);
|
|
|
|
if (dialog) {
|
2010-04-26 10:03:09 +00:00
|
|
|
bool const visible = dialog->isVisibleView();
|
2008-08-13 14:25:56 +00:00
|
|
|
dialog->showData(data);
|
2009-09-27 10:29:13 +00:00
|
|
|
if (inset && currentBufferView())
|
|
|
|
currentBufferView()->editInset(name, inset);
|
2010-04-26 10:03:09 +00:00
|
|
|
// We only set the focus to the new dialog if it was not yet
|
|
|
|
// visible in order not to change the existing previous behaviour
|
2010-09-07 14:11:28 +00:00
|
|
|
if (visible) {
|
2010-04-26 10:03:09 +00:00
|
|
|
// activateWindow is needed for floating dockviews
|
2010-04-26 10:26:06 +00:00
|
|
|
dialog->asQWidget()->raise();
|
2010-04-26 10:03:09 +00:00
|
|
|
dialog->asQWidget()->activateWindow();
|
|
|
|
dialog->asQWidget()->setFocus();
|
|
|
|
}
|
2008-08-13 14:25:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ExceptionMessage const & ex) {
|
|
|
|
d.in_show_ = false;
|
|
|
|
throw ex;
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
2007-11-18 23:30:41 +00:00
|
|
|
d.in_show_ = false;
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiView::isDialogVisible(string const & name) const
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (it == d.dialogs_.end())
|
|
|
|
return false;
|
2009-05-14 23:46:42 +00:00
|
|
|
return it->second.get()->isVisibleView() && !it->second.get()->isClosing();
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::hideDialog(string const & name, Inset * inset)
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (it == d.dialogs_.end())
|
|
|
|
return;
|
|
|
|
|
2011-01-03 23:23:09 +00:00
|
|
|
if (inset) {
|
|
|
|
if (!currentBufferView())
|
|
|
|
return;
|
|
|
|
if (inset != currentBufferView()->editedInset(name))
|
|
|
|
return;
|
|
|
|
}
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
Dialog * const dialog = it->second.get();
|
|
|
|
if (dialog->isVisibleView())
|
2007-12-09 22:35:04 +00:00
|
|
|
dialog->hideView();
|
2009-09-27 10:29:13 +00:00
|
|
|
if (currentBufferView())
|
|
|
|
currentBufferView()->editInset(name, 0);
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::disconnectDialog(string const & name)
|
|
|
|
{
|
|
|
|
if (!isValidName(name))
|
|
|
|
return;
|
2009-09-27 10:29:13 +00:00
|
|
|
if (currentBufferView())
|
|
|
|
currentBufferView()->editInset(name, 0);
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiView::hideAll() const
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
|
|
|
|
map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
for(; it != end; ++it)
|
2007-12-09 22:35:04 +00:00
|
|
|
it->second->hideView();
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-27 22:24:20 +00:00
|
|
|
void GuiView::updateDialogs()
|
2007-11-18 00:01:14 +00:00
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
|
|
|
|
map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
for(; it != end; ++it) {
|
|
|
|
Dialog * dialog = it->second.get();
|
2010-01-13 20:25:17 +00:00
|
|
|
if (dialog) {
|
Fix bug #6451 (last part): Crash when interacting with buffer-dependent dialog with no buffer open.
- First, the comment for isBufferDependent is corrected. It seems that the actual use of this function differs from the comment. As the comment said, I decided to close all dialogs that were buffer dependent, but this didn't seem to be correct for the view source pan, the outliner, and find-and-replace.
- Second, the dialogs that are buffer dependent are now closed, but dockviews are not, except for the spellchecker pane, which really depends on an open buffer, but I can't test that.
So, please test whether the spellchecker dockviewed window behaves as one expects.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34291 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-26 02:12:10 +00:00
|
|
|
if (dialog->needBufferOpen() && !documentBufferView())
|
2010-01-13 20:25:17 +00:00
|
|
|
hideDialog(fromqstr(dialog->name()), 0);
|
|
|
|
else if (dialog->isVisibleView())
|
|
|
|
dialog->checkStatus();
|
|
|
|
}
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
2008-04-27 22:24:20 +00:00
|
|
|
updateToolbars();
|
|
|
|
updateLayoutList();
|
2007-11-18 00:01:14 +00:00
|
|
|
}
|
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
Dialog * createDialog(GuiView & lv, string const & name);
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
// will be replaced by a proper factory...
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiAbout(GuiView & lv);
|
|
|
|
Dialog * createGuiBibtex(GuiView & lv);
|
|
|
|
Dialog * createGuiChanges(GuiView & lv);
|
|
|
|
Dialog * createGuiCharacter(GuiView & lv);
|
|
|
|
Dialog * createGuiCitation(GuiView & lv);
|
2009-10-24 15:47:05 +00:00
|
|
|
Dialog * createGuiCompare(GuiView & lv);
|
2010-09-07 11:28:57 +00:00
|
|
|
Dialog * createGuiCompareHistory(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiDelimiter(GuiView & lv);
|
|
|
|
Dialog * createGuiDocument(GuiView & lv);
|
|
|
|
Dialog * createGuiErrorList(GuiView & lv);
|
|
|
|
Dialog * createGuiExternal(GuiView & lv);
|
|
|
|
Dialog * createGuiGraphics(GuiView & lv);
|
|
|
|
Dialog * createGuiInclude(GuiView & lv);
|
2009-04-17 09:22:44 +00:00
|
|
|
Dialog * createGuiIndex(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiListings(GuiView & lv);
|
|
|
|
Dialog * createGuiLog(GuiView & lv);
|
|
|
|
Dialog * createGuiMathMatrix(GuiView & lv);
|
2009-01-25 23:50:54 +00:00
|
|
|
Dialog * createGuiNote(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiParagraph(GuiView & lv);
|
2009-02-05 18:09:36 +00:00
|
|
|
Dialog * createGuiPhantom(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiPreferences(GuiView & lv);
|
|
|
|
Dialog * createGuiPrint(GuiView & lv);
|
2009-04-17 14:29:32 +00:00
|
|
|
Dialog * createGuiPrintindex(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiRef(GuiView & lv);
|
|
|
|
Dialog * createGuiSearch(GuiView & lv);
|
2008-11-16 01:20:34 +00:00
|
|
|
Dialog * createGuiSearchAdv(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiSendTo(GuiView & lv);
|
|
|
|
Dialog * createGuiShowFile(GuiView & lv);
|
|
|
|
Dialog * createGuiSpellchecker(GuiView & lv);
|
2008-02-07 13:18:07 +00:00
|
|
|
Dialog * createGuiSymbols(GuiView & lv);
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiTabularCreate(GuiView & lv);
|
|
|
|
Dialog * createGuiTexInfo(GuiView & lv);
|
|
|
|
Dialog * createGuiToc(GuiView & lv);
|
|
|
|
Dialog * createGuiThesaurus(GuiView & lv);
|
|
|
|
Dialog * createGuiViewSource(GuiView & lv);
|
|
|
|
Dialog * createGuiWrap(GuiView & lv);
|
2009-12-22 10:04:30 +00:00
|
|
|
Dialog * createGuiProgressView(GuiView & lv);
|
2009-12-21 11:48:19 +00:00
|
|
|
|
|
|
|
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
Dialog * GuiView::build(string const & name)
|
|
|
|
{
|
2008-09-29 08:42:18 +00:00
|
|
|
LASSERT(isValidName(name), return 0);
|
2007-11-18 00:01:14 +00:00
|
|
|
|
2010-02-15 23:17:45 +00:00
|
|
|
Dialog * dialog = createDialog(*this, name);
|
|
|
|
if (dialog)
|
|
|
|
return dialog;
|
|
|
|
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "aboutlyx")
|
|
|
|
return createGuiAbout(*this);
|
|
|
|
if (name == "bibtex")
|
|
|
|
return createGuiBibtex(*this);
|
|
|
|
if (name == "changes")
|
|
|
|
return createGuiChanges(*this);
|
|
|
|
if (name == "character")
|
|
|
|
return createGuiCharacter(*this);
|
|
|
|
if (name == "citation")
|
|
|
|
return createGuiCitation(*this);
|
2009-10-24 15:47:05 +00:00
|
|
|
if (name == "compare")
|
|
|
|
return createGuiCompare(*this);
|
2010-09-07 11:28:57 +00:00
|
|
|
if (name == "comparehistory")
|
|
|
|
return createGuiCompareHistory(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "document")
|
|
|
|
return createGuiDocument(*this);
|
|
|
|
if (name == "errorlist")
|
|
|
|
return createGuiErrorList(*this);
|
|
|
|
if (name == "external")
|
|
|
|
return createGuiExternal(*this);
|
|
|
|
if (name == "file")
|
|
|
|
return createGuiShowFile(*this);
|
|
|
|
if (name == "findreplace")
|
|
|
|
return createGuiSearch(*this);
|
2008-11-16 01:20:34 +00:00
|
|
|
if (name == "findreplaceadv")
|
|
|
|
return createGuiSearchAdv(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "graphics")
|
|
|
|
return createGuiGraphics(*this);
|
|
|
|
if (name == "include")
|
|
|
|
return createGuiInclude(*this);
|
2009-04-17 09:22:44 +00:00
|
|
|
if (name == "index")
|
|
|
|
return createGuiIndex(*this);
|
2009-05-22 16:41:20 +00:00
|
|
|
if (name == "index_print")
|
|
|
|
return createGuiPrintindex(*this);
|
|
|
|
if (name == "listings")
|
|
|
|
return createGuiListings(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "log")
|
|
|
|
return createGuiLog(*this);
|
|
|
|
if (name == "mathdelimiter")
|
|
|
|
return createGuiDelimiter(*this);
|
|
|
|
if (name == "mathmatrix")
|
|
|
|
return createGuiMathMatrix(*this);
|
2009-01-25 23:50:54 +00:00
|
|
|
if (name == "note")
|
|
|
|
return createGuiNote(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "paragraph")
|
|
|
|
return createGuiParagraph(*this);
|
2009-02-05 18:09:36 +00:00
|
|
|
if (name == "phantom")
|
|
|
|
return createGuiPhantom(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "prefs")
|
|
|
|
return createGuiPreferences(*this);
|
|
|
|
if (name == "print")
|
|
|
|
return createGuiPrint(*this);
|
|
|
|
if (name == "ref")
|
|
|
|
return createGuiRef(*this);
|
|
|
|
if (name == "sendto")
|
|
|
|
return createGuiSendTo(*this);
|
|
|
|
if (name == "spellchecker")
|
|
|
|
return createGuiSpellchecker(*this);
|
2008-02-07 13:18:07 +00:00
|
|
|
if (name == "symbols")
|
|
|
|
return createGuiSymbols(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "tabularcreate")
|
|
|
|
return createGuiTabularCreate(*this);
|
|
|
|
if (name == "texinfo")
|
|
|
|
return createGuiTexInfo(*this);
|
|
|
|
if (name == "thesaurus")
|
|
|
|
return createGuiThesaurus(*this);
|
2009-02-05 18:09:36 +00:00
|
|
|
if (name == "toc")
|
|
|
|
return createGuiToc(*this);
|
2009-05-22 16:41:20 +00:00
|
|
|
if (name == "view-source")
|
|
|
|
return createGuiViewSource(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
if (name == "wrap")
|
|
|
|
return createGuiWrap(*this);
|
2009-12-22 10:04:30 +00:00
|
|
|
if (name == "progress")
|
|
|
|
return createGuiProgressView(*this);
|
2007-11-18 00:01:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiView.cpp"
|