Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: solvespace/solvespace
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a7b2f2899944
Choose a base ref
...
head repository: solvespace/solvespace
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ce0b130d6ceb
Choose a head ref
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Apr 13, 2019

  1. Disable mnemonics when pathnames are used as menu item labels.

    Based on a patch by Matthew White.
    whitequark committed Apr 13, 2019
    Copy the full SHA
    ce0b130 View commit details
Showing with 24 additions and 10 deletions.
  1. +2 −2 src/graphicswin.cpp
  2. +2 −1 src/platform/gui.h
  3. +4 −3 src/platform/guigtk.cpp
  4. +3 −2 src/platform/guimac.mm
  5. +13 −2 src/platform/guiwin.cpp
4 changes: 2 additions & 2 deletions src/graphicswin.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
3 changes: 2 additions & 1 deletion src/platform/gui.h
Original file line number Diff line number Diff line change
@@ -171,7 +171,8 @@ class Menu {
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;

7 changes: 4 additions & 3 deletions src/platform/guigtk.cpp
Original file line number Diff line number Diff line change
@@ -345,12 +345,13 @@ class MenuImplGtk final : public Menu {
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);
5 changes: 3 additions & 2 deletions src/platform/guimac.mm
Original file line number Diff line number Diff line change
@@ -257,12 +257,13 @@ void SetEnabled(bool enabled) override {
}

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;
15 changes: 13 additions & 2 deletions src/platform/guiwin.cpp
Original file line number Diff line number Diff line change
@@ -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 @@ class MenuImplWin32 final : public Menu {
}

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.