When adding new hotkeys, automatically select and start editing the new hotkey

Originally committed to SVN as r6420.
This commit is contained in:
Thomas Goyne 2012-02-01 18:47:00 +00:00
parent 499a9b2869
commit f0933ecb1a
3 changed files with 27 additions and 11 deletions

View File

@ -145,10 +145,11 @@ public:
{ {
} }
void AddChild(Combo const& combo) { wxDataViewItem AddChild(Combo const& combo) {
children.push_back(HotkeyModelCombo(this, combo)); children.push_back(HotkeyModelCombo(this, combo));
visible_items.push_back(wxDataViewItem(&children.back())); visible_items.push_back(wxDataViewItem(&children.back()));
model->ItemAdded(wxDataViewItem(this), wxDataViewItem(&children.back())); model->ItemAdded(wxDataViewItem(this), wxDataViewItem(&children.back()));
return wxDataViewItem(&children.back());
} }
void Delete(wxDataViewItem const& item) { void Delete(wxDataViewItem const& item) {
@ -307,8 +308,8 @@ bool HotkeyDataViewModel::SetValue(wxVariant const& variant, wxDataViewItem cons
return get(item)->SetValue(variant, col); return get(item)->SetValue(variant, col);
} }
void HotkeyDataViewModel::New(wxDataViewItem item) { wxDataViewItem HotkeyDataViewModel::New(wxDataViewItem item) {
if (!item.IsOk()) return; if (!item.IsOk()) return wxDataViewItem();
if (!IsContainer(item)) if (!IsContainer(item))
item = GetParent(item); item = GetParent(item);
@ -316,7 +317,7 @@ void HotkeyDataViewModel::New(wxDataViewItem item) {
HotkeyModelCategory *ctx = static_cast<HotkeyModelCategory*>(item.GetID()); HotkeyModelCategory *ctx = static_cast<HotkeyModelCategory*>(item.GetID());
wxVariant name; wxVariant name;
ctx->GetValue(name, 0); ctx->GetValue(name, 0);
ctx->AddChild(Combo(STD_STR(name.GetString()), "", std::vector<std::string>())); return ctx->AddChild(Combo(STD_STR(name.GetString()), "", std::vector<std::string>()));
} }
void HotkeyDataViewModel::Delete(wxDataViewItem const& item) { void HotkeyDataViewModel::Delete(wxDataViewItem const& item) {

View File

@ -46,7 +46,9 @@ public:
HotkeyDataViewModel(Preferences *parent); HotkeyDataViewModel(Preferences *parent);
/// Create a new hotkey in the current context /// Create a new hotkey in the current context
void New(wxDataViewItem item); /// @param item A context or hotkey entry
/// @return The new hotkey
wxDataViewItem New(wxDataViewItem item);
/// Delete the currently selected hotkey /// Delete the currently selected hotkey
void Delete(wxDataViewItem const& item); void Delete(wxDataViewItem const& item);
/// Update the hotkeys with changes made to the model /// Update the hotkeys with changes made to the model

View File

@ -417,16 +417,29 @@ Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent)
SetSizerAndFit(sizer); SetSizerAndFit(sizer);
} }
static void edit_item(wxDataViewCtrl *dvc, wxDataViewItem item) {
#if wxCHECK_VERSION(2, 9, 4)
dvc->EditItem(item, dvc->GetColumn(0));
#else
dvc->StartEditor(item, 0);
#endif
}
void Interface_Hotkeys::OnNewButton(wxCommandEvent&) { void Interface_Hotkeys::OnNewButton(wxCommandEvent&) {
model->New(dvc->GetSelection()); wxDataViewItem sel = dvc->GetSelection();
dvc->ExpandAncestors(sel);
dvc->Expand(sel);
wxDataViewItem new_item = model->New(sel);
if (new_item.IsOk()) {
dvc->Select(new_item);
dvc->EnsureVisible(new_item);
edit_item(dvc, new_item);
}
} }
void Interface_Hotkeys::OnEditButton(wxCommandEvent&) { void Interface_Hotkeys::OnEditButton(wxCommandEvent&) {
#if wxCHECK_VERSION(2, 9, 4) edit_item(dvc, dvc->GetSelection());
dvc->EditItem(dvc->GetSelection(), dvc->GetColumn(0));
#else
dvc->StartEditor(dvc->GetSelection(), 0);
#endif
} }
void Interface_Hotkeys::OnDeleteButton(wxCommandEvent&) { void Interface_Hotkeys::OnDeleteButton(wxCommandEvent&) {