]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
Factorize general code out of GuiDialog and into the base Dialog class. This is now...
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 0e16d88a56f532accc68185534d883e27c64203f..f2c7ced20391b7abbd35b60100cb5f64383c8a9c 100644 (file)
@@ -23,6 +23,7 @@
 #include "GuiMenubar.h"
 #include "GuiToolbar.h"
 #include "GuiToolbars.h"
+#include "GuiProgress.h"
 
 #include "qt_helpers.h"
 
@@ -461,7 +462,7 @@ void GuiView::dropEvent(QDropEvent* event)
                string const file = support::os::internal_path(fromqstr(
                        files.at(i).toLocalFile()));
                if (!file.empty())
-                       dispatch(FuncRequest(LFUN_FILE_OPEN, file));
+                       lyx::dispatch(FuncRequest(LFUN_FILE_OPEN, file));
        }
 }
 
@@ -1032,6 +1033,49 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
 }
 
 
+static FileName selectTemplateFile()
+{
+       FileDialog dlg(_("Select template file"));
+       dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+       dlg.setButton1(_("Templates|#T#t"), from_utf8(lyxrc.template_path));
+
+       FileDialog::Result result =
+               dlg.open(from_utf8(lyxrc.template_path),
+                            FileFilterList(_("LyX Documents (*.lyx)")),
+                            docstring());
+
+       if (result.first == FileDialog::Later)
+               return FileName();
+       if (result.second.empty())
+               return FileName();
+       return FileName(to_utf8(result.second));
+}
+
+
+void GuiView::newDocument(string const & filename, bool from_template)
+{
+       FileName initpath(lyxrc.document_path);
+       Buffer * buf = buffer();
+       if (buf) {
+               FileName const trypath(buf->filePath());
+               // If directory is writeable, use this as default.
+               if (trypath.isDirWritable())
+                       initpath = trypath;
+       }
+
+       string templatefile = from_template ?
+               selectTemplateFile().absFilename() : string();
+       Buffer * b;
+       if (filename.empty())
+               b = newUnnamedFile(templatefile, initpath);
+       else
+               b = newFile(filename, templatefile, true);
+
+       if (b)
+               setBuffer(b);
+}
+
+
 void GuiView::insertLyXFile(docstring const & fname)
 {
        BufferView * bv = view();
@@ -1526,7 +1570,7 @@ char const * const dialognames[] = {
 "thesaurus",
 #endif
 
-"texinfo", "toc", "href", "view-source", "vspace", "wrap", "listings" };
+"texinfo", "toc", "href", "view-source", "latex-progress", "vspace", "wrap", "listings" };
 
 char const * const * const end_dialognames =
        dialognames + (sizeof(dialognames) / sizeof(char *));
@@ -1624,7 +1668,7 @@ void GuiView::hideDialog(string const & name, Inset * inset)
 
        Dialog * const dialog = it->second.get();
        if (dialog->isVisibleView())
-               dialog->hide();
+               dialog->hideView();
        d.open_insets_[name] = 0;
 }
 
@@ -1655,7 +1699,7 @@ void GuiView::hideAll() const
        std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
 
        for(; it != end; ++it)
-               it->second->hide();
+               it->second->hideView();
 }
 
 
@@ -1667,7 +1711,7 @@ void GuiView::hideBufferDependent() const
        for(; it != end; ++it) {
                Dialog * dialog = it->second.get();
                if (dialog->isBufferDependent())
-                       dialog->hide();
+                       dialog->hideView();
        }
 }
 
@@ -1679,11 +1723,13 @@ void GuiView::updateBufferDependent(bool switched) const
 
        for(; it != end; ++it) {
                Dialog * dialog = it->second.get();
+               if (!dialog->isVisibleView())
+                       continue;
                if (switched && dialog->isBufferDependent()) {
-                       if (dialog->isVisibleView() && dialog->initialiseParams(""))
+                       if (dialog->initialiseParams(""))
                                dialog->updateView();
                        else
-                               dialog->hide();
+                               dialog->hideView();
                } else {
                        // A bit clunky, but the dialog will request
                        // that the kernel provides it with the necessary
@@ -1748,6 +1794,7 @@ Dialog * createGuiThesaurus(GuiView & lv);
 Dialog * createGuiHyperlink(GuiView & lv);
 Dialog * createGuiVSpace(GuiView & lv);
 Dialog * createGuiViewSource(GuiView & lv);
+Dialog * createGuiProgress(GuiView & lv);
 Dialog * createGuiWrap(GuiView & lv);
 
 
@@ -1799,6 +1846,8 @@ Dialog * GuiView::build(string const & name)
                return createGuiLog(*this);
        if (name == "view-source")
                return createGuiViewSource(*this);
+       if (name == "latex-progress")
+               return createGuiProgress(*this);
        if (name == "mathdelimiter")
                return createGuiDelimiter(*this);
        if (name == "mathmatrix")