From f1efb4a92833fe816d08699d46261ed4804a3995 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 25 Nov 2004 09:15:26 +0000 Subject: [PATCH 1/1] correctly display messages issued by getStatus git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9303 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 16 +++++++++++++++- src/FuncStatus.C | 17 +++++++++++++++++ src/FuncStatus.h | 11 ++++++++++- src/lyxfunc.C | 29 +++++++++++------------------ src/lyxfunc.h | 6 ------ 5 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4995fc3697..6e03fbe666 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2004-11-24 Jean-Marc Lasgouttes + + * lyxfunc.C (getStatus, dispatch): use FuncStatus::message; only + call BufferView::getStatus if LCursor::getStatus did nothing + (setStatusMessage, getStatusMessage): removed. + + * FuncStatus.C (message): new methods. Used to provide an error + message indicating why a command is disabled. + (clear, |=, FuncStatus): update for message. + +2004-11-23 Georg Baum + + * lyxfunc.C (dispatch): always call sendDispatchMessage + 2004-11-24 Alfredo Braunstein * BufferView.C: @@ -36,7 +50,7 @@ 2004-11-22 Jean-Marc Lasgouttes * lyxfind.C (findNextChange): update the bufferview after setting - the selection + the selection. 2004-11-16 Jean-Marc Lasgouttes diff --git a/src/FuncStatus.C b/src/FuncStatus.C index 3e0c615096..2f0cf8e064 100644 --- a/src/FuncStatus.C +++ b/src/FuncStatus.C @@ -12,6 +12,8 @@ #include "FuncStatus.h" +using std::string; + FuncStatus::FuncStatus() : v_(OK) { } @@ -20,12 +22,15 @@ FuncStatus::FuncStatus() : v_(OK) void FuncStatus::clear() { v_ = OK; + message_.erase(); } void FuncStatus::operator|=(FuncStatus const & f) { v_ |= f.v_; + if (!f.message_.empty()) + message_ = f.message_; } @@ -73,3 +78,15 @@ bool FuncStatus::onoff(bool b) const else return (v_ & OFF); } + + +void FuncStatus::message(string const & m) +{ + message_ = m; +} + + +string const & FuncStatus::message() const +{ + return message_; +} diff --git a/src/FuncStatus.h b/src/FuncStatus.h index c9629112de..3f5d7b14c1 100644 --- a/src/FuncStatus.h +++ b/src/FuncStatus.h @@ -12,6 +12,8 @@ #ifndef FUNC_STATUS_H #define FUNC_STATUS_H +#include + /// The status of a function. class FuncStatus @@ -33,10 +35,12 @@ private: unsigned int v_; + std::string message_; + public: /// FuncStatus(); - // + /// void clear(); /// void operator|=(FuncStatus const & f); @@ -54,6 +58,11 @@ public: void setOnOff(bool b); /// bool onoff(bool b) const; + + /// + void message(std::string const & m); + /// + std::string const & message() const; }; #endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b5c3ad161b..fb7343aab1 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -286,7 +286,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const buf = owner->buffer(); if (cmd.action == LFUN_NOACTION) { - setStatusMessage(N_("Nothing to do")); + flag.message(N_("Nothing to do")); flag.enabled(false); return flag; } @@ -304,19 +304,19 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const } if (flag.unknown()) { - setStatusMessage(N_("Unknown action")); + flag.message(N_("Unknown action")); return flag; } // the default error message if we disable the command - setStatusMessage(N_("Command disabled")); + flag.message(N_("Command disabled")); if (!flag.enabled()) return flag; // Check whether we need a buffer if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) { // no, exit directly - setStatusMessage(N_("Command not allowed with" + flag.message(N_("Command not allowed with" "out any document open")); flag.enabled(false); return flag; @@ -522,8 +522,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const default: - cur.getStatus(cmd, flag); - if (!flag.enabled()) + if (!cur.getStatus(cmd, flag)) flag = view()->getStatus(cmd); } @@ -534,7 +533,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const if (buf && buf->isReadonly() && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly) && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) { - setStatusMessage(N_("Document is read-only")); + flag.message(N_("Document is read-only")); flag.enabled(false); } @@ -615,14 +614,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd) bool update = true; - // We cannot use this function here - if (!getStatus(cmd).enabled()) { + FuncStatus const flag = getStatus(cmd); + if (!flag.enabled()) { + // We cannot use this function here lyxerr[Debug::ACTION] << "LyXFunc::dispatch: " << lyxaction.getActionName(action) << " [" << action << "] is disabled at this location" << endl; - setErrorMessage(getStatusMessage()); - + setErrorMessage(flag.message()); } else { if (view()->available()) @@ -1477,9 +1476,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (view()->cursor().inTexted()) { view()->owner()->updateLayoutChoice(); - sendDispatchMessage(getMessage(), cmd); } } + sendDispatchMessage(getMessage(), cmd); } @@ -1779,12 +1778,6 @@ void LyXFunc::setMessage(string const & m) const } -void LyXFunc::setStatusMessage(string const & m) const -{ - status_buffer = m; -} - - string const LyXFunc::viewStatusMessage() { // When meta-fake key is pressed, show the key sequence so far + "M-". diff --git a/src/lyxfunc.h b/src/lyxfunc.h index 5b9a57bd7b..0bc95eb9ac 100644 --- a/src/lyxfunc.h +++ b/src/lyxfunc.h @@ -64,12 +64,8 @@ public: void setMessage(std::string const & m) const; /// Buffer to store result messages void setErrorMessage(std::string const &) const; - /// Buffer to store result messages from getStatus - void setStatusMessage(std::string const &) const; /// Buffer to store result messages std::string const getMessage() const { return dispatch_buffer; } - /// Buffer to store result messages - std::string const getStatusMessage() const { return status_buffer; } /// Handle a accented char key sequence void handleKeyFunc(kb_action action); @@ -98,8 +94,6 @@ private: good reason to have this one as static in Dispatch? (Ale) */ mutable std::string dispatch_buffer; - /// Buffer to store messages and result data from getStatus - mutable std::string status_buffer; /// send a post-dispatch status message void sendDispatchMessage(std::string const & msg, -- 2.39.5