mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Get rid of the errorstat and dispatch_buffer members of LyXFunc.
This required to make Cursor::disp_ mutable. Also, the server parts now pass a DispatchResult object to dispatch (which is a good thing anyway). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33259 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
00338d3747
commit
a1e991a82e
@ -27,7 +27,7 @@
|
||||
#include "FuncRequest.h"
|
||||
#include "Language.h"
|
||||
#include "LyXAction.h"
|
||||
#include "LyXFunc.h" // only for setMessage()
|
||||
#include "LyXFunc.h"
|
||||
#include "LyXRC.h"
|
||||
#include "Paragraph.h"
|
||||
#include "ParIterator.h"
|
||||
@ -1983,13 +1983,14 @@ void Cursor::handleFont(string const & font)
|
||||
|
||||
void Cursor::message(docstring const & msg) const
|
||||
{
|
||||
theLyXFunc().setMessage(msg);
|
||||
disp_.setMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
void Cursor::errorMessage(docstring const & msg) const
|
||||
{
|
||||
theLyXFunc().setErrorMessage(msg);
|
||||
disp_.setMessage(msg);
|
||||
disp_.setError(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -292,7 +292,7 @@ public:
|
||||
DocIterator anchor_;
|
||||
|
||||
///
|
||||
DispatchResult disp_;
|
||||
mutable DispatchResult disp_;
|
||||
///
|
||||
DocIterator const & beforeDispatchCursor() { return beforeDispatchCursor_; }
|
||||
|
||||
|
@ -295,8 +295,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
return flag;
|
||||
}
|
||||
|
||||
/// send a post-dispatch status message
|
||||
static docstring sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
|
||||
/// make a post-dispatch status message
|
||||
static docstring makeDispatchMessage(docstring const & msg,
|
||||
FuncRequest const & cmd)
|
||||
{
|
||||
const bool verbose = (cmd.origin == FuncRequest::MENU
|
||||
|| cmd.origin == FuncRequest::TOOLBAR
|
||||
@ -370,11 +371,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
FuncCode const action = cmd.action;
|
||||
|
||||
LYXERR(Debug::ACTION, "\nLyXFunc::dispatch: cmd: " << cmd);
|
||||
//lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
|
||||
|
||||
// we have not done anything wrong yet.
|
||||
errorstat = false;
|
||||
dispatch_buffer.erase();
|
||||
dr.setError(false);
|
||||
|
||||
LyXView * lv = theApp()->currentWindow();
|
||||
|
||||
@ -384,10 +383,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
LYXERR(Debug::ACTION, "LyXFunc::dispatch: "
|
||||
<< lyxaction.getActionName(action)
|
||||
<< " [" << action << "] is disabled at this location");
|
||||
//FIXME: pass this using the DispatchResult object
|
||||
setErrorMessage(flag.message());
|
||||
if (lv)
|
||||
lv->restartCursor();
|
||||
dr.setMessage(flag.message());
|
||||
dr.setError(true);
|
||||
dr.dispatched(false);
|
||||
dr.update(Update::None);
|
||||
} else {
|
||||
@ -496,10 +495,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
}
|
||||
|
||||
if (defaults.writeFile(FileName(defaults.absFileName())))
|
||||
setMessage(bformat(_("Document defaults saved in %1$s"),
|
||||
dr.setMessage(bformat(_("Document defaults saved in %1$s"),
|
||||
makeDisplayPath(fname)));
|
||||
else
|
||||
setErrorMessage(from_ascii(N_("Unable to save document defaults")));
|
||||
else {
|
||||
dr.setError(true);
|
||||
dr.setMessage(from_ascii(N_("Unable to save document defaults")));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -601,29 +602,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
}
|
||||
if (lv) {
|
||||
// Some messages may already be translated, so we cannot use _()
|
||||
lv->message(sendDispatchMessage(
|
||||
translateIfPossible(getMessage()), cmd));
|
||||
lv->message(makeDispatchMessage(translateIfPossible(dr.message()), cmd));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Each LyXView should have it's own message method. lyxview and
|
||||
// the minibuffer would use the minibuffer, but lyxserver would
|
||||
// send an ERROR signal to its client. Alejandro 970603
|
||||
// This function is bit problematic when it comes to NLS, to make the
|
||||
// lyx servers client be language indepenent we must not translate
|
||||
// strings sent to this func.
|
||||
void LyXFunc::setErrorMessage(docstring const & m) const
|
||||
{
|
||||
dispatch_buffer = m;
|
||||
errorstat = true;
|
||||
}
|
||||
|
||||
|
||||
void LyXFunc::setMessage(docstring const & m) const
|
||||
{
|
||||
dispatch_buffer = m;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -57,14 +57,6 @@ public:
|
||||
///
|
||||
FuncStatus getStatus(FuncRequest const & action) const;
|
||||
|
||||
/// True if lyxfunc reports an error
|
||||
bool errorStat() const { return errorstat; }
|
||||
/// Buffer to store result messages
|
||||
void setMessage(docstring const & m) const;
|
||||
/// Buffer to store result messages
|
||||
void setErrorMessage(docstring const &) const;
|
||||
/// Buffer to store result messages
|
||||
docstring const getMessage() const { return dispatch_buffer; }
|
||||
/// goto a bookmark
|
||||
/// openFile: whether or not open a file if the file is not opened
|
||||
/// switchToBuffer: whether or not switch to buffer if the buffer is
|
||||
@ -80,14 +72,6 @@ private:
|
||||
/// cursor position before dispatch started
|
||||
int cursorPosBeforeDispatchX_;
|
||||
int cursorPosBeforeDispatchY_;
|
||||
|
||||
/// Error status, only Dispatch can change this flag
|
||||
mutable bool errorstat;
|
||||
|
||||
/** Buffer to store messages and result data. Is there a
|
||||
good reason to have this one as static in Dispatch? (Ale)
|
||||
*/
|
||||
mutable docstring dispatch_buffer;
|
||||
};
|
||||
|
||||
/// Implementation is in LyX.cpp
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "Server.h"
|
||||
|
||||
#include "DispatchResult.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "LyXAction.h"
|
||||
#include "LyXFunc.h"
|
||||
@ -1111,14 +1113,16 @@ void Server::callback(string const & msg)
|
||||
// connect to the lyxfunc in the single LyXView we
|
||||
// support currently. (Lgb)
|
||||
|
||||
func_->dispatch(FuncRequest(lyxaction.lookupFunc(cmd), arg));
|
||||
string const rval = to_utf8(func_->getMessage());
|
||||
FuncRequest const fr(lyxaction.lookupFunc(cmd), arg);
|
||||
DispatchResult dr;
|
||||
func_->dispatch(fr, dr);
|
||||
string const rval = to_utf8(dr.message());
|
||||
|
||||
// all commands produce an INFO or ERROR message
|
||||
// in the output pipe, even if they do not return
|
||||
// anything. See chapter 4 of Customization doc.
|
||||
string buf;
|
||||
if (func_->errorStat())
|
||||
if (dr.error())
|
||||
buf = "ERROR:";
|
||||
else
|
||||
buf = "INFO:";
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "ServerSocket.h"
|
||||
|
||||
#include "DispatchResult.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "LyXAction.h"
|
||||
#include "LyXFunc.h"
|
||||
@ -141,13 +142,13 @@ void ServerSocket::dataCallback(int fd)
|
||||
string const key = line.substr(0, pos);
|
||||
if (key == "LYXCMD") {
|
||||
string const cmd = line.substr(pos + 1);
|
||||
func->dispatch(lyxaction.lookupFunc(cmd));
|
||||
string const rval = to_utf8(func->getMessage());
|
||||
if (func->errorStat()) {
|
||||
DispatchResult dr;
|
||||
func->dispatch(lyxaction.lookupFunc(cmd), dr);
|
||||
string const rval = to_utf8(dr.message());
|
||||
if (dr.error())
|
||||
client->writeln("ERROR:" + cmd + ':' + rval);
|
||||
} else {
|
||||
else
|
||||
client->writeln("INFO:" + cmd + ':' + rval);
|
||||
}
|
||||
} else if (key == "HELLO") {
|
||||
// no use for client name!
|
||||
client->writeln("HELLO:");
|
||||
|
Loading…
Reference in New Issue
Block a user