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>
* BufferView.C:
@ -36,7 +50,7 @@
2004-11-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxfind.C (findNextChange): update the bufferview after setting
the selection
the selection.
2004-11-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>

View File

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

View File

@ -12,6 +12,8 @@
#ifndef FUNC_STATUS_H
#define FUNC_STATUS_H
#include <string>
/// 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

View File

@ -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-".

View File

@ -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,