Disable mnemonics when pathnames are used as menu item labels.

Based on a patch by Matthew White.
pull/396/head
whitequark 2019-04-13 11:00:35 +00:00
parent a7b2f28999
commit ce0b130d6c
5 changed files with 24 additions and 10 deletions

View File

@ -344,8 +344,8 @@ static void PopulateMenuWithPathnames(Platform::MenuRef menu,
menuItem->SetEnabled(false);
} else {
for(Platform::Path pathname : pathnames) {
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw);
menuItem->onTrigger = [=]() { onTrigger(pathname); };
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw,
[=]() { onTrigger(pathname); }, /*mnemonics=*/false);
}
}
}

View File

@ -171,7 +171,8 @@ public:
virtual ~Menu() {}
virtual std::shared_ptr<MenuItem> AddItem(
const std::string &label, std::function<void()> onTrigger = std::function<void()>()) = 0;
const std::string &label, std::function<void()> onTrigger = std::function<void()>(),
bool mnemonics = true) = 0;
virtual std::shared_ptr<Menu> AddSubMenu(const std::string &label) = 0;
virtual void AddSeparator() = 0;

View File

@ -345,12 +345,13 @@ public:
std::vector<std::shared_ptr<MenuImplGtk>> subMenus;
MenuItemRef AddItem(const std::string &label,
std::function<void()> onTrigger = NULL) override {
std::function<void()> onTrigger = NULL,
bool mnemonics = true) override {
auto menuItem = std::make_shared<MenuItemImplGtk>();
menuItems.push_back(menuItem);
menuItem->gtkMenuItem.set_label(PrepareMnemonics(label));
menuItem->gtkMenuItem.set_use_underline(true);
menuItem->gtkMenuItem.set_label(mnemonics ? PrepareMnemonics(label) : label);
menuItem->gtkMenuItem.set_use_underline(mnemonics);
menuItem->gtkMenuItem.show();
menuItem->onTrigger = onTrigger;
gtkMenu.append(menuItem->gtkMenuItem);

View File

@ -257,12 +257,13 @@ public:
}
MenuItemRef AddItem(const std::string &label,
std::function<void()> onTrigger = NULL) override {
std::function<void()> onTrigger = NULL,
bool mnemonics = true) override {
auto menuItem = std::make_shared<MenuItemImplCocoa>();
menuItems.push_back(menuItem);
menuItem->onTrigger = onTrigger;
[menuItem->nsMenuItem setTitle:Wrap(PrepareMnemonics(label))];
[menuItem->nsMenuItem setTitle:Wrap(mnemonics ? PrepareMnemonics(label) : label)];
[nsMenu addItem:menuItem->nsMenuItem];
return menuItem;

View File

@ -107,6 +107,15 @@ static std::wstring PrepareTitle(const std::string &s) {
return Widen("SolveSpace - " + s);
}
static std::string NegateMnemonics(const std::string &label) {
std::string newLabel;
for(char c : label) {
newLabel.push_back(c);
if(c == '&') newLabel.push_back(c);
}
return newLabel;
}
static int Clamp(int x, int a, int b) {
return max(a, min(x, b));
}
@ -353,13 +362,15 @@ public:
}
MenuItemRef AddItem(const std::string &label,
std::function<void()> onTrigger = NULL) override {
std::function<void()> onTrigger = NULL,
bool mnemonics = true) override {
auto menuItem = std::make_shared<MenuItemImplWin32>();
menuItem->menu = weakThis.lock();
menuItem->onTrigger = onTrigger;
menuItems.push_back(menuItem);
sscheck(AppendMenuW(hMenu, MF_STRING, (UINT_PTR)menuItem.get(), Widen(label).c_str()));
sscheck(AppendMenuW(hMenu, MF_STRING, (UINT_PTR)menuItem.get(),
Widen(mnemonics ? label : NegateMnemonics(label)).c_str()));
// uID is just an UINT, which isn't large enough to hold a pointer on 64-bit Windows,
// so we use dwItemData, which is.