]> git.lyx.org Git - features.git/commitdiff
Use DispatchResult also in GuiView::dispatchVC to handle messages.
authorPeter Kümmel <syntheticpp@gmx.net>
Sun, 17 Oct 2010 10:44:53 +0000 (10:44 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Sun, 17 Oct 2010 10:44:53 +0000 (10:44 +0000)
Make it possible to suppress messages stored in DispatchResult objects.
BUG: 6417

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35662 a592a061-630c-0410-9148-cb99ea01b6c8

src/DispatchResult.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h

index bc5bb59c8e95b59d8fe7fdb7565d30099bf934d9..687e55c8fded3a02ec562a846b97e66d73269dc3 100644 (file)
@@ -4,7 +4,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author none
+ * \author Peter Kümmel
  * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
 
 namespace lyx {
 
-/// Maybe this can go entirely
-class DispatchResult {
+
+class DispatchResult
+{
 public:
        ///
-       DispatchResult() : dispatched_(false), error_(false), 
-                          update_(Update::None), need_buf_update_(false) {}
+       DispatchResult() :
+                       dispatched_(false),
+                       error_(false),
+                       update_(Update::None),
+                       need_buf_update_(false),
+                       need_msg_update_(true)
+       {}
        ///
-       DispatchResult(bool disp, Update::flags f) 
-               : dispatched_(disp), error_(false), update_(f) {}
+       DispatchResult(bool dispatched, Update::flags f) :
+                       dispatched_(dispatched),
+                       error_(false),
+                       update_(f),
+                       need_buf_update_(false),
+                       need_msg_update_(true)
+       {}
        ///
        bool dispatched() const { return dispatched_; }
        ///
@@ -39,7 +50,9 @@ public:
        ///
        docstring message() { return message_; }
        ///
-       void setMessage(docstring m) { message_ = m; }
+       void setMessage(docstring const & m) { message_ = m; }
+       ///
+       void setMessage(std::string const & m) { message_ = from_utf8(m); }
        ///
        Update::flags screenUpdate() const { return update_; }
        ///
@@ -50,6 +63,13 @@ public:
        void forceBufferUpdate() { need_buf_update_ = true; }
        /// Clear the flag indicating we need an update
        void clearBufferUpdate() { need_buf_update_ = false; }
+       ///
+       bool needMessageUpdate() const { return need_msg_update_; }
+       /// Force the buffer to be updated
+       void forceMessageUpdate() { need_msg_update_ = true; }
+       /// Clear the flag indicating we need an update
+       void suppressMessageUpdate() { need_msg_update_ = false; }
+
 private:
        /// was the event fully dispatched?
        bool dispatched_;
@@ -61,6 +81,8 @@ private:
        docstring message_;
        /// 
        bool need_buf_update_;
+       ///
+       bool need_msg_update_;
 };
 
 
index 10cbe38b3c9ccaabd46cbda6b3aca4a3e913741f..cf6d4d7c8253ace56185955fea75f941bc68cd8e 100644 (file)
@@ -1116,9 +1116,11 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
                // update gui
                current_view_->restartCursor();
        }
-       // Some messages may already be translated, so we cannot use _()
-       current_view_->message(makeDispatchMessage(
-                       translateIfPossible(dr.message()), cmd));
+       if (dr.needMessageUpdate()) {
+               // Some messages may already be translated, so we cannot use _()
+               current_view_->message(makeDispatchMessage(
+                               translateIfPossible(dr.message()), cmd));
+       }
 }
 
 
index 704c94a648b8f1a6e850ff91738e4984efebe5f0..cac6a54ef42bd1b7d9265318d03b8dd815cfa1b3 100644 (file)
@@ -2522,10 +2522,10 @@ static bool ensureBufferClean(Buffer * buffer)
 }
 
 
-void GuiView::reloadBuffer()
+bool GuiView::reloadBuffer()
 {
        Buffer * buf = &documentBufferView()->buffer();
-       buf->reload();
+       return buf->reload();
 }
 
 
@@ -2548,11 +2548,8 @@ void GuiView::checkExternallyModifiedBuffers()
 }
 
 
-//FIXME use a DispatchResult object to transmit messages
-void GuiView::dispatchVC(FuncRequest const & cmd)
+void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
 {
-       // message for statusbar
-       string msg;
        Buffer * buffer = documentBufferView()
                ? &(documentBufferView()->buffer()) : 0;
 
@@ -2561,8 +2558,10 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                if (!buffer || !ensureBufferClean(buffer))
                        break;
                if (!buffer->lyxvc().inUse()) {
-                       if (buffer->lyxvc().registrer())
+                       if (buffer->lyxvc().registrer()) {
                                reloadBuffer();
+                               dr.suppressMessageUpdate();
+                       }
                }
                break;
 
@@ -2570,8 +2569,8 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                if (!buffer || !ensureBufferClean(buffer))
                        break;
                if (buffer->lyxvc().inUse() && !buffer->isReadonly()) {
-                       msg = buffer->lyxvc().checkIn();
-                       if (!msg.empty())
+                       dr.setMessage(buffer->lyxvc().checkIn());
+                       if (!dr.message().empty())
                                reloadBuffer();
                }
                break;
@@ -2580,7 +2579,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                if (!buffer || !ensureBufferClean(buffer))
                        break;
                if (buffer->lyxvc().inUse()) {
-                       msg = buffer->lyxvc().checkOut();
+                       dr.setMessage(buffer->lyxvc().checkOut());
                        reloadBuffer();
                }
                break;
@@ -2595,7 +2594,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                                frontend::Alert::error(_("Revision control error."),
                                _("Error when setting the locking property."));
                        } else {
-                               msg = res;
+                               dr.setMessage(res);
                                reloadBuffer();
                        }
                }
@@ -2605,18 +2604,20 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                LASSERT(buffer, return);
                buffer->lyxvc().revert();
                reloadBuffer();
+               dr.suppressMessageUpdate();
                break;
 
        case LFUN_VC_UNDO_LAST:
                LASSERT(buffer, return);
                buffer->lyxvc().undoLast();
                reloadBuffer();
+               dr.suppressMessageUpdate();
                break;
 
        case LFUN_VC_REPO_UPDATE:
                LASSERT(buffer, return);
                if (ensureBufferClean(buffer)) {
-                       msg = buffer->lyxvc().repoUpdate();
+                       dr.setMessage(buffer->lyxvc().repoUpdate());
                        checkExternallyModifiedBuffers();
                }
                break;
@@ -2698,9 +2699,6 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
        default:
                break;
        }
-
-       if (!msg.empty())
-               message(from_utf8(msg));
 }
 
 
@@ -3268,7 +3266,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_VC_UNDO_LAST:
                case LFUN_VC_COMMAND:
                case LFUN_VC_COMPARE:
-                       dispatchVC(cmd);
+                       dispatchVC(cmd, dr);
                        break;
 
                case LFUN_SERVER_GOTO_FILE_ROW:
index f1612b99d7e4390c072846bd101801ec26e306f4..deb1e24a72ae4335b5bd85e9b6a0cd20ce59ecf7 100644 (file)
@@ -398,9 +398,9 @@ private:
        ///
        Dialog * build(std::string const & name);
        ///
-       void reloadBuffer();
+       bool reloadBuffer();
        ///
-       void dispatchVC(FuncRequest const & cmd);
+       void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
        ///
        void showMessage();