From 46992201b71c3b20e9cdf640ce1b8d36ecaf48ac Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 9 Dec 2022 14:43:19 +0100 Subject: [PATCH] Add != operator to FuncRequest and special value FuncRequest::prefix Use this value (and `unknown' where relevant) --- src/FuncRequest.cpp | 8 ++++++++ src/FuncRequest.h | 5 +++++ src/KeyMap.cpp | 3 +-- src/frontends/qt/GuiPrefs.cpp | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/FuncRequest.cpp b/src/FuncRequest.cpp index 25ea41a82f..1597027311 100644 --- a/src/FuncRequest.cpp +++ b/src/FuncRequest.cpp @@ -28,6 +28,7 @@ namespace lyx { FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION); FuncRequest const FuncRequest::noaction(LFUN_NOACTION); +FuncRequest const FuncRequest::prefix(LFUN_COMMAND_PREFIX); FuncRequest::FuncRequest(Origin o) : origin_(o) @@ -114,12 +115,19 @@ string FuncRequest::getLongArg(unsigned int i) const return i < args.size() ? args[i] : string(); } + bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) { 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) { return os diff --git a/src/FuncRequest.h b/src/FuncRequest.h index 52fb1434aa..efbe425f57 100644 --- a/src/FuncRequest.h +++ b/src/FuncRequest.h @@ -98,6 +98,9 @@ public: static FuncRequest const unknown; /// static FuncRequest const noaction; + /// + static FuncRequest const prefix; + /// 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); + std::ostream & operator<<(std::ostream &, FuncRequest const &); LyXErr & operator<<(LyXErr &, FuncRequest const &); diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp index 1fb82c2f19..c530f5f1f2 100644 --- a/src/KeyMap.cpp +++ b/src/KeyMap.cpp @@ -457,8 +457,7 @@ FuncRequest const & KeyMap::lookup(KeySymbol const &key, if (cit->prefixes) { // this is a prefix key - set new map seq->curmap = cit->prefixes.get(); - static const FuncRequest prefix(LFUN_COMMAND_PREFIX); - return prefix; + return FuncRequest::prefix; } else { // final key - reset map seq->reset(); diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp index c72baee337..46baffdcfe 100644 --- a/src/frontends/qt/GuiPrefs.cpp +++ b/src/frontends/qt/GuiPrefs.cpp @@ -3359,9 +3359,10 @@ docstring makeCmdString(FuncRequest const & f) FuncRequest PrefShortcuts::currentBinding(KeySequence const & k) { FuncRequest res = user_bind_.getBinding(k); - if (res.action() != LFUN_UNKNOWN_ACTION) + if (res != FuncRequest::unknown) return res; res = system_bind_.getBinding(k); + // Check if it is unbound. Note: user_unbind_ can only unbind one // FuncRequest per key sequence. if (user_unbind_.getBinding(k) == res)