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 "LayoutBox.h"
33 #include "qt_helpers.h"
35 #include "frontends/alert.h"
37 #include "buffer_funcs.h"
39 #include "BufferList.h"
40 #include "BufferParams.h"
41 #include "BufferView.h"
42 #include "Converter.h"
44 #include "CutAndPaste.h"
46 #include "ErrorList.h"
48 #include "FuncStatus.h"
49 #include "FuncRequest.h"
53 #include "LyXAction.h"
57 #include "Paragraph.h"
58 #include "SpellChecker.h"
59 #include "TextClass.h"
64 #include "support/convert.h"
65 #include "support/debug.h"
66 #include "support/ExceptionMessage.h"
67 #include "support/FileName.h"
68 #include "support/filetools.h"
69 #include "support/gettext.h"
70 #include "support/filetools.h"
71 #include "support/ForkedCalls.h"
72 #include "support/lassert.h"
73 #include "support/lstrings.h"
74 #include "support/os.h"
75 #include "support/Package.h"
76 #include "support/Path.h"
77 #include "support/Systemcall.h"
78 #include "support/Timeout.h"
79 #include "support/ProgressInterface.h"
80 #include "GuiProgress.h"
83 #include <QApplication>
84 #include <QCloseEvent>
86 #include <QDesktopWidget>
87 #include <QDragEnterEvent>
94 #include <QPixmapCache>
96 #include <QPushButton>
100 #include <QStackedWidget>
101 #include <QStatusBar>
106 #include <QScrollBar>
108 #define EXPORT_in_THREAD 1
111 // QtConcurrent was introduced in Qt 4.4
112 #if (QT_VERSION >= 0x040400)
114 #include <QFutureWatcher>
115 #include <QtConcurrentRun>
118 #include <boost/bind.hpp>
122 #ifdef HAVE_SYS_TIME_H
123 # include <sys/time.h>
130 using namespace lyx::support;
137 class BackgroundWidget : public QWidget
142 LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
143 /// The text to be written on top of the pixmap
144 QString const text = lyx_version ?
145 qt_("version ") + lyx_version : qt_("unknown version");
146 splash_ = getPixmap("images/", "banner", "png");
148 QPainter pain(&splash_);
149 pain.setPen(QColor(0, 0, 0));
151 // The font used to display the version info
152 font.setStyleHint(QFont::SansSerif);
153 font.setWeight(QFont::Bold);
154 font.setPointSize(int(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble()));
156 pain.drawText(260, 15, text);
157 setFocusPolicy(Qt::StrongFocus);
160 void paintEvent(QPaintEvent *)
162 int x = (width() - splash_.width()) / 2;
163 int y = (height() - splash_.height()) / 2;
165 pain.drawPixmap(x, y, splash_);
168 void keyPressEvent(QKeyEvent * ev)
171 setKeySymbol(&sym, ev);
173 guiApp->processKeySym(sym, q_key_state(ev->modifiers()));
185 /// Toolbar store providing access to individual toolbars by name.
186 typedef map<string, GuiToolbar *> ToolbarMap;
188 typedef boost::shared_ptr<Dialog> DialogPtr;
193 struct GuiView::GuiViewPrivate
195 GuiViewPrivate(GuiView * gv)
196 : gv_(gv), current_work_area_(0), current_main_work_area_(0),
197 layout_(0), autosave_timeout_(5000),
200 // hardcode here the platform specific icon size
201 smallIconSize = 14; // scaling problems
202 normalIconSize = 20; // ok, default
203 bigIconSize = 26; // better for some math icons
205 splitter_ = new QSplitter;
206 bg_widget_ = new BackgroundWidget;
207 stack_widget_ = new QStackedWidget;
208 stack_widget_->addWidget(bg_widget_);
209 stack_widget_->addWidget(splitter_);
211 progress_ = new GuiProgress(gv);
218 delete stack_widget_;
222 QMenu * toolBarPopup(GuiView * parent)
224 // FIXME: translation
225 QMenu * menu = new QMenu(parent);
226 QActionGroup * iconSizeGroup = new QActionGroup(parent);
228 QAction * smallIcons = new QAction(iconSizeGroup);
229 smallIcons->setText(qt_("Small-sized icons"));
230 smallIcons->setCheckable(true);
231 QObject::connect(smallIcons, SIGNAL(triggered()),
232 parent, SLOT(smallSizedIcons()));
233 menu->addAction(smallIcons);
235 QAction * normalIcons = new QAction(iconSizeGroup);
236 normalIcons->setText(qt_("Normal-sized icons"));
237 normalIcons->setCheckable(true);
238 QObject::connect(normalIcons, SIGNAL(triggered()),
239 parent, SLOT(normalSizedIcons()));
240 menu->addAction(normalIcons);
242 QAction * bigIcons = new QAction(iconSizeGroup);
243 bigIcons->setText(qt_("Big-sized icons"));
244 bigIcons->setCheckable(true);
245 QObject::connect(bigIcons, SIGNAL(triggered()),
246 parent, SLOT(bigSizedIcons()));
247 menu->addAction(bigIcons);
249 unsigned int cur = parent->iconSize().width();
250 if ( cur == parent->d.smallIconSize)
251 smallIcons->setChecked(true);
252 else if (cur == parent->d.normalIconSize)
253 normalIcons->setChecked(true);
254 else if (cur == parent->d.bigIconSize)
255 bigIcons->setChecked(true);
262 stack_widget_->setCurrentWidget(bg_widget_);
263 bg_widget_->setUpdatesEnabled(true);
264 bg_widget_->setFocus();
267 TabWorkArea * tabWorkArea(int i)
269 return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
272 TabWorkArea * currentTabWorkArea()
274 if (splitter_->count() == 1)
275 // The first TabWorkArea is always the first one, if any.
276 return tabWorkArea(0);
278 for (int i = 0; i != splitter_->count(); ++i) {
279 TabWorkArea * twa = tabWorkArea(i);
280 if (current_main_work_area_ == twa->currentWorkArea())
284 // None has the focus so we just take the first one.
285 return tabWorkArea(0);
288 #if (QT_VERSION >= 0x040400)
289 void setPreviewFuture(QFuture<docstring> const & f)
291 if (preview_watcher_.isRunning()) {
292 // we prefer to cancel this preview in order to keep a snappy
296 preview_watcher_.setFuture(f);
302 GuiWorkArea * current_work_area_;
303 GuiWorkArea * current_main_work_area_;
304 QSplitter * splitter_;
305 QStackedWidget * stack_widget_;
306 BackgroundWidget * bg_widget_;
308 ToolbarMap toolbars_;
309 ProgressInterface* progress_;
310 /// The main layout box.
312 * \warning Don't Delete! The layout box is actually owned by
313 * whichever toolbar contains it. All the GuiView class needs is a
314 * means of accessing it.
316 * FIXME: replace that with a proper model so that we are not limited
317 * to only one dialog.
322 map<string, DialogPtr> dialogs_;
324 unsigned int smallIconSize;
325 unsigned int normalIconSize;
326 unsigned int bigIconSize;
328 QTimer statusbar_timer_;
329 /// auto-saving of buffers
330 Timeout autosave_timeout_;
331 /// flag against a race condition due to multiclicks, see bug #1119
335 TocModels toc_models_;
337 #if (QT_VERSION >= 0x040400)
339 QFutureWatcher<docstring> autosave_watcher_;
340 QFutureWatcher<docstring> preview_watcher_;
342 struct DummyWatcher { bool isRunning(){return false;} };
343 DummyWatcher preview_watcher_;
348 GuiView::GuiView(int id)
349 : d(*new GuiViewPrivate(this)), id_(id), closing_(false)
351 // GuiToolbars *must* be initialised before the menu bar.
352 normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
355 // set ourself as the current view. This is needed for the menu bar
356 // filling, at least for the static special menu item on Mac. Otherwise
357 // they are greyed out.
358 guiApp->setCurrentView(this);
360 // Fill up the menu bar.
361 guiApp->menus().fillMenuBar(menuBar(), this, true);
363 setCentralWidget(d.stack_widget_);
365 // Start autosave timer
366 if (lyxrc.autosave) {
367 d.autosave_timeout_.timeout.connect(boost::bind(&GuiView::autoSave, this));
368 d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
369 d.autosave_timeout_.start();
371 connect(&d.statusbar_timer_, SIGNAL(timeout()),
372 this, SLOT(clearMessage()));
374 // We don't want to keep the window in memory if it is closed.
375 setAttribute(Qt::WA_DeleteOnClose, true);
377 #if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX))
378 // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
379 // since the icon is provided in the application bundle.
380 setWindowIcon(getPixmap("images/", "lyx", "png"));
383 #if (QT_VERSION >= 0x040300)
384 // use tabbed dock area for multiple docks
385 // (such as "source" and "messages")
386 setDockOptions(QMainWindow::ForceTabbedDocks);
390 setAcceptDrops(true);
392 statusBar()->setSizeGripEnabled(true);
395 #if (QT_VERSION >= 0x040400)
396 connect(&d.autosave_watcher_, SIGNAL(finished()), this,
397 SLOT(threadFinished()));
398 connect(&d.preview_watcher_, SIGNAL(finished()), this,
399 SLOT(threadFinished()));
402 connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
403 SLOT(doShowDialog(QString const &, QString const &, Inset *)));
405 // Forbid too small unresizable window because it can happen
406 // with some window manager under X11.
407 setMinimumSize(300, 200);
409 if (lyxrc.allow_geometry_session) {
410 // Now take care of session management.
415 // no session handling, default to a sane size.
416 setGeometry(50, 50, 690, 510);
419 // clear session data if any.
421 settings.remove("views");
431 void GuiView::threadFinished()
433 #if (QT_VERSION >= 0x040400)
434 QFutureWatcher<docstring> const * watcher =
435 static_cast<QFutureWatcher<docstring> const *>(sender());
436 message(watcher->result());
441 void GuiView::saveLayout() const
444 settings.beginGroup("views");
445 settings.beginGroup(QString::number(id_));
447 settings.setValue("pos", pos());
448 settings.setValue("size", size());
450 settings.setValue("geometry", saveGeometry());
452 settings.setValue("layout", saveState(0));
453 settings.setValue("icon_size", iconSize());
457 bool GuiView::restoreLayout()
460 settings.beginGroup("views");
461 settings.beginGroup(QString::number(id_));
462 QString const icon_key = "icon_size";
463 if (!settings.contains(icon_key))
466 //code below is skipped when when ~/.config/LyX is (re)created
467 setIconSize(settings.value(icon_key).toSize());
469 QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
470 QSize size = settings.value("size", QSize(690, 510)).toSize();
474 // Work-around for bug #6034: the window ends up in an undetermined
475 // state when trying to restore a maximized window when it is
476 // already maximized.
477 if (!(windowState() & Qt::WindowMaximized))
478 if (!restoreGeometry(settings.value("geometry").toByteArray()))
479 setGeometry(50, 50, 690, 510);
481 // Make sure layout is correctly oriented.
482 setLayoutDirection(qApp->layoutDirection());
484 // Allow the toc and view-source dock widget to be restored if needed.
486 if ((dialog = findOrBuild("toc", true)))
487 // see bug 5082. At least setup title and enabled state.
488 // Visibility will be adjusted by restoreState below.
489 dialog->prepareView();
490 if ((dialog = findOrBuild("view-source", true)))
491 dialog->prepareView();
492 if ((dialog = findOrBuild("progress", true)))
493 dialog->prepareView();
495 if (!restoreState(settings.value("layout").toByteArray(), 0))
502 GuiToolbar * GuiView::toolbar(string const & name)
504 ToolbarMap::iterator it = d.toolbars_.find(name);
505 if (it != d.toolbars_.end())
508 LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
513 void GuiView::constructToolbars()
515 ToolbarMap::iterator it = d.toolbars_.begin();
516 for (; it != d.toolbars_.end(); ++it)
520 // I don't like doing this here, but the standard toolbar
521 // destroys this object when it's destroyed itself (vfr)
522 d.layout_ = new LayoutBox(*this);
523 d.stack_widget_->addWidget(d.layout_);
524 d.layout_->move(0,0);
526 // extracts the toolbars from the backend
527 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
528 Toolbars::Infos::iterator end = guiApp->toolbars().end();
529 for (; cit != end; ++cit)
530 d.toolbars_[cit->name] = new GuiToolbar(*cit, *this);
534 void GuiView::initToolbars()
536 // extracts the toolbars from the backend
537 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
538 Toolbars::Infos::iterator end = guiApp->toolbars().end();
539 for (; cit != end; ++cit) {
540 GuiToolbar * tb = toolbar(cit->name);
543 int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
544 bool newline = !(visibility & Toolbars::SAMEROW);
545 tb->setVisible(false);
546 tb->setVisibility(visibility);
548 if (visibility & Toolbars::TOP) {
550 addToolBarBreak(Qt::TopToolBarArea);
551 addToolBar(Qt::TopToolBarArea, tb);
554 if (visibility & Toolbars::BOTTOM) {
555 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
556 #if (QT_VERSION >= 0x040202)
558 addToolBarBreak(Qt::BottomToolBarArea);
560 addToolBar(Qt::BottomToolBarArea, tb);
563 if (visibility & Toolbars::LEFT) {
564 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
565 #if (QT_VERSION >= 0x040202)
567 addToolBarBreak(Qt::LeftToolBarArea);
569 addToolBar(Qt::LeftToolBarArea, tb);
572 if (visibility & Toolbars::RIGHT) {
573 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
574 #if (QT_VERSION >= 0x040202)
576 addToolBarBreak(Qt::RightToolBarArea);
578 addToolBar(Qt::RightToolBarArea, tb);
581 if (visibility & Toolbars::ON)
582 tb->setVisible(true);
587 TocModels & GuiView::tocModels()
589 return d.toc_models_;
593 void GuiView::setFocus()
595 LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this);
596 QMainWindow::setFocus();
600 void GuiView::focusInEvent(QFocusEvent * e)
602 LYXERR(Debug::DEBUG, "GuiView::focusInEvent()" << this);
603 QMainWindow::focusInEvent(e);
604 // Make sure guiApp points to the correct view.
605 guiApp->setCurrentView(this);
606 if (currentMainWorkArea())
607 currentMainWorkArea()->setFocus();
608 else if (currentWorkArea())
609 currentWorkArea()->setFocus();
611 d.bg_widget_->setFocus();
615 QMenu * GuiView::createPopupMenu()
617 return d.toolBarPopup(this);
621 void GuiView::showEvent(QShowEvent * e)
623 LYXERR(Debug::GUI, "Passed Geometry "
624 << size().height() << "x" << size().width()
625 << "+" << pos().x() << "+" << pos().y());
627 if (d.splitter_->count() == 0)
628 // No work area, switch to the background widget.
631 QMainWindow::showEvent(e);
635 /** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
636 ** is responsibility of the container (e.g., dialog)
638 void GuiView::closeEvent(QCloseEvent * close_event)
640 LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
645 // it can happen that this event arrives without selecting the view,
646 // e.g. when clicking the close button on a background window.
648 if (!closeWorkAreaAll()) {
650 close_event->ignore();
654 // Make sure that nothing will use this to be closed View.
655 guiApp->unregisterView(this);
657 if (isFullScreen()) {
658 // Switch off fullscreen before closing.
663 // Make sure the timer time out will not trigger a statusbar update.
664 d.statusbar_timer_.stop();
666 // Saving fullscreen requires additional tweaks in the toolbar code.
667 // It wouldn't also work under linux natively.
668 if (lyxrc.allow_geometry_session) {
669 // Save this window geometry and layout.
671 // Then the toolbar private states.
672 ToolbarMap::iterator end = d.toolbars_.end();
673 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
674 it->second->saveSession();
675 // Now take care of all other dialogs:
676 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
677 for (; it!= d.dialogs_.end(); ++it)
678 it->second->saveSession();
681 close_event->accept();
685 void GuiView::dragEnterEvent(QDragEnterEvent * event)
687 if (event->mimeData()->hasUrls())
689 /// \todo Ask lyx-devel is this is enough:
690 /// if (event->mimeData()->hasFormat("text/plain"))
691 /// event->acceptProposedAction();
695 void GuiView::dropEvent(QDropEvent * event)
697 QList<QUrl> files = event->mimeData()->urls();
701 LYXERR(Debug::GUI, "GuiView::dropEvent: got URLs!");
702 for (int i = 0; i != files.size(); ++i) {
703 string const file = os::internal_path(fromqstr(
704 files.at(i).toLocalFile()));
708 string const ext = support::getExtension(file);
709 vector<const Format *> found_formats;
711 // Find all formats that have the correct extension.
712 vector<const Format *> const & import_formats
713 = theConverters().importableFormats();
714 vector<const Format *>::const_iterator it = import_formats.begin();
715 for (; it != import_formats.end(); ++it)
716 if ((*it)->extension() == ext)
717 found_formats.push_back(*it);
720 if (found_formats.size() >= 1) {
721 if (found_formats.size() > 1) {
722 //FIXME: show a dialog to choose the correct importable format
724 "Multiple importable formats found, selecting first");
726 string const arg = found_formats[0]->name() + " " + file;
727 cmd = FuncRequest(LFUN_BUFFER_IMPORT, arg);
730 //FIXME: do we have to explicitly check whether it's a lyx file?
732 "No formats found, trying to open it as a lyx file");
733 cmd = FuncRequest(LFUN_FILE_OPEN, file);
736 // Asynchronously post the event. DropEvent usually comes
737 // from the BufferView. But reloading a file might close
738 // the BufferView from within its own event handler.
739 guiApp->dispatchDelayed(cmd);
745 void GuiView::message(docstring const & str)
747 if (ForkedProcess::iAmAChild())
750 // call is moved to GUI-thread by GuiProgress
751 d.progress_->appendMessage(toqstr(str));
755 void GuiView::updateMessage(QString const & str)
757 statusBar()->showMessage(str);
758 d.statusbar_timer_.stop();
759 d.statusbar_timer_.start(3000);
763 void GuiView::smallSizedIcons()
765 setIconSize(QSize(d.smallIconSize, d.smallIconSize));
769 void GuiView::normalSizedIcons()
771 setIconSize(QSize(d.normalIconSize, d.normalIconSize));
775 void GuiView::bigSizedIcons()
777 setIconSize(QSize(d.bigIconSize, d.bigIconSize));
781 void GuiView::clearMessage()
783 // FIXME: This code was introduced in r19643 to fix bug #4123. However,
784 // the hasFocus function mostly returns false, even if the focus is on
785 // a workarea in this view.
789 d.statusbar_timer_.stop();
793 void GuiView::updateWindowTitle(GuiWorkArea * wa)
795 if (wa != d.current_work_area_
796 || wa->bufferView().buffer().isInternal())
798 setWindowTitle(qt_("LyX: ") + wa->windowTitle());
799 setWindowIconText(wa->windowIconText());
803 void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
806 disconnectBufferView();
807 connectBufferView(wa->bufferView());
808 connectBuffer(wa->bufferView().buffer());
809 d.current_work_area_ = wa;
810 QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
811 this, SLOT(updateWindowTitle(GuiWorkArea *)));
812 updateWindowTitle(wa);
816 // The document settings needs to be reinitialised.
817 updateDialog("document", "");
819 // Buffer-dependent dialogs must be updated. This is done here because
820 // some dialogs require buffer()->text.
825 void GuiView::on_lastWorkAreaRemoved()
828 // We already are in a close event. Nothing more to do.
831 if (d.splitter_->count() > 1)
832 // We have a splitter so don't close anything.
835 // Reset and updates the dialogs.
836 d.toc_models_.reset(0);
837 updateDialog("document", "");
840 resetWindowTitleAndIconText();
843 if (lyxrc.open_buffers_in_tabs)
844 // Nothing more to do, the window should stay open.
847 if (guiApp->viewIds().size() > 1) {
853 // On Mac we also close the last window because the application stay
854 // resident in memory. On other platforms we don't close the last
855 // window because this would quit the application.
861 void GuiView::updateStatusBar()
863 // let the user see the explicit message
864 if (d.statusbar_timer_.isActive())
871 void GuiView::showMessage()
873 QString msg = toqstr(theGuiApp()->viewStatusMessage());
875 BufferView const * bv = currentBufferView();
877 msg = toqstr(bv->cursor().currentState());
879 msg = qt_("Welcome to LyX!");
881 statusBar()->showMessage(msg);
885 bool GuiView::event(QEvent * e)
889 // Useful debug code:
890 //case QEvent::ActivationChange:
891 //case QEvent::WindowDeactivate:
892 //case QEvent::Paint:
893 //case QEvent::Enter:
894 //case QEvent::Leave:
895 //case QEvent::HoverEnter:
896 //case QEvent::HoverLeave:
897 //case QEvent::HoverMove:
898 //case QEvent::StatusTip:
899 //case QEvent::DragEnter:
900 //case QEvent::DragLeave:
904 case QEvent::WindowActivate: {
905 GuiView * old_view = guiApp->currentView();
906 if (this == old_view) {
908 return QMainWindow::event(e);
910 if (old_view && old_view->currentBufferView()) {
911 // save current selection to the selection buffer to allow
912 // middle-button paste in this window.
913 cap::saveSelection(old_view->currentBufferView()->cursor());
915 guiApp->setCurrentView(this);
916 if (d.current_work_area_) {
917 BufferView & bv = d.current_work_area_->bufferView();
918 connectBufferView(bv);
919 connectBuffer(bv.buffer());
920 // The document structure, name and dialogs might have
921 // changed in another view.
923 // The document settings needs to be reinitialised.
924 updateDialog("document", "");
927 resetWindowTitleAndIconText();
930 return QMainWindow::event(e);
933 case QEvent::ShortcutOverride: {
936 #if (!defined Q_WS_X11) || (QT_VERSION >= 0x040500)
937 if (isFullScreen() && menuBar()->isHidden()) {
938 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
939 // FIXME: we should also try to detect special LyX shortcut such as
940 // Alt-P and Alt-M. Right now there is a hack in
941 // GuiWorkArea::processKeySym() that hides again the menubar for
943 if (ke->modifiers() & Qt::AltModifier && ke->key() != Qt::Key_Alt) {
945 return QMainWindow::event(e);
949 return QMainWindow::event(e);
953 return QMainWindow::event(e);
957 void GuiView::resetWindowTitleAndIconText()
959 setWindowTitle(qt_("LyX"));
960 setWindowIconText(qt_("LyX"));
963 bool GuiView::focusNextPrevChild(bool /*next*/)
970 void GuiView::setBusy(bool busy)
972 if (d.current_work_area_) {
973 d.current_work_area_->setUpdatesEnabled(!busy);
975 d.current_work_area_->stopBlinkingCursor();
977 d.current_work_area_->startBlinkingCursor();
981 QApplication::setOverrideCursor(Qt::WaitCursor);
983 QApplication::restoreOverrideCursor();
987 GuiWorkArea * GuiView::workArea(Buffer & buffer)
989 if (currentWorkArea()
990 && ¤tWorkArea()->bufferView().buffer() == &buffer)
991 return (GuiWorkArea *) currentWorkArea();
992 if (TabWorkArea * twa = d.currentTabWorkArea())
993 return twa->workArea(buffer);
998 GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
1000 // Automatically create a TabWorkArea if there are none yet.
1001 TabWorkArea * tab_widget = d.splitter_->count()
1002 ? d.currentTabWorkArea() : addTabWorkArea();
1003 return tab_widget->addWorkArea(buffer, *this);
1007 TabWorkArea * GuiView::addTabWorkArea()
1009 TabWorkArea * twa = new TabWorkArea;
1010 QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
1011 this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
1012 QObject::connect(twa, SIGNAL(lastWorkAreaRemoved()),
1013 this, SLOT(on_lastWorkAreaRemoved()));
1015 d.splitter_->addWidget(twa);
1016 d.stack_widget_->setCurrentWidget(d.splitter_);
1021 GuiWorkArea const * GuiView::currentWorkArea() const
1023 return d.current_work_area_;
1027 GuiWorkArea * GuiView::currentWorkArea()
1029 return d.current_work_area_;
1033 GuiWorkArea const * GuiView::currentMainWorkArea() const
1035 if (d.currentTabWorkArea() == NULL)
1037 return d.currentTabWorkArea()->currentWorkArea();
1041 GuiWorkArea * GuiView::currentMainWorkArea()
1043 if (d.currentTabWorkArea() == NULL)
1045 return d.currentTabWorkArea()->currentWorkArea();
1049 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
1051 LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
1053 d.current_work_area_ = NULL;
1057 GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
1061 if (currentBufferView())
1062 cap::saveSelection(currentBufferView()->cursor());
1064 theGuiApp()->setCurrentView(this);
1065 d.current_work_area_ = wa;
1066 for (int i = 0; i != d.splitter_->count(); ++i) {
1067 if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
1068 //if (d.current_main_work_area_)
1069 // d.current_main_work_area_->setFrameStyle(QFrame::NoFrame);
1070 d.current_main_work_area_ = wa;
1071 //d.current_main_work_area_->setFrameStyle(QFrame::Box | QFrame::Plain);
1072 //d.current_main_work_area_->setLineWidth(2);
1073 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
1077 LYXERR(Debug::DEBUG, "This is not a tabbed wa");
1078 on_currentWorkAreaChanged(wa);
1079 BufferView & bv = wa->bufferView();
1080 bv.cursor().fixIfBroken();
1082 wa->setUpdatesEnabled(true);
1083 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
1087 void GuiView::removeWorkArea(GuiWorkArea * wa)
1089 LASSERT(wa, return);
1090 if (wa == d.current_work_area_) {
1092 disconnectBufferView();
1093 d.current_work_area_ = 0;
1094 d.current_main_work_area_ = 0;
1097 bool found_twa = false;
1098 for (int i = 0; i != d.splitter_->count(); ++i) {
1099 TabWorkArea * twa = d.tabWorkArea(i);
1100 if (twa->removeWorkArea(wa)) {
1101 // Found in this tab group, and deleted the GuiWorkArea.
1103 if (twa->count() != 0) {
1104 if (d.current_work_area_ == 0)
1105 // This means that we are closing the current GuiWorkArea, so
1106 // switch to the next GuiWorkArea in the found TabWorkArea.
1107 setCurrentWorkArea(twa->currentWorkArea());
1109 // No more WorkAreas in this tab group, so delete it.
1116 // It is not a tabbed work area (i.e., the search work area), so it
1117 // should be deleted by other means.
1118 LASSERT(found_twa, /* */);
1120 if (d.current_work_area_ == 0) {
1121 if (d.splitter_->count() != 0) {
1122 TabWorkArea * twa = d.currentTabWorkArea();
1123 setCurrentWorkArea(twa->currentWorkArea());
1125 // No more work areas, switch to the background widget.
1126 setCurrentWorkArea(0);
1132 LayoutBox * GuiView::getLayoutDialog() const
1138 void GuiView::updateLayoutList()
1141 d.layout_->updateContents(false);
1145 void GuiView::updateToolbars()
1147 ToolbarMap::iterator end = d.toolbars_.end();
1148 if (d.current_work_area_) {
1150 d.current_work_area_->bufferView().cursor().inMathed();
1152 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
1154 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
1155 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
1156 bool const mathmacrotemplate =
1157 lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
1159 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1160 it->second->update(math, table, review, mathmacrotemplate);
1162 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1163 it->second->update(false, false, false, false);
1167 void GuiView::setBuffer(Buffer * newBuffer)
1169 LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl);
1170 LASSERT(newBuffer, return);
1173 GuiWorkArea * wa = workArea(*newBuffer);
1175 newBuffer->masterBuffer()->updateLabels();
1176 wa = addWorkArea(*newBuffer);
1178 //Disconnect the old buffer...there's no new one.
1181 connectBuffer(*newBuffer);
1182 connectBufferView(wa->bufferView());
1183 setCurrentWorkArea(wa);
1189 void GuiView::connectBuffer(Buffer & buf)
1191 buf.setGuiDelegate(this);
1195 void GuiView::disconnectBuffer()
1197 if (d.current_work_area_)
1198 d.current_work_area_->bufferView().buffer().setGuiDelegate(0);
1202 void GuiView::connectBufferView(BufferView & bv)
1204 bv.setGuiDelegate(this);
1208 void GuiView::disconnectBufferView()
1210 if (d.current_work_area_)
1211 d.current_work_area_->bufferView().setGuiDelegate(0);
1215 void GuiView::errors(string const & error_type, bool from_master)
1217 ErrorList & el = from_master ?
1218 documentBufferView()->buffer().masterBuffer()->errorList(error_type)
1219 : documentBufferView()->buffer().errorList(error_type);
1220 string data = error_type;
1222 data = "from_master|" + error_type;
1224 showDialog("errorlist", data);
1228 void GuiView::updateTocItem(string const & type, DocIterator const & dit)
1230 d.toc_models_.updateItem(toqstr(type), dit);
1234 void GuiView::structureChanged()
1236 d.toc_models_.reset(documentBufferView());
1237 // Navigator needs more than a simple update in this case. It needs to be
1239 updateDialog("toc", "");
1243 void GuiView::updateDialog(string const & name, string const & data)
1245 if (!isDialogVisible(name))
1248 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
1249 if (it == d.dialogs_.end())
1252 Dialog * const dialog = it->second.get();
1253 if (dialog->isVisibleView())
1254 dialog->initialiseParams(data);
1258 BufferView * GuiView::documentBufferView()
1260 return currentMainWorkArea()
1261 ? ¤tMainWorkArea()->bufferView()
1266 BufferView const * GuiView::documentBufferView() const
1268 return currentMainWorkArea()
1269 ? ¤tMainWorkArea()->bufferView()
1274 BufferView * GuiView::currentBufferView()
1276 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1280 BufferView const * GuiView::currentBufferView() const
1282 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1286 #if (QT_VERSION >= 0x040400)
1287 static docstring saveAndDestroyBuffer(Buffer * buffer, FileName const & fname)
1290 FileName const tmp_ret = FileName::tempName("lyxauto");
1291 if (!tmp_ret.empty()) {
1292 if (buffer->writeFile(tmp_ret))
1293 failed = !tmp_ret.moveTo(fname);
1296 // failed to write/rename tmp_ret so try writing direct
1297 failed = buffer->writeFile(fname);
1301 ? _("Automatic save failed!")
1302 : _("Automatic save done.");
1307 void GuiView::autoSave()
1309 LYXERR(Debug::INFO, "Running autoSave()");
1311 Buffer * buffer = documentBufferView()
1312 ? &documentBufferView()->buffer() : 0;
1316 #if (QT_VERSION >= 0x040400)
1317 QFuture<docstring> f = QtConcurrent::run(saveAndDestroyBuffer, buffer->clone(),
1318 buffer->getAutosaveFilename());
1319 d.autosave_watcher_.setFuture(f);
1326 void GuiView::resetAutosaveTimers()
1329 d.autosave_timeout_.restart();
1333 bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
1336 Buffer * buf = currentBufferView()
1337 ? ¤tBufferView()->buffer() : 0;
1338 Buffer * doc_buffer = documentBufferView()
1339 ? &(documentBufferView()->buffer()) : 0;
1341 // Check whether we need a buffer
1342 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
1343 // no, exit directly
1344 flag.message(from_utf8(N_("Command not allowed with"
1345 "out any document open")));
1346 flag.setEnabled(false);
1350 if (cmd.origin == FuncRequest::TOC) {
1351 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
1353 if (toc->getStatus(documentBufferView()->cursor(), cmd, fs))
1356 flag.setEnabled(false);
1360 switch(cmd.action) {
1361 case LFUN_BUFFER_IMPORT:
1364 case LFUN_MASTER_BUFFER_UPDATE:
1365 case LFUN_MASTER_BUFFER_VIEW:
1366 enable = doc_buffer && doc_buffer->parent() != 0
1367 && !d.preview_watcher_.isRunning();
1370 case LFUN_BUFFER_UPDATE:
1371 case LFUN_BUFFER_VIEW: {
1372 if (!doc_buffer || d.preview_watcher_.isRunning()) {
1376 string format = to_utf8(cmd.argument());
1377 if (cmd.argument().empty())
1378 format = doc_buffer->getDefaultOutputFormat();
1379 enable = doc_buffer->isExportableFormat(format);
1383 case LFUN_BUFFER_RELOAD:
1384 enable = doc_buffer && !doc_buffer->isUnnamed()
1385 && doc_buffer->fileName().exists()
1386 && (!doc_buffer->isClean()
1387 || doc_buffer->isExternallyModified(Buffer::timestamp_method));
1390 case LFUN_BUFFER_CHILD_OPEN:
1391 enable = doc_buffer;
1394 case LFUN_BUFFER_WRITE:
1395 enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
1398 //FIXME: This LFUN should be moved to GuiApplication.
1399 case LFUN_BUFFER_WRITE_ALL: {
1400 // We enable the command only if there are some modified buffers
1401 Buffer * first = theBufferList().first();
1406 // We cannot use a for loop as the buffer list is a cycle.
1408 if (!b->isClean()) {
1412 b = theBufferList().next(b);
1413 } while (b != first);
1417 case LFUN_BUFFER_WRITE_AS:
1418 enable = doc_buffer;
1421 case LFUN_BUFFER_CLOSE:
1422 enable = doc_buffer;
1425 case LFUN_BUFFER_CLOSE_ALL:
1426 enable = theBufferList().last() != theBufferList().first();
1429 case LFUN_SPLIT_VIEW:
1430 if (cmd.getArg(0) == "vertical")
1431 enable = doc_buffer && (d.splitter_->count() == 1 ||
1432 d.splitter_->orientation() == Qt::Vertical);
1434 enable = doc_buffer && (d.splitter_->count() == 1 ||
1435 d.splitter_->orientation() == Qt::Horizontal);
1438 case LFUN_CLOSE_TAB_GROUP:
1439 enable = d.currentTabWorkArea();
1442 case LFUN_TOOLBAR_TOGGLE: {
1443 string const name = cmd.getArg(0);
1444 if (GuiToolbar * t = toolbar(name))
1445 flag.setOnOff(t->isVisible());
1448 docstring const msg =
1449 bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
1455 case LFUN_DROP_LAYOUTS_CHOICE:
1459 case LFUN_UI_TOGGLE:
1460 flag.setOnOff(isFullScreen());
1463 case LFUN_DIALOG_DISCONNECT_INSET:
1466 case LFUN_DIALOG_HIDE:
1467 // FIXME: should we check if the dialog is shown?
1470 case LFUN_DIALOG_TOGGLE:
1471 flag.setOnOff(isDialogVisible(cmd.getArg(0)));
1472 // fall through to set "enable"
1473 case LFUN_DIALOG_SHOW: {
1474 string const name = cmd.getArg(0);
1476 enable = name == "aboutlyx"
1477 || name == "file" //FIXME: should be removed.
1479 || name == "texinfo"
1480 || name == "progress"
1481 || name == "compare";
1482 else if (name == "print")
1483 enable = doc_buffer->isExportable("dvi")
1484 && lyxrc.print_command != "none";
1485 else if (name == "character" || name == "symbols") {
1486 if (!buf || buf->isReadonly()
1487 || !currentBufferView()->cursor().inTexted())
1490 // FIXME we should consider passthru
1492 Inset const & in = currentBufferView()->cursor().inset();
1493 enable = !in.getLayout().isPassThru();
1496 else if (name == "latexlog")
1497 enable = FileName(doc_buffer->logName()).isReadableFile();
1498 else if (name == "spellchecker")
1499 enable = theSpellChecker() && !doc_buffer->isReadonly();
1500 else if (name == "vclog")
1501 enable = doc_buffer->lyxvc().inUse();
1505 case LFUN_DIALOG_UPDATE: {
1506 string const name = cmd.getArg(0);
1508 enable = name == "prefs";
1512 case LFUN_COMMAND_EXECUTE:
1514 case LFUN_MENU_OPEN:
1515 // Nothing to check.
1518 case LFUN_COMPLETION_INLINE:
1519 if (!d.current_work_area_
1520 || !d.current_work_area_->completer().inlinePossible(
1521 currentBufferView()->cursor()))
1525 case LFUN_COMPLETION_POPUP:
1526 if (!d.current_work_area_
1527 || !d.current_work_area_->completer().popupPossible(
1528 currentBufferView()->cursor()))
1532 case LFUN_COMPLETION_COMPLETE:
1533 if (!d.current_work_area_
1534 || !d.current_work_area_->completer().inlinePossible(
1535 currentBufferView()->cursor()))
1539 case LFUN_COMPLETION_ACCEPT:
1540 if (!d.current_work_area_
1541 || (!d.current_work_area_->completer().popupVisible()
1542 && !d.current_work_area_->completer().inlineVisible()
1543 && !d.current_work_area_->completer().completionAvailable()))
1547 case LFUN_COMPLETION_CANCEL:
1548 if (!d.current_work_area_
1549 || (!d.current_work_area_->completer().popupVisible()
1550 && !d.current_work_area_->completer().inlineVisible()))
1554 case LFUN_BUFFER_ZOOM_OUT:
1555 enable = doc_buffer && lyxrc.zoom > 10;
1558 case LFUN_BUFFER_ZOOM_IN:
1559 enable = doc_buffer;
1562 case LFUN_BUFFER_NEXT:
1563 case LFUN_BUFFER_PREVIOUS:
1564 // FIXME: should we check is there is an previous or next buffer?
1566 case LFUN_BUFFER_SWITCH:
1567 // toggle on the current buffer, but do not toggle off
1568 // the other ones (is that a good idea?)
1570 && to_utf8(cmd.argument()) == doc_buffer->absFileName())
1571 flag.setOnOff(true);
1574 case LFUN_VC_REGISTER:
1575 enable = doc_buffer && !doc_buffer->lyxvc().inUse();
1577 case LFUN_VC_CHECK_IN:
1578 enable = doc_buffer && doc_buffer->lyxvc().checkInEnabled();
1580 case LFUN_VC_CHECK_OUT:
1581 enable = doc_buffer && doc_buffer->lyxvc().checkOutEnabled();
1583 case LFUN_VC_LOCKING_TOGGLE:
1584 enable = doc_buffer && !doc_buffer->isReadonly()
1585 && doc_buffer->lyxvc().lockingToggleEnabled();
1586 flag.setOnOff(enable && doc_buffer->lyxvc().locking());
1588 case LFUN_VC_REVERT:
1589 enable = doc_buffer && doc_buffer->lyxvc().inUse();
1591 case LFUN_VC_UNDO_LAST:
1592 enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
1594 case LFUN_VC_REPO_UPDATE:
1595 enable = doc_buffer && doc_buffer->lyxvc().inUse();
1597 case LFUN_VC_COMMAND: {
1598 if (cmd.argument().empty())
1600 if (!doc_buffer && contains(cmd.getArg(0), 'D'))
1604 case LFUN_VC_COMPARE:
1605 enable = doc_buffer && !cmd.argument().empty()
1606 && doc_buffer->lyxvc().prepareFileRevisionEnabled();
1609 case LFUN_SERVER_GOTO_FILE_ROW:
1617 flag.setEnabled(false);
1623 static FileName selectTemplateFile()
1625 FileDialog dlg(qt_("Select template file"));
1626 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1627 dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
1629 FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
1630 QStringList(qt_("LyX Documents (*.lyx)")));
1632 if (result.first == FileDialog::Later)
1634 if (result.second.isEmpty())
1636 return FileName(fromqstr(result.second));
1640 Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
1644 Buffer * newBuffer = checkAndLoadLyXFile(filename);
1647 message(_("Document not loaded."));
1652 setBuffer(newBuffer);
1654 // scroll to the position when the file was last closed
1655 if (lyxrc.use_lastfilepos) {
1656 LastFilePosSection::FilePos filepos =
1657 theSession().lastFilePos().load(filename);
1658 documentBufferView()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
1662 theSession().lastFiles().add(filename);
1669 void GuiView::openDocument(string const & fname)
1671 string initpath = lyxrc.document_path;
1673 if (documentBufferView()) {
1674 string const trypath = documentBufferView()->buffer().filePath();
1675 // If directory is writeable, use this as default.
1676 if (FileName(trypath).isDirWritable())
1682 if (fname.empty()) {
1683 FileDialog dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
1684 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1685 dlg.setButton2(qt_("Examples|#E#e"),
1686 toqstr(addPath(package().system_support().absFilename(), "examples")));
1688 QStringList filter(qt_("LyX Documents (*.lyx)"));
1689 filter << qt_("LyX-1.3.x Documents (*.lyx13)")
1690 << qt_("LyX-1.4.x Documents (*.lyx14)")
1691 << qt_("LyX-1.5.x Documents (*.lyx15)")
1692 << qt_("LyX-1.6.x Documents (*.lyx16)");
1693 FileDialog::Result result =
1694 dlg.open(toqstr(initpath), filter);
1696 if (result.first == FileDialog::Later)
1699 filename = fromqstr(result.second);
1701 // check selected filename
1702 if (filename.empty()) {
1703 message(_("Canceled."));
1709 // get absolute path of file and add ".lyx" to the filename if
1711 FileName const fullname =
1712 fileSearch(string(), filename, "lyx", support::may_not_exist);
1713 if (!fullname.empty())
1714 filename = fullname.absFilename();
1716 if (!fullname.onlyPath().isDirectory()) {
1717 Alert::warning(_("Invalid filename"),
1718 bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
1719 from_utf8(fullname.absFilename())));
1722 // if the file doesn't exist, let the user create one
1723 if (!fullname.exists()) {
1724 // the user specifically chose this name. Believe him.
1725 Buffer * const b = newFile(filename, string(), true);
1731 docstring const disp_fn = makeDisplayPath(filename);
1732 message(bformat(_("Opening document %1$s..."), disp_fn));
1735 Buffer * buf = loadDocument(fullname);
1737 buf->updateLabels();
1739 buf->errors("Parse");
1740 str2 = bformat(_("Document %1$s opened."), disp_fn);
1741 if (buf->lyxvc().inUse())
1742 str2 += " " + from_utf8(buf->lyxvc().versionString()) +
1743 " " + _("Version control detected.");
1745 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1750 // FIXME: clean that
1751 static bool import(GuiView * lv, FileName const & filename,
1752 string const & format, ErrorList & errorList)
1754 FileName const lyxfile(support::changeExtension(filename.absFilename(), ".lyx"));
1756 string loader_format;
1757 vector<string> loaders = theConverters().loaders();
1758 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
1759 for (vector<string>::const_iterator it = loaders.begin();
1760 it != loaders.end(); ++it) {
1761 if (!theConverters().isReachable(format, *it))
1764 string const tofile =
1765 support::changeExtension(filename.absFilename(),
1766 formats.extension(*it));
1767 if (!theConverters().convert(0, filename, FileName(tofile),
1768 filename, format, *it, errorList))
1770 loader_format = *it;
1773 if (loader_format.empty()) {
1774 frontend::Alert::error(_("Couldn't import file"),
1775 bformat(_("No information for importing the format %1$s."),
1776 formats.prettyName(format)));
1780 loader_format = format;
1782 if (loader_format == "lyx") {
1783 Buffer * buf = lv->loadDocument(lyxfile);
1786 buf->updateLabels();
1788 buf->errors("Parse");
1790 Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
1794 bool as_paragraphs = loader_format == "textparagraph";
1795 string filename2 = (loader_format == format) ? filename.absFilename()
1796 : support::changeExtension(filename.absFilename(),
1797 formats.extension(loader_format));
1798 lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
1800 guiApp->setCurrentView(lv);
1801 lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
1808 void GuiView::importDocument(string const & argument)
1811 string filename = split(argument, format, ' ');
1813 LYXERR(Debug::INFO, format << " file: " << filename);
1815 // need user interaction
1816 if (filename.empty()) {
1817 string initpath = lyxrc.document_path;
1818 if (documentBufferView()) {
1819 string const trypath = documentBufferView()->buffer().filePath();
1820 // If directory is writeable, use this as default.
1821 if (FileName(trypath).isDirWritable())
1825 docstring const text = bformat(_("Select %1$s file to import"),
1826 formats.prettyName(format));
1828 FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
1829 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1830 dlg.setButton2(qt_("Examples|#E#e"),
1831 toqstr(addPath(package().system_support().absFilename(), "examples")));
1833 docstring filter = formats.prettyName(format);
1836 filter += from_utf8(formats.extension(format));
1839 FileDialog::Result result =
1840 dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
1842 if (result.first == FileDialog::Later)
1845 filename = fromqstr(result.second);
1847 // check selected filename
1848 if (filename.empty())
1849 message(_("Canceled."));
1852 if (filename.empty())
1855 // get absolute path of file
1856 FileName const fullname(support::makeAbsPath(filename));
1858 FileName const lyxfile(support::changeExtension(fullname.absFilename(), ".lyx"));
1860 // Check if the document already is open
1861 Buffer * buf = theBufferList().getBuffer(lyxfile);
1864 if (!closeBuffer()) {
1865 message(_("Canceled."));
1870 docstring const displaypath = makeDisplayPath(lyxfile.absFilename(), 30);
1872 // if the file exists already, and we didn't do
1873 // -i lyx thefile.lyx, warn
1874 if (lyxfile.exists() && fullname != lyxfile) {
1876 docstring text = bformat(_("The document %1$s already exists.\n\n"
1877 "Do you want to overwrite that document?"), displaypath);
1878 int const ret = Alert::prompt(_("Overwrite document?"),
1879 text, 0, 1, _("&Overwrite"), _("&Cancel"));
1882 message(_("Canceled."));
1887 message(bformat(_("Importing %1$s..."), displaypath));
1888 ErrorList errorList;
1889 if (import(this, fullname, format, errorList))
1890 message(_("imported."));
1892 message(_("file not imported!"));
1894 // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
1898 void GuiView::newDocument(string const & filename, bool from_template)
1900 FileName initpath(lyxrc.document_path);
1901 if (documentBufferView()) {
1902 FileName const trypath(documentBufferView()->buffer().filePath());
1903 // If directory is writeable, use this as default.
1904 if (trypath.isDirWritable())
1908 string templatefile;
1909 if (from_template) {
1910 templatefile = selectTemplateFile().absFilename();
1911 if (templatefile.empty())
1916 if (filename.empty())
1917 b = newUnnamedFile(initpath, to_utf8(_("newfile")), templatefile);
1919 b = newFile(filename, templatefile, true);
1924 // If no new document could be created, it is unsure
1925 // whether there is a valid BufferView.
1926 if (currentBufferView())
1927 // Ensure the cursor is correctly positioned on screen.
1928 currentBufferView()->showCursor();
1932 void GuiView::insertLyXFile(docstring const & fname)
1934 BufferView * bv = documentBufferView();
1939 FileName filename(to_utf8(fname));
1941 if (!filename.empty()) {
1942 bv->insertLyXFile(filename);
1946 // Launch a file browser
1948 string initpath = lyxrc.document_path;
1949 string const trypath = bv->buffer().filePath();
1950 // If directory is writeable, use this as default.
1951 if (FileName(trypath).isDirWritable())
1955 FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
1956 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1957 dlg.setButton2(qt_("Examples|#E#e"),
1958 toqstr(addPath(package().system_support().absFilename(),
1961 FileDialog::Result result = dlg.open(toqstr(initpath),
1962 QStringList(qt_("LyX Documents (*.lyx)")));
1964 if (result.first == FileDialog::Later)
1968 filename.set(fromqstr(result.second));
1970 // check selected filename
1971 if (filename.empty()) {
1972 // emit message signal.
1973 message(_("Canceled."));
1977 bv->insertLyXFile(filename);
1981 void GuiView::insertPlaintextFile(docstring const & fname,
1984 BufferView * bv = documentBufferView();
1988 if (!fname.empty() && !FileName::isAbsolute(to_utf8(fname))) {
1989 message(_("Absolute filename expected."));
1994 FileName filename(to_utf8(fname));
1996 if (!filename.empty()) {
1997 bv->insertPlaintextFile(filename, asParagraph);
2001 FileDialog dlg(qt_("Select file to insert"), (asParagraph ?
2002 LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
2004 FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
2005 QStringList(qt_("All Files (*)")));
2007 if (result.first == FileDialog::Later)
2011 filename.set(fromqstr(result.second));
2013 // check selected filename
2014 if (filename.empty()) {
2015 // emit message signal.
2016 message(_("Canceled."));
2020 bv->insertPlaintextFile(filename, asParagraph);
2024 bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
2026 FileName fname = b.fileName();
2027 FileName const oldname = fname;
2029 if (!newname.empty()) {
2031 fname = support::makeAbsPath(to_utf8(newname), oldname.onlyPath().absFilename());
2033 // Switch to this Buffer.
2036 // No argument? Ask user through dialog.
2038 FileDialog dlg(qt_("Choose a filename to save document as"),
2039 LFUN_BUFFER_WRITE_AS);
2040 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2041 dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
2043 if (!isLyXFilename(fname.absFilename()))
2044 fname.changeExtension(".lyx");
2046 FileDialog::Result result =
2047 dlg.save(toqstr(fname.onlyPath().absFilename()),
2048 QStringList(qt_("LyX Documents (*.lyx)")),
2049 toqstr(fname.onlyFileName()));
2051 if (result.first == FileDialog::Later)
2054 fname.set(fromqstr(result.second));
2059 if (!isLyXFilename(fname.absFilename()))
2060 fname.changeExtension(".lyx");
2063 if (FileName(fname).exists()) {
2064 docstring const file = makeDisplayPath(fname.absFilename(), 30);
2065 docstring text = bformat(_("The document %1$s already "
2066 "exists.\n\nDo you want to "
2067 "overwrite that document?"),
2069 int const ret = Alert::prompt(_("Overwrite document?"),
2070 text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
2073 case 1: return renameBuffer(b, docstring());
2074 case 2: return false;
2078 FileName oldauto = b.getAutosaveFilename();
2080 // Ok, change the name of the buffer
2081 b.setFileName(fname.absFilename());
2083 bool unnamed = b.isUnnamed();
2084 b.setUnnamed(false);
2085 b.saveCheckSum(fname);
2087 // bring the autosave file with us, just in case.
2088 b.moveAutosaveFile(oldauto);
2090 if (!saveBuffer(b)) {
2091 oldauto = b.getAutosaveFilename();
2092 b.setFileName(oldname.absFilename());
2093 b.setUnnamed(unnamed);
2094 b.saveCheckSum(oldname);
2095 b.moveAutosaveFile(oldauto);
2103 bool GuiView::saveBuffer(Buffer & b)
2105 if (workArea(b) && workArea(b)->inDialogMode())
2109 return renameBuffer(b, docstring());
2112 theSession().lastFiles().add(b.fileName());
2116 // Switch to this Buffer.
2119 // FIXME: we don't tell the user *WHY* the save failed !!
2120 docstring const file = makeDisplayPath(b.absFileName(), 30);
2121 docstring text = bformat(_("The document %1$s could not be saved.\n\n"
2122 "Do you want to rename the document and "
2123 "try again?"), file);
2124 int const ret = Alert::prompt(_("Rename and save?"),
2125 text, 0, 2, _("&Rename"), _("&Retry"), _("&Cancel"));
2128 if (!renameBuffer(b, docstring()))
2137 return saveBuffer(b);
2141 bool GuiView::hideWorkArea(GuiWorkArea * wa)
2143 return closeWorkArea(wa, false);
2147 bool GuiView::closeWorkArea(GuiWorkArea * wa)
2149 Buffer & buf = wa->bufferView().buffer();
2150 return closeWorkArea(wa, !buf.parent());
2154 bool GuiView::closeBuffer()
2156 GuiWorkArea * wa = currentMainWorkArea();
2157 setCurrentWorkArea(wa);
2158 Buffer & buf = wa->bufferView().buffer();
2159 return wa && closeWorkArea(wa, !buf.parent());
2163 void GuiView::writeSession() const {
2164 GuiWorkArea const * active_wa = currentMainWorkArea();
2165 for (int i = 0; i < d.splitter_->count(); ++i) {
2166 TabWorkArea * twa = d.tabWorkArea(i);
2167 for (int j = 0; j < twa->count(); ++j) {
2168 GuiWorkArea * wa = static_cast<GuiWorkArea *>(twa->widget(j));
2169 Buffer & buf = wa->bufferView().buffer();
2170 theSession().lastOpened().add(buf.fileName(), wa == active_wa);
2176 bool GuiView::closeBufferAll()
2178 // Close the workareas in all other views
2179 QList<int> const ids = guiApp->viewIds();
2180 for (int i = 0; i != ids.size(); ++i) {
2181 if (id_ != ids[i] && !guiApp->view(ids[i]).closeWorkAreaAll())
2185 // Close our own workareas
2186 if (!closeWorkAreaAll())
2189 // Now close the hidden buffers. We prevent hidden buffers from being
2190 // dirty, so we can just close them.
2191 theBufferList().closeAll();
2196 bool GuiView::closeWorkAreaAll()
2198 setCurrentWorkArea(currentMainWorkArea());
2200 // We might be in a situation that there is still a tabWorkArea, but
2201 // there are no tabs anymore. This can happen when we get here after a
2202 // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
2203 // many TabWorkArea's have no documents anymore.
2206 // We have to call count() each time, because it can happen that
2207 // more than one splitter will disappear in one iteration (bug 5998).
2208 for (; d.splitter_->count() > empty_twa; ) {
2209 TabWorkArea * twa = d.tabWorkArea(empty_twa);
2211 if (twa->count() == 0)
2214 setCurrentWorkArea(twa->currentWorkArea());
2215 if (!closeTabWorkArea(twa))
2223 bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer)
2228 Buffer & buf = wa->bufferView().buffer();
2231 return closeBuffer(buf);
2233 if (!inMultiTabs(wa))
2234 if (!saveBufferIfNeeded(buf, true))
2242 bool GuiView::closeBuffer(Buffer & buf)
2244 // If we are in a close_event all children will be closed in some time,
2245 // so no need to do it here. This will ensure that the children end up
2246 // in the session file in the correct order. If we close the master
2247 // buffer, we can close or release the child buffers here too.
2249 vector<Buffer *> clist = buf.getChildren(false);
2250 for (vector<Buffer *>::const_iterator it = clist.begin();
2251 it != clist.end(); ++it) {
2252 // If a child is dirty, do not close
2253 // without user intervention
2254 //FIXME: should we look in other tabworkareas?
2255 Buffer * child_buf = *it;
2256 GuiWorkArea * child_wa = workArea(*child_buf);
2258 if (!closeWorkArea(child_wa, true))
2261 theBufferList().releaseChild(&buf, child_buf);
2264 // goto bookmark to update bookmark pit.
2265 //FIXME: we should update only the bookmarks related to this buffer!
2266 LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
2267 for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
2268 guiApp->gotoBookmark(i+1, false, false);
2270 if (saveBufferIfNeeded(buf, false)) {
2271 theBufferList().release(&buf);
2278 bool GuiView::closeTabWorkArea(TabWorkArea * twa)
2280 while (twa == d.currentTabWorkArea()) {
2281 twa->setCurrentIndex(twa->count()-1);
2283 GuiWorkArea * wa = twa->currentWorkArea();
2284 Buffer & b = wa->bufferView().buffer();
2286 // We only want to close the buffer if the same buffer is not visible
2287 // in another view, and if this is not a child and if we are closing
2288 // a view (not a tabgroup).
2289 bool const close_buffer =
2290 !inMultiViews(wa) && !b.parent() && closing_;
2292 if (!closeWorkArea(wa, close_buffer))
2299 bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
2301 if (buf.isClean() || buf.paragraphs().empty())
2304 // Switch to this Buffer.
2309 if (buf.isUnnamed())
2310 file = from_utf8(buf.fileName().onlyFileName());
2312 file = buf.fileName().displayName(30);
2314 // Bring this window to top before asking questions.
2319 if (hiding && buf.isUnnamed()) {
2320 docstring const text = bformat(_("The document %1$s has not been "
2321 "saved yet.\n\nDo you want to save "
2322 "the document?"), file);
2323 ret = Alert::prompt(_("Save new document?"),
2324 text, 0, 1, _("&Save"), _("&Cancel"));
2328 docstring const text = bformat(_("The document %1$s has unsaved changes."
2329 "\n\nDo you want to save the document or discard the changes?"), file);
2330 ret = Alert::prompt(_("Save changed document?"),
2331 text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
2336 if (!saveBuffer(buf))
2340 // if we crash after this we could
2341 // have no autosave file but I guess
2342 // this is really improbable (Jug)
2343 buf.removeAutosaveFile();
2345 // revert all changes
2356 bool GuiView::inMultiTabs(GuiWorkArea * wa)
2358 Buffer & buf = wa->bufferView().buffer();
2360 for (int i = 0; i != d.splitter_->count(); ++i) {
2361 GuiWorkArea * wa_ = d.tabWorkArea(i)->workArea(buf);
2362 if (wa_ && wa_ != wa)
2365 return inMultiViews(wa);
2369 bool GuiView::inMultiViews(GuiWorkArea * wa)
2371 QList<int> const ids = guiApp->viewIds();
2372 Buffer & buf = wa->bufferView().buffer();
2375 for (int i = 0; i != ids.size() && found_twa <= 1; ++i) {
2379 if (guiApp->view(ids[i]).workArea(buf))
2386 void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
2388 Buffer * const curbuf = documentBufferView()
2389 ? &documentBufferView()->buffer() : 0;
2390 Buffer * nextbuf = curbuf;
2392 if (np == NEXTBUFFER)
2393 nextbuf = theBufferList().next(nextbuf);
2395 nextbuf = theBufferList().previous(nextbuf);
2396 if (nextbuf == curbuf)
2402 if (workArea(*nextbuf))
2409 /// make sure the document is saved
2410 static bool ensureBufferClean(Buffer * buffer)
2412 LASSERT(buffer, return false);
2413 if (buffer->isClean() && !buffer->isUnnamed())
2416 docstring const file = buffer->fileName().displayName(30);
2419 if (!buffer->isUnnamed()) {
2420 text = bformat(_("The document %1$s has unsaved "
2421 "changes.\n\nDo you want to save "
2422 "the document?"), file);
2423 title = _("Save changed document?");
2426 text = bformat(_("The document %1$s has not been "
2427 "saved yet.\n\nDo you want to save "
2428 "the document?"), file);
2429 title = _("Save new document?");
2431 int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
2434 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
2436 return buffer->isClean() && !buffer->isUnnamed();
2440 void GuiView::reloadBuffer()
2442 Buffer * buf = &documentBufferView()->buffer();
2447 void GuiView::checkExternallyModifiedBuffers()
2449 BufferList::iterator bit = theBufferList().begin();
2450 BufferList::iterator const bend = theBufferList().end();
2451 for (; bit != bend; ++bit) {
2452 if ((*bit)->fileName().exists()
2453 && (*bit)->isExternallyModified(Buffer::checksum_method)) {
2454 docstring text = bformat(_("Document \n%1$s\n has been externally modified."
2455 " Reload now? Any local changes will be lost."),
2456 from_utf8((*bit)->absFileName()));
2457 int const ret = Alert::prompt(_("Reload externally changed document?"),
2458 text, 0, 1, _("&Reload"), _("&Cancel"));
2466 //FIXME use a DispatchResult object to transmit messages
2467 void GuiView::dispatchVC(FuncRequest const & cmd)
2469 // message for statusbar
2471 Buffer * buffer = documentBufferView()
2472 ? &(documentBufferView()->buffer()) : 0;
2474 switch (cmd.action) {
2475 case LFUN_VC_REGISTER:
2476 if (!buffer || !ensureBufferClean(buffer))
2478 if (!buffer->lyxvc().inUse()) {
2479 if (buffer->lyxvc().registrer())
2484 case LFUN_VC_CHECK_IN:
2485 if (!buffer || !ensureBufferClean(buffer))
2487 if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
2488 msg = buffer->lyxvc().checkIn();
2494 case LFUN_VC_CHECK_OUT:
2495 if (!buffer || !ensureBufferClean(buffer))
2497 if (buffer->lyxvc().inUse()) {
2498 msg = buffer->lyxvc().checkOut();
2503 case LFUN_VC_LOCKING_TOGGLE:
2504 LASSERT(buffer, return);
2505 if (!ensureBufferClean(buffer) || buffer->isReadonly())
2507 if (buffer->lyxvc().inUse()) {
2508 string res = buffer->lyxvc().lockingToggle();
2510 frontend::Alert::error(_("Revision control error."),
2511 _("Error when setting the locking property."));
2519 case LFUN_VC_REVERT:
2520 LASSERT(buffer, return);
2521 buffer->lyxvc().revert();
2525 case LFUN_VC_UNDO_LAST:
2526 LASSERT(buffer, return);
2527 buffer->lyxvc().undoLast();
2531 case LFUN_VC_REPO_UPDATE:
2532 LASSERT(buffer, return);
2533 if (ensureBufferClean(buffer)) {
2534 msg = buffer->lyxvc().repoUpdate();
2535 checkExternallyModifiedBuffers();
2539 case LFUN_VC_COMMAND: {
2540 string flag = cmd.getArg(0);
2541 if (buffer && contains(flag, 'R') && !ensureBufferClean(buffer))
2544 if (contains(flag, 'M')) {
2545 if (!Alert::askForText(message, _("LyX VC: Log Message")))
2548 string path = cmd.getArg(1);
2549 if (contains(path, "$$p") && buffer)
2550 path = subst(path, "$$p", buffer->filePath());
2551 LYXERR(Debug::LYXVC, "Directory: " << path);
2553 if (!pp.isReadableDirectory()) {
2554 lyxerr << _("Directory is not accessible.") << endl;
2557 support::PathChanger p(pp);
2559 string command = cmd.getArg(2);
2560 if (command.empty())
2563 command = subst(command, "$$i", buffer->absFileName());
2564 command = subst(command, "$$p", buffer->filePath());
2566 command = subst(command, "$$m", to_utf8(message));
2567 LYXERR(Debug::LYXVC, "Command: " << command);
2569 one.startscript(Systemcall::Wait, command);
2573 if (contains(flag, 'I'))
2574 buffer->markDirty();
2575 if (contains(flag, 'R'))
2581 case LFUN_VC_COMPARE: {
2583 string rev1 = cmd.getArg(0);
2587 if (!buffer->lyxvc().prepareFileRevision(rev1, f1))
2590 if (isStrInt(rev1) && convert<int>(rev1) <= 0) {
2591 f2 = buffer->absFileName();
2593 string rev2 = cmd.getArg(1);
2597 if (!buffer->lyxvc().prepareFileRevision(rev2, f2))
2600 // FIXME We need to call comparison feature here
2601 // I'm not sure whether with or without dialog.
2602 // (Gui)Compare::compare(f1, f2);
2611 message(from_utf8(msg));
2615 void GuiView::openChildDocument(string const & fname)
2617 LASSERT(documentBufferView(), return);
2618 Buffer & buffer = documentBufferView()->buffer();
2619 FileName const filename = support::makeAbsPath(fname, buffer.filePath());
2620 documentBufferView()->saveBookmark(false);
2622 bool parsed = false;
2623 if (theBufferList().exists(filename)) {
2624 child = theBufferList().getBuffer(filename);
2626 message(bformat(_("Opening child document %1$s..."),
2627 makeDisplayPath(filename.absFilename())));
2628 child = loadDocument(filename, false);
2634 // Set the parent name of the child document.
2635 // This makes insertion of citations and references in the child work,
2636 // when the target is in the parent or another child document.
2637 child->setParent(&buffer);
2638 child->masterBuffer()->updateLabels();
2641 child->errors("Parse");
2645 bool GuiView::goToFileRow(string const & argument)
2649 size_t i = argument.find_last_of(' ');
2650 if (i != string::npos) {
2651 file_name = os::internal_path(trim(argument.substr(0, i)));
2652 istringstream is(argument.substr(i + 1));
2657 if (i == string::npos) {
2658 LYXERR0("Wrong argument: " << argument);
2662 string const abstmp = package().temp_dir().absFilename();
2663 string const realtmp = package().temp_dir().realPath();
2664 // We have to use os::path_prefix_is() here, instead of
2665 // simply prefixIs(), because the file name comes from
2666 // an external application and may need case adjustment.
2667 if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
2668 || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
2669 // Needed by inverse dvi search. If it is a file
2670 // in tmpdir, call the apropriated function.
2671 // If tmpdir is a symlink, we may have the real
2672 // path passed back, so we correct for that.
2673 if (!prefixIs(file_name, abstmp))
2674 file_name = subst(file_name, realtmp, abstmp);
2675 buf = theBufferList().getBufferFromTmp(file_name);
2677 // Must replace extension of the file to be .lyx
2678 // and get full path
2679 FileName const s = fileSearch(string(),
2680 support::changeExtension(file_name, ".lyx"), "lyx");
2681 // Either change buffer or load the file
2682 if (theBufferList().exists(s))
2683 buf = theBufferList().getBuffer(s);
2684 else if (s.exists()) {
2685 buf = loadDocument(s);
2686 buf->updateLabels();
2687 buf->errors("Parse");
2690 _("File does not exist: %1$s"),
2691 makeDisplayPath(file_name)));
2696 documentBufferView()->setCursorFromRow(row);
2701 #if (QT_VERSION >= 0x040400)
2702 static docstring exportAndDestroy(Buffer * buffer, string const & format)
2704 bool const update_unincluded =
2705 buffer->params().maintain_unincluded_children
2706 && !buffer->params().getIncludedChildren().empty();
2707 bool const success = buffer->doExport(format, true, update_unincluded);
2710 ? bformat(_("Successful export to format: %1$s"), from_utf8(format))
2711 : bformat(_("Error exporting to format: %1$s"), from_utf8(format));
2715 static docstring previewAndDestroy(Buffer * buffer, string const & format)
2717 bool const update_unincluded =
2718 buffer->params().maintain_unincluded_children
2719 && !buffer->params().getIncludedChildren().empty();
2720 bool const success = buffer->preview(format, update_unincluded);
2723 ? bformat(_("Successful preview of format: %1$s"), from_utf8(format))
2724 : bformat(_("Error previewing format: %1$s"), from_utf8(format));
2729 void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
2731 BufferView * bv = currentBufferView();
2732 // By default we won't need any update.
2733 dr.update(Update::None);
2734 // assume cmd will be dispatched
2735 dr.dispatched(true);
2737 Buffer * doc_buffer = documentBufferView()
2738 ? &(documentBufferView()->buffer()) : 0;
2740 if (cmd.origin == FuncRequest::TOC) {
2741 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
2742 // FIXME: do we need to pass a DispatchResult object here?
2743 toc->doDispatch(bv->cursor(), cmd);
2747 string const argument = to_utf8(cmd.argument());
2749 switch(cmd.action) {
2750 case LFUN_BUFFER_CHILD_OPEN:
2751 openChildDocument(to_utf8(cmd.argument()));
2754 case LFUN_BUFFER_IMPORT:
2755 importDocument(to_utf8(cmd.argument()));
2758 case LFUN_BUFFER_EXPORT: {
2761 // GCC only sees strfwd.h when building merged
2762 if (::lyx::operator==(cmd.argument(), "custom")) {
2763 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"),
2767 if (doc_buffer->doExport(argument, false)) {
2769 dr.setMessage(bformat(_("Error exporting to format: %1$s."),
2775 case LFUN_BUFFER_UPDATE: {
2778 string format = argument;
2779 if (argument.empty())
2780 format = doc_buffer->getDefaultOutputFormat();
2781 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2782 d.progress_->clearMessages();
2783 message(_("Exporting ..."));
2784 QFuture<docstring> f = QtConcurrent::run(exportAndDestroy,
2785 doc_buffer->clone(), format);
2786 d.setPreviewFuture(f);
2788 bool const update_unincluded =
2789 doc_buffer->params().maintain_unincluded_children
2790 && !doc_buffer->params().getIncludedChildren().empty();
2791 doc_buffer->doExport(format, true, update_unincluded);
2795 case LFUN_BUFFER_VIEW: {
2798 string format = argument;
2799 if (argument.empty())
2800 format = doc_buffer->getDefaultOutputFormat();
2801 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2802 d.progress_->clearMessages();
2803 message(_("Previewing ..."));
2804 QFuture<docstring> f = QtConcurrent::run(previewAndDestroy,
2805 doc_buffer->clone(), format);
2806 d.setPreviewFuture(f);
2808 bool const update_unincluded =
2809 doc_buffer->params().maintain_unincluded_children
2810 && !doc_buffer->params().getIncludedChildren().empty();
2811 doc_buffer->preview(format, update_unincluded);
2815 case LFUN_MASTER_BUFFER_UPDATE: {
2818 string format = argument;
2819 Buffer const * master = doc_buffer->masterBuffer();
2820 if (argument.empty())
2821 format = master->getDefaultOutputFormat();
2822 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2823 QFuture<docstring> f = QtConcurrent::run(exportAndDestroy,
2824 master->clone(), format);
2825 d.setPreviewFuture(f);
2827 bool const update_unincluded =
2828 master->params().maintain_unincluded_children
2829 && !master->params().getIncludedChildren().empty();
2830 master->doExport(format, true);
2834 case LFUN_MASTER_BUFFER_VIEW: {
2835 string format = argument;
2836 Buffer const * master = doc_buffer->masterBuffer();
2837 if (argument.empty())
2838 format = master->getDefaultOutputFormat();
2839 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2840 QFuture<docstring> f = QtConcurrent::run(previewAndDestroy,
2841 master->clone(), format);
2842 d.setPreviewFuture(f);
2844 master->preview(format);
2848 case LFUN_BUFFER_SWITCH:
2849 if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
2851 theBufferList().getBuffer(FileName(to_utf8(cmd.argument())));
2856 dr.setMessage(_("Document not loaded"));
2861 case LFUN_BUFFER_NEXT:
2862 gotoNextOrPreviousBuffer(NEXTBUFFER);
2865 case LFUN_BUFFER_PREVIOUS:
2866 gotoNextOrPreviousBuffer(PREVBUFFER);
2869 case LFUN_COMMAND_EXECUTE: {
2870 bool const show_it = cmd.argument() != "off";
2871 // FIXME: this is a hack, "minibuffer" should not be
2873 if (GuiToolbar * t = toolbar("minibuffer")) {
2874 t->setVisible(show_it);
2875 if (show_it && t->commandBuffer())
2876 t->commandBuffer()->setFocus();
2880 case LFUN_DROP_LAYOUTS_CHOICE:
2881 d.layout_->showPopup();
2884 case LFUN_MENU_OPEN:
2885 if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument()), *this))
2886 menu->exec(QCursor::pos());
2889 case LFUN_FILE_INSERT:
2890 insertLyXFile(cmd.argument());
2892 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
2893 insertPlaintextFile(cmd.argument(), true);
2896 case LFUN_FILE_INSERT_PLAINTEXT:
2897 insertPlaintextFile(cmd.argument(), false);
2900 case LFUN_BUFFER_RELOAD: {
2901 LASSERT(doc_buffer, break);
2902 docstring const file = makeDisplayPath(doc_buffer->absFileName(), 20);
2903 docstring text = bformat(_("Any changes will be lost. Are you sure "
2904 "you want to revert to the saved version of the document %1$s?"), file);
2905 int const ret = Alert::prompt(_("Revert to saved document?"),
2906 text, 1, 1, _("&Revert"), _("&Cancel"));
2909 doc_buffer->markClean();
2915 case LFUN_BUFFER_WRITE:
2916 LASSERT(doc_buffer, break);
2917 saveBuffer(*doc_buffer);
2920 case LFUN_BUFFER_WRITE_AS:
2921 LASSERT(doc_buffer, break);
2922 renameBuffer(*doc_buffer, cmd.argument());
2925 case LFUN_BUFFER_WRITE_ALL: {
2926 Buffer * first = theBufferList().first();
2929 message(_("Saving all documents..."));
2930 // We cannot use a for loop as the buffer list cycles.
2933 if (!b->isClean()) {
2935 LYXERR(Debug::ACTION, "Saved " << b->absFileName());
2937 b = theBufferList().next(b);
2938 } while (b != first);
2939 dr.setMessage(_("All documents saved."));
2943 case LFUN_BUFFER_CLOSE:
2947 case LFUN_BUFFER_CLOSE_ALL:
2951 case LFUN_TOOLBAR_TOGGLE: {
2952 string const name = cmd.getArg(0);
2953 if (GuiToolbar * t = toolbar(name))
2958 case LFUN_DIALOG_UPDATE: {
2959 string const name = to_utf8(cmd.argument());
2960 if (currentBufferView()) {
2961 Inset * inset = currentBufferView()->editedInset(name);
2962 // Can only update a dialog connected to an existing inset
2965 // FIXME: get rid of this indirection; GuiView ask the inset
2966 // if he is kind enough to update itself...
2967 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
2968 //FIXME: pass DispatchResult here?
2969 inset->dispatch(currentBufferView()->cursor(), fr);
2970 } else if (name == "paragraph") {
2971 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
2972 } else if (name == "prefs" || name == "document") {
2973 updateDialog(name, string());
2978 case LFUN_DIALOG_TOGGLE: {
2979 if (isDialogVisible(cmd.getArg(0)))
2980 dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument()), dr);
2982 dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument()), dr);
2986 case LFUN_DIALOG_DISCONNECT_INSET:
2987 disconnectDialog(to_utf8(cmd.argument()));
2990 case LFUN_DIALOG_HIDE: {
2991 guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
2995 case LFUN_DIALOG_SHOW: {
2996 string const name = cmd.getArg(0);
2997 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
2999 if (name == "character") {
3000 data = freefont2string();
3002 showDialog("character", data);
3003 } else if (name == "latexlog") {
3004 Buffer::LogType type;
3005 string const logfile = doc_buffer->logName(&type);
3007 case Buffer::latexlog:
3010 case Buffer::buildlog:
3014 data += Lexer::quoteString(logfile);
3015 showDialog("log", data);
3016 } else if (name == "vclog") {
3017 string const data = "vc " +
3018 Lexer::quoteString(doc_buffer->lyxvc().getLogFile());
3019 showDialog("log", data);
3020 } else if (name == "symbols") {
3021 data = bv->cursor().getEncoding()->name();
3023 showDialog("symbols", data);
3025 } else if (name == "prefs" && isFullScreen()) {
3026 lfunUiToggle("fullscreen");
3027 showDialog("prefs", data);
3029 showDialog(name, data);
3034 dr.setMessage(cmd.argument());
3037 case LFUN_UI_TOGGLE: {
3038 string arg = cmd.getArg(0);
3039 if (!lfunUiToggle(arg)) {
3040 docstring const msg = "ui-toggle " + _("%1$s unknown command!");
3041 dr.setMessage(bformat(msg, from_utf8(arg)));
3043 // Make sure the keyboard focus stays in the work area.
3048 case LFUN_SPLIT_VIEW: {
3049 LASSERT(doc_buffer, break);
3050 string const orientation = cmd.getArg(0);
3051 d.splitter_->setOrientation(orientation == "vertical"
3052 ? Qt::Vertical : Qt::Horizontal);
3053 TabWorkArea * twa = addTabWorkArea();
3054 GuiWorkArea * wa = twa->addWorkArea(*doc_buffer, *this);
3055 setCurrentWorkArea(wa);
3058 case LFUN_CLOSE_TAB_GROUP:
3059 if (TabWorkArea * twa = d.currentTabWorkArea()) {
3060 closeTabWorkArea(twa);
3061 d.current_work_area_ = 0;
3062 twa = d.currentTabWorkArea();
3063 // Switch to the next GuiWorkArea in the found TabWorkArea.
3065 // Make sure the work area is up to date.
3066 setCurrentWorkArea(twa->currentWorkArea());
3068 setCurrentWorkArea(0);
3073 case LFUN_COMPLETION_INLINE:
3074 if (d.current_work_area_)
3075 d.current_work_area_->completer().showInline();
3078 case LFUN_COMPLETION_POPUP:
3079 if (d.current_work_area_)
3080 d.current_work_area_->completer().showPopup();
3084 case LFUN_COMPLETION_COMPLETE:
3085 if (d.current_work_area_)
3086 d.current_work_area_->completer().tab();
3089 case LFUN_COMPLETION_CANCEL:
3090 if (d.current_work_area_) {
3091 if (d.current_work_area_->completer().popupVisible())
3092 d.current_work_area_->completer().hidePopup();
3094 d.current_work_area_->completer().hideInline();
3098 case LFUN_COMPLETION_ACCEPT:
3099 if (d.current_work_area_)
3100 d.current_work_area_->completer().activate();
3103 case LFUN_BUFFER_ZOOM_IN:
3104 case LFUN_BUFFER_ZOOM_OUT:
3105 if (cmd.argument().empty()) {
3106 if (cmd.action == LFUN_BUFFER_ZOOM_IN)
3111 lyxrc.zoom += convert<int>(cmd.argument());
3113 if (lyxrc.zoom < 10)
3116 // The global QPixmapCache is used in GuiPainter to cache text
3117 // painting so we must reset it.
3118 QPixmapCache::clear();
3119 guiApp->fontLoader().update();
3120 lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3123 case LFUN_VC_REGISTER:
3124 case LFUN_VC_CHECK_IN:
3125 case LFUN_VC_CHECK_OUT:
3126 case LFUN_VC_REPO_UPDATE:
3127 case LFUN_VC_LOCKING_TOGGLE:
3128 case LFUN_VC_REVERT:
3129 case LFUN_VC_UNDO_LAST:
3130 case LFUN_VC_COMMAND:
3131 case LFUN_VC_COMPARE:
3135 case LFUN_SERVER_GOTO_FILE_ROW:
3136 goToFileRow(to_utf8(cmd.argument()));
3140 dr.dispatched(false);
3144 // Part of automatic menu appearance feature.
3145 if (isFullScreen()) {
3146 if (menuBar()->isVisible() && lyxrc.full_screen_menubar)
3148 if (statusBar()->isVisible())
3149 statusBar()->hide();
3156 bool GuiView::lfunUiToggle(string const & ui_component)
3158 if (ui_component == "scrollbar") {
3159 // hide() is of no help
3160 if (d.current_work_area_->verticalScrollBarPolicy() ==
3161 Qt::ScrollBarAlwaysOff)
3163 d.current_work_area_->setVerticalScrollBarPolicy(
3164 Qt::ScrollBarAsNeeded);
3166 d.current_work_area_->setVerticalScrollBarPolicy(
3167 Qt::ScrollBarAlwaysOff);
3168 } else if (ui_component == "statusbar") {
3169 statusBar()->setVisible(!statusBar()->isVisible());
3170 } else if (ui_component == "menubar") {
3171 menuBar()->setVisible(!menuBar()->isVisible());
3173 #if QT_VERSION >= 0x040300
3174 if (ui_component == "frame") {
3176 getContentsMargins(&l, &t, &r, &b);
3177 //are the frames in default state?
3178 d.current_work_area_->setFrameStyle(QFrame::NoFrame);
3180 setContentsMargins(-2, -2, -2, -2);
3182 setContentsMargins(0, 0, 0, 0);
3186 if (ui_component == "fullscreen") {
3194 void GuiView::toggleFullScreen()
3196 if (isFullScreen()) {
3197 for (int i = 0; i != d.splitter_->count(); ++i)
3198 d.tabWorkArea(i)->setFullScreen(false);
3199 #if QT_VERSION >= 0x040300
3200 setContentsMargins(0, 0, 0, 0);
3202 setWindowState(windowState() ^ Qt::WindowFullScreen);
3205 statusBar()->show();
3208 hideDialogs("prefs", 0);
3209 for (int i = 0; i != d.splitter_->count(); ++i)
3210 d.tabWorkArea(i)->setFullScreen(true);
3211 #if QT_VERSION >= 0x040300
3212 setContentsMargins(-2, -2, -2, -2);
3215 setWindowState(windowState() ^ Qt::WindowFullScreen);
3216 statusBar()->hide();
3217 if (lyxrc.full_screen_menubar)
3219 if (lyxrc.full_screen_toolbars) {
3220 ToolbarMap::iterator end = d.toolbars_.end();
3221 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
3226 // give dialogs like the TOC a chance to adapt
3231 Buffer const * GuiView::updateInset(Inset const * inset)
3233 if (!d.current_work_area_)
3237 d.current_work_area_->scheduleRedraw();
3239 return &d.current_work_area_->bufferView().buffer();
3243 void GuiView::restartCursor()
3245 /* When we move around, or type, it's nice to be able to see
3246 * the cursor immediately after the keypress.
3248 if (d.current_work_area_)
3249 d.current_work_area_->startBlinkingCursor();
3251 // Take this occasion to update the other GUI elements.
3257 void GuiView::updateCompletion(Cursor & cur, bool start, bool keep)
3259 if (d.current_work_area_)
3260 d.current_work_area_->completer().updateVisibility(cur, start, keep);
3265 // This list should be kept in sync with the list of insets in
3266 // src/insets/Inset.cpp. I.e., if a dialog goes with an inset, the
3267 // dialog should have the same name as the inset.
3268 // Changes should be also recorded in LFUN_DIALOG_SHOW doxygen
3269 // docs in LyXAction.cpp.
3271 char const * const dialognames[] = {
3272 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
3273 "citation", "compare", "document", "errorlist", "ert", "external", "file",
3274 "findreplace", "findreplaceadv", "float", "graphics", "href", "include",
3275 "index", "index_print", "info", "listings", "label", "log", "mathdelimiter",
3276 "mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note",
3277 "paragraph", "phantom", "prefs", "print", "ref", "sendto", "space",
3278 "spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo",
3279 "toc", "view-source", "vspace", "wrap", "progress"};
3281 char const * const * const end_dialognames =
3282 dialognames + (sizeof(dialognames) / sizeof(char *));
3286 cmpCStr(char const * name) : name_(name) {}
3287 bool operator()(char const * other) {
3288 return strcmp(other, name_) == 0;
3295 bool isValidName(string const & name)
3297 return find_if(dialognames, end_dialognames,
3298 cmpCStr(name.c_str())) != end_dialognames;
3304 void GuiView::resetDialogs()
3306 // Make sure that no LFUN uses any GuiView.
3307 guiApp->setCurrentView(0);
3310 constructToolbars();
3311 guiApp->menus().fillMenuBar(menuBar(), this, false);
3312 d.layout_->updateContents(true);
3313 // Now update controls with current buffer.
3314 guiApp->setCurrentView(this);
3320 Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
3322 if (!isValidName(name))
3325 map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
3327 if (it != d.dialogs_.end()) {
3329 it->second->hideView();
3330 return it->second.get();
3333 Dialog * dialog = build(name);
3334 d.dialogs_[name].reset(dialog);
3335 if (lyxrc.allow_geometry_session)
3336 dialog->restoreSession();
3343 void GuiView::showDialog(string const & name, string const & data,
3346 triggerShowDialog(toqstr(name), toqstr(data), inset);
3350 void GuiView::doShowDialog(QString const & qname, QString const & qdata,
3356 const string name = fromqstr(qname);
3357 const string data = fromqstr(qdata);
3361 Dialog * dialog = findOrBuild(name, false);
3363 dialog->showData(data);
3364 if (inset && currentBufferView())
3365 currentBufferView()->editInset(name, inset);
3368 catch (ExceptionMessage const & ex) {
3376 bool GuiView::isDialogVisible(string const & name) const
3378 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
3379 if (it == d.dialogs_.end())
3381 return it->second.get()->isVisibleView() && !it->second.get()->isClosing();
3385 void GuiView::hideDialog(string const & name, Inset * inset)
3387 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
3388 if (it == d.dialogs_.end())
3391 if (inset && currentBufferView()
3392 && inset != currentBufferView()->editedInset(name))
3395 Dialog * const dialog = it->second.get();
3396 if (dialog->isVisibleView())
3398 if (currentBufferView())
3399 currentBufferView()->editInset(name, 0);
3403 void GuiView::disconnectDialog(string const & name)
3405 if (!isValidName(name))
3407 if (currentBufferView())
3408 currentBufferView()->editInset(name, 0);
3412 void GuiView::hideAll() const
3414 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
3415 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
3417 for(; it != end; ++it)
3418 it->second->hideView();
3422 void GuiView::updateDialogs()
3424 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
3425 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
3427 for(; it != end; ++it) {
3428 Dialog * dialog = it->second.get();
3430 if (dialog->isBufferDependent() && !documentBufferView())
3431 hideDialog(fromqstr(dialog->name()), 0);
3432 else if (dialog->isVisibleView())
3433 dialog->checkStatus();
3440 Dialog * createDialog(GuiView & lv, string const & name);
3442 // will be replaced by a proper factory...
3443 Dialog * createGuiAbout(GuiView & lv);
3444 Dialog * createGuiBibitem(GuiView & lv);
3445 Dialog * createGuiBibtex(GuiView & lv);
3446 Dialog * createGuiChanges(GuiView & lv);
3447 Dialog * createGuiCharacter(GuiView & lv);
3448 Dialog * createGuiCitation(GuiView & lv);
3449 Dialog * createGuiCompare(GuiView & lv);
3450 Dialog * createGuiDelimiter(GuiView & lv);
3451 Dialog * createGuiDocument(GuiView & lv);
3452 Dialog * createGuiErrorList(GuiView & lv);
3453 Dialog * createGuiExternal(GuiView & lv);
3454 Dialog * createGuiGraphics(GuiView & lv);
3455 Dialog * createGuiInclude(GuiView & lv);
3456 Dialog * createGuiIndex(GuiView & lv);
3457 Dialog * createGuiLabel(GuiView & lv);
3458 Dialog * createGuiListings(GuiView & lv);
3459 Dialog * createGuiLog(GuiView & lv);
3460 Dialog * createGuiMathHSpace(GuiView & lv);
3461 Dialog * createGuiMathMatrix(GuiView & lv);
3462 Dialog * createGuiNomenclature(GuiView & lv);
3463 Dialog * createGuiNote(GuiView & lv);
3464 Dialog * createGuiParagraph(GuiView & lv);
3465 Dialog * createGuiPhantom(GuiView & lv);
3466 Dialog * createGuiPreferences(GuiView & lv);
3467 Dialog * createGuiPrint(GuiView & lv);
3468 Dialog * createGuiPrintindex(GuiView & lv);
3469 Dialog * createGuiPrintNomencl(GuiView & lv);
3470 Dialog * createGuiRef(GuiView & lv);
3471 Dialog * createGuiSearch(GuiView & lv);
3472 Dialog * createGuiSearchAdv(GuiView & lv);
3473 Dialog * createGuiSendTo(GuiView & lv);
3474 Dialog * createGuiShowFile(GuiView & lv);
3475 Dialog * createGuiSpellchecker(GuiView & lv);
3476 Dialog * createGuiSymbols(GuiView & lv);
3477 Dialog * createGuiTabularCreate(GuiView & lv);
3478 Dialog * createGuiTexInfo(GuiView & lv);
3479 Dialog * createGuiTextHSpace(GuiView & lv);
3480 Dialog * createGuiToc(GuiView & lv);
3481 Dialog * createGuiThesaurus(GuiView & lv);
3482 Dialog * createGuiHyperlink(GuiView & lv);
3483 Dialog * createGuiViewSource(GuiView & lv);
3484 Dialog * createGuiWrap(GuiView & lv);
3485 Dialog * createGuiProgressView(GuiView & lv);
3489 Dialog * GuiView::build(string const & name)
3491 LASSERT(isValidName(name), return 0);
3493 Dialog * dialog = createDialog(*this, name);
3497 if (name == "aboutlyx")
3498 return createGuiAbout(*this);
3499 if (name == "bibitem")
3500 return createGuiBibitem(*this);
3501 if (name == "bibtex")
3502 return createGuiBibtex(*this);
3503 if (name == "changes")
3504 return createGuiChanges(*this);
3505 if (name == "character")
3506 return createGuiCharacter(*this);
3507 if (name == "citation")
3508 return createGuiCitation(*this);
3509 if (name == "compare")
3510 return createGuiCompare(*this);
3511 if (name == "document")
3512 return createGuiDocument(*this);
3513 if (name == "errorlist")
3514 return createGuiErrorList(*this);
3515 if (name == "external")
3516 return createGuiExternal(*this);
3518 return createGuiShowFile(*this);
3519 if (name == "findreplace")
3520 return createGuiSearch(*this);
3521 if (name == "findreplaceadv")
3522 return createGuiSearchAdv(*this);
3523 if (name == "graphics")
3524 return createGuiGraphics(*this);
3526 return createGuiHyperlink(*this);
3527 if (name == "include")
3528 return createGuiInclude(*this);
3529 if (name == "index")
3530 return createGuiIndex(*this);
3531 if (name == "index_print")
3532 return createGuiPrintindex(*this);
3533 if (name == "label")
3534 return createGuiLabel(*this);
3535 if (name == "listings")
3536 return createGuiListings(*this);
3538 return createGuiLog(*this);
3539 if (name == "mathdelimiter")
3540 return createGuiDelimiter(*this);
3541 if (name == "mathspace")
3542 return createGuiMathHSpace(*this);
3543 if (name == "mathmatrix")
3544 return createGuiMathMatrix(*this);
3545 if (name == "nomenclature")
3546 return createGuiNomenclature(*this);
3547 if (name == "nomencl_print")
3548 return createGuiPrintNomencl(*this);
3550 return createGuiNote(*this);
3551 if (name == "paragraph")
3552 return createGuiParagraph(*this);
3553 if (name == "phantom")
3554 return createGuiPhantom(*this);
3555 if (name == "prefs")
3556 return createGuiPreferences(*this);
3557 if (name == "print")
3558 return createGuiPrint(*this);
3560 return createGuiRef(*this);
3561 if (name == "sendto")
3562 return createGuiSendTo(*this);
3563 if (name == "space")
3564 return createGuiTextHSpace(*this);
3565 if (name == "spellchecker")
3566 return createGuiSpellchecker(*this);
3567 if (name == "symbols")
3568 return createGuiSymbols(*this);
3569 if (name == "tabularcreate")
3570 return createGuiTabularCreate(*this);
3571 if (name == "texinfo")
3572 return createGuiTexInfo(*this);
3573 if (name == "thesaurus")
3574 return createGuiThesaurus(*this);
3576 return createGuiToc(*this);
3577 if (name == "view-source")
3578 return createGuiViewSource(*this);
3580 return createGuiWrap(*this);
3581 if (name == "progress")
3582 return createGuiProgressView(*this);
3588 } // namespace frontend
3591 #include "moc_GuiView.cpp"