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"
|
|
|
|
|
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"
|
2015-05-19 20:46:06 +00:00
|
|
|
#include "support/filetools.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-04 22:21:25 +00:00
|
|
|
#include "frontends/alert.h"
|
2013-05-21 01:47:16 +00:00
|
|
|
#include "frontends/KeySymbol.h"
|
2007-12-04 22:21:25 +00:00
|
|
|
|
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"
|
2013-05-23 02:58:58 +00:00
|
|
|
#include "Session.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>
|
2015-05-19 20:46:06 +00:00
|
|
|
#include <QSvgRenderer>
|
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
|
|
|
|
2014-11-19 21:45:25 +00:00
|
|
|
// sync with GuiAlert.cpp
|
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:
|
2015-05-19 20:46:06 +00:00
|
|
|
BackgroundWidget(int width, int height)
|
|
|
|
: width_(width), height_(height)
|
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");
|
2015-05-20 06:46:26 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2015-05-19 20:46:06 +00:00
|
|
|
QString imagedir = "images/";
|
|
|
|
FileName fname = imageLibFileSearch(imagedir, "banner", "svgz");
|
|
|
|
QSvgRenderer svgRenderer(toqstr(fname.absFileName()));
|
|
|
|
if (svgRenderer.isValid()) {
|
|
|
|
splash_ = QPixmap(splashSize());
|
|
|
|
QPainter painter(&splash_);
|
|
|
|
svgRenderer.render(&painter);
|
|
|
|
splash_.setDevicePixelRatio(pixelRatio());
|
|
|
|
} else {
|
|
|
|
splash_ = getPixmap("images/", "banner", "png");
|
|
|
|
}
|
2015-05-20 05:51:50 +00:00
|
|
|
#else
|
2015-05-20 06:46:26 +00:00
|
|
|
splash_ = getPixmap("images/", "banner", "svgz,png");
|
2015-05-20 05:51:50 +00:00
|
|
|
#endif
|
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));
|
2015-05-19 20:46:06 +00:00
|
|
|
qreal const fsize = fontSize();
|
|
|
|
QPointF const position = textPosition();
|
2014-10-21 11:48:14 +00:00
|
|
|
LYXERR(Debug::GUI,
|
|
|
|
"widget pixel ratio: " << pixelRatio() <<
|
|
|
|
" splash pixel ratio: " << splashPixelRatio() <<
|
2015-05-19 20:46:06 +00:00
|
|
|
" version text size,position: " << fsize << "@" << position.x() << "+" << position.y());
|
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);
|
2015-05-19 20:46:06 +00:00
|
|
|
font.setPointSizeF(fsize);
|
2007-08-21 07:33:46 +00:00
|
|
|
pain.setFont(font);
|
2015-05-19 20:46:06 +00:00
|
|
|
pain.drawText(position, 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
|
|
|
{
|
2015-05-19 20:46:06 +00:00
|
|
|
int const w = width_;
|
|
|
|
int const h = height_;
|
2014-10-21 11:48:14 +00:00
|
|
|
int const x = (width() - w) / 2;
|
|
|
|
int const y = (height() - h) / 2;
|
2014-10-20 15:37:12 +00:00
|
|
|
LYXERR(Debug::GUI,
|
2014-10-21 11:48:14 +00:00
|
|
|
"widget pixel ratio: " << pixelRatio() <<
|
|
|
|
" splash pixel ratio: " << splashPixelRatio() <<
|
|
|
|
" paint pixmap: " << w << "x" << h << "@" << x << "+" << y);
|
2007-08-21 07:33:46 +00:00
|
|
|
QPainter pain(this);
|
2014-10-20 15:37:12 +00:00
|
|
|
pain.drawPixmap(x, y, w, h, 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_;
|
2015-05-19 20:46:06 +00:00
|
|
|
int const width_;
|
|
|
|
int const height_;
|
2014-10-20 15:37:12 +00:00
|
|
|
|
|
|
|
/// Current ratio between physical pixels and device-independent pixels
|
|
|
|
double pixelRatio() const {
|
|
|
|
#if QT_VERSION >= 0x050000
|
2017-01-22 00:06:00 +00:00
|
|
|
return qt_scale_factor * devicePixelRatio();
|
2014-10-20 15:37:12 +00:00
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-22 19:53:37 +00:00
|
|
|
qreal fontSize() const {
|
2015-05-28 06:01:58 +00:00
|
|
|
return toqstr(lyxrc.font_sizes[FONT_SIZE_NORMAL]).toDouble();
|
2015-05-19 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 19:53:37 +00:00
|
|
|
QPointF textPosition() const {
|
2015-05-28 06:01:58 +00:00
|
|
|
return QPointF(width_/2 - 18, height_/2 + 45);
|
2015-05-19 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 19:53:37 +00:00
|
|
|
QSize splashSize() const {
|
2015-05-22 20:04:10 +00:00
|
|
|
return QSize(
|
2015-05-22 19:53:37 +00:00
|
|
|
static_cast<unsigned int>(width_ * pixelRatio()),
|
|
|
|
static_cast<unsigned int>(height_ * pixelRatio()));
|
2015-05-19 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 15:37:12 +00:00
|
|
|
/// Ratio between physical pixels and device-independent pixels of splash image
|
|
|
|
double splashPixelRatio() const {
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
return splash_.devicePixelRatio();
|
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
|
|
|
}
|
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
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2008-05-27 11:15:17 +00:00
|
|
|
|
|
|
|
|
2015-09-20 17:43:06 +00:00
|
|
|
class GuiView::GuiViewPrivate
|
2006-10-31 14:12:46 +00:00
|
|
|
{
|
2015-09-20 17:43:06 +00:00
|
|
|
/// noncopyable
|
|
|
|
GuiViewPrivate(GuiViewPrivate const &);
|
|
|
|
void operator=(GuiViewPrivate const &);
|
|
|
|
public:
|
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
|
2015-03-12 23:47:21 +00:00
|
|
|
hugeIconSize = 32; // better for hires displays
|
|
|
|
giantIconSize = 48;
|
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;
|
2015-03-12 23:47:21 +00:00
|
|
|
else if (image.width() > int(giantIconSize))
|
|
|
|
normalIconSize = giantIconSize;
|
2011-03-22 23:41:26 +00:00
|
|
|
else
|
|
|
|
normalIconSize = image.width();
|
|
|
|
}
|
|
|
|
|
2007-11-18 23:30:41 +00:00
|
|
|
splitter_ = new QSplitter;
|
2015-05-19 20:46:06 +00:00
|
|
|
bg_widget_ = new BackgroundWidget(400, 250);
|
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-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
|
|
|
}
|
|
|
|
|
2016-11-23 16:30:49 +00:00
|
|
|
QSize iconSize(docstring const & icon_size)
|
|
|
|
{
|
2016-11-23 16:43:37 +00:00
|
|
|
unsigned int size;
|
2016-11-23 16:30:49 +00:00
|
|
|
if (icon_size == "small")
|
|
|
|
size = smallIconSize;
|
|
|
|
else if (icon_size == "normal")
|
|
|
|
size = normalIconSize;
|
|
|
|
else if (icon_size == "big")
|
|
|
|
size = bigIconSize;
|
|
|
|
else if (icon_size == "huge")
|
|
|
|
size = hugeIconSize;
|
|
|
|
else if (icon_size == "giant")
|
|
|
|
size = giantIconSize;
|
|
|
|
else
|
|
|
|
size = icon_size.empty() ? normalIconSize : convert<int>(icon_size);
|
|
|
|
|
|
|
|
if (size < smallIconSize)
|
|
|
|
size = smallIconSize;
|
|
|
|
|
|
|
|
return QSize(size, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize iconSize(QString const & icon_size)
|
|
|
|
{
|
|
|
|
return iconSize(qstring_to_ucs4(icon_size));
|
|
|
|
}
|
|
|
|
|
|
|
|
string & iconSize(QSize const & qsize)
|
|
|
|
{
|
|
|
|
LATTEST(qsize.width() == qsize.height());
|
|
|
|
|
|
|
|
static string icon_size;
|
|
|
|
|
2016-11-23 16:43:37 +00:00
|
|
|
unsigned int size = qsize.width();
|
2016-11-23 16:30:49 +00:00
|
|
|
|
|
|
|
if (size < smallIconSize)
|
|
|
|
size = smallIconSize;
|
|
|
|
|
|
|
|
if (size == smallIconSize)
|
|
|
|
icon_size = "small";
|
|
|
|
else if (size == normalIconSize)
|
|
|
|
icon_size = "normal";
|
|
|
|
else if (size == bigIconSize)
|
|
|
|
icon_size = "big";
|
|
|
|
else if (size == hugeIconSize)
|
|
|
|
icon_size = "huge";
|
|
|
|
else if (size == giantIconSize)
|
|
|
|
icon_size = "giant";
|
|
|
|
else
|
|
|
|
icon_size = convert<string>(size);
|
|
|
|
|
|
|
|
return icon_size;
|
|
|
|
}
|
|
|
|
|
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;
|
2015-03-12 23:47:21 +00:00
|
|
|
unsigned int hugeIconSize;
|
|
|
|
unsigned int giantIconSize;
|
2007-11-18 23:30:41 +00:00
|
|
|
///
|
|
|
|
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)
|
2015-04-18 17:10:33 +00:00
|
|
|
: d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0),
|
2017-07-23 22:21:43 +00:00
|
|
|
command_execute_(false), minibuffer_focus_(false), devel_mode_(false)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2016-10-09 22:14:57 +00:00
|
|
|
connect(this, SIGNAL(bufferViewChanged()),
|
2016-11-09 22:37:35 +00:00
|
|
|
this, SLOT(onBufferViewChanged()));
|
2016-10-09 22:14:57 +00:00
|
|
|
|
2007-12-26 10:55:43 +00:00
|
|
|
// GuiToolbars *must* be initialised before the menu bar.
|
2016-10-09 07:15:20 +00:00
|
|
|
setIconSize(QSize(d.normalIconSize, d.normalIconSize)); // 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) {
|
2017-05-28 11:25:53 +00:00
|
|
|
// The connection is closed when this is destroyed.
|
|
|
|
d.autosave_timeout_.timeout.connect([this](){ autoSave();});
|
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
|
|
|
|
2014-08-25 18:08:59 +00:00
|
|
|
#if !(defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)) && !defined(Q_OS_MAC)
|
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.
|
2015-03-12 23:47:21 +00:00
|
|
|
setWindowIcon(QIcon::fromTheme("lyx", getPixmap("images/", "lyx", "svg,png")));
|
2011-12-07 16:47:43 +00:00
|
|
|
#else
|
2015-03-12 23:47:21 +00:00
|
|
|
setWindowIcon(getPixmap("images/", "lyx", "svg,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
|
2016-09-06 09:17:10 +00:00
|
|
|
resetWindowTitle();
|
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);
|
2014-10-18 13:50:22 +00:00
|
|
|
search_mode mode = theGuiApp()->imageSearchMode();
|
|
|
|
QString fn = toqstr(lyx::libFileSearch("images", "busy", "gif", mode).absFileName());
|
2011-01-23 09:17:52 +00:00
|
|
|
QMovie * busyanim = new QMovie(fn, QByteArray(), busylabel);
|
|
|
|
busylabel->setMovie(busyanim);
|
|
|
|
busyanim->start();
|
|
|
|
busylabel->hide();
|
2011-01-24 11:38:13 +00:00
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
connect(&d.processing_thread_watcher_, SIGNAL(started()),
|
2011-01-23 09:17:52 +00:00
|
|
|
busylabel, SLOT(show()));
|
2017-07-03 17:53:14 +00:00
|
|
|
connect(&d.processing_thread_watcher_, SIGNAL(finished()),
|
2011-01-23 09:17:52 +00:00
|
|
|
busylabel, SLOT(hide()));
|
|
|
|
|
2016-09-06 09:17:10 +00:00
|
|
|
QFontMetrics const fm(statusBar()->fontMetrics());
|
2017-08-03 11:07:41 +00:00
|
|
|
int const iconheight = max(int(d.normalIconSize), fm.height());
|
|
|
|
QSize const iconsize(iconheight, iconheight);
|
|
|
|
|
|
|
|
QPixmap shellescape = QIcon(getPixmap("images/", "emblem-shellescape", "svgz,png")).pixmap(iconsize);
|
|
|
|
shell_escape_ = new QLabel(statusBar());
|
|
|
|
shell_escape_->setPixmap(shellescape);
|
|
|
|
shell_escape_->setScaledContents(true);
|
|
|
|
shell_escape_->setAlignment(Qt::AlignCenter);
|
|
|
|
shell_escape_->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
shell_escape_->setToolTip(qt_("WARNING: LaTeX is allowed to execute "
|
|
|
|
"external commands for this document. "
|
|
|
|
"Right click to change."));
|
|
|
|
SEMenu * menu = new SEMenu(this);
|
|
|
|
connect(shell_escape_, SIGNAL(customContextMenuRequested(QPoint)),
|
|
|
|
menu, SLOT(showMenu(QPoint)));
|
|
|
|
shell_escape_->hide();
|
|
|
|
statusBar()->addPermanentWidget(shell_escape_);
|
|
|
|
|
|
|
|
QPixmap readonly = QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")).pixmap(iconsize);
|
2016-09-06 09:17:10 +00:00
|
|
|
read_only_ = new QLabel(statusBar());
|
|
|
|
read_only_->setPixmap(readonly);
|
|
|
|
read_only_->setScaledContents(true);
|
|
|
|
read_only_->setAlignment(Qt::AlignCenter);
|
|
|
|
read_only_->hide();
|
|
|
|
statusBar()->addPermanentWidget(read_only_);
|
|
|
|
|
|
|
|
version_control_ = new QLabel(statusBar());
|
|
|
|
version_control_->setAlignment(Qt::AlignCenter);
|
|
|
|
version_control_->setFrameStyle(QFrame::StyledPanel);
|
|
|
|
version_control_->hide();
|
|
|
|
statusBar()->addPermanentWidget(version_control_);
|
|
|
|
|
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 *)));
|
|
|
|
|
2016-10-09 07:15:20 +00:00
|
|
|
// set custom application bars context menu, e.g. tool bar and menu bar
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
|
|
|
|
SLOT(toolBarPopup(const QPoint &)));
|
|
|
|
|
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-04-20 09:42:21 +00:00
|
|
|
if (restoreLayout())
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-03 11:07:41 +00:00
|
|
|
void GuiView::disableShellEscape()
|
|
|
|
{
|
|
|
|
BufferView * bv = documentBufferView();
|
|
|
|
if (!bv)
|
|
|
|
return;
|
|
|
|
theSession().shellescapeFiles().remove(bv->buffer().absFileName());
|
|
|
|
bv->buffer().params().shell_escape = false;
|
|
|
|
bv->processUpdateFlags(Update::Force);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-03-14 03:33:40 +00:00
|
|
|
docstring const fmt = theFormats().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);
|
2017-07-03 17:53:14 +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;
|
2017-09-06 16:11:31 +00:00
|
|
|
settings.setValue("zoom_ratio", zoom_ratio_);
|
2017-07-23 22:21:43 +00:00
|
|
|
settings.setValue("devel_mode", devel_mode_);
|
2008-09-22 06:50:35 +00:00
|
|
|
settings.beginGroup("views");
|
|
|
|
settings.beginGroup(QString::number(id_));
|
2015-01-11 18:36:41 +00:00
|
|
|
#if defined(Q_WS_X11) || defined(QPA_XCB)
|
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));
|
2016-11-23 16:30:49 +00:00
|
|
|
settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
|
2008-05-27 13:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-03 16:49:15 +00:00
|
|
|
void GuiView::saveUISettings() const
|
|
|
|
{
|
2017-10-18 11:12:20 +00:00
|
|
|
QSettings settings;
|
|
|
|
|
2011-01-03 16:49:15 +00:00
|
|
|
// Save the toolbar private states
|
|
|
|
ToolbarMap::iterator end = d.toolbars_.end();
|
|
|
|
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
|
2017-10-18 11:12:20 +00:00
|
|
|
it->second->saveSession(settings);
|
2011-01-03 16:49:15 +00:00
|
|
|
// Now take care of all other dialogs
|
|
|
|
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
|
|
|
|
for (; it!= d.dialogs_.end(); ++it)
|
2017-10-18 11:12:20 +00:00
|
|
|
it->second->saveSession(settings);
|
2011-01-03 16:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-20 09:40:40 +00:00
|
|
|
bool GuiView::restoreLayout()
|
2008-05-27 13:16:50 +00:00
|
|
|
{
|
|
|
|
QSettings settings;
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble();
|
|
|
|
// Actual zoom value: default zoom + fractional offset
|
|
|
|
int zoom = lyxrc.defaultZoom * zoom_ratio_;
|
|
|
|
if (zoom < static_cast<int>(zoom_min_))
|
|
|
|
zoom = zoom_min_;
|
|
|
|
lyxrc.currentZoom = zoom;
|
2017-07-23 22:21:43 +00:00
|
|
|
devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
|
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
|
2016-11-23 16:30:49 +00:00
|
|
|
setIconSize(d.iconSize(settings.value(icon_key).toString()));
|
2011-03-27 19:07:09 +00:00
|
|
|
|
2015-01-11 18:36:41 +00:00
|
|
|
#if defined(Q_WS_X11) || defined(QPA_XCB)
|
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();
|
2008-09-12 02:21:14 +00:00
|
|
|
|
2013-04-20 09:40:40 +00:00
|
|
|
if (!restoreState(settings.value("layout").toByteArray(), 0))
|
2008-05-27 11:15:17 +00:00
|
|
|
initToolbars();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-05-19 20:04:29 +00:00
|
|
|
// init the toolbars that have not been restored
|
|
|
|
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 && !tb->isRestored())
|
|
|
|
initToolbar(cit->name);
|
|
|
|
}
|
|
|
|
|
2016-11-24 12:10:03 +00:00
|
|
|
// update lock (all) toolbars positions
|
|
|
|
updateLockToolbars();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-24 12:10:03 +00:00
|
|
|
void GuiView::updateLockToolbars()
|
|
|
|
{
|
2017-05-07 12:18:17 +00:00
|
|
|
toolbarsMovable_ = false;
|
2016-11-24 12:10:03 +00:00
|
|
|
for (ToolbarInfo const & info : guiApp->toolbars()) {
|
|
|
|
GuiToolbar * tb = toolbar(info.name);
|
|
|
|
if (tb && tb->isMovable())
|
2017-05-07 12:18:17 +00:00
|
|
|
toolbarsMovable_ = true;
|
2016-11-24 12:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 11:15:17 +00:00
|
|
|
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();
|
2013-05-19 20:04:29 +00:00
|
|
|
for (; cit != end; ++cit)
|
|
|
|
initToolbar(cit->name);
|
|
|
|
}
|
2008-05-27 11:15:17 +00:00
|
|
|
|
|
|
|
|
2013-05-19 20:04:29 +00:00
|
|
|
void GuiView::initToolbar(string const & name)
|
|
|
|
{
|
|
|
|
GuiToolbar * tb = toolbar(name);
|
|
|
|
if (!tb)
|
|
|
|
return;
|
|
|
|
int const visibility = guiApp->toolbars().defaultVisibility(name);
|
|
|
|
bool newline = !(visibility & Toolbars::SAMEROW);
|
|
|
|
tb->setVisible(false);
|
|
|
|
tb->setVisibility(visibility);
|
|
|
|
|
|
|
|
if (visibility & Toolbars::TOP) {
|
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::TopToolBarArea);
|
|
|
|
addToolBar(Qt::TopToolBarArea, tb);
|
|
|
|
}
|
2008-05-27 11:15:17 +00:00
|
|
|
|
2013-05-19 20:04:29 +00:00
|
|
|
if (visibility & Toolbars::BOTTOM) {
|
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::BottomToolBarArea);
|
|
|
|
addToolBar(Qt::BottomToolBarArea, tb);
|
|
|
|
}
|
2008-05-27 11:15:17 +00:00
|
|
|
|
2013-05-19 20:04:29 +00:00
|
|
|
if (visibility & Toolbars::LEFT) {
|
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::LeftToolBarArea);
|
|
|
|
addToolBar(Qt::LeftToolBarArea, tb);
|
2008-05-27 11:15:17 +00:00
|
|
|
}
|
2013-05-19 20:04:29 +00:00
|
|
|
|
|
|
|
if (visibility & Toolbars::RIGHT) {
|
|
|
|
if (newline)
|
|
|
|
addToolBarBreak(Qt::RightToolBarArea);
|
|
|
|
addToolBar(Qt::RightToolBarArea, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibility & Toolbars::ON)
|
|
|
|
tb->setVisible(true);
|
2016-11-24 12:10:03 +00:00
|
|
|
|
|
|
|
tb->setMovable(true);
|
2008-05-27 11:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-08 17:09:00 +00:00
|
|
|
bool GuiView::hasFocus() const
|
|
|
|
{
|
|
|
|
if (currentWorkArea())
|
|
|
|
return currentWorkArea()->hasFocus();
|
|
|
|
if (currentMainWorkArea())
|
|
|
|
return currentMainWorkArea()->hasFocus();
|
|
|
|
return d.bg_widget_->hasFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-10 19:08:41 +00:00
|
|
|
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-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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-06 11:50:32 +00:00
|
|
|
bool GuiView::prepareAllBuffersForLogout()
|
|
|
|
{
|
|
|
|
Buffer * first = theBufferList().first();
|
|
|
|
if (!first)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// First, iterate over all buffers and ask the users if unsaved
|
|
|
|
// changes should be saved.
|
|
|
|
// We cannot use a for loop as the buffer list cycles.
|
|
|
|
Buffer * b = first;
|
|
|
|
do {
|
|
|
|
if (!saveBufferIfNeeded(const_cast<Buffer &>(*b), false))
|
|
|
|
return false;
|
|
|
|
b = theBufferList().next(b);
|
|
|
|
} while (b != first);
|
|
|
|
|
|
|
|
// Next, save session state
|
|
|
|
// When a view/window was closed before without quitting LyX, there
|
|
|
|
// are already entries in the lastOpened list.
|
|
|
|
theSession().lastOpened().clear();
|
|
|
|
writeSession();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()) {
|
2017-07-03 17:53:14 +00:00
|
|
|
Alert::warning(_("Exit LyX"),
|
2010-11-18 23:12:46 +00:00
|
|
|
_("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-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;
|
2016-09-06 09:17:10 +00:00
|
|
|
Buffer const & buf = wa->bufferView().buffer();
|
|
|
|
// Set the windows title
|
|
|
|
docstring title = buf.fileName().displayName(130) + from_ascii("[*]");
|
2017-02-28 21:58:44 +00:00
|
|
|
if (buf.notifiesExternalModification()) {
|
|
|
|
title = bformat(_("%1$s (modified externally)"), title);
|
|
|
|
// If the external modification status has changed, then maybe the status of
|
|
|
|
// buffer-save has changed too.
|
|
|
|
updateToolbars();
|
|
|
|
}
|
2016-09-06 09:17:10 +00:00
|
|
|
#ifndef Q_WS_MAC
|
2016-09-21 11:56:28 +00:00
|
|
|
title += from_ascii(" - LyX");
|
2014-03-17 16:46:14 +00:00
|
|
|
#endif
|
2016-09-06 09:17:10 +00:00
|
|
|
setWindowTitle(toqstr(title));
|
2016-09-14 20:33:56 +00:00
|
|
|
// Sets the path for the window: this is used by OSX to
|
|
|
|
// allow a context click on the title bar showing a menu
|
|
|
|
// with the path up to the file
|
|
|
|
setWindowFilePath(toqstr(buf.absFileName()));
|
|
|
|
// Tell Qt whether the current document is changed
|
|
|
|
setWindowModified(!buf.isClean());
|
2016-09-06 09:17:10 +00:00
|
|
|
|
2017-08-03 11:07:41 +00:00
|
|
|
if (buf.params().shell_escape)
|
|
|
|
shell_escape_->show();
|
|
|
|
else
|
|
|
|
shell_escape_->hide();
|
|
|
|
|
2017-03-01 21:03:44 +00:00
|
|
|
if (buf.hasReadonlyFlag())
|
2016-09-06 09:17:10 +00:00
|
|
|
read_only_->show();
|
|
|
|
else
|
|
|
|
read_only_->hide();
|
|
|
|
|
|
|
|
if (buf.lyxvc().inUse()) {
|
|
|
|
version_control_->show();
|
2016-10-19 09:55:08 +00:00
|
|
|
version_control_->setText(toqstr(buf.lyxvc().vcstatus()));
|
2016-09-06 09:17:10 +00:00
|
|
|
} else
|
|
|
|
version_control_->hide();
|
2007-11-11 22:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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_)
|
2016-09-28 19:33:44 +00:00
|
|
|
// disconnect the current work area from all slots
|
|
|
|
QObject::disconnect(d.current_work_area_, 0, this, 0);
|
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 *)),
|
2016-09-28 19:33:44 +00:00
|
|
|
this, SLOT(updateWindowTitle(GuiWorkArea *)));
|
|
|
|
QObject::connect(wa, SIGNAL(busy(bool)),
|
|
|
|
this, SLOT(setBusy(bool)));
|
2016-11-09 21:54:27 +00:00
|
|
|
// connection of a signal to a signal
|
2016-09-28 19:33:44 +00:00
|
|
|
QObject::connect(wa, SIGNAL(bufferViewChanged()),
|
|
|
|
this, SIGNAL(bufferViewChanged()));
|
|
|
|
Q_EMIT updateWindowTitle(wa);
|
|
|
|
Q_EMIT bufferViewChanged();
|
2016-10-09 22:14:57 +00:00
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
2016-10-09 22:14:57 +00:00
|
|
|
|
2016-11-09 22:37:35 +00:00
|
|
|
void GuiView::onBufferViewChanged()
|
2016-10-09 22:14:57 +00:00
|
|
|
{
|
2008-04-27 22:24:20 +00:00
|
|
|
structureChanged();
|
|
|
|
// 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.
|
2016-09-28 19:33:44 +00:00
|
|
|
Q_EMIT bufferViewChanged();
|
2008-06-20 06:35:42 +00:00
|
|
|
|
2016-09-06 09:17:10 +00:00
|
|
|
resetWindowTitle();
|
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
|
|
|
|
2014-08-25 18:08:59 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2008-06-20 06:35:42 +00:00
|
|
|
// 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)
|
2017-07-23 22:21:43 +00:00
|
|
|
msg = toqstr(bv->cursor().currentState(devel_mode_));
|
2009-09-30 07:40:27 +00:00
|
|
|
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);
|
2016-09-28 19:33:44 +00:00
|
|
|
if (d.current_work_area_)
|
|
|
|
on_currentWorkAreaChanged(d.current_work_area_);
|
|
|
|
else
|
2016-09-06 09:17:10 +00:00
|
|
|
resetWindowTitle();
|
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
|
|
|
}
|
|
|
|
|
2016-09-06 09:17:10 +00:00
|
|
|
void GuiView::resetWindowTitle()
|
2008-08-11 12:57:02 +00:00
|
|
|
{
|
2010-03-05 18:07:05 +00:00
|
|
|
setWindowTitle(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();
|
2017-07-03 17:53:14 +00:00
|
|
|
updateLayoutList();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 11:03:21 +00:00
|
|
|
|
2015-04-18 17:10:33 +00:00
|
|
|
void GuiView::resetCommandExecute()
|
|
|
|
{
|
|
|
|
command_execute_ = false;
|
|
|
|
updateToolbars();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-12 17:23:13 +00:00
|
|
|
double GuiView::pixelRatio() const
|
|
|
|
{
|
2014-10-18 13:50:22 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
2017-01-22 00:06:00 +00:00
|
|
|
return qt_scale_factor * devicePixelRatio();
|
2014-10-12 17:23:13 +00:00
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
|
|
|
}
|
2017-03-01 23:41:02 +00:00
|
|
|
|
|
|
|
|
2010-11-30 13:03:46 +00:00
|
|
|
GuiWorkArea * GuiView::workArea(int index)
|
|
|
|
{
|
|
|
|
if (TabWorkArea * twa = d.currentTabWorkArea())
|
|
|
|
if (index < twa->count())
|
2017-03-01 23:41:02 +00:00
|
|
|
return twa->workArea(index);
|
2010-11-30 13:03:46 +00:00
|
|
|
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)
|
2015-10-10 19:44:08 +00:00
|
|
|
return 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();
|
2016-09-28 19:33:44 +00:00
|
|
|
Q_EMIT bufferViewChanged();
|
2008-11-16 01:20:34 +00:00
|
|
|
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;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
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)) {
|
2017-07-03 17:53:14 +00:00
|
|
|
LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea()
|
2010-11-02 15:33:52 +00:00
|
|
|
<< ", Current main wa: " << currentMainWorkArea());
|
2008-11-16 15:32:11 +00:00
|
|
|
return;
|
2008-11-16 01:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-11-02 15:33:52 +00:00
|
|
|
d.current_main_work_area_ = old_cmwa;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
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.
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(found_twa, return);
|
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_) {
|
2015-06-18 13:30:44 +00:00
|
|
|
int context = 0;
|
|
|
|
if (d.current_work_area_->bufferView().cursor().inMathed()
|
|
|
|
&& !d.current_work_area_->bufferView().cursor().inRegexped())
|
|
|
|
context |= Toolbars::MATH;
|
|
|
|
if (lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled())
|
|
|
|
context |= Toolbars::TABLE;
|
2016-01-30 23:14:36 +00:00
|
|
|
if (currentBufferView()->buffer().areChangesPresent()
|
|
|
|
|| (lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled()
|
2016-05-05 21:01:19 +00:00
|
|
|
&& lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onOff(true))
|
|
|
|
|| (lyx::getStatus(FuncRequest(LFUN_CHANGES_OUTPUT)).enabled()
|
|
|
|
&& lyx::getStatus(FuncRequest(LFUN_CHANGES_OUTPUT)).onOff(true)))
|
2015-06-18 13:30:44 +00:00
|
|
|
context |= Toolbars::REVIEW;
|
|
|
|
if (lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled())
|
|
|
|
context |= Toolbars::MATHMACROTEMPLATE;
|
|
|
|
if (lyx::getStatus(FuncRequest(LFUN_IN_IPA)).enabled())
|
|
|
|
context |= Toolbars::IPA;
|
2015-04-18 17:10:33 +00:00
|
|
|
if (command_execute_)
|
|
|
|
context |= Toolbars::MINIBUFFER;
|
2016-08-19 12:53:31 +00:00
|
|
|
if (minibuffer_focus_) {
|
|
|
|
context |= Toolbars::MINIBUFFER_FOCUS;
|
|
|
|
minibuffer_focus_ = false;
|
|
|
|
}
|
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)
|
2015-06-18 13:30:44 +00:00
|
|
|
it->second->update(context);
|
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)
|
2015-06-18 13:30:44 +00:00
|
|
|
it->second->update();
|
2007-10-01 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-10 19:51:44 +00:00
|
|
|
void GuiView::setBuffer(Buffer * newBuffer, bool switch_to)
|
2007-11-12 23:23:19 +00:00
|
|
|
{
|
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);
|
2017-07-03 17:53:14 +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());
|
2017-06-10 19:51:44 +00:00
|
|
|
if (switch_to)
|
|
|
|
setCurrentWorkArea(wa);
|
2007-11-12 23:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2016-12-31 14:16:15 +00:00
|
|
|
// This is called from the Buffer, which has no way to ensure that cursors
|
|
|
|
// in BufferView remain valid.
|
|
|
|
if (documentBufferView())
|
2017-02-01 09:11:20 +00:00
|
|
|
documentBufferView()->cursor().sanitize();
|
2016-05-30 21:11:00 +00:00
|
|
|
// FIXME: This is slightly expensive, though less than the tocBackend update
|
|
|
|
// (#9880). This also resets the view in the Toc Widget (#6675).
|
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
|
|
|
|
2015-05-28 11:27:53 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2015-05-08 17:09:00 +00:00
|
|
|
/* In LyX/Mac, when a dialog is open, the menus of the
|
|
|
|
application can still be accessed without giving focus to
|
|
|
|
the main window. In this case, we want to disable the menu
|
|
|
|
entries that are buffer-related.
|
2015-05-28 11:34:58 +00:00
|
|
|
This code must not be used on Linux and Windows, since it
|
|
|
|
would disable buffer-related entries when hovering over the
|
|
|
|
menu (see bug #9574).
|
2015-05-08 17:09:00 +00:00
|
|
|
*/
|
|
|
|
if (cmd.origin() == FuncRequest::MENU && !hasFocus()) {
|
|
|
|
buf = 0;
|
|
|
|
doc_buffer = 0;
|
|
|
|
}
|
2015-05-28 11:27:53 +00:00
|
|
|
#endif
|
2015-05-08 17:09:00 +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:
|
2013-07-09 14:28:58 +00:00
|
|
|
enable = doc_buffer
|
|
|
|
&& (doc_buffer->parent() != 0
|
|
|
|
|| doc_buffer->hasChildren())
|
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();
|
2016-10-21 02:56:40 +00:00
|
|
|
enable = doc_buffer->params().isExportable(format, true);
|
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()
|
2017-03-05 19:12:07 +00:00
|
|
|
&& doc_buffer->fileName().exists() && !doc_buffer->isClean();
|
2009-09-12 20:41:24 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-19 16:49:31 +00:00
|
|
|
case LFUN_BUFFER_CHILD_OPEN:
|
2015-09-28 18:40:56 +00:00
|
|
|
enable = doc_buffer != 0;
|
2009-09-19 16:49:31 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-01 20:16:37 +00:00
|
|
|
case LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR:
|
|
|
|
enable = doc_buffer && doc_buffer->notifiesExternalModification();
|
|
|
|
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:
|
2015-09-28 18:40:56 +00:00
|
|
|
enable = doc_buffer != 0;
|
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:
|
2015-09-28 18:40:56 +00:00
|
|
|
enable = doc_buffer != 0;
|
2009-09-19 14:34:46 +00:00
|
|
|
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;
|
|
|
|
|
2017-07-23 22:21:43 +00:00
|
|
|
case LFUN_DEVEL_MODE_TOGGLE:
|
|
|
|
flag.setOnOff(devel_mode_);
|
|
|
|
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
|
|
|
|
2016-11-24 12:10:03 +00:00
|
|
|
case LFUN_TOOLBAR_MOVABLE: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
// use negation since locked == !movable
|
2017-05-07 12:18:17 +00:00
|
|
|
if (name == "*")
|
2016-11-24 12:10:03 +00:00
|
|
|
// toolbar name * locks all toolbars
|
2017-05-07 12:18:17 +00:00
|
|
|
flag.setOnOff(!toolbarsMovable_);
|
|
|
|
else if (GuiToolbar * t = toolbar(name))
|
2016-11-24 12:10:03 +00:00
|
|
|
flag.setOnOff(!(t->isMovable()));
|
2017-05-07 12:18:17 +00:00
|
|
|
else {
|
2016-11-24 12:10:03 +00:00
|
|
|
enable = false;
|
|
|
|
docstring const msg =
|
|
|
|
bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
|
|
|
|
flag.message(msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-11-23 16:30:49 +00:00
|
|
|
case LFUN_ICON_SIZE:
|
|
|
|
flag.setOnOff(d.iconSize(cmd.argument()) == iconSize());
|
2016-10-09 07:15:20 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-04 21:03:37 +00:00
|
|
|
case LFUN_DROP_LAYOUTS_CHOICE:
|
2015-09-28 18:40:56 +00:00
|
|
|
enable = buf != 0;
|
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)));
|
2017-08-12 07:06:29 +00:00
|
|
|
// to set "enable"
|
|
|
|
// fall through
|
2007-11-19 20:56:05 +00:00
|
|
|
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";
|
2014-03-04 10:56:03 +00:00
|
|
|
else if (name == "character" || name == "symbols"
|
|
|
|
|| name == "mathdelimiter" || name == "mathmatrix") {
|
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")
|
2017-04-05 09:53:17 +00:00
|
|
|
enable = theSpellChecker()
|
2011-12-31 16:29:27 +00:00
|
|
|
&& !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;
|
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_COMPLETE:
|
2008-02-21 19:42:34 +00:00
|
|
|
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:
|
2016-07-19 05:44:39 +00:00
|
|
|
case LFUN_BUFFER_ZOOM_IN: {
|
|
|
|
// only diff between these two is that the default for ZOOM_OUT
|
|
|
|
// is a neg. number
|
|
|
|
bool const neg_zoom =
|
|
|
|
convert<int>(cmd.argument()) < 0 ||
|
|
|
|
(cmd.action() == LFUN_BUFFER_ZOOM_OUT && cmd.argument().empty());
|
2016-10-29 08:28:34 +00:00
|
|
|
if (lyxrc.currentZoom <= zoom_min_ && neg_zoom) {
|
2016-10-08 03:18:54 +00:00
|
|
|
docstring const msg =
|
2016-10-09 21:22:22 +00:00
|
|
|
bformat(_("Zoom level cannot be less than %1$d%."), zoom_min_);
|
2016-10-08 03:18:54 +00:00
|
|
|
flag.message(msg);
|
2016-07-19 05:44:39 +00:00
|
|
|
enable = false;
|
|
|
|
} else
|
|
|
|
enable = doc_buffer;
|
2009-04-04 09:14:38 +00:00
|
|
|
break;
|
2016-07-19 05:44:39 +00:00
|
|
|
}
|
2016-10-29 08:28:34 +00:00
|
|
|
|
|
|
|
case LFUN_BUFFER_ZOOM: {
|
|
|
|
bool const less_than_min_zoom =
|
|
|
|
!cmd.argument().empty() && convert<int>(cmd.argument()) < zoom_min_;
|
|
|
|
if (lyxrc.currentZoom <= zoom_min_ && less_than_min_zoom) {
|
|
|
|
docstring const msg =
|
|
|
|
bformat(_("Zoom level cannot be less than %1$d%."), zoom_min_);
|
|
|
|
flag.message(msg);
|
|
|
|
enable = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enable = doc_buffer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-08 03:18:21 +00:00
|
|
|
case LFUN_BUFFER_MOVE_NEXT:
|
|
|
|
case LFUN_BUFFER_MOVE_PREVIOUS:
|
|
|
|
// we do not cycle when moving
|
2015-04-08 02:59:34 +00:00
|
|
|
case LFUN_BUFFER_NEXT:
|
|
|
|
case LFUN_BUFFER_PREVIOUS:
|
2015-04-08 02:55:20 +00:00
|
|
|
// because we cycle, it doesn't matter whether on first or last
|
2015-04-08 16:58:03 +00:00
|
|
|
enable = (d.currentTabWorkArea()->count() > 1);
|
2009-09-12 21:12:24 +00:00
|
|
|
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:
|
2017-03-01 21:03:44 +00:00
|
|
|
enable = doc_buffer && !doc_buffer->hasReadonlyFlag()
|
2009-09-12 20:41:24 +00:00
|
|
|
&& 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:
|
2017-03-01 21:03:44 +00:00
|
|
|
enable = doc_buffer && doc_buffer->lyxvc().inUse()
|
|
|
|
&& !doc_buffer->hasReadonlyFlag();
|
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:
|
2016-08-04 05:20:14 +00:00
|
|
|
case LFUN_LYX_ACTIVATE:
|
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;
|
|
|
|
|
2013-03-24 18:20:19 +00:00
|
|
|
case LFUN_SPELLING_CONTINUOUSLY:
|
|
|
|
flag.setOnOff(lyxrc.spellcheck_continuously);
|
|
|
|
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()) {
|
2014-04-21 14:50:56 +00:00
|
|
|
FileDialog dlg(qt_("Select document to open"));
|
2008-03-05 23:10:53 +00:00
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
2017-04-18 07:32:22 +00:00
|
|
|
dlg.setButton2(qt_("Examples|#E#e"), toqstr(lyxrc.example_path));
|
2008-02-06 23:02:57 +00:00
|
|
|
|
2014-04-01 19:53:37 +00:00
|
|
|
QStringList const filter(qt_("LyX Documents (*.lyx)"));
|
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(),
|
2017-03-14 03:33:40 +00:00
|
|
|
theFormats().extension(*it));
|
2008-02-07 09:51:49 +00:00
|
|
|
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."),
|
2017-03-14 03:33:40 +00:00
|
|
|
theFormats().prettyName(format)));
|
2008-02-06 23:54:13 +00:00
|
|
|
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(),
|
2017-03-14 03:33:40 +00:00
|
|
|
theFormats().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"),
|
2017-03-14 03:33:40 +00:00
|
|
|
theFormats().prettyName(format));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
2014-04-21 14:50:56 +00:00
|
|
|
FileDialog dlg(toqstr(text));
|
2008-03-05 23:10:53 +00:00
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
2017-04-18 07:32:22 +00:00
|
|
|
dlg.setButton2(qt_("Examples|#E#e"), toqstr(lyxrc.example_path));
|
2008-02-06 23:54:13 +00:00
|
|
|
|
2017-03-14 03:33:40 +00:00
|
|
|
docstring filter = theFormats().prettyName(format);
|
2011-09-17 11:04:55 +00:00
|
|
|
filter += " (*.{";
|
2008-02-06 23:54:13 +00:00
|
|
|
// FIXME UNICODE
|
2017-03-14 03:33:40 +00:00
|
|
|
filter += from_utf8(theFormats().extensions(format));
|
2011-09-17 11:04:55 +00:00
|
|
|
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
|
|
|
|
2014-03-23 12:31:21 +00:00
|
|
|
// Can happen if the user entered a path into the dialog
|
|
|
|
// (see bug #7437)
|
|
|
|
if (fullname.onlyFileName().empty()) {
|
|
|
|
docstring msg = bformat(_("The file name '%1$s' is invalid!\n"
|
|
|
|
"Aborting import."),
|
|
|
|
from_utf8(fullname.absFileName()));
|
|
|
|
frontend::Alert::error(_("File name error"), msg);
|
|
|
|
message(_("Canceled."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2014-04-21 14:50:56 +00:00
|
|
|
FileDialog dlg(qt_("Select LyX document to insert"));
|
2010-10-29 16:51:50 +00:00
|
|
|
dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
2017-04-18 07:32:22 +00:00
|
|
|
dlg.setButton2(qt_("Examples|#E#e"), toqstr(lyxrc.example_path));
|
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
|
2014-04-21 14:50:56 +00:00
|
|
|
FileDialog dlg(qt_("Choose a filename to save document 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)
|
2013-10-04 13:01:42 +00:00
|
|
|
b.reload();
|
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
|
|
|
|
2013-11-15 08:20:07 +00:00
|
|
|
bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
|
2011-10-06 13:47:42 +00:00
|
|
|
{
|
|
|
|
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;
|
2013-11-15 07:57:11 +00:00
|
|
|
QString const anyformat = qt_("Guess from extension (*.*)");
|
2013-09-14 13:40:57 +00:00
|
|
|
types << anyformat;
|
2016-08-28 00:27:37 +00:00
|
|
|
|
2011-10-07 08:21:31 +00:00
|
|
|
vector<Format const *> export_formats;
|
2017-03-14 03:33:40 +00:00
|
|
|
for (Format const & f : theFormats())
|
2016-08-28 00:27:37 +00:00
|
|
|
if (f.documentFormat())
|
|
|
|
export_formats.push_back(&f);
|
|
|
|
sort(export_formats.begin(), export_formats.end(), Format::formatSorter);
|
2013-09-14 15:53:57 +00:00
|
|
|
map<QString, string> fmap;
|
2013-11-15 08:20:07 +00:00
|
|
|
QString filter;
|
|
|
|
string ext;
|
2016-08-28 00:27:37 +00:00
|
|
|
for (Format const * f : export_formats) {
|
|
|
|
docstring const loc_prettyname = translateIfPossible(f->prettyname());
|
2013-11-17 18:41:18 +00:00
|
|
|
QString const loc_filter = toqstr(bformat(from_ascii("%1$s (*.%2$s)"),
|
2013-09-14 15:53:57 +00:00
|
|
|
loc_prettyname,
|
2016-08-28 00:27:37 +00:00
|
|
|
from_ascii(f->extension())));
|
2013-09-14 15:53:57 +00:00
|
|
|
types << loc_filter;
|
2016-08-28 00:27:37 +00:00
|
|
|
fmap[loc_filter] = f->name();
|
|
|
|
if (from_ascii(f->name()) == iformat) {
|
2013-11-15 08:20:07 +00:00
|
|
|
filter = loc_filter;
|
2016-08-28 00:27:37 +00:00
|
|
|
ext = f->extension();
|
2013-11-15 08:20:07 +00:00
|
|
|
}
|
2013-09-14 11:11:10 +00:00
|
|
|
}
|
2013-11-15 08:20:07 +00:00
|
|
|
string ofname = fname.onlyFileName();
|
|
|
|
if (!ext.empty())
|
|
|
|
ofname = support::changeExtension(ofname, ext);
|
2011-10-06 13:47:42 +00:00
|
|
|
FileDialog::Result result =
|
|
|
|
dlg.save(toqstr(fname.onlyPath().absFileName()),
|
|
|
|
types,
|
2013-11-15 08:20:07 +00:00
|
|
|
toqstr(ofname),
|
2011-10-15 13:41:15 +00:00
|
|
|
&filter);
|
2011-10-06 13:47:42 +00:00
|
|
|
if (result.first != FileDialog::Chosen)
|
|
|
|
return false;
|
|
|
|
|
2011-10-07 08:21:31 +00:00
|
|
|
string fmt_name;
|
2011-10-06 13:47:42 +00:00
|
|
|
fname.set(fromqstr(result.second));
|
2013-09-14 13:40:57 +00:00
|
|
|
if (filter == anyformat)
|
2017-03-14 03:33:40 +00:00
|
|
|
fmt_name = theFormats().getFormatFromExtension(fname.extension());
|
2011-10-07 08:21:31 +00:00
|
|
|
else
|
2013-09-14 15:53:57 +00:00
|
|
|
fmt_name = fmap[filter];
|
|
|
|
LYXERR(Debug::FILES, "filter=" << fromqstr(filter)
|
2011-10-07 08:21:31 +00:00
|
|
|
<< ", 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;
|
2013-11-15 08:20:07 +00:00
|
|
|
case 1: return exportBufferAs(b, from_ascii(fmt_name));
|
2011-10-06 13:47:42 +00:00
|
|
|
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();
|
2016-06-12 04:12:03 +00:00
|
|
|
// coverity complained about this
|
|
|
|
// it seems unnecessary, but perhaps is worth the check
|
|
|
|
LASSERT(wa, return false);
|
|
|
|
|
2010-01-08 09:29:17 +00:00
|
|
|
setCurrentWorkArea(wa);
|
2009-08-15 21:29:14 +00:00
|
|
|
Buffer & buf = wa->bufferView().buffer();
|
2016-06-12 04:12:03 +00:00
|
|
|
return 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) {
|
2017-03-01 23:41:02 +00:00
|
|
|
GuiWorkArea * wa = twa->workArea(j);
|
2009-08-19 20:06:57 +00:00
|
|
|
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).
|
2015-11-30 03:24:55 +00:00
|
|
|
while (d.splitter_->count() > empty_twa) {
|
2009-08-18 20:12:34 +00:00
|
|
|
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();
|
|
|
|
|
2015-12-12 17:57:33 +00:00
|
|
|
if (GuiViewPrivate::busyBuffers.contains(&buf)) {
|
2017-07-03 17:53:14 +00:00
|
|
|
Alert::warning(_("Close document"),
|
2010-11-18 23:12:46 +00:00
|
|
|
_("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-18 21:18:21 +00:00
|
|
|
Buffer * child_buf = *it;
|
2016-01-05 14:53:42 +00:00
|
|
|
if (theBufferList().isOthersChild(&buf, child_buf)) {
|
|
|
|
child_buf->setParent(0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: should we look in other tabworkareas?
|
|
|
|
// ANSWER: I don't think so. I've tested, and if the child is
|
|
|
|
// open in some other window, it closes without a problem.
|
2009-08-18 21:18:21 +00:00
|
|
|
GuiWorkArea * child_wa = workArea(*child_buf);
|
|
|
|
if (child_wa) {
|
2016-01-05 14:53:42 +00:00
|
|
|
success = closeWorkArea(child_wa, true);
|
|
|
|
if (!success)
|
2010-12-09 21:35:39 +00:00
|
|
|
break;
|
2016-01-05 14:53:42 +00:00
|
|
|
} else {
|
|
|
|
// In this case the child buffer is open but hidden.
|
|
|
|
// It therefore should not (MUST NOT) be dirty!
|
|
|
|
LATTEST(child_buf->isClean());
|
|
|
|
theBufferList().release(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.
|
2016-01-05 14:53:42 +00:00
|
|
|
// FIXME: we should update only the bookmarks related to this buffer!
|
2010-12-09 21:35:39 +00:00
|
|
|
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()) {
|
2015-11-29 16:20:56 +00:00
|
|
|
twa->setCurrentIndex(twa->count() - 1);
|
2009-08-18 19:04:39 +00:00
|
|
|
|
|
|
|
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;
|
2017-06-11 04:01:04 +00:00
|
|
|
bool exists;
|
2007-12-04 22:21:25 +00:00
|
|
|
// FIXME: Unicode?
|
2017-06-11 04:01:04 +00:00
|
|
|
if (buf.isUnnamed()) {
|
2007-12-04 22:21:25 +00:00
|
|
|
file = from_utf8(buf.fileName().onlyFileName());
|
2017-06-11 04:01:04 +00:00
|
|
|
exists = false;
|
|
|
|
} else {
|
|
|
|
FileName filename = buf.fileName();
|
|
|
|
filename.refresh();
|
|
|
|
file = filename.displayName(30);
|
|
|
|
exists = filename.exists();
|
|
|
|
}
|
2007-12-04 22:21:25 +00:00
|
|
|
|
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 {
|
2017-06-11 04:01:04 +00:00
|
|
|
docstring const text = exists ?
|
|
|
|
bformat(_("The document %1$s has unsaved changes."
|
|
|
|
"\n\nDo you want to save the document or "
|
|
|
|
"discard the changes?"), file) :
|
|
|
|
bformat(_("The document %1$s has not been saved yet."
|
|
|
|
"\n\nDo you want to save the document or "
|
|
|
|
"discard it entirely?"), file);
|
|
|
|
docstring const title = exists ?
|
|
|
|
_("Save changed document?") : _("Save document?");
|
|
|
|
ret = Alert::prompt(title, text, 0, 2,
|
|
|
|
_("&Save"), _("&Discard"), _("&Cancel"));
|
2009-08-14 23:12:21 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-08 03:18:21 +00:00
|
|
|
void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np, bool const move)
|
2009-03-25 14:34:42 +00:00
|
|
|
{
|
2010-11-30 13:03:46 +00:00
|
|
|
if (!documentBufferView())
|
|
|
|
return;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-11-30 13:03:46 +00:00
|
|
|
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);
|
2015-04-08 03:18:21 +00:00
|
|
|
if (move)
|
|
|
|
twa->moveTab(i, next_index);
|
|
|
|
else
|
|
|
|
setBuffer(&workArea(next_index)->bufferView().buffer());
|
2010-11-30 13:03:46 +00:00
|
|
|
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
|
|
|
{
|
2017-10-03 21:21:21 +00:00
|
|
|
currentBufferView()->cursor().reset();
|
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;
|
2017-03-05 19:12:07 +00:00
|
|
|
if (buf->fileName().exists() && buf->isChecksumModified()) {
|
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);
|
2014-02-17 20:47:22 +00:00
|
|
|
dr.clearMessageUpdate();
|
2010-10-17 10:44:53 +00:00
|
|
|
}
|
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;
|
2017-03-01 21:03:44 +00:00
|
|
|
if (buffer->lyxvc().inUse() && !buffer->hasReadonlyFlag()) {
|
2013-02-05 20:31:58 +00:00
|
|
|
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;
|
2017-03-01 21:03:44 +00:00
|
|
|
if (buffer->lyxvc().inUse() && !buffer->hasReadonlyFlag()) {
|
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
|
2015-02-09 23:42:35 +00:00
|
|
|
// an error occurred before the real checkin VCS command
|
2013-02-04 20:40:28 +00:00
|
|
|
// 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);
|
2017-03-01 21:03:44 +00:00
|
|
|
if (!ensureBufferClean(buffer) || buffer->hasReadonlyFlag())
|
2009-09-12 20:41:24 +00:00
|
|
|
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);
|
2014-02-17 20:47:22 +00:00
|
|
|
dr.clearMessageUpdate();
|
2010-11-06 11:54:08 +00:00
|
|
|
}
|
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);
|
2014-02-17 20:47:22 +00:00
|
|
|
dr.clearMessageUpdate();
|
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-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;
|
2017-03-31 09:47:47 +00:00
|
|
|
LATTEST(buffer)
|
2010-02-12 14:09:44 +00:00
|
|
|
|
|
|
|
// 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);
|
2016-09-05 02:23:24 +00:00
|
|
|
bool success = documentBufferView()->setCursorFromRow(row);
|
|
|
|
if (!success) {
|
|
|
|
LYXERR(Debug::LATEX,
|
|
|
|
"setCursorFromRow: invalid position for row " << row);
|
|
|
|
frontend::Alert::error(_("Inverse Search Failed"),
|
|
|
|
_("Invalid position requested by inverse search.\n"
|
|
|
|
"You may need to update the viewed document."));
|
|
|
|
}
|
|
|
|
return success;
|
2009-09-23 13:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-23 16:43:37 +00:00
|
|
|
void GuiView::toolBarPopup(const QPoint & /*pos*/)
|
2016-10-09 07:15:20 +00:00
|
|
|
{
|
2017-07-05 10:28:26 +00:00
|
|
|
QMenu * menu = guiApp->menus().menu(toqstr("context-toolbars"), * this);
|
2016-10-09 07:15:20 +00:00
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2010-10-18 09:31:50 +00:00
|
|
|
if (!msg.empty()) {
|
|
|
|
progress_->clearMessages();
|
|
|
|
gv_->message(msg);
|
|
|
|
}
|
2014-11-19 21:45:25 +00:00
|
|
|
#if EXPORT_in_THREAD
|
2010-10-18 09:31:50 +00:00
|
|
|
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) {
|
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) {
|
2017-07-03 17:53:14 +00:00
|
|
|
status = (used_buffer->*previewFunc)(format);
|
2011-10-29 11:14:47 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
handleExportStatus(gv_, status, format);
|
2010-10-18 09:31:50 +00:00
|
|
|
(void) asyncFunc;
|
2017-07-03 17:53:14 +00:00
|
|
|
return (status == Buffer::ExportSuccess
|
2011-10-29 11:14:47 +00:00
|
|
|
|| 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();
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(bv, return);
|
2010-12-04 22:48:08 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2016-06-25 02:04:59 +00:00
|
|
|
|
|
|
|
string const dest = cmd.getArg(1);
|
|
|
|
FileName target_dir;
|
|
|
|
if (!dest.empty() && FileName::isAbsolute(dest))
|
|
|
|
target_dir = FileName(support::onlyPath(dest));
|
|
|
|
else
|
2016-06-25 02:26:34 +00:00
|
|
|
target_dir = doc_buffer->fileName().onlyPath();
|
2016-06-25 02:04:59 +00:00
|
|
|
|
2017-03-09 22:35:27 +00:00
|
|
|
string const format = (argument.empty() || argument == "default") ?
|
2017-02-27 19:43:11 +00:00
|
|
|
doc_buffer->params().getDefaultOutputFormat() : argument;
|
|
|
|
|
2016-06-25 04:38:27 +00:00
|
|
|
if ((dest.empty() && doc_buffer->isUnnamed())
|
|
|
|
|| !target_dir.isDirWritable()) {
|
2017-02-27 19:43:11 +00:00
|
|
|
exportBufferAs(*doc_buffer, from_utf8(format));
|
2013-08-26 10:28:07 +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 */
|
2017-02-27 19:43:11 +00:00
|
|
|
d.asyncBufferProcessing(format,
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-15 08:20:07 +00:00
|
|
|
case LFUN_BUFFER_EXPORT_AS: {
|
2011-10-06 13:47:42 +00:00
|
|
|
LASSERT(doc_buffer, break);
|
2013-11-15 08:20:07 +00:00
|
|
|
docstring f = cmd.argument();
|
|
|
|
if (f.empty())
|
|
|
|
f = from_ascii(doc_buffer->params().getDefaultOutputFormat());
|
|
|
|
exportBufferAs(*doc_buffer, f);
|
2011-10-06 13:47:42 +00:00
|
|
|
break;
|
2013-11-15 08:20:07 +00:00
|
|
|
}
|
2011-10-06 13:47:42 +00:00
|
|
|
|
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)) {
|
2016-04-16 20:30:33 +00:00
|
|
|
gv.raise();
|
2010-06-07 21:57:37 +00:00
|
|
|
gv.activateWindow();
|
2016-04-16 20:30:33 +00:00
|
|
|
gv.setFocus();
|
2010-06-07 21:57:37 +00:00
|
|
|
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:
|
2015-04-08 03:18:21 +00:00
|
|
|
gotoNextOrPreviousBuffer(NEXTBUFFER, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_MOVE_NEXT:
|
|
|
|
gotoNextOrPreviousBuffer(NEXTBUFFER, true);
|
2007-11-23 12:37:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_PREVIOUS:
|
2015-04-08 03:18:21 +00:00
|
|
|
gotoNextOrPreviousBuffer(PREVBUFFER, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_MOVE_PREVIOUS:
|
|
|
|
gotoNextOrPreviousBuffer(PREVBUFFER, true);
|
2007-11-23 12:37:09 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-14 11:14:06 +00:00
|
|
|
case LFUN_COMMAND_EXECUTE: {
|
2015-04-18 17:10:33 +00:00
|
|
|
command_execute_ = true;
|
2016-08-19 12:53:31 +00:00
|
|
|
minibuffer_focus_ = true;
|
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: {
|
|
|
|
string const fname = to_utf8(cmd.argument());
|
|
|
|
if (!fname.empty() && !FileName::isAbsolute(fname)) {
|
|
|
|
dr.setMessage(_("Absolute filename expected."));
|
|
|
|
break;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2011-12-05 13:12:57 +00:00
|
|
|
FileName filename(fname);
|
|
|
|
if (fname.empty()) {
|
2014-04-21 14:50:56 +00:00
|
|
|
FileDialog dlg(qt_("Select file to insert"));
|
2011-12-05 13:12:57 +00:00
|
|
|
|
|
|
|
FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
|
|
|
|
QStringList(qt_("All Files (*)")));
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2011-12-05 13:12:57 +00:00
|
|
|
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);
|
2017-05-15 22:28:43 +00:00
|
|
|
if (doc_buffer->notifiesExternalModification()) {
|
|
|
|
docstring text = _("The current version will be lost. "
|
2017-03-05 22:55:59 +00:00
|
|
|
"Are you sure you want to load the version on disk "
|
2017-05-15 22:28:43 +00:00
|
|
|
"of the document %1$s?");
|
|
|
|
ret = Alert::prompt(_("Reload saved document?"),
|
|
|
|
bformat(text, file), 1, 1,
|
|
|
|
_("&Reload"), _("&Cancel"));
|
|
|
|
} else {
|
|
|
|
docstring text = _("Any changes will be lost. "
|
2017-03-05 22:55:59 +00:00
|
|
|
"Are you sure you want to revert to the saved version "
|
|
|
|
"of the document %1$s?");
|
2017-05-15 22:28:43 +00:00
|
|
|
ret = Alert::prompt(_("Revert to saved document?"),
|
|
|
|
bformat(text, file), 1, 1,
|
|
|
|
_("&Revert"), _("&Cancel"));
|
|
|
|
}
|
2010-10-25 16:10:01 +00:00
|
|
|
}
|
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
|
|
|
|
2017-03-01 20:16:37 +00:00
|
|
|
case LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR:
|
|
|
|
LASSERT(doc_buffer, break);
|
|
|
|
doc_buffer->clearExternalModification();
|
|
|
|
break;
|
|
|
|
|
2009-09-19 14:34:46 +00:00
|
|
|
case LFUN_BUFFER_CLOSE:
|
|
|
|
closeBuffer();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BUFFER_CLOSE_ALL:
|
|
|
|
closeBufferAll();
|
|
|
|
break;
|
|
|
|
|
2017-07-23 22:21:43 +00:00
|
|
|
case LFUN_DEVEL_MODE_TOGGLE:
|
|
|
|
devel_mode_ = !devel_mode_;
|
|
|
|
if (devel_mode_)
|
|
|
|
dr.setMessage(_("Developer mode is now enabled."));
|
|
|
|
else
|
|
|
|
dr.setMessage(_("Developer mode is now disabled."));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-24 12:10:03 +00:00
|
|
|
case LFUN_TOOLBAR_MOVABLE: {
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
if (name == "*") {
|
|
|
|
// toggle (all) toolbars movablility
|
2017-05-07 12:18:17 +00:00
|
|
|
toolbarsMovable_ = !toolbarsMovable_;
|
|
|
|
for (ToolbarInfo const & ti : guiApp->toolbars()) {
|
|
|
|
GuiToolbar * tb = toolbar(ti.name);
|
|
|
|
if (tb && tb->isMovable() != toolbarsMovable_)
|
|
|
|
// toggle toolbar movablity if it does not fit lock
|
|
|
|
// (all) toolbars positions state silent = true, since
|
|
|
|
// status bar notifications are slow
|
2016-11-24 12:10:03 +00:00
|
|
|
tb->movable(true);
|
|
|
|
}
|
2017-05-07 12:18:17 +00:00
|
|
|
if (toolbarsMovable_)
|
|
|
|
dr.setMessage(_("Toolbars unlocked."));
|
|
|
|
else
|
|
|
|
dr.setMessage(_("Toolbars locked."));
|
2016-11-24 12:10:03 +00:00
|
|
|
} else if (GuiToolbar * t = toolbar(name)) {
|
|
|
|
// toggle current toolbar movablity
|
|
|
|
t->movable();
|
|
|
|
// update lock (all) toolbars positions
|
|
|
|
updateLockToolbars();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-09 07:15:20 +00:00
|
|
|
case LFUN_ICON_SIZE: {
|
2016-11-23 16:30:49 +00:00
|
|
|
QSize size = d.iconSize(cmd.argument());
|
|
|
|
setIconSize(size);
|
|
|
|
dr.setMessage(bformat(_("Icon size set to %1$dx%2$d."),
|
|
|
|
size.width(), size.height()));
|
2016-10-09 07:15:20 +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") {
|
2017-04-05 09:53:17 +00:00
|
|
|
// getStatus checks that
|
|
|
|
LATTEST(doc_buffer);
|
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") {
|
2017-04-05 09:53:17 +00:00
|
|
|
// getStatus checks that
|
|
|
|
LATTEST(doc_buffer);
|
2007-11-19 20:56:05 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_COMPLETE:
|
2008-02-21 19:42:34 +00:00
|
|
|
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:
|
2016-10-29 08:28:34 +00:00
|
|
|
case LFUN_BUFFER_ZOOM_OUT:
|
|
|
|
case LFUN_BUFFER_ZOOM: {
|
2009-04-04 09:14:38 +00:00
|
|
|
if (cmd.argument().empty()) {
|
2016-10-29 08:28:34 +00:00
|
|
|
if (cmd.action() == LFUN_BUFFER_ZOOM)
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ = 1.0;
|
2016-10-29 08:28:34 +00:00
|
|
|
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ += 0.1;
|
2009-04-04 09:14:38 +00:00
|
|
|
else
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ -= 0.1;
|
2016-10-29 08:28:34 +00:00
|
|
|
} else {
|
|
|
|
if (cmd.action() == LFUN_BUFFER_ZOOM)
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ = convert<int>(cmd.argument()) / double(lyxrc.defaultZoom);
|
2016-10-29 08:28:34 +00:00
|
|
|
else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ += convert<int>(cmd.argument()) / 100.0;
|
2016-10-29 08:28:34 +00:00
|
|
|
else
|
2017-09-06 16:11:31 +00:00
|
|
|
zoom_ratio_ -= convert<int>(cmd.argument()) / 100.0;
|
2016-10-29 08:28:34 +00:00
|
|
|
}
|
2009-04-04 09:14:38 +00:00
|
|
|
|
2017-09-06 16:11:31 +00:00
|
|
|
// Actual zoom value: default zoom + fractional extra value
|
|
|
|
int zoom = lyxrc.defaultZoom * zoom_ratio_;
|
2016-10-09 21:22:22 +00:00
|
|
|
if (zoom < static_cast<int>(zoom_min_))
|
|
|
|
zoom = zoom_min_;
|
2016-07-18 14:44:06 +00:00
|
|
|
|
2016-10-29 08:28:34 +00:00
|
|
|
lyxrc.currentZoom = zoom;
|
|
|
|
|
2017-09-06 16:11:31 +00:00
|
|
|
dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"),
|
|
|
|
lyxrc.currentZoom, lyxrc.defaultZoom));
|
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;
|
2016-07-18 14:44:06 +00:00
|
|
|
}
|
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:
|
2016-10-11 09:21:40 +00:00
|
|
|
if(goToFileRow(to_utf8(cmd.argument())))
|
|
|
|
dr.screenUpdate(Update::Force | Update::FitCursor);
|
2009-09-23 13:45:58 +00:00
|
|
|
break;
|
|
|
|
|
2016-08-04 05:20:14 +00:00
|
|
|
case LFUN_LYX_ACTIVATE:
|
|
|
|
activateWindow();
|
|
|
|
break;
|
|
|
|
|
2010-04-15 13:19:48 +00:00
|
|
|
case LFUN_FORWARD_SEARCH: {
|
2017-03-31 09:47:47 +00:00
|
|
|
// it seems safe to assume we have a document buffer, since
|
|
|
|
// getStatus wants one.
|
|
|
|
LATTEST(doc_buffer);
|
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();
|
2017-07-03 17:53:14 +00:00
|
|
|
string const fulltexname =
|
2012-08-26 09:42:43 +00:00
|
|
|
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
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
DocIterator cur = bv->cursor();
|
|
|
|
int row = doc_buffer->texrow().rowFromDocIterator(cur).first;
|
2010-04-16 18:30:52 +00:00
|
|
|
LYXERR(Debug::ACTION, "Forward search: row:" << row
|
2015-09-15 04:56:01 +00:00
|
|
|
<< " cur:" << cur);
|
|
|
|
if (row == -1 || command.empty()) {
|
2010-04-16 08:18:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-03-24 18:20:19 +00:00
|
|
|
|
|
|
|
case LFUN_SPELLING_CONTINUOUSLY:
|
|
|
|
lyxrc.spellcheck_continuously = !lyxrc.spellcheck_continuously;
|
2016-10-30 23:38:28 +00:00
|
|
|
dr.screenUpdate(Update::Force);
|
2013-03-24 18:20:19 +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();
|
|
|
|
}
|
2014-10-21 05:45:31 +00:00
|
|
|
|
|
|
|
// Need to update bv because many LFUNs here might have destroyed it
|
|
|
|
bv = currentBufferView();
|
|
|
|
|
|
|
|
// Clear non-empty selections
|
2016-10-09 17:42:18 +00:00
|
|
|
// (e.g. from a "char-forward-select" followed by "char-backward-select")
|
2014-10-21 05:45:31 +00:00
|
|
|
if (bv) {
|
|
|
|
Cursor & cur = bv->cursor();
|
|
|
|
if ((cur.selection() && cur.selBegin() == cur.selEnd())) {
|
|
|
|
cur.clearSelection();
|
|
|
|
}
|
|
|
|
}
|
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);
|
2014-02-26 01:48:56 +00:00
|
|
|
if (lyxrc.full_screen_statusbar)
|
|
|
|
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",
|
2015-11-27 03:15:24 +00:00
|
|
|
"nomencl_print", "note", "paragraph", "phantom", "prefs", "ref",
|
2010-09-07 00:41:00 +00:00
|
|
|
"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
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2007-11-18 23:49:52 +00:00
|
|
|
|
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 == "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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-03 11:07:41 +00:00
|
|
|
SEMenu::SEMenu(QWidget * parent)
|
|
|
|
{
|
|
|
|
QAction * action = addAction(qt_("Disable Shell Escape"));
|
|
|
|
connect(action, SIGNAL(triggered()),
|
|
|
|
parent, SLOT(disableShellEscape()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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"
|