From de4ef145989bce7e749ca1fae965fed5c5df2f02 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 2 Dec 2012 13:29:46 -0800 Subject: [PATCH] Use lambdas for very short event handlers --- aegisub/src/dialog_export.cpp | 61 +++++++++---------------- aegisub/src/dialog_export.h | 5 -- aegisub/src/dialog_selected_choices.cpp | 6 +-- aegisub/src/dialog_selected_choices.h | 1 - aegisub/src/dialog_spellchecker.cpp | 6 +-- aegisub/src/dialog_spellchecker.h | 1 - aegisub/src/preferences.cpp | 37 +++++---------- aegisub/src/visual_tool_vector_clip.cpp | 6 +-- aegisub/src/visual_tool_vector_clip.h | 3 -- 9 files changed, 35 insertions(+), 91 deletions(-) diff --git a/aegisub/src/dialog_export.cpp b/aegisub/src/dialog_export.cpp index 718378758..4b3147e1b 100644 --- a/aegisub/src/dialog_export.cpp +++ b/aegisub/src/dialog_export.cpp @@ -50,6 +50,22 @@ #include "libresrc/libresrc.h" #include "subtitle_format.h" +// Swap the items at idx and idx + 1 +static void swap(wxCheckListBox *list, int idx, int sel_dir) { + if (idx < 0 || idx + 1 == (int)list->GetCount()) return; + + list->Freeze(); + wxString tempname = list->GetString(idx); + bool tempval = list->IsChecked(idx); + list->SetString(idx, list->GetString(idx + 1)); + list->Check(idx, list->IsChecked(idx + 1)); + list->SetString(idx + 1, tempname); + list->Check(idx + 1, tempval); + list->SetSelection(idx + sel_dir); + list->Thaw(); +} + + DialogExport::DialogExport(agi::Context *c) : wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX) , c(c) @@ -60,7 +76,7 @@ DialogExport::DialogExport(agi::Context *c) wxArrayString filters = exporter->GetAllFilterNames(); filter_list = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(200, 100), filters); - filter_list->Bind(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, &DialogExport::OnCheck, this); + filter_list->Bind(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, [=](wxCommandEvent&) { RefreshOptions(); }); filter_list->Bind(wxEVT_COMMAND_LISTBOX_SELECTED, &DialogExport::OnChange, this); // Get selected filters @@ -80,10 +96,10 @@ DialogExport::DialogExport(agi::Context *c) wxButton *btn_all = new wxButton(this, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1)); wxButton *btn_none = new wxButton(this, -1, _("Select &None"), wxDefaultPosition, wxSize(80, -1)); - btn_up->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnMoveUp, this); - btn_down->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnMoveDown, this); - btn_all->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnSelectAll, this); - btn_none->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnSelectNone, this); + btn_up->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); }); + btn_down->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); }); + btn_all->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { SetAll(true); }); + btn_none->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { SetAll(true); }); wxSizer *top_buttons = new wxBoxSizer(wxHORIZONTAL); top_buttons->Add(btn_up, wxSizerFlags(1).Expand()); @@ -171,10 +187,6 @@ void DialogExport::OnProcess(wxCommandEvent &) { EndModal(0); } -void DialogExport::OnCheck(wxCommandEvent &) { - RefreshOptions(); -} - void DialogExport::OnChange(wxCommandEvent &) { int n = filter_list->GetSelection(); if (n != wxNOT_FOUND) { @@ -183,37 +195,6 @@ void DialogExport::OnChange(wxCommandEvent &) { } } -// Swap the items at idx and idx + 1 -static void swap(wxCheckListBox *list, int idx, int sel_dir) { - if (idx < 0 || idx + 1 == (int)list->GetCount()) return; - - list->Freeze(); - wxString tempname = list->GetString(idx); - bool tempval = list->IsChecked(idx); - list->SetString(idx, list->GetString(idx + 1)); - list->Check(idx, list->IsChecked(idx + 1)); - list->SetString(idx + 1, tempname); - list->Check(idx + 1, tempval); - list->SetSelection(idx + sel_dir); - list->Thaw(); -} - -void DialogExport::OnMoveUp(wxCommandEvent &) { - swap(filter_list, filter_list->GetSelection() - 1, 0); -} - -void DialogExport::OnMoveDown(wxCommandEvent &) { - swap(filter_list, filter_list->GetSelection(), 1); -} - -void DialogExport::OnSelectAll(wxCommandEvent &) { - SetAll(true); -} - -void DialogExport::OnSelectNone(wxCommandEvent &) { - SetAll(false); -} - void DialogExport::SetAll(bool new_value) { filter_list->Freeze(); for (size_t i = 0; i < filter_list->GetCount(); ++i) diff --git a/aegisub/src/dialog_export.h b/aegisub/src/dialog_export.h index f2d2a76c5..952319701 100644 --- a/aegisub/src/dialog_export.h +++ b/aegisub/src/dialog_export.h @@ -65,11 +65,6 @@ class DialogExport : public wxDialog { wxSizer *opt_sizer; void OnProcess(wxCommandEvent &); - void OnMoveUp(wxCommandEvent &); - void OnMoveDown(wxCommandEvent &); - void OnSelectAll(wxCommandEvent &); - void OnSelectNone(wxCommandEvent &); - void OnCheck(wxCommandEvent &); void OnChange(wxCommandEvent &); /// Set all the checkboxes diff --git a/aegisub/src/dialog_selected_choices.cpp b/aegisub/src/dialog_selected_choices.cpp index ffa697548..969d76fd0 100644 --- a/aegisub/src/dialog_selected_choices.cpp +++ b/aegisub/src/dialog_selected_choices.cpp @@ -32,7 +32,7 @@ SelectedChoicesDialog::SelectedChoicesDialog(wxWindow *parent, wxString const& m wxButton *selAll = new wxButton(this, -1, _("Select &All")); wxButton *selNone = new wxButton(this, -1, _("Select &None")); selAll->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SelectedChoicesDialog::SelectAll, this); - selNone->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SelectedChoicesDialog::SelectNone, this); + selNone->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { SetSelections(wxArrayInt()); }); wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); buttonSizer->Add(selAll, wxSizerFlags(0).Left()); @@ -50,10 +50,6 @@ void SelectedChoicesDialog::SelectAll(wxCommandEvent&) { SetSelections(sel); } -void SelectedChoicesDialog::SelectNone(wxCommandEvent&) { - SetSelections(wxArrayInt()); -} - int GetSelectedChoices(wxWindow *parent, wxArrayInt& selections, wxString const& message, wxString const& caption, wxArrayString const& choices) { SelectedChoicesDialog dialog(parent, message, caption, choices); dialog.SetSelections(selections); diff --git a/aegisub/src/dialog_selected_choices.h b/aegisub/src/dialog_selected_choices.h index c2767d445..6bb869a0f 100644 --- a/aegisub/src/dialog_selected_choices.h +++ b/aegisub/src/dialog_selected_choices.h @@ -31,7 +31,6 @@ class SelectedChoicesDialog : public wxMultiChoiceDialog { SelectedChoicesDialog& operator=(SelectedChoicesDialog const&); void SelectAll(wxCommandEvent&); - void SelectNone(wxCommandEvent&); public: SelectedChoicesDialog(wxWindow *parent, wxString const& message, wxString const& caption, wxArrayString const& choices); diff --git a/aegisub/src/dialog_spellchecker.cpp b/aegisub/src/dialog_spellchecker.cpp index 92bf60656..20145ea3e 100644 --- a/aegisub/src/dialog_spellchecker.cpp +++ b/aegisub/src/dialog_spellchecker.cpp @@ -135,7 +135,7 @@ DialogSpellChecker::DialogSpellChecker(agi::Context *context) button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnReplaceAll, this); actions_sizer->Add(button = new wxButton(this, -1, _("&Ignore")), button_flags); - button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnIgnore, this); + button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { FindNext(); }); actions_sizer->Add(button = new wxButton(this, -1, _("Ignore a&ll")), button_flags); button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnIgnoreAll, this); @@ -170,10 +170,6 @@ void DialogSpellChecker::OnReplaceAll(wxCommandEvent&) { FindNext(); } -void DialogSpellChecker::OnIgnore(wxCommandEvent&) { - FindNext(); -} - void DialogSpellChecker::OnIgnoreAll(wxCommandEvent&) { auto_ignore.insert(from_wx(orig_word->GetValue())); FindNext(); diff --git a/aegisub/src/dialog_spellchecker.h b/aegisub/src/dialog_spellchecker.h index c14a94903..a5b6131d1 100644 --- a/aegisub/src/dialog_spellchecker.h +++ b/aegisub/src/dialog_spellchecker.h @@ -85,7 +85,6 @@ class DialogSpellChecker : public wxDialog { void OnReplace(wxCommandEvent&); void OnReplaceAll(wxCommandEvent&); - void OnIgnore(wxCommandEvent&); void OnIgnoreAll(wxCommandEvent&); void OnAdd(wxCommandEvent&); diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index 31b261f47..c03f4fc16 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -91,10 +91,7 @@ class Interface_Hotkeys : public OptionPage { wxSearchCtrl *quick_search; void OnNewButton(wxCommandEvent&); - void OnEditButton(wxCommandEvent&); - void OnDeleteButton(wxCommandEvent&); void OnUpdateFilter(wxCommandEvent&); - void OnClearFilter(wxCommandEvent&); public: Interface_Hotkeys(wxTreebook *book, Preferences *parent); }; @@ -376,6 +373,14 @@ public: bool HasEditorCtrl() const { return true; } }; +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 +} + /// Interface Hotkeys preferences subpage Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent) : OptionPage(book, parent, _("Hotkeys"), PAGE_SUB) @@ -387,11 +392,11 @@ Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent) wxButton *delete_button = new wxButton(this, -1, _("&Delete")); new_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnNewButton, this); - edit_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnEditButton, this); - delete_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnDeleteButton, this); + edit_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { edit_item(dvc, dvc->GetSelection()); }); + delete_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { model->Delete(dvc->GetSelection()); }); quick_search->Bind(wxEVT_COMMAND_TEXT_UPDATED, &Interface_Hotkeys::OnUpdateFilter, this); - quick_search->Bind(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, &Interface_Hotkeys::OnClearFilter, this); + quick_search->Bind(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, [=](wxCommandEvent&) { quick_search->SetValue(""); }); dvc = new wxDataViewCtrl(this, -1); dvc->AssociateModel(model.get()); @@ -412,14 +417,6 @@ Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent) 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&) { wxDataViewItem sel = dvc->GetSelection(); dvc->ExpandAncestors(sel); @@ -433,14 +430,6 @@ void Interface_Hotkeys::OnNewButton(wxCommandEvent&) { } } -void Interface_Hotkeys::OnEditButton(wxCommandEvent&) { - edit_item(dvc, dvc->GetSelection()); -} - -void Interface_Hotkeys::OnDeleteButton(wxCommandEvent&) { - model->Delete(dvc->GetSelection()); -} - void Interface_Hotkeys::OnUpdateFilter(wxCommandEvent&) { model->SetFilter(quick_search->GetValue()); @@ -452,10 +441,6 @@ void Interface_Hotkeys::OnUpdateFilter(wxCommandEvent&) { } } -void Interface_Hotkeys::OnClearFilter(wxCommandEvent &) { - quick_search->SetValue(""); -} - /// Backup preferences page Backup::Backup(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Backup")) { wxFlexGridSizer *save = PageSizer(_("Automatic Save")); diff --git a/aegisub/src/visual_tool_vector_clip.cpp b/aegisub/src/visual_tool_vector_clip.cpp index 10af01afa..29cb2d800 100644 --- a/aegisub/src/visual_tool_vector_clip.cpp +++ b/aegisub/src/visual_tool_vector_clip.cpp @@ -74,15 +74,11 @@ void VisualToolVectorClip::SetToolbar(wxToolBar *toolBar) { toolBar->ToggleTool(BUTTON_DRAG, true); toolBar->Realize(); toolBar->Show(true); - toolBar->Bind(wxEVT_COMMAND_TOOL_CLICKED, &VisualToolVectorClip::OnSubTool, this); + toolBar->Bind(wxEVT_COMMAND_TOOL_CLICKED, [=](wxCommandEvent& e) { SetMode(e.GetId() - BUTTON_DRAG); }); SetMode(features.empty()); #undef ICON } -void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) { - SetMode(event.GetId() - BUTTON_DRAG); -} - void VisualToolVectorClip::SetMode(int new_mode) { // Manually enforce radio behavior as we want one selection in the bar // rather than one per group diff --git a/aegisub/src/visual_tool_vector_clip.h b/aegisub/src/visual_tool_vector_clip.h index 22e160660..b3c232d06 100644 --- a/aegisub/src/visual_tool_vector_clip.h +++ b/aegisub/src/visual_tool_vector_clip.h @@ -67,7 +67,4 @@ class VisualToolVectorClip : public VisualTool