3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
19 #include "DispatchResult.h"
20 #include "FileDialog.h"
21 #include "FontLoader.h"
22 #include "GuiApplication.h"
23 #include "GuiCommandBuffer.h"
24 #include "GuiCompleter.h"
25 #include "GuiKeySymbol.h"
27 #include "GuiToolbar.h"
28 #include "GuiWorkArea.h"
29 #include "GuiProgress.h"
30 #include "LayoutBox.h"
34 #include "qt_helpers.h"
36 #include "frontends/alert.h"
37 #include "frontends/KeySymbol.h"
39 #include "buffer_funcs.h"
41 #include "BufferList.h"
42 #include "BufferParams.h"
43 #include "BufferView.h"
45 #include "Converter.h"
47 #include "CutAndPaste.h"
49 #include "ErrorList.h"
51 #include "FuncStatus.h"
52 #include "FuncRequest.h"
56 #include "LyXAction.h"
60 #include "Paragraph.h"
61 #include "SpellChecker.h"
64 #include "TextClass.h"
69 #include "support/convert.h"
70 #include "support/debug.h"
71 #include "support/ExceptionMessage.h"
72 #include "support/FileName.h"
73 #include "support/filetools.h"
74 #include "support/gettext.h"
75 #include "support/filetools.h"
76 #include "support/ForkedCalls.h"
77 #include "support/lassert.h"
78 #include "support/lstrings.h"
79 #include "support/os.h"
80 #include "support/Package.h"
81 #include "support/PathChanger.h"
82 #include "support/Systemcall.h"
83 #include "support/Timeout.h"
84 #include "support/ProgressInterface.h"
87 #include <QApplication>
88 #include <QCloseEvent>
90 #include <QDesktopWidget>
91 #include <QDragEnterEvent>
94 #include <QFutureWatcher>
103 #include <QPixmapCache>
105 #include <QPushButton>
106 #include <QScrollBar>
108 #include <QShowEvent>
110 #include <QStackedWidget>
111 #include <QStatusBar>
112 #include <QtConcurrentRun>
120 // sync with GuiAlert.cpp
121 #define EXPORT_in_THREAD 1
124 #include "support/bind.h"
128 #ifdef HAVE_SYS_TIME_H
129 # include <sys/time.h>
137 using namespace lyx::support;
141 using support::addExtension;
142 using support::changeExtension;
143 using support::removeExtension;
149 class BackgroundWidget : public QWidget
154 LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
155 if (!lyxrc.show_banner)
157 /// The text to be written on top of the pixmap
158 QString const text = lyx_version ?
159 qt_("version ") + lyx_version : qt_("unknown version");
160 splash_ = getPixmap("images/", "banner", "png");
162 QPainter pain(&splash_);
163 pain.setPen(QColor(0, 0, 0));
164 double const multiplier = splashPixelRatio() / pixelRatio();
165 int const size = static_cast<int>(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble() * multiplier);
166 int const x = static_cast<int>(190 * multiplier);
167 int const y = static_cast<int>(225 * multiplier);
169 "widget pixel ratio: " << pixelRatio() <<
170 " splash pixel ratio: " << splashPixelRatio() <<
171 " version text size,position: " << size << "@" << x << "+" << y);
173 // The font used to display the version info
174 font.setStyleHint(QFont::SansSerif);
175 font.setWeight(QFont::Bold);
176 font.setPointSize(size);
178 pain.drawText(x, y, text);
179 setFocusPolicy(Qt::StrongFocus);
182 void paintEvent(QPaintEvent *)
184 int const w = static_cast<int>(splash_.width() / splashPixelRatio());
185 int const h = static_cast<int>(splash_.height() / splashPixelRatio());
186 int const x = (width() - w) / 2;
187 int const y = (height() - h) / 2;
189 "widget pixel ratio: " << pixelRatio() <<
190 " splash pixel ratio: " << splashPixelRatio() <<
191 " paint pixmap: " << w << "x" << h << "@" << x << "+" << y);
193 pain.drawPixmap(x, y, w, h, splash_);
196 void keyPressEvent(QKeyEvent * ev)
199 setKeySymbol(&sym, ev);
201 guiApp->processKeySym(sym, q_key_state(ev->modifiers()));
211 /// Current ratio between physical pixels and device-independent pixels
212 double pixelRatio() const {
213 #if QT_VERSION >= 0x050000
214 return devicePixelRatio();
220 /// Ratio between physical pixels and device-independent pixels of splash image
221 double splashPixelRatio() const {
222 #if QT_VERSION >= 0x050000
223 return splash_.devicePixelRatio();
231 /// Toolbar store providing access to individual toolbars by name.
232 typedef map<string, GuiToolbar *> ToolbarMap;
234 typedef shared_ptr<Dialog> DialogPtr;
239 struct GuiView::GuiViewPrivate
241 GuiViewPrivate(GuiView * gv)
242 : gv_(gv), current_work_area_(0), current_main_work_area_(0),
243 layout_(0), autosave_timeout_(5000),
246 // hardcode here the platform specific icon size
247 smallIconSize = 16; // scaling problems
248 normalIconSize = 20; // ok, default if iconsize.png is missing
249 bigIconSize = 26; // better for some math icons
251 // if it exists, use width of iconsize.png as normal size
252 QString const dir = toqstr(addPath("images", lyxrc.icon_set));
253 FileName const fn = lyx::libFileSearch(dir, "iconsize.png");
255 QImage image(toqstr(fn.absFileName()));
256 if (image.width() < int(smallIconSize))
257 normalIconSize = smallIconSize;
258 else if (image.width() > int(bigIconSize))
259 normalIconSize = bigIconSize;
261 normalIconSize = image.width();
264 splitter_ = new QSplitter;
265 bg_widget_ = new BackgroundWidget;
266 stack_widget_ = new QStackedWidget;
267 stack_widget_->addWidget(bg_widget_);
268 stack_widget_->addWidget(splitter_);
271 // TODO cleanup, remove the singleton, handle multiple Windows?
272 progress_ = ProgressInterface::instance();
273 if (!dynamic_cast<GuiProgress*>(progress_)) {
274 progress_ = new GuiProgress; // TODO who deletes it
275 ProgressInterface::setInstance(progress_);
278 dynamic_cast<GuiProgress*>(progress_),
279 SIGNAL(updateStatusBarMessage(QString const&)),
280 gv, SLOT(updateStatusBarMessage(QString const&)));
282 dynamic_cast<GuiProgress*>(progress_),
283 SIGNAL(clearMessageText()),
284 gv, SLOT(clearMessageText()));
291 delete stack_widget_;
294 QMenu * toolBarPopup(GuiView * parent)
296 // FIXME: translation
297 QMenu * menu = new QMenu(parent);
298 QActionGroup * iconSizeGroup = new QActionGroup(parent);
300 QAction * smallIcons = new QAction(iconSizeGroup);
301 smallIcons->setText(qt_("Small-sized icons"));
302 smallIcons->setCheckable(true);
303 QObject::connect(smallIcons, SIGNAL(triggered()),
304 parent, SLOT(smallSizedIcons()));
305 menu->addAction(smallIcons);
307 QAction * normalIcons = new QAction(iconSizeGroup);
308 normalIcons->setText(qt_("Normal-sized icons"));
309 normalIcons->setCheckable(true);
310 QObject::connect(normalIcons, SIGNAL(triggered()),
311 parent, SLOT(normalSizedIcons()));
312 menu->addAction(normalIcons);
314 QAction * bigIcons = new QAction(iconSizeGroup);
315 bigIcons->setText(qt_("Big-sized icons"));
316 bigIcons->setCheckable(true);
317 QObject::connect(bigIcons, SIGNAL(triggered()),
318 parent, SLOT(bigSizedIcons()));
319 menu->addAction(bigIcons);
321 unsigned int cur = parent->iconSize().width();
322 if ( cur == parent->d.smallIconSize)
323 smallIcons->setChecked(true);
324 else if (cur == parent->d.normalIconSize)
325 normalIcons->setChecked(true);
326 else if (cur == parent->d.bigIconSize)
327 bigIcons->setChecked(true);
334 stack_widget_->setCurrentWidget(bg_widget_);
335 bg_widget_->setUpdatesEnabled(true);
336 bg_widget_->setFocus();
339 int tabWorkAreaCount()
341 return splitter_->count();
344 TabWorkArea * tabWorkArea(int i)
346 return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
349 TabWorkArea * currentTabWorkArea()
351 int areas = tabWorkAreaCount();
353 // The first TabWorkArea is always the first one, if any.
354 return tabWorkArea(0);
356 for (int i = 0; i != areas; ++i) {
357 TabWorkArea * twa = tabWorkArea(i);
358 if (current_main_work_area_ == twa->currentWorkArea())
362 // None has the focus so we just take the first one.
363 return tabWorkArea(0);
366 int countWorkAreasOf(Buffer & buf)
368 int areas = tabWorkAreaCount();
370 for (int i = 0; i != areas; ++i) {
371 TabWorkArea * twa = tabWorkArea(i);
372 if (twa->workArea(buf))
378 void setPreviewFuture(QFuture<Buffer::ExportStatus> const & f)
380 if (processing_thread_watcher_.isRunning()) {
381 // we prefer to cancel this preview in order to keep a snappy
385 processing_thread_watcher_.setFuture(f);
390 GuiWorkArea * current_work_area_;
391 GuiWorkArea * current_main_work_area_;
392 QSplitter * splitter_;
393 QStackedWidget * stack_widget_;
394 BackgroundWidget * bg_widget_;
396 ToolbarMap toolbars_;
397 ProgressInterface* progress_;
398 /// The main layout box.
400 * \warning Don't Delete! The layout box is actually owned by
401 * whichever toolbar contains it. All the GuiView class needs is a
402 * means of accessing it.
404 * FIXME: replace that with a proper model so that we are not limited
405 * to only one dialog.
410 map<string, DialogPtr> dialogs_;
412 unsigned int smallIconSize;
413 unsigned int normalIconSize;
414 unsigned int bigIconSize;
416 QTimer statusbar_timer_;
417 /// auto-saving of buffers
418 Timeout autosave_timeout_;
419 /// flag against a race condition due to multiclicks, see bug #1119
423 TocModels toc_models_;
426 QFutureWatcher<docstring> autosave_watcher_;
427 QFutureWatcher<Buffer::ExportStatus> processing_thread_watcher_;
429 string last_export_format;
430 string processing_format;
432 static QSet<Buffer const *> busyBuffers;
433 static Buffer::ExportStatus previewAndDestroy(Buffer const * orig, Buffer * buffer, string const & format);
434 static Buffer::ExportStatus exportAndDestroy(Buffer const * orig, Buffer * buffer, string const & format);
435 static Buffer::ExportStatus compileAndDestroy(Buffer const * orig, Buffer * buffer, string const & format);
436 static docstring autosaveAndDestroy(Buffer const * orig, Buffer * buffer);
439 static Buffer::ExportStatus runAndDestroy(const T& func, Buffer const * orig, Buffer * buffer, string const & format);
441 // TODO syncFunc/previewFunc: use bind
442 bool asyncBufferProcessing(string const & argument,
443 Buffer const * used_buffer,
444 docstring const & msg,
445 Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
446 Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
447 Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const);
449 QVector<GuiWorkArea*> guiWorkAreas();
452 QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
455 GuiView::GuiView(int id)
456 : d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0)
458 // GuiToolbars *must* be initialised before the menu bar.
459 normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
462 // set ourself as the current view. This is needed for the menu bar
463 // filling, at least for the static special menu item on Mac. Otherwise
464 // they are greyed out.
465 guiApp->setCurrentView(this);
467 // Fill up the menu bar.
468 guiApp->menus().fillMenuBar(menuBar(), this, true);
470 setCentralWidget(d.stack_widget_);
472 // Start autosave timer
473 if (lyxrc.autosave) {
474 d.autosave_timeout_.timeout.connect(bind(&GuiView::autoSave, this));
475 d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
476 d.autosave_timeout_.start();
478 connect(&d.statusbar_timer_, SIGNAL(timeout()),
479 this, SLOT(clearMessage()));
481 // We don't want to keep the window in memory if it is closed.
482 setAttribute(Qt::WA_DeleteOnClose, true);
484 #if !(defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)) && !defined(Q_OS_MAC)
485 // QIcon::fromTheme was introduced in Qt 4.6
486 #if (QT_VERSION >= 0x040600)
487 // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
488 // since the icon is provided in the application bundle. We use a themed
489 // version when available and use the bundled one as fallback.
490 setWindowIcon(QIcon::fromTheme("lyx", getPixmap("images/", "lyx", "png")));
492 setWindowIcon(getPixmap("images/", "lyx", "png"));
496 resetWindowTitleAndIconText();
498 // use tabbed dock area for multiple docks
499 // (such as "source" and "messages")
500 setDockOptions(QMainWindow::ForceTabbedDocks);
503 setAcceptDrops(true);
505 // add busy indicator to statusbar
506 QLabel * busylabel = new QLabel(statusBar());
507 statusBar()->addPermanentWidget(busylabel);
508 search_mode mode = theGuiApp()->imageSearchMode();
509 QString fn = toqstr(lyx::libFileSearch("images", "busy", "gif", mode).absFileName());
510 QMovie * busyanim = new QMovie(fn, QByteArray(), busylabel);
511 busylabel->setMovie(busyanim);
515 connect(&d.processing_thread_watcher_, SIGNAL(started()),
516 busylabel, SLOT(show()));
517 connect(&d.processing_thread_watcher_, SIGNAL(finished()),
518 busylabel, SLOT(hide()));
520 statusBar()->setSizeGripEnabled(true);
523 connect(&d.autosave_watcher_, SIGNAL(finished()), this,
524 SLOT(autoSaveThreadFinished()));
526 connect(&d.processing_thread_watcher_, SIGNAL(started()), this,
527 SLOT(processingThreadStarted()));
528 connect(&d.processing_thread_watcher_, SIGNAL(finished()), this,
529 SLOT(processingThreadFinished()));
531 connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
532 SLOT(doShowDialog(QString const &, QString const &, Inset *)));
534 // Forbid too small unresizable window because it can happen
535 // with some window manager under X11.
536 setMinimumSize(300, 200);
538 if (lyxrc.allow_geometry_session) {
539 // Now take care of session management.
544 // no session handling, default to a sane size.
545 setGeometry(50, 50, 690, 510);
548 // clear session data if any.
550 settings.remove("views");
560 QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
562 QVector<GuiWorkArea*> areas;
563 for (int i = 0; i < tabWorkAreaCount(); i++) {
564 TabWorkArea* ta = tabWorkArea(i);
565 for (int u = 0; u < ta->count(); u++) {
566 areas << ta->workArea(u);
572 static void handleExportStatus(GuiView * view, Buffer::ExportStatus status,
573 string const & format)
575 docstring const fmt = formats.prettyName(format);
578 case Buffer::ExportSuccess:
579 msg = bformat(_("Successful export to format: %1$s"), fmt);
581 case Buffer::ExportCancel:
582 msg = _("Document export cancelled.");
584 case Buffer::ExportError:
585 case Buffer::ExportNoPathToFormat:
586 case Buffer::ExportTexPathHasSpaces:
587 case Buffer::ExportConverterError:
588 msg = bformat(_("Error while exporting format: %1$s"), fmt);
590 case Buffer::PreviewSuccess:
591 msg = bformat(_("Successful preview of format: %1$s"), fmt);
593 case Buffer::PreviewError:
594 msg = bformat(_("Error while previewing format: %1$s"), fmt);
601 void GuiView::processingThreadStarted()
606 void GuiView::processingThreadFinished()
608 QFutureWatcher<Buffer::ExportStatus> const * watcher =
609 static_cast<QFutureWatcher<Buffer::ExportStatus> const *>(sender());
611 Buffer::ExportStatus const status = watcher->result();
612 handleExportStatus(this, status, d.processing_format);
615 BufferView const * const bv = currentBufferView();
616 if (bv && !bv->buffer().errorList("Export").empty()) {
620 errors(d.last_export_format);
624 void GuiView::autoSaveThreadFinished()
626 QFutureWatcher<docstring> const * watcher =
627 static_cast<QFutureWatcher<docstring> const *>(sender());
628 message(watcher->result());
633 void GuiView::saveLayout() const
636 settings.beginGroup("views");
637 settings.beginGroup(QString::number(id_));
638 #if defined(Q_WS_X11) || defined(QPA_XCB)
639 settings.setValue("pos", pos());
640 settings.setValue("size", size());
642 settings.setValue("geometry", saveGeometry());
644 settings.setValue("layout", saveState(0));
645 settings.setValue("icon_size", iconSize());
649 void GuiView::saveUISettings() const
651 // Save the toolbar private states
652 ToolbarMap::iterator end = d.toolbars_.end();
653 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
654 it->second->saveSession();
655 // Now take care of all other dialogs
656 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
657 for (; it!= d.dialogs_.end(); ++it)
658 it->second->saveSession();
662 bool GuiView::restoreLayout()
665 settings.beginGroup("views");
666 settings.beginGroup(QString::number(id_));
667 QString const icon_key = "icon_size";
668 if (!settings.contains(icon_key))
671 //code below is skipped when when ~/.config/LyX is (re)created
672 QSize icon_size = settings.value(icon_key).toSize();
673 // Check whether session size changed.
674 if (icon_size.width() != int(d.smallIconSize) &&
675 icon_size.width() != int(d.normalIconSize) &&
676 icon_size.width() != int(d.bigIconSize)) {
677 icon_size.setWidth(d.normalIconSize);
678 icon_size.setHeight(d.normalIconSize);
680 setIconSize(icon_size);
682 #if defined(Q_WS_X11) || defined(QPA_XCB)
683 QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
684 QSize size = settings.value("size", QSize(690, 510)).toSize();
688 // Work-around for bug #6034: the window ends up in an undetermined
689 // state when trying to restore a maximized window when it is
690 // already maximized.
691 if (!(windowState() & Qt::WindowMaximized))
692 if (!restoreGeometry(settings.value("geometry").toByteArray()))
693 setGeometry(50, 50, 690, 510);
695 // Make sure layout is correctly oriented.
696 setLayoutDirection(qApp->layoutDirection());
698 // Allow the toc and view-source dock widget to be restored if needed.
700 if ((dialog = findOrBuild("toc", true)))
701 // see bug 5082. At least setup title and enabled state.
702 // Visibility will be adjusted by restoreState below.
703 dialog->prepareView();
704 if ((dialog = findOrBuild("view-source", true)))
705 dialog->prepareView();
706 if ((dialog = findOrBuild("progress", true)))
707 dialog->prepareView();
709 if (!restoreState(settings.value("layout").toByteArray(), 0))
712 // init the toolbars that have not been restored
713 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
714 Toolbars::Infos::iterator end = guiApp->toolbars().end();
715 for (; cit != end; ++cit) {
716 GuiToolbar * tb = toolbar(cit->name);
717 if (tb && !tb->isRestored())
718 initToolbar(cit->name);
726 GuiToolbar * GuiView::toolbar(string const & name)
728 ToolbarMap::iterator it = d.toolbars_.find(name);
729 if (it != d.toolbars_.end())
732 LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
737 void GuiView::constructToolbars()
739 ToolbarMap::iterator it = d.toolbars_.begin();
740 for (; it != d.toolbars_.end(); ++it)
744 // I don't like doing this here, but the standard toolbar
745 // destroys this object when it's destroyed itself (vfr)
746 d.layout_ = new LayoutBox(*this);
747 d.stack_widget_->addWidget(d.layout_);
748 d.layout_->move(0,0);
750 // extracts the toolbars from the backend
751 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
752 Toolbars::Infos::iterator end = guiApp->toolbars().end();
753 for (; cit != end; ++cit)
754 d.toolbars_[cit->name] = new GuiToolbar(*cit, *this);
758 void GuiView::initToolbars()
760 // extracts the toolbars from the backend
761 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
762 Toolbars::Infos::iterator end = guiApp->toolbars().end();
763 for (; cit != end; ++cit)
764 initToolbar(cit->name);
768 void GuiView::initToolbar(string const & name)
770 GuiToolbar * tb = toolbar(name);
773 int const visibility = guiApp->toolbars().defaultVisibility(name);
774 bool newline = !(visibility & Toolbars::SAMEROW);
775 tb->setVisible(false);
776 tb->setVisibility(visibility);
778 if (visibility & Toolbars::TOP) {
780 addToolBarBreak(Qt::TopToolBarArea);
781 addToolBar(Qt::TopToolBarArea, tb);
784 if (visibility & Toolbars::BOTTOM) {
786 addToolBarBreak(Qt::BottomToolBarArea);
787 addToolBar(Qt::BottomToolBarArea, tb);
790 if (visibility & Toolbars::LEFT) {
792 addToolBarBreak(Qt::LeftToolBarArea);
793 addToolBar(Qt::LeftToolBarArea, tb);
796 if (visibility & Toolbars::RIGHT) {
798 addToolBarBreak(Qt::RightToolBarArea);
799 addToolBar(Qt::RightToolBarArea, tb);
802 if (visibility & Toolbars::ON)
803 tb->setVisible(true);
807 TocModels & GuiView::tocModels()
809 return d.toc_models_;
813 void GuiView::setFocus()
815 LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this);
816 QMainWindow::setFocus();
820 void GuiView::focusInEvent(QFocusEvent * e)
822 LYXERR(Debug::DEBUG, "GuiView::focusInEvent()" << this);
823 QMainWindow::focusInEvent(e);
824 // Make sure guiApp points to the correct view.
825 guiApp->setCurrentView(this);
826 if (currentWorkArea())
827 currentWorkArea()->setFocus();
828 else if (currentMainWorkArea())
829 currentMainWorkArea()->setFocus();
831 d.bg_widget_->setFocus();
835 QMenu * GuiView::createPopupMenu()
837 return d.toolBarPopup(this);
841 void GuiView::showEvent(QShowEvent * e)
843 LYXERR(Debug::GUI, "Passed Geometry "
844 << size().height() << "x" << size().width()
845 << "+" << pos().x() << "+" << pos().y());
847 if (d.splitter_->count() == 0)
848 // No work area, switch to the background widget.
852 QMainWindow::showEvent(e);
856 bool GuiView::closeScheduled()
863 /** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
864 ** is responsibility of the container (e.g., dialog)
866 void GuiView::closeEvent(QCloseEvent * close_event)
868 LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
870 if (!GuiViewPrivate::busyBuffers.isEmpty()) {
871 Alert::warning(_("Exit LyX"),
872 _("LyX could not be closed because documents are being processed by LyX."));
873 close_event->setAccepted(false);
877 // If the user pressed the x (so we didn't call closeView
878 // programmatically), we want to clear all existing entries.
880 theSession().lastOpened().clear();
885 // it can happen that this event arrives without selecting the view,
886 // e.g. when clicking the close button on a background window.
888 if (!closeWorkAreaAll()) {
890 close_event->ignore();
894 // Make sure that nothing will use this to be closed View.
895 guiApp->unregisterView(this);
897 if (isFullScreen()) {
898 // Switch off fullscreen before closing.
903 // Make sure the timer time out will not trigger a statusbar update.
904 d.statusbar_timer_.stop();
906 // Saving fullscreen requires additional tweaks in the toolbar code.
907 // It wouldn't also work under linux natively.
908 if (lyxrc.allow_geometry_session) {
913 close_event->accept();
917 void GuiView::dragEnterEvent(QDragEnterEvent * event)
919 if (event->mimeData()->hasUrls())
921 /// \todo Ask lyx-devel is this is enough:
922 /// if (event->mimeData()->hasFormat("text/plain"))
923 /// event->acceptProposedAction();
927 void GuiView::dropEvent(QDropEvent * event)
929 QList<QUrl> files = event->mimeData()->urls();
933 LYXERR(Debug::GUI, "GuiView::dropEvent: got URLs!");
934 for (int i = 0; i != files.size(); ++i) {
935 string const file = os::internal_path(fromqstr(
936 files.at(i).toLocalFile()));
940 string const ext = support::getExtension(file);
941 vector<const Format *> found_formats;
943 // Find all formats that have the correct extension.
944 vector<const Format *> const & import_formats
945 = theConverters().importableFormats();
946 vector<const Format *>::const_iterator it = import_formats.begin();
947 for (; it != import_formats.end(); ++it)
948 if ((*it)->hasExtension(ext))
949 found_formats.push_back(*it);
952 if (found_formats.size() >= 1) {
953 if (found_formats.size() > 1) {
954 //FIXME: show a dialog to choose the correct importable format
956 "Multiple importable formats found, selecting first");
958 string const arg = found_formats[0]->name() + " " + file;
959 cmd = FuncRequest(LFUN_BUFFER_IMPORT, arg);
962 //FIXME: do we have to explicitly check whether it's a lyx file?
964 "No formats found, trying to open it as a lyx file");
965 cmd = FuncRequest(LFUN_FILE_OPEN, file);
967 // add the functions to the queue
968 guiApp->addToFuncRequestQueue(cmd);
971 // now process the collected functions. We perform the events
972 // asynchronously. This prevents potential problems in case the
973 // BufferView is closed within an event.
974 guiApp->processFuncRequestQueueAsync();
978 void GuiView::message(docstring const & str)
980 if (ForkedProcess::iAmAChild())
983 // call is moved to GUI-thread by GuiProgress
984 d.progress_->appendMessage(toqstr(str));
988 void GuiView::clearMessageText()
990 message(docstring());
994 void GuiView::updateStatusBarMessage(QString const & str)
996 statusBar()->showMessage(str);
997 d.statusbar_timer_.stop();
998 d.statusbar_timer_.start(3000);
1002 void GuiView::smallSizedIcons()
1004 setIconSize(QSize(d.smallIconSize, d.smallIconSize));
1008 void GuiView::normalSizedIcons()
1010 setIconSize(QSize(d.normalIconSize, d.normalIconSize));
1014 void GuiView::bigSizedIcons()
1016 setIconSize(QSize(d.bigIconSize, d.bigIconSize));
1020 void GuiView::clearMessage()
1022 // FIXME: This code was introduced in r19643 to fix bug #4123. However,
1023 // the hasFocus function mostly returns false, even if the focus is on
1024 // a workarea in this view.
1028 d.statusbar_timer_.stop();
1032 void GuiView::updateWindowTitle(GuiWorkArea * wa)
1034 if (wa != d.current_work_area_
1035 || wa->bufferView().buffer().isInternal())
1037 setWindowTitle(qt_("LyX: ") + wa->windowTitle());
1038 setWindowIconText(wa->windowIconText());
1039 #if (QT_VERSION >= 0x040400)
1040 // Sets the path for the window: this is used by OSX to
1041 // allow a context click on the title bar showing a menu
1042 // with the path up to the file
1043 setWindowFilePath(toqstr(wa->bufferView().buffer().absFileName()));
1048 void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
1050 if (d.current_work_area_)
1051 QObject::disconnect(d.current_work_area_, SIGNAL(busy(bool)),
1052 this, SLOT(setBusy(bool)));
1054 disconnectBufferView();
1055 connectBufferView(wa->bufferView());
1056 connectBuffer(wa->bufferView().buffer());
1057 d.current_work_area_ = wa;
1058 QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
1059 this, SLOT(updateWindowTitle(GuiWorkArea *)));
1060 QObject::connect(wa, SIGNAL(busy(bool)), this, SLOT(setBusy(bool)));
1061 updateWindowTitle(wa);
1065 // The document settings needs to be reinitialised.
1066 updateDialog("document", "");
1068 // Buffer-dependent dialogs must be updated. This is done here because
1069 // some dialogs require buffer()->text.
1074 void GuiView::on_lastWorkAreaRemoved()
1077 // We already are in a close event. Nothing more to do.
1080 if (d.splitter_->count() > 1)
1081 // We have a splitter so don't close anything.
1084 // Reset and updates the dialogs.
1085 d.toc_models_.reset(0);
1086 updateDialog("document", "");
1089 resetWindowTitleAndIconText();
1092 if (lyxrc.open_buffers_in_tabs)
1093 // Nothing more to do, the window should stay open.
1096 if (guiApp->viewIds().size() > 1) {
1102 // On Mac we also close the last window because the application stay
1103 // resident in memory. On other platforms we don't close the last
1104 // window because this would quit the application.
1110 void GuiView::updateStatusBar()
1112 // let the user see the explicit message
1113 if (d.statusbar_timer_.isActive())
1120 void GuiView::showMessage()
1124 QString msg = toqstr(theGuiApp()->viewStatusMessage());
1125 if (msg.isEmpty()) {
1126 BufferView const * bv = currentBufferView();
1128 msg = toqstr(bv->cursor().currentState());
1130 msg = qt_("Welcome to LyX!");
1132 statusBar()->showMessage(msg);
1136 bool GuiView::event(QEvent * e)
1140 // Useful debug code:
1141 //case QEvent::ActivationChange:
1142 //case QEvent::WindowDeactivate:
1143 //case QEvent::Paint:
1144 //case QEvent::Enter:
1145 //case QEvent::Leave:
1146 //case QEvent::HoverEnter:
1147 //case QEvent::HoverLeave:
1148 //case QEvent::HoverMove:
1149 //case QEvent::StatusTip:
1150 //case QEvent::DragEnter:
1151 //case QEvent::DragLeave:
1152 //case QEvent::Drop:
1155 case QEvent::WindowActivate: {
1156 GuiView * old_view = guiApp->currentView();
1157 if (this == old_view) {
1159 return QMainWindow::event(e);
1161 if (old_view && old_view->currentBufferView()) {
1162 // save current selection to the selection buffer to allow
1163 // middle-button paste in this window.
1164 cap::saveSelection(old_view->currentBufferView()->cursor());
1166 guiApp->setCurrentView(this);
1167 if (d.current_work_area_) {
1168 BufferView & bv = d.current_work_area_->bufferView();
1169 connectBufferView(bv);
1170 connectBuffer(bv.buffer());
1171 // The document structure, name and dialogs might have
1172 // changed in another view.
1174 // The document settings needs to be reinitialised.
1175 updateDialog("document", "");
1178 resetWindowTitleAndIconText();
1181 return QMainWindow::event(e);
1184 case QEvent::ShortcutOverride: {
1186 if (isFullScreen() && menuBar()->isHidden()) {
1187 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
1188 // FIXME: we should also try to detect special LyX shortcut such as
1189 // Alt-P and Alt-M. Right now there is a hack in
1190 // GuiWorkArea::processKeySym() that hides again the menubar for
1192 if (ke->modifiers() & Qt::AltModifier && ke->key() != Qt::Key_Alt) {
1194 return QMainWindow::event(e);
1197 return QMainWindow::event(e);
1201 return QMainWindow::event(e);
1205 void GuiView::resetWindowTitleAndIconText()
1207 setWindowTitle(qt_("LyX"));
1208 setWindowIconText(qt_("LyX"));
1211 bool GuiView::focusNextPrevChild(bool /*next*/)
1218 bool GuiView::busy() const
1224 void GuiView::setBusy(bool busy)
1226 bool const busy_before = busy_ > 0;
1227 busy ? ++busy_ : --busy_;
1228 if ((busy_ > 0) == busy_before)
1229 // busy state didn't change
1233 QApplication::setOverrideCursor(Qt::WaitCursor);
1236 QApplication::restoreOverrideCursor();
1241 double GuiView::pixelRatio() const
1243 #if QT_VERSION >= 0x050000
1244 return devicePixelRatio();
1251 GuiWorkArea * GuiView::workArea(int index)
1253 if (TabWorkArea * twa = d.currentTabWorkArea())
1254 if (index < twa->count())
1255 return dynamic_cast<GuiWorkArea *>(twa->widget(index));
1260 GuiWorkArea * GuiView::workArea(Buffer & buffer)
1262 if (currentWorkArea()
1263 && ¤tWorkArea()->bufferView().buffer() == &buffer)
1264 return (GuiWorkArea *) currentWorkArea();
1265 if (TabWorkArea * twa = d.currentTabWorkArea())
1266 return twa->workArea(buffer);
1271 GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
1273 // Automatically create a TabWorkArea if there are none yet.
1274 TabWorkArea * tab_widget = d.splitter_->count()
1275 ? d.currentTabWorkArea() : addTabWorkArea();
1276 return tab_widget->addWorkArea(buffer, *this);
1280 TabWorkArea * GuiView::addTabWorkArea()
1282 TabWorkArea * twa = new TabWorkArea;
1283 QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
1284 this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
1285 QObject::connect(twa, SIGNAL(lastWorkAreaRemoved()),
1286 this, SLOT(on_lastWorkAreaRemoved()));
1288 d.splitter_->addWidget(twa);
1289 d.stack_widget_->setCurrentWidget(d.splitter_);
1294 GuiWorkArea const * GuiView::currentWorkArea() const
1296 return d.current_work_area_;
1300 GuiWorkArea * GuiView::currentWorkArea()
1302 return d.current_work_area_;
1306 GuiWorkArea const * GuiView::currentMainWorkArea() const
1308 if (!d.currentTabWorkArea())
1310 return d.currentTabWorkArea()->currentWorkArea();
1314 GuiWorkArea * GuiView::currentMainWorkArea()
1316 if (!d.currentTabWorkArea())
1318 return d.currentTabWorkArea()->currentWorkArea();
1322 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
1324 LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
1326 d.current_work_area_ = 0;
1331 // FIXME: I've no clue why this is here and why it accesses
1332 // theGuiApp()->currentView, which might be 0 (bug 6464).
1333 // See also 27525 (vfr).
1334 if (theGuiApp()->currentView() == this
1335 && theGuiApp()->currentView()->currentWorkArea() == wa)
1338 if (currentBufferView())
1339 cap::saveSelection(currentBufferView()->cursor());
1341 theGuiApp()->setCurrentView(this);
1342 d.current_work_area_ = wa;
1344 // We need to reset this now, because it will need to be
1345 // right if the tabWorkArea gets reset in the for loop. We
1346 // will change it back if we aren't in that case.
1347 GuiWorkArea * const old_cmwa = d.current_main_work_area_;
1348 d.current_main_work_area_ = wa;
1350 for (int i = 0; i != d.splitter_->count(); ++i) {
1351 if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
1352 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea()
1353 << ", Current main wa: " << currentMainWorkArea());
1358 d.current_main_work_area_ = old_cmwa;
1360 LYXERR(Debug::DEBUG, "This is not a tabbed wa");
1361 on_currentWorkAreaChanged(wa);
1362 BufferView & bv = wa->bufferView();
1363 bv.cursor().fixIfBroken();
1365 wa->setUpdatesEnabled(true);
1366 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
1370 void GuiView::removeWorkArea(GuiWorkArea * wa)
1372 LASSERT(wa, return);
1373 if (wa == d.current_work_area_) {
1375 disconnectBufferView();
1376 d.current_work_area_ = 0;
1377 d.current_main_work_area_ = 0;
1380 bool found_twa = false;
1381 for (int i = 0; i != d.splitter_->count(); ++i) {
1382 TabWorkArea * twa = d.tabWorkArea(i);
1383 if (twa->removeWorkArea(wa)) {
1384 // Found in this tab group, and deleted the GuiWorkArea.
1386 if (twa->count() != 0) {
1387 if (d.current_work_area_ == 0)
1388 // This means that we are closing the current GuiWorkArea, so
1389 // switch to the next GuiWorkArea in the found TabWorkArea.
1390 setCurrentWorkArea(twa->currentWorkArea());
1392 // No more WorkAreas in this tab group, so delete it.
1399 // It is not a tabbed work area (i.e., the search work area), so it
1400 // should be deleted by other means.
1401 LASSERT(found_twa, return);
1403 if (d.current_work_area_ == 0) {
1404 if (d.splitter_->count() != 0) {
1405 TabWorkArea * twa = d.currentTabWorkArea();
1406 setCurrentWorkArea(twa->currentWorkArea());
1408 // No more work areas, switch to the background widget.
1409 setCurrentWorkArea(0);
1415 LayoutBox * GuiView::getLayoutDialog() const
1421 void GuiView::updateLayoutList()
1424 d.layout_->updateContents(false);
1428 void GuiView::updateToolbars()
1430 ToolbarMap::iterator end = d.toolbars_.end();
1431 if (d.current_work_area_) {
1433 d.current_work_area_->bufferView().cursor().inMathed()
1434 && !d.current_work_area_->bufferView().cursor().inRegexped();
1436 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
1438 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
1439 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onOff(true);
1440 bool const mathmacrotemplate =
1441 lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
1443 lyx::getStatus(FuncRequest(LFUN_IN_IPA)).enabled();
1445 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1446 it->second->update(math, table, review, mathmacrotemplate, ipa);
1448 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1449 it->second->update(false, false, false, false, false);
1453 void GuiView::setBuffer(Buffer * newBuffer)
1455 LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl);
1456 LASSERT(newBuffer, return);
1458 GuiWorkArea * wa = workArea(*newBuffer);
1461 newBuffer->masterBuffer()->updateBuffer();
1463 wa = addWorkArea(*newBuffer);
1464 // scroll to the position when the BufferView was last closed
1465 if (lyxrc.use_lastfilepos) {
1466 LastFilePosSection::FilePos filepos =
1467 theSession().lastFilePos().load(newBuffer->fileName());
1468 wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
1471 //Disconnect the old buffer...there's no new one.
1474 connectBuffer(*newBuffer);
1475 connectBufferView(wa->bufferView());
1476 setCurrentWorkArea(wa);
1480 void GuiView::connectBuffer(Buffer & buf)
1482 buf.setGuiDelegate(this);
1486 void GuiView::disconnectBuffer()
1488 if (d.current_work_area_)
1489 d.current_work_area_->bufferView().buffer().setGuiDelegate(0);
1493 void GuiView::connectBufferView(BufferView & bv)
1495 bv.setGuiDelegate(this);
1499 void GuiView::disconnectBufferView()
1501 if (d.current_work_area_)
1502 d.current_work_area_->bufferView().setGuiDelegate(0);
1506 void GuiView::errors(string const & error_type, bool from_master)
1508 BufferView const * const bv = currentBufferView();
1512 #if EXPORT_in_THREAD
1513 // We are called with from_master == false by default, so we
1514 // have to figure out whether that is the case or not.
1515 ErrorList & el = bv->buffer().errorList(error_type);
1517 el = bv->buffer().masterBuffer()->errorList(error_type);
1521 ErrorList const & el = from_master ?
1522 bv->buffer().masterBuffer()->errorList(error_type) :
1523 bv->buffer().errorList(error_type);
1529 string data = error_type;
1531 data = "from_master|" + error_type;
1532 showDialog("errorlist", data);
1536 void GuiView::updateTocItem(string const & type, DocIterator const & dit)
1538 d.toc_models_.updateItem(toqstr(type), dit);
1542 void GuiView::structureChanged()
1544 d.toc_models_.reset(documentBufferView());
1545 // Navigator needs more than a simple update in this case. It needs to be
1547 updateDialog("toc", "");
1551 void GuiView::updateDialog(string const & name, string const & data)
1553 if (!isDialogVisible(name))
1556 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
1557 if (it == d.dialogs_.end())
1560 Dialog * const dialog = it->second.get();
1561 if (dialog->isVisibleView())
1562 dialog->initialiseParams(data);
1566 BufferView * GuiView::documentBufferView()
1568 return currentMainWorkArea()
1569 ? ¤tMainWorkArea()->bufferView()
1574 BufferView const * GuiView::documentBufferView() const
1576 return currentMainWorkArea()
1577 ? ¤tMainWorkArea()->bufferView()
1582 BufferView * GuiView::currentBufferView()
1584 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1588 BufferView const * GuiView::currentBufferView() const
1590 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1594 docstring GuiView::GuiViewPrivate::autosaveAndDestroy(
1595 Buffer const * orig, Buffer * clone)
1597 bool const success = clone->autoSave();
1599 busyBuffers.remove(orig);
1601 ? _("Automatic save done.")
1602 : _("Automatic save failed!");
1606 void GuiView::autoSave()
1608 LYXERR(Debug::INFO, "Running autoSave()");
1610 Buffer * buffer = documentBufferView()
1611 ? &documentBufferView()->buffer() : 0;
1613 resetAutosaveTimers();
1617 GuiViewPrivate::busyBuffers.insert(buffer);
1618 QFuture<docstring> f = QtConcurrent::run(GuiViewPrivate::autosaveAndDestroy,
1619 buffer, buffer->cloneBufferOnly());
1620 d.autosave_watcher_.setFuture(f);
1621 resetAutosaveTimers();
1625 void GuiView::resetAutosaveTimers()
1628 d.autosave_timeout_.restart();
1632 bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
1635 Buffer * buf = currentBufferView()
1636 ? ¤tBufferView()->buffer() : 0;
1637 Buffer * doc_buffer = documentBufferView()
1638 ? &(documentBufferView()->buffer()) : 0;
1640 // Check whether we need a buffer
1641 if (!lyxaction.funcHasFlag(cmd.action(), LyXAction::NoBuffer) && !buf) {
1642 // no, exit directly
1643 flag.message(from_utf8(N_("Command not allowed with"
1644 "out any document open")));
1645 flag.setEnabled(false);
1649 if (cmd.origin() == FuncRequest::TOC) {
1650 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
1651 if (!toc || !toc->getStatus(documentBufferView()->cursor(), cmd, flag))
1652 flag.setEnabled(false);
1656 switch(cmd.action()) {
1657 case LFUN_BUFFER_IMPORT:
1660 case LFUN_MASTER_BUFFER_UPDATE:
1661 case LFUN_MASTER_BUFFER_VIEW:
1663 && (doc_buffer->parent() != 0
1664 || doc_buffer->hasChildren())
1665 && !d.processing_thread_watcher_.isRunning();
1668 case LFUN_BUFFER_UPDATE:
1669 case LFUN_BUFFER_VIEW: {
1670 if (!doc_buffer || d.processing_thread_watcher_.isRunning()) {
1674 string format = to_utf8(cmd.argument());
1675 if (cmd.argument().empty())
1676 format = doc_buffer->params().getDefaultOutputFormat();
1677 enable = doc_buffer->params().isExportableFormat(format);
1681 case LFUN_BUFFER_RELOAD:
1682 enable = doc_buffer && !doc_buffer->isUnnamed()
1683 && doc_buffer->fileName().exists()
1684 && (!doc_buffer->isClean()
1685 || doc_buffer->isExternallyModified(Buffer::timestamp_method));
1688 case LFUN_BUFFER_CHILD_OPEN:
1689 enable = doc_buffer;
1692 case LFUN_BUFFER_WRITE:
1693 enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
1696 //FIXME: This LFUN should be moved to GuiApplication.
1697 case LFUN_BUFFER_WRITE_ALL: {
1698 // We enable the command only if there are some modified buffers
1699 Buffer * first = theBufferList().first();
1704 // We cannot use a for loop as the buffer list is a cycle.
1706 if (!b->isClean()) {
1710 b = theBufferList().next(b);
1711 } while (b != first);
1715 case LFUN_BUFFER_WRITE_AS:
1716 case LFUN_BUFFER_EXPORT_AS:
1717 enable = doc_buffer;
1720 case LFUN_BUFFER_CLOSE:
1721 case LFUN_VIEW_CLOSE:
1722 enable = doc_buffer;
1725 case LFUN_BUFFER_CLOSE_ALL:
1726 enable = theBufferList().last() != theBufferList().first();
1729 case LFUN_VIEW_SPLIT:
1730 if (cmd.getArg(0) == "vertical")
1731 enable = doc_buffer && (d.splitter_->count() == 1 ||
1732 d.splitter_->orientation() == Qt::Vertical);
1734 enable = doc_buffer && (d.splitter_->count() == 1 ||
1735 d.splitter_->orientation() == Qt::Horizontal);
1738 case LFUN_TAB_GROUP_CLOSE:
1739 enable = d.tabWorkAreaCount() > 1;
1742 case LFUN_TOOLBAR_TOGGLE: {
1743 string const name = cmd.getArg(0);
1744 if (GuiToolbar * t = toolbar(name))
1745 flag.setOnOff(t->isVisible());
1748 docstring const msg =
1749 bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
1755 case LFUN_DROP_LAYOUTS_CHOICE:
1759 case LFUN_UI_TOGGLE:
1760 flag.setOnOff(isFullScreen());
1763 case LFUN_DIALOG_DISCONNECT_INSET:
1766 case LFUN_DIALOG_HIDE:
1767 // FIXME: should we check if the dialog is shown?
1770 case LFUN_DIALOG_TOGGLE:
1771 flag.setOnOff(isDialogVisible(cmd.getArg(0)));
1772 // fall through to set "enable"
1773 case LFUN_DIALOG_SHOW: {
1774 string const name = cmd.getArg(0);
1776 enable = name == "aboutlyx"
1777 || name == "file" //FIXME: should be removed.
1779 || name == "texinfo"
1780 || name == "progress"
1781 || name == "compare";
1782 else if (name == "print")
1783 enable = doc_buffer->params().isExportable("dvi")
1784 && lyxrc.print_command != "none";
1785 else if (name == "character" || name == "symbols"
1786 || name == "mathdelimiter" || name == "mathmatrix") {
1787 if (!buf || buf->isReadonly())
1790 Cursor const & cur = currentBufferView()->cursor();
1791 enable = !(cur.inTexted() && cur.paragraph().isPassThru());
1794 else if (name == "latexlog")
1795 enable = FileName(doc_buffer->logName()).isReadableFile();
1796 else if (name == "spellchecker")
1797 enable = theSpellChecker()
1798 && !doc_buffer->isReadonly()
1799 && !doc_buffer->text().empty();
1800 else if (name == "vclog")
1801 enable = doc_buffer->lyxvc().inUse();
1805 case LFUN_DIALOG_UPDATE: {
1806 string const name = cmd.getArg(0);
1808 enable = name == "prefs";
1812 case LFUN_COMMAND_EXECUTE:
1814 case LFUN_MENU_OPEN:
1815 // Nothing to check.
1818 case LFUN_COMPLETION_INLINE:
1819 if (!d.current_work_area_
1820 || !d.current_work_area_->completer().inlinePossible(
1821 currentBufferView()->cursor()))
1825 case LFUN_COMPLETION_POPUP:
1826 if (!d.current_work_area_
1827 || !d.current_work_area_->completer().popupPossible(
1828 currentBufferView()->cursor()))
1833 if (!d.current_work_area_
1834 || !d.current_work_area_->completer().inlinePossible(
1835 currentBufferView()->cursor()))
1839 case LFUN_COMPLETION_ACCEPT:
1840 if (!d.current_work_area_
1841 || (!d.current_work_area_->completer().popupVisible()
1842 && !d.current_work_area_->completer().inlineVisible()
1843 && !d.current_work_area_->completer().completionAvailable()))
1847 case LFUN_COMPLETION_CANCEL:
1848 if (!d.current_work_area_
1849 || (!d.current_work_area_->completer().popupVisible()
1850 && !d.current_work_area_->completer().inlineVisible()))
1854 case LFUN_BUFFER_ZOOM_OUT:
1855 enable = doc_buffer && lyxrc.zoom > 10;
1858 case LFUN_BUFFER_ZOOM_IN:
1859 enable = doc_buffer;
1862 case LFUN_BUFFER_NEXT:
1863 case LFUN_BUFFER_PREVIOUS:
1864 // FIXME: should we check is there is an previous or next buffer?
1866 case LFUN_BUFFER_SWITCH:
1867 // toggle on the current buffer, but do not toggle off
1868 // the other ones (is that a good idea?)
1870 && to_utf8(cmd.argument()) == doc_buffer->absFileName())
1871 flag.setOnOff(true);
1874 case LFUN_VC_REGISTER:
1875 enable = doc_buffer && !doc_buffer->lyxvc().inUse();
1877 case LFUN_VC_RENAME:
1878 enable = doc_buffer && doc_buffer->lyxvc().renameEnabled();
1881 enable = doc_buffer && doc_buffer->lyxvc().copyEnabled();
1883 case LFUN_VC_CHECK_IN:
1884 enable = doc_buffer && doc_buffer->lyxvc().checkInEnabled();
1886 case LFUN_VC_CHECK_OUT:
1887 enable = doc_buffer && doc_buffer->lyxvc().checkOutEnabled();
1889 case LFUN_VC_LOCKING_TOGGLE:
1890 enable = doc_buffer && !doc_buffer->isReadonly()
1891 && doc_buffer->lyxvc().lockingToggleEnabled();
1892 flag.setOnOff(enable && doc_buffer->lyxvc().locking());
1894 case LFUN_VC_REVERT:
1895 enable = doc_buffer && doc_buffer->lyxvc().inUse() && !doc_buffer->isReadonly();
1897 case LFUN_VC_UNDO_LAST:
1898 enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
1900 case LFUN_VC_REPO_UPDATE:
1901 enable = doc_buffer && doc_buffer->lyxvc().repoUpdateEnabled();
1903 case LFUN_VC_COMMAND: {
1904 if (cmd.argument().empty())
1906 if (!doc_buffer && contains(cmd.getArg(0), 'D'))
1910 case LFUN_VC_COMPARE:
1911 enable = doc_buffer && doc_buffer->lyxvc().prepareFileRevisionEnabled();
1914 case LFUN_SERVER_GOTO_FILE_ROW:
1916 case LFUN_FORWARD_SEARCH:
1917 enable = !(lyxrc.forward_search_dvi.empty() && lyxrc.forward_search_pdf.empty());
1920 case LFUN_FILE_INSERT_PLAINTEXT:
1921 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
1922 enable = documentBufferView() && documentBufferView()->cursor().inTexted();
1925 case LFUN_SPELLING_CONTINUOUSLY:
1926 flag.setOnOff(lyxrc.spellcheck_continuously);
1934 flag.setEnabled(false);
1940 static FileName selectTemplateFile()
1942 FileDialog dlg(qt_("Select template file"));
1943 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1944 dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
1946 FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
1947 QStringList(qt_("LyX Documents (*.lyx)")));
1949 if (result.first == FileDialog::Later)
1951 if (result.second.isEmpty())
1953 return FileName(fromqstr(result.second));
1957 Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
1961 Buffer * newBuffer = 0;
1963 newBuffer = checkAndLoadLyXFile(filename);
1964 } catch (ExceptionMessage const & e) {
1971 message(_("Document not loaded."));
1975 setBuffer(newBuffer);
1976 newBuffer->errors("Parse");
1979 theSession().lastFiles().add(filename);
1985 void GuiView::openDocument(string const & fname)
1987 string initpath = lyxrc.document_path;
1989 if (documentBufferView()) {
1990 string const trypath = documentBufferView()->buffer().filePath();
1991 // If directory is writeable, use this as default.
1992 if (FileName(trypath).isDirWritable())
1998 if (fname.empty()) {
1999 FileDialog dlg(qt_("Select document to open"));
2000 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2001 dlg.setButton2(qt_("Examples|#E#e"),
2002 toqstr(addPath(package().system_support().absFileName(), "examples")));
2004 QStringList const filter(qt_("LyX Documents (*.lyx)"));
2005 FileDialog::Result result =
2006 dlg.open(toqstr(initpath), filter);
2008 if (result.first == FileDialog::Later)
2011 filename = fromqstr(result.second);
2013 // check selected filename
2014 if (filename.empty()) {
2015 message(_("Canceled."));
2021 // get absolute path of file and add ".lyx" to the filename if
2023 FileName const fullname =
2024 fileSearch(string(), filename, "lyx", support::may_not_exist);
2025 if (!fullname.empty())
2026 filename = fullname.absFileName();
2028 if (!fullname.onlyPath().isDirectory()) {
2029 Alert::warning(_("Invalid filename"),
2030 bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
2031 from_utf8(fullname.absFileName())));
2035 // if the file doesn't exist and isn't already open (bug 6645),
2036 // let the user create one
2037 if (!fullname.exists() && !theBufferList().exists(fullname) &&
2038 !LyXVC::file_not_found_hook(fullname)) {
2039 // the user specifically chose this name. Believe him.
2040 Buffer * const b = newFile(filename, string(), true);
2046 docstring const disp_fn = makeDisplayPath(filename);
2047 message(bformat(_("Opening document %1$s..."), disp_fn));
2050 Buffer * buf = loadDocument(fullname);
2052 str2 = bformat(_("Document %1$s opened."), disp_fn);
2053 if (buf->lyxvc().inUse())
2054 str2 += " " + from_utf8(buf->lyxvc().versionString()) +
2055 " " + _("Version control detected.");
2057 str2 = bformat(_("Could not open document %1$s"), disp_fn);
2062 // FIXME: clean that
2063 static bool import(GuiView * lv, FileName const & filename,
2064 string const & format, ErrorList & errorList)
2066 FileName const lyxfile(support::changeExtension(filename.absFileName(), ".lyx"));
2068 string loader_format;
2069 vector<string> loaders = theConverters().loaders();
2070 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
2071 vector<string>::const_iterator it = loaders.begin();
2072 vector<string>::const_iterator en = loaders.end();
2073 for (; it != en; ++it) {
2074 if (!theConverters().isReachable(format, *it))
2077 string const tofile =
2078 support::changeExtension(filename.absFileName(),
2079 formats.extension(*it));
2080 if (!theConverters().convert(0, filename, FileName(tofile),
2081 filename, format, *it, errorList))
2083 loader_format = *it;
2086 if (loader_format.empty()) {
2087 frontend::Alert::error(_("Couldn't import file"),
2088 bformat(_("No information for importing the format %1$s."),
2089 formats.prettyName(format)));
2093 loader_format = format;
2095 if (loader_format == "lyx") {
2096 Buffer * buf = lv->loadDocument(lyxfile);
2100 Buffer * const b = newFile(lyxfile.absFileName(), string(), true);
2104 bool as_paragraphs = loader_format == "textparagraph";
2105 string filename2 = (loader_format == format) ? filename.absFileName()
2106 : support::changeExtension(filename.absFileName(),
2107 formats.extension(loader_format));
2108 lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
2110 guiApp->setCurrentView(lv);
2111 lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
2118 void GuiView::importDocument(string const & argument)
2121 string filename = split(argument, format, ' ');
2123 LYXERR(Debug::INFO, format << " file: " << filename);
2125 // need user interaction
2126 if (filename.empty()) {
2127 string initpath = lyxrc.document_path;
2128 if (documentBufferView()) {
2129 string const trypath = documentBufferView()->buffer().filePath();
2130 // If directory is writeable, use this as default.
2131 if (FileName(trypath).isDirWritable())
2135 docstring const text = bformat(_("Select %1$s file to import"),
2136 formats.prettyName(format));
2138 FileDialog dlg(toqstr(text));
2139 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2140 dlg.setButton2(qt_("Examples|#E#e"),
2141 toqstr(addPath(package().system_support().absFileName(), "examples")));
2143 docstring filter = formats.prettyName(format);
2146 filter += from_utf8(formats.extensions(format));
2149 FileDialog::Result result =
2150 dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
2152 if (result.first == FileDialog::Later)
2155 filename = fromqstr(result.second);
2157 // check selected filename
2158 if (filename.empty())
2159 message(_("Canceled."));
2162 if (filename.empty())
2165 // get absolute path of file
2166 FileName const fullname(support::makeAbsPath(filename));
2168 // Can happen if the user entered a path into the dialog
2170 if (fullname.onlyFileName().empty()) {
2171 docstring msg = bformat(_("The file name '%1$s' is invalid!\n"
2172 "Aborting import."),
2173 from_utf8(fullname.absFileName()));
2174 frontend::Alert::error(_("File name error"), msg);
2175 message(_("Canceled."));
2180 FileName const lyxfile(support::changeExtension(fullname.absFileName(), ".lyx"));
2182 // Check if the document already is open
2183 Buffer * buf = theBufferList().getBuffer(lyxfile);
2186 if (!closeBuffer()) {
2187 message(_("Canceled."));
2192 docstring const displaypath = makeDisplayPath(lyxfile.absFileName(), 30);
2194 // if the file exists already, and we didn't do
2195 // -i lyx thefile.lyx, warn
2196 if (lyxfile.exists() && fullname != lyxfile) {
2198 docstring text = bformat(_("The document %1$s already exists.\n\n"
2199 "Do you want to overwrite that document?"), displaypath);
2200 int const ret = Alert::prompt(_("Overwrite document?"),
2201 text, 0, 1, _("&Overwrite"), _("&Cancel"));
2204 message(_("Canceled."));
2209 message(bformat(_("Importing %1$s..."), displaypath));
2210 ErrorList errorList;
2211 if (import(this, fullname, format, errorList))
2212 message(_("imported."));
2214 message(_("file not imported!"));
2216 // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
2220 void GuiView::newDocument(string const & filename, bool from_template)
2222 FileName initpath(lyxrc.document_path);
2223 if (documentBufferView()) {
2224 FileName const trypath(documentBufferView()->buffer().filePath());
2225 // If directory is writeable, use this as default.
2226 if (trypath.isDirWritable())
2230 string templatefile;
2231 if (from_template) {
2232 templatefile = selectTemplateFile().absFileName();
2233 if (templatefile.empty())
2238 if (filename.empty())
2239 b = newUnnamedFile(initpath, to_utf8(_("newfile")), templatefile);
2241 b = newFile(filename, templatefile, true);
2246 // If no new document could be created, it is unsure
2247 // whether there is a valid BufferView.
2248 if (currentBufferView())
2249 // Ensure the cursor is correctly positioned on screen.
2250 currentBufferView()->showCursor();
2254 void GuiView::insertLyXFile(docstring const & fname)
2256 BufferView * bv = documentBufferView();
2261 FileName filename(to_utf8(fname));
2262 if (filename.empty()) {
2263 // Launch a file browser
2265 string initpath = lyxrc.document_path;
2266 string const trypath = bv->buffer().filePath();
2267 // If directory is writeable, use this as default.
2268 if (FileName(trypath).isDirWritable())
2272 FileDialog dlg(qt_("Select LyX document to insert"));
2273 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2274 dlg.setButton2(qt_("Examples|#E#e"),
2275 toqstr(addPath(package().system_support().absFileName(),
2278 FileDialog::Result result = dlg.open(toqstr(initpath),
2279 QStringList(qt_("LyX Documents (*.lyx)")));
2281 if (result.first == FileDialog::Later)
2285 filename.set(fromqstr(result.second));
2287 // check selected filename
2288 if (filename.empty()) {
2289 // emit message signal.
2290 message(_("Canceled."));
2295 bv->insertLyXFile(filename);
2296 bv->buffer().errors("Parse");
2300 bool GuiView::renameBuffer(Buffer & b, docstring const & newname, RenameKind kind)
2302 FileName fname = b.fileName();
2303 FileName const oldname = fname;
2305 if (!newname.empty()) {
2307 fname = support::makeAbsPath(to_utf8(newname), oldname.onlyPath().absFileName());
2309 // Switch to this Buffer.
2312 // No argument? Ask user through dialog.
2314 FileDialog dlg(qt_("Choose a filename to save document as"));
2315 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2316 dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
2318 if (!isLyXFileName(fname.absFileName()))
2319 fname.changeExtension(".lyx");
2321 FileDialog::Result result =
2322 dlg.save(toqstr(fname.onlyPath().absFileName()),
2323 QStringList(qt_("LyX Documents (*.lyx)")),
2324 toqstr(fname.onlyFileName()));
2326 if (result.first == FileDialog::Later)
2329 fname.set(fromqstr(result.second));
2334 if (!isLyXFileName(fname.absFileName()))
2335 fname.changeExtension(".lyx");
2338 // fname is now the new Buffer location.
2340 // if there is already a Buffer open with this name, we do not want
2341 // to have another one. (the second test makes sure we're not just
2342 // trying to overwrite ourselves, which is fine.)
2343 if (theBufferList().exists(fname) && fname != oldname
2344 && theBufferList().getBuffer(fname) != &b) {
2345 docstring const text =
2346 bformat(_("The file\n%1$s\nis already open in your current session.\n"
2347 "Please close it before attempting to overwrite it.\n"
2348 "Do you want to choose a new filename?"),
2349 from_utf8(fname.absFileName()));
2350 int const ret = Alert::prompt(_("Chosen File Already Open"),
2351 text, 0, 1, _("&Rename"), _("&Cancel"));
2353 case 0: return renameBuffer(b, docstring(), kind);
2354 case 1: return false;
2359 bool const existsLocal = fname.exists();
2360 bool const existsInVC = LyXVC::fileInVC(fname);
2361 if (existsLocal || existsInVC) {
2362 docstring const file = makeDisplayPath(fname.absFileName(), 30);
2363 if (kind != LV_WRITE_AS && existsInVC) {
2364 // renaming to a name that is already in VC
2366 docstring text = bformat(_("The document %1$s "
2367 "is already registered.\n\n"
2368 "Do you want to choose a new name?"),
2370 docstring const title = (kind == LV_VC_RENAME) ?
2371 _("Rename document?") : _("Copy document?");
2372 docstring const button = (kind == LV_VC_RENAME) ?
2373 _("&Rename") : _("&Copy");
2374 int const ret = Alert::prompt(title, text, 0, 1,
2375 button, _("&Cancel"));
2377 case 0: return renameBuffer(b, docstring(), kind);
2378 case 1: return false;
2383 docstring text = bformat(_("The document %1$s "
2384 "already exists.\n\n"
2385 "Do you want to overwrite that document?"),
2387 int const ret = Alert::prompt(_("Overwrite document?"),
2388 text, 0, 2, _("&Overwrite"),
2389 _("&Rename"), _("&Cancel"));
2392 case 1: return renameBuffer(b, docstring(), kind);
2393 case 2: return false;
2399 case LV_VC_RENAME: {
2400 string msg = b.lyxvc().rename(fname);
2403 message(from_utf8(msg));
2407 string msg = b.lyxvc().copy(fname);
2410 message(from_utf8(msg));
2416 // LyXVC created the file already in case of LV_VC_RENAME or
2417 // LV_VC_COPY, but call saveBuffer() nevertheless to get
2418 // relative paths of included stuff right if we moved e.g. from
2419 // /a/b.lyx to /a/c/b.lyx.
2421 bool const saved = saveBuffer(b, fname);
2428 struct PrettyNameComparator
2430 bool operator()(Format const *first, Format const *second) const {
2431 return compare_no_case(translateIfPossible(from_ascii(first->prettyname())),
2432 translateIfPossible(from_ascii(second->prettyname()))) <= 0;
2437 bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
2439 FileName fname = b.fileName();
2441 FileDialog dlg(qt_("Choose a filename to export the document as"));
2442 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2445 QString const anyformat = qt_("Guess from extension (*.*)");
2447 Formats::const_iterator it = formats.begin();
2448 vector<Format const *> export_formats;
2449 for (; it != formats.end(); ++it)
2450 if (it->documentFormat())
2451 export_formats.push_back(&(*it));
2452 PrettyNameComparator cmp;
2453 sort(export_formats.begin(), export_formats.end(), cmp);
2454 vector<Format const *>::const_iterator fit = export_formats.begin();
2455 map<QString, string> fmap;
2458 for (; fit != export_formats.end(); ++fit) {
2459 docstring const loc_prettyname =
2460 translateIfPossible(from_utf8((*fit)->prettyname()));
2461 QString const loc_filter = toqstr(bformat(from_ascii("%1$s (*.%2$s)"),
2463 from_ascii((*fit)->extension())));
2464 types << loc_filter;
2465 fmap[loc_filter] = (*fit)->name();
2466 if (from_ascii((*fit)->name()) == iformat) {
2467 filter = loc_filter;
2468 ext = (*fit)->extension();
2471 string ofname = fname.onlyFileName();
2473 ofname = support::changeExtension(ofname, ext);
2474 FileDialog::Result result =
2475 dlg.save(toqstr(fname.onlyPath().absFileName()),
2479 if (result.first != FileDialog::Chosen)
2483 fname.set(fromqstr(result.second));
2484 if (filter == anyformat)
2485 fmt_name = formats.getFormatFromExtension(fname.extension());
2487 fmt_name = fmap[filter];
2488 LYXERR(Debug::FILES, "filter=" << fromqstr(filter)
2489 << ", fmt_name=" << fmt_name << ", fname=" << fname.absFileName());
2491 if (fmt_name.empty() || fname.empty())
2494 // fname is now the new Buffer location.
2495 if (FileName(fname).exists()) {
2496 docstring const file = makeDisplayPath(fname.absFileName(), 30);
2497 docstring text = bformat(_("The document %1$s already "
2498 "exists.\n\nDo you want to "
2499 "overwrite that document?"),
2501 int const ret = Alert::prompt(_("Overwrite document?"),
2502 text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
2505 case 1: return exportBufferAs(b, from_ascii(fmt_name));
2506 case 2: return false;
2510 FuncRequest cmd(LFUN_BUFFER_EXPORT, fmt_name + " " + fname.absFileName());
2513 return dr.dispatched();
2517 bool GuiView::saveBuffer(Buffer & b)
2519 return saveBuffer(b, FileName());
2523 bool GuiView::saveBuffer(Buffer & b, FileName const & fn)
2525 if (workArea(b) && workArea(b)->inDialogMode())
2528 if (fn.empty() && b.isUnnamed())
2529 return renameBuffer(b, docstring());
2531 bool const success = (fn.empty() ? b.save() : b.saveAs(fn));
2533 theSession().lastFiles().add(b.fileName());
2537 // Switch to this Buffer.
2540 // FIXME: we don't tell the user *WHY* the save failed !!
2541 docstring const file = makeDisplayPath(b.absFileName(), 30);
2542 docstring text = bformat(_("The document %1$s could not be saved.\n\n"
2543 "Do you want to rename the document and "
2544 "try again?"), file);
2545 int const ret = Alert::prompt(_("Rename and save?"),
2546 text, 0, 2, _("&Rename"), _("&Retry"), _("&Cancel"));
2549 if (!renameBuffer(b, docstring()))
2558 return saveBuffer(b, fn);
2562 bool GuiView::hideWorkArea(GuiWorkArea * wa)
2564 return closeWorkArea(wa, false);
2568 // We only want to close the buffer if it is not visible in other workareas
2569 // of the same view, nor in other views, and if this is not a child
2570 bool GuiView::closeWorkArea(GuiWorkArea * wa)
2572 Buffer & buf = wa->bufferView().buffer();
2574 bool last_wa = d.countWorkAreasOf(buf) == 1
2575 && !inOtherView(buf) && !buf.parent();
2577 bool close_buffer = last_wa;
2580 if (lyxrc.close_buffer_with_last_view == "yes")
2582 else if (lyxrc.close_buffer_with_last_view == "no")
2583 close_buffer = false;
2586 if (buf.isUnnamed())
2587 file = from_utf8(buf.fileName().onlyFileName());
2589 file = buf.fileName().displayName(30);
2590 docstring const text = bformat(
2591 _("Last view on document %1$s is being closed.\n"
2592 "Would you like to close or hide the document?\n"
2594 "Hidden documents can be displayed back through\n"
2595 "the menu: View->Hidden->...\n"
2597 "To remove this question, set your preference in:\n"
2598 " Tools->Preferences->Look&Feel->UserInterface\n"
2600 int ret = Alert::prompt(_("Close or hide document?"),
2601 text, 0, 1, _("&Close"), _("&Hide"));
2602 close_buffer = (ret == 0);
2606 return closeWorkArea(wa, close_buffer);
2610 bool GuiView::closeBuffer()
2612 GuiWorkArea * wa = currentMainWorkArea();
2613 setCurrentWorkArea(wa);
2614 Buffer & buf = wa->bufferView().buffer();
2615 return wa && closeWorkArea(wa, !buf.parent());
2619 void GuiView::writeSession() const {
2620 GuiWorkArea const * active_wa = currentMainWorkArea();
2621 for (int i = 0; i < d.splitter_->count(); ++i) {
2622 TabWorkArea * twa = d.tabWorkArea(i);
2623 for (int j = 0; j < twa->count(); ++j) {
2624 GuiWorkArea * wa = static_cast<GuiWorkArea *>(twa->widget(j));
2625 Buffer & buf = wa->bufferView().buffer();
2626 theSession().lastOpened().add(buf.fileName(), wa == active_wa);
2632 bool GuiView::closeBufferAll()
2634 // Close the workareas in all other views
2635 QList<int> const ids = guiApp->viewIds();
2636 for (int i = 0; i != ids.size(); ++i) {
2637 if (id_ != ids[i] && !guiApp->view(ids[i]).closeWorkAreaAll())
2641 // Close our own workareas
2642 if (!closeWorkAreaAll())
2645 // Now close the hidden buffers. We prevent hidden buffers from being
2646 // dirty, so we can just close them.
2647 theBufferList().closeAll();
2652 bool GuiView::closeWorkAreaAll()
2654 setCurrentWorkArea(currentMainWorkArea());
2656 // We might be in a situation that there is still a tabWorkArea, but
2657 // there are no tabs anymore. This can happen when we get here after a
2658 // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
2659 // many TabWorkArea's have no documents anymore.
2662 // We have to call count() each time, because it can happen that
2663 // more than one splitter will disappear in one iteration (bug 5998).
2664 for (; d.splitter_->count() > empty_twa; ) {
2665 TabWorkArea * twa = d.tabWorkArea(empty_twa);
2667 if (twa->count() == 0)
2670 setCurrentWorkArea(twa->currentWorkArea());
2671 if (!closeTabWorkArea(twa))
2679 bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer)
2684 Buffer & buf = wa->bufferView().buffer();
2686 if (close_buffer && GuiViewPrivate::busyBuffers.contains(&buf)) {
2687 Alert::warning(_("Close document"),
2688 _("Document could not be closed because it is being processed by LyX."));
2693 return closeBuffer(buf);
2695 if (!inMultiTabs(wa))
2696 if (!saveBufferIfNeeded(buf, true))
2704 bool GuiView::closeBuffer(Buffer & buf)
2706 // If we are in a close_event all children will be closed in some time,
2707 // so no need to do it here. This will ensure that the children end up
2708 // in the session file in the correct order. If we close the master
2709 // buffer, we can close or release the child buffers here too.
2710 bool success = true;
2712 ListOfBuffers clist = buf.getChildren();
2713 ListOfBuffers::const_iterator it = clist.begin();
2714 ListOfBuffers::const_iterator const bend = clist.end();
2715 for (; it != bend; ++it) {
2716 // If a child is dirty, do not close
2717 // without user intervention
2718 //FIXME: should we look in other tabworkareas?
2719 Buffer * child_buf = *it;
2720 GuiWorkArea * child_wa = workArea(*child_buf);
2722 if (!closeWorkArea(child_wa, true)) {
2727 theBufferList().releaseChild(&buf, child_buf);
2731 // goto bookmark to update bookmark pit.
2732 //FIXME: we should update only the bookmarks related to this buffer!
2733 LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
2734 for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
2735 guiApp->gotoBookmark(i+1, false, false);
2737 if (saveBufferIfNeeded(buf, false)) {
2738 buf.removeAutosaveFile();
2739 theBufferList().release(&buf);
2743 // open all children again to avoid a crash because of dangling
2744 // pointers (bug 6603)
2750 bool GuiView::closeTabWorkArea(TabWorkArea * twa)
2752 while (twa == d.currentTabWorkArea()) {
2753 twa->setCurrentIndex(twa->count()-1);
2755 GuiWorkArea * wa = twa->currentWorkArea();
2756 Buffer & b = wa->bufferView().buffer();
2758 // We only want to close the buffer if the same buffer is not visible
2759 // in another view, and if this is not a child and if we are closing
2760 // a view (not a tabgroup).
2761 bool const close_buffer =
2762 !inOtherView(b) && !b.parent() && closing_;
2764 if (!closeWorkArea(wa, close_buffer))
2771 bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
2773 if (buf.isClean() || buf.paragraphs().empty())
2776 // Switch to this Buffer.
2781 if (buf.isUnnamed())
2782 file = from_utf8(buf.fileName().onlyFileName());
2784 file = buf.fileName().displayName(30);
2786 // Bring this window to top before asking questions.
2791 if (hiding && buf.isUnnamed()) {
2792 docstring const text = bformat(_("The document %1$s has not been "
2793 "saved yet.\n\nDo you want to save "
2794 "the document?"), file);
2795 ret = Alert::prompt(_("Save new document?"),
2796 text, 0, 1, _("&Save"), _("&Cancel"));
2800 docstring const text = bformat(_("The document %1$s has unsaved changes."
2801 "\n\nDo you want to save the document or discard the changes?"), file);
2802 ret = Alert::prompt(_("Save changed document?"),
2803 text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
2808 if (!saveBuffer(buf))
2812 // If we crash after this we could have no autosave file
2813 // but I guess this is really improbable (Jug).
2814 // Sometimes improbable things happen:
2815 // - see bug http://www.lyx.org/trac/ticket/6587 (ps)
2816 // buf.removeAutosaveFile();
2818 // revert all changes
2829 bool GuiView::inMultiTabs(GuiWorkArea * wa)
2831 Buffer & buf = wa->bufferView().buffer();
2833 for (int i = 0; i != d.splitter_->count(); ++i) {
2834 GuiWorkArea * wa_ = d.tabWorkArea(i)->workArea(buf);
2835 if (wa_ && wa_ != wa)
2838 return inOtherView(buf);
2842 bool GuiView::inOtherView(Buffer & buf)
2844 QList<int> const ids = guiApp->viewIds();
2846 for (int i = 0; i != ids.size(); ++i) {
2850 if (guiApp->view(ids[i]).workArea(buf))
2857 void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
2859 if (!documentBufferView())
2862 if (TabWorkArea * twa = d.currentTabWorkArea()) {
2863 Buffer * const curbuf = &documentBufferView()->buffer();
2864 int nwa = twa->count();
2865 for (int i = 0; i < nwa; ++i) {
2866 if (&workArea(i)->bufferView().buffer() == curbuf) {
2868 if (np == NEXTBUFFER)
2869 next_index = (i == nwa - 1 ? 0 : i + 1);
2871 next_index = (i == 0 ? nwa - 1 : i - 1);
2872 setBuffer(&workArea(next_index)->bufferView().buffer());
2880 /// make sure the document is saved
2881 static bool ensureBufferClean(Buffer * buffer)
2883 LASSERT(buffer, return false);
2884 if (buffer->isClean() && !buffer->isUnnamed())
2887 docstring const file = buffer->fileName().displayName(30);
2890 if (!buffer->isUnnamed()) {
2891 text = bformat(_("The document %1$s has unsaved "
2892 "changes.\n\nDo you want to save "
2893 "the document?"), file);
2894 title = _("Save changed document?");
2897 text = bformat(_("The document %1$s has not been "
2898 "saved yet.\n\nDo you want to save "
2899 "the document?"), file);
2900 title = _("Save new document?");
2902 int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
2905 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
2907 return buffer->isClean() && !buffer->isUnnamed();
2911 bool GuiView::reloadBuffer(Buffer & buf)
2913 Buffer::ReadStatus status = buf.reload();
2914 return status == Buffer::ReadSuccess;
2918 void GuiView::checkExternallyModifiedBuffers()
2920 BufferList::iterator bit = theBufferList().begin();
2921 BufferList::iterator const bend = theBufferList().end();
2922 for (; bit != bend; ++bit) {
2923 Buffer * buf = *bit;
2924 if (buf->fileName().exists()
2925 && buf->isExternallyModified(Buffer::checksum_method)) {
2926 docstring text = bformat(_("Document \n%1$s\n has been externally modified."
2927 " Reload now? Any local changes will be lost."),
2928 from_utf8(buf->absFileName()));
2929 int const ret = Alert::prompt(_("Reload externally changed document?"),
2930 text, 0, 1, _("&Reload"), _("&Cancel"));
2938 void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
2940 Buffer * buffer = documentBufferView()
2941 ? &(documentBufferView()->buffer()) : 0;
2943 switch (cmd.action()) {
2944 case LFUN_VC_REGISTER:
2945 if (!buffer || !ensureBufferClean(buffer))
2947 if (!buffer->lyxvc().inUse()) {
2948 if (buffer->lyxvc().registrer()) {
2949 reloadBuffer(*buffer);
2950 dr.clearMessageUpdate();
2955 case LFUN_VC_RENAME:
2956 case LFUN_VC_COPY: {
2957 if (!buffer || !ensureBufferClean(buffer))
2959 if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
2960 if (buffer->lyxvc().isCheckInWithConfirmation()) {
2961 // Some changes are not yet committed.
2962 // We test here and not in getStatus(), since
2963 // this test is expensive.
2965 LyXVC::CommandResult ret =
2966 buffer->lyxvc().checkIn(log);
2968 if (ret == LyXVC::ErrorCommand ||
2969 ret == LyXVC::VCSuccess)
2970 reloadBuffer(*buffer);
2971 if (buffer->lyxvc().isCheckInWithConfirmation()) {
2972 frontend::Alert::error(
2973 _("Revision control error."),
2974 _("Document could not be checked in."));
2978 RenameKind const kind = (cmd.action() == LFUN_VC_RENAME) ?
2979 LV_VC_RENAME : LV_VC_COPY;
2980 renameBuffer(*buffer, cmd.argument(), kind);
2985 case LFUN_VC_CHECK_IN:
2986 if (!buffer || !ensureBufferClean(buffer))
2988 if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
2990 LyXVC::CommandResult ret = buffer->lyxvc().checkIn(log);
2992 // Only skip reloading if the checkin was cancelled or
2993 // an error occurred before the real checkin VCS command
2994 // was executed, since the VCS might have changed the
2995 // file even if it could not checkin successfully.
2996 if (ret == LyXVC::ErrorCommand || ret == LyXVC::VCSuccess)
2997 reloadBuffer(*buffer);
3001 case LFUN_VC_CHECK_OUT:
3002 if (!buffer || !ensureBufferClean(buffer))
3004 if (buffer->lyxvc().inUse()) {
3005 dr.setMessage(buffer->lyxvc().checkOut());
3006 reloadBuffer(*buffer);
3010 case LFUN_VC_LOCKING_TOGGLE:
3011 LASSERT(buffer, return);
3012 if (!ensureBufferClean(buffer) || buffer->isReadonly())
3014 if (buffer->lyxvc().inUse()) {
3015 string res = buffer->lyxvc().lockingToggle();
3017 frontend::Alert::error(_("Revision control error."),
3018 _("Error when setting the locking property."));
3021 reloadBuffer(*buffer);
3026 case LFUN_VC_REVERT:
3027 LASSERT(buffer, return);
3028 if (buffer->lyxvc().revert()) {
3029 reloadBuffer(*buffer);
3030 dr.clearMessageUpdate();
3034 case LFUN_VC_UNDO_LAST:
3035 LASSERT(buffer, return);
3036 buffer->lyxvc().undoLast();
3037 reloadBuffer(*buffer);
3038 dr.clearMessageUpdate();
3041 case LFUN_VC_REPO_UPDATE:
3042 LASSERT(buffer, return);
3043 if (ensureBufferClean(buffer)) {
3044 dr.setMessage(buffer->lyxvc().repoUpdate());
3045 checkExternallyModifiedBuffers();
3049 case LFUN_VC_COMMAND: {
3050 string flag = cmd.getArg(0);
3051 if (buffer && contains(flag, 'R') && !ensureBufferClean(buffer))
3054 if (contains(flag, 'M')) {
3055 if (!Alert::askForText(message, _("LyX VC: Log Message")))
3058 string path = cmd.getArg(1);
3059 if (contains(path, "$$p") && buffer)
3060 path = subst(path, "$$p", buffer->filePath());
3061 LYXERR(Debug::LYXVC, "Directory: " << path);
3063 if (!pp.isReadableDirectory()) {
3064 lyxerr << _("Directory is not accessible.") << endl;
3067 support::PathChanger p(pp);
3069 string command = cmd.getArg(2);
3070 if (command.empty())
3073 command = subst(command, "$$i", buffer->absFileName());
3074 command = subst(command, "$$p", buffer->filePath());
3076 command = subst(command, "$$m", to_utf8(message));
3077 LYXERR(Debug::LYXVC, "Command: " << command);
3079 one.startscript(Systemcall::Wait, command);
3083 if (contains(flag, 'I'))
3084 buffer->markDirty();
3085 if (contains(flag, 'R'))
3086 reloadBuffer(*buffer);
3091 case LFUN_VC_COMPARE: {
3093 if (cmd.argument().empty()) {
3094 lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "comparehistory"));
3098 string rev1 = cmd.getArg(0);
3102 if (!buffer->lyxvc().prepareFileRevision(rev1, f1))
3105 if (isStrInt(rev1) && convert<int>(rev1) <= 0) {
3106 f2 = buffer->absFileName();
3108 string rev2 = cmd.getArg(1);
3112 if (!buffer->lyxvc().prepareFileRevision(rev2, f2))
3116 LYXERR(Debug::LYXVC, "Launching comparison for fetched revisions:\n" <<
3117 f1 << "\n" << f2 << "\n" );
3118 string par = "compare run " + quoteName(f1) + " " + quoteName(f2);
3119 lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, par));
3129 void GuiView::openChildDocument(string const & fname)
3131 LASSERT(documentBufferView(), return);
3132 Buffer & buffer = documentBufferView()->buffer();
3133 FileName const filename = support::makeAbsPath(fname, buffer.filePath());
3134 documentBufferView()->saveBookmark(false);
3136 if (theBufferList().exists(filename)) {
3137 child = theBufferList().getBuffer(filename);
3140 message(bformat(_("Opening child document %1$s..."),
3141 makeDisplayPath(filename.absFileName())));
3142 child = loadDocument(filename, false);
3144 // Set the parent name of the child document.
3145 // This makes insertion of citations and references in the child work,
3146 // when the target is in the parent or another child document.
3148 child->setParent(&buffer);
3152 bool GuiView::goToFileRow(string const & argument)
3156 size_t i = argument.find_last_of(' ');
3157 if (i != string::npos) {
3158 file_name = os::internal_path(trim(argument.substr(0, i)));
3159 istringstream is(argument.substr(i + 1));
3164 if (i == string::npos) {
3165 LYXERR0("Wrong argument: " << argument);
3169 string const abstmp = package().temp_dir().absFileName();
3170 string const realtmp = package().temp_dir().realPath();
3171 // We have to use os::path_prefix_is() here, instead of
3172 // simply prefixIs(), because the file name comes from
3173 // an external application and may need case adjustment.
3174 if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
3175 || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
3176 // Needed by inverse dvi search. If it is a file
3177 // in tmpdir, call the apropriated function.
3178 // If tmpdir is a symlink, we may have the real
3179 // path passed back, so we correct for that.
3180 if (!prefixIs(file_name, abstmp))
3181 file_name = subst(file_name, realtmp, abstmp);
3182 buf = theBufferList().getBufferFromTmp(file_name);
3184 // Must replace extension of the file to be .lyx
3185 // and get full path
3186 FileName const s = fileSearch(string(),
3187 support::changeExtension(file_name, ".lyx"), "lyx");
3188 // Either change buffer or load the file
3189 if (theBufferList().exists(s))
3190 buf = theBufferList().getBuffer(s);
3191 else if (s.exists()) {
3192 buf = loadDocument(s);
3197 _("File does not exist: %1$s"),
3198 makeDisplayPath(file_name)));
3204 _("No buffer for file: %1$s."),
3205 makeDisplayPath(file_name))
3210 documentBufferView()->setCursorFromRow(row);
3216 Buffer::ExportStatus GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffer const * orig, Buffer * clone, string const & format)
3218 Buffer::ExportStatus const status = func(format);
3220 // the cloning operation will have produced a clone of the entire set of
3221 // documents, starting from the master. so we must delete those.
3222 Buffer * mbuf = const_cast<Buffer *>(clone->masterBuffer());
3224 busyBuffers.remove(orig);
3229 Buffer::ExportStatus GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
3231 Buffer::ExportStatus (Buffer::* mem_func)(std::string const &, bool) const = &Buffer::doExport;
3232 return runAndDestroy(lyx::bind(mem_func, clone, _1, true), orig, clone, format);
3236 Buffer::ExportStatus GuiView::GuiViewPrivate::exportAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
3238 Buffer::ExportStatus (Buffer::* mem_func)(std::string const &, bool) const = &Buffer::doExport;
3239 return runAndDestroy(lyx::bind(mem_func, clone, _1, false), orig, clone, format);
3243 Buffer::ExportStatus GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer * clone, string const & format)
3245 Buffer::ExportStatus (Buffer::* mem_func)(std::string const &) const = &Buffer::preview;
3246 return runAndDestroy(lyx::bind(mem_func, clone, _1), orig, clone, format);
3250 bool GuiView::GuiViewPrivate::asyncBufferProcessing(
3251 string const & argument,
3252 Buffer const * used_buffer,
3253 docstring const & msg,
3254 Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
3255 Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
3256 Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const)
3261 string format = argument;
3263 format = used_buffer->params().getDefaultOutputFormat();
3264 processing_format = format;
3266 progress_->clearMessages();
3269 #if EXPORT_in_THREAD
3270 GuiViewPrivate::busyBuffers.insert(used_buffer);
3271 Buffer * cloned_buffer = used_buffer->cloneFromMaster();
3272 if (!cloned_buffer) {
3273 Alert::error(_("Export Error"),
3274 _("Error cloning the Buffer."));
3277 QFuture<Buffer::ExportStatus> f = QtConcurrent::run(
3282 setPreviewFuture(f);
3283 last_export_format = used_buffer->params().bufferFormat();
3286 // We are asynchronous, so we don't know here anything about the success
3289 Buffer::ExportStatus status;
3291 // TODO check here if it breaks exporting with Qt < 4.4
3292 status = (used_buffer->*syncFunc)(format, true);
3293 } else if (previewFunc) {
3294 status = (used_buffer->*previewFunc)(format);
3297 handleExportStatus(gv_, status, format);
3299 return (status == Buffer::ExportSuccess
3300 || status == Buffer::PreviewSuccess);
3304 void GuiView::dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr)
3306 BufferView * bv = currentBufferView();
3307 LASSERT(bv, return);
3309 // Let the current BufferView dispatch its own actions.
3310 bv->dispatch(cmd, dr);
3311 if (dr.dispatched())
3314 // Try with the document BufferView dispatch if any.
3315 BufferView * doc_bv = documentBufferView();
3316 if (doc_bv && doc_bv != bv) {
3317 doc_bv->dispatch(cmd, dr);
3318 if (dr.dispatched())
3322 // Then let the current Cursor dispatch its own actions.
3323 bv->cursor().dispatch(cmd);
3325 // update completion. We do it here and not in
3326 // processKeySym to avoid another redraw just for a
3327 // changed inline completion
3328 if (cmd.origin() == FuncRequest::KEYBOARD) {
3329 if (cmd.action() == LFUN_SELF_INSERT
3330 || (cmd.action() == LFUN_ERT_INSERT && bv->cursor().inMathed()))
3331 updateCompletion(bv->cursor(), true, true);
3332 else if (cmd.action() == LFUN_CHAR_DELETE_BACKWARD)
3333 updateCompletion(bv->cursor(), false, true);
3335 updateCompletion(bv->cursor(), false, false);
3338 dr = bv->cursor().result();
3342 void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
3344 BufferView * bv = currentBufferView();
3345 // By default we won't need any update.
3346 dr.screenUpdate(Update::None);
3347 // assume cmd will be dispatched
3348 dr.dispatched(true);
3350 Buffer * doc_buffer = documentBufferView()
3351 ? &(documentBufferView()->buffer()) : 0;
3353 if (cmd.origin() == FuncRequest::TOC) {
3354 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
3355 // FIXME: do we need to pass a DispatchResult object here?
3356 toc->doDispatch(bv->cursor(), cmd);
3360 string const argument = to_utf8(cmd.argument());
3362 switch(cmd.action()) {
3363 case LFUN_BUFFER_CHILD_OPEN:
3364 openChildDocument(to_utf8(cmd.argument()));
3367 case LFUN_BUFFER_IMPORT:
3368 importDocument(to_utf8(cmd.argument()));
3371 case LFUN_BUFFER_EXPORT: {
3374 FileName target_dir = doc_buffer->fileName().onlyPath();
3375 string const dest = cmd.getArg(1);
3376 if (!dest.empty() && FileName::isAbsolute(dest))
3377 target_dir = FileName(support::onlyPath(dest));
3378 // GCC only sees strfwd.h when building merged
3379 if (::lyx::operator==(cmd.argument(), "custom")) {
3380 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"), dr);
3383 if (!target_dir.isDirWritable()) {
3384 exportBufferAs(*doc_buffer, cmd.argument());
3387 /* TODO/Review: Is it a problem to also export the children?
3388 See the update_unincluded flag */
3389 d.asyncBufferProcessing(argument,
3392 &GuiViewPrivate::exportAndDestroy,
3395 // TODO Inform user about success
3399 case LFUN_BUFFER_EXPORT_AS: {
3400 LASSERT(doc_buffer, break);
3401 docstring f = cmd.argument();
3403 f = from_ascii(doc_buffer->params().getDefaultOutputFormat());
3404 exportBufferAs(*doc_buffer, f);
3408 case LFUN_BUFFER_UPDATE: {
3409 d.asyncBufferProcessing(argument,
3412 &GuiViewPrivate::compileAndDestroy,
3417 case LFUN_BUFFER_VIEW: {
3418 d.asyncBufferProcessing(argument,
3420 _("Previewing ..."),
3421 &GuiViewPrivate::previewAndDestroy,
3426 case LFUN_MASTER_BUFFER_UPDATE: {
3427 d.asyncBufferProcessing(argument,
3428 (doc_buffer ? doc_buffer->masterBuffer() : 0),
3430 &GuiViewPrivate::compileAndDestroy,
3435 case LFUN_MASTER_BUFFER_VIEW: {
3436 d.asyncBufferProcessing(argument,
3437 (doc_buffer ? doc_buffer->masterBuffer() : 0),
3439 &GuiViewPrivate::previewAndDestroy,
3440 0, &Buffer::preview);
3443 case LFUN_BUFFER_SWITCH: {
3444 string const file_name = to_utf8(cmd.argument());
3445 if (!FileName::isAbsolute(file_name)) {
3447 dr.setMessage(_("Absolute filename expected."));
3451 Buffer * buffer = theBufferList().getBuffer(FileName(file_name));
3454 dr.setMessage(_("Document not loaded"));
3458 // Do we open or switch to the buffer in this view ?
3459 if (workArea(*buffer)
3460 || lyxrc.open_buffers_in_tabs || !documentBufferView()) {
3465 // Look for the buffer in other views
3466 QList<int> const ids = guiApp->viewIds();
3468 for (; i != ids.size(); ++i) {
3469 GuiView & gv = guiApp->view(ids[i]);
3470 if (gv.workArea(*buffer)) {
3471 gv.activateWindow();
3472 gv.setBuffer(buffer);
3477 // If necessary, open a new window as a last resort
3478 if (i == ids.size()) {
3479 lyx::dispatch(FuncRequest(LFUN_WINDOW_NEW));
3485 case LFUN_BUFFER_NEXT:
3486 gotoNextOrPreviousBuffer(NEXTBUFFER);
3489 case LFUN_BUFFER_PREVIOUS:
3490 gotoNextOrPreviousBuffer(PREVBUFFER);
3493 case LFUN_COMMAND_EXECUTE: {
3494 bool const show_it = cmd.argument() != "off";
3495 // FIXME: this is a hack, "minibuffer" should not be
3497 if (GuiToolbar * t = toolbar("minibuffer")) {
3498 t->setVisible(show_it);
3499 if (show_it && t->commandBuffer())
3500 t->commandBuffer()->setFocus();
3504 case LFUN_DROP_LAYOUTS_CHOICE:
3505 d.layout_->showPopup();
3508 case LFUN_MENU_OPEN:
3509 if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument()), *this))
3510 menu->exec(QCursor::pos());
3513 case LFUN_FILE_INSERT:
3514 insertLyXFile(cmd.argument());
3517 case LFUN_FILE_INSERT_PLAINTEXT:
3518 case LFUN_FILE_INSERT_PLAINTEXT_PARA: {
3519 string const fname = to_utf8(cmd.argument());
3520 if (!fname.empty() && !FileName::isAbsolute(fname)) {
3521 dr.setMessage(_("Absolute filename expected."));
3525 FileName filename(fname);
3526 if (fname.empty()) {
3527 FileDialog dlg(qt_("Select file to insert"));
3529 FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
3530 QStringList(qt_("All Files (*)")));
3532 if (result.first == FileDialog::Later || result.second.isEmpty()) {
3533 dr.setMessage(_("Canceled."));
3537 filename.set(fromqstr(result.second));
3541 FuncRequest const new_cmd(cmd, filename.absoluteFilePath());
3542 bv->dispatch(new_cmd, dr);
3547 case LFUN_BUFFER_RELOAD: {
3548 LASSERT(doc_buffer, break);
3551 if (!doc_buffer->isClean()) {
3552 docstring const file =
3553 makeDisplayPath(doc_buffer->absFileName(), 20);
3554 docstring text = bformat(_("Any changes will be lost. "
3555 "Are you sure you want to revert to the saved version "
3556 "of the document %1$s?"), file);
3557 ret = Alert::prompt(_("Revert to saved document?"),
3558 text, 1, 1, _("&Revert"), _("&Cancel"));
3562 doc_buffer->markClean();
3563 reloadBuffer(*doc_buffer);
3564 dr.forceBufferUpdate();
3569 case LFUN_BUFFER_WRITE:
3570 LASSERT(doc_buffer, break);
3571 saveBuffer(*doc_buffer);
3574 case LFUN_BUFFER_WRITE_AS:
3575 LASSERT(doc_buffer, break);
3576 renameBuffer(*doc_buffer, cmd.argument());
3579 case LFUN_BUFFER_WRITE_ALL: {
3580 Buffer * first = theBufferList().first();
3583 message(_("Saving all documents..."));
3584 // We cannot use a for loop as the buffer list cycles.
3587 if (!b->isClean()) {
3589 LYXERR(Debug::ACTION, "Saved " << b->absFileName());
3591 b = theBufferList().next(b);
3592 } while (b != first);
3593 dr.setMessage(_("All documents saved."));
3597 case LFUN_BUFFER_CLOSE:
3601 case LFUN_BUFFER_CLOSE_ALL:
3605 case LFUN_TOOLBAR_TOGGLE: {
3606 string const name = cmd.getArg(0);
3607 if (GuiToolbar * t = toolbar(name))
3612 case LFUN_DIALOG_UPDATE: {
3613 string const name = to_utf8(cmd.argument());
3614 if (name == "prefs" || name == "document")
3615 updateDialog(name, string());
3616 else if (name == "paragraph")
3617 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
3618 else if (currentBufferView()) {
3619 Inset * inset = currentBufferView()->editedInset(name);
3620 // Can only update a dialog connected to an existing inset
3622 // FIXME: get rid of this indirection; GuiView ask the inset
3623 // if he is kind enough to update itself...
3624 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
3625 //FIXME: pass DispatchResult here?
3626 inset->dispatch(currentBufferView()->cursor(), fr);
3632 case LFUN_DIALOG_TOGGLE: {
3633 FuncCode const func_code = isDialogVisible(cmd.getArg(0))
3634 ? LFUN_DIALOG_HIDE : LFUN_DIALOG_SHOW;
3635 dispatch(FuncRequest(func_code, cmd.argument()), dr);
3639 case LFUN_DIALOG_DISCONNECT_INSET:
3640 disconnectDialog(to_utf8(cmd.argument()));
3643 case LFUN_DIALOG_HIDE: {
3644 guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
3648 case LFUN_DIALOG_SHOW: {
3649 string const name = cmd.getArg(0);
3650 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
3652 if (name == "character") {
3653 data = freefont2string();
3655 showDialog("character", data);
3656 } else if (name == "latexlog") {
3657 Buffer::LogType type;
3658 string const logfile = doc_buffer->logName(&type);
3660 case Buffer::latexlog:
3663 case Buffer::buildlog:
3667 data += Lexer::quoteString(logfile);
3668 showDialog("log", data);
3669 } else if (name == "vclog") {
3670 string const data = "vc " +
3671 Lexer::quoteString(doc_buffer->lyxvc().getLogFile());
3672 showDialog("log", data);
3673 } else if (name == "symbols") {
3674 data = bv->cursor().getEncoding()->name();
3676 showDialog("symbols", data);
3678 } else if (name == "prefs" && isFullScreen()) {
3679 lfunUiToggle("fullscreen");
3680 showDialog("prefs", data);
3682 showDialog(name, data);
3687 dr.setMessage(cmd.argument());
3690 case LFUN_UI_TOGGLE: {
3691 string arg = cmd.getArg(0);
3692 if (!lfunUiToggle(arg)) {
3693 docstring const msg = "ui-toggle " + _("%1$s unknown command!");
3694 dr.setMessage(bformat(msg, from_utf8(arg)));
3696 // Make sure the keyboard focus stays in the work area.
3701 case LFUN_VIEW_SPLIT: {
3702 LASSERT(doc_buffer, break);
3703 string const orientation = cmd.getArg(0);
3704 d.splitter_->setOrientation(orientation == "vertical"
3705 ? Qt::Vertical : Qt::Horizontal);
3706 TabWorkArea * twa = addTabWorkArea();
3707 GuiWorkArea * wa = twa->addWorkArea(*doc_buffer, *this);
3708 setCurrentWorkArea(wa);
3711 case LFUN_TAB_GROUP_CLOSE:
3712 if (TabWorkArea * twa = d.currentTabWorkArea()) {
3713 closeTabWorkArea(twa);
3714 d.current_work_area_ = 0;
3715 twa = d.currentTabWorkArea();
3716 // Switch to the next GuiWorkArea in the found TabWorkArea.
3718 // Make sure the work area is up to date.
3719 setCurrentWorkArea(twa->currentWorkArea());
3721 setCurrentWorkArea(0);
3726 case LFUN_VIEW_CLOSE:
3727 if (TabWorkArea * twa = d.currentTabWorkArea()) {
3728 closeWorkArea(twa->currentWorkArea());
3729 d.current_work_area_ = 0;
3730 twa = d.currentTabWorkArea();
3731 // Switch to the next GuiWorkArea in the found TabWorkArea.
3733 // Make sure the work area is up to date.
3734 setCurrentWorkArea(twa->currentWorkArea());
3736 setCurrentWorkArea(0);
3741 case LFUN_COMPLETION_INLINE:
3742 if (d.current_work_area_)
3743 d.current_work_area_->completer().showInline();
3746 case LFUN_COMPLETION_POPUP:
3747 if (d.current_work_area_)
3748 d.current_work_area_->completer().showPopup();
3753 if (d.current_work_area_)
3754 d.current_work_area_->completer().tab();
3757 case LFUN_COMPLETION_CANCEL:
3758 if (d.current_work_area_) {
3759 if (d.current_work_area_->completer().popupVisible())
3760 d.current_work_area_->completer().hidePopup();
3762 d.current_work_area_->completer().hideInline();
3766 case LFUN_COMPLETION_ACCEPT:
3767 if (d.current_work_area_)
3768 d.current_work_area_->completer().activate();
3771 case LFUN_BUFFER_ZOOM_IN:
3772 case LFUN_BUFFER_ZOOM_OUT:
3773 if (cmd.argument().empty()) {
3774 if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
3779 lyxrc.zoom += convert<int>(cmd.argument());
3781 if (lyxrc.zoom < 10)
3784 // The global QPixmapCache is used in GuiPainter to cache text
3785 // painting so we must reset it.
3786 QPixmapCache::clear();
3787 guiApp->fontLoader().update();
3788 lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3791 case LFUN_VC_REGISTER:
3792 case LFUN_VC_RENAME:
3794 case LFUN_VC_CHECK_IN:
3795 case LFUN_VC_CHECK_OUT:
3796 case LFUN_VC_REPO_UPDATE:
3797 case LFUN_VC_LOCKING_TOGGLE:
3798 case LFUN_VC_REVERT:
3799 case LFUN_VC_UNDO_LAST:
3800 case LFUN_VC_COMMAND:
3801 case LFUN_VC_COMPARE:
3802 dispatchVC(cmd, dr);
3805 case LFUN_SERVER_GOTO_FILE_ROW:
3806 goToFileRow(to_utf8(cmd.argument()));
3809 case LFUN_FORWARD_SEARCH: {
3810 Buffer const * doc_master = doc_buffer->masterBuffer();
3811 FileName const path(doc_master->temppath());
3812 string const texname = doc_master->isChild(doc_buffer)
3813 ? DocFileName(changeExtension(
3814 doc_buffer->absFileName(),
3815 "tex")).mangledFileName()
3816 : doc_buffer->latexName();
3817 string const fulltexname =
3818 support::makeAbsPath(texname, doc_master->temppath()).absFileName();
3819 string const mastername =
3820 removeExtension(doc_master->latexName());
3821 FileName const dviname(addName(path.absFileName(),
3822 addExtension(mastername, "dvi")));
3823 FileName const pdfname(addName(path.absFileName(),
3824 addExtension(mastername, "pdf")));
3825 bool const have_dvi = dviname.exists();
3826 bool const have_pdf = pdfname.exists();
3827 if (!have_dvi && !have_pdf) {
3828 dr.setMessage(_("Please, preview the document first."));
3831 string outname = dviname.onlyFileName();
3832 string command = lyxrc.forward_search_dvi;
3833 if (!have_dvi || (have_pdf &&
3834 pdfname.lastModified() > dviname.lastModified())) {
3835 outname = pdfname.onlyFileName();
3836 command = lyxrc.forward_search_pdf;
3839 DocIterator tmpcur = bv->cursor();
3841 while (tmpcur.inMathed())
3843 int row = tmpcur.inMathed() ? 0 : doc_buffer->texrow().getRowFromIdPos(
3844 tmpcur.paragraph().id(), tmpcur.pos());
3845 LYXERR(Debug::ACTION, "Forward search: row:" << row
3846 << " id:" << tmpcur.paragraph().id());
3847 if (!row || command.empty()) {
3848 dr.setMessage(_("Couldn't proceed."));
3851 string texrow = convert<string>(row);
3853 command = subst(command, "$$n", texrow);
3854 command = subst(command, "$$f", fulltexname);
3855 command = subst(command, "$$t", texname);
3856 command = subst(command, "$$o", outname);
3858 PathChanger p(path);
3860 one.startscript(Systemcall::DontWait, command);
3864 case LFUN_SPELLING_CONTINUOUSLY:
3865 lyxrc.spellcheck_continuously = !lyxrc.spellcheck_continuously;
3866 dr.screenUpdate(Update::Force | Update::FitCursor);
3870 // The LFUN must be for one of BufferView, Buffer or Cursor;
3872 dispatchToBufferView(cmd, dr);
3876 // Part of automatic menu appearance feature.
3877 if (isFullScreen()) {
3878 if (menuBar()->isVisible() && lyxrc.full_screen_menubar)
3882 // Need to update bv because many LFUNs here might have destroyed it
3883 bv = currentBufferView();
3885 // Clear non-empty selections
3886 // (e.g. from a "char-forward-select" followed by "char-backward-select")
3888 Cursor & cur = bv->cursor();
3889 if ((cur.selection() && cur.selBegin() == cur.selEnd())) {
3890 cur.clearSelection();
3896 bool GuiView::lfunUiToggle(string const & ui_component)
3898 if (ui_component == "scrollbar") {
3899 // hide() is of no help
3900 if (d.current_work_area_->verticalScrollBarPolicy() ==
3901 Qt::ScrollBarAlwaysOff)
3903 d.current_work_area_->setVerticalScrollBarPolicy(
3904 Qt::ScrollBarAsNeeded);
3906 d.current_work_area_->setVerticalScrollBarPolicy(
3907 Qt::ScrollBarAlwaysOff);
3908 } else if (ui_component == "statusbar") {
3909 statusBar()->setVisible(!statusBar()->isVisible());
3910 } else if (ui_component == "menubar") {
3911 menuBar()->setVisible(!menuBar()->isVisible());
3913 if (ui_component == "frame") {
3915 getContentsMargins(&l, &t, &r, &b);
3916 //are the frames in default state?
3917 d.current_work_area_->setFrameStyle(QFrame::NoFrame);
3919 setContentsMargins(-2, -2, -2, -2);
3921 setContentsMargins(0, 0, 0, 0);
3924 if (ui_component == "fullscreen") {
3932 void GuiView::toggleFullScreen()
3934 if (isFullScreen()) {
3935 for (int i = 0; i != d.splitter_->count(); ++i)
3936 d.tabWorkArea(i)->setFullScreen(false);
3937 setContentsMargins(0, 0, 0, 0);
3938 setWindowState(windowState() ^ Qt::WindowFullScreen);
3941 statusBar()->show();
3944 hideDialogs("prefs", 0);
3945 for (int i = 0; i != d.splitter_->count(); ++i)
3946 d.tabWorkArea(i)->setFullScreen(true);
3947 setContentsMargins(-2, -2, -2, -2);
3949 setWindowState(windowState() ^ Qt::WindowFullScreen);
3950 if (lyxrc.full_screen_statusbar)
3951 statusBar()->hide();
3952 if (lyxrc.full_screen_menubar)
3954 if (lyxrc.full_screen_toolbars) {
3955 ToolbarMap::iterator end = d.toolbars_.end();
3956 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
3961 // give dialogs like the TOC a chance to adapt
3966 Buffer const * GuiView::updateInset(Inset const * inset)
3971 Buffer const * inset_buffer = &(inset->buffer());
3973 for (int i = 0; i != d.splitter_->count(); ++i) {
3974 GuiWorkArea * wa = d.tabWorkArea(i)->currentWorkArea();
3977 Buffer const * buffer = &(wa->bufferView().buffer());
3978 if (inset_buffer == buffer)
3979 wa->scheduleRedraw();
3981 return inset_buffer;
3985 void GuiView::restartCursor()
3987 /* When we move around, or type, it's nice to be able to see
3988 * the cursor immediately after the keypress.
3990 if (d.current_work_area_)
3991 d.current_work_area_->startBlinkingCursor();
3993 // Take this occasion to update the other GUI elements.
3999 void GuiView::updateCompletion(Cursor & cur, bool start, bool keep)
4001 if (d.current_work_area_)
4002 d.current_work_area_->completer().updateVisibility(cur, start, keep);
4007 // This list should be kept in sync with the list of insets in
4008 // src/insets/Inset.cpp. I.e., if a dialog goes with an inset, the
4009 // dialog should have the same name as the inset.
4010 // Changes should be also recorded in LFUN_DIALOG_SHOW doxygen
4011 // docs in LyXAction.cpp.
4013 char const * const dialognames[] = {
4015 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
4016 "citation", "compare", "comparehistory", "document", "errorlist", "ert",
4017 "external", "file", "findreplace", "findreplaceadv", "float", "graphics",
4018 "href", "include", "index", "index_print", "info", "listings", "label", "line",
4019 "log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
4020 "nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref",
4021 "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate",
4022 "thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", "progress"};
4024 char const * const * const end_dialognames =
4025 dialognames + (sizeof(dialognames) / sizeof(char *));
4029 cmpCStr(char const * name) : name_(name) {}
4030 bool operator()(char const * other) {
4031 return strcmp(other, name_) == 0;
4038 bool isValidName(string const & name)
4040 return find_if(dialognames, end_dialognames,
4041 cmpCStr(name.c_str())) != end_dialognames;
4047 void GuiView::resetDialogs()
4049 // Make sure that no LFUN uses any GuiView.
4050 guiApp->setCurrentView(0);
4054 constructToolbars();
4055 guiApp->menus().fillMenuBar(menuBar(), this, false);
4056 d.layout_->updateContents(true);
4057 // Now update controls with current buffer.
4058 guiApp->setCurrentView(this);
4064 Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
4066 if (!isValidName(name))
4069 map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
4071 if (it != d.dialogs_.end()) {
4073 it->second->hideView();
4074 return it->second.get();
4077 Dialog * dialog = build(name);
4078 d.dialogs_[name].reset(dialog);
4079 if (lyxrc.allow_geometry_session)
4080 dialog->restoreSession();
4087 void GuiView::showDialog(string const & name, string const & data,
4090 triggerShowDialog(toqstr(name), toqstr(data), inset);
4094 void GuiView::doShowDialog(QString const & qname, QString const & qdata,
4100 const string name = fromqstr(qname);
4101 const string data = fromqstr(qdata);
4105 Dialog * dialog = findOrBuild(name, false);
4107 bool const visible = dialog->isVisibleView();
4108 dialog->showData(data);
4109 if (inset && currentBufferView())
4110 currentBufferView()->editInset(name, inset);
4111 // We only set the focus to the new dialog if it was not yet
4112 // visible in order not to change the existing previous behaviour
4114 // activateWindow is needed for floating dockviews
4115 dialog->asQWidget()->raise();
4116 dialog->asQWidget()->activateWindow();
4117 dialog->asQWidget()->setFocus();
4121 catch (ExceptionMessage const & ex) {
4129 bool GuiView::isDialogVisible(string const & name) const
4131 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
4132 if (it == d.dialogs_.end())
4134 return it->second.get()->isVisibleView() && !it->second.get()->isClosing();
4138 void GuiView::hideDialog(string const & name, Inset * inset)
4140 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
4141 if (it == d.dialogs_.end())
4145 if (!currentBufferView())
4147 if (inset != currentBufferView()->editedInset(name))
4151 Dialog * const dialog = it->second.get();
4152 if (dialog->isVisibleView())
4154 if (currentBufferView())
4155 currentBufferView()->editInset(name, 0);
4159 void GuiView::disconnectDialog(string const & name)
4161 if (!isValidName(name))
4163 if (currentBufferView())
4164 currentBufferView()->editInset(name, 0);
4168 void GuiView::hideAll() const
4170 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
4171 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
4173 for(; it != end; ++it)
4174 it->second->hideView();
4178 void GuiView::updateDialogs()
4180 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
4181 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
4183 for(; it != end; ++it) {
4184 Dialog * dialog = it->second.get();
4186 if (dialog->needBufferOpen() && !documentBufferView())
4187 hideDialog(fromqstr(dialog->name()), 0);
4188 else if (dialog->isVisibleView())
4189 dialog->checkStatus();
4196 Dialog * createDialog(GuiView & lv, string const & name);
4198 // will be replaced by a proper factory...
4199 Dialog * createGuiAbout(GuiView & lv);
4200 Dialog * createGuiBibtex(GuiView & lv);
4201 Dialog * createGuiChanges(GuiView & lv);
4202 Dialog * createGuiCharacter(GuiView & lv);
4203 Dialog * createGuiCitation(GuiView & lv);
4204 Dialog * createGuiCompare(GuiView & lv);
4205 Dialog * createGuiCompareHistory(GuiView & lv);
4206 Dialog * createGuiDelimiter(GuiView & lv);
4207 Dialog * createGuiDocument(GuiView & lv);
4208 Dialog * createGuiErrorList(GuiView & lv);
4209 Dialog * createGuiExternal(GuiView & lv);
4210 Dialog * createGuiGraphics(GuiView & lv);
4211 Dialog * createGuiInclude(GuiView & lv);
4212 Dialog * createGuiIndex(GuiView & lv);
4213 Dialog * createGuiListings(GuiView & lv);
4214 Dialog * createGuiLog(GuiView & lv);
4215 Dialog * createGuiMathMatrix(GuiView & lv);
4216 Dialog * createGuiNote(GuiView & lv);
4217 Dialog * createGuiParagraph(GuiView & lv);
4218 Dialog * createGuiPhantom(GuiView & lv);
4219 Dialog * createGuiPreferences(GuiView & lv);
4220 Dialog * createGuiPrint(GuiView & lv);
4221 Dialog * createGuiPrintindex(GuiView & lv);
4222 Dialog * createGuiRef(GuiView & lv);
4223 Dialog * createGuiSearch(GuiView & lv);
4224 Dialog * createGuiSearchAdv(GuiView & lv);
4225 Dialog * createGuiSendTo(GuiView & lv);
4226 Dialog * createGuiShowFile(GuiView & lv);
4227 Dialog * createGuiSpellchecker(GuiView & lv);
4228 Dialog * createGuiSymbols(GuiView & lv);
4229 Dialog * createGuiTabularCreate(GuiView & lv);
4230 Dialog * createGuiTexInfo(GuiView & lv);
4231 Dialog * createGuiToc(GuiView & lv);
4232 Dialog * createGuiThesaurus(GuiView & lv);
4233 Dialog * createGuiViewSource(GuiView & lv);
4234 Dialog * createGuiWrap(GuiView & lv);
4235 Dialog * createGuiProgressView(GuiView & lv);
4239 Dialog * GuiView::build(string const & name)
4241 LASSERT(isValidName(name), return 0);
4243 Dialog * dialog = createDialog(*this, name);
4247 if (name == "aboutlyx")
4248 return createGuiAbout(*this);
4249 if (name == "bibtex")
4250 return createGuiBibtex(*this);
4251 if (name == "changes")
4252 return createGuiChanges(*this);
4253 if (name == "character")
4254 return createGuiCharacter(*this);
4255 if (name == "citation")
4256 return createGuiCitation(*this);
4257 if (name == "compare")
4258 return createGuiCompare(*this);
4259 if (name == "comparehistory")
4260 return createGuiCompareHistory(*this);
4261 if (name == "document")
4262 return createGuiDocument(*this);
4263 if (name == "errorlist")
4264 return createGuiErrorList(*this);
4265 if (name == "external")
4266 return createGuiExternal(*this);
4268 return createGuiShowFile(*this);
4269 if (name == "findreplace")
4270 return createGuiSearch(*this);
4271 if (name == "findreplaceadv")
4272 return createGuiSearchAdv(*this);
4273 if (name == "graphics")
4274 return createGuiGraphics(*this);
4275 if (name == "include")
4276 return createGuiInclude(*this);
4277 if (name == "index")
4278 return createGuiIndex(*this);
4279 if (name == "index_print")
4280 return createGuiPrintindex(*this);
4281 if (name == "listings")
4282 return createGuiListings(*this);
4284 return createGuiLog(*this);
4285 if (name == "mathdelimiter")
4286 return createGuiDelimiter(*this);
4287 if (name == "mathmatrix")
4288 return createGuiMathMatrix(*this);
4290 return createGuiNote(*this);
4291 if (name == "paragraph")
4292 return createGuiParagraph(*this);
4293 if (name == "phantom")
4294 return createGuiPhantom(*this);
4295 if (name == "prefs")
4296 return createGuiPreferences(*this);
4297 if (name == "print")
4298 return createGuiPrint(*this);
4300 return createGuiRef(*this);
4301 if (name == "sendto")
4302 return createGuiSendTo(*this);
4303 if (name == "spellchecker")
4304 return createGuiSpellchecker(*this);
4305 if (name == "symbols")
4306 return createGuiSymbols(*this);
4307 if (name == "tabularcreate")
4308 return createGuiTabularCreate(*this);
4309 if (name == "texinfo")
4310 return createGuiTexInfo(*this);
4311 if (name == "thesaurus")
4312 return createGuiThesaurus(*this);
4314 return createGuiToc(*this);
4315 if (name == "view-source")
4316 return createGuiViewSource(*this);
4318 return createGuiWrap(*this);
4319 if (name == "progress")
4320 return createGuiProgressView(*this);
4326 } // namespace frontend
4329 #include "moc_GuiView.cpp"