Skip to content

Commit

Permalink
Fix broken key binding
Browse files Browse the repository at this point in the history
Was showing incorrect binding due to b538fae
Also fixed showing double entries
  • Loading branch information
aardappel committed Nov 8, 2022
1 parent 86c0307 commit d6adf61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
23 changes: 8 additions & 15 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,6 @@ struct Document {
}
}

static int CompareMenuString(const wxString &first, const wxString &second) {
auto a = first;
auto b = second;
if (a[0] == '&') a = a.Mid(1);
if (b[0] == '&') b = b.Mid(1);
return a.Cmp(b);
}

const wxChar *Key(wxDC &dc, wxChar uk, int k, bool alt, bool ctrl, bool shift,
bool &unprocessed) {
Cell *c = selected.GetCell();
Expand Down Expand Up @@ -1104,10 +1096,12 @@ struct Document {

case A_CUSTKEY: {
wxArrayString strs;
MyFrame::MenuString &ms = sys->frame->menustrings;
for (MyFrame::MenuStringIterator it = ms.begin(); it != ms.end(); ++it)
wxArrayString keys;
for (auto it = sys->frame->menustrings.begin(); it != sys->frame->menustrings.end();
++it) {
strs.push_back(it->first);
strs.Sort(CompareMenuString);
keys.push_back(it->second);
}
wxSingleChoiceDialog choice(
sys->frame, _(L"Please pick a menu item to change the key binding for"),
_(L"Key binding"), strs);
Expand All @@ -1117,12 +1111,11 @@ struct Document {
int sel = choice.GetSelection();
wxTextEntryDialog textentry(sys->frame,
"Please enter the new key binding string",
"Key binding", ms[sel].second);
"Key binding", keys[sel]);
if (textentry.ShowModal() == wxID_OK) {
wxString key = textentry.GetValue();
ms[sel].second = key;

sys->cfg->Write(ms[sel].first, key);
sys->frame->menustrings[strs[sel]] = key;
sys->cfg->Write(strs[sel], key);
return _(L"NOTE: key binding will take effect next run of TreeSheets.");
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/myframe.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
struct MyFrame : wxFrame {
typedef std::vector<std::pair<wxString, wxString>> MenuString;
typedef MenuString::iterator MenuStringIterator;
wxMenu *editmenupopup;
wxString exepath_;
wxFileHistory filehistory;
Expand Down Expand Up @@ -61,7 +59,7 @@ struct MyFrame : wxFrame {
return wxString(relativePath.c_str());
}

MenuString menustrings;
std::map<wxString, wxString> menustrings;

void MyAppend(wxMenu *menu, int tag, const wxString &contents, const wchar_t *help = L"") {
wxString item = contents;
Expand All @@ -75,7 +73,7 @@ struct MyFrame : wxFrame {
wxString newcontents = item;
if (key.Length()) newcontents += "\t" + key;
menu->Append(tag, newcontents, help);
menustrings.push_back(std::make_pair(item, key));
menustrings[item] = key;
}

MyFrame(wxString exename, MyApp *_app)
Expand Down

0 comments on commit d6adf61

Please sign in to comment.