Skip to content

Shortcuts v2. Added presets - #213

Open
Eism wants to merge 7 commits into
musescore:mainfrom
Eism:shortcuts_v2_presets
Open

Shortcuts v2. Added presets#213
Eism wants to merge 7 commits into
musescore:mainfrom
Eism:shortcuts_v2_presets

Conversation

@Eism

@Eism Eism commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Adds preset support to the command shortcuts system. A preset is a named keyboard layout scheme (e.g. AZERTY) that the user can switch to, customize, and reset — without losing customizations of other presets.

Shortcuts are resolved as a chain of layers, each layer is a diff applied on top of the previous one:

base (shortcuts.json)
      -> platform diff   (shortcuts_mac.json, macOS only)
          -> preset diff     (shortcuts_azerty.json, if a preset is selected, from shortcuts_mac on macOS)

The user diff of each set lives in its own file, so switching presets never loses customizations. A set is considered edited iff its user file exists (same convention as workspaces). When the user reverts all changes, the computed diff becomes empty and the file is deleted — the set returns to the pristine state automatically.

UI isn't finished (just an example)

Screen.Recording.2026-08-11.at.5.19.27.PM.mov

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The shortcuts build now selects the V2 or legacy module conditionally. Shortcuts V2 adds named preset configuration, selection, persistence, diff application, reset, and deletion. The QML model and panels expose preset state and track unsaved changes. Tests cover preset loading, persistence, reset, editing, and deletion. Compatibility stubs implement the expanded configuration interface.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains preset support and its layered behavior, but it omits the issue reference, required checklist, and build configuration. Add the required Resolves entry, complete all checklist items, and include the repository's build configuration section.
Docstring Coverage ⚠️ Warning Docstring coverage is 1.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding presets to the Shortcuts v2 system.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@framework/shortcuts_v2/internal/commandshortcutsregister.cpp`:
- Around line 361-369: Update setShortcuts() so the empty-diff branch assigns ok
from removeUserFile() instead of assuming success, and change removeUserFile()
to return whether removal succeeded. Preserve m_shortcuts updates and success
signaling only when ok is true, and propagate the same failure handling through
reset and deletion flows, including appropriate logging or handling.
- Around line 413-415: Replace mi::ReadResourceLockGuard with
mi::WriteResourceLockGuard around the io::File::copy operation in the preset
import block, preserving the existing multiwindowsProvider() and
COMMAND_SHORTCUTS_TAG lock scope.

In `@framework/shortcuts_v2/internal/shortcutsconfiguration.cpp`:
- Around line 116-119: Validate shortcutsName before
commandShortcutsUserAppDataPath constructs the path: reject empty names or
segments, path separators, and traversal components such as “.” or “..”. Apply
the same validation to persisted preset names before setShortcuts(),
importFromFile(), or deletePreset() resolves, writes, copies, or removes paths,
and fail safely for invalid values.

In `@framework/shortcuts_v2/qml/Muse/Shortcuts/shortcutsmodel.cpp`:
- Around line 191-193: Update the currentPresetNameChanged callback in
ShortcutsModel so it also emits presetsChanged() after a preset switch. Preserve
the existing currentPresetNameChanged() emission, ensuring preset-dependent
properties such as isCurrentPresetEdited and canDeleteCurrentPreset refresh for
the newly selected preset.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0224aa99-2354-486d-be4e-cc87de88eb14

📥 Commits

Reviewing files that changed from the base of the PR and between 4f86705 and 8ad9dbd.

📒 Files selected for processing (27)
  • framework/CMakeLists.txt
  • framework/shortcuts/ishortcutsconfiguration.h
  • framework/shortcuts/ishortcutscontroller.h
  • framework/shortcuts/ishortcutsregister.h
  • framework/shortcuts/shortcutcontext.h
  • framework/shortcuts/shortcutsmodule.h
  • framework/shortcuts/shortcutstypes.h
  • framework/shortcuts_v2/CMakeLists.txt
  • framework/shortcuts_v2/icommandshortcutsregister.h
  • framework/shortcuts_v2/internal/commandshortcutsregister.cpp
  • framework/shortcuts_v2/internal/commandshortcutsregister.h
  • framework/shortcuts_v2/internal/shortcutsconfiguration.cpp
  • framework/shortcuts_v2/internal/shortcutsconfiguration.h
  • framework/shortcuts_v2/ishortcutsconfiguration.h
  • framework/shortcuts_v2/qml/Muse/Shortcuts/ShortcutsPage.qml
  • framework/shortcuts_v2/qml/Muse/Shortcuts/internal/ShortcutsTopPanel.qml
  • framework/shortcuts_v2/qml/Muse/Shortcuts/shortcutsmodel.cpp
  • framework/shortcuts_v2/qml/Muse/Shortcuts/shortcutsmodel.h
  • framework/shortcuts_v2/tests/CMakeLists.txt
  • framework/shortcuts_v2/tests/commandshortcutsregister_tests.cpp
  • framework/shortcuts_v2/tests/mocks/shortcutsconfigurationmock.h
  • framework/shortcuts_v2/tests/testdata/shortcuts.json
  • framework/shortcuts_v2/tests/testdata/shortcuts_azerty.json
  • framework/shortcuts_v2/tests/testdata/shortcuts_mac.json
  • framework/stubs/shortcuts/shortcutsconfigurationstub.cpp
  • framework/stubs/shortcuts/shortcutsconfigurationstub.h
  • framework/ui/uitypes.h
💤 Files with no reviewable changes (2)
  • framework/ui/uitypes.h
  • framework/CMakeLists.txt

Comment on lines +361 to +369
bool ok = true;
if (diff.empty()) {
removeUserFile();
} else {
ok = writeToFile(diff, userShortcutsPath());
}

if (ok) {
m_shortcuts = needToWrite;
m_shortcuts = diff;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not report success when user-file removal fails.

When diff is empty, Line 363 removes the user file but leaves ok true. If removal fails, this method updates m_shortcuts, sends m_shortcutsChanged, and returns success while the old diff remains on disk. The edit returns after the next reload.

Make removeUserFile() return the removal status. Propagate that status through setShortcuts(). Log or handle the same failure in reset and deletion flows.

🧰 Tools
🪛 Clang (14.0.6)

[warning] 361-361: variable name 'ok' is too short, expected at least 3 characters

(readability-identifier-length)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/shortcuts_v2/internal/commandshortcutsregister.cpp` around lines
361 - 369, Update setShortcuts() so the empty-diff branch assigns ok from
removeUserFile() instead of assuming success, and change removeUserFile() to
return whether removal succeeded. Preserve m_shortcuts updates and success
signaling only when ok is true, and propagate the same failure handling through
reset and deletion flows, including appropriate logging or handling.

Comment on lines 413 to +415
{
mi::ReadResourceLockGuard guard(multiwindowsProvider(), COMMAND_SHORTCUTS_TAG);
Ret ret = io::File::copy(filePath, configuration()->commandShortcutsUserAppDataPath(), true);
Ret ret = io::File::copy(filePath, userShortcutsPath(), true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Use a write lock for preset import.

io::File::copy() writes userShortcutsPath(), but this block uses mi::ReadResourceLockGuard. A concurrent reload can read a partially copied JSON file. A concurrent writer can also overwrite the imported preset.

Replace the read guard with mi::WriteResourceLockGuard.

Proposed fix
-        mi::ReadResourceLockGuard guard(multiwindowsProvider(), COMMAND_SHORTCUTS_TAG);
+        mi::WriteResourceLockGuard guard(multiwindowsProvider(), COMMAND_SHORTCUTS_TAG);
         Ret ret = io::File::copy(filePath, userShortcutsPath(), true);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
mi::ReadResourceLockGuard guard(multiwindowsProvider(), COMMAND_SHORTCUTS_TAG);
Ret ret = io::File::copy(filePath, configuration()->commandShortcutsUserAppDataPath(), true);
Ret ret = io::File::copy(filePath, userShortcutsPath(), true);
{
mi::WriteResourceLockGuard guard(multiwindowsProvider(), COMMAND_SHORTCUTS_TAG);
Ret ret = io::File::copy(filePath, userShortcutsPath(), true);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/shortcuts_v2/internal/commandshortcutsregister.cpp` around lines
413 - 415, Replace mi::ReadResourceLockGuard with mi::WriteResourceLockGuard
around the io::File::copy operation in the preset import block, preserving the
existing multiwindowsProvider() and COMMAND_SHORTCUTS_TAG lock scope.

Comment on lines +116 to +119
io::path_t ShortcutsConfiguration::commandShortcutsUserAppDataPath(const std::string& shortcutsName) const
{
return userShortcutsDirPath() + "/" + shortcutsName + ".json";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Validate preset names before building file paths.

Line 118 concatenates an unchecked preset name into a writable path. A value such as "../../other-file" escapes the shortcuts directory. setShortcuts(), importFromFile(), and deletePreset() then write, copy, or remove the resolved path.

Reject path separators, traversal components, and empty segments before persisting or resolving a preset name. Apply the validation to persisted values before using them.

🧰 Tools
🪛 Clang (14.0.6)

[warning] 116-116: use a trailing return type for this function

(modernize-use-trailing-return-type)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/shortcuts_v2/internal/shortcutsconfiguration.cpp` around lines 116
- 119, Validate shortcutsName before commandShortcutsUserAppDataPath constructs
the path: reject empty names or segments, path separators, and traversal
components such as “.” or “..”. Apply the same validation to persisted preset
names before setShortcuts(), importFromFile(), or deletePreset() resolves,
writes, copies, or removes paths, and fail safely for invalid values.

Comment on lines +191 to +193
commandShortcutsRegister()->currentPresetNameChanged().onReceive(this, [this](const std::string&) {
emit currentPresetNameChanged();
}, async::Asyncable::Mode::SetReplace);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Notify preset-dependent properties after a preset switch.

Line 191 emits currentPresetNameChanged() only. isCurrentPresetEdited and canDeleteCurrentPreset use presetsChanged as their notifier. The reset button can retain the state of the previous preset after selection. Emit presetsChanged() in this callback.

Proposed fix
     commandShortcutsRegister()->currentPresetNameChanged().onReceive(this, [this](const std::string&) {
         emit currentPresetNameChanged();
+        emit presetsChanged();
     }, async::Asyncable::Mode::SetReplace);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
commandShortcutsRegister()->currentPresetNameChanged().onReceive(this, [this](const std::string&) {
emit currentPresetNameChanged();
}, async::Asyncable::Mode::SetReplace);
commandShortcutsRegister()->currentPresetNameChanged().onReceive(this, [this](const std::string&) {
emit currentPresetNameChanged();
emit presetsChanged();
}, async::Asyncable::Mode::SetReplace);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/shortcuts_v2/qml/Muse/Shortcuts/shortcutsmodel.cpp` around lines
191 - 193, Update the currentPresetNameChanged callback in ShortcutsModel so it
also emits presetsChanged() after a preset switch. Preserve the existing
currentPresetNameChanged() emission, ensuring preset-dependent properties such
as isCurrentPresetEdited and canDeleteCurrentPreset refresh for the newly
selected preset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant