From 5520817bd37ee2e17ea2cc64dec2a50cc0386144 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Sun, 17 Oct 2010 10:44:53 +0000 Subject: [PATCH] Use DispatchResult also in GuiView::dispatchVC to handle messages. 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 | 38 ++++++++++++++++++++++------ src/frontends/qt4/GuiApplication.cpp | 8 +++--- src/frontends/qt4/GuiView.cpp | 30 ++++++++++------------ src/frontends/qt4/GuiView.h | 4 +-- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/DispatchResult.h b/src/DispatchResult.h index bc5bb59c8e..687e55c8fd 100644 --- a/src/DispatchResult.h +++ b/src/DispatchResult.h @@ -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. @@ -19,15 +19,26 @@ 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_; }; diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 10cbe38b3c..cf6d4d7c82 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -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)); + } } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 704c94a648..cac6a54ef4 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -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: diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index f1612b99d7..deb1e24a72 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -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(); -- 2.39.2