Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/appshell/internal/iappmenumodelhook.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define MU_APPSHELL_IAPPMENUMODELHOOK_H

#include "modularity/imoduleinterface.h"
#include "uicomponents/qml/Muse/UiComponents/menuitem.h"

namespace mu::appshell {
class IAppMenuModelHook : MODULE_CONTEXT_INTERFACE
Expand All @@ -32,13 +33,14 @@ class IAppMenuModelHook : MODULE_CONTEXT_INTERFACE
public:
virtual ~IAppMenuModelHook() = default;

virtual void onAppMenuInited() = 0;
//! Invoked once the application's top-level menu hierarchy has been loaded.
virtual void onAppMenuInited(const muse::uicomponents::MenuItemList& items) = 0;
};

class AppMenuModelHookStub : public IAppMenuModelHook
{
public:
void onAppMenuInited() override {}
void onAppMenuInited(const muse::uicomponents::MenuItemList& /*items*/) override {}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ namespace mu::appshell {
class MacOSAppMenuModelHook : public IAppMenuModelHook
{
public:
void onAppMenuInited() override;
void onAppMenuInited(const muse::uicomponents::MenuItemList& items) override;
};
}
51 changes: 50 additions & 1 deletion src/appshell/internal/platform/macos/macosappmenumodelhook.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,59 @@

#include <Cocoa/Cocoa.h>

#include "interactive/internal/platform/macos/macosinteractivehelper.h"
#include "notationscene/notationcommands.h"

using namespace mu::appshell;

void MacOSAppMenuModelHook::onAppMenuInited()
void MacOSAppMenuModelHook::onAppMenuInited(const muse::uicomponents::MenuItemList& items)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSDisabledDictationMenuItem"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSDisabledCharacterPaletteMenuItem"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSMenuEnableActionImages"];

const muse::uicomponents::MenuItem* editMenu = nullptr;
int editTopLevelIndex = -1;
for (int i = 0; i < items.size(); ++i) {
if (items[i] && items[i]->id() == "menu-edit") {
editMenu = items[i];
editTopLevelIndex = i;
break;
}
}

if (!editMenu || editTopLevelIndex < 0) {
return;
}

// AppKit inserts the Application menu at index 0 on macOS, shifting top-level menus by +1
muse::MacOSInteractiveHelper::setEditMenuIndex(editTopLevelIndex + 1);

int index = 0;
std::map<muse::MacOSInteractiveHelper::EditAction, int> structure;

for (const muse::uicomponents::MenuItem* subitem : editMenu->subitems()) {
if (!subitem || subitem->id().isEmpty()) {
index++;
continue;
}

if (subitem->id() == mu::notation::UNDO_COMMAND.toString()) {
structure[muse::MacOSInteractiveHelper::EditAction::Undo] = index;
} else if (subitem->id() == mu::notation::REDO_COMMAND.toString()) {
structure[muse::MacOSInteractiveHelper::EditAction::Redo] = index;
} else if (subitem->id() == mu::notation::CUT_COMMAND.toString()) {
structure[muse::MacOSInteractiveHelper::EditAction::Cut] = index;
} else if (subitem->id() == mu::notation::COPY_COMMAND.toString()) {
structure[muse::MacOSInteractiveHelper::EditAction::Copy] = index;
} else if (subitem->id() == mu::notation::PASTE_COMMAND.toString()) {
structure[muse::MacOSInteractiveHelper::EditAction::Paste] = index;
} else if (subitem->id() == mu::notation::SELECT_ALL_COMMAND.toString()) {
structure[muse::MacOSInteractiveHelper::EditAction::SelectAll] = index;
}

index++;
}

muse::MacOSInteractiveHelper::setEditMenuStructure(structure);
}
2 changes: 1 addition & 1 deletion src/appshell/qml/MuseScore/AppShell/appmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void AppMenuModel::load()

//! NOTE: removes some undesired platform-specific items
//! (such as "Start Dictation" and "Special Characters" on macOS)
appMenuModelHook()->onAppMenuInited();
appMenuModelHook()->onAppMenuInited(items);
}

bool AppMenuModel::isGlobalMenuAvailable()
Expand Down
Loading