]> git.lyx.org Git - features.git/commitdiff
Transfer LyXView::loadLyXFile() to lyxFunc::loadAndViewFile(). This enables to get...
authorAbdelrazak Younes <younes@lyx.org>
Mon, 19 Nov 2007 12:03:38 +0000 (12:03 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 19 Nov 2007 12:03:38 +0000 (12:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21677 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyX.cpp
src/LyXFunc.cpp
src/LyXFunc.h
src/frontends/LyXView.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp

index f90e09ce5bfe8cefbb0f20d34f6c83922f0baeaf..456b47ebf698493d9a55e9fd8373d84751f4bd83 100644 (file)
@@ -638,7 +638,7 @@ void LyX::restoreGuiSession()
        if (!pimpl_->files_to_load_.empty()) {
                for_each(pimpl_->files_to_load_.begin(),
                        pimpl_->files_to_load_.end(),
-                       bind(&LyXView::loadLyXFile, view, _1, true));
+                       bind(&LyXFunc::loadAndViewFile, pimpl_->lyxfunc_, _1, true));
                // clear this list to save a few bytes of RAM
                pimpl_->files_to_load_.clear();
                pimpl_->session_->lastOpened().clear();
@@ -649,7 +649,7 @@ void LyX::restoreGuiSession()
                // last session, and should be already there (regular files), or should
                // not be added at all (help files).
                for_each(lastopened.begin(), lastopened.end(),
-                       bind(&LyXView::loadLyXFile, view, _1, false));
+                       bind(&LyXFunc::loadAndViewFile, pimpl_->lyxfunc_, _1, false));
 
                // clear this list to save a few bytes of RAM
                pimpl_->session_->lastOpened().clear();
index ca9428fc26b070749b5aca48399b1800ce9b8820..bd8d8da8ff51cd9d2bc675a76820ea0680036138 100644 (file)
@@ -84,6 +84,7 @@
 
 #include "support/environment.h"
 #include "support/FileFilterList.h"
+#include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/Path.h"
@@ -176,7 +177,7 @@ bool import(LyXView * lv, FileName const & filename,
 
 
        if (loader_format == "lyx") {
-               Buffer * buf = lv->loadLyXFile(lyxfile);
+               Buffer * buf = theLyXFunc().loadAndViewFile(lyxfile);
                if (!buf) {
                        // we are done
                        lv->message(_("file not imported!"));
@@ -1273,7 +1274,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                        lyx_view_->message(bformat(_("Opening help file %1$s..."),
                                makeDisplayPath(fname.absFilename())));
-                       Buffer * buf = lyx_view_->loadLyXFile(fname, false);
+                       Buffer * buf = loadAndViewFile(fname, false);
                        if (buf) {
                                updateLabels(*buf);
                                lyx_view_->setBuffer(buf);
@@ -1398,7 +1399,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                if (theBufferList().exists(s.absFilename()))
                                        buf = theBufferList().getBuffer(s.absFilename());
                                else {
-                                       buf = lyx_view_->loadLyXFile(s);
+                                       buf = loadAndViewFile(s);
                                        loaded = true;
                                }
                        }
@@ -1620,7 +1621,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        } else {
                                setMessage(bformat(_("Opening child document %1$s..."),
                                        makeDisplayPath(filename.absFilename())));
-                               child = lyx_view_->loadLyXFile(filename, true);
+                               child = loadAndViewFile(filename, true);
                                parsed = true;
                        }
                        if (child) {
@@ -2164,6 +2165,36 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
 }
 
 
+Buffer * LyXFunc::loadAndViewFile(FileName const & filename, bool tolastfiles)
+{
+       lyx_view_->setBusy(true);
+
+       Buffer * newBuffer = checkAndLoadLyXFile(filename);
+
+       if (!newBuffer) {
+               lyx_view_->message(_("Document not loaded."));
+               lyx_view_->updateStatusBar();
+               lyx_view_->setBusy(false);
+               return 0;
+       }
+
+       lyx_view_->setBuffer(newBuffer);
+
+       // scroll to the position when the file was last closed
+       if (lyxrc.use_lastfilepos) {
+               LastFilePosSection::FilePos filepos =
+                       LyX::ref().session().lastFilePos().load(filename);
+               lyx_view_->view()->moveToPosition(filepos.pit, filepos.pos, 0, 0);
+       }
+
+       if (tolastfiles)
+               LyX::ref().session().lastFiles().add(filename);
+
+       lyx_view_->setBusy(false);
+       return newBuffer;
+}
+
+
 void LyXFunc::open(string const & fname)
 {
        string initpath = lyxrc.document_path;
@@ -2220,7 +2251,7 @@ void LyXFunc::open(string const & fname)
        lyx_view_->message(bformat(_("Opening document %1$s..."), disp_fn));
 
        docstring str2;
-       Buffer * buf = lyx_view_->loadLyXFile(fullname);
+       Buffer * buf = loadAndViewFile(fullname);
        if (buf) {
                updateLabels(*buf);
                lyx_view_->setBuffer(buf);
@@ -2335,7 +2366,7 @@ void LyXFunc::reloadBuffer()
        docstring const disp_fn = makeDisplayPath(filename.absFilename());
        docstring str;
        closeBuffer();
-       Buffer * buf = lyx_view_->loadLyXFile(filename);
+       Buffer * buf = loadAndViewFile(filename);
        if (buf) {
                updateLabels(*buf);
                lyx_view_->setBuffer(buf);
index 137b533f5303e1f72e96a1d5b18ef006fee12440..bb5cab78ace1df3dd49e80856ad8cf98617400de 100644 (file)
@@ -30,6 +30,10 @@ class FuncStatus;
 class KeySymbol;
 class Text;
 
+namespace support {
+class FileName;
+}
+
 namespace frontend {
 class LyXView;
 }
@@ -83,6 +87,10 @@ public:
        ///             not the current buffer
        void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
 
+       /// load a buffer into the current workarea.
+       Buffer * loadAndViewFile(support::FileName const &  name, ///< File to load.
+               bool tolastfiles = true);  ///< append to the "Open recent" menu?
+
 private:
        ///
        BufferView * view() const;
index 3ce3381ab8f4e92d604cbe88069272867d8a3aad..573934d0db7b800a326e6d9c3366b199061d47a3 100644 (file)
@@ -72,10 +72,6 @@ public:
 
        //@}
 
-       /// load a buffer into the current workarea.
-       virtual Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
-               bool tolastfiles = true) = 0;  ///< append to the "Open recent" menu?
-
        /// updates the possible layouts selectable
        virtual void updateLayoutChoice(bool force) = 0;
        /// update the toolbar
index fc781eddcae7bc0cf981d76f474dc49af3a1e154..7415abc94fc965f0c4e7977c8da4a21d13388e6f 100644 (file)
@@ -31,11 +31,6 @@ using std::string;
 
 #include "qt_helpers.h"
 
-#include "support/filetools.h"
-#include "support/convert.h"
-#include "support/lstrings.h"
-#include "support/os.h"
-
 #include "buffer_funcs.h"
 #include "Buffer.h"
 #include "BufferList.h"
@@ -58,8 +53,9 @@ using std::string;
 #include "ToolbarBackend.h"
 #include "version.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
-#include "support/filetools.h" // OnlyFilename()
+#include "support/os.h"
 #include "support/Timeout.h"
 
 #include <QAction>
@@ -104,9 +100,6 @@ extern bool quitting;
 namespace frontend {
 
 using support::bformat;
-using support::FileName;
-using support::makeDisplayPath;
-using support::onlyFilename;
 
 namespace {
 
@@ -874,40 +867,6 @@ void GuiView::setBuffer(Buffer * newBuffer)
 }
 
 
-Buffer * GuiView::loadLyXFile(FileName const & filename, bool tolastfiles)
-{
-       setBusy(true);
-
-       Buffer * newBuffer = checkAndLoadLyXFile(filename);
-
-       if (!newBuffer) {
-               message(_("Document not loaded."));
-               updateStatusBar();
-               setBusy(false);
-               return 0;
-       }
-
-       GuiWorkArea * wa = workArea(*newBuffer);
-       if (wa == 0)
-               wa = addWorkArea(*newBuffer);
-
-       // scroll to the position when the file was last closed
-       if (lyxrc.use_lastfilepos) {
-               LastFilePosSection::FilePos filepos =
-                       LyX::ref().session().lastFilePos().load(filename);
-               // if successfully move to pit (returned par_id is not zero),
-               // update metrics and reset font
-               wa->bufferView().moveToPosition(filepos.pit, filepos.pos, 0, 0);
-       }
-
-       if (tolastfiles)
-               LyX::ref().session().lastFiles().add(filename);
-
-       setBusy(false);
-       return newBuffer;
-}
-
-
 void GuiView::connectBuffer(Buffer & buf)
 {
        buf.setGuiDelegate(this);
index 05bcfe3c67296952613037087e5976208da2a312..e7b08aa48fcb17cae788eb18543b84c2c300ba6d 100644 (file)
@@ -99,10 +99,6 @@ public:
        /// \return the current buffer view.
        BufferView * view();
 
-       /// load a buffer into the current workarea.
-       Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
-               bool tolastfiles = true);  ///< append to the "Open recent" menu?
-
        /** redraw \c inset in all the BufferViews in which it is currently
         *  visible. If successful return a pointer to the owning Buffer.
         */
index d68b4cc392c34986c598ebf17b9f51940e36273b..73d31fb888c839a9db95961ce793f410effb8901 100644 (file)
@@ -1060,12 +1060,14 @@ GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
 {
        GuiWorkArea * wa = new GuiWorkArea(buffer, view);
        wa->setUpdatesEnabled(false);
+       // Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
+       // when hiding it again below).
+       showBar(count() > 0);
        addTab(wa, wa->windowTitle());
        QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
                this, SLOT(updateTabText(GuiWorkArea *)));
        // Hide tabbar if there's only one tab.
        showBar(count() > 1);
-       wa->resizeBufferView();
        return wa;
 }