Skip to content

Commit

Permalink
Fix #25702: Update shortcut definitions in "Playback settings" contex…
Browse files Browse the repository at this point in the history
…t without restarting (#25740)
  • Loading branch information
pacebes authored Dec 13, 2024
1 parent 483fb38 commit f461818
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/framework/ui/uiaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct UiAction
&& description == other.description
&& iconCode == other.iconCode
&& checkable == other.checkable
&& shortcuts == shortcuts;
&& shortcuts == other.shortcuts;
}
};

Expand Down
30 changes: 30 additions & 0 deletions src/framework/uicomponents/view/abstractmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void AbstractMenuModel::load()
uiActionsRegister()->actionStateChanged().onReceive(this, [this](const ActionCodeList& codes) {
onActionsStateChanges(codes);
});

shortcutsRegister()->shortcutsChanged().onNotify(this, [this]() {
updateShortcutsAll();
});
}

QVariantList AbstractMenuModel::itemsProperty() const
Expand Down Expand Up @@ -315,3 +319,29 @@ MenuItem& AbstractMenuModel::menu(MenuItemList& items, const QString& menuId)
static MenuItem dummy;
return dummy;
}

void AbstractMenuModel::updateShortcutsAll()
{
for (MenuItem* menuItem : m_items) {
if (!menuItem) {
continue;
}

updateShortcuts(menuItem);
}
}

void AbstractMenuModel::updateShortcuts(MenuItem* item)
{
UiAction action = item->action();
action.shortcuts = shortcutsRegister()->shortcut(action.code).sequences;
item->setAction(action);

for (MenuItem* subItem : item->subitems()) {
if (!subItem) {
continue;
}

updateShortcuts(subItem);
}
}
5 changes: 5 additions & 0 deletions src/framework/uicomponents/view/abstractmenumodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "modularity/ioc.h"
#include "ui/iuiactionsregister.h"
#include "shortcuts/ishortcutsregister.h"
#include "actions/iactionsdispatcher.h"

namespace muse::uicomponents {
Expand All @@ -43,6 +44,7 @@ class AbstractMenuModel : public QAbstractListModel, public muse::Injectable, pu
public:
muse::Inject<ui::IUiActionsRegister> uiActionsRegister = { this };
muse::Inject<muse::actions::IActionsDispatcher> dispatcher = { this };
muse::Inject<shortcuts::IShortcutsRegister> shortcutsRegister = { this };

public:
explicit AbstractMenuModel(QObject* parent = nullptr);
Expand Down Expand Up @@ -98,6 +100,9 @@ class AbstractMenuModel : public QAbstractListModel, public muse::Injectable, pu
MenuItem& item(MenuItemList& items, const muse::actions::ActionCode& actionCode);
MenuItem& menu(MenuItemList& items, const QString& menuId);

void updateShortcutsAll();
void updateShortcuts(MenuItem* item);

MenuItemList m_items;
};
}
Expand Down
40 changes: 40 additions & 0 deletions src/framework/uicomponents/view/abstracttoolbarmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ void AbstractToolBarModel::load()
uiActionsRegister()->actionStateChanged().onReceive(this, [this](const ActionCodeList& codes) {
onActionsStateChanges(codes);
});

shortcutsRegister()->shortcutsChanged().onNotify(this, [this]() {
updateShortcutsAll();
});
}

QVariantList AbstractToolBarModel::itemsProperty() const
Expand Down Expand Up @@ -322,3 +326,39 @@ ToolBarItem& AbstractToolBarModel::item(const ToolBarItemList& items, const Acti
static ToolBarItem dummy;
return dummy;
}

void AbstractToolBarModel::updateShortcutsAll()
{
for (ToolBarItem* toolBarItem : m_items) {
if (!toolBarItem) {
continue;
}

UiAction action = toolBarItem->action();
action.shortcuts = shortcutsRegister()->shortcut(action.code).sequences;
toolBarItem->setAction(action);

for (MenuItem* menuItem : toolBarItem->menuItems()) {
if (!menuItem) {
continue;
}

updateShortcuts(menuItem);
}
}
}

void AbstractToolBarModel::updateShortcuts(MenuItem* menuItem)
{
UiAction action = menuItem->action();
action.shortcuts = shortcutsRegister()->shortcut(action.code).sequences;
menuItem->setAction(action);

for (MenuItem* subItem : menuItem->subitems()) {
if (!subItem) {
continue;
}

updateShortcuts(subItem);
}
}
6 changes: 6 additions & 0 deletions src/framework/uicomponents/view/abstracttoolbarmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

#include "modularity/ioc.h"
#include "ui/iuiactionsregister.h"
#include "shortcuts/ishortcutsregister.h"
#include "actions/iactionsdispatcher.h"

namespace muse::uicomponents {
class ToolBarItem;
class MenuItem;
using ToolBarItemList = QList<ToolBarItem*>;
class ToolBarItemType
{
Expand All @@ -56,6 +58,7 @@ class AbstractToolBarModel : public QAbstractListModel, public Injectable, publi
public:
Inject<ui::IUiActionsRegister> uiActionsRegister = { this };
Inject<actions::IActionsDispatcher> dispatcher = { this };
Inject<shortcuts::IShortcutsRegister> shortcutsRegister = { this };

public:
explicit AbstractToolBarModel(QObject* parent = nullptr);
Expand Down Expand Up @@ -112,6 +115,9 @@ class AbstractToolBarModel : public QAbstractListModel, public Injectable, publi
ToolBarItem& item(const ToolBarItemList& items, const QString& itemId);
ToolBarItem& item(const ToolBarItemList& items, const actions::ActionCode& actionCode);

void updateShortcutsAll();
void updateShortcuts(MenuItem* menuItem);

ToolBarItemList m_items;
};
}

0 comments on commit f461818

Please sign in to comment.