Add != operator to FuncRequest and special value FuncRequest::prefix

Use this value (and `unknown' where relevant)
This commit is contained in:
Jean-Marc Lasgouttes 2022-12-09 14:43:19 +01:00
parent fff02aca1a
commit 46992201b7
4 changed files with 16 additions and 3 deletions

View File

@ -28,6 +28,7 @@ namespace lyx {
FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION); FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
FuncRequest const FuncRequest::noaction(LFUN_NOACTION); FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
FuncRequest const FuncRequest::prefix(LFUN_COMMAND_PREFIX);
FuncRequest::FuncRequest(Origin o) FuncRequest::FuncRequest(Origin o)
: origin_(o) : origin_(o)
@ -114,12 +115,19 @@ string FuncRequest::getLongArg(unsigned int i) const
return i < args.size() ? args[i] : string(); return i < args.size() ? args[i] : string();
} }
bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
{ {
return lhs.action() == rhs.action() && lhs.argument() == rhs.argument(); return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
} }
bool operator!=(FuncRequest const & lhs, FuncRequest const & rhs)
{
return !(lhs == rhs);
}
ostream & operator<<(ostream & os, FuncRequest const & cmd) ostream & operator<<(ostream & os, FuncRequest const & cmd)
{ {
return os return os

View File

@ -98,6 +98,9 @@ public:
static FuncRequest const unknown; static FuncRequest const unknown;
/// ///
static FuncRequest const noaction; static FuncRequest const noaction;
///
static FuncRequest const prefix;
/// ///
bool allowAsync() const { return allow_async_; } bool allowAsync() const { return allow_async_; }
/// ///
@ -129,6 +132,8 @@ private:
bool operator==(FuncRequest const & lhs, FuncRequest const & rhs); bool operator==(FuncRequest const & lhs, FuncRequest const & rhs);
bool operator!=(FuncRequest const & lhs, FuncRequest const & rhs);
std::ostream & operator<<(std::ostream &, FuncRequest const &); std::ostream & operator<<(std::ostream &, FuncRequest const &);
LyXErr & operator<<(LyXErr &, FuncRequest const &); LyXErr & operator<<(LyXErr &, FuncRequest const &);

View File

@ -457,8 +457,7 @@ FuncRequest const & KeyMap::lookup(KeySymbol const &key,
if (cit->prefixes) { if (cit->prefixes) {
// this is a prefix key - set new map // this is a prefix key - set new map
seq->curmap = cit->prefixes.get(); seq->curmap = cit->prefixes.get();
static const FuncRequest prefix(LFUN_COMMAND_PREFIX); return FuncRequest::prefix;
return prefix;
} else { } else {
// final key - reset map // final key - reset map
seq->reset(); seq->reset();

View File

@ -3359,9 +3359,10 @@ docstring makeCmdString(FuncRequest const & f)
FuncRequest PrefShortcuts::currentBinding(KeySequence const & k) FuncRequest PrefShortcuts::currentBinding(KeySequence const & k)
{ {
FuncRequest res = user_bind_.getBinding(k); FuncRequest res = user_bind_.getBinding(k);
if (res.action() != LFUN_UNKNOWN_ACTION) if (res != FuncRequest::unknown)
return res; return res;
res = system_bind_.getBinding(k); res = system_bind_.getBinding(k);
// Check if it is unbound. Note: user_unbind_ can only unbind one // Check if it is unbound. Note: user_unbind_ can only unbind one
// FuncRequest per key sequence. // FuncRequest per key sequence.
if (user_unbind_.getBinding(k) == res) if (user_unbind_.getBinding(k) == res)