]> 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 5c1c3577a6c65122a7317024e88b84b24c4ec190..714af17b6883c863761ad459d0c43dd200f77f1c 100644 (file)
 
 #include "GuiView.h"
 
+#include "DialogFactory.h"
 #include "DispatchResult.h"
 #include "FileDialog.h"
 #include "FontLoader.h"
 #include "GuiApplication.h"
 #include "GuiClickableLabel.h"
-#include "GuiCommandBuffer.h"
 #include "GuiCompleter.h"
+#include "GuiFontMetrics.h"
 #include "GuiKeySymbol.h"
 #include "GuiToc.h"
 #include "GuiToolbar.h"
@@ -51,9 +52,8 @@
 #include "Format.h"
 #include "FuncStatus.h"
 #include "FuncRequest.h"
-#include "Intl.h"
+#include "KeySymbol.h"
 #include "Language.h"
-#include "Layout.h"
 #include "LayoutFile.h"
 #include "Lexer.h"
 #include "LyXAction.h"
@@ -64,7 +64,6 @@
 #include "SpellChecker.h"
 #include "Session.h"
 #include "TexRow.h"
-#include "TextClass.h"
 #include "Text.h"
 #include "Toolbars.h"
 #include "version.h"
@@ -73,9 +72,7 @@
 #include "support/debug.h"
 #include "support/ExceptionMessage.h"
 #include "support/FileName.h"
-#include "support/filetools.h"
 #include "support/gettext.h"
-#include "support/filetools.h"
 #include "support/ForkedCalls.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
@@ -89,8 +86,6 @@
 #include <QAction>
 #include <QApplication>
 #include <QCloseEvent>
-#include <QDebug>
-#include <QDesktopWidget>
 #include <QDragEnterEvent>
 #include <QDropEvent>
 #include <QFuture>
 #include <QPainter>
 #include <QPixmap>
 #include <QPoint>
-#include <QPushButton>
-#include <QScrollBar>
 #include <QSettings>
 #include <QShowEvent>
 #include <QSplitter>
 #include <QStatusBar>
 #include <QSvgRenderer>
 #include <QtConcurrentRun>
-#include <QTime>
 #include <QTimer>
-#include <QToolBar>
 #include <QUrl>
 #include <QWindowStateChangeEvent>
 
@@ -210,16 +201,16 @@ public:
                // Check how long the logo gets with the current font
                // and adapt if the font is running wider than what
                // we assume
-               QFontMetrics fm(font);
+               GuiFontMetrics fm(font);
                // Split the title into lines to measure the longest line
                // in the current l7n.
                QStringList titlesegs = htext.split('\n');
                int wline = 0;
-               int hline = fm.height();
+               int hline = fm.maxHeight();
                QStringList::const_iterator sit;
-               for (sit = titlesegs.constBegin(); sit != titlesegs.constEnd(); ++sit) {
-                       if (fm.width(*sit) > wline)
-                               wline = fm.width(*sit);
+               for (QString const & seg : titlesegs) {
+                       if (fm.width(seg) > wline)
+                               wline = fm.width(seg);
                }
                // The longest line in the reference font (for English)
                // is 180. Calculate scale factor from that.
@@ -236,7 +227,7 @@ public:
                setFocusPolicy(Qt::StrongFocus);
        }
 
-       void paintEvent(QPaintEvent *)
+       void paintEvent(QPaintEvent *) override
        {
                int const w = width_;
                int const h = height_;
@@ -250,7 +241,7 @@ public:
                pain.drawPixmap(x, y, w, h, splash_);
        }
 
-       void keyPressEvent(QKeyEvent * ev)
+       void keyPressEvent(QKeyEvent * ev) override
        {
                KeySymbol sym;
                setKeySymbol(&sym, ev);
@@ -500,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();
 
@@ -746,7 +737,7 @@ QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 static void handleExportStatus(GuiView * view, Buffer::ExportStatus status,
        string const & format)
 {
-       docstring const fmt = theFormats().prettyName(format);
+       docstring const fmt = translateIfPossible(theFormats().prettyName(format));
        docstring msg;
        switch (status) {
        case Buffer::ExportSuccess:
@@ -826,12 +817,11 @@ void GuiView::saveLayout() const
        settings.setValue("devel_mode", devel_mode_);
        settings.beginGroup("views");
        settings.beginGroup(QString::number(id_));
-#if defined(Q_WS_X11) || defined(QPA_XCB)
-       settings.setValue("pos", pos());
-       settings.setValue("size", size());
-#else
-       settings.setValue("geometry", saveGeometry());
-#endif
+       if (guiApp->platformName() == "qt4x11" || guiApp->platformName() == "xcb") {
+               settings.setValue("pos", pos());
+               settings.setValue("size", size());
+       } else
+               settings.setValue("geometry", saveGeometry());
        settings.setValue("layout", saveState(0));
        settings.setValue("icon_size", toqstr(d.iconSize(iconSize())));
 }
@@ -842,13 +832,11 @@ void GuiView::saveUISettings() const
        QSettings settings;
 
        // Save the toolbar private states
-       ToolbarMap::iterator end = d.toolbars_.end();
-       for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-               it->second->saveSession(settings);
+       for (auto const & tb_p : d.toolbars_)
+               tb_p.second->saveSession(settings);
        // Now take care of all other dialogs
-       map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
-       for (; it!= d.dialogs_.end(); ++it)
-               it->second->saveSession(settings);
+       for (auto const & dlg_p : d.dialogs_)
+               dlg_p.second->saveSession(settings);
 }
 
 
@@ -871,19 +859,20 @@ bool GuiView::restoreLayout()
        //code below is skipped when when ~/.config/LyX is (re)created
        setIconSize(d.iconSize(settings.value(icon_key).toString()));
 
-#if defined(Q_WS_X11) || defined(QPA_XCB)
-       QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
-       QSize size = settings.value("size", QSize(690, 510)).toSize();
-       resize(size);
-       move(pos);
-#else
-       // Work-around for bug #6034: the window ends up in an undetermined
-       // state when trying to restore a maximized window when it is
-       // already maximized.
-       if (!(windowState() & Qt::WindowMaximized))
-               if (!restoreGeometry(settings.value("geometry").toByteArray()))
-                       setGeometry(50, 50, 690, 510);
-#endif
+       if (guiApp->platformName() == "qt4x11" || guiApp->platformName() == "xcb") {
+               QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
+               QSize size = settings.value("size", QSize(690, 510)).toSize();
+               resize(size);
+               move(pos);
+       } else {
+               // Work-around for bug #6034: the window ends up in an undetermined
+               // state when trying to restore a maximized window when it is
+               // already maximized.
+               if (!(windowState() & Qt::WindowMaximized))
+                       if (!restoreGeometry(settings.value("geometry").toByteArray()))
+                               setGeometry(50, 50, 690, 510);
+       }
+
        // Make sure layout is correctly oriented.
        setLayoutDirection(qApp->layoutDirection());
 
@@ -902,12 +891,10 @@ bool GuiView::restoreLayout()
                initToolbars();
 
        // init the toolbars that have not been restored
-       Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
-       Toolbars::Infos::iterator end = guiApp->toolbars().end();
-       for (; cit != end; ++cit) {
-               GuiToolbar * tb = toolbar(cit->name);
+       for (auto const & tb_p : guiApp->toolbars()) {
+               GuiToolbar * tb = toolbar(tb_p.name);
                if (tb && !tb->isRestored())
-                       initToolbar(cit->name);
+                       initToolbar(tb_p.name);
        }
 
        // update lock (all) toolbars positions
@@ -942,9 +929,8 @@ void GuiView::updateLockToolbars()
 
 void GuiView::constructToolbars()
 {
-       ToolbarMap::iterator it = d.toolbars_.begin();
-       for (; it != d.toolbars_.end(); ++it)
-               delete it->second;
+       for (auto const & tb_p : d.toolbars_)
+               delete tb_p.second;
        d.toolbars_.clear();
 
        // I don't like doing this here, but the standard toolbar
@@ -954,20 +940,16 @@ void GuiView::constructToolbars()
        d.layout_->move(0,0);
 
        // extracts the toolbars from the backend
-       Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
-       Toolbars::Infos::iterator end = guiApp->toolbars().end();
-       for (; cit != end; ++cit)
-               d.toolbars_[cit->name] =  new GuiToolbar(*cit, *this);
+       for (ToolbarInfo const & inf : guiApp->toolbars())
+               d.toolbars_[inf.name] =  new GuiToolbar(inf, *this);
 }
 
 
 void GuiView::initToolbars()
 {
        // extracts the toolbars from the backend
-       Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
-       Toolbars::Infos::iterator end = guiApp->toolbars().end();
-       for (; cit != end; ++cit)
-               initToolbar(cit->name);
+       for (ToolbarInfo const & inf : guiApp->toolbars())
+               initToolbar(inf.name);
 }
 
 
@@ -1179,15 +1161,12 @@ void GuiView::dropEvent(QDropEvent * event)
                vector<const Format *> found_formats;
 
                // Find all formats that have the correct extension.
-               vector<const Format *> const & import_formats
-                       = theConverters().importableFormats();
-               vector<const Format *>::const_iterator it = import_formats.begin();
-               for (; it != import_formats.end(); ++it)
-                       if ((*it)->hasExtension(ext))
-                               found_formats.push_back(*it);
+               for (const Format * fmt : theConverters().importableFormats())
+                       if (fmt->hasExtension(ext))
+                               found_formats.push_back(fmt);
 
                FuncRequest cmd;
-               if (found_formats.size() >= 1) {
+               if (!found_formats.empty()) {
                        if (found_formats.size() > 1) {
                                //FIXME: show a dialog to choose the correct importable format
                                LYXERR(Debug::FILES,
@@ -1415,13 +1394,16 @@ bool GuiView::event(QEvent * e)
                        if (lyxrc.full_screen_menubar)
                                menuBar()->hide();
                        if (lyxrc.full_screen_toolbars) {
-                               ToolbarMap::iterator end = d.toolbars_.end();
-                               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                                       if (it->second->isVisibiltyOn() && it->second->isVisible())
-                                               it->second->hide();
+                               for (auto const & tb_p  : d.toolbars_)
+                                       if (tb_p.second->isVisibiltyOn() && tb_p.second->isVisible())
+                                               tb_p.second->hide();
                        }
                        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);
@@ -1433,14 +1415,16 @@ bool GuiView::event(QEvent * e)
                        if (lyxrc.full_screen_menubar && !menuBar()->isVisible())
                                menuBar()->show();
                        if (lyxrc.full_screen_toolbars) {
-                               ToolbarMap::iterator end = d.toolbars_.end();
-                               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                                       if (it->second->isVisibiltyOn() && !it->second->isVisible())
-                                               it->second->show();
+                               for (auto const & tb_p  : d.toolbars_)
+                                       if (tb_p.second->isVisibiltyOn() && !tb_p.second->isVisible())
+                                               tb_p.second->show();
                                //updateToolbars();
                        }
                        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;
@@ -1718,7 +1702,6 @@ void GuiView::updateLayoutList()
 
 void GuiView::updateToolbars()
 {
-       ToolbarMap::iterator end = d.toolbars_.end();
        if (d.current_work_area_) {
                int context = 0;
                if (d.current_work_area_->bufferView().cursor().inMathed()
@@ -1743,11 +1726,11 @@ void GuiView::updateToolbars()
                        minibuffer_focus_ = false;
                }
 
-               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                       it->second->update(context);
+               for (auto const & tb_p : d.toolbars_)
+                       tb_p.second->update(context);
        } else
-               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                       it->second->update();
+               for (auto const & tb_p : d.toolbars_)
+                       tb_p.second->update();
 }
 
 
@@ -2134,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))
@@ -2210,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();
@@ -2410,9 +2427,9 @@ Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
        Buffer * newBuffer = nullptr;
        try {
                newBuffer = checkAndLoadLyXFile(filename);
-       } catch (ExceptionMessage const & e) {
+       } catch (ExceptionMessage const &) {
                setBusy(false);
-               throw(e);
+               throw;
        }
        setBusy(false);
 
@@ -2518,25 +2535,23 @@ 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 (; it != en; ++it) {
-                       if (!theConverters().isReachable(format, *it))
+               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()) {
                        frontend::Alert::error(_("Couldn't import file"),
                                         bformat(_("No information for importing the format %1$s."),
-                                        theFormats().prettyName(format)));
+                                        translateIfPossible(theFormats().prettyName(format))));
                        return false;
                }
        } else
@@ -2583,13 +2598,13 @@ void GuiView::importDocument(string const & argument)
                }
 
                docstring const text = bformat(_("Select %1$s file to import"),
-                       theFormats().prettyName(format));
+                       translateIfPossible(theFormats().prettyName(format)));
 
                FileDialog dlg(toqstr(text));
                dlg.setButton1(qt_("D&ocuments"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("&Examples"), toqstr(lyxrc.example_path));
 
-               docstring filter = theFormats().prettyName(format);
+               docstring filter = translateIfPossible(theFormats().prettyName(format));
                filter += " (*.{";
                // FIXME UNICODE
                filter += from_utf8(theFormats().extensions(format));
@@ -3235,11 +3250,7 @@ bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer)
 bool GuiView::closeBuffer(Buffer & buf)
 {
        bool success = true;
-       ListOfBuffers clist = buf.getChildren();
-       ListOfBuffers::const_iterator it = clist.begin();
-       ListOfBuffers::const_iterator const bend = clist.end();
-       for (; it != bend; ++it) {
-               Buffer * child_buf = *it;
+       for (Buffer * child_buf : buf.getChildren()) {
                if (theBufferList().isOthersChild(&buf, child_buf)) {
                        child_buf->setParent(nullptr);
                        continue;
@@ -3286,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();
@@ -3490,10 +3502,7 @@ bool GuiView::reloadBuffer(Buffer & buf)
 
 void GuiView::checkExternallyModifiedBuffers()
 {
-       BufferList::iterator bit = theBufferList().begin();
-       BufferList::iterator const bend = theBufferList().end();
-       for (; bit != bend; ++bit) {
-               Buffer * buf = *bit;
+       for (Buffer * buf : theBufferList()) {
                if (buf->fileName().exists() && buf->isChecksumModified()) {
                        docstring text = bformat(_("Document \n%1$s\n has been externally modified."
                                        " Reload now? Any local changes will be lost."),
@@ -3837,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;
@@ -3880,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
@@ -4037,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: {
@@ -4055,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: {
@@ -4302,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))
@@ -4624,9 +4640,15 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.screenUpdate(Update::Force);
                        break;
 
-               case LFUN_CITATION_OPEN:
-                       frontend::showTarget(argument);
+               case LFUN_CITATION_OPEN: {
+                       string pdfv, psv;
+                       if (theFormats().getFormat("pdf"))
+                               pdfv = theFormats().getFormat("pdf")->viewer();
+                       if (theFormats().getFormat("ps"))
+                               psv = theFormats().getFormat("ps")->viewer();
+                       frontend::showTarget(argument, pdfv, psv);
                        break;
+               }
 
                default:
                        // The LFUN must be for one of BufferView, Buffer or Cursor;
@@ -4678,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
@@ -4870,9 +4898,9 @@ void GuiView::doShowDialog(QString const & qname, QString const & qdata,
                        }
                }
        }
-       catch (ExceptionMessage const & ex) {
+       catch (ExceptionMessage const &) {
                d.in_show_ = false;
-               throw ex;
+               throw;
        }
        d.in_show_ = false;
 }
@@ -4919,21 +4947,15 @@ void GuiView::disconnectDialog(string const & name)
 
 void GuiView::hideAll() const
 {
-       map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
-       map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
-
-       for(; it != end; ++it)
-               it->second->hideView();
+       for(auto const & dlg_p : d.dialogs_)
+               dlg_p.second->hideView();
 }
 
 
 void GuiView::updateDialogs()
 {
-       map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
-       map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
-
-       for(; it != end; ++it) {
-               Dialog * dialog = it->second.get();
+       for(auto const & dlg_p : d.dialogs_) {
+               Dialog * dialog = dlg_p.second.get();
                if (dialog) {
                        if (dialog->needBufferOpen() && !documentBufferView())
                                hideDialog(fromqstr(dialog->name()), nullptr);
@@ -4945,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);
 }