]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
Don't hide dialogs upon buffer switch. I've been wanting to do this for a looonnng...
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index db7462f7e05255034e4c71ba10728285f427e832..215cdeb16057b5ea6f52b38dcaa8b94a2d03b8d7 100644 (file)
@@ -18,6 +18,7 @@
 #include "Dialog.h"
 #include "FileDialog.h"
 #include "GuiApplication.h"
+#include "GuiCompleter.h"
 #include "GuiWorkArea.h"
 #include "GuiKeySymbol.h"
 #include "GuiToolbar.h"
 #include "BufferView.h"
 #include "Converter.h"
 #include "Cursor.h"
+#include "Encoding.h"
 #include "ErrorList.h"
 #include "Format.h"
 #include "FuncStatus.h"
 #include "FuncRequest.h"
-#include "support/gettext.h"
 #include "Intl.h"
 #include "Layout.h"
 #include "Lexer.h"
 #include "ToolbarBackend.h"
 #include "version.h"
 
+#include "support/assert.h"
 #include "support/debug.h"
-#include "support/FileFilterList.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
+#include "support/gettext.h"
 #include "support/ForkedCalls.h"
 #include "support/lstrings.h"
 #include "support/os.h"
@@ -87,7 +89,6 @@
 #include <QUrl>
 #include <QScrollBar>
 
-#include <boost/assert.hpp>
 #include <boost/bind.hpp>
 
 #ifdef HAVE_SYS_TIME_H
@@ -112,18 +113,19 @@ public:
        {
                LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
                /// The text to be written on top of the pixmap
-               QString const text = lyx_version ? lyx_version : qt_("unknown version");
+               QString const text = lyx_version ?
+                       qt_("version ") + lyx_version : qt_("unknown version");
                splash_ = QPixmap(":/images/banner.png");
 
                QPainter pain(&splash_);
-               pain.setPen(QColor(255, 255, 0));
+               pain.setPen(QColor(0, 0, 0));
                QFont font;
                // The font used to display the version info
                font.setStyleHint(QFont::SansSerif);
                font.setWeight(QFont::Bold);
                font.setPointSize(int(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble()));
                pain.setFont(font);
-               pain.drawText(260, 270, text);
+               pain.drawText(190, 225, text);
        }
 
        void paintEvent(QPaintEvent *)
@@ -299,8 +301,8 @@ GuiView::GuiView(int id)
        // We don't want to keep the window in memory if it is closed.
        setAttribute(Qt::WA_DeleteOnClose, true);
 
-#ifndef Q_WS_MACX
-       // assign an icon to main form. We do not do it under Qt/Mac,
+#if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX))
+       // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac,
        // since the icon is provided in the application bundle.
        setWindowIcon(QPixmap(":/images/lyx.png"));
 #endif
@@ -409,7 +411,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
                                break;
                        }
                }
-               if (b && !closeBuffer(*b)) {
+               if (b && !closeBuffer(*b, true)) {
                        close_event->ignore();
                        return;
                }
@@ -762,7 +764,7 @@ GuiWorkArea const * GuiView::currentWorkArea() const
 
 void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
 {
-       BOOST_ASSERT(wa);
+       LASSERT(wa, /**/);
 
        // Changing work area can result from opening a file so
        // update the toc in any case.
@@ -778,11 +780,10 @@ void GuiView::setCurrentWorkArea(GuiWorkArea * wa)
 
 void GuiView::removeWorkArea(GuiWorkArea * wa)
 {
-       BOOST_ASSERT(wa);
+       LASSERT(wa, /**/);
        if (wa == d.current_work_area_) {
                disconnectBuffer();
                disconnectBufferView();
-               hideBufferDependent();
                d.current_work_area_ = 0;
        }
 
@@ -867,7 +868,7 @@ Buffer const * GuiView::buffer() const
 
 void GuiView::setBuffer(Buffer * newBuffer)
 {
-       BOOST_ASSERT(newBuffer);
+       LASSERT(newBuffer, /**/);
        setBusy(true);
 
        GuiWorkArea * wa = workArea(*newBuffer);
@@ -947,12 +948,6 @@ void GuiView::updateToc()
 }
 
 
-void GuiView::updateEmbeddedFiles()
-{
-       updateDialog("embedding", "");
-}
-
-
 void GuiView::autoSave()
 {
        LYXERR(Debug::INFO, "Running autoSave()");
@@ -1072,7 +1067,7 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
                        FuncStatus fs;
                        if (!inset->getStatus(view()->cursor(), fr, fs)) {
                                // Every inset is supposed to handle this
-                               BOOST_ASSERT(false);
+                               LASSERT(false, /**/);
                        }
                        flag |= fs;
                } else {
@@ -1121,9 +1116,8 @@ static FileName selectTemplateFile()
        dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
        dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
 
-       FileDialog::Result result =
-               dlg.open(toqstr(lyxrc.template_path),
-                            FileFilterList(_("LyX Documents (*.lyx)")));
+       FileDialog::Result result = dlg.open(toqstr(lyxrc.template_path),
+                            QStringList(qt_("LyX Documents (*.lyx)")));
 
        if (result.first == FileDialog::Later)
                return FileName();
@@ -1182,7 +1176,7 @@ void GuiView::openDocument(string const & fname)
                                toqstr(addPath(package().system_support().absFilename(), "examples")));
 
                FileDialog::Result result =
-                       dlg.open(toqstr(initpath), FileFilterList(_("LyX Documents (*.lyx)")));
+                       dlg.open(toqstr(initpath), QStringList(qt_("LyX Documents (*.lyx)")));
 
                if (result.first == FileDialog::Later)
                        return;
@@ -1321,7 +1315,7 @@ void GuiView::importDocument(string const & argument)
                filter += ')';
 
                FileDialog::Result result =
-                       dlg.open(toqstr(initpath), FileFilterList(filter));
+                       dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));
 
                if (result.first == FileDialog::Later)
                        return;
@@ -1337,7 +1331,7 @@ void GuiView::importDocument(string const & argument)
                return;
 
        // get absolute path of file
-       FileName const fullname(makeAbsPath(filename));
+       FileName const fullname(support::makeAbsPath(filename));
 
        FileName const lyxfile(support::changeExtension(fullname.absFilename(), ".lyx"));
 
@@ -1434,9 +1428,8 @@ void GuiView::insertLyXFile(docstring const & fname)
                toqstr(addPath(package().system_support().absFilename(),
                "examples")));
 
-       FileDialog::Result result =
-               dlg.open(toqstr(initpath),
-                            FileFilterList(_("LyX Documents (*.lyx)")));
+       FileDialog::Result result = dlg.open(toqstr(initpath),
+                            QStringList(qt_("LyX Documents (*.lyx)")));
 
        if (result.first == FileDialog::Later)
                return;
@@ -1474,7 +1467,7 @@ void GuiView::insertPlaintextFile(docstring const & fname,
                LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
 
        FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
-               FileFilterList());
+               QStringList());
 
        if (result.first == FileDialog::Later)
                return;
@@ -1500,7 +1493,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
 
        if (!newname.empty()) {
                // FIXME UNICODE
-               fname = makeAbsPath(to_utf8(newname), oldname.onlyPath().absFilename());
+               fname = support::makeAbsPath(to_utf8(newname), oldname.onlyPath().absFilename());
        } else {
                // Switch to this Buffer.
                setBuffer(&b);
@@ -1515,11 +1508,9 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                if (!isLyXFilename(fname.absFilename()))
                        fname.changeExtension(".lyx");
 
-               FileFilterList const filter(_("LyX Documents (*.lyx)"));
-
                FileDialog::Result result =
                        dlg.save(toqstr(fname.onlyPath().absFilename()),
-                                    filter,
+                              QStringList(qt_("LyX Documents (*.lyx)")),
                                     toqstr(fname.onlyFileName()));
 
                if (result.first == FileDialog::Later)
@@ -1609,7 +1600,7 @@ bool GuiView::closeBuffer()
 }
 
 
-bool GuiView::closeBuffer(Buffer & buf)
+bool GuiView::closeBuffer(Buffer & buf, bool tolastopened)
 {
        // goto bookmark to update bookmark pit.
        //FIXME: we should update only the bookmarks related to this buffer!
@@ -1617,7 +1608,7 @@ bool GuiView::closeBuffer(Buffer & buf)
                theLyXFunc().gotoBookmark(i+1, false, false);
 
        if (buf.isClean() || buf.paragraphs().empty()) {
-               if (buf.masterBuffer() == &buf)
+               if (buf.masterBuffer() == &buf && tolastopened)
                        LyX::ref().session().lastOpened().add(buf.fileName());
                theBufferList().release(&buf);
                return true;
@@ -1659,7 +1650,7 @@ bool GuiView::closeBuffer(Buffer & buf)
        // save file names to .lyx/session
        // if master/slave are both open, do not save slave since it
        // will be automatically loaded when the master is loaded
-       if (buf.masterBuffer() == &buf)
+       if (buf.masterBuffer() == &buf && tolastopened)
                LyX::ref().session().lastOpened().add(buf.fileName());
 
        theBufferList().release(&buf);
@@ -1735,10 +1726,10 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                        // We cannot use a for loop as the buffer list cycles.
                        Buffer * b = first;
                        do {
-                               if (b->isClean())
-                                       continue;
-                               saveBuffer(*b);
-                               LYXERR(Debug::ACTION, "Saved " << b->absFileName());
+                               if (!b->isClean()) {
+                                       saveBuffer(*b);
+                                       LYXERR(Debug::ACTION, "Saved " << b->absFileName());
+                               }
                                b = theBufferList().next(b);
                        } while (b != first); 
                        message(_("All documents saved."));
@@ -1959,7 +1950,7 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd)
 #if QT_VERSION >= 0x040300
                setContentsMargins(0, 0, 0, 0);
 #endif
-               showNormal();
+               setWindowState(windowState() ^ Qt::WindowFullScreen);
                menuBar()->show();
                statusBar()->show();
        } else {
@@ -1968,7 +1959,7 @@ void GuiView::lfunUiToggle(FuncRequest const & cmd)
 #if QT_VERSION >= 0x040300
                setContentsMargins(-2, -2, -2, -2);
 #endif
-               showFullScreen();
+               setWindowState(windowState() ^ Qt::WindowFullScreen);
                statusBar()->hide();
                menuBar()->hide();
        }
@@ -2016,7 +2007,7 @@ namespace {
 
 char const * const dialognames[] = {
 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
-"citation", "document", "embedding", "errorlist", "ert", "external", "file",
+"citation", "document", "errorlist", "ert", "external", "file",
 "findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log",
 "mathdelimiter", "mathmatrix", "note", "paragraph", "prefs", "print", 
 "ref", "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate",
@@ -2156,19 +2147,6 @@ void GuiView::hideAll() const
 }
 
 
-void GuiView::hideBufferDependent() const
-{
-       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();
-               if (dialog->isBufferDependent())
-                       dialog->hideView();
-       }
-}
-
-
 void GuiView::updateBufferDependent(bool switched) const
 {
        map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
@@ -2253,7 +2231,7 @@ Dialog * createGuiWrap(GuiView & lv);
 
 Dialog * GuiView::build(string const & name)
 {
-       BOOST_ASSERT(isValidName(name));
+       LASSERT(isValidName(name), /**/);
 
        if (name == "aboutlyx")
                return createGuiAbout(*this);