correctly display messages issued by getStatus

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9303 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2004-11-25 09:15:26 +00:00
parent 10ba1b8918
commit f1efb4a928
5 changed files with 53 additions and 26 deletions

View File

@ -1,3 +1,17 @@
2004-11-24 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* 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 <Georg.Baum@post.rwth-aachen.de>
* lyxfunc.C (dispatch): always call sendDispatchMessage
2004-11-24 Alfredo Braunstein <abraunst@lyx.org> 2004-11-24 Alfredo Braunstein <abraunst@lyx.org>
* BufferView.C: * BufferView.C:
@ -36,7 +50,7 @@
2004-11-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2004-11-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxfind.C (findNextChange): update the bufferview after setting * lyxfind.C (findNextChange): update the bufferview after setting
the selection the selection.
2004-11-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2004-11-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>

View File

@ -12,6 +12,8 @@
#include "FuncStatus.h" #include "FuncStatus.h"
using std::string;
FuncStatus::FuncStatus() : v_(OK) FuncStatus::FuncStatus() : v_(OK)
{ {
} }
@ -20,12 +22,15 @@ FuncStatus::FuncStatus() : v_(OK)
void FuncStatus::clear() void FuncStatus::clear()
{ {
v_ = OK; v_ = OK;
message_.erase();
} }
void FuncStatus::operator|=(FuncStatus const & f) void FuncStatus::operator|=(FuncStatus const & f)
{ {
v_ |= f.v_; v_ |= f.v_;
if (!f.message_.empty())
message_ = f.message_;
} }
@ -73,3 +78,15 @@ bool FuncStatus::onoff(bool b) const
else else
return (v_ & OFF); return (v_ & OFF);
} }
void FuncStatus::message(string const & m)
{
message_ = m;
}
string const & FuncStatus::message() const
{
return message_;
}

View File

@ -12,6 +12,8 @@
#ifndef FUNC_STATUS_H #ifndef FUNC_STATUS_H
#define FUNC_STATUS_H #define FUNC_STATUS_H
#include <string>
/// The status of a function. /// The status of a function.
class FuncStatus class FuncStatus
@ -33,10 +35,12 @@ private:
unsigned int v_; unsigned int v_;
std::string message_;
public: public:
/// ///
FuncStatus(); FuncStatus();
// ///
void clear(); void clear();
/// ///
void operator|=(FuncStatus const & f); void operator|=(FuncStatus const & f);
@ -54,6 +58,11 @@ public:
void setOnOff(bool b); void setOnOff(bool b);
/// ///
bool onoff(bool b) const; bool onoff(bool b) const;
///
void message(std::string const & m);
///
std::string const & message() const;
}; };
#endif #endif

View File

@ -286,7 +286,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
buf = owner->buffer(); buf = owner->buffer();
if (cmd.action == LFUN_NOACTION) { if (cmd.action == LFUN_NOACTION) {
setStatusMessage(N_("Nothing to do")); flag.message(N_("Nothing to do"));
flag.enabled(false); flag.enabled(false);
return flag; return flag;
} }
@ -304,19 +304,19 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
} }
if (flag.unknown()) { if (flag.unknown()) {
setStatusMessage(N_("Unknown action")); flag.message(N_("Unknown action"));
return flag; return flag;
} }
// the default error message if we disable the command // the default error message if we disable the command
setStatusMessage(N_("Command disabled")); flag.message(N_("Command disabled"));
if (!flag.enabled()) if (!flag.enabled())
return flag; return flag;
// Check whether we need a buffer // Check whether we need a buffer
if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) { if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
// no, exit directly // no, exit directly
setStatusMessage(N_("Command not allowed with" flag.message(N_("Command not allowed with"
"out any document open")); "out any document open"));
flag.enabled(false); flag.enabled(false);
return flag; return flag;
@ -522,8 +522,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
default: default:
cur.getStatus(cmd, flag); if (!cur.getStatus(cmd, flag))
if (!flag.enabled())
flag = view()->getStatus(cmd); flag = view()->getStatus(cmd);
} }
@ -534,7 +533,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
if (buf && buf->isReadonly() if (buf && buf->isReadonly()
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly) && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) { && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
setStatusMessage(N_("Document is read-only")); flag.message(N_("Document is read-only"));
flag.enabled(false); flag.enabled(false);
} }
@ -615,14 +614,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
bool update = true; bool update = true;
// We cannot use this function here FuncStatus const flag = getStatus(cmd);
if (!getStatus(cmd).enabled()) { if (!flag.enabled()) {
// We cannot use this function here
lyxerr[Debug::ACTION] << "LyXFunc::dispatch: " lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
<< lyxaction.getActionName(action) << lyxaction.getActionName(action)
<< " [" << action << "] is disabled at this location" << " [" << action << "] is disabled at this location"
<< endl; << endl;
setErrorMessage(getStatusMessage()); setErrorMessage(flag.message());
} else { } else {
if (view()->available()) if (view()->available())
@ -1477,9 +1476,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
if (view()->cursor().inTexted()) { if (view()->cursor().inTexted()) {
view()->owner()->updateLayoutChoice(); 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() string const LyXFunc::viewStatusMessage()
{ {
// When meta-fake key is pressed, show the key sequence so far + "M-". // When meta-fake key is pressed, show the key sequence so far + "M-".

View File

@ -64,12 +64,8 @@ public:
void setMessage(std::string const & m) const; void setMessage(std::string const & m) const;
/// Buffer to store result messages /// Buffer to store result messages
void setErrorMessage(std::string const &) const; void setErrorMessage(std::string const &) const;
/// Buffer to store result messages from getStatus
void setStatusMessage(std::string const &) const;
/// Buffer to store result messages /// Buffer to store result messages
std::string const getMessage() const { return dispatch_buffer; } 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 /// Handle a accented char key sequence
void handleKeyFunc(kb_action action); void handleKeyFunc(kb_action action);
@ -98,8 +94,6 @@ private:
good reason to have this one as static in Dispatch? (Ale) good reason to have this one as static in Dispatch? (Ale)
*/ */
mutable std::string dispatch_buffer; 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 /// send a post-dispatch status message
void sendDispatchMessage(std::string const & msg, void sendDispatchMessage(std::string const & msg,