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 "FileDialog.h"
20 #include "FontLoader.h"
21 #include "GuiApplication.h"
22 #include "GuiCommandBuffer.h"
23 #include "GuiCompleter.h"
24 #include "GuiWorkArea.h"
25 #include "GuiKeySymbol.h"
27 #include "GuiToolbar.h"
28 #include "LayoutBox.h"
32 #include "qt_helpers.h"
34 #include "frontends/alert.h"
36 #include "buffer_funcs.h"
38 #include "BufferList.h"
39 #include "BufferParams.h"
40 #include "BufferView.h"
41 #include "Converter.h"
43 #include "CutAndPaste.h"
45 #include "ErrorList.h"
47 #include "FuncStatus.h"
48 #include "FuncRequest.h"
56 #include "Paragraph.h"
57 #include "SpellChecker.h"
58 #include "TextClass.h"
63 #include "support/convert.h"
64 #include "support/debug.h"
65 #include "support/ExceptionMessage.h"
66 #include "support/FileName.h"
67 #include "support/filetools.h"
68 #include "support/gettext.h"
69 #include "support/ForkedCalls.h"
70 #include "support/lassert.h"
71 #include "support/lstrings.h"
72 #include "support/os.h"
73 #include "support/Package.h"
74 #include "support/Path.h"
75 #include "support/Systemcall.h"
76 #include "support/Timeout.h"
79 #include <QApplication>
80 #include <QCloseEvent>
82 #include <QDesktopWidget>
83 #include <QDragEnterEvent>
90 #include <QPixmapCache>
92 #include <QPushButton>
96 #include <QStackedWidget>
101 #include <QScrollBar>
103 #include <boost/bind.hpp>
105 #ifdef HAVE_SYS_TIME_H
106 # include <sys/time.h>
113 using namespace lyx::support;
120 class BackgroundWidget : public QWidget
125 LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
126 /// The text to be written on top of the pixmap
127 QString const text = lyx_version ?
128 qt_("version ") + lyx_version : qt_("unknown version");
129 splash_ = getPixmap("images/", "banner", "png");
131 QPainter pain(&splash_);
132 pain.setPen(QColor(0, 0, 0));
134 // The font used to display the version info
135 font.setStyleHint(QFont::SansSerif);
136 font.setWeight(QFont::Bold);
137 font.setPointSize(int(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble()));
139 pain.drawText(260, 15, text);
142 void paintEvent(QPaintEvent *)
144 int x = (width() - splash_.width()) / 2;
145 int y = (height() - splash_.height()) / 2;
147 pain.drawPixmap(x, y, splash_);
155 /// Toolbar store providing access to individual toolbars by name.
156 typedef std::map<std::string, GuiToolbar *> ToolbarMap;
158 typedef boost::shared_ptr<Dialog> DialogPtr;
163 struct GuiView::GuiViewPrivate
166 : current_work_area_(0), current_main_work_area_(0),
167 layout_(0), autosave_timeout_(5000),
170 // hardcode here the platform specific icon size
171 smallIconSize = 14; // scaling problems
172 normalIconSize = 20; // ok, default
173 bigIconSize = 26; // better for some math icons
175 splitter_ = new QSplitter;
176 bg_widget_ = new BackgroundWidget;
177 stack_widget_ = new QStackedWidget;
178 stack_widget_->addWidget(bg_widget_);
179 stack_widget_->addWidget(splitter_);
187 delete stack_widget_;
190 QMenu * toolBarPopup(GuiView * parent)
192 // FIXME: translation
193 QMenu * menu = new QMenu(parent);
194 QActionGroup * iconSizeGroup = new QActionGroup(parent);
196 QAction * smallIcons = new QAction(iconSizeGroup);
197 smallIcons->setText(qt_("Small-sized icons"));
198 smallIcons->setCheckable(true);
199 QObject::connect(smallIcons, SIGNAL(triggered()),
200 parent, SLOT(smallSizedIcons()));
201 menu->addAction(smallIcons);
203 QAction * normalIcons = new QAction(iconSizeGroup);
204 normalIcons->setText(qt_("Normal-sized icons"));
205 normalIcons->setCheckable(true);
206 QObject::connect(normalIcons, SIGNAL(triggered()),
207 parent, SLOT(normalSizedIcons()));
208 menu->addAction(normalIcons);
210 QAction * bigIcons = new QAction(iconSizeGroup);
211 bigIcons->setText(qt_("Big-sized icons"));
212 bigIcons->setCheckable(true);
213 QObject::connect(bigIcons, SIGNAL(triggered()),
214 parent, SLOT(bigSizedIcons()));
215 menu->addAction(bigIcons);
217 unsigned int cur = parent->iconSize().width();
218 if ( cur == parent->d.smallIconSize)
219 smallIcons->setChecked(true);
220 else if (cur == parent->d.normalIconSize)
221 normalIcons->setChecked(true);
222 else if (cur == parent->d.bigIconSize)
223 bigIcons->setChecked(true);
230 stack_widget_->setCurrentWidget(bg_widget_);
231 bg_widget_->setUpdatesEnabled(true);
234 TabWorkArea * tabWorkArea(int i)
236 return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
239 TabWorkArea * currentTabWorkArea()
241 if (splitter_->count() == 1)
242 // The first TabWorkArea is always the first one, if any.
243 return tabWorkArea(0);
245 for (int i = 0; i != splitter_->count(); ++i) {
246 TabWorkArea * twa = tabWorkArea(i);
247 if (current_main_work_area_ == twa->currentWorkArea())
251 // None has the focus so we just take the first one.
252 return tabWorkArea(0);
256 GuiWorkArea * current_work_area_;
257 GuiWorkArea * current_main_work_area_;
258 QSplitter * splitter_;
259 QStackedWidget * stack_widget_;
260 BackgroundWidget * bg_widget_;
262 ToolbarMap toolbars_;
263 /// The main layout box.
265 * \warning Don't Delete! The layout box is actually owned by
266 * whichever toolbar contains it. All the GuiView class needs is a
267 * means of accessing it.
269 * FIXME: replace that with a proper model so that we are not limited
270 * to only one dialog.
275 map<string, Inset *> open_insets_;
278 map<string, DialogPtr> dialogs_;
280 unsigned int smallIconSize;
281 unsigned int normalIconSize;
282 unsigned int bigIconSize;
284 QTimer statusbar_timer_;
285 /// auto-saving of buffers
286 Timeout autosave_timeout_;
287 /// flag against a race condition due to multiclicks, see bug #1119
291 TocModels toc_models_;
295 GuiView::GuiView(int id)
296 : d(*new GuiViewPrivate), id_(id), closing_(false)
298 // GuiToolbars *must* be initialised before the menu bar.
299 normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
302 // set ourself as the current view. This is needed for the menu bar
303 // filling, at least for the static special menu item on Mac. Otherwise
304 // they are greyed out.
305 theLyXFunc().setLyXView(this);
307 // Fill up the menu bar.
308 guiApp->menus().fillMenuBar(menuBar(), this, true);
310 setCentralWidget(d.stack_widget_);
312 // Start autosave timer
313 if (lyxrc.autosave) {
314 d.autosave_timeout_.timeout.connect(boost::bind(&GuiView::autoSave, this));
315 d.autosave_timeout_.setTimeout(lyxrc.autosave * 1000);
316 d.autosave_timeout_.start();
318 connect(&d.statusbar_timer_, SIGNAL(timeout()),
319 this, SLOT(clearMessage()));
321 // We don't want to keep the window in memory if it is closed.
322 setAttribute(Qt::WA_DeleteOnClose, true);
324 #if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX))
325 // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
326 // since the icon is provided in the application bundle.
327 setWindowIcon(getPixmap("images/", "lyx", "png"));
331 setAcceptDrops(true);
333 statusBar()->setSizeGripEnabled(true);
335 // Forbid too small unresizable window because it can happen
336 // with some window manager under X11.
337 setMinimumSize(300, 200);
339 if (lyxrc.allow_geometry_session) {
340 // Now take care of session management.
345 // no session handling, default to a sane size.
346 setGeometry(50, 50, 690, 510);
349 // clear session data if any.
351 settings.remove("views");
361 void GuiView::saveLayout() const
364 settings.beginGroup("views");
365 settings.beginGroup(QString::number(id_));
367 settings.setValue("pos", pos());
368 settings.setValue("size", size());
370 settings.setValue("geometry", saveGeometry());
372 settings.setValue("layout", saveState(0));
373 settings.setValue("icon_size", iconSize());
377 bool GuiView::restoreLayout()
380 settings.beginGroup("views");
381 settings.beginGroup(QString::number(id_));
382 QString const icon_key = "icon_size";
383 if (!settings.contains(icon_key))
386 //code below is skipped when when ~/.config/LyX is (re)created
387 setIconSize(settings.value(icon_key).toSize());
389 QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
390 QSize size = settings.value("size", QSize(690, 510)).toSize();
394 // Work-around for bug #6034: the window ends up in an undetermined
395 // state when trying to restore a maximized window when it is
396 // already maximized.
397 if (!(windowState() & Qt::WindowMaximized))
398 if (!restoreGeometry(settings.value("geometry").toByteArray()))
399 setGeometry(50, 50, 690, 510);
401 // Make sure layout is correctly oriented.
402 setLayoutDirection(qApp->layoutDirection());
404 // Allow the toc and view-source dock widget to be restored if needed.
406 if ((dialog = findOrBuild("toc", true)))
407 // see bug 5082. At least setup title and enabled state.
408 // Visibility will be adjusted by restoreState below.
409 dialog->prepareView();
410 if ((dialog = findOrBuild("view-source", true)))
411 dialog->prepareView();
413 if (!restoreState(settings.value("layout").toByteArray(), 0))
420 GuiToolbar * GuiView::toolbar(string const & name)
422 ToolbarMap::iterator it = d.toolbars_.find(name);
423 if (it != d.toolbars_.end())
426 LYXERR(Debug::GUI, "Toolbar::display: no toolbar named " << name);
427 message(bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name)));
432 void GuiView::constructToolbars()
434 ToolbarMap::iterator it = d.toolbars_.begin();
435 for (; it != d.toolbars_.end(); ++it)
439 // I don't like doing this here, but the standard toolbar
440 // destroys this object when it's destroyed itself (vfr)
441 d.layout_ = new LayoutBox(*this);
442 d.stack_widget_->addWidget(d.layout_);
443 d.layout_->move(0,0);
445 // extracts the toolbars from the backend
446 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
447 Toolbars::Infos::iterator end = guiApp->toolbars().end();
448 for (; cit != end; ++cit)
449 d.toolbars_[cit->name] = new GuiToolbar(*cit, *this);
453 void GuiView::initToolbars()
455 // extracts the toolbars from the backend
456 Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
457 Toolbars::Infos::iterator end = guiApp->toolbars().end();
458 for (; cit != end; ++cit) {
459 GuiToolbar * tb = toolbar(cit->name);
462 int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
464 tb->setVisible(false);
465 tb->setVisibility(visibility);
467 if (visibility & Toolbars::TOP) {
469 addToolBarBreak(Qt::TopToolBarArea);
470 addToolBar(Qt::TopToolBarArea, tb);
473 if (visibility & Toolbars::BOTTOM) {
474 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
475 #if (QT_VERSION >= 0x040202)
476 addToolBarBreak(Qt::BottomToolBarArea);
478 addToolBar(Qt::BottomToolBarArea, tb);
481 if (visibility & Toolbars::LEFT) {
482 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
483 #if (QT_VERSION >= 0x040202)
484 addToolBarBreak(Qt::LeftToolBarArea);
486 addToolBar(Qt::LeftToolBarArea, tb);
489 if (visibility & Toolbars::RIGHT) {
490 // Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
491 #if (QT_VERSION >= 0x040202)
492 addToolBarBreak(Qt::RightToolBarArea);
494 addToolBar(Qt::RightToolBarArea, tb);
497 if (visibility & Toolbars::ON)
498 tb->setVisible(true);
503 TocModels & GuiView::tocModels()
505 return d.toc_models_;
509 void GuiView::setFocus()
511 LYXERR(Debug::DEBUG, "GuiView::setFocus()" << this);
512 // Make sure LyXFunc points to the correct view.
513 guiApp->setCurrentView(this);
514 theLyXFunc().setLyXView(this);
515 QMainWindow::setFocus();
516 if (d.current_work_area_)
517 d.current_work_area_->setFocus();
521 QMenu * GuiView::createPopupMenu()
523 return d.toolBarPopup(this);
527 void GuiView::showEvent(QShowEvent * e)
529 LYXERR(Debug::GUI, "Passed Geometry "
530 << size().height() << "x" << size().width()
531 << "+" << pos().x() << "+" << pos().y());
533 if (d.splitter_->count() == 0)
534 // No work area, switch to the background widget.
537 QMainWindow::showEvent(e);
541 /** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
542 ** is responsibility of the container (e.g., dialog)
544 void GuiView::closeEvent(QCloseEvent * close_event)
546 LYXERR(Debug::DEBUG, "GuiView::closeEvent()");
551 // it can happen that this event arrives without selecting the view,
552 // e.g. when clicking the close button on a background window.
554 if (!closeWorkAreaAll()) {
556 close_event->ignore();
560 // Make sure that nothing will use this to be closed View.
561 guiApp->unregisterView(this);
563 if (isFullScreen()) {
564 // Switch off fullscreen before closing.
569 // Make sure the timer time out will not trigger a statusbar update.
570 d.statusbar_timer_.stop();
572 // Saving fullscreen requires additional tweaks in the toolbar code.
573 // It wouldn't also work under linux natively.
574 if (lyxrc.allow_geometry_session) {
575 // Save this window geometry and layout.
577 // Then the toolbar private states.
578 ToolbarMap::iterator end = d.toolbars_.end();
579 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
580 it->second->saveSession();
581 // Now take care of all other dialogs:
582 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
583 for (; it!= d.dialogs_.end(); ++it)
584 it->second->saveSession();
587 close_event->accept();
591 void GuiView::dragEnterEvent(QDragEnterEvent * event)
593 if (event->mimeData()->hasUrls())
595 /// \todo Ask lyx-devel is this is enough:
596 /// if (event->mimeData()->hasFormat("text/plain"))
597 /// event->acceptProposedAction();
601 void GuiView::dropEvent(QDropEvent * event)
603 QList<QUrl> files = event->mimeData()->urls();
607 LYXERR(Debug::GUI, "GuiView::dropEvent: got URLs!");
608 for (int i = 0; i != files.size(); ++i) {
609 string const file = os::internal_path(fromqstr(
610 files.at(i).toLocalFile()));
612 // Asynchronously post the event. DropEvent usually come
613 // from the BufferView. But reloading a file might close
614 // the BufferView from within its own event handler.
615 guiApp->dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, file));
622 void GuiView::message(docstring const & str)
624 if (ForkedProcess::iAmAChild())
627 statusBar()->showMessage(toqstr(str));
628 d.statusbar_timer_.stop();
629 d.statusbar_timer_.start(3000);
633 void GuiView::smallSizedIcons()
635 setIconSize(QSize(d.smallIconSize, d.smallIconSize));
639 void GuiView::normalSizedIcons()
641 setIconSize(QSize(d.normalIconSize, d.normalIconSize));
645 void GuiView::bigSizedIcons()
647 setIconSize(QSize(d.bigIconSize, d.bigIconSize));
651 void GuiView::clearMessage()
655 theLyXFunc().setLyXView(this);
656 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
657 d.statusbar_timer_.stop();
661 void GuiView::updateWindowTitle(GuiWorkArea * wa)
663 if (wa != d.current_work_area_)
665 setWindowTitle(qt_("LyX: ") + wa->windowTitle());
666 setWindowIconText(wa->windowIconText());
670 void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
673 disconnectBufferView();
674 connectBufferView(wa->bufferView());
675 connectBuffer(wa->bufferView().buffer());
676 d.current_work_area_ = wa;
677 QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
678 this, SLOT(updateWindowTitle(GuiWorkArea *)));
679 updateWindowTitle(wa);
683 // The document settings needs to be reinitialised.
684 updateDialog("document", "");
686 // Buffer-dependent dialogs must be updated. This is done here because
687 // some dialogs require buffer()->text.
692 void GuiView::on_lastWorkAreaRemoved()
695 // We already are in a close event. Nothing more to do.
698 if (d.splitter_->count() > 1)
699 // We have a splitter so don't close anything.
702 // Reset and updates the dialogs.
703 d.toc_models_.reset(0);
704 updateDialog("document", "");
707 resetWindowTitleAndIconText();
709 if (lyxrc.open_buffers_in_tabs)
710 // Nothing more to do, the window should stay open.
713 if (guiApp->viewIds().size() > 1) {
719 // On Mac we also close the last window because the application stay
720 // resident in memory. On other platforms we don't close the last
721 // window because this would quit the application.
727 void GuiView::updateStatusBar()
729 // let the user see the explicit message
730 if (d.statusbar_timer_.isActive())
733 theLyXFunc().setLyXView(this);
734 statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
738 bool GuiView::hasFocus() const
740 return qApp->activeWindow() == this;
744 bool GuiView::event(QEvent * e)
748 // Useful debug code:
749 //case QEvent::ActivationChange:
750 //case QEvent::WindowDeactivate:
751 //case QEvent::Paint:
752 //case QEvent::Enter:
753 //case QEvent::Leave:
754 //case QEvent::HoverEnter:
755 //case QEvent::HoverLeave:
756 //case QEvent::HoverMove:
757 //case QEvent::StatusTip:
758 //case QEvent::DragEnter:
759 //case QEvent::DragLeave:
763 case QEvent::WindowActivate: {
764 if (this == guiApp->currentView()) {
766 return QMainWindow::event(e);
768 guiApp->setCurrentView(this);
769 theLyXFunc().setLyXView(this);
770 if (d.current_work_area_) {
771 BufferView & bv = d.current_work_area_->bufferView();
772 connectBufferView(bv);
773 connectBuffer(bv.buffer());
774 // The document structure, name and dialogs might have
775 // changed in another view.
777 // The document settings needs to be reinitialised.
778 updateDialog("document", "");
781 resetWindowTitleAndIconText();
784 return QMainWindow::event(e);
787 case QEvent::ShortcutOverride: {
790 #if (!defined Q_WS_X11) || (QT_VERSION >= 0x040500)
791 if (isFullScreen() && menuBar()->isHidden()) {
792 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
793 // FIXME: we should also try to detect special LyX shortcut such as
794 // Alt-P and Alt-M. Right now there is a hack in
795 // GuiWorkArea::processKeySym() that hides again the menubar for
797 if (ke->modifiers() & Qt::AltModifier && ke->key() != Qt::Key_Alt) {
799 return QMainWindow::event(e);
804 if (d.current_work_area_)
805 // Nothing special to do.
806 return QMainWindow::event(e);
808 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
809 // Let Qt handle menu access and the Tab keys to navigate keys to navigate
811 if (ke->modifiers() & Qt::AltModifier || ke->key() == Qt::Key_Tab
812 || ke->key() == Qt::Key_Backtab)
813 return QMainWindow::event(e);
815 // Allow processing of shortcuts that are allowed even when no Buffer
817 theLyXFunc().setLyXView(this);
819 setKeySymbol(&sym, ke);
820 theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
826 return QMainWindow::event(e);
830 void GuiView::resetWindowTitleAndIconText()
832 setWindowTitle(qt_("LyX"));
833 setWindowIconText(qt_("LyX"));
836 bool GuiView::focusNextPrevChild(bool /*next*/)
843 void GuiView::setBusy(bool busy)
845 if (d.current_work_area_) {
846 d.current_work_area_->setUpdatesEnabled(!busy);
848 d.current_work_area_->stopBlinkingCursor();
850 d.current_work_area_->startBlinkingCursor();
854 QApplication::setOverrideCursor(Qt::WaitCursor);
856 QApplication::restoreOverrideCursor();
860 GuiWorkArea * GuiView::workArea(Buffer & buffer)
862 if (currentWorkArea()
863 && ¤tWorkArea()->bufferView().buffer() == &buffer)
864 return (GuiWorkArea *) currentWorkArea();
865 if (TabWorkArea * twa = d.currentTabWorkArea())
866 return twa->workArea(buffer);
871 GuiWorkArea * GuiView::addWorkArea(Buffer & buffer)
873 // Automatically create a TabWorkArea if there are none yet.
874 TabWorkArea * tab_widget = d.splitter_->count()
875 ? d.currentTabWorkArea() : addTabWorkArea();
876 return tab_widget->addWorkArea(buffer, *this);
880 TabWorkArea * GuiView::addTabWorkArea()
882 TabWorkArea * twa = new TabWorkArea;
883 QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
884 this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
885 QObject::connect(twa, SIGNAL(lastWorkAreaRemoved()),
886 this, SLOT(on_lastWorkAreaRemoved()));
888 d.splitter_->addWidget(twa);
889 d.stack_widget_->setCurrentWidget(d.splitter_);
894 GuiWorkArea const * GuiView::currentWorkArea() const
896 return d.current_work_area_;
900 GuiWorkArea * GuiView::currentWorkArea()
902 return d.current_work_area_;
906 GuiWorkArea const * GuiView::currentMainWorkArea() const
908 if (d.currentTabWorkArea() == NULL)
910 return d.currentTabWorkArea()->currentWorkArea();
914 GuiWorkArea * GuiView::currentMainWorkArea()
916 if (d.currentTabWorkArea() == NULL)
918 return d.currentTabWorkArea()->currentWorkArea();
922 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
924 LYXERR(Debug::DEBUG, "Setting current wa: " << wa << endl);
926 d.current_work_area_ = NULL;
930 GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
934 if (currentBufferView())
935 cap::saveSelection(currentBufferView()->cursor());
937 theGuiApp()->setCurrentView(this);
938 d.current_work_area_ = wa;
939 for (int i = 0; i != d.splitter_->count(); ++i) {
940 if (d.tabWorkArea(i)->setCurrentWorkArea(wa)) {
941 //if (d.current_main_work_area_)
942 // d.current_main_work_area_->setFrameStyle(QFrame::NoFrame);
943 d.current_main_work_area_ = wa;
944 //d.current_main_work_area_->setFrameStyle(QFrame::Box | QFrame::Plain);
945 //d.current_main_work_area_->setLineWidth(2);
946 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
950 LYXERR(Debug::DEBUG, "This is not a tabbed wa");
951 on_currentWorkAreaChanged(wa);
952 BufferView & bv = wa->bufferView();
953 bv.cursor().fixIfBroken();
955 wa->setUpdatesEnabled(true);
956 LYXERR(Debug::DEBUG, "Current wa: " << currentWorkArea() << ", Current main wa: " << currentMainWorkArea());
960 void GuiView::removeWorkArea(GuiWorkArea * wa)
963 if (wa == d.current_work_area_) {
965 disconnectBufferView();
966 d.current_work_area_ = 0;
967 d.current_main_work_area_ = 0;
970 bool found_twa = false;
971 for (int i = 0; i != d.splitter_->count(); ++i) {
972 TabWorkArea * twa = d.tabWorkArea(i);
973 if (twa->removeWorkArea(wa)) {
974 // Found in this tab group, and deleted the GuiWorkArea.
976 if (twa->count() != 0) {
977 if (d.current_work_area_ == 0)
978 // This means that we are closing the current GuiWorkArea, so
979 // switch to the next GuiWorkArea in the found TabWorkArea.
980 setCurrentWorkArea(twa->currentWorkArea());
982 // No more WorkAreas in this tab group, so delete it.
989 // It is not a tabbed work area (i.e., the search work area), so it
990 // should be deleted by other means.
991 LASSERT(found_twa, /* */);
993 if (d.current_work_area_ == 0) {
994 if (d.splitter_->count() != 0) {
995 TabWorkArea * twa = d.currentTabWorkArea();
996 setCurrentWorkArea(twa->currentWorkArea());
998 // No more work areas, switch to the background widget.
999 setCurrentWorkArea(0);
1005 LayoutBox * GuiView::getLayoutDialog() const
1011 void GuiView::updateLayoutList()
1014 d.layout_->updateContents(false);
1018 void GuiView::updateToolbars()
1020 ToolbarMap::iterator end = d.toolbars_.end();
1021 if (d.current_work_area_) {
1023 d.current_work_area_->bufferView().cursor().inMathed();
1025 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
1027 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
1028 lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
1029 bool const mathmacrotemplate =
1030 lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
1032 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1033 it->second->update(math, table, review, mathmacrotemplate);
1035 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
1036 it->second->update(false, false, false, false);
1040 void GuiView::setBuffer(Buffer * newBuffer)
1042 LYXERR(Debug::DEBUG, "Setting buffer: " << newBuffer << std::endl);
1043 LASSERT(newBuffer, return);
1046 GuiWorkArea * wa = workArea(*newBuffer);
1048 newBuffer->masterBuffer()->updateLabels();
1049 wa = addWorkArea(*newBuffer);
1051 //Disconnect the old buffer...there's no new one.
1054 connectBuffer(*newBuffer);
1055 connectBufferView(wa->bufferView());
1056 setCurrentWorkArea(wa);
1062 void GuiView::connectBuffer(Buffer & buf)
1064 buf.setGuiDelegate(this);
1068 void GuiView::disconnectBuffer()
1070 if (d.current_work_area_)
1071 d.current_work_area_->bufferView().buffer().setGuiDelegate(0);
1075 void GuiView::connectBufferView(BufferView & bv)
1077 bv.setGuiDelegate(this);
1081 void GuiView::disconnectBufferView()
1083 if (d.current_work_area_)
1084 d.current_work_area_->bufferView().setGuiDelegate(0);
1088 void GuiView::errors(string const & error_type, bool from_master)
1090 ErrorList & el = from_master ?
1091 documentBufferView()->buffer().masterBuffer()->errorList(error_type)
1092 : documentBufferView()->buffer().errorList(error_type);
1093 string data = error_type;
1095 data = "from_master|" + error_type;
1097 showDialog("errorlist", data);
1101 void GuiView::updateTocItem(std::string const & type, DocIterator const & dit)
1103 d.toc_models_.updateItem(toqstr(type), dit);
1107 void GuiView::structureChanged()
1109 d.toc_models_.reset(documentBufferView());
1110 // Navigator needs more than a simple update in this case. It needs to be
1112 updateDialog("toc", "");
1116 void GuiView::updateDialog(string const & name, string const & data)
1118 if (!isDialogVisible(name))
1121 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
1122 if (it == d.dialogs_.end())
1125 Dialog * const dialog = it->second.get();
1126 if (dialog->isVisibleView())
1127 dialog->initialiseParams(data);
1131 BufferView * GuiView::documentBufferView()
1133 return currentMainWorkArea()
1134 ? ¤tMainWorkArea()->bufferView()
1139 BufferView const * GuiView::documentBufferView() const
1141 return currentMainWorkArea()
1142 ? ¤tMainWorkArea()->bufferView()
1147 BufferView * GuiView::currentBufferView()
1149 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1153 BufferView const * GuiView::currentBufferView() const
1155 return d.current_work_area_ ? &d.current_work_area_->bufferView() : 0;
1159 void GuiView::autoSave()
1161 LYXERR(Debug::INFO, "Running autoSave()");
1163 if (documentBufferView())
1164 documentBufferView()->buffer().autoSave();
1168 void GuiView::resetAutosaveTimers()
1171 d.autosave_timeout_.restart();
1175 bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
1178 Buffer * buf = currentBufferView()
1179 ? ¤tBufferView()->buffer() : 0;
1180 Buffer * doc_buffer = documentBufferView()
1181 ? &(documentBufferView()->buffer()) : 0;
1183 if (cmd.origin == FuncRequest::TOC) {
1184 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
1186 if (toc->getStatus(documentBufferView()->cursor(), cmd, fs))
1189 flag.setEnabled(false);
1193 switch(cmd.action) {
1194 case LFUN_BUFFER_IMPORT:
1197 case LFUN_BUFFER_RELOAD:
1198 enable = doc_buffer && !doc_buffer->isUnnamed()
1199 && doc_buffer->fileName().exists()
1200 && (!doc_buffer->isClean()
1201 || doc_buffer->isExternallyModified(Buffer::timestamp_method));
1204 case LFUN_BUFFER_WRITE:
1205 enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
1208 case LFUN_BUFFER_WRITE_AS:
1209 enable = doc_buffer;
1212 case LFUN_BUFFER_CLOSE_ALL:
1213 enable = theBufferList().last() != theBufferList().first();
1216 case LFUN_SPLIT_VIEW:
1217 if (cmd.getArg(0) == "vertical")
1218 enable = doc_buffer && (d.splitter_->count() == 1 ||
1219 d.splitter_->orientation() == Qt::Vertical);
1221 enable = doc_buffer && (d.splitter_->count() == 1 ||
1222 d.splitter_->orientation() == Qt::Horizontal);
1225 case LFUN_CLOSE_TAB_GROUP:
1226 enable = d.currentTabWorkArea();
1229 case LFUN_TOOLBAR_TOGGLE:
1230 if (GuiToolbar * t = toolbar(cmd.getArg(0)))
1231 flag.setOnOff(t->isVisible());
1234 case LFUN_UI_TOGGLE:
1235 flag.setOnOff(isFullScreen());
1238 case LFUN_DIALOG_DISCONNECT_INSET:
1241 case LFUN_DIALOG_HIDE:
1242 // FIXME: should we check if the dialog is shown?
1245 case LFUN_DIALOG_TOGGLE:
1246 flag.setOnOff(isDialogVisible(cmd.getArg(0)));
1247 // fall through to set "enable"
1248 case LFUN_DIALOG_SHOW: {
1249 string const name = cmd.getArg(0);
1251 enable = name == "aboutlyx"
1252 || name == "file" //FIXME: should be removed.
1254 || name == "texinfo";
1255 else if (name == "print")
1256 enable = doc_buffer->isExportable("dvi")
1257 && lyxrc.print_command != "none";
1258 else if (name == "character" || name == "symbols") {
1259 if (!buf || buf->isReadonly()
1260 || !currentBufferView()->cursor().inTexted())
1263 // FIXME we should consider passthru
1265 Inset const & in = currentBufferView()->cursor().inset();
1266 enable = !in.getLayout().isPassThru();
1269 else if (name == "latexlog")
1270 enable = FileName(doc_buffer->logName()).isReadableFile();
1271 else if (name == "spellchecker")
1272 enable = theSpellChecker() && !doc_buffer->isReadonly();
1273 else if (name == "vclog")
1274 enable = doc_buffer->lyxvc().inUse();
1278 case LFUN_DIALOG_UPDATE: {
1279 string const name = cmd.getArg(0);
1281 enable = name == "prefs";
1285 case LFUN_COMMAND_EXECUTE:
1287 case LFUN_MENU_OPEN:
1288 // Nothing to check.
1291 case LFUN_INSET_APPLY: {
1292 string const name = cmd.getArg(0);
1293 Inset * inset = getOpenInset(name);
1295 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
1297 if (!inset->getStatus(currentBufferView()->cursor(), fr, fs)) {
1298 // Every inset is supposed to handle this
1299 LASSERT(false, break);
1303 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
1304 flag |= lyx::getStatus(fr);
1306 enable = flag.enabled();
1310 case LFUN_COMPLETION_INLINE:
1311 if (!d.current_work_area_
1312 || !d.current_work_area_->completer().inlinePossible(
1313 currentBufferView()->cursor()))
1317 case LFUN_COMPLETION_POPUP:
1318 if (!d.current_work_area_
1319 || !d.current_work_area_->completer().popupPossible(
1320 currentBufferView()->cursor()))
1324 case LFUN_COMPLETION_COMPLETE:
1325 if (!d.current_work_area_
1326 || !d.current_work_area_->completer().inlinePossible(
1327 currentBufferView()->cursor()))
1331 case LFUN_COMPLETION_ACCEPT:
1332 if (!d.current_work_area_
1333 || (!d.current_work_area_->completer().popupVisible()
1334 && !d.current_work_area_->completer().inlineVisible()
1335 && !d.current_work_area_->completer().completionAvailable()))
1339 case LFUN_COMPLETION_CANCEL:
1340 if (!d.current_work_area_
1341 || (!d.current_work_area_->completer().popupVisible()
1342 && !d.current_work_area_->completer().inlineVisible()))
1346 case LFUN_BUFFER_ZOOM_OUT:
1347 enable = doc_buffer && lyxrc.zoom > 10;
1350 case LFUN_BUFFER_ZOOM_IN:
1351 enable = doc_buffer;
1354 case LFUN_BUFFER_NEXT:
1355 case LFUN_BUFFER_PREVIOUS:
1356 // FIXME: should we check is there is an previous or next buffer?
1358 case LFUN_BUFFER_SWITCH:
1359 // toggle on the current buffer, but do not toggle off
1360 // the other ones (is that a good idea?)
1362 && to_utf8(cmd.argument()) == doc_buffer->absFileName())
1363 flag.setOnOff(true);
1366 case LFUN_VC_REGISTER:
1367 enable = doc_buffer && !doc_buffer->lyxvc().inUse();
1369 case LFUN_VC_CHECK_IN:
1370 enable = doc_buffer && doc_buffer->lyxvc().checkInEnabled();
1372 case LFUN_VC_CHECK_OUT:
1373 enable = doc_buffer && doc_buffer->lyxvc().checkOutEnabled();
1375 case LFUN_VC_LOCKING_TOGGLE:
1376 enable = doc_buffer && !doc_buffer->isReadonly()
1377 && doc_buffer->lyxvc().lockingToggleEnabled();
1378 flag.setOnOff(enable && !doc_buffer->lyxvc().locker().empty());
1380 case LFUN_VC_REVERT:
1381 enable = doc_buffer && doc_buffer->lyxvc().inUse();
1383 case LFUN_VC_UNDO_LAST:
1384 enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
1386 case LFUN_VC_COMMAND: {
1387 if (cmd.argument().empty())
1389 if (!doc_buffer && contains(cmd.getArg(0), 'D'))
1399 flag.setEnabled(false);
1405 static FileName selectTemplateFile()
1407 FileDialog dlg(qt_("Select template file"));
1408 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1409 dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
1411 FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
1412 QStringList(qt_("LyX Documents (*.lyx)")));
1414 if (result.first == FileDialog::Later)
1416 if (result.second.isEmpty())
1418 return FileName(fromqstr(result.second));
1422 Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
1426 Buffer * newBuffer = checkAndLoadLyXFile(filename);
1429 message(_("Document not loaded."));
1434 setBuffer(newBuffer);
1436 // scroll to the position when the file was last closed
1437 if (lyxrc.use_lastfilepos) {
1438 LastFilePosSection::FilePos filepos =
1439 theSession().lastFilePos().load(filename);
1440 documentBufferView()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
1444 theSession().lastFiles().add(filename);
1451 void GuiView::openDocument(string const & fname)
1453 string initpath = lyxrc.document_path;
1455 if (documentBufferView()) {
1456 string const trypath = documentBufferView()->buffer().filePath();
1457 // If directory is writeable, use this as default.
1458 if (FileName(trypath).isDirWritable())
1464 if (fname.empty()) {
1465 FileDialog dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
1466 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1467 dlg.setButton2(qt_("Examples|#E#e"),
1468 toqstr(addPath(package().system_support().absFilename(), "examples")));
1470 QStringList filter(qt_("LyX Documents (*.lyx)"));
1471 filter << qt_("LyX-1.3.x Documents (*.lyx13)")
1472 << qt_("LyX-1.4.x Documents (*.lyx14)")
1473 << qt_("LyX-1.5.x Documents (*.lyx15)")
1474 << qt_("LyX-1.6.x Documents (*.lyx16)");
1475 FileDialog::Result result =
1476 dlg.open(toqstr(initpath), filter);
1478 if (result.first == FileDialog::Later)
1481 filename = fromqstr(result.second);
1483 // check selected filename
1484 if (filename.empty()) {
1485 message(_("Canceled."));
1491 // get absolute path of file and add ".lyx" to the filename if
1493 FileName const fullname =
1494 fileSearch(string(), filename, "lyx", support::may_not_exist);
1495 if (!fullname.empty())
1496 filename = fullname.absFilename();
1498 if (!fullname.onlyPath().isDirectory()) {
1499 Alert::warning(_("Invalid filename"),
1500 bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
1501 from_utf8(fullname.absFilename())));
1504 // if the file doesn't exist, let the user create one
1505 if (!fullname.exists()) {
1506 // the user specifically chose this name. Believe him.
1507 Buffer * const b = newFile(filename, string(), true);
1513 docstring const disp_fn = makeDisplayPath(filename);
1514 message(bformat(_("Opening document %1$s..."), disp_fn));
1517 Buffer * buf = loadDocument(fullname);
1519 buf->updateLabels();
1521 buf->errors("Parse");
1522 str2 = bformat(_("Document %1$s opened."), disp_fn);
1523 if (buf->lyxvc().inUse())
1524 str2 += " " + from_utf8(buf->lyxvc().versionString()) +
1525 " " + _("Version control detected.");
1527 str2 = bformat(_("Could not open document %1$s"), disp_fn);
1532 // FIXME: clean that
1533 static bool import(GuiView * lv, FileName const & filename,
1534 string const & format, ErrorList & errorList)
1536 FileName const lyxfile(support::changeExtension(filename.absFilename(), ".lyx"));
1538 string loader_format;
1539 vector<string> loaders = theConverters().loaders();
1540 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
1541 for (vector<string>::const_iterator it = loaders.begin();
1542 it != loaders.end(); ++it) {
1543 if (!theConverters().isReachable(format, *it))
1546 string const tofile =
1547 support::changeExtension(filename.absFilename(),
1548 formats.extension(*it));
1549 if (!theConverters().convert(0, filename, FileName(tofile),
1550 filename, format, *it, errorList))
1552 loader_format = *it;
1555 if (loader_format.empty()) {
1556 frontend::Alert::error(_("Couldn't import file"),
1557 bformat(_("No information for importing the format %1$s."),
1558 formats.prettyName(format)));
1562 loader_format = format;
1564 if (loader_format == "lyx") {
1565 Buffer * buf = lv->loadDocument(lyxfile);
1568 buf->updateLabels();
1570 buf->errors("Parse");
1572 Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
1576 bool as_paragraphs = loader_format == "textparagraph";
1577 string filename2 = (loader_format == format) ? filename.absFilename()
1578 : support::changeExtension(filename.absFilename(),
1579 formats.extension(loader_format));
1580 lv->currentBufferView()->insertPlaintextFile(FileName(filename2),
1582 theLyXFunc().setLyXView(lv);
1583 lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
1590 void GuiView::importDocument(string const & argument)
1593 string filename = split(argument, format, ' ');
1595 LYXERR(Debug::INFO, format << " file: " << filename);
1597 // need user interaction
1598 if (filename.empty()) {
1599 string initpath = lyxrc.document_path;
1600 if (documentBufferView()) {
1601 string const trypath = documentBufferView()->buffer().filePath();
1602 // If directory is writeable, use this as default.
1603 if (FileName(trypath).isDirWritable())
1607 docstring const text = bformat(_("Select %1$s file to import"),
1608 formats.prettyName(format));
1610 FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
1611 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1612 dlg.setButton2(qt_("Examples|#E#e"),
1613 toqstr(addPath(package().system_support().absFilename(), "examples")));
1615 docstring filter = formats.prettyName(format);
1618 filter += from_utf8(formats.extension(format));
1621 FileDialog::Result result =
1622 dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
1624 if (result.first == FileDialog::Later)
1627 filename = fromqstr(result.second);
1629 // check selected filename
1630 if (filename.empty())
1631 message(_("Canceled."));
1634 if (filename.empty())
1637 // get absolute path of file
1638 FileName const fullname(support::makeAbsPath(filename));
1640 FileName const lyxfile(support::changeExtension(fullname.absFilename(), ".lyx"));
1642 // Check if the document already is open
1643 Buffer * buf = theBufferList().getBuffer(lyxfile);
1646 if (!closeBuffer()) {
1647 message(_("Canceled."));
1652 docstring const displaypath = makeDisplayPath(lyxfile.absFilename(), 30);
1654 // if the file exists already, and we didn't do
1655 // -i lyx thefile.lyx, warn
1656 if (lyxfile.exists() && fullname != lyxfile) {
1658 docstring text = bformat(_("The document %1$s already exists.\n\n"
1659 "Do you want to overwrite that document?"), displaypath);
1660 int const ret = Alert::prompt(_("Overwrite document?"),
1661 text, 0, 1, _("&Overwrite"), _("&Cancel"));
1664 message(_("Canceled."));
1669 message(bformat(_("Importing %1$s..."), displaypath));
1670 ErrorList errorList;
1671 if (import(this, fullname, format, errorList))
1672 message(_("imported."));
1674 message(_("file not imported!"));
1676 // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
1680 void GuiView::newDocument(string const & filename, bool from_template)
1682 FileName initpath(lyxrc.document_path);
1683 if (documentBufferView()) {
1684 FileName const trypath(documentBufferView()->buffer().filePath());
1685 // If directory is writeable, use this as default.
1686 if (trypath.isDirWritable())
1690 string templatefile;
1691 if (from_template) {
1692 templatefile = selectTemplateFile().absFilename();
1693 if (templatefile.empty())
1698 if (filename.empty())
1699 b = newUnnamedFile(templatefile, initpath);
1701 b = newFile(filename, templatefile, true);
1706 // If no new document could be created, it is unsure
1707 // whether there is a valid BufferView.
1708 if (currentBufferView())
1709 // Ensure the cursor is correctly positioned on screen.
1710 currentBufferView()->showCursor();
1714 void GuiView::insertLyXFile(docstring const & fname)
1716 BufferView * bv = documentBufferView();
1721 FileName filename(to_utf8(fname));
1723 if (!filename.empty()) {
1724 bv->insertLyXFile(filename);
1728 // Launch a file browser
1730 string initpath = lyxrc.document_path;
1731 string const trypath = bv->buffer().filePath();
1732 // If directory is writeable, use this as default.
1733 if (FileName(trypath).isDirWritable())
1737 FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
1738 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1739 dlg.setButton2(qt_("Examples|#E#e"),
1740 toqstr(addPath(package().system_support().absFilename(),
1743 FileDialog::Result result = dlg.open(toqstr(initpath),
1744 QStringList(qt_("LyX Documents (*.lyx)")));
1746 if (result.first == FileDialog::Later)
1750 filename.set(fromqstr(result.second));
1752 // check selected filename
1753 if (filename.empty()) {
1754 // emit message signal.
1755 message(_("Canceled."));
1759 bv->insertLyXFile(filename);
1763 void GuiView::insertPlaintextFile(docstring const & fname,
1766 BufferView * bv = documentBufferView();
1770 if (!fname.empty() && !FileName::isAbsolute(to_utf8(fname))) {
1771 message(_("Absolute filename expected."));
1776 FileName filename(to_utf8(fname));
1778 if (!filename.empty()) {
1779 bv->insertPlaintextFile(filename, asParagraph);
1783 FileDialog dlg(qt_("Select file to insert"), (asParagraph ?
1784 LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
1786 FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
1787 QStringList(qt_("All Files (*)")));
1789 if (result.first == FileDialog::Later)
1793 filename.set(fromqstr(result.second));
1795 // check selected filename
1796 if (filename.empty()) {
1797 // emit message signal.
1798 message(_("Canceled."));
1802 bv->insertPlaintextFile(filename, asParagraph);
1806 bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
1808 FileName fname = b.fileName();
1809 FileName const oldname = fname;
1811 if (!newname.empty()) {
1813 fname = support::makeAbsPath(to_utf8(newname), oldname.onlyPath().absFilename());
1815 // Switch to this Buffer.
1818 // No argument? Ask user through dialog.
1820 FileDialog dlg(qt_("Choose a filename to save document as"),
1821 LFUN_BUFFER_WRITE_AS);
1822 dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1823 dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
1825 if (!isLyXFilename(fname.absFilename()))
1826 fname.changeExtension(".lyx");
1828 FileDialog::Result result =
1829 dlg.save(toqstr(fname.onlyPath().absFilename()),
1830 QStringList(qt_("LyX Documents (*.lyx)")),
1831 toqstr(fname.onlyFileName()));
1833 if (result.first == FileDialog::Later)
1836 fname.set(fromqstr(result.second));
1841 if (!isLyXFilename(fname.absFilename()))
1842 fname.changeExtension(".lyx");
1845 if (FileName(fname).exists()) {
1846 docstring const file = makeDisplayPath(fname.absFilename(), 30);
1847 docstring text = bformat(_("The document %1$s already "
1848 "exists.\n\nDo you want to "
1849 "overwrite that document?"),
1851 int const ret = Alert::prompt(_("Overwrite document?"),
1852 text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
1855 case 1: return renameBuffer(b, docstring());
1856 case 2: return false;
1860 FileName oldauto = b.getAutosaveFilename();
1862 // Ok, change the name of the buffer
1863 b.setFileName(fname.absFilename());
1865 bool unnamed = b.isUnnamed();
1866 b.setUnnamed(false);
1867 b.saveCheckSum(fname);
1869 // bring the autosave file with us, just in case.
1870 b.moveAutosaveFile(oldauto);
1872 if (!saveBuffer(b)) {
1873 oldauto = b.getAutosaveFilename();
1874 b.setFileName(oldname.absFilename());
1875 b.setUnnamed(unnamed);
1876 b.saveCheckSum(oldname);
1877 b.moveAutosaveFile(oldauto);
1885 bool GuiView::saveBuffer(Buffer & b)
1887 if (workArea(b) && workArea(b)->inDialogMode())
1891 return renameBuffer(b, docstring());
1894 theSession().lastFiles().add(b.fileName());
1898 // Switch to this Buffer.
1901 // FIXME: we don't tell the user *WHY* the save failed !!
1902 docstring const file = makeDisplayPath(b.absFileName(), 30);
1903 docstring text = bformat(_("The document %1$s could not be saved.\n\n"
1904 "Do you want to rename the document and "
1905 "try again?"), file);
1906 int const ret = Alert::prompt(_("Rename and save?"),
1907 text, 0, 2, _("&Rename"), _("&Retry"), _("&Cancel"));
1910 if (!renameBuffer(b, docstring()))
1919 return saveBuffer(b);
1923 bool GuiView::hideWorkArea(GuiWorkArea * wa)
1925 return closeWorkArea(wa, false);
1929 bool GuiView::closeWorkArea(GuiWorkArea * wa)
1931 Buffer & buf = wa->bufferView().buffer();
1932 return closeWorkArea(wa, !buf.parent());
1936 bool GuiView::closeBuffer()
1938 GuiWorkArea * wa = currentMainWorkArea();
1939 Buffer & buf = wa->bufferView().buffer();
1940 return wa && closeWorkArea(wa, !buf.parent());
1944 void GuiView::writeSession() const {
1945 GuiWorkArea const * active_wa = currentMainWorkArea();
1946 for (int i = 0; i < d.splitter_->count(); ++i) {
1947 TabWorkArea * twa = d.tabWorkArea(i);
1948 for (int j = 0; j < twa->count(); ++j) {
1949 GuiWorkArea * wa = static_cast<GuiWorkArea *>(twa->widget(j));
1950 Buffer & buf = wa->bufferView().buffer();
1951 theSession().lastOpened().add(buf.fileName(), wa == active_wa);
1957 bool GuiView::closeBufferAll()
1959 // Close the workareas in all other views
1960 QList<int> const ids = guiApp->viewIds();
1961 for (int i = 0; i != ids.size(); ++i) {
1962 if (id_ != ids[i] && !guiApp->view(ids[i]).closeWorkAreaAll())
1966 // Close our own workareas
1967 if (!closeWorkAreaAll())
1970 // Now close the hidden buffers. We prevent hidden buffers from being
1971 // dirty, so we can just close them.
1972 theBufferList().closeAll();
1977 bool GuiView::closeWorkAreaAll()
1979 setCurrentWorkArea(currentMainWorkArea());
1981 // We might be in a situation that there is still a tabWorkArea, but
1982 // there are no tabs anymore. This can happen when we get here after a
1983 // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
1984 // many TabWorkArea's have no documents anymore.
1987 // We have to call count() each time, because it can happen that
1988 // more than one splitter will disappear in one iteration (bug 5998).
1989 for (; d.splitter_->count() > empty_twa; ) {
1990 TabWorkArea * twa = d.tabWorkArea(empty_twa);
1992 if (twa->count() == 0)
1995 setCurrentWorkArea(twa->currentWorkArea());
1996 if (!closeTabWorkArea(twa))
2004 bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer)
2006 Buffer & buf = wa->bufferView().buffer();
2008 // If we are in a close_event all children will be closed in some time,
2009 // so no need to do it here. This will ensure that the children end up
2010 // in the session file in the correct order. If we close the master
2011 // buffer, we can close or release the child buffers here too.
2012 if (close_buffer && !closing_) {
2013 vector<Buffer *> clist = buf.getChildren();
2014 for (vector<Buffer *>::const_iterator it = clist.begin();
2015 it != clist.end(); ++it) {
2016 // If a child is dirty, do not close
2017 // without user intervention
2018 //FIXME: should we look in other tabworkareas?
2019 Buffer * child_buf = *it;
2020 GuiWorkArea * child_wa = workArea(*child_buf);
2022 if (!closeWorkArea(child_wa, true))
2025 theBufferList().releaseChild(&buf, child_buf);
2028 // goto bookmark to update bookmark pit.
2029 //FIXME: we should update only the bookmarks related to this buffer!
2030 LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
2031 for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
2032 theLyXFunc().gotoBookmark(i+1, false, false);
2034 // if we are only hiding the buffer and there are multiple views
2035 // of the buffer, then we do not need to ensure a clean buffer.
2036 bool const allow_dirty = inMultiTabs(wa) && !close_buffer;
2038 if (allow_dirty || saveBufferIfNeeded(buf, !close_buffer)) {
2039 // save in sessions if requested
2040 // do not save childs if their master
2041 // is opened as well
2045 theBufferList().release(&buf);
2052 bool GuiView::closeTabWorkArea(TabWorkArea * twa)
2054 while (twa == d.currentTabWorkArea()) {
2055 twa->setCurrentIndex(twa->count()-1);
2057 GuiWorkArea * wa = twa->currentWorkArea();
2058 Buffer & b = wa->bufferView().buffer();
2060 // We only want to close the buffer if the same buffer is not visible
2061 // in another view, and if this is not a child and if we are closing
2062 // a view (not a tabgroup).
2063 bool const close_buffer =
2064 !inMultiViews(wa) && !b.parent() && closing_;
2066 if (!closeWorkArea(wa, close_buffer))
2073 bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
2075 if (buf.isClean() || buf.paragraphs().empty())
2078 // Switch to this Buffer.
2083 if (buf.isUnnamed())
2084 file = from_utf8(buf.fileName().onlyFileName());
2086 file = buf.fileName().displayName(30);
2088 // Bring this window to top before asking questions.
2093 if (hiding && buf.isUnnamed()) {
2094 docstring const text = bformat(_("The document %1$s has not been "
2095 "saved yet.\n\nDo you want to save "
2096 "the document?"), file);
2097 ret = Alert::prompt(_("Save new document?"),
2098 text, 0, 1, _("&Save"), _("&Cancel"));
2102 docstring const text = bformat(_("The document %1$s has unsaved changes."
2103 "\n\nDo you want to save the document or discard the changes?"), file);
2104 ret = Alert::prompt(_("Save changed document?"),
2105 text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
2110 if (!saveBuffer(buf))
2114 // if we crash after this we could
2115 // have no autosave file but I guess
2116 // this is really improbable (Jug)
2117 buf.removeAutosaveFile();
2119 // revert all changes
2120 buf.loadLyXFile(buf.fileName());
2130 bool GuiView::inMultiTabs(GuiWorkArea * wa)
2132 Buffer & buf = wa->bufferView().buffer();
2134 for (int i = 0; i != d.splitter_->count(); ++i) {
2135 GuiWorkArea * wa_ = d.tabWorkArea(i)->workArea(buf);
2136 if (wa_ && wa_ != wa)
2139 return inMultiViews(wa);
2143 bool GuiView::inMultiViews(GuiWorkArea * wa)
2145 QList<int> const ids = guiApp->viewIds();
2146 Buffer & buf = wa->bufferView().buffer();
2149 for (int i = 0; i != ids.size() && found_twa <= 1; ++i) {
2153 if (guiApp->view(ids[i]).workArea(buf))
2160 void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np)
2162 Buffer * const curbuf = documentBufferView()
2163 ? &documentBufferView()->buffer() : 0;
2164 Buffer * nextbuf = curbuf;
2166 if (np == NEXTBUFFER)
2167 nextbuf = theBufferList().next(nextbuf);
2169 nextbuf = theBufferList().previous(nextbuf);
2170 if (nextbuf == curbuf)
2176 if (workArea(*nextbuf))
2183 /// make sure the document is saved
2184 static bool ensureBufferClean(Buffer * buffer)
2186 LASSERT(buffer, return false);
2187 if (buffer->isClean() && !buffer->isUnnamed())
2190 docstring const file = buffer->fileName().displayName(30);
2193 if (!buffer->isUnnamed()) {
2194 text = bformat(_("The document %1$s has unsaved "
2195 "changes.\n\nDo you want to save "
2196 "the document?"), file);
2197 title = _("Save changed document?");
2200 text = bformat(_("The document %1$s has not been "
2201 "saved yet.\n\nDo you want to save "
2202 "the document?"), file);
2203 title = _("Save new document?");
2205 int const ret = Alert::prompt(title, text, 0, 1, _("&Save"), _("&Cancel"));
2208 dispatch(FuncRequest(LFUN_BUFFER_WRITE));
2210 return buffer->isClean() && !buffer->isUnnamed();
2214 void GuiView::reloadBuffer()
2216 Buffer * buf = &documentBufferView()->buffer();
2217 FileName filename = buf->fileName();
2218 // The user has already confirmed that the changes, if any, should
2219 // be discarded. So we just release the Buffer and don't call closeBuffer();
2220 theBufferList().release(buf);
2221 buf = loadDocument(filename);
2222 docstring const disp_fn = makeDisplayPath(filename.absFilename());
2225 buf->updateLabels();
2227 buf->errors("Parse");
2228 str = bformat(_("Document %1$s reloaded."), disp_fn);
2230 str = bformat(_("Could not reload document %1$s"), disp_fn);
2236 void GuiView::dispatchVC(FuncRequest const & cmd)
2238 Buffer * buffer = documentBufferView()
2239 ? &(documentBufferView()->buffer()) : 0;
2241 switch (cmd.action) {
2242 case LFUN_VC_REGISTER:
2243 if (!buffer || !ensureBufferClean(buffer))
2245 if (!buffer->lyxvc().inUse()) {
2246 if (buffer->lyxvc().registrer())
2251 case LFUN_VC_CHECK_IN:
2252 if (!buffer || !ensureBufferClean(buffer))
2254 if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
2255 message(from_utf8(buffer->lyxvc().checkIn()));
2260 case LFUN_VC_CHECK_OUT:
2261 if (!buffer || !ensureBufferClean(buffer))
2263 if (buffer->lyxvc().inUse()) {
2264 message(from_utf8(buffer->lyxvc().checkOut()));
2269 case LFUN_VC_LOCKING_TOGGLE:
2270 LASSERT(buffer, return);
2271 if (!ensureBufferClean(buffer) || buffer->isReadonly())
2273 if (buffer->lyxvc().inUse()) {
2274 string res = buffer->lyxvc().lockingToggle();
2276 frontend::Alert::error(_("Revision control error."),
2277 _("Error when setting the locking property."));
2279 message(from_utf8(res));
2285 case LFUN_VC_REVERT:
2286 LASSERT(buffer, return);
2287 buffer->lyxvc().revert();
2291 case LFUN_VC_UNDO_LAST:
2292 LASSERT(buffer, return);
2293 buffer->lyxvc().undoLast();
2297 case LFUN_VC_COMMAND: {
2298 string flag = cmd.getArg(0);
2299 if (buffer && contains(flag, 'R') && !ensureBufferClean(buffer))
2302 if (contains(flag, 'M')) {
2303 if (!Alert::askForText(message, _("LyX VC: Log Message")))
2306 string path = cmd.getArg(1);
2307 if (contains(path, "$$p") && buffer)
2308 path = subst(path, "$$p", buffer->filePath());
2309 LYXERR(Debug::LYXVC, "Directory: " << path);
2311 if (!pp.isReadableDirectory()) {
2312 lyxerr << _("Directory is not accessible.") << endl;
2315 support::PathChanger p(pp);
2317 string command = cmd.getArg(2);
2318 if (command.empty())
2321 command = subst(command, "$$i", buffer->absFileName());
2322 command = subst(command, "$$p", buffer->filePath());
2324 command = subst(command, "$$m", to_utf8(message));
2325 LYXERR(Debug::LYXVC, "Command: " << command);
2327 one.startscript(Systemcall::Wait, command);
2331 if (contains(flag, 'I'))
2332 buffer->markDirty();
2333 if (contains(flag, 'R'))
2342 bool GuiView::dispatch(FuncRequest const & cmd)
2344 BufferView * bv = currentBufferView();
2345 // By default we won't need any update.
2347 bv->cursor().updateFlags(Update::None);
2349 Buffer * doc_buffer = documentBufferView()
2350 ? &(documentBufferView()->buffer()) : 0;
2352 bool dispatched = true;
2354 if (cmd.origin == FuncRequest::TOC) {
2355 GuiToc * toc = static_cast<GuiToc*>(findOrBuild("toc", false));
2356 toc->doDispatch(bv->cursor(), cmd);
2360 switch(cmd.action) {
2361 case LFUN_BUFFER_IMPORT:
2362 importDocument(to_utf8(cmd.argument()));
2365 case LFUN_BUFFER_SWITCH:
2366 if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
2368 theBufferList().getBuffer(FileName(to_utf8(cmd.argument())));
2372 bv->cursor().message(_("Document not loaded"));
2376 case LFUN_BUFFER_NEXT:
2377 gotoNextOrPreviousBuffer(NEXTBUFFER);
2380 case LFUN_BUFFER_PREVIOUS:
2381 gotoNextOrPreviousBuffer(PREVBUFFER);
2384 case LFUN_COMMAND_EXECUTE: {
2385 bool const show_it = cmd.argument() != "off";
2386 // FIXME: this is a hack, "minibuffer" should not be
2388 if (GuiToolbar * t = toolbar("minibuffer")) {
2389 t->setVisible(show_it);
2390 if (show_it && t->commandBuffer())
2391 t->commandBuffer()->setFocus();
2395 case LFUN_DROP_LAYOUTS_CHOICE:
2396 d.layout_->showPopup();
2399 case LFUN_MENU_OPEN:
2400 if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument()), *this))
2401 menu->exec(QCursor::pos());
2404 case LFUN_FILE_INSERT:
2405 insertLyXFile(cmd.argument());
2407 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
2408 insertPlaintextFile(cmd.argument(), true);
2411 case LFUN_FILE_INSERT_PLAINTEXT:
2412 insertPlaintextFile(cmd.argument(), false);
2415 case LFUN_BUFFER_RELOAD: {
2416 LASSERT(doc_buffer, break);
2417 docstring const file = makeDisplayPath(doc_buffer->absFileName(), 20);
2418 docstring text = bformat(_("Any changes will be lost. Are you sure "
2419 "you want to revert to the saved version of the document %1$s?"), file);
2420 int const ret = Alert::prompt(_("Revert to saved document?"),
2421 text, 1, 1, _("&Revert"), _("&Cancel"));
2428 case LFUN_BUFFER_WRITE:
2429 LASSERT(doc_buffer, break);
2430 saveBuffer(*doc_buffer);
2433 case LFUN_BUFFER_WRITE_AS:
2434 LASSERT(doc_buffer, break);
2435 renameBuffer(*doc_buffer, cmd.argument());
2438 case LFUN_BUFFER_WRITE_ALL: {
2439 Buffer * first = theBufferList().first();
2442 message(_("Saving all documents..."));
2443 // We cannot use a for loop as the buffer list cycles.
2446 if (!b->isClean()) {
2448 LYXERR(Debug::ACTION, "Saved " << b->absFileName());
2450 b = theBufferList().next(b);
2451 } while (b != first);
2452 message(_("All documents saved."));
2456 case LFUN_TOOLBAR_TOGGLE: {
2457 string const name = cmd.getArg(0);
2458 if (GuiToolbar * t = toolbar(name))
2463 case LFUN_DIALOG_UPDATE: {
2464 string const name = to_utf8(cmd.argument());
2465 // Can only update a dialog connected to an existing inset
2466 Inset * inset = getOpenInset(name);
2468 FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
2469 inset->dispatch(currentBufferView()->cursor(), fr);
2470 } else if (name == "paragraph") {
2471 lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
2472 } else if (name == "prefs" || name == "document") {
2473 updateDialog(name, string());
2478 case LFUN_DIALOG_TOGGLE: {
2479 if (isDialogVisible(cmd.getArg(0)))
2480 dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument()));
2482 dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument()));
2486 case LFUN_DIALOG_DISCONNECT_INSET:
2487 disconnectDialog(to_utf8(cmd.argument()));
2490 case LFUN_DIALOG_HIDE: {
2491 guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
2495 case LFUN_DIALOG_SHOW: {
2496 string const name = cmd.getArg(0);
2497 string data = trim(to_utf8(cmd.argument()).substr(name.size()));
2499 if (name == "character") {
2500 data = freefont2string();
2502 showDialog("character", data);
2503 } else if (name == "latexlog") {
2504 Buffer::LogType type;
2505 string const logfile = doc_buffer->logName(&type);
2507 case Buffer::latexlog:
2510 case Buffer::buildlog:
2514 data += Lexer::quoteString(logfile);
2515 showDialog("log", data);
2516 } else if (name == "vclog") {
2517 string const data = "vc " +
2518 Lexer::quoteString(doc_buffer->lyxvc().getLogFile());
2519 showDialog("log", data);
2520 } else if (name == "symbols") {
2521 data = bv->cursor().getEncoding()->name();
2523 showDialog("symbols", data);
2525 } else if (name == "prefs" && isFullScreen()) {
2526 FuncRequest fr(LFUN_INSET_INSERT, "fullscreen");
2528 showDialog("prefs", data);
2530 showDialog(name, data);
2535 message(cmd.argument());
2538 case LFUN_INSET_APPLY: {
2539 string const name = cmd.getArg(0);
2540 Inset * inset = getOpenInset(name);
2542 // put cursor in front of inset.
2543 if (!currentBufferView()->setCursorFromInset(inset)) {
2544 LASSERT(false, break);
2546 BufferView * bv = currentBufferView();
2547 // useful if we are called from a dialog.
2548 bv->cursor().beginUndoGroup();
2549 bv->cursor().recordUndo();
2550 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
2551 inset->dispatch(bv->cursor(), fr);
2552 bv->cursor().endUndoGroup();
2554 FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
2560 case LFUN_UI_TOGGLE:
2562 // Make sure the keyboard focus stays in the work area.
2566 case LFUN_SPLIT_VIEW: {
2567 LASSERT(doc_buffer, break);
2568 string const orientation = cmd.getArg(0);
2569 d.splitter_->setOrientation(orientation == "vertical"
2570 ? Qt::Vertical : Qt::Horizontal);
2571 TabWorkArea * twa = addTabWorkArea();
2572 GuiWorkArea * wa = twa->addWorkArea(*doc_buffer, *this);
2573 setCurrentWorkArea(wa);
2576 case LFUN_CLOSE_TAB_GROUP:
2577 if (TabWorkArea * twa = d.currentTabWorkArea()) {
2578 closeTabWorkArea(twa);
2579 d.current_work_area_ = 0;
2580 twa = d.currentTabWorkArea();
2581 // Switch to the next GuiWorkArea in the found TabWorkArea.
2583 // Make sure the work area is up to date.
2584 setCurrentWorkArea(twa->currentWorkArea());
2586 setCurrentWorkArea(0);
2591 case LFUN_COMPLETION_INLINE:
2592 if (d.current_work_area_)
2593 d.current_work_area_->completer().showInline();
2596 case LFUN_COMPLETION_POPUP:
2597 if (d.current_work_area_)
2598 d.current_work_area_->completer().showPopup();
2602 case LFUN_COMPLETION_COMPLETE:
2603 if (d.current_work_area_)
2604 d.current_work_area_->completer().tab();
2607 case LFUN_COMPLETION_CANCEL:
2608 if (d.current_work_area_) {
2609 if (d.current_work_area_->completer().popupVisible())
2610 d.current_work_area_->completer().hidePopup();
2612 d.current_work_area_->completer().hideInline();
2616 case LFUN_COMPLETION_ACCEPT:
2617 if (d.current_work_area_)
2618 d.current_work_area_->completer().activate();
2621 case LFUN_BUFFER_ZOOM_IN:
2622 case LFUN_BUFFER_ZOOM_OUT:
2623 if (cmd.argument().empty()) {
2624 if (cmd.action == LFUN_BUFFER_ZOOM_IN)
2629 lyxrc.zoom += convert<int>(cmd.argument());
2631 if (lyxrc.zoom < 10)
2634 // The global QPixmapCache is used in GuiPainter to cache text
2635 // painting so we must reset it.
2636 QPixmapCache::clear();
2637 guiApp->fontLoader().update();
2638 lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
2641 case LFUN_VC_REGISTER:
2642 case LFUN_VC_CHECK_IN:
2643 case LFUN_VC_CHECK_OUT:
2644 case LFUN_VC_LOCKING_TOGGLE:
2645 case LFUN_VC_REVERT:
2646 case LFUN_VC_UNDO_LAST:
2647 case LFUN_VC_COMMAND:
2656 // Part of automatic menu appearance feature.
2657 if (isFullScreen()) {
2658 if (menuBar()->isVisible() && lyxrc.full_screen_menubar)
2660 if (statusBar()->isVisible())
2661 statusBar()->hide();
2668 void GuiView::lfunUiToggle(FuncRequest const & cmd)
2670 string const arg = cmd.getArg(0);
2671 if (arg == "scrollbar") {
2672 // hide() is of no help
2673 if (d.current_work_area_->verticalScrollBarPolicy() ==
2674 Qt::ScrollBarAlwaysOff)
2676 d.current_work_area_->setVerticalScrollBarPolicy(
2677 Qt::ScrollBarAsNeeded);
2679 d.current_work_area_->setVerticalScrollBarPolicy(
2680 Qt::ScrollBarAlwaysOff);
2683 if (arg == "statusbar") {
2684 statusBar()->setVisible(!statusBar()->isVisible());
2687 if (arg == "menubar") {
2688 menuBar()->setVisible(!menuBar()->isVisible());
2691 #if QT_VERSION >= 0x040300
2692 if (arg == "frame") {
2694 getContentsMargins(&l, &t, &r, &b);
2695 //are the frames in default state?
2696 d.current_work_area_->setFrameStyle(QFrame::NoFrame);
2698 setContentsMargins(-2, -2, -2, -2);
2700 setContentsMargins(0, 0, 0, 0);
2705 if (arg == "fullscreen") {
2710 message(bformat("LFUN_UI_TOGGLE " + _("%1$s unknown command!"), from_utf8(arg)));
2714 void GuiView::toggleFullScreen()
2716 if (isFullScreen()) {
2717 for (int i = 0; i != d.splitter_->count(); ++i)
2718 d.tabWorkArea(i)->setFullScreen(false);
2719 #if QT_VERSION >= 0x040300
2720 setContentsMargins(0, 0, 0, 0);
2722 setWindowState(windowState() ^ Qt::WindowFullScreen);
2725 statusBar()->show();
2728 hideDialogs("prefs", 0);
2729 for (int i = 0; i != d.splitter_->count(); ++i)
2730 d.tabWorkArea(i)->setFullScreen(true);
2731 #if QT_VERSION >= 0x040300
2732 setContentsMargins(-2, -2, -2, -2);
2735 setWindowState(windowState() ^ Qt::WindowFullScreen);
2736 statusBar()->hide();
2737 if (lyxrc.full_screen_menubar)
2739 if (lyxrc.full_screen_toolbars) {
2740 ToolbarMap::iterator end = d.toolbars_.end();
2741 for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
2746 // give dialogs like the TOC a chance to adapt
2751 Buffer const * GuiView::updateInset(Inset const * inset)
2753 if (!d.current_work_area_)
2757 d.current_work_area_->scheduleRedraw();
2759 return &d.current_work_area_->bufferView().buffer();
2763 void GuiView::restartCursor()
2765 /* When we move around, or type, it's nice to be able to see
2766 * the cursor immediately after the keypress.
2768 if (d.current_work_area_)
2769 d.current_work_area_->startBlinkingCursor();
2771 // Take this occasion to update the other GUI elements.
2777 void GuiView::updateCompletion(Cursor & cur, bool start, bool keep)
2779 if (d.current_work_area_)
2780 d.current_work_area_->completer().updateVisibility(cur, start, keep);
2785 // This list should be kept in sync with the list of insets in
2786 // src/insets/Inset.cpp. I.e., if a dialog goes with an inset, the
2787 // dialog should have the same name as the inset.
2788 // Changes should be also recorded in LFUN_DIALOG_SHOW doxygen
2789 // docs in LyXAction.cpp.
2791 char const * const dialognames[] = {
2792 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
2793 "citation", "document", "errorlist", "ert", "external", "file", "findreplace",
2794 "findreplaceadv", "float", "graphics", "href", "include", "index",
2795 "index_print", "info", "listings", "label", "log", "mathdelimiter",
2796 "mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note",
2797 "paragraph", "phantom", "prefs", "print", "ref", "sendto", "space",
2798 "spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo",
2799 "toc", "view-source", "vspace", "wrap" };
2801 char const * const * const end_dialognames =
2802 dialognames + (sizeof(dialognames) / sizeof(char *));
2806 cmpCStr(char const * name) : name_(name) {}
2807 bool operator()(char const * other) {
2808 return strcmp(other, name_) == 0;
2815 bool isValidName(string const & name)
2817 return find_if(dialognames, end_dialognames,
2818 cmpCStr(name.c_str())) != end_dialognames;
2824 void GuiView::resetDialogs()
2826 // Make sure that no LFUN uses any LyXView.
2827 theLyXFunc().setLyXView(0);
2830 constructToolbars();
2831 guiApp->menus().fillMenuBar(menuBar(), this, false);
2832 d.layout_->updateContents(true);
2833 // Now update controls with current buffer.
2834 theLyXFunc().setLyXView(this);
2840 Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
2842 if (!isValidName(name))
2845 map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
2847 if (it != d.dialogs_.end()) {
2849 it->second->hideView();
2850 return it->second.get();
2853 Dialog * dialog = build(name);
2854 d.dialogs_[name].reset(dialog);
2855 if (lyxrc.allow_geometry_session)
2856 dialog->restoreSession();
2863 void GuiView::showDialog(string const & name, string const & data,
2871 Dialog * dialog = findOrBuild(name, false);
2873 dialog->showData(data);
2875 d.open_insets_[name] = inset;
2878 catch (ExceptionMessage const & ex) {
2886 bool GuiView::isDialogVisible(string const & name) const
2888 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
2889 if (it == d.dialogs_.end())
2891 return it->second.get()->isVisibleView() && !it->second.get()->isClosing();
2895 void GuiView::hideDialog(string const & name, Inset * inset)
2897 map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
2898 if (it == d.dialogs_.end())
2901 if (inset && inset != getOpenInset(name))
2904 Dialog * const dialog = it->second.get();
2905 if (dialog->isVisibleView())
2907 d.open_insets_[name] = 0;
2911 void GuiView::disconnectDialog(string const & name)
2913 if (!isValidName(name))
2916 if (d.open_insets_.find(name) != d.open_insets_.end())
2917 d.open_insets_[name] = 0;
2921 Inset * GuiView::getOpenInset(string const & name) const
2923 if (!isValidName(name))
2926 map<string, Inset *>::const_iterator it = d.open_insets_.find(name);
2927 return it == d.open_insets_.end() ? 0 : it->second;
2931 void GuiView::hideAll() const
2933 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
2934 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
2936 for(; it != end; ++it)
2937 it->second->hideView();
2941 void GuiView::updateDialogs()
2943 map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
2944 map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
2946 for(; it != end; ++it) {
2947 Dialog * dialog = it->second.get();
2948 if (dialog && dialog->isVisibleView())
2949 dialog->checkStatus();
2956 // will be replaced by a proper factory...
2957 Dialog * createGuiAbout(GuiView & lv);
2958 Dialog * createGuiBibitem(GuiView & lv);
2959 Dialog * createGuiBibtex(GuiView & lv);
2960 Dialog * createGuiBox(GuiView & lv);
2961 Dialog * createGuiBranch(GuiView & lv);
2962 Dialog * createGuiChanges(GuiView & lv);
2963 Dialog * createGuiCharacter(GuiView & lv);
2964 Dialog * createGuiCitation(GuiView & lv);
2965 Dialog * createGuiDelimiter(GuiView & lv);
2966 Dialog * createGuiDocument(GuiView & lv);
2967 Dialog * createGuiErrorList(GuiView & lv);
2968 Dialog * createGuiERT(GuiView & lv);
2969 Dialog * createGuiExternal(GuiView & lv);
2970 Dialog * createGuiFloat(GuiView & lv);
2971 Dialog * createGuiGraphics(GuiView & lv);
2972 Dialog * createGuiInclude(GuiView & lv);
2973 Dialog * createGuiIndex(GuiView & lv);
2974 Dialog * createGuiInfo(GuiView & lv);
2975 Dialog * createGuiLabel(GuiView & lv);
2976 Dialog * createGuiListings(GuiView & lv);
2977 Dialog * createGuiLog(GuiView & lv);
2978 Dialog * createGuiMathHSpace(GuiView & lv);
2979 Dialog * createGuiMathMatrix(GuiView & lv);
2980 Dialog * createGuiNomenclature(GuiView & lv);
2981 Dialog * createGuiNote(GuiView & lv);
2982 Dialog * createGuiParagraph(GuiView & lv);
2983 Dialog * createGuiPhantom(GuiView & lv);
2984 Dialog * createGuiPreferences(GuiView & lv);
2985 Dialog * createGuiPrint(GuiView & lv);
2986 Dialog * createGuiPrintindex(GuiView & lv);
2987 Dialog * createGuiPrintNomencl(GuiView & lv);
2988 Dialog * createGuiRef(GuiView & lv);
2989 Dialog * createGuiSearch(GuiView & lv);
2990 Dialog * createGuiSearchAdv(GuiView & lv);
2991 Dialog * createGuiSendTo(GuiView & lv);
2992 Dialog * createGuiShowFile(GuiView & lv);
2993 Dialog * createGuiSpellchecker(GuiView & lv);
2994 Dialog * createGuiSymbols(GuiView & lv);
2995 Dialog * createGuiTabularCreate(GuiView & lv);
2996 Dialog * createGuiTabular(GuiView & lv);
2997 Dialog * createGuiTexInfo(GuiView & lv);
2998 Dialog * createGuiTextHSpace(GuiView & lv);
2999 Dialog * createGuiToc(GuiView & lv);
3000 Dialog * createGuiThesaurus(GuiView & lv);
3001 Dialog * createGuiHyperlink(GuiView & lv);
3002 Dialog * createGuiVSpace(GuiView & lv);
3003 Dialog * createGuiViewSource(GuiView & lv);
3004 Dialog * createGuiWrap(GuiView & lv);
3007 Dialog * GuiView::build(string const & name)
3009 LASSERT(isValidName(name), return 0);
3011 if (name == "aboutlyx")
3012 return createGuiAbout(*this);
3013 if (name == "bibitem")
3014 return createGuiBibitem(*this);
3015 if (name == "bibtex")
3016 return createGuiBibtex(*this);
3018 return createGuiBox(*this);
3019 if (name == "branch")
3020 return createGuiBranch(*this);
3021 if (name == "changes")
3022 return createGuiChanges(*this);
3023 if (name == "character")
3024 return createGuiCharacter(*this);
3025 if (name == "citation")
3026 return createGuiCitation(*this);
3027 if (name == "document")
3028 return createGuiDocument(*this);
3029 if (name == "errorlist")
3030 return createGuiErrorList(*this);
3032 return createGuiERT(*this);
3033 if (name == "external")
3034 return createGuiExternal(*this);
3036 return createGuiShowFile(*this);
3037 if (name == "findreplace")
3038 return createGuiSearch(*this);
3039 if (name == "findreplaceadv")
3040 return createGuiSearchAdv(*this);
3041 if (name == "float")
3042 return createGuiFloat(*this);
3043 if (name == "graphics")
3044 return createGuiGraphics(*this);
3046 return createGuiHyperlink(*this);
3047 if (name == "include")
3048 return createGuiInclude(*this);
3049 if (name == "index")
3050 return createGuiIndex(*this);
3051 if (name == "index_print")
3052 return createGuiPrintindex(*this);
3054 return createGuiInfo(*this);
3055 if (name == "label")
3056 return createGuiLabel(*this);
3057 if (name == "listings")
3058 return createGuiListings(*this);
3060 return createGuiLog(*this);
3061 if (name == "mathdelimiter")
3062 return createGuiDelimiter(*this);
3063 if (name == "mathspace")
3064 return createGuiMathHSpace(*this);
3065 if (name == "mathmatrix")
3066 return createGuiMathMatrix(*this);
3067 if (name == "nomenclature")
3068 return createGuiNomenclature(*this);
3069 if (name == "nomencl_print")
3070 return createGuiPrintNomencl(*this);
3072 return createGuiNote(*this);
3073 if (name == "paragraph")
3074 return createGuiParagraph(*this);
3075 if (name == "phantom")
3076 return createGuiPhantom(*this);
3077 if (name == "prefs")
3078 return createGuiPreferences(*this);
3079 if (name == "print")
3080 return createGuiPrint(*this);
3082 return createGuiRef(*this);
3083 if (name == "sendto")
3084 return createGuiSendTo(*this);
3085 if (name == "space")
3086 return createGuiTextHSpace(*this);
3087 if (name == "spellchecker")
3088 return createGuiSpellchecker(*this);
3089 if (name == "symbols")
3090 return createGuiSymbols(*this);
3091 if (name == "tabular")
3092 return createGuiTabular(*this);
3093 if (name == "tabularcreate")
3094 return createGuiTabularCreate(*this);
3095 if (name == "texinfo")
3096 return createGuiTexInfo(*this);
3097 if (name == "thesaurus")
3098 return createGuiThesaurus(*this);
3100 return createGuiToc(*this);
3101 if (name == "view-source")
3102 return createGuiViewSource(*this);
3103 if (name == "vspace")
3104 return createGuiVSpace(*this);
3106 return createGuiWrap(*this);
3112 } // namespace frontend
3115 #include "moc_GuiView.cpp"