Disable mnemonics when pathnames are used as menu item labels.
Based on a patch by Matthew White.pull/396/head
parent
a7b2f28999
commit
ce0b130d6c
|
@ -344,8 +344,8 @@ static void PopulateMenuWithPathnames(Platform::MenuRef menu,
|
||||||
menuItem->SetEnabled(false);
|
menuItem->SetEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
for(Platform::Path pathname : pathnames) {
|
for(Platform::Path pathname : pathnames) {
|
||||||
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw);
|
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw,
|
||||||
menuItem->onTrigger = [=]() { onTrigger(pathname); };
|
[=]() { onTrigger(pathname); }, /*mnemonics=*/false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,8 @@ public:
|
||||||
virtual ~Menu() {}
|
virtual ~Menu() {}
|
||||||
|
|
||||||
virtual std::shared_ptr<MenuItem> AddItem(
|
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 std::shared_ptr<Menu> AddSubMenu(const std::string &label) = 0;
|
||||||
virtual void AddSeparator() = 0;
|
virtual void AddSeparator() = 0;
|
||||||
|
|
||||||
|
|
|
@ -345,12 +345,13 @@ public:
|
||||||
std::vector<std::shared_ptr<MenuImplGtk>> subMenus;
|
std::vector<std::shared_ptr<MenuImplGtk>> subMenus;
|
||||||
|
|
||||||
MenuItemRef AddItem(const std::string &label,
|
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>();
|
auto menuItem = std::make_shared<MenuItemImplGtk>();
|
||||||
menuItems.push_back(menuItem);
|
menuItems.push_back(menuItem);
|
||||||
|
|
||||||
menuItem->gtkMenuItem.set_label(PrepareMnemonics(label));
|
menuItem->gtkMenuItem.set_label(mnemonics ? PrepareMnemonics(label) : label);
|
||||||
menuItem->gtkMenuItem.set_use_underline(true);
|
menuItem->gtkMenuItem.set_use_underline(mnemonics);
|
||||||
menuItem->gtkMenuItem.show();
|
menuItem->gtkMenuItem.show();
|
||||||
menuItem->onTrigger = onTrigger;
|
menuItem->onTrigger = onTrigger;
|
||||||
gtkMenu.append(menuItem->gtkMenuItem);
|
gtkMenu.append(menuItem->gtkMenuItem);
|
||||||
|
|
|
@ -257,12 +257,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItemRef AddItem(const std::string &label,
|
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>();
|
auto menuItem = std::make_shared<MenuItemImplCocoa>();
|
||||||
menuItems.push_back(menuItem);
|
menuItems.push_back(menuItem);
|
||||||
|
|
||||||
menuItem->onTrigger = onTrigger;
|
menuItem->onTrigger = onTrigger;
|
||||||
[menuItem->nsMenuItem setTitle:Wrap(PrepareMnemonics(label))];
|
[menuItem->nsMenuItem setTitle:Wrap(mnemonics ? PrepareMnemonics(label) : label)];
|
||||||
[nsMenu addItem:menuItem->nsMenuItem];
|
[nsMenu addItem:menuItem->nsMenuItem];
|
||||||
|
|
||||||
return menuItem;
|
return menuItem;
|
||||||
|
|
|
@ -107,6 +107,15 @@ static std::wstring PrepareTitle(const std::string &s) {
|
||||||
return Widen("SolveSpace - " + 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) {
|
static int Clamp(int x, int a, int b) {
|
||||||
return max(a, min(x, b));
|
return max(a, min(x, b));
|
||||||
}
|
}
|
||||||
|
@ -353,13 +362,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItemRef AddItem(const std::string &label,
|
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>();
|
auto menuItem = std::make_shared<MenuItemImplWin32>();
|
||||||
menuItem->menu = weakThis.lock();
|
menuItem->menu = weakThis.lock();
|
||||||
menuItem->onTrigger = onTrigger;
|
menuItem->onTrigger = onTrigger;
|
||||||
menuItems.push_back(menuItem);
|
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,
|
// uID is just an UINT, which isn't large enough to hold a pointer on 64-bit Windows,
|
||||||
// so we use dwItemData, which is.
|
// so we use dwItemData, which is.
|
||||||
|
|
Loading…
Reference in New Issue