Lars Gullik Bjønnes wrote:
Abdelrazak Younes <[EMAIL PROTECTED]> writes:

| Right now, when the user press a key, th Qt event handler calls the
| processKeySym lfun which calls BufferView::update() (two times). The
| signal LyXView::view_state_changed() is then emitted from there (two
| times). But the frontend was of course aware of the keyPress as it was
| asking for it. So it does not have to react to it but just to complete
| the action with the relevant needed update (titles, dialogs, etc). My
| next cleanup round eliminates this view_state_changed signal.

But the frontend should not know the action required from a
keypress... So how does the frontend know that something actually has
to change at all?

This patch answers your question.

Committed to "younes". Once I have verified that qt3 works correctly I will be ready to merge. If you are happy about the size of the patch feel free to split it up. IMHO, it is one logical change.

Log:

This commit move out from BufferView all update to the LyXView owner. The goal is that BufferView is not used directly but LyXView instead. There is a degradation of performance due to too many calls to WorkArea::redraw(). I have to review which one is really necessary.

BufferView(pimpl):
* std::string firstLayout(): new method returning the first layout of the Buffer.
* newFile(...): method deleted
* connectBuffer(): connect Buffer::closing to LyXView::setBuffer()
* setBuffer(): calls to owner_->update* deleted
* update(): additional updateMetrics(singlePar) call needed for fitCursor.

[qt3,qt4,gtk]/lyx_gui.C:
* connect the files to LyXView::loadLyXFile instead of BufferView::loadLyXFile

LyXView:
* setBuffer(): new methods to be used instead of BufferView::setBuffer()
* loadLyXFile(): new methods to be used instead of BufferView::loadLyXFile()

importer.C, lyx_cb.C, lyxfunc.C:
* adapt to BufferView and LyXView changes




Index: BufferView.C
===================================================================
--- BufferView.C        (revision 14345)
+++ BufferView.C        (working copy)
@@ -97,9 +97,9 @@
 }
 
 
-void BufferView::newFile(string const & fn, string const & tn, bool named)
+string BufferView::firstLayout()
 {
-       pimpl_->newFile(fn, tn, named);
+       return pimpl_->firstLayout();
 }
 
 
Index: BufferView.h
===================================================================
--- BufferView.h        (revision 14345)
+++ BufferView.h        (working copy)
@@ -98,6 +98,8 @@
        void setBuffer(Buffer * b);
        /// return the buffer being viewed
        Buffer * buffer() const;
+       /// return the first layout of the Buffer.
+       std::string firstLayout();
 
        /// return the owning main view
        LyXView * owner() const;
@@ -107,9 +109,6 @@
 
        /// reload the contained buffer
        void reload();
-       /// create a new buffer based on template
-       void newFile(std::string const & fname, std::string const & tname,
-                    bool named = true);
        /// load a buffer into the view
        bool loadLyXFile(std::string const & name, bool tolastfiles = true);
 
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 14374)
+++ BufferView_pimpl.C  (working copy)
@@ -188,7 +188,7 @@
 
        closingConnection_ =
                buf.closing.connect(
-                       boost::bind(&BufferView::Pimpl::setBuffer, this, 
(Buffer *)0));
+                       boost::bind(&LyXView::setBuffer, owner_, (Buffer *)0));
 }
 
 
@@ -204,13 +204,6 @@
 }
 
 
-void BufferView::Pimpl::newFile(string const & filename, string const & tname,
-       bool isNamed)
-{
-       setBuffer(::newFile(filename, tname, isNamed));
-}
-
-
 bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
 {
        // Get absolute path of file and add ".lyx"
@@ -258,7 +251,7 @@
                         text, 0, 1, _("&Create"), _("Cancel"));
 
                if (ret == 0)
-                       b = ::newFile(s, string(), true);
+                       b = newFile(s, string(), true);
                else
                        return false;
        }
@@ -378,12 +371,14 @@
 
        update();
 
-       // FIXME: All these calls should be transfered to the frontend.
-       owner_->updateMenubar();
-       owner_->updateToolbars();
-       owner_->updateLayoutChoice();
-       owner_->updateWindowTitle();
+       if (buffer_ && lyx::graphics::Previews::status() != LyXRC::PREVIEW_OFF)
+               lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
+}
 
+string BufferView::Pimpl::firstLayout()
+{
+       string firstlayout;
+
        // This is done after the layout combox has been populated
        if (buffer_) {
                size_t i = cursor_.depth() - 1;
@@ -392,20 +387,14 @@
                        CursorSlice const & slice = cursor_[i];
                        if (!slice.inset().inMathed()) {
                                LyXLayout_ptr const layout = 
slice.paragraph().layout();
-                               owner_->setLayout(layout->name());
+                               firstlayout = layout->name();
                                break;
                        }
                        BOOST_ASSERT(i>0);
                        --i;
                }
        }
-
-       if (buffer_ && lyx::graphics::Previews::status() != LyXRC::PREVIEW_OFF)
-               lyx::graphics::Previews::get().generateBufferPreviews(*buffer_);
-
-       // FIXME: This call is needed for the first drawing of the buffer
-       // on screen. This call should be transfered to the frontend elsewhere.
-       owner_->redrawWorkArea();
+       return firstlayout;
 }
 
 
@@ -690,6 +679,8 @@
        bool singlePar = flags & Update::SinglePar;
        needs_redraw_ = (flags & (Update::Force | Update::SinglePar));
 
+       updateMetrics(singlePar);
+
        if ((flags & (Update::FitCursor | Update::MultiParSel))
                && (fitCursor() || multiParSel())) {
                        needs_redraw_ = true;
@@ -700,11 +691,6 @@
                // Second drawing step
                updateMetrics(singlePar);
        }
-
-       // FIXME: this call should be removed. It is still there now
-       // because some actions do not redraw the screen. When all action
-       // have been fixed, the line will be removed.
-//     owner_->redrawWorkArea();
 }
 
 
@@ -843,7 +829,7 @@
                string initpath = lyxrc.document_path;
 
                if (available()) {
-                       string const trypath = owner_->buffer()->filePath();
+                       string const trypath = buffer_->filePath();
                        // If directory is writeable, use this as default.
                        if (isDirWriteable(trypath))
                                initpath = trypath;
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h  (revision 14344)
+++ BufferView_pimpl.h  (working copy)
@@ -49,6 +49,8 @@
        Pimpl(BufferView & bv, LyXView * owner);
        ///
        void setBuffer(Buffer * buf);
+       /// return the first layout of the Buffer.
+       std::string firstLayout();
        ///
        void resizeCurrentBuffer();
        //
@@ -57,9 +59,7 @@
        bool multiParSel();
        ///
        void update(Update::flags flags = Update::Force);
-       ///
-       void newFile(std::string const &, std::string const &, bool);
-       ///
+       /// load a buffer into the view
        bool loadLyXFile(std::string const &, bool);
        ///
        void workAreaResize(int width, int height);
Index: frontends/gtk/lyx_gui.C
===================================================================
--- frontends/gtk/lyx_gui.C     (revision 14346)
+++ frontends/gtk/lyx_gui.C     (working copy)
@@ -160,7 +160,7 @@
                          os::internal_path(package().temp_dir() + 
"/lyxsocket"));
 
        for_each(files.begin(), files.end(),
-                bind(&BufferView::loadLyXFile, view.view(), _1, true));
+                bind(&LyXView::loadLyXFile, &view, _1, true));
 
        // handle the batch commands the user asked for
        if (!batch.empty()) {
Index: frontends/LyXView.C
===================================================================
--- frontends/LyXView.C (revision 14368)
+++ frontends/LyXView.C (working copy)
@@ -120,6 +120,32 @@
 }
 
 
+void LyXView::setBuffer(Buffer * b)
+{
+       work_area_->bufferView().setBuffer(b);
+       updateMenubar();
+       updateToolbars();
+       updateLayoutChoice();
+       updateWindowTitle();
+       if (b)
+               setLayout(work_area_->bufferView().firstLayout());
+       redrawWorkArea();
+}
+
+
+bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
+{
+       bool loaded = work_area_->bufferView().loadLyXFile(filename, 
tolastfiles);
+       updateMenubar();
+       updateToolbars();
+       updateLayoutChoice();
+       updateWindowTitle();
+       if (loaded)
+               setLayout(work_area_->bufferView().firstLayout());
+       redrawWorkArea();
+       return loaded;
+}
+
 BufferView * LyXView::view() const
 {
        return &work_area_->bufferView();
Index: frontends/LyXView.h
===================================================================
--- frontends/LyXView.h (revision 14368)
+++ frontends/LyXView.h (working copy)
@@ -111,6 +111,12 @@
 
        //@}
 
+       /// load a buffer into the current workarea
+       bool loadLyXFile(std::string const &  name, bool tolastfiles = true);
+
+       /// set a buffer to the current workarea
+       void setBuffer(Buffer * b);
+
        /// sets the layout in the toolbar layout selection
        void setLayout(std::string const & layout);
        /// updates the possible layouts selectable
Index: frontends/qt3/lyx_gui.C
===================================================================
--- frontends/qt3/lyx_gui.C     (revision 14345)
+++ frontends/qt3/lyx_gui.C     (working copy)
@@ -265,7 +265,7 @@
                          os::internal_path(package().temp_dir() + 
"/lyxsocket"));
 
        for_each(files.begin(), files.end(),
-                bind(&BufferView::loadLyXFile, view.view(), _1, true));
+                bind(&LyXView::loadLyXFile, &view, _1, true));
 
        // handle the batch commands the user asked for
        if (!batch.empty()) {
Index: frontends/qt4/lyx_gui.C
===================================================================
--- frontends/qt4/lyx_gui.C     (revision 14346)
+++ frontends/qt4/lyx_gui.C     (working copy)
@@ -240,7 +240,7 @@
                          os::internal_path(package().temp_dir() + 
"/lyxsocket"));
 
        for_each(files.begin(), files.end(),
-                bind(&BufferView::loadLyXFile, view.view(), _1, true));
+                bind(&LyXView::loadLyXFile, &view, _1, true));
 
        // handle the batch commands the user asked for
        if (!batch.empty()) {
Index: importer.C
===================================================================
--- importer.C  (revision 14344)
+++ importer.C  (working copy)
@@ -24,6 +24,7 @@
 #include "frontends/Alert.h"
 #include "gettext.h"
 #include "BufferView.h"
+#include "buffer_funcs.h"
 
 using lyx::support::bformat;
 using lyx::support::changeExtension;
@@ -69,9 +70,10 @@
 
 
        if (loader_format == "lyx") {
-               lv->view()->loadLyXFile(lyxfile);
+               lv->loadLyXFile(lyxfile);
        } else {
-               lv->view()->newFile(lyxfile, string(), true);
+               lv->setBuffer(newFile(lyxfile, string(), true));
                bool as_paragraphs = loader_format == "textparagraph";
                string filename2 = (loader_format == format) ? filename
                        : changeExtension(filename,
Index: lyx_cb.C
===================================================================
--- lyx_cb.C    (revision 14344)
+++ lyx_cb.C    (working copy)
@@ -19,6 +19,7 @@
 #include "buffer.h"
 #include "bufferlist.h"
 #include "BufferView.h"
+#include "buffer_funcs.h"
 #include "cursor.h"
 #include "debug.h"
 #include "gettext.h"
@@ -342,7 +343,7 @@
                            << "\nName is " << name
                            << "\nTemplate is " << tmpname << endl;
 
-       bv->newFile(name, tmpname);
+       bv->setBuffer(newFile(name, tmpname));
 }
 
 
Index: lyxfunc.C
===================================================================
--- lyxfunc.C   (revision 14344)
+++ lyxfunc.C   (working copy)
@@ -1046,7 +1046,7 @@
                        }
                        owner->message(bformat(_("Opening help file %1$s..."),
                                makeDisplayPath(fname)));
-                       view()->loadLyXFile(fname, false);
+                       owner->loadLyXFile(fname, false);
                        break;
                }
 
@@ -1092,15 +1092,15 @@
 
                // --- buffers ----------------------------------------
                case LFUN_BUFFER_SWITCH:
-                       view()->setBuffer(bufferlist.getBuffer(argument));
+                       owner->setBuffer(bufferlist.getBuffer(argument));
                        break;
 
                case LFUN_BUFFER_NEXT:
-                       view()->setBuffer(bufferlist.next(view()->buffer()));
+                       owner->setBuffer(bufferlist.next(view()->buffer()));
                        break;
 
                case LFUN_BUFFER_PREVIOUS:
-                       
view()->setBuffer(bufferlist.previous(view()->buffer()));
+                       owner->setBuffer(bufferlist.previous(view()->buffer()));
                        break;
 
                case LFUN_FILE_NEW:
@@ -1140,16 +1140,16 @@
                        if (prefixIs(file_name, package().temp_dir())) {
                                // Needed by inverse dvi search. If it is a file
                                // in tmpdir, call the apropriated function
-                               
view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
+                               
owner->setBuffer(bufferlist.getBufferFromTmp(file_name));
                        } else {
                                // Must replace extension of the file to be .lyx
                                // and get full path
                                string const s = changeExtension(file_name, 
".lyx");
                                // Either change buffer or load the file
                                if (bufferlist.exists(s)) {
-                                       
view()->setBuffer(bufferlist.getBuffer(s));
+                                       
owner->setBuffer(bufferlist.getBuffer(s));
                                } else {
-                                       view()->loadLyXFile(s);
+                                       owner->loadLyXFile(s);
                                }
                        }
 
@@ -1300,9 +1300,9 @@
                        view()->savePosition(0);
                        string const parentfilename = 
owner->buffer()->fileName();
                        if (bufferlist.exists(filename))
-                               
view()->setBuffer(bufferlist.getBuffer(filename));
+                               
owner->setBuffer(bufferlist.getBuffer(filename));
                        else
-                               view()->loadLyXFile(filename);
+                               owner->loadLyXFile(filename);
                        // Set the parent name of the child document.
                        // This makes insertion of citations and references in 
the child work,
                        // when the target is in the parent or another child 
document.
@@ -1611,6 +1611,8 @@
                        else if (update)
                                view()->update(Update::FitCursor);
 
+                       owner->redrawWorkArea();
+
                        // if we executed a mutating lfun, mark the buffer as 
dirty
                        if (flag.enabled()
                            && !lyxaction.funcHasFlag(cmd.action, 
LyXAction::NoBuffer)
@@ -1737,7 +1739,7 @@
                templname = result.second;
        }
 
-       view()->newFile(filename, templname, !name.empty());
+       owner->setBuffer(newFile(filename, templname, !name.empty()));
 }
 
 
@@ -1791,15 +1793,15 @@
 
        // if the file doesn't exist, let the user create one
        if (!fs::exists(filename)) {
-               // the user specifically chose this name. Believe them.
-               view()->newFile(filename, "", true);
+               // the user specifically chose this name. Believe him.
+               owner->setBuffer(newFile(filename, "", true));
                return;
        }
 
        owner->message(bformat(_("Opening document %1$s..."), disp_fn));
 
        string str2;
-       if (view()->loadLyXFile(filename)) {
+       if (owner->loadLyXFile(filename)) {
                str2 = bformat(_("Document %1$s opened."), disp_fn);
        } else {
                str2 = bformat(_("Could not open document %1$s"), disp_fn);
@@ -1903,7 +1905,7 @@
                        // since there's no current buffer
                        owner->getDialogs().hideBufferDependent();
                } else {
-                       view()->setBuffer(bufferlist.first());
+                       owner->setBuffer(bufferlist.first());
                }
        }
 }

Reply via email to