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
This commit is contained in:
Peter Kümmel 2010-10-17 10:44:53 +00:00
parent ee2eabd416
commit 5520817bd3
4 changed files with 51 additions and 29 deletions

View 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.
@ -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_;
};

View File

@ -1116,9 +1116,11 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
// update gui
current_view_->restartCursor();
}
if (dr.needMessageUpdate()) {
// Some messages may already be translated, so we cannot use _()
current_view_->message(makeDispatchMessage(
translateIfPossible(dr.message()), cmd));
}
}

View 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:

View 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();