]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiView.cpp
Fix use of BookmarkSection::size()
[features.git] / src / frontends / qt / GuiView.cpp
index 4298fd1d8147d1ac9c8806d43be76973b82b7475..714af17b6883c863761ad459d0c43dd200f77f1c 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "GuiView.h"
 
+#include "DialogFactory.h"
 #include "DispatchResult.h"
 #include "FileDialog.h"
 #include "FontLoader.h"
@@ -490,7 +491,7 @@ public:
                                   Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
                                   Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
                                   Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const,
-                                  bool allow_async);
+                                  bool allow_async, bool use_tmpdir = false);
 
        QVector<GuiWorkArea*> guiWorkAreas();
 
@@ -1399,6 +1400,10 @@ bool GuiView::event(QEvent * e)
                        }
                        for (int i = 0; i != d.splitter_->count(); ++i)
                                d.tabWorkArea(i)->setFullScreen(true);
+#if QT_VERSION > 0x050903
+                       //Qt's 5.9.4 ba44cdae38406c safe area measures won't allow us to go negative in margins
+                       setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, false);
+#endif
                        setContentsMargins(-2, -2, -2, -2);
                        // bug 5274
                        hideDialogs("prefs", nullptr);
@@ -1417,6 +1422,9 @@ bool GuiView::event(QEvent * e)
                        }
                        for (int i = 0; i != d.splitter_->count(); ++i)
                                d.tabWorkArea(i)->setFullScreen(false);
+#if QT_VERSION > 0x050903
+                       setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, true);
+#endif
                        setContentsMargins(0, 0, 0, 0);
                }
                return result;
@@ -2109,6 +2117,41 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setOnOff(devel_mode_);
                break;
 
+       case LFUN_TOOLBAR_SET: {
+               string const name = cmd.getArg(0);
+               string const state = cmd.getArg(1);
+               if (name.empty() || state.empty()) {
+                       enable = false;
+                       docstring const msg =
+                               _("Function toolbar-set requires two arguments!");
+                       flag.message(msg);
+                       break;
+               }
+               if (state != "on" && state != "off" && state != "auto") {
+                       enable = false;
+                       docstring const msg =
+                               bformat(_("Invalid argument \"%1$s\" to function toolbar-set!"),
+                                       from_utf8(state));
+                       flag.message(msg);
+                       break;
+               }
+               if (GuiToolbar * t = toolbar(name)) {
+                       bool const autovis = t->visibility() & Toolbars::AUTO;
+                       if (state == "on")
+                               flag.setOnOff(t->isVisible() && !autovis);
+                       else if (state == "off")
+                               flag.setOnOff(!t->isVisible() && !autovis);
+                       else if (state == "auto")
+                               flag.setOnOff(autovis);
+               } else {
+                       enable = false;
+                       docstring const msg =
+                               bformat(_("Unknown toolbar \"%1$s\""), from_utf8(name));
+                       flag.message(msg);
+               }
+               break;
+       }
+
        case LFUN_TOOLBAR_TOGGLE: {
                string const name = cmd.getArg(0);
                if (GuiToolbar * t = toolbar(name))
@@ -2185,7 +2228,6 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                        enable = FileName(doc_buffer->logName()).isReadableFile();
                else if (name == "spellchecker")
                        enable = theSpellChecker()
-                               && !doc_buffer->isReadonly()
                                && !doc_buffer->text().empty();
                else if (name == "vclog")
                        enable = doc_buffer->lyxvc().inUse();
@@ -2493,19 +2535,17 @@ static bool import(GuiView * lv, FileName const & filename,
        string loader_format;
        vector<string> loaders = theConverters().loaders();
        if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
-               vector<string>::const_iterator it = loaders.begin();
-               vector<string>::const_iterator en = loaders.end();
                for (string const & loader : loaders) {
                        if (!theConverters().isReachable(format, loader))
                                continue;
 
                        string const tofile =
                                support::changeExtension(filename.absFileName(),
-                               theFormats().extension(*it));
+                               theFormats().extension(loader));
                        if (theConverters().convert(nullptr, filename, FileName(tofile),
-                               filename, format, *it, errorList) != Converters::SUCCESS)
+                               filename, format, loader, errorList) != Converters::SUCCESS)
                                return false;
-                       loader_format = *it;
+                       loader_format = loader;
                        break;
                }
                if (loader_format.empty()) {
@@ -3257,9 +3297,10 @@ bool GuiView::closeBuffer(Buffer & buf)
        if (success) {
                // goto bookmark to update bookmark pit.
                // FIXME: we should update only the bookmarks related to this buffer!
+               // FIXME: this is done also in LFUN_WINDOW_CLOSE!
                LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
-               for (unsigned int i = 0; i < theSession().bookmarks().size(); ++i)
-                       guiApp->gotoBookmark(i + 1, false, false);
+               for (unsigned int i = 1; i < theSession().bookmarks().size(); ++i)
+                       guiApp->gotoBookmark(i, false, false);
 
                if (saveBufferIfNeeded(buf, false)) {
                        buf.removeAutosaveFile();
@@ -3805,14 +3846,13 @@ Buffer::ExportStatus GuiView::GuiViewPrivate::previewAndDestroy(
 }
 
 
-bool GuiView::GuiViewPrivate::asyncBufferProcessing(
-                          string const & argument,
+bool GuiView::GuiViewPrivate::asyncBufferProcessing(string const & argument,
                           Buffer const * used_buffer,
                           docstring const & msg,
                           Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
                           Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
                           Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const,
-                          bool allow_async)
+                          bool allow_async, bool use_tmpdir)
 {
        if (!used_buffer)
                return false;
@@ -3848,7 +3888,7 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
        } else {
                Buffer::ExportStatus status;
                if (syncFunc) {
-                       status = (used_buffer->*syncFunc)(format, false);
+                       status = (used_buffer->*syncFunc)(format, use_tmpdir);
                } else if (previewFunc) {
                        status = (used_buffer->*previewFunc)(format);
                } else
@@ -4005,7 +4045,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                                _("Exporting ..."),
                                                &GuiViewPrivate::compileAndDestroy,
                                                &Buffer::doExport,
-                                               nullptr, cmd.allowAsync());
+                                               nullptr, cmd.allowAsync(), true);
                        break;
                }
                case LFUN_BUFFER_VIEW: {
@@ -4023,7 +4063,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                                docstring(),
                                                &GuiViewPrivate::compileAndDestroy,
                                                &Buffer::doExport,
-                                               nullptr, cmd.allowAsync());
+                                               nullptr, cmd.allowAsync(), true);
                        break;
                }
                case LFUN_MASTER_BUFFER_VIEW: {
@@ -4270,6 +4310,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                dr.setMessage(_("Developer mode is now disabled."));
                        break;
 
+               case LFUN_TOOLBAR_SET: {
+                       string const name = cmd.getArg(0);
+                       string const state = cmd.getArg(1);
+                       if (GuiToolbar * t = toolbar(name))
+                               t->setState(state);
+                       break;
+               }
+
                case LFUN_TOOLBAR_TOGGLE: {
                        string const name = cmd.getArg(0);
                        if (GuiToolbar * t = toolbar(name))
@@ -4652,8 +4700,14 @@ bool GuiView::lfunUiToggle(string const & ui_component)
                //are the frames in default state?
                d.current_work_area_->setFrameStyle(QFrame::NoFrame);
                if (l == 0) {
+#if QT_VERSION >  0x050903
+                       setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, false);
+#endif
                        setContentsMargins(-2, -2, -2, -2);
                } else {
+#if QT_VERSION >  0x050903
+                       setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, true);
+#endif
                        setContentsMargins(0, 0, 0, 0);
                }
        } else
@@ -4900,7 +4954,7 @@ void GuiView::hideAll() const
 
 void GuiView::updateDialogs()
 {
-       for(auto const & dlg_p : d.dialogs_)
+       for(auto const & dlg_p : d.dialogs_) {
                Dialog * dialog = dlg_p.second.get();
                if (dialog) {
                        if (dialog->needBufferOpen() && !documentBufferView())
@@ -4913,134 +4967,10 @@ void GuiView::updateDialogs()
        updateLayoutList();
 }
 
-Dialog * createDialog(GuiView & lv, string const & name);
-
-// will be replaced by a proper factory...
-Dialog * createGuiAbout(GuiView & lv);
-Dialog * createGuiBibtex(GuiView & lv);
-Dialog * createGuiChanges(GuiView & lv);
-Dialog * createGuiCharacter(GuiView & lv);
-Dialog * createGuiCitation(GuiView & lv);
-Dialog * createGuiCompare(GuiView & lv);
-Dialog * createGuiCompareHistory(GuiView & lv);
-Dialog * createGuiDelimiter(GuiView & lv);
-Dialog * createGuiDocument(GuiView & lv);
-Dialog * createGuiErrorList(GuiView & lv);
-Dialog * createGuiExternal(GuiView & lv);
-Dialog * createGuiGraphics(GuiView & lv);
-Dialog * createGuiInclude(GuiView & lv);
-Dialog * createGuiIndex(GuiView & lv);
-Dialog * createGuiListings(GuiView & lv);
-Dialog * createGuiLog(GuiView & lv);
-Dialog * createGuiLyXFiles(GuiView & lv);
-Dialog * createGuiMathMatrix(GuiView & lv);
-Dialog * createGuiNote(GuiView & lv);
-Dialog * createGuiParagraph(GuiView & lv);
-Dialog * createGuiPhantom(GuiView & lv);
-Dialog * createGuiPreferences(GuiView & lv);
-Dialog * createGuiPrint(GuiView & lv);
-Dialog * createGuiPrintindex(GuiView & lv);
-Dialog * createGuiRef(GuiView & lv);
-Dialog * createGuiSearch(GuiView & lv);
-Dialog * createGuiSearchAdv(GuiView & lv);
-Dialog * createGuiSendTo(GuiView & lv);
-Dialog * createGuiShowFile(GuiView & lv);
-Dialog * createGuiSpellchecker(GuiView & lv);
-Dialog * createGuiSymbols(GuiView & lv);
-Dialog * createGuiTabularCreate(GuiView & lv);
-Dialog * createGuiTexInfo(GuiView & lv);
-Dialog * createGuiToc(GuiView & lv);
-Dialog * createGuiThesaurus(GuiView & lv);
-Dialog * createGuiViewSource(GuiView & lv);
-Dialog * createGuiWrap(GuiView & lv);
-Dialog * createGuiProgressView(GuiView & lv);
-
-
 
 Dialog * GuiView::build(string const & name)
 {
-       LASSERT(isValidName(name), return nullptr);
-
-       Dialog * dialog = createDialog(*this, name);
-       if (dialog)
-               return dialog;
-
-       if (name == "aboutlyx")
-               return createGuiAbout(*this);
-       if (name == "bibtex")
-               return createGuiBibtex(*this);
-       if (name == "changes")
-               return createGuiChanges(*this);
-       if (name == "character")
-               return createGuiCharacter(*this);
-       if (name == "citation")
-               return createGuiCitation(*this);
-       if (name == "compare")
-               return createGuiCompare(*this);
-       if (name == "comparehistory")
-               return createGuiCompareHistory(*this);
-       if (name == "document")
-               return createGuiDocument(*this);
-       if (name == "errorlist")
-               return createGuiErrorList(*this);
-       if (name == "external")
-               return createGuiExternal(*this);
-       if (name == "file")
-               return createGuiShowFile(*this);
-       if (name == "findreplace")
-               return createGuiSearch(*this);
-       if (name == "findreplaceadv")
-               return createGuiSearchAdv(*this);
-       if (name == "graphics")
-               return createGuiGraphics(*this);
-       if (name == "include")
-               return createGuiInclude(*this);
-       if (name == "index")
-               return createGuiIndex(*this);
-       if (name == "index_print")
-               return createGuiPrintindex(*this);
-       if (name == "listings")
-               return createGuiListings(*this);
-       if (name == "log")
-               return createGuiLog(*this);
-       if (name == "lyxfiles")
-               return createGuiLyXFiles(*this);
-       if (name == "mathdelimiter")
-               return createGuiDelimiter(*this);
-       if (name == "mathmatrix")
-               return createGuiMathMatrix(*this);
-       if (name == "note")
-               return createGuiNote(*this);
-       if (name == "paragraph")
-               return createGuiParagraph(*this);
-       if (name == "phantom")
-               return createGuiPhantom(*this);
-       if (name == "prefs")
-               return createGuiPreferences(*this);
-       if (name == "ref")
-               return createGuiRef(*this);
-       if (name == "sendto")
-               return createGuiSendTo(*this);
-       if (name == "spellchecker")
-               return createGuiSpellchecker(*this);
-       if (name == "symbols")
-               return createGuiSymbols(*this);
-       if (name == "tabularcreate")
-               return createGuiTabularCreate(*this);
-       if (name == "texinfo")
-               return createGuiTexInfo(*this);
-       if (name == "thesaurus")
-               return createGuiThesaurus(*this);
-       if (name == "toc")
-               return createGuiToc(*this);
-       if (name == "view-source")
-               return createGuiViewSource(*this);
-       if (name == "wrap")
-               return createGuiWrap(*this);
-       if (name == "progress")
-               return createGuiProgressView(*this);
-
-       return nullptr;
+       return createDialog(*this, name);
 }