Skip to content

Commit aee9f67

Browse files
authored
Merge pull request #148 from igorkorsukov/w/rcmd/rcmd_step0
returned shortcut module v1
2 parents 7d6e9ca + 96c4aaa commit aee9f67

56 files changed

Lines changed: 4018 additions & 283 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

framework/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ if (MUSE_MODULE_RCONTROL)
110110
endif()
111111

112112
if (MUSE_MODULE_SHORTCUTS)
113-
add_subdirectory(shortcuts)
113+
if (MUSE_MODULE_SHORTCUTS_V2)
114+
add_subdirectory(shortcuts_v2)
115+
else()
116+
add_subdirectory(shortcuts)
117+
endif()
114118
endif()
115119

116120
if (MUSE_MODULE_TOURS)

framework/cmake/MuseDeclareOptions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ declare_muse_module_opt(RCOMMAND ON)
8484
declare_muse_module_opt(RCONTROL ON)
8585

8686
declare_muse_module_opt(SHORTCUTS ON)
87+
option(MUSE_MODULE_SHORTCUTS_V2 "Use shortcuts v2" OFF)
88+
8789
declare_muse_module_opt(TESTFLOW ON)
8890
declare_muse_module_opt(TOURS ON)
8991

framework/cmake/muse_framework_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
#cmakedefine MUSE_MODULE_SHORTCUTS 1
140140
#cmakedefine MUSE_MODULE_SHORTCUTS_TESTS 1
141141
#cmakedefine MUSE_MODULE_SHORTCUTS_API 1
142+
#cmakedefine MUSE_MODULE_SHORTCUTS_V2 1
142143

143144
#cmakedefine MUSE_MODULE_TOURS 1
144145
#cmakedefine MUSE_MODULE_TOURS_TESTS 1

framework/shortcuts/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@ target_sources(muse_shortcuts PRIVATE
2828
shortcutstypes.h
2929
shortcutcontext.h
3030
ishortcutsregister.h
31-
icommandshortcutsregister.h
3231
ishortcutscontroller.h
3332
ishortcutsconfiguration.h
34-
ishortcutsresolver.h
3533

3634
api/shortcutsapi.cpp
3735
api/shortcutsapi.h
3836

3937
internal/shortcutsregister.cpp
4038
internal/shortcutsregister.h
41-
internal/commandshortcutsregister.cpp
42-
internal/commandshortcutsregister.h
4339
internal/shortcutscontroller.cpp
4440
internal/shortcutscontroller.h
4541
internal/shortcutsconfiguration.cpp

framework/shortcuts/internal/shortcutsconfiguration.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,7 @@ io::path_t ShortcutsConfiguration::shortcutsAppDataPath() const
5858
{
5959
#if defined(Q_OS_MACOS)
6060
return m_config.value("shortcuts_mac").toPath();
61-
#else
62-
return m_config.value("shortcuts").toPath();
6361
#endif
64-
}
65-
66-
io::path_t ShortcutsConfiguration::commandShortcutsUserAppDataPath() const
67-
{
68-
return globalConfiguration()->userAppDataPath() + "/shortcuts.json";
69-
}
7062

71-
io::path_t ShortcutsConfiguration::commandShortcutsAppDataPath() const
72-
{
73-
#if defined(Q_OS_MACOS)
74-
return m_config.value("command_shortcuts_mac").toPath();
75-
#else
76-
return m_config.value("command_shortcuts").toPath();
77-
#endif
63+
return m_config.value("shortcuts").toPath();
7864
}

framework/shortcuts/internal/shortcutsconfiguration.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class ShortcutsConfiguration : public IShortcutsConfiguration, public Contextabl
4747
io::path_t shortcutsUserAppDataPath() const override;
4848
io::path_t shortcutsAppDataPath() const override;
4949

50-
io::path_t commandShortcutsUserAppDataPath() const override;
51-
io::path_t commandShortcutsAppDataPath() const override;
52-
5350
private:
5451
Config m_config;
5552
};

framework/shortcuts/internal/shortcutscontroller.cpp

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,10 @@
2121
*/
2222
#include "shortcutscontroller.h"
2323

24-
#include "actions/actiontypes.h"
2524
#include "log.h"
2625

27-
#define SHORTCUTS_DEBUG 1
28-
29-
#if SHORTCUTS_DEBUG
30-
#define SC_LOG() LOGDA() << "[SC] "
31-
#else
32-
#define SC_LOG() LOGN()
33-
#endif
34-
3526
using namespace muse::shortcuts;
3627
using namespace muse::actions;
37-
using namespace muse::rcommand;
38-
using namespace muse::ui;
3928

4029
void ShortcutsController::init()
4130
{
@@ -49,42 +38,10 @@ void ShortcutsController::activate(const std::string& sequence)
4938
{
5039
LOGD() << sequence;
5140

52-
//! NOTE: command shortcuts first
53-
bool commandShortcutsProcessed = false;
54-
{
55-
ShortcutList allowedShortcuts;
56-
const ShortcutList& commandShortcuts = commandShortcutsRegister()->shortcutsForSequence(sequence);
57-
SC_LOG() << "commandShortcuts: " << commandShortcuts.size();
58-
for (const Shortcut& sc : commandShortcuts) {
59-
const Command& command = Command(sc.command);
60-
if (commandsState()->commandState(command).enabled) {
61-
allowedShortcuts.push_back(sc);
62-
}
63-
}
64-
SC_LOG() << "allowedShortcuts: " << allowedShortcuts.size();
65-
66-
Shortcut selectedShortcut;
67-
if (allowedShortcuts.size() == 1) {
68-
selectedShortcut = allowedShortcuts.front();
69-
} else if (allowedShortcuts.size() > 1) {
70-
if (shortcutsResolver()) {
71-
selectedShortcut = shortcutsResolver()->selectOne(allowedShortcuts);
72-
} else {
73-
selectedShortcut = allowedShortcuts.front();
74-
}
75-
}
76-
SC_LOG() << "selectedShortcut: " << selectedShortcut.command;
77-
if (selectedShortcut.isValid()) {
78-
commandDispatcher()->dispatch(Command(selectedShortcut.command));
79-
commandShortcutsProcessed = true;
80-
}
81-
}
41+
ActionCode actionCode = resolveAction(sequence);
8242

83-
if (!commandShortcutsProcessed) {
84-
ActionCode actionCode = resolveAction(sequence);
85-
if (!actionCode.empty()) {
86-
dispatcher()->dispatch(actionCode);
87-
}
43+
if (!actionCode.empty()) {
44+
dispatcher()->dispatch(actionCode);
8845
}
8946
}
9047

@@ -112,8 +69,7 @@ static bool defaultHasLowerPriorityThan(const std::string& ctx1, const std::stri
11269
ActionCode ShortcutsController::resolveAction(const std::string& sequence) const
11370
{
11471
ShortcutList shortcutsForSequence = shortcutsRegister()->shortcutsForSequence(sequence);
115-
if (shortcutsForSequence.empty()) {
116-
LOGD() << "No shortcuts found for sequence: " << sequence;
72+
IF_ASSERT_FAILED(!shortcutsForSequence.empty()) {
11773
return ActionCode();
11874
}
11975

framework/shortcuts/internal/shortcutscontroller.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,23 @@
2727
#include "async/asyncable.h"
2828
#include "modularity/ioc.h"
2929
#include "actions/iactionsdispatcher.h"
30-
#include "rcommand/icommanddispatcher.h"
31-
#include "rcommand/icommandsstate.h"
3230
#include "interactive/iinteractive.h"
3331
#include "ui/iuiactionsregister.h"
3432
#include "ui/iuicontextresolver.h"
3533
#include "ishortcutsregister.h"
36-
#include "icommandshortcutsregister.h"
3734
#include "shortcutcontext.h"
38-
#include "../ishortcutsresolver.h"
3935

4036
namespace muse::shortcuts {
4137
class ShortcutsController : public IShortcutsController, public Contextable, public async::Asyncable
4238
{
43-
GlobalInject<ICommandShortcutsRegister> commandShortcutsRegister;
4439
ContextInject<muse::ui::IUiActionsRegister> aregister = { this };
4540
ContextInject<IShortcutsRegister> shortcutsRegister = { this };
4641
ContextInject<muse::actions::IActionsDispatcher> dispatcher = { this };
47-
ContextInject<muse::rcommand::ICommandsState> commandsState = { this };
48-
ContextInject<muse::rcommand::ICommandDispatcher> commandDispatcher = { this };
4942
ContextInject<muse::IInteractive> interactive = { this };
5043
ContextInject<muse::ui::IUiContextResolver> uiContextResolver = { this };
5144

5245
//! NOTE May be missing because it must be implemented outside the framework
5346
ContextInject<IShortcutContextPriority> shortcutContextPriority = { this };
54-
ContextInject<IShortcutsResolver> shortcutsResolver = { this };
5547

5648
public:
5749
ShortcutsController(const modularity::ContextPtr& iocCtx)

framework/shortcuts/internal/shortcutsregister.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@
2828
#include "global/io/file.h"
2929
#include "global/serialization/xmlstreamreader.h"
3030
#include "global/serialization/xmlstreamwriter.h"
31-
#include "global/containers.h"
3231

3332
#include "multiwindows/resourcelockguard.h"
34-
#include "ui/navigationcommands.h"
3533

3634
#include "log.h"
3735

3836
using namespace muse;
3937
using namespace muse::shortcuts;
4038
using namespace muse::async;
41-
using namespace muse::ui;
4239

4340
static constexpr std::string_view SHORTCUTS_TAG("Shortcuts");
4441
static constexpr std::string_view SHORTCUT_TAG("SC");
@@ -49,25 +46,6 @@ static constexpr std::string_view AUTOREPEAT_TAG("autorepeat");
4946

5047
static const std::string SHORTCUTS_RESOURCE_NAME("SHORTCUTS");
5148

52-
static const std::map<std::string, rcommand::Command> compatActionToCommand = {
53-
{ "nav-next-section", NEXT_SECTION_COMMAND },
54-
{ "nav-prev-section", PREV_SECTION_COMMAND },
55-
{ "nav-next-panel", NEXT_PANEL_COMMAND },
56-
{ "nav-prev-panel", PREV_PANEL_COMMAND },
57-
{ "nav-next-tab", NEXT_PANEL_COMMAND },
58-
{ "nav-prev-tab", PREV_PANEL_COMMAND },
59-
{ "nav-trigger-control", TRIGGER_CONTROL_COMMAND },
60-
{ "nav-right", RIGHT_COMMAND },
61-
{ "nav-left", LEFT_COMMAND },
62-
{ "nav-up", UP_COMMAND },
63-
{ "nav-down", DOWN_COMMAND },
64-
{ "nav-escape", ESCAPE_COMMAND },
65-
{ "nav-first-control", FIRST_CONTROL_COMMAND },
66-
{ "nav-last-control", LAST_CONTROL_COMMAND },
67-
{ "nav-nextrow-control", NEXTROW_CONTROL_COMMAND },
68-
{ "nav-prevrow-control", PREVROW_CONTROL_COMMAND },
69-
};
70-
7149
static const std::map<QKeySequence::StandardKey, QKeyCombination> SHORTCUTS_EXPAND_IGNORE_MAP = {
7250
{ QKeySequence::StandardKey::HelpContents, Qt::Key_Help },
7351
{ QKeySequence::StandardKey::Open, Qt::Key_Open },
@@ -346,10 +324,6 @@ Shortcut ShortcutsRegister::readShortcut(XmlStreamReader& reader) const
346324

347325
if (tag == ACTION_CODE_TAG) {
348326
shortcut.action = reader.readAsciiText();
349-
const rcommand::Command& command = muse::value(compatActionToCommand, shortcut.action);
350-
if (command.isValid()) {
351-
shortcut.action = command.toString();
352-
}
353327
} else if (tag == STANDARD_KEY_TAG) {
354328
shortcut.standardKey = QKeySequence::StandardKey(reader.readInt());
355329
} else if (tag == SEQUENCE_TAG) {

framework/shortcuts/ishortcutsconfiguration.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,5 @@ class IShortcutsConfiguration : MODULE_GLOBAL_INTERFACE
3939

4040
virtual io::path_t shortcutsUserAppDataPath() const = 0;
4141
virtual io::path_t shortcutsAppDataPath() const = 0;
42-
43-
virtual io::path_t commandShortcutsUserAppDataPath() const = 0;
44-
virtual io::path_t commandShortcutsAppDataPath() const = 0;
4542
};
4643
}

0 commit comments

Comments
 (0)