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"
43 #include "Converter.h"
45 #include "CutAndPaste.h"
47 #include "ErrorList.h"
49 #include "FuncStatus.h"
50 #include "FuncRequest.h"
54 #include "LyXAction.h"
58 #include "Paragraph.h"
59 #include "SpellChecker.h"
60 #include "TextClass.h"
65 #include "support/convert.h"
66 #include "support/debug.h"
67 #include "support/ExceptionMessage.h"
68 #include "support/FileName.h"
69 #include "support/filetools.h"
70 #include "support/gettext.h"
71 #include "support/filetools.h"
72 #include "support/ForkedCalls.h"
73 #include "support/lassert.h"
74 #include "support/lstrings.h"
75 #include "support/os.h"
76 #include "support/Package.h"
77 #include "support/Path.h"
78 #include "support/Systemcall.h"
79 #include "support/Timeout.h"
80 #include "support/ProgressInterface.h"
81 #include "GuiProgress.h"
84 #include <QApplication>
85 #include <QCloseEvent>
87 #include <QDesktopWidget>
88 #include <QDragEnterEvent>
95 #include <QPixmapCache>
97 #include <QPushButton>
101 #include <QStackedWidget>
102 #include <QStatusBar>
108 #include <QScrollBar>
110 #define EXPORT_in_THREAD 1
112 struct Sleep : QThread
114 static void millisec(unsigned long ms)
116 QThread::usleep(ms * 1000);
121 // QtConcurrent was introduced in Qt 4.4
122 #if (QT_VERSION >= 0x040400)
124 #include <QFutureWatcher>
125 #include <QtConcurrentRun>
128 #include <boost/bind.hpp>
132 #ifdef HAVE_SYS_TIME_H
133 # include <sys/time.h>
140 using namespace lyx::support;
147 class BackgroundWidget : public QWidget
152 LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
153 /// The text to be written on top of the pixmap
154 QString const text = lyx_version ?
155 qt_("version ") + lyx_version : qt_("unknown version");
156 splash_ = getPixmap("images/", "banner", "png");
158 QPainter pain(&splash_);
159 pain.setPen(QColor(0, 0, 0));
161 // The font used to display the version info
162 font.setStyleHint(QFont::SansSerif);
163 font.setWeight(QFont::Bold);
164 font.setPointSize(int(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble()));
166 pain.drawText(260, 15, text);
167 setFocusPolicy(Qt::StrongFocus);
170 void paintEvent(QPaintEvent *)
172 int x = (width() - splash_.width()) / 2;
173 int y = (height() - splash_.height()) / 2;
175 pain.drawPixmap(x, y, splash_);
178 void keyPressEvent(QKeyEvent * ev)
181 setKeySymbol(&sym, ev);
183 guiApp->processKeySym(sym, q_key_state(ev->modifiers()));
195 /// Toolbar store providing access to individual toolbars by name.
196 typedef map<string, GuiToolbar *> ToolbarMap;
198 typedef boost::shared_ptr<Dialog> DialogPtr;
203 struct GuiView::GuiViewPrivate
205 GuiViewPrivate(GuiView * gv)
206 : gv_(gv), current_work_area_(0), current_main_work_area_(0),
207 layout_(0), autosave_timeout_(5000),
210 // hardcode here the platform specific icon size
211 smallIconSize = 14; // scaling problems
212 normalIconSize = 20; // ok, default
213 bigIconSize = 26; // better for some math icons
215 splitter_ = new QSplitter;
216 bg_widget_ = new BackgroundWidget;
217 stack_widget_ = new QStackedWidget;
218 stack_widget_->addWidget(bg_widget_);
219 stack_widget_->addWidget(splitter_);
221 progress_ = new GuiProgress(gv);
228 delete stack_widget_;
232 QMenu * toolBarPopup(GuiView * parent)
234 // FIXME: translation
235 QMenu * menu = new QMenu(parent);
236 QActionGroup * iconSizeGroup = new QActionGroup(parent);
238 QAction * smallIcons = new QAction(iconSizeGroup);
239 smallIcons->setText(qt_("Small-sized icons"));
240 smallIcons->setCheckable(true);
241 QObject::connect(smallIcons, SIGNAL(triggered()),
242 parent, SLOT(smallSizedIcons()));
243 menu->addAction(smallIcons);
245 QAction * normalIcons = new QAction(iconSizeGroup);
246 normalIcons->setText(qt_("Normal-sized icons"));
247 normalIcons->setCheckable(true);
248 QObject::connect(normalIcons, SIGNAL(triggered()),
249 parent, SLOT(normalSizedIcons()));
250 menu->addAction(normalIcons);
252 QAction * bigIcons = new QAction(iconSizeGroup);
253 bigIcons->setText(qt_("Big-sized icons"));
254 bigIcons->setCheckable(true);
255 QObject::connect(bigIcons, SIGNAL(triggered()),
256 parent, SLOT(bigSizedIcons()));
257 menu->addAction(bigIcons);
259 unsigned int cur = parent->iconSize().width();
260 if ( cur == parent->d.smallIconSize)
261 smallIcons->setChecked(true);
262 else if (cur == parent->d.normalIconSize)
263 normalIcons->setChecked(true);
264 else if (cur == parent->d.bigIconSize)
265 bigIcons->setChecked(true);
272 stack_widget_->setCurrentWidget(bg_widget_);
273 bg_widget_->setUpdatesEnabled(true);
274 bg_widget_->setFocus();
277 TabWorkArea * tabWorkArea(int i)
279 return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
282 TabWorkArea * currentTabWorkArea()
284 if (splitter_->count() == 1)
285 // The first TabWorkArea is always the first one, if any.
286 return tabWorkArea(0);
288 for (int i = 0; i != splitter_->count(); ++i) {
289 TabWorkArea * twa = tabWorkArea(i);
290 if (current_main_work_area_ == twa->currentWorkArea())
294 // None has the focus so we just take the first one.
295 return tabWorkArea(0);
298 #if (QT_VERSION >= 0x040400)
299 void setPreviewFuture(QFuture<docstring> const & f)
301 if (preview_watcher_.isRunning()) {
302 // we prefer to cancel this preview in order to keep a snappy
306 preview_watcher_.setFuture(f);
312 GuiWorkArea * current_work_area_;
313 GuiWorkArea * current_main_work_area_;
314 QSplitter * splitter_;
315 QStackedWidget * stack_widget_;
316 BackgroundWidget * bg_widget_;
318 ToolbarMap toolbars_;
319 ProgressInterface* progress_;
320 /// The main layout box.
322 * \warning Don't Delete! The layout box is actually owned by
323 * whichever toolbar contains it. All the GuiView class needs is a
324 * means of accessing it.
326 * FIXME: replace that with a proper model so that we are not limited
327 * to only one dialog.
332 map<string, DialogPtr> dialogs_;
334 unsigned int smallIconSize;
335 unsigned int normalIconSize;
336 unsigned int bigIconSize;
338 QTimer statusbar_timer_;
339 /// auto-saving of buffers
340 Timeout autosave_timeout_;
341 /// flag against a race condition due to multiclicks, see bug #1119
345 TocModels toc_models_;
347 #if (QT_VERSION >= 0x040400)
349 QFutureWatcher<docstring> autosave_watcher_;
350 QFutureWatcher<docstring> preview_watcher_;
352 struct DummyWatcher { bool isRunning(){return false;} };
353 DummyWatcher preview_watcher_;
358 GuiView::GuiView(int id)
359 : d(*new GuiViewPrivate(this)), id_(id), closing_(false)
361 // GuiToolbars *must* be initialised before the menu bar.
362 normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
365 // set ourself as the current view. This is needed for the menu bar
366 // filling, at least for the static special menu item on Mac. Otherwise
367 // they are greyed out.
368 guiApp->setCurrentView(this);
370 // Fill up the menu bar.
371 guiApp->menus().fillMenuBar(menuBar(), this, true);
373 setCentralWidget(d.stack_widget_);
375 // Start autosave timer
376 if (lyxrc.autosave) {
377 d.autosave_timeout_.timeout.connect(boost::bind(&GuiView::autoSave, this));
378 d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
379 d.autosave_timeout_.start();
381 connect(&d.statusbar_timer_, SIGNAL(timeout()),
382 this, SLOT(clearMessage()));
384 // We don't want to keep the window in memory if it is closed.
385 setAttribute(Qt::WA_DeleteOnClose, true);
387 #if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX))
388 // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
389 // since the icon is provided in the application bundle.
390 setWindowIcon(getPixmap("images/", "lyx", "png"));
393 #if (QT_VERSION >= 0x040300)
394 // use tabbed dock area for multiple docks
395 // (such as "source" and "messages")
396 setDockOptions(QMainWindow::ForceTabbedDocks);
400 setAcceptDrops(true);
402 statusBar()->setSizeGripEnabled(true);
405 #if (QT_VERSION >= 0x040400)
406 connect(&d.autosave_watcher_, SIGNAL(finished()), this,
407 SLOT(threadFinished()));
408 connect(&d.preview_watcher_, SIGNAL(finished()), this,
409 SLOT(threadFinished()));
412 connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)),
413 SLOT(doShowDialog(QString const &, QString const &, Inset *)));
415 // Forbid too small unresizable window because it can happen
416 // with some window manager under X11.
417 setMinimumSize(300, 200);
419 if (lyxrc.allow_geometry_session) {
420 // Now take care of session management.
425 // no session handling, default to a sane size.
426 setGeometry(50, 50, 690, 510);
429 // clear session data if any.
431 settings.remove("views");
441 void GuiView::threadFinished()
443 #if (QT_VERSION >= 0x040400)
444 QFutureWatcher<docstring> const * watcher =
445 static_cast<QFutureWatcher<docstring> const *>(sender());
446 message(watcher->result());
451 void GuiView::saveLayout() const
454 settings.beginGroup("views");
455 settings.beginGroup(QString::number(id_));
457 settings.setValue("pos", pos());
458 settings.setValue("size", size());
460 settings.setValue("geometry", saveGeometry());
462 settings.setValue("layout", saveState(0));
463 settings.setValue("icon_size", iconSize());
467 bool GuiView::restoreLayout()
470 settings.beginGroup("views");
471 settings.beginGroup(QString::number(id_));
472 QString const icon_key = "icon_size";
473 if (!settings.contains(icon_key))
476 //code below is skipped when when ~/.config/LyX is (re)created
477 setIconSize(settings.value(icon_key).toSize());
479 QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
480 QSize size = settings.value("size", QSize(690, 510)).toSize();
484 // Work-around for bug #6034: the window ends up in an undetermined
485 // state when trying to restore a maximized window when it is
486 // already maximized.
487 if (!(windowState() & Qt::WindowMaximized))
488 if (!restoreGeometry(settings.value("geometry").toByteArray()))
489 setGeometry(50, 50, 690, 510);
491 // Make sure layout is correctly oriented.
492 setLayoutDirection(qApp->layoutDirection());
494 // Allow the toc and view-source dock widget to be restored if needed.
496 if ((dialog = findOrBuild("toc", true)))
497 // see bug 5082. At least setup title and enabled state.
498 // Visibility will be adjusted by restoreState below.
499 dialog->prepareView();
500 if ((dialog = findOrBuild("view-source", true)))
501 dialog->prepareView();
502 if ((dialog = findOrBuild("progress", true)))
503 dialog->prepareView();
505 if (!restoreState(settings.value("layout").toByteArray(), 0))
512 GuiToolbar * GuiView::toolbar(string const & name)
514 ToolbarMap::iterator it = d.toolbars_.find(name);
515 if (it != d.toolbars_.end())
518 LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
523 void GuiView::constructToolbars()
525 ToolbarMap::iterator it = d.toolbars_.begin();
526 for (; it != d.toolbars_.end(); ++it)
530 // I don't like doing this here, but the standard toolbar
531 // destroys this object when it's destroyed itself (vfr)
532 d.layout_ = new LayoutBox(*this);
533 d.stack_widget_->addWidget(d.layout_);
534 d.layout_->move(0,0);
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 d.toolbars_[cit->name] = new GuiToolbar(*cit, *this);
544 void GuiView::initToolbars()
546 // extracts the toolbars from the backend
547 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
548 Toolbars::Infos::iterator end = guiApp->toolbars().end();
549 for (; cit != end; ++cit) {
550 GuiToolbar * tb = toolbar(cit->name);
553 int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
554 bool newline = !(visibility & Toolbars::SAMEROW);
555 tb->setVisible(false);
556 tb->setVisibility(visibility);
558 if (visibility & Toolbars::TOP) {
560 addToolBarBreak(Qt::TopToolBarArea);
561 addToolBar(Qt::TopToolBarArea, tb);
564 if (visibility & Toolbars::BOTTOM) {
565 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
566 #if (QT_VERSION >= 0x040202)
568 addToolBarBreak(Qt::BottomToolBarArea);
570 addToolBar(Qt::BottomToolBarArea, tb);
573 if (visibility & Toolbars::LEFT) {
574 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
575 #if (QT_VERSION >= 0x040202)
577 addToolBarBreak(Qt::LeftToolBarArea);
579 addToolBar(Qt::LeftToolBarArea, tb);
582 if (visibility & Toolbars::RIGHT) {
583 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
584 #if (QT_VERSION >= 0x040202)
586 addToolBarBreak(Qt::RightToolBarArea);
588 addToolBar(Qt::RightToolBarArea, tb);
591 if (visibility & Toolbars::ON)
592 tb->setVisible(true);
597 TocModels & GuiView::tocModels()
599 return d.toc_models_;
603 void GuiView::setFocus()
605 LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this);
606 QMainWindow::setFocus();
610 void GuiView::focusInEvent(QFocusEvent * e)
612 LYXERR(Debug::DEBUG, "GuiView::focusInEvent()" << this);
613 QMainWindow::focusInEvent(e);
614 // Make sure guiApp points to the correct view.
615 guiApp->setCurrentView(this);
616 if (currentMainWorkArea())
617 currentMainWorkArea()->setFocus();
618 else if (currentWorkArea())
619 currentWorkArea()->setFocus();
621 d.bg_widget_->setFocus();
625 QMenu * GuiView::createPopupMenu()
627 return d.toolBarPopup(this);
631 void GuiView::showEvent(QShowEvent * e)
633 LYXERR(Debug::GUI, "Passed Geometry "
634 << size().height() << "x" << size().width()
635 << "+" << pos().x() << "+" << pos().y());
637 if (d.splitter_->count() == 0)
638 // No work area, switch to the background widget.
641 QMainWindow::showEvent(e);
645 /** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
646 ** is responsibility of the container (e.g., dialog)
648 void GuiView::closeEvent(QCloseEvent * close_event)
650 LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
655 // it can happen that this event arrives without selecting the view,
656 // e.g. when clicking the close button on a background window.
658 if (!closeWorkAreaAll()) {
660 close_event->ignore();
664 // Make sure that nothing will use this to be closed View.
665 guiApp->unregisterView(this);
667 if (isFullScreen()) {
668 // Switch off fullscreen before closing.
673 // Make sure the timer time out will not trigger a statusbar update.
674 d.statusbar_timer_.stop();
676 // Saving fullscreen requires additional tweaks in the toolbar code.
677 // It wouldn't also work under linux natively.
678 if (lyxrc.allow_geometry_session) {
679 // Save this window geometry and layout.
681 // Then the toolbar private states.
682 ToolbarMap::iterator end = d.toolbars_.end();
683 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
684 it->second->saveSession();
685 // Now take care of all other dialogs:
686 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
687 for (; it!= d.dialogs_.end(); ++it)
688 it->second->saveSession();
691 close_event->accept();
695 void GuiView::dragEnterEvent(QDragEnterEvent * event)
697 if (event->mimeData()->hasUrls())
699 /// \todo Ask lyx-devel is this is enough:
700 /// if (event->mimeData()->hasFormat("text/plain"))
701 /// event->acceptProposedAction();
705 void GuiView::dropEvent(QDropEvent * event)
707 QList<QUrl> files = event->mimeData()->urls();
711 LYXERR(Debug::GUI, "GuiView::dropEvent: got URLs!");
712 for (int i = 0; i != files.size(); ++i) {
713 string const file = os::internal_path(fromqstr(
714 files.at(i).toLocalFile()));
718 string const ext = support::getExtension(file);
719 vector<const Format *> found_formats;
721 // Find all formats that have the correct extension.
722 vector<const Format *> const & import_formats
723 = theConverters().importableFormats();
724 vector<const Format *>::const_iterator it = import_formats.begin();
725 for (; it != import_formats.end(); ++it)
726 if ((*it)->extension() == ext)
727 found_formats.push_back(*it);
730 if (found_formats.size() >= 1) {
731 if (found_formats.size() > 1) {
732 //FIXME: show a dialog to choose the correct importable format
734 "Multiple importable formats found, selecting first");
736 string const arg = found_formats[0]->name() + " " + file;
737 cmd = FuncRequest(LFUN_BUFFER_IMPORT, arg);
740 //FIXME: do we have to explicitly check whether it's a lyx file?
742 "No formats found, trying to open it as a lyx file");
743 cmd = FuncRequest(LFUN_FILE_OPEN, file);
746 // Asynchronously post the event. DropEvent usually comes
747 // from the BufferView. But reloading a file might close
748 // the BufferView from within its own event handler.
749 guiApp->dispatchDelayed(cmd);
755 void GuiView::message(docstring const & str)
757 if (ForkedProcess::iAmAChild())
760 // call is moved to GUI-thread by GuiProgress
761 d.progress_->appendMessage(toqstr(str));
765 void GuiView::updateMessage(QString const & str)
767 statusBar()->showMessage(str);
768 d.statusbar_timer_.stop();
769 d.statusbar_timer_.start(3000);
773 void GuiView::smallSizedIcons()
775 setIconSize(QSize(d.smallIconSize, d.smallIconSize));
779 void GuiView::normalSizedIcons()
781 setIconSize(QSize(d.normalIconSize, d.normalIconSize));
785 void GuiView::bigSizedIcons()
787 setIconSize(QSize(d.bigIconSize, d.bigIconSize));
791 void GuiView::clearMessage()
793 // FIXME: This code was introduced in r19643 to fix bug #4123. However,
794 // the hasFocus function mostly returns false, even if the focus is on
795 // a workarea in this view.
799 d.statusbar_timer_.stop();
803 void GuiView::updateWindowTitle(GuiWorkArea * wa)
805 if (wa != d.current_work_area_
806 || wa->bufferView().buffer().isInternal())
808 setWindowTitle(qt_("LyX: ") + wa->windowTitle());
809 setWindowIconText(wa->windowIconText());
813 void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
816 disconnectBufferView();
817 connectBufferView(wa->bufferView());
818 connectBuffer(wa->bufferView().buffer());
819 d.current_work_area_ = wa;
820 QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
821 this, SLOT(updateWindowTitle(GuiWorkArea *)));
822 updateWindowTitle(wa);
826 // The document settings needs to be reinitialised.
827 updateDialog("document", "");
829 // Buffer-dependent dialogs must be updated. This is done here because
830 // some dialogs require buffer()->text.
835 void GuiView::on_lastWorkAreaRemoved()
838 // We already are in a close event. Nothing more to do.
841 if (d.splitter_->count() > 1)
842 // We have a splitter so don't close anything.
845 // Reset and updates the dialogs.
846 d.toc_models_.reset(0);
847 updateDialog("document", "");
850 resetWindowTitleAndIconText();
853 if (lyxrc.open_buffers_in_tabs)
854 // Nothing more to do, the window should stay open.
857 if (guiApp->viewIds().size() > 1) {
863 // On Mac we also close the last window because the application stay
864 // resident in memory. On other platforms we don't close the last
865 // window because this would quit the application.
871 void GuiView::updateStatusBar()
873 // let the user see the explicit message
874 if (d.statusbar_timer_.isActive())
881 void GuiView::showMessage()
883 QString msg = toqstr(theGuiApp()->viewStatusMessage());
885 BufferView const * bv = currentBufferView();
887 msg = toqstr(bv->cursor().currentState());
889 msg = qt_("Welcome to LyX!");
891 statusBar()->showMessage(msg);
895 bool GuiView::event(QEvent * e)
899 // Useful debug code:
900 //case QEvent::ActivationChange:
901 //case QEvent::WindowDeactivate:
902 //case QEvent::Paint:
903 //case QEvent::Enter:
904 //case QEvent::Leave:
905 //case QEvent::HoverEnter:
906 //case QEvent::HoverLeave:
907 //case QEvent::HoverMove:
908 //case QEvent::StatusTip:
909 //case QEvent::DragEnter:
910 //case QEvent::DragLeave:
914 case QEvent::WindowActivate: {
915 GuiView * old_view = guiApp->currentView();
916 if (this == old_view) {
918 return QMainWindow::event(e);
920 if (old_view && old_view->currentBufferView()) {
921 // save current selection to the selection buffer to allow
922 // middle-button paste in this window.
923 cap::saveSelection(old_view->currentBufferView()->cursor());
925 guiApp->setCurrentView(this);
926 if (d.current_work_area_) {
927 BufferView & bv = d.current_work_area_->bufferView();
928 connectBufferView(bv);
929 connectBuffer(bv.buffer());
930 // The document structure, name and dialogs might have
931 // changed in another view.
933 // The document settings needs to be reinitialised.
934 updateDialog("document", "");
937 resetWindowTitleAndIconText();
940 return QMainWindow::event(e);
943 case QEvent::ShortcutOverride: {
946 #if (!defined Q_WS_X11) || (QT_VERSION >= 0x040500)
947 if (isFullScreen() && menuBar()->isHidden()) {
948 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
949 // FIXME: we should also try to detect special LyX shortcut such as
950 // Alt-P and Alt-M. Right now there is a hack in
951 // GuiWorkArea::processKeySym() that hides again the menubar for
953 if (ke->modifiers() & Qt::AltModifier && ke->key() != Qt::Key_Alt) {
955 return QMainWindow::event(e);
959 return QMainWindow::event(e);
963 return QMainWindow::event(e);
967 void GuiView::resetWindowTitleAndIconText()
969 setWindowTitle(qt_("LyX"));
970 setWindowIconText(qt_("LyX"));
973 bool GuiView::focusNextPrevChild(bool /*next*/)
980 void GuiView::setBusy(bool busy)
982 if (d.current_work_area_) {
983 d.current_work_area_->setUpdatesEnabled(!busy);
985 d.current_work_area_->stopBlinkingCursor();
987 d.current_work_area_->startBlinkingCursor();
991 QApplication::setOverrideCursor(Qt::WaitCursor);
993 QApplication::restoreOverrideCursor();
997 GuiWorkArea * GuiView::workArea(Buffer & buffer)
999 if (currentWorkArea()
1000 && ¤tWorkArea()->bufferView().buffer() == &buffer)
1001 return (GuiWorkArea *) currentWorkArea();
1002 if (TabWorkArea * twa = d.currentTabWorkArea())
1003 return twa->workArea(buffer);
1008 GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
1010 // Automatically create a TabWorkArea if there are none yet.
1011 TabWorkArea * tab_widget = d.splitter_->count()
1012 ? d.currentTabWorkArea() : addTabWorkArea();
1013 return tab_widget->addWorkArea(buffer, *this);
1017 TabWorkArea * GuiView::addTabWorkArea()
1019 TabWorkArea * twa = new TabWorkArea;
1020 QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
1021 this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
1022 QObject::connect(twa, SIGNAL(lastWorkAreaRemoved()),
1023 this, SLOT(on_lastWorkAreaRemoved()));
1025 d.splitter_->addWidget(twa);
1026 d.stack_widget_->setCurrentWidget(d.splitter_);
1031 GuiWorkArea const * GuiView::currentWorkArea() const
1033 return d.current_work_area_;
1037 GuiWorkArea * GuiView::currentWorkArea()
1039 return d.current_work_area_;
1043 GuiWorkArea const * GuiView::currentMainWorkArea() const
1045 if (d.currentTabWorkArea() == NULL)
1047 return d.currentTabWorkArea()->currentWorkArea();
1051 GuiWorkArea * GuiView::currentMainWorkArea()
1053 if (d.currentTabWorkArea() == NULL)
1055 return d.currentTabWorkArea()->currentWorkArea();
1059 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
1061 LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
1063 d.current_work_area_ = NULL;
1067 GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
1071 if (currentBufferView())
1072 cap::saveSelection(currentBufferView()->cursor());
1074 theGuiApp()->setCurrentView(this);
1075 d.current_work_area_ = wa;
1076 for (int i = 0; i != d.splitter_->count(); ++i) {
1077 if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
1078 //if (d.current_main_work_area_)
1079 // d.current_main_work_area_->setFrameStyle(QFrame::NoFrame);
1080 d.current_main_work_area_ = wa;
1081 //d.current_main_work_area_->setFrameStyle(QFrame::Box | QFrame::Plain);
1082 //d.current_main_work_area_->setLineWidth(2);
1083 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
1087 LYXERR(Debug::DEBUG, "This is not a tabbed wa");
1088 on_currentWorkAreaChanged(wa);
1089 BufferView & bv = wa->bufferView();
1090 bv.cursor().fixIfBroken();
1092 wa->setUpdatesEnabled(true);
1093 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
1097 void GuiView::removeWorkArea(GuiWorkArea * wa)
1099 LASSERT(wa, return);
1100 if (wa == d.current_work_area_) {
1102 disconnectBufferView();
1103 d.current_work_area_ = 0;
1104 d.current_main_work_area_ = 0;
1107 bool found_twa = false;
1108 for (int i = 0; i != d.splitter_->count(); ++i) {
1109 TabWorkArea * twa = d.tabWorkArea(i);
1110 if (twa->removeWorkArea(wa)) {
1111 // Found in this tab group, and deleted the GuiWorkArea.
1113 if (twa->count() != 0) {
1114 if (d.current_work_area_ == 0)
1115 // This means that we are closing the current GuiWorkArea, so
1116 // switch to the next GuiWorkArea in the found TabWorkArea.
1117 setCurrentWorkArea(twa->currentWorkArea());
1119 // No more WorkAreas in this tab group, so delete it.
1126 // It is not a tabbed work area (i.e., the search work area), so it
1127 // should be deleted by other means.
1128 LASSERT(found_twa, /* */);
1130 if (d.current_work_area_ == 0) {
1131 if (d.splitter_->count() != 0) {
1132 TabWorkArea * twa = d.currentTabWorkArea();
1133 setCurrentWorkArea(twa->currentWorkArea());
1135 // No more work areas, switch to the background widget.
1136 setCurrentWorkArea(0);
1142 LayoutBox * GuiView::getLayoutDialog() const
1148 void GuiView::updateLayoutList()
1151 d.layout_->updateContents(false);
1155 void GuiView::updateToolbars()
1157 ToolbarMap::iterator end = d.toolbars_.end();
1158 if (d.current_work_area_) {
1160 d.current_work_area_->bufferView().cursor().inMathed();
1162 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
1164 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
1165 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
1166 bool const mathmacrotemplate =
1167 lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
1169 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1170 it->second->update(math, table, review, mathmacrotemplate);
1172 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1173 it->second->update(false, false, false, false);
1177 void GuiView::setBuffer(Buffer * newBuffer)
1179 LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << endl);
1180 LASSERT(newBuffer, return);
1183 GuiWorkArea * wa = workArea(*newBuffer);
1185 newBuffer->masterBuffer()->updateLabels();
1186 wa = addWorkArea(*newBuffer);
1188 //Disconnect the old buffer...there's no new one.
1191 connectBuffer(*newBuffer);
1192 connectBufferView(wa->bufferView());
1193 setCurrentWorkArea(wa);
1199 void GuiView::connectBuffer(Buffer & buf)
1201 buf.setGuiDelegate(this);
1205 void GuiView::disconnectBuffer()
1207 if (d.current_work_area_)
1208 d.current_work_area_->bufferView().buffer().setGuiDelegate(0);
1212 void GuiView::connectBufferView(BufferView & bv)
1214 bv.setGuiDelegate(this);
1218 void GuiView::disconnectBufferView()
1220 if (d.current_work_area_)
1221 d.current_work_area_->bufferView().setGuiDelegate(0);
1225 void GuiView::errors(string const & error_type, bool from_master)
1227 ErrorList & el = from_master ?
1228 documentBufferView()->buffer().masterBuffer()->errorList(error_type)
1229 : documentBufferView()->buffer().errorList(error_type);
1230 string data = error_type;
1232 data = "from_master|" + error_type;
1234 showDialog("errorlist", data);
1238 void GuiView::updateTocItem(string const & type, DocIterator const & dit)
1240 d.toc_models_.updateItem(toqstr(type), dit);
1244 void GuiView::structureChanged()
1246 d.toc_models_.reset(documentBufferView());
1247 // Navigator needs more than a simple update in this case. It needs to be
1249 updateDialog("toc", "");
1253 void GuiView::updateDialog(string const & name, string const & data)
1255 if (!isDialogVisible(name))
1258 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
1259 if (it == d.dialogs_.end())
1262 Dialog * const dialog = it->second.get();
1263 if (dialog->isVisibleView())
1264 dialog->initialiseParams(data);
1268 BufferView * GuiView::documentBufferView()
1270 return currentMainWorkArea()
1271 ? ¤tMainWorkArea()->bufferView()
1276 BufferView const * GuiView::documentBufferView() const
1278 return currentMainWorkArea()
1279 ? ¤tMainWorkArea()->bufferView()
1284 BufferView * GuiView::currentBufferView()
1286 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1290 BufferView const * GuiView::currentBufferView() const
1292 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1296 #if (QT_VERSION >= 0x040400)
1297 static docstring saveAndDestroyBuffer(Buffer * buffer, FileName const & fname)
1300 FileName const tmp_ret = FileName::tempName("lyxauto");
1301 if (!tmp_ret.empty()) {
1302 if (buffer->writeFile(tmp_ret))
1303 failed = !tmp_ret.moveTo(fname);
1306 // failed to write/rename tmp_ret so try writing direct
1307 failed = buffer->writeFile(fname);
1311 ? _("Automatic save failed!")
1312 : _("Automatic save done.");
1317 void GuiView::autoSave()
1319 LYXERR(Debug::INFO, "Running autoSave()");
1321 Buffer * buffer = documentBufferView()
1322 ? &documentBufferView()->buffer() : 0;
1326 #if (QT_VERSION >= 0x040400)
1327 QFuture<docstring> f = QtConcurrent::run(saveAndDestroyBuffer, buffer->clone(),
1328 buffer->getAutosaveFilename());
1329 d.autosave_watcher_.setFuture(f);
1336 void GuiView::resetAutosaveTimers()
1339 d.autosave_timeout_.restart();
1343 bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
1346 Buffer * buf = currentBufferView()
1347 ? ¤tBufferView()->buffer() : 0;
1348 Buffer * doc_buffer = documentBufferView()
1349 ? &(documentBufferView()->buffer()) : 0;
1351 // Check whether we need a buffer
1352 if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
1353 // no, exit directly
1354 flag.message(from_utf8(N_("Command not allowed with"
1355 "out any document open")));
1356 flag.setEnabled(false);
1360 if (cmd.origin == FuncRequest::TOC) {
1361 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
1363 if (toc->getStatus(documentBufferView()->cursor(), cmd, fs))
1366 flag.setEnabled(false);
1370 switch(cmd.action) {
1371 case LFUN_BUFFER_IMPORT:
1374 case LFUN_MASTER_BUFFER_UPDATE:
1375 case LFUN_MASTER_BUFFER_VIEW:
1376 enable = doc_buffer && doc_buffer->parent() != 0
1377 && !d.preview_watcher_.isRunning();
1380 case LFUN_BUFFER_UPDATE:
1381 case LFUN_BUFFER_VIEW: {
1382 if (!doc_buffer || d.preview_watcher_.isRunning()) {
1386 string format = to_utf8(cmd.argument());
1387 if (cmd.argument().empty())
1388 format = doc_buffer->getDefaultOutputFormat();
1389 enable = doc_buffer->isExportableFormat(format);
1393 case LFUN_BUFFER_RELOAD:
1394 enable = doc_buffer && !doc_buffer->isUnnamed()
1395 && doc_buffer->fileName().exists()
1396 && (!doc_buffer->isClean()
1397 || doc_buffer->isExternallyModified(Buffer::timestamp_method));
1400 case LFUN_BUFFER_CHILD_OPEN:
1401 enable = doc_buffer;
1404 case LFUN_BUFFER_WRITE:
1405 enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
1408 //FIXME: This LFUN should be moved to GuiApplication.
1409 case LFUN_BUFFER_WRITE_ALL: {
1410 // We enable the command only if there are some modified buffers
1411 Buffer * first = theBufferList().first();
1416 // We cannot use a for loop as the buffer list is a cycle.
1418 if (!b->isClean()) {
1422 b = theBufferList().next(b);
1423 } while (b != first);
1427 case LFUN_BUFFER_WRITE_AS:
1428 enable = doc_buffer;
1431 case LFUN_BUFFER_CLOSE:
1432 enable = doc_buffer;
1435 case LFUN_BUFFER_CLOSE_ALL:
1436 enable = theBufferList().last() != theBufferList().first();
1439 case LFUN_SPLIT_VIEW:
1440 if (cmd.getArg(0) == "vertical")
1441 enable = doc_buffer && (d.splitter_->count() == 1 ||
1442 d.splitter_->orientation() == Qt::Vertical);
1444 enable = doc_buffer && (d.splitter_->count() == 1 ||
1445 d.splitter_->orientation() == Qt::Horizontal);
1448 case LFUN_CLOSE_TAB_GROUP:
1449 enable = d.currentTabWorkArea();
1452 case LFUN_TOOLBAR_TOGGLE: {
1453 string const name = cmd.getArg(0);
1454 if (GuiToolbar * t = toolbar(name))
1455 flag.setOnOff(t->isVisible());
1458 docstring const msg =
1459 bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
1465 case LFUN_DROP_LAYOUTS_CHOICE:
1469 case LFUN_UI_TOGGLE:
1470 flag.setOnOff(isFullScreen());
1473 case LFUN_DIALOG_DISCONNECT_INSET:
1476 case LFUN_DIALOG_HIDE:
1477 // FIXME: should we check if the dialog is shown?
1480 case LFUN_DIALOG_TOGGLE:
1481 flag.setOnOff(isDialogVisible(cmd.getArg(0)));
1482 // fall through to set "enable"
1483 case LFUN_DIALOG_SHOW: {
1484 string const name = cmd.getArg(0);
1486 enable = name == "aboutlyx"
1487 || name == "file" //FIXME: should be removed.
1489 || name == "texinfo"
1490 || name == "progress"
1491 || name == "compare";
1492 else if (name == "print")
1493 enable = doc_buffer->isExportable("dvi")
1494 && lyxrc.print_command != "none";
1495 else if (name == "character" || name == "symbols") {
1496 if (!buf || buf->isReadonly()
1497 || !currentBufferView()->cursor().inTexted())
1500 // FIXME we should consider passthru
1502 Inset const & in = currentBufferView()->cursor().inset();
1503 enable = !in.getLayout().isPassThru();
1506 else if (name == "latexlog")
1507 enable = FileName(doc_buffer->logName()).isReadableFile();
1508 else if (name == "spellchecker")
1509 enable = theSpellChecker() && !doc_buffer->isReadonly();
1510 else if (name == "vclog")
1511 enable = doc_buffer->lyxvc().inUse();
1515 case LFUN_DIALOG_UPDATE: {
1516 string const name = cmd.getArg(0);
1518 enable = name == "prefs";
1522 case LFUN_COMMAND_EXECUTE:
1524 case LFUN_MENU_OPEN:
1525 // Nothing to check.
1528 case LFUN_COMPLETION_INLINE:
1529 if (!d.current_work_area_
1530 || !d.current_work_area_->completer().inlinePossible(
1531 currentBufferView()->cursor()))
1535 case LFUN_COMPLETION_POPUP:
1536 if (!d.current_work_area_
1537 || !d.current_work_area_->completer().popupPossible(
1538 currentBufferView()->cursor()))
1542 case LFUN_COMPLETION_COMPLETE:
1543 if (!d.current_work_area_
1544 || !d.current_work_area_->completer().inlinePossible(
1545 currentBufferView()->cursor()))
1549 case LFUN_COMPLETION_ACCEPT:
1550 if (!d.current_work_area_
1551 || (!d.current_work_area_->completer().popupVisible()
1552 && !d.current_work_area_->completer().inlineVisible()
1553 && !d.current_work_area_->completer().completionAvailable()))
1557 case LFUN_COMPLETION_CANCEL:
1558 if (!d.current_work_area_
1559 || (!d.current_work_area_->completer().popupVisible()
1560 && !d.current_work_area_->completer().inlineVisible()))
1564 case LFUN_BUFFER_ZOOM_OUT:
1565 enable = doc_buffer && lyxrc.zoom > 10;
1568 case LFUN_BUFFER_ZOOM_IN:
1569 enable = doc_buffer;
1572 case LFUN_BUFFER_NEXT:
1573 case LFUN_BUFFER_PREVIOUS:
1574 // FIXME: should we check is there is an previous or next buffer?
1576 case LFUN_BUFFER_SWITCH:
1577 // toggle on the current buffer, but do not toggle off
1578 // the other ones (is that a good idea?)
1580 && to_utf8(cmd.argument()) == doc_buffer->absFileName())
1581 flag.setOnOff(true);
1584 case LFUN_VC_REGISTER:
1585 enable = doc_buffer && !doc_buffer->lyxvc().inUse();
1587 case LFUN_VC_CHECK_IN:
1588 enable = doc_buffer && doc_buffer->lyxvc().checkInEnabled();
1590 case LFUN_VC_CHECK_OUT:
1591 enable = doc_buffer && doc_buffer->lyxvc().checkOutEnabled();
1593 case LFUN_VC_LOCKING_TOGGLE:
1594 enable = doc_buffer && !doc_buffer->isReadonly()
1595 && doc_buffer->lyxvc().lockingToggleEnabled();
1596 flag.setOnOff(enable && doc_buffer->lyxvc().locking());
1598 case LFUN_VC_REVERT:
1599 enable = doc_buffer && doc_buffer->lyxvc().inUse();
1601 case LFUN_VC_UNDO_LAST:
1602 enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
1604 case LFUN_VC_REPO_UPDATE:
1605 enable = doc_buffer && doc_buffer->lyxvc().inUse();
1607 case LFUN_VC_COMMAND: {
1608 if (cmd.argument().empty())
1610 if (!doc_buffer && contains(cmd.getArg(0), 'D'))
1614 case LFUN_VC_COMPARE:
1615 enable = doc_buffer && !cmd.argument().empty()
1616 && doc_buffer->lyxvc().prepareFileRevisionEnabled();
1619 case LFUN_SERVER_GOTO_FILE_ROW:
1627 flag.setEnabled(false);
1633 static FileName selectTemplateFile()
1635 FileDialog dlg(qt_("Select template file"));
1636 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1637 dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
1639 FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
1640 QStringList(qt_("LyX Documents (*.lyx)")));
1642 if (result.first == FileDialog::Later)
1644 if (result.second.isEmpty())
1646 return FileName(fromqstr(result.second));
1650 Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
1654 Buffer * newBuffer = checkAndLoadLyXFile(filename);
1657 message(_("Document not loaded."));
1662 setBuffer(newBuffer);
1664 // scroll to the position when the file was last closed
1665 if (lyxrc.use_lastfilepos) {
1666 LastFilePosSection::FilePos filepos =
1667 theSession().lastFilePos().load(filename);
1668 documentBufferView()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
1672 theSession().lastFiles().add(filename);
1679 void GuiView::openDocument(string const & fname)
1681 string initpath = lyxrc.document_path;
1683 if (documentBufferView()) {
1684 string const trypath = documentBufferView()->buffer().filePath();
1685 // If directory is writeable, use this as default.
1686 if (FileName(trypath).isDirWritable())
1692 if (fname.empty()) {
1693 FileDialog dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
1694 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1695 dlg.setButton2(qt_("Examples|#E#e"),
1696 toqstr(addPath(package().system_support().absFilename(), "examples")));
1698 QStringList filter(qt_("LyX Documents (*.lyx)"));
1699 filter << qt_("LyX-1.3.x Documents (*.lyx13)")
1700 << qt_("LyX-1.4.x Documents (*.lyx14)")
1701 << qt_("LyX-1.5.x Documents (*.lyx15)")
1702 << qt_("LyX-1.6.x Documents (*.lyx16)");
1703 FileDialog::Result result =
1704 dlg.open(toqstr(initpath), filter);
1706 if (result.first == FileDialog::Later)
1709 filename = fromqstr(result.second);
1711 // check selected filename
1712 if (filename.empty()) {
1713 message(_("Canceled."));
1719 // get absolute path of file and add ".lyx" to the filename if
1721 FileName const fullname =
1722 fileSearch(string(), filename, "lyx", support::may_not_exist);
1723 if (!fullname.empty())
1724 filename = fullname.absFilename();
1726 if (!fullname.onlyPath().isDirectory()) {
1727 Alert::warning(_("Invalid filename"),
1728 bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
1729 from_utf8(fullname.absFilename())));
1732 // if the file doesn't exist, let the user create one
1733 if (!fullname.exists()) {
1734 // the user specifically chose this name. Believe him.
1735 Buffer * const b = newFile(filename, string(), true);
1741 docstring const disp_fn = makeDisplayPath(filename);
1742 message(bformat(_("Opening document %1$s..."), disp_fn));
1745 Buffer * buf = loadDocument(fullname);
1747 buf->updateLabels();
1749 buf->errors("Parse");
1750 str2 = bformat(_("Document %1$s opened."), disp_fn);
1751 if (buf->lyxvc().inUse())
1752 str2 += " " + from_utf8(buf->lyxvc().versionString()) +
1753 " " + _("Version control detected.");
1755 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1760 // FIXME: clean that
1761 static bool import(GuiView * lv, FileName const & filename,
1762 string const & format, ErrorList & errorList)
1764 FileName const lyxfile(support::changeExtension(filename.absFilename(), ".lyx"));
1766 string loader_format;
1767 vector<string> loaders = theConverters().loaders();
1768 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
1769 for (vector<string>::const_iterator it = loaders.begin();
1770 it != loaders.end(); ++it) {
1771 if (!theConverters().isReachable(format, *it))
1774 string const tofile =
1775 support::changeExtension(filename.absFilename(),
1776 formats.extension(*it));
1777 if (!theConverters().convert(0, filename, FileName(tofile),
1778 filename, format, *it, errorList))
1780 loader_format = *it;
1783 if (loader_format.empty()) {
1784 frontend::Alert::error(_("Couldn't import file"),
1785 bformat(_("No information for importing the format %1$s."),
1786 formats.prettyName(format)));
1790 loader_format = format;
1792 if (loader_format == "lyx") {
1793 Buffer * buf = lv->loadDocument(lyxfile);
1796 buf->updateLabels();
1798 buf->errors("Parse");
1800 Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
1804 bool as_paragraphs = loader_format == "textparagraph";
1805 string filename2 = (loader_format == format) ? filename.absFilename()
1806 : support::changeExtension(filename.absFilename(),
1807 formats.extension(loader_format));
1808 lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
1810 guiApp->setCurrentView(lv);
1811 lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
1818 void GuiView::importDocument(string const & argument)
1821 string filename = split(argument, format, ' ');
1823 LYXERR(Debug::INFO, format << " file: " << filename);
1825 // need user interaction
1826 if (filename.empty()) {
1827 string initpath = lyxrc.document_path;
1828 if (documentBufferView()) {
1829 string const trypath = documentBufferView()->buffer().filePath();
1830 // If directory is writeable, use this as default.
1831 if (FileName(trypath).isDirWritable())
1835 docstring const text = bformat(_("Select %1$s file to import"),
1836 formats.prettyName(format));
1838 FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
1839 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1840 dlg.setButton2(qt_("Examples|#E#e"),
1841 toqstr(addPath(package().system_support().absFilename(), "examples")));
1843 docstring filter = formats.prettyName(format);
1846 filter += from_utf8(formats.extension(format));
1849 FileDialog::Result result =
1850 dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
1852 if (result.first == FileDialog::Later)
1855 filename = fromqstr(result.second);
1857 // check selected filename
1858 if (filename.empty())
1859 message(_("Canceled."));
1862 if (filename.empty())
1865 // get absolute path of file
1866 FileName const fullname(support::makeAbsPath(filename));
1868 FileName const lyxfile(support::changeExtension(fullname.absFilename(), ".lyx"));
1870 // Check if the document already is open
1871 Buffer * buf = theBufferList().getBuffer(lyxfile);
1874 if (!closeBuffer()) {
1875 message(_("Canceled."));
1880 docstring const displaypath = makeDisplayPath(lyxfile.absFilename(), 30);
1882 // if the file exists already, and we didn't do
1883 // -i lyx thefile.lyx, warn
1884 if (lyxfile.exists() && fullname != lyxfile) {
1886 docstring text = bformat(_("The document %1$s already exists.\n\n"
1887 "Do you want to overwrite that document?"), displaypath);
1888 int const ret = Alert::prompt(_("Overwrite document?"),
1889 text, 0, 1, _("&Overwrite"), _("&Cancel"));
1892 message(_("Canceled."));
1897 message(bformat(_("Importing %1$s..."), displaypath));
1898 ErrorList errorList;
1899 if (import(this, fullname, format, errorList))
1900 message(_("imported."));
1902 message(_("file not imported!"));
1904 // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
1908 void GuiView::newDocument(string const & filename, bool from_template)
1910 FileName initpath(lyxrc.document_path);
1911 if (documentBufferView()) {
1912 FileName const trypath(documentBufferView()->buffer().filePath());
1913 // If directory is writeable, use this as default.
1914 if (trypath.isDirWritable())
1918 string templatefile;
1919 if (from_template) {
1920 templatefile = selectTemplateFile().absFilename();
1921 if (templatefile.empty())
1926 if (filename.empty())
1927 b = newUnnamedFile(initpath, to_utf8(_("newfile")), templatefile);
1929 b = newFile(filename, templatefile, true);
1934 // If no new document could be created, it is unsure
1935 // whether there is a valid BufferView.
1936 if (currentBufferView())
1937 // Ensure the cursor is correctly positioned on screen.
1938 currentBufferView()->showCursor();
1942 void GuiView::insertLyXFile(docstring const & fname)
1944 BufferView * bv = documentBufferView();
1949 FileName filename(to_utf8(fname));
1951 if (!filename.empty()) {
1952 bv->insertLyXFile(filename);
1956 // Launch a file browser
1958 string initpath = lyxrc.document_path;
1959 string const trypath = bv->buffer().filePath();
1960 // If directory is writeable, use this as default.
1961 if (FileName(trypath).isDirWritable())
1965 FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
1966 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1967 dlg.setButton2(qt_("Examples|#E#e"),
1968 toqstr(addPath(package().system_support().absFilename(),
1971 FileDialog::Result result = dlg.open(toqstr(initpath),
1972 QStringList(qt_("LyX Documents (*.lyx)")));
1974 if (result.first == FileDialog::Later)
1978 filename.set(fromqstr(result.second));
1980 // check selected filename
1981 if (filename.empty()) {
1982 // emit message signal.
1983 message(_("Canceled."));
1987 bv->insertLyXFile(filename);
1991 void GuiView::insertPlaintextFile(docstring const & fname,
1994 BufferView * bv = documentBufferView();
1998 if (!fname.empty() && !FileName::isAbsolute(to_utf8(fname))) {
1999 message(_("Absolute filename expected."));
2004 FileName filename(to_utf8(fname));
2006 if (!filename.empty()) {
2007 bv->insertPlaintextFile(filename, asParagraph);
2011 FileDialog dlg(qt_("Select file to insert"), (asParagraph ?
2012 LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
2014 FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
2015 QStringList(qt_("All Files (*)")));
2017 if (result.first == FileDialog::Later)
2021 filename.set(fromqstr(result.second));
2023 // check selected filename
2024 if (filename.empty()) {
2025 // emit message signal.
2026 message(_("Canceled."));
2030 bv->insertPlaintextFile(filename, asParagraph);
2034 bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
2036 FileName fname = b.fileName();
2037 FileName const oldname = fname;
2039 if (!newname.empty()) {
2041 fname = support::makeAbsPath(to_utf8(newname), oldname.onlyPath().absFilename());
2043 // Switch to this Buffer.
2046 // No argument? Ask user through dialog.
2048 FileDialog dlg(qt_("Choose a filename to save document as"),
2049 LFUN_BUFFER_WRITE_AS);
2050 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2051 dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
2053 if (!isLyXFilename(fname.absFilename()))
2054 fname.changeExtension(".lyx");
2056 FileDialog::Result result =
2057 dlg.save(toqstr(fname.onlyPath().absFilename()),
2058 QStringList(qt_("LyX Documents (*.lyx)")),
2059 toqstr(fname.onlyFileName()));
2061 if (result.first == FileDialog::Later)
2064 fname.set(fromqstr(result.second));
2069 if (!isLyXFilename(fname.absFilename()))
2070 fname.changeExtension(".lyx");
2073 if (FileName(fname).exists()) {
2074 docstring const file = makeDisplayPath(fname.absFilename(), 30);
2075 docstring text = bformat(_("The document %1$s already "
2076 "exists.\n\nDo you want to "
2077 "overwrite that document?"),
2079 int const ret = Alert::prompt(_("Overwrite document?"),
2080 text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
2083 case 1: return renameBuffer(b, docstring());
2084 case 2: return false;
2088 FileName oldauto = b.getAutosaveFilename();
2090 // Ok, change the name of the buffer
2091 b.setFileName(fname.absFilename());
2093 bool unnamed = b.isUnnamed();
2094 b.setUnnamed(false);
2095 b.saveCheckSum(fname);
2097 // bring the autosave file with us, just in case.
2098 b.moveAutosaveFile(oldauto);
2100 if (!saveBuffer(b)) {
2101 oldauto = b.getAutosaveFilename();
2102 b.setFileName(oldname.absFilename());
2103 b.setUnnamed(unnamed);
2104 b.saveCheckSum(oldname);
2105 b.moveAutosaveFile(oldauto);
2113 bool GuiView::saveBuffer(Buffer & b)
2115 if (workArea(b) && workArea(b)->inDialogMode())
2119 return renameBuffer(b, docstring());
2122 theSession().lastFiles().add(b.fileName());
2126 // Switch to this Buffer.
2129 // FIXME: we don't tell the user *WHY* the save failed !!
2130 docstring const file = makeDisplayPath(b.absFileName(), 30);
2131 docstring text = bformat(_("The document %1$s could not be saved.\n\n"
2132 "Do you want to rename the document and "
2133 "try again?"), file);
2134 int const ret = Alert::prompt(_("Rename and save?"),
2135 text, 0, 2, _("&Rename"), _("&Retry"), _("&Cancel"));
2138 if (!renameBuffer(b, docstring()))
2147 return saveBuffer(b);
2151 bool GuiView::hideWorkArea(GuiWorkArea * wa)
2153 return closeWorkArea(wa, false);
2157 bool GuiView::closeWorkArea(GuiWorkArea * wa)
2159 Buffer & buf = wa->bufferView().buffer();
2160 return closeWorkArea(wa, !buf.parent());
2164 bool GuiView::closeBuffer()
2166 GuiWorkArea * wa = currentMainWorkArea();
2167 setCurrentWorkArea(wa);
2168 Buffer & buf = wa->bufferView().buffer();
2169 return wa && closeWorkArea(wa, !buf.parent());
2173 void GuiView::writeSession() const {
2174 GuiWorkArea const * active_wa = currentMainWorkArea();
2175 for (int i = 0; i < d.splitter_->count(); ++i) {
2176 TabWorkArea * twa = d.tabWorkArea(i);
2177 for (int j = 0; j < twa->count(); ++j) {
2178 GuiWorkArea * wa = static_cast<GuiWorkArea *>(twa->widget(j));
2179 Buffer & buf = wa->bufferView().buffer();
2180 theSession().lastOpened().add(buf.fileName(), wa == active_wa);
2186 bool GuiView::closeBufferAll()
2188 // Close the workareas in all other views
2189 QList<int> const ids = guiApp->viewIds();
2190 for (int i = 0; i != ids.size(); ++i) {
2191 if (id_ != ids[i] && !guiApp->view(ids[i]).closeWorkAreaAll())
2195 // Close our own workareas
2196 if (!closeWorkAreaAll())
2199 // Now close the hidden buffers. We prevent hidden buffers from being
2200 // dirty, so we can just close them.
2201 theBufferList().closeAll();
2206 bool GuiView::closeWorkAreaAll()
2208 setCurrentWorkArea(currentMainWorkArea());
2210 // We might be in a situation that there is still a tabWorkArea, but
2211 // there are no tabs anymore. This can happen when we get here after a
2212 // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
2213 // many TabWorkArea's have no documents anymore.
2216 // We have to call count() each time, because it can happen that
2217 // more than one splitter will disappear in one iteration (bug 5998).
2218 for (; d.splitter_->count() > empty_twa; ) {
2219 TabWorkArea * twa = d.tabWorkArea(empty_twa);
2221 if (twa->count() == 0)
2224 setCurrentWorkArea(twa->currentWorkArea());
2225 if (!closeTabWorkArea(twa))
2233 bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer)
2238 Buffer & buf = wa->bufferView().buffer();
2241 return closeBuffer(buf);
2243 if (!inMultiTabs(wa))
2244 if (!saveBufferIfNeeded(buf, true))
2252 bool GuiView::closeBuffer(Buffer & buf)
2254 // If we are in a close_event all children will be closed in some time,
2255 // so no need to do it here. This will ensure that the children end up
2256 // in the session file in the correct order. If we close the master
2257 // buffer, we can close or release the child buffers here too.
2259 vector<Buffer *> clist = buf.getChildren(false);
2260 for (vector<Buffer *>::const_iterator it = clist.begin();
2261 it != clist.end(); ++it) {
2262 // If a child is dirty, do not close
2263 // without user intervention
2264 //FIXME: should we look in other tabworkareas?
2265 Buffer * child_buf = *it;
2266 GuiWorkArea * child_wa = workArea(*child_buf);
2268 if (!closeWorkArea(child_wa, true))
2271 theBufferList().releaseChild(&buf, child_buf);
2274 // goto bookmark to update bookmark pit.
2275 //FIXME: we should update only the bookmarks related to this buffer!
2276 LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
2277 for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
2278 guiApp->gotoBookmark(i+1, false, false);
2280 if (saveBufferIfNeeded(buf, false)) {
2281 theBufferList().release(&buf);
2288 bool GuiView::closeTabWorkArea(TabWorkArea * twa)
2290 while (twa == d.currentTabWorkArea()) {
2291 twa->setCurrentIndex(twa->count()-1);
2293 GuiWorkArea * wa = twa->currentWorkArea();
2294 Buffer & b = wa->bufferView().buffer();
2296 // We only want to close the buffer if the same buffer is not visible
2297 // in another view, and if this is not a child and if we are closing
2298 // a view (not a tabgroup).
2299 bool const close_buffer =
2300 !inMultiViews(wa) && !b.parent() && closing_;
2302 if (!closeWorkArea(wa, close_buffer))
2309 bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
2311 if (buf.isClean() || buf.paragraphs().empty())
2314 // Switch to this Buffer.
2319 if (buf.isUnnamed())
2320 file = from_utf8(buf.fileName().onlyFileName());
2322 file = buf.fileName().displayName(30);
2324 // Bring this window to top before asking questions.
2329 if (hiding && buf.isUnnamed()) {
2330 docstring const text = bformat(_("The document %1$s has not been "
2331 "saved yet.\n\nDo you want to save "
2332 "the document?"), file);
2333 ret = Alert::prompt(_("Save new document?"),
2334 text, 0, 1, _("&Save"), _("&Cancel"));
2338 docstring const text = bformat(_("The document %1$s has unsaved changes."
2339 "\n\nDo you want to save the document or discard the changes?"), file);
2340 ret = Alert::prompt(_("Save changed document?"),
2341 text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
2346 if (!saveBuffer(buf))
2350 // if we crash after this we could
2351 // have no autosave file but I guess
2352 // this is really improbable (Jug)
2353 buf.removeAutosaveFile();
2355 // revert all changes
2366 bool GuiView::inMultiTabs(GuiWorkArea * wa)
2368 Buffer & buf = wa->bufferView().buffer();
2370 for (int i = 0; i != d.splitter_->count(); ++i) {
2371 GuiWorkArea * wa_ = d.tabWorkArea(i)->workArea(buf);
2372 if (wa_ && wa_ != wa)
2375 return inMultiViews(wa);
2379 bool GuiView::inMultiViews(GuiWorkArea * wa)
2381 QList<int> const ids = guiApp->viewIds();
2382 Buffer & buf = wa->bufferView().buffer();
2385 for (int i = 0; i != ids.size() && found_twa <= 1; ++i) {
2389 if (guiApp->view(ids[i]).workArea(buf))
2396 void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
2398 Buffer * const curbuf = documentBufferView()
2399 ? &documentBufferView()->buffer() : 0;
2400 Buffer * nextbuf = curbuf;
2402 if (np == NEXTBUFFER)
2403 nextbuf = theBufferList().next(nextbuf);
2405 nextbuf = theBufferList().previous(nextbuf);
2406 if (nextbuf == curbuf)
2412 if (workArea(*nextbuf))
2419 /// make sure the document is saved
2420 static bool ensureBufferClean(Buffer * buffer)
2422 LASSERT(buffer, return false);
2423 if (buffer->isClean() && !buffer->isUnnamed())
2426 docstring const file = buffer->fileName().displayName(30);
2429 if (!buffer->isUnnamed()) {
2430 text = bformat(_("The document %1$s has unsaved "
2431 "changes.\n\nDo you want to save "
2432 "the document?"), file);
2433 title = _("Save changed document?");
2436 text = bformat(_("The document %1$s has not been "
2437 "saved yet.\n\nDo you want to save "
2438 "the document?"), file);
2439 title = _("Save new document?");
2441 int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
2444 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
2446 return buffer->isClean() && !buffer->isUnnamed();
2450 void GuiView::reloadBuffer()
2452 Buffer * buf = &documentBufferView()->buffer();
2457 void GuiView::checkExternallyModifiedBuffers()
2459 BufferList::iterator bit = theBufferList().begin();
2460 BufferList::iterator const bend = theBufferList().end();
2461 for (; bit != bend; ++bit) {
2462 if ((*bit)->fileName().exists()
2463 && (*bit)->isExternallyModified(Buffer::checksum_method)) {
2464 docstring text = bformat(_("Document \n%1$s\n has been externally modified."
2465 " Reload now? Any local changes will be lost."),
2466 from_utf8((*bit)->absFileName()));
2467 int const ret = Alert::prompt(_("Reload externally changed document?"),
2468 text, 0, 1, _("&Reload"), _("&Cancel"));
2476 //FIXME use a DispatchResult object to transmit messages
2477 void GuiView::dispatchVC(FuncRequest const & cmd)
2479 // message for statusbar
2481 Buffer * buffer = documentBufferView()
2482 ? &(documentBufferView()->buffer()) : 0;
2484 switch (cmd.action) {
2485 case LFUN_VC_REGISTER:
2486 if (!buffer || !ensureBufferClean(buffer))
2488 if (!buffer->lyxvc().inUse()) {
2489 if (buffer->lyxvc().registrer())
2494 case LFUN_VC_CHECK_IN:
2495 if (!buffer || !ensureBufferClean(buffer))
2497 if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
2498 msg = buffer->lyxvc().checkIn();
2504 case LFUN_VC_CHECK_OUT:
2505 if (!buffer || !ensureBufferClean(buffer))
2507 if (buffer->lyxvc().inUse()) {
2508 msg = buffer->lyxvc().checkOut();
2513 case LFUN_VC_LOCKING_TOGGLE:
2514 LASSERT(buffer, return);
2515 if (!ensureBufferClean(buffer) || buffer->isReadonly())
2517 if (buffer->lyxvc().inUse()) {
2518 string res = buffer->lyxvc().lockingToggle();
2520 frontend::Alert::error(_("Revision control error."),
2521 _("Error when setting the locking property."));
2529 case LFUN_VC_REVERT:
2530 LASSERT(buffer, return);
2531 buffer->lyxvc().revert();
2535 case LFUN_VC_UNDO_LAST:
2536 LASSERT(buffer, return);
2537 buffer->lyxvc().undoLast();
2541 case LFUN_VC_REPO_UPDATE:
2542 LASSERT(buffer, return);
2543 if (ensureBufferClean(buffer)) {
2544 msg = buffer->lyxvc().repoUpdate();
2545 checkExternallyModifiedBuffers();
2549 case LFUN_VC_COMMAND: {
2550 string flag = cmd.getArg(0);
2551 if (buffer && contains(flag, 'R') && !ensureBufferClean(buffer))
2554 if (contains(flag, 'M')) {
2555 if (!Alert::askForText(message, _("LyX VC: Log Message")))
2558 string path = cmd.getArg(1);
2559 if (contains(path, "$$p") && buffer)
2560 path = subst(path, "$$p", buffer->filePath());
2561 LYXERR(Debug::LYXVC, "Directory: " << path);
2563 if (!pp.isReadableDirectory()) {
2564 lyxerr << _("Directory is not accessible.") << endl;
2567 support::PathChanger p(pp);
2569 string command = cmd.getArg(2);
2570 if (command.empty())
2573 command = subst(command, "$$i", buffer->absFileName());
2574 command = subst(command, "$$p", buffer->filePath());
2576 command = subst(command, "$$m", to_utf8(message));
2577 LYXERR(Debug::LYXVC, "Command: " << command);
2579 one.startscript(Systemcall::Wait, command);
2583 if (contains(flag, 'I'))
2584 buffer->markDirty();
2585 if (contains(flag, 'R'))
2591 case LFUN_VC_COMPARE: {
2593 string rev1 = cmd.getArg(0);
2597 if (!buffer->lyxvc().prepareFileRevision(rev1, f1))
2600 if (isStrInt(rev1) && convert<int>(rev1) <= 0) {
2601 f2 = buffer->absFileName();
2603 string rev2 = cmd.getArg(1);
2607 if (!buffer->lyxvc().prepareFileRevision(rev2, f2))
2610 // FIXME We need to call comparison feature here.
2611 // This is quick and dirty code for testing VC.
2612 // We need that comparison feature has some LFUN_COMPARE <FLAG> file1 file1
2613 FileName initpath(lyxrc.document_path);
2614 Buffer * dest = newUnnamedFile(initpath, to_utf8(_("differences")));
2615 CompareOptions options;
2616 Compare * compare = new Compare(loadIfNeeded(FileName(f1)), loadIfNeeded(FileName(f2)), dest, options);
2617 compare->start(QThread::LowPriority);
2618 Sleep::millisec(200);
2619 lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest->absFileName()));
2628 message(from_utf8(msg));
2632 void GuiView::openChildDocument(string const & fname)
2634 LASSERT(documentBufferView(), return);
2635 Buffer & buffer = documentBufferView()->buffer();
2636 FileName const filename = support::makeAbsPath(fname, buffer.filePath());
2637 documentBufferView()->saveBookmark(false);
2639 bool parsed = false;
2640 if (theBufferList().exists(filename)) {
2641 child = theBufferList().getBuffer(filename);
2643 message(bformat(_("Opening child document %1$s..."),
2644 makeDisplayPath(filename.absFilename())));
2645 child = loadDocument(filename, false);
2651 // Set the parent name of the child document.
2652 // This makes insertion of citations and references in the child work,
2653 // when the target is in the parent or another child document.
2654 child->setParent(&buffer);
2655 child->masterBuffer()->updateLabels();
2658 child->errors("Parse");
2662 bool GuiView::goToFileRow(string const & argument)
2666 size_t i = argument.find_last_of(' ');
2667 if (i != string::npos) {
2668 file_name = os::internal_path(trim(argument.substr(0, i)));
2669 istringstream is(argument.substr(i + 1));
2674 if (i == string::npos) {
2675 LYXERR0("Wrong argument: " << argument);
2679 string const abstmp = package().temp_dir().absFilename();
2680 string const realtmp = package().temp_dir().realPath();
2681 // We have to use os::path_prefix_is() here, instead of
2682 // simply prefixIs(), because the file name comes from
2683 // an external application and may need case adjustment.
2684 if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
2685 || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
2686 // Needed by inverse dvi search. If it is a file
2687 // in tmpdir, call the apropriated function.
2688 // If tmpdir is a symlink, we may have the real
2689 // path passed back, so we correct for that.
2690 if (!prefixIs(file_name, abstmp))
2691 file_name = subst(file_name, realtmp, abstmp);
2692 buf = theBufferList().getBufferFromTmp(file_name);
2694 // Must replace extension of the file to be .lyx
2695 // and get full path
2696 FileName const s = fileSearch(string(),
2697 support::changeExtension(file_name, ".lyx"), "lyx");
2698 // Either change buffer or load the file
2699 if (theBufferList().exists(s))
2700 buf = theBufferList().getBuffer(s);
2701 else if (s.exists()) {
2702 buf = loadDocument(s);
2703 buf->updateLabels();
2704 buf->errors("Parse");
2707 _("File does not exist: %1$s"),
2708 makeDisplayPath(file_name)));
2713 documentBufferView()->setCursorFromRow(row);
2718 #if (QT_VERSION >= 0x040400)
2719 static docstring exportAndDestroy(Buffer * buffer, string const & format)
2721 bool const update_unincluded =
2722 buffer->params().maintain_unincluded_children
2723 && !buffer->params().getIncludedChildren().empty();
2724 bool const success = buffer->doExport(format, true, update_unincluded);
2727 ? bformat(_("Successful export to format: %1$s"), from_utf8(format))
2728 : bformat(_("Error exporting to format: %1$s"), from_utf8(format));
2732 static docstring previewAndDestroy(Buffer * buffer, string const & format)
2734 bool const update_unincluded =
2735 buffer->params().maintain_unincluded_children
2736 && !buffer->params().getIncludedChildren().empty();
2737 bool const success = buffer->preview(format, update_unincluded);
2740 ? bformat(_("Successful preview of format: %1$s"), from_utf8(format))
2741 : bformat(_("Error previewing format: %1$s"), from_utf8(format));
2746 void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
2748 BufferView * bv = currentBufferView();
2749 // By default we won't need any update.
2750 dr.update(Update::None);
2751 // assume cmd will be dispatched
2752 dr.dispatched(true);
2754 Buffer * doc_buffer = documentBufferView()
2755 ? &(documentBufferView()->buffer()) : 0;
2757 if (cmd.origin == FuncRequest::TOC) {
2758 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
2759 // FIXME: do we need to pass a DispatchResult object here?
2760 toc->doDispatch(bv->cursor(), cmd);
2764 string const argument = to_utf8(cmd.argument());
2766 switch(cmd.action) {
2767 case LFUN_BUFFER_CHILD_OPEN:
2768 openChildDocument(to_utf8(cmd.argument()));
2771 case LFUN_BUFFER_IMPORT:
2772 importDocument(to_utf8(cmd.argument()));
2775 case LFUN_BUFFER_EXPORT: {
2778 // GCC only sees strfwd.h when building merged
2779 if (::lyx::operator==(cmd.argument(), "custom")) {
2780 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"),
2784 if (doc_buffer->doExport(argument, false)) {
2786 dr.setMessage(bformat(_("Error exporting to format: %1$s."),
2792 case LFUN_BUFFER_UPDATE: {
2795 string format = argument;
2796 if (argument.empty())
2797 format = doc_buffer->getDefaultOutputFormat();
2798 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2799 d.progress_->clearMessages();
2800 message(_("Exporting ..."));
2801 QFuture<docstring> f = QtConcurrent::run(exportAndDestroy,
2802 doc_buffer->clone(), format);
2803 d.setPreviewFuture(f);
2805 bool const update_unincluded =
2806 doc_buffer->params().maintain_unincluded_children
2807 && !doc_buffer->params().getIncludedChildren().empty();
2808 doc_buffer->doExport(format, true, update_unincluded);
2812 case LFUN_BUFFER_VIEW: {
2815 string format = argument;
2816 if (argument.empty())
2817 format = doc_buffer->getDefaultOutputFormat();
2818 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2819 d.progress_->clearMessages();
2820 message(_("Previewing ..."));
2821 QFuture<docstring> f = QtConcurrent::run(previewAndDestroy,
2822 doc_buffer->clone(), format);
2823 d.setPreviewFuture(f);
2825 bool const update_unincluded =
2826 doc_buffer->params().maintain_unincluded_children
2827 && !doc_buffer->params().getIncludedChildren().empty();
2828 doc_buffer->preview(format, update_unincluded);
2832 case LFUN_MASTER_BUFFER_UPDATE: {
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(exportAndDestroy,
2841 master->clone(), format);
2842 d.setPreviewFuture(f);
2844 bool const update_unincluded =
2845 master->params().maintain_unincluded_children
2846 && !master->params().getIncludedChildren().empty();
2847 master->doExport(format, true);
2851 case LFUN_MASTER_BUFFER_VIEW: {
2852 string format = argument;
2853 Buffer const * master = doc_buffer->masterBuffer();
2854 if (argument.empty())
2855 format = master->getDefaultOutputFormat();
2856 #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
2857 QFuture<docstring> f = QtConcurrent::run(previewAndDestroy,
2858 master->clone(), format);
2859 d.setPreviewFuture(f);
2861 master->preview(format);
2865 case LFUN_BUFFER_SWITCH:
2866 if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
2868 theBufferList().getBuffer(FileName(to_utf8(cmd.argument())));
2873 dr.setMessage(_("Document not loaded"));
2878 case LFUN_BUFFER_NEXT:
2879 gotoNextOrPreviousBuffer(NEXTBUFFER);
2882 case LFUN_BUFFER_PREVIOUS:
2883 gotoNextOrPreviousBuffer(PREVBUFFER);
2886 case LFUN_COMMAND_EXECUTE: {
2887 bool const show_it = cmd.argument() != "off";
2888 // FIXME: this is a hack, "minibuffer" should not be
2890 if (GuiToolbar * t = toolbar("minibuffer")) {
2891 t->setVisible(show_it);
2892 if (show_it && t->commandBuffer())
2893 t->commandBuffer()->setFocus();
2897 case LFUN_DROP_LAYOUTS_CHOICE:
2898 d.layout_->showPopup();
2901 case LFUN_MENU_OPEN:
2902 if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument()), *this))
2903 menu->exec(QCursor::pos());
2906 case LFUN_FILE_INSERT:
2907 insertLyXFile(cmd.argument());
2909 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
2910 insertPlaintextFile(cmd.argument(), true);
2913 case LFUN_FILE_INSERT_PLAINTEXT:
2914 insertPlaintextFile(cmd.argument(), false);
2917 case LFUN_BUFFER_RELOAD: {
2918 LASSERT(doc_buffer, break);
2919 docstring const file = makeDisplayPath(doc_buffer->absFileName(), 20);
2920 docstring text = bformat(_("Any changes will be lost. Are you sure "
2921 "you want to revert to the saved version of the document %1$s?"), file);
2922 int const ret = Alert::prompt(_("Revert to saved document?"),
2923 text, 1, 1, _("&Revert"), _("&Cancel"));
2926 doc_buffer->markClean();
2932 case LFUN_BUFFER_WRITE:
2933 LASSERT(doc_buffer, break);
2934 saveBuffer(*doc_buffer);
2937 case LFUN_BUFFER_WRITE_AS:
2938 LASSERT(doc_buffer, break);
2939 renameBuffer(*doc_buffer, cmd.argument());
2942 case LFUN_BUFFER_WRITE_ALL: {
2943 Buffer * first = theBufferList().first();
2946 message(_("Saving all documents..."));
2947 // We cannot use a for loop as the buffer list cycles.
2950 if (!b->isClean()) {
2952 LYXERR(Debug::ACTION, "Saved " << b->absFileName());
2954 b = theBufferList().next(b);
2955 } while (b != first);
2956 dr.setMessage(_("All documents saved."));
2960 case LFUN_BUFFER_CLOSE:
2964 case LFUN_BUFFER_CLOSE_ALL:
2968 case LFUN_TOOLBAR_TOGGLE: {
2969 string const name = cmd.getArg(0);
2970 if (GuiToolbar * t = toolbar(name))
2975 case LFUN_DIALOG_UPDATE: {
2976 string const name = to_utf8(cmd.argument());
2977 if (currentBufferView()) {
2978 Inset * inset = currentBufferView()->editedInset(name);
2979 // Can only update a dialog connected to an existing inset
2982 // FIXME: get rid of this indirection; GuiView ask the inset
2983 // if he is kind enough to update itself...
2984 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
2985 //FIXME: pass DispatchResult here?
2986 inset->dispatch(currentBufferView()->cursor(), fr);
2987 } else if (name == "paragraph") {
2988 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
2989 } else if (name == "prefs" || name == "document") {
2990 updateDialog(name, string());
2995 case LFUN_DIALOG_TOGGLE: {
2996 if (isDialogVisible(cmd.getArg(0)))
2997 dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument()), dr);
2999 dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument()), dr);
3003 case LFUN_DIALOG_DISCONNECT_INSET:
3004 disconnectDialog(to_utf8(cmd.argument()));
3007 case LFUN_DIALOG_HIDE: {
3008 guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
3012 case LFUN_DIALOG_SHOW: {
3013 string const name = cmd.getArg(0);
3014 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
3016 if (name == "character") {
3017 data = freefont2string();
3019 showDialog("character", data);
3020 } else if (name == "latexlog") {
3021 Buffer::LogType type;
3022 string const logfile = doc_buffer->logName(&type);
3024 case Buffer::latexlog:
3027 case Buffer::buildlog:
3031 data += Lexer::quoteString(logfile);
3032 showDialog("log", data);
3033 } else if (name == "vclog") {
3034 string const data = "vc " +
3035 Lexer::quoteString(doc_buffer->lyxvc().getLogFile());
3036 showDialog("log", data);
3037 } else if (name == "symbols") {
3038 data = bv->cursor().getEncoding()->name();
3040 showDialog("symbols", data);
3042 } else if (name == "prefs" && isFullScreen()) {
3043 lfunUiToggle("fullscreen");
3044 showDialog("prefs", data);
3046 showDialog(name, data);
3051 dr.setMessage(cmd.argument());
3054 case LFUN_UI_TOGGLE: {
3055 string arg = cmd.getArg(0);
3056 if (!lfunUiToggle(arg)) {
3057 docstring const msg = "ui-toggle " + _("%1$s unknown command!");
3058 dr.setMessage(bformat(msg, from_utf8(arg)));
3060 // Make sure the keyboard focus stays in the work area.
3065 case LFUN_SPLIT_VIEW: {
3066 LASSERT(doc_buffer, break);
3067 string const orientation = cmd.getArg(0);
3068 d.splitter_->setOrientation(orientation == "vertical"
3069 ? Qt::Vertical : Qt::Horizontal);
3070 TabWorkArea * twa = addTabWorkArea();
3071 GuiWorkArea * wa = twa->addWorkArea(*doc_buffer, *this);
3072 setCurrentWorkArea(wa);
3075 case LFUN_CLOSE_TAB_GROUP:
3076 if (TabWorkArea * twa = d.currentTabWorkArea()) {
3077 closeTabWorkArea(twa);
3078 d.current_work_area_ = 0;
3079 twa = d.currentTabWorkArea();
3080 // Switch to the next GuiWorkArea in the found TabWorkArea.
3082 // Make sure the work area is up to date.
3083 setCurrentWorkArea(twa->currentWorkArea());
3085 setCurrentWorkArea(0);
3090 case LFUN_COMPLETION_INLINE:
3091 if (d.current_work_area_)
3092 d.current_work_area_->completer().showInline();
3095 case LFUN_COMPLETION_POPUP:
3096 if (d.current_work_area_)
3097 d.current_work_area_->completer().showPopup();
3101 case LFUN_COMPLETION_COMPLETE:
3102 if (d.current_work_area_)
3103 d.current_work_area_->completer().tab();
3106 case LFUN_COMPLETION_CANCEL:
3107 if (d.current_work_area_) {
3108 if (d.current_work_area_->completer().popupVisible())
3109 d.current_work_area_->completer().hidePopup();
3111 d.current_work_area_->completer().hideInline();
3115 case LFUN_COMPLETION_ACCEPT:
3116 if (d.current_work_area_)
3117 d.current_work_area_->completer().activate();
3120 case LFUN_BUFFER_ZOOM_IN:
3121 case LFUN_BUFFER_ZOOM_OUT:
3122 if (cmd.argument().empty()) {
3123 if (cmd.action == LFUN_BUFFER_ZOOM_IN)
3128 lyxrc.zoom += convert<int>(cmd.argument());
3130 if (lyxrc.zoom < 10)
3133 // The global QPixmapCache is used in GuiPainter to cache text
3134 // painting so we must reset it.
3135 QPixmapCache::clear();
3136 guiApp->fontLoader().update();
3137 lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
3140 case LFUN_VC_REGISTER:
3141 case LFUN_VC_CHECK_IN:
3142 case LFUN_VC_CHECK_OUT:
3143 case LFUN_VC_REPO_UPDATE:
3144 case LFUN_VC_LOCKING_TOGGLE:
3145 case LFUN_VC_REVERT:
3146 case LFUN_VC_UNDO_LAST:
3147 case LFUN_VC_COMMAND:
3148 case LFUN_VC_COMPARE:
3152 case LFUN_SERVER_GOTO_FILE_ROW:
3153 goToFileRow(to_utf8(cmd.argument()));
3157 dr.dispatched(false);
3161 // Part of automatic menu appearance feature.
3162 if (isFullScreen()) {
3163 if (menuBar()->isVisible() && lyxrc.full_screen_menubar)
3165 if (statusBar()->isVisible())
3166 statusBar()->hide();
3173 bool GuiView::lfunUiToggle(string const & ui_component)
3175 if (ui_component == "scrollbar") {
3176 // hide() is of no help
3177 if (d.current_work_area_->verticalScrollBarPolicy() ==
3178 Qt::ScrollBarAlwaysOff)
3180 d.current_work_area_->setVerticalScrollBarPolicy(
3181 Qt::ScrollBarAsNeeded);
3183 d.current_work_area_->setVerticalScrollBarPolicy(
3184 Qt::ScrollBarAlwaysOff);
3185 } else if (ui_component == "statusbar") {
3186 statusBar()->setVisible(!statusBar()->isVisible());
3187 } else if (ui_component == "menubar") {
3188 menuBar()->setVisible(!menuBar()->isVisible());
3190 #if QT_VERSION >= 0x040300
3191 if (ui_component == "frame") {
3193 getContentsMargins(&l, &t, &r, &b);
3194 //are the frames in default state?
3195 d.current_work_area_->setFrameStyle(QFrame::NoFrame);
3197 setContentsMargins(-2, -2, -2, -2);
3199 setContentsMargins(0, 0, 0, 0);
3203 if (ui_component == "fullscreen") {
3211 void GuiView::toggleFullScreen()
3213 if (isFullScreen()) {
3214 for (int i = 0; i != d.splitter_->count(); ++i)
3215 d.tabWorkArea(i)->setFullScreen(false);
3216 #if QT_VERSION >= 0x040300
3217 setContentsMargins(0, 0, 0, 0);
3219 setWindowState(windowState() ^ Qt::WindowFullScreen);
3222 statusBar()->show();
3225 hideDialogs("prefs", 0);
3226 for (int i = 0; i != d.splitter_->count(); ++i)
3227 d.tabWorkArea(i)->setFullScreen(true);
3228 #if QT_VERSION >= 0x040300
3229 setContentsMargins(-2, -2, -2, -2);
3232 setWindowState(windowState() ^ Qt::WindowFullScreen);
3233 statusBar()->hide();
3234 if (lyxrc.full_screen_menubar)
3236 if (lyxrc.full_screen_toolbars) {
3237 ToolbarMap::iterator end = d.toolbars_.end();
3238 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
3243 // give dialogs like the TOC a chance to adapt
3248 Buffer const * GuiView::updateInset(Inset const * inset)
3250 if (!d.current_work_area_)
3254 d.current_work_area_->scheduleRedraw();
3256 return &d.current_work_area_->bufferView().buffer();
3260 void GuiView::restartCursor()
3262 /* When we move around, or type, it's nice to be able to see
3263 * the cursor immediately after the keypress.
3265 if (d.current_work_area_)
3266 d.current_work_area_->startBlinkingCursor();
3268 // Take this occasion to update the other GUI elements.
3274 void GuiView::updateCompletion(Cursor & cur, bool start, bool keep)
3276 if (d.current_work_area_)
3277 d.current_work_area_->completer().updateVisibility(cur, start, keep);
3282 // This list should be kept in sync with the list of insets in
3283 // src/insets/Inset.cpp. I.e., if a dialog goes with an inset, the
3284 // dialog should have the same name as the inset.
3285 // Changes should be also recorded in LFUN_DIALOG_SHOW doxygen
3286 // docs in LyXAction.cpp.
3288 char const * const dialognames[] = {
3289 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
3290 "citation", "compare", "document", "errorlist", "ert", "external", "file",
3291 "findreplace", "findreplaceadv", "float", "graphics", "href", "include",
3292 "index", "index_print", "info", "listings", "label", "log", "mathdelimiter",
3293 "mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note",
3294 "paragraph", "phantom", "prefs", "print", "ref", "sendto", "space",
3295 "spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo",
3296 "toc", "view-source", "vspace", "wrap", "progress"};
3298 char const * const * const end_dialognames =
3299 dialognames + (sizeof(dialognames) / sizeof(char *));
3303 cmpCStr(char const * name) : name_(name) {}
3304 bool operator()(char const * other) {
3305 return strcmp(other, name_) == 0;
3312 bool isValidName(string const & name)
3314 return find_if(dialognames, end_dialognames,
3315 cmpCStr(name.c_str())) != end_dialognames;
3321 void GuiView::resetDialogs()
3323 // Make sure that no LFUN uses any GuiView.
3324 guiApp->setCurrentView(0);
3327 constructToolbars();
3328 guiApp->menus().fillMenuBar(menuBar(), this, false);
3329 d.layout_->updateContents(true);
3330 // Now update controls with current buffer.
3331 guiApp->setCurrentView(this);
3337 Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
3339 if (!isValidName(name))
3342 map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
3344 if (it != d.dialogs_.end()) {
3346 it->second->hideView();
3347 return it->second.get();
3350 Dialog * dialog = build(name);
3351 d.dialogs_[name].reset(dialog);
3352 if (lyxrc.allow_geometry_session)
3353 dialog->restoreSession();
3360 void GuiView::showDialog(string const & name, string const & data,
3363 triggerShowDialog(toqstr(name), toqstr(data), inset);
3367 void GuiView::doShowDialog(QString const & qname, QString const & qdata,
3373 const string name = fromqstr(qname);
3374 const string data = fromqstr(qdata);
3378 Dialog * dialog = findOrBuild(name, false);
3380 dialog->showData(data);
3381 if (inset && currentBufferView())
3382 currentBufferView()->editInset(name, inset);
3385 catch (ExceptionMessage const & ex) {
3393 bool GuiView::isDialogVisible(string const & name) const
3395 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
3396 if (it == d.dialogs_.end())
3398 return it->second.get()->isVisibleView() && !it->second.get()->isClosing();
3402 void GuiView::hideDialog(string const & name, Inset * inset)
3404 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
3405 if (it == d.dialogs_.end())
3408 if (inset && currentBufferView()
3409 && inset != currentBufferView()->editedInset(name))
3412 Dialog * const dialog = it->second.get();
3413 if (dialog->isVisibleView())
3415 if (currentBufferView())
3416 currentBufferView()->editInset(name, 0);
3420 void GuiView::disconnectDialog(string const & name)
3422 if (!isValidName(name))
3424 if (currentBufferView())
3425 currentBufferView()->editInset(name, 0);
3429 void GuiView::hideAll() const
3431 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
3432 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
3434 for(; it != end; ++it)
3435 it->second->hideView();
3439 void GuiView::updateDialogs()
3441 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
3442 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
3444 for(; it != end; ++it) {
3445 Dialog * dialog = it->second.get();
3447 if (dialog->isBufferDependent() && !documentBufferView())
3448 hideDialog(fromqstr(dialog->name()), 0);
3449 else if (dialog->isVisibleView())
3450 dialog->checkStatus();
3457 Dialog * createDialog(GuiView & lv, string const & name);
3459 // will be replaced by a proper factory...
3460 Dialog * createGuiAbout(GuiView & lv);
3461 Dialog * createGuiBibitem(GuiView & lv);
3462 Dialog * createGuiBibtex(GuiView & lv);
3463 Dialog * createGuiChanges(GuiView & lv);
3464 Dialog * createGuiCharacter(GuiView & lv);
3465 Dialog * createGuiCitation(GuiView & lv);
3466 Dialog * createGuiCompare(GuiView & lv);
3467 Dialog * createGuiDelimiter(GuiView & lv);
3468 Dialog * createGuiDocument(GuiView & lv);
3469 Dialog * createGuiErrorList(GuiView & lv);
3470 Dialog * createGuiExternal(GuiView & lv);
3471 Dialog * createGuiGraphics(GuiView & lv);
3472 Dialog * createGuiInclude(GuiView & lv);
3473 Dialog * createGuiIndex(GuiView & lv);
3474 Dialog * createGuiLabel(GuiView & lv);
3475 Dialog * createGuiListings(GuiView & lv);
3476 Dialog * createGuiLog(GuiView & lv);
3477 Dialog * createGuiMathMatrix(GuiView & lv);
3478 Dialog * createGuiNomenclature(GuiView & lv);
3479 Dialog * createGuiNote(GuiView & lv);
3480 Dialog * createGuiParagraph(GuiView & lv);
3481 Dialog * createGuiPhantom(GuiView & lv);
3482 Dialog * createGuiPreferences(GuiView & lv);
3483 Dialog * createGuiPrint(GuiView & lv);
3484 Dialog * createGuiPrintindex(GuiView & lv);
3485 Dialog * createGuiPrintNomencl(GuiView & lv);
3486 Dialog * createGuiRef(GuiView & lv);
3487 Dialog * createGuiSearch(GuiView & lv);
3488 Dialog * createGuiSearchAdv(GuiView & lv);
3489 Dialog * createGuiSendTo(GuiView & lv);
3490 Dialog * createGuiShowFile(GuiView & lv);
3491 Dialog * createGuiSpellchecker(GuiView & lv);
3492 Dialog * createGuiSymbols(GuiView & lv);
3493 Dialog * createGuiTabularCreate(GuiView & lv);
3494 Dialog * createGuiTexInfo(GuiView & lv);
3495 Dialog * createGuiToc(GuiView & lv);
3496 Dialog * createGuiThesaurus(GuiView & lv);
3497 Dialog * createGuiHyperlink(GuiView & lv);
3498 Dialog * createGuiViewSource(GuiView & lv);
3499 Dialog * createGuiWrap(GuiView & lv);
3500 Dialog * createGuiProgressView(GuiView & lv);
3504 Dialog * GuiView::build(string const & name)
3506 LASSERT(isValidName(name), return 0);
3508 Dialog * dialog = createDialog(*this, name);
3512 if (name == "aboutlyx")
3513 return createGuiAbout(*this);
3514 if (name == "bibitem")
3515 return createGuiBibitem(*this);
3516 if (name == "bibtex")
3517 return createGuiBibtex(*this);
3518 if (name == "changes")
3519 return createGuiChanges(*this);
3520 if (name == "character")
3521 return createGuiCharacter(*this);
3522 if (name == "citation")
3523 return createGuiCitation(*this);
3524 if (name == "compare")
3525 return createGuiCompare(*this);
3526 if (name == "document")
3527 return createGuiDocument(*this);
3528 if (name == "errorlist")
3529 return createGuiErrorList(*this);
3530 if (name == "external")
3531 return createGuiExternal(*this);
3533 return createGuiShowFile(*this);
3534 if (name == "findreplace")
3535 return createGuiSearch(*this);
3536 if (name == "findreplaceadv")
3537 return createGuiSearchAdv(*this);
3538 if (name == "graphics")
3539 return createGuiGraphics(*this);
3541 return createGuiHyperlink(*this);
3542 if (name == "include")
3543 return createGuiInclude(*this);
3544 if (name == "index")
3545 return createGuiIndex(*this);
3546 if (name == "index_print")
3547 return createGuiPrintindex(*this);
3548 if (name == "label")
3549 return createGuiLabel(*this);
3550 if (name == "listings")
3551 return createGuiListings(*this);
3553 return createGuiLog(*this);
3554 if (name == "mathdelimiter")
3555 return createGuiDelimiter(*this);
3556 if (name == "mathmatrix")
3557 return createGuiMathMatrix(*this);
3558 if (name == "nomenclature")
3559 return createGuiNomenclature(*this);
3560 if (name == "nomencl_print")
3561 return createGuiPrintNomencl(*this);
3563 return createGuiNote(*this);
3564 if (name == "paragraph")
3565 return createGuiParagraph(*this);
3566 if (name == "phantom")
3567 return createGuiPhantom(*this);
3568 if (name == "prefs")
3569 return createGuiPreferences(*this);
3570 if (name == "print")
3571 return createGuiPrint(*this);
3573 return createGuiRef(*this);
3574 if (name == "sendto")
3575 return createGuiSendTo(*this);
3576 if (name == "spellchecker")
3577 return createGuiSpellchecker(*this);
3578 if (name == "symbols")
3579 return createGuiSymbols(*this);
3580 if (name == "tabularcreate")
3581 return createGuiTabularCreate(*this);
3582 if (name == "texinfo")
3583 return createGuiTexInfo(*this);
3584 if (name == "thesaurus")
3585 return createGuiThesaurus(*this);
3587 return createGuiToc(*this);
3588 if (name == "view-source")
3589 return createGuiViewSource(*this);
3591 return createGuiWrap(*this);
3592 if (name == "progress")
3593 return createGuiProgressView(*this);
3599 } // namespace frontend
3602 #include "moc_GuiView.cpp"