Abdelrazak Younes wrote:
Angus Leeming wrote:
Abdelrazak Younes wrote:
Hello,

The subject says it all. This patch is obviously the right thing to do so I will commit soon.

Is it really the right thing to do? Imagine that you have multiple bufferviews on a buffer. If you perform some action from one bufferview, do you really want the message to be displayed in all of them? (If we had multiple windows then the message would be displayed in the minibuffer at the bottom of each window.)

Hum, you have a point but I still think that this is the right thing to do. If the Buffer is changed then it should say so regardless to wo is listening (or watching). _But_ an additional filtering should be done somewhere that will let the connected LyXView to decide whether to display this message on screen. I guess autosave related messages or reconfigure messages should be shown on all LyXView but inset insertion in a non currently visible part of the Buffer should not be displayed for example.

I think that the code is right as it is.

If need be we can create a BufferView::message() signal in the future that will allow to differentiate between different kind of messages. But this kind of feature should really be asynchronous so emitting a signal is the right thing to do.

That patch is doing so. Only the Buffer::message() signal emissions from within "BufferView_pimpl.C" and "lyxfind.C" are replaced with BufferView::message() signal emission.

The following messages are really Buffer dependant and not BufferView dependant and should stay so IMHO:

lyx_cb.C(289): bv_.buffer()->message(_("Autosave failed!"));
lyx_cb.C(316): bv->buffer()->message(_("Autosaving current document..."));
lyx_cb.C(442): bv->buffer()->message(_("Running configure..."));
lyx_cb.C(451): bv->buffer()->message(_("Reloading configuration..."));
lyxfind.C(292): bv->buffer()->message(_("String not found!"));

I think most of the Cursor::message() calls could be replaced with this BufferView::message() signal emission.

Comments, opinion?

Abdel.

PS: sorry Georg, I have not found yet how to put the function names in the patch.

Log:
* BufferView.h: new message boost signal.

* BufferView_pimpl.C: replace Buffer::message() with BufferView::message() signal emission.

* lyxfind.C: ditto.

* WorkArea:
  - displayMessage(): new private method that calls LyXView::message().
  - messageConnection_: new signal connection.
  - setBufferView(): handle BufferView connection/disconnection.

Index: BufferView.h
===================================================================
--- BufferView.h        (revision 14826)
+++ BufferView.h        (working copy)
@@ -22,6 +22,7 @@
 #include "support/types.h"
 
 #include <boost/utility.hpp>
+#include <boost/signal.hpp>
 
 #include <string>
 
@@ -218,6 +219,9 @@
        ///
        void updateMetrics(bool singlepar = false);
 
+       /// This signal is emitted when some message shows up.
+       boost::signal<void(std::string)> message;
+
 private:
        ///
        class Pimpl;
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 14827)
+++ BufferView_pimpl.C  (working copy)
@@ -631,7 +631,7 @@
                                      cursor_.pos());
        if (i > 0)
                // emit message signal.
-               buffer_->message(bformat(_("Saved bookmark %1$d"), i));
+               bv_->message(bformat(_("Saved bookmark %1$d"), i));
 }
 
 
@@ -665,7 +665,7 @@
 
        if (i > 0)
                // emit message signal.
-               buffer_->message(bformat(_("Moved to bookmark %1$d"), i));
+               bv_->message(bformat(_("Moved to bookmark %1$d"), i));
 }
 
 
@@ -755,7 +755,7 @@
                // check selected filename
                if (filename.empty()) {
                        // emit message signal.
-                       buffer_->message(_("Canceled."));
+                       bv_->message(_("Canceled."));
                        return;
                }
        }
@@ -766,7 +766,7 @@
 
        string const disp_fn = makeDisplayPath(filename);
        // emit message signal.
-       buffer_->message(bformat(_("Inserting document %1$s..."), disp_fn));
+       bv_->message(bformat(_("Inserting document %1$s..."), disp_fn));
 
        string res;
        Buffer buf("", false);
@@ -781,7 +781,7 @@
                res = _("Could not insert document %1$s");
 
        // emit message signal.
-       buffer_->message(bformat(res, disp_fn));
+       bv_->message(bformat(res, disp_fn));
        buffer_->errors("Parse");
        resizeCurrentBuffer();
 }
Index: frontends/WorkArea.C
===================================================================
--- frontends/WorkArea.C        (revision 14826)
+++ frontends/WorkArea.C        (working copy)
@@ -49,7 +49,6 @@
 #include <boost/utility.hpp>
 #include <boost/bind.hpp>
 #include <boost/current_function.hpp>
-#include <boost/signals/trackable.hpp>
 
 using lyx::support::libFileSearch;
 using lyx::support::ForkedcallsController;
@@ -160,9 +159,15 @@
 
 void WorkArea::setBufferView(BufferView * buffer_view)
 {
+       if (buffer_view_)
+               messageConnection_.disconnect();
+
        hideCursor();
        buffer_view_ = buffer_view;
        toggleCursor();
+
+       messageConnection_ = buffer_view_->message.connect(
+                       boost::bind(&WorkArea::displayMessage, this, _1));
 }
 
 
@@ -406,5 +411,11 @@
        cursor_timeout_.restart();
 }
 
+
+void WorkArea::displayMessage(std::string const & message)
+{
+       lyx_view_.message(message);
+}
+
 } // namespace frontend
 } // namespace lyx
Index: frontends/WorkArea.h
===================================================================
--- frontends/WorkArea.h        (revision 14826)
+++ frontends/WorkArea.h        (working copy)
@@ -34,6 +34,7 @@
 #include "frontends/LyXKeySym.h"
 #include "frontends/Timeout.h"
 
+#include <boost/signals/trackable.hpp>
 
 class BufferView;
 class FuncRequest;
@@ -61,7 +62,7 @@
  * It works in concert with the BaseScreen class to update the
  * widget view of a document.
  */
-class WorkArea {
+class WorkArea : public boost::signals::trackable {
 public:
        WorkArea(LyXView & lyx_view);
 
@@ -143,6 +144,10 @@
        void updateScrollbar();
        ///
        void checkAndGreyOut();
+       ///
+       void displayMessage(std::string const &);
+       /// buffer messages signal connection
+       boost::signals::connection messageConnection_;
 
        ///
        bool greyed_out_;
Index: lyxfind.C
===================================================================
--- lyxfind.C   (revision 14827)
+++ lyxfind.C   (working copy)
@@ -289,7 +289,7 @@
 
        if (!found)
                // emit message signal.
-               bv->buffer()->message(_("String not found!"));
+               bv->message(_("String not found!"));
 }
 
 

Reply via email to