Use lambdas for very short event handlers

This commit is contained in:
Thomas Goyne 2012-12-02 13:29:46 -08:00
parent 004b032a54
commit de4ef14598
9 changed files with 35 additions and 91 deletions

View File

@ -50,6 +50,22 @@
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "subtitle_format.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) DialogExport::DialogExport(agi::Context *c)
: wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX) : wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
, c(c) , c(c)
@ -60,7 +76,7 @@ DialogExport::DialogExport(agi::Context *c)
wxArrayString filters = exporter->GetAllFilterNames(); wxArrayString filters = exporter->GetAllFilterNames();
filter_list = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(200, 100), filters); 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); filter_list->Bind(wxEVT_COMMAND_LISTBOX_SELECTED, &DialogExport::OnChange, this);
// Get selected filters // 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_all = new wxButton(this, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1));
wxButton *btn_none = new wxButton(this, -1, _("Select &None"), 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_up->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
btn_down->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnMoveDown, this); btn_down->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
btn_all->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnSelectAll, this); btn_all->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { SetAll(true); });
btn_none->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogExport::OnSelectNone, this); btn_none->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { SetAll(true); });
wxSizer *top_buttons = new wxBoxSizer(wxHORIZONTAL); wxSizer *top_buttons = new wxBoxSizer(wxHORIZONTAL);
top_buttons->Add(btn_up, wxSizerFlags(1).Expand()); top_buttons->Add(btn_up, wxSizerFlags(1).Expand());
@ -171,10 +187,6 @@ void DialogExport::OnProcess(wxCommandEvent &) {
EndModal(0); EndModal(0);
} }
void DialogExport::OnCheck(wxCommandEvent &) {
RefreshOptions();
}
void DialogExport::OnChange(wxCommandEvent &) { void DialogExport::OnChange(wxCommandEvent &) {
int n = filter_list->GetSelection(); int n = filter_list->GetSelection();
if (n != wxNOT_FOUND) { 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) { void DialogExport::SetAll(bool new_value) {
filter_list->Freeze(); filter_list->Freeze();
for (size_t i = 0; i < filter_list->GetCount(); ++i) for (size_t i = 0; i < filter_list->GetCount(); ++i)

View File

@ -65,11 +65,6 @@ class DialogExport : public wxDialog {
wxSizer *opt_sizer; wxSizer *opt_sizer;
void OnProcess(wxCommandEvent &); void OnProcess(wxCommandEvent &);
void OnMoveUp(wxCommandEvent &);
void OnMoveDown(wxCommandEvent &);
void OnSelectAll(wxCommandEvent &);
void OnSelectNone(wxCommandEvent &);
void OnCheck(wxCommandEvent &);
void OnChange(wxCommandEvent &); void OnChange(wxCommandEvent &);
/// Set all the checkboxes /// Set all the checkboxes

View File

@ -32,7 +32,7 @@ SelectedChoicesDialog::SelectedChoicesDialog(wxWindow *parent, wxString const& m
wxButton *selAll = new wxButton(this, -1, _("Select &All")); wxButton *selAll = new wxButton(this, -1, _("Select &All"));
wxButton *selNone = new wxButton(this, -1, _("Select &None")); wxButton *selNone = new wxButton(this, -1, _("Select &None"));
selAll->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SelectedChoicesDialog::SelectAll, this); 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); wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->Add(selAll, wxSizerFlags(0).Left()); buttonSizer->Add(selAll, wxSizerFlags(0).Left());
@ -50,10 +50,6 @@ void SelectedChoicesDialog::SelectAll(wxCommandEvent&) {
SetSelections(sel); SetSelections(sel);
} }
void SelectedChoicesDialog::SelectNone(wxCommandEvent&) {
SetSelections(wxArrayInt());
}
int GetSelectedChoices(wxWindow *parent, wxArrayInt& selections, wxString const& message, wxString const& caption, wxArrayString const& choices) { int GetSelectedChoices(wxWindow *parent, wxArrayInt& selections, wxString const& message, wxString const& caption, wxArrayString const& choices) {
SelectedChoicesDialog dialog(parent, message, caption, choices); SelectedChoicesDialog dialog(parent, message, caption, choices);
dialog.SetSelections(selections); dialog.SetSelections(selections);

View File

@ -31,7 +31,6 @@ class SelectedChoicesDialog : public wxMultiChoiceDialog {
SelectedChoicesDialog& operator=(SelectedChoicesDialog const&); SelectedChoicesDialog& operator=(SelectedChoicesDialog const&);
void SelectAll(wxCommandEvent&); void SelectAll(wxCommandEvent&);
void SelectNone(wxCommandEvent&);
public: public:
SelectedChoicesDialog(wxWindow *parent, wxString const& message, wxString const& caption, wxArrayString const& choices); SelectedChoicesDialog(wxWindow *parent, wxString const& message, wxString const& caption, wxArrayString const& choices);

View File

@ -135,7 +135,7 @@ DialogSpellChecker::DialogSpellChecker(agi::Context *context)
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnReplaceAll, this); button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnReplaceAll, this);
actions_sizer->Add(button = new wxButton(this, -1, _("&Ignore")), button_flags); 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); actions_sizer->Add(button = new wxButton(this, -1, _("Ignore a&ll")), button_flags);
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnIgnoreAll, this); button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnIgnoreAll, this);
@ -170,10 +170,6 @@ void DialogSpellChecker::OnReplaceAll(wxCommandEvent&) {
FindNext(); FindNext();
} }
void DialogSpellChecker::OnIgnore(wxCommandEvent&) {
FindNext();
}
void DialogSpellChecker::OnIgnoreAll(wxCommandEvent&) { void DialogSpellChecker::OnIgnoreAll(wxCommandEvent&) {
auto_ignore.insert(from_wx(orig_word->GetValue())); auto_ignore.insert(from_wx(orig_word->GetValue()));
FindNext(); FindNext();

View File

@ -85,7 +85,6 @@ class DialogSpellChecker : public wxDialog {
void OnReplace(wxCommandEvent&); void OnReplace(wxCommandEvent&);
void OnReplaceAll(wxCommandEvent&); void OnReplaceAll(wxCommandEvent&);
void OnIgnore(wxCommandEvent&);
void OnIgnoreAll(wxCommandEvent&); void OnIgnoreAll(wxCommandEvent&);
void OnAdd(wxCommandEvent&); void OnAdd(wxCommandEvent&);

View File

@ -91,10 +91,7 @@ class Interface_Hotkeys : public OptionPage {
wxSearchCtrl *quick_search; wxSearchCtrl *quick_search;
void OnNewButton(wxCommandEvent&); void OnNewButton(wxCommandEvent&);
void OnEditButton(wxCommandEvent&);
void OnDeleteButton(wxCommandEvent&);
void OnUpdateFilter(wxCommandEvent&); void OnUpdateFilter(wxCommandEvent&);
void OnClearFilter(wxCommandEvent&);
public: public:
Interface_Hotkeys(wxTreebook *book, Preferences *parent); Interface_Hotkeys(wxTreebook *book, Preferences *parent);
}; };
@ -376,6 +373,14 @@ public:
bool HasEditorCtrl() const { return true; } 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 preferences subpage
Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent) Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent)
: OptionPage(book, parent, _("Hotkeys"), PAGE_SUB) : 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")); wxButton *delete_button = new wxButton(this, -1, _("&Delete"));
new_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnNewButton, this); new_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnNewButton, this);
edit_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnEditButton, this); edit_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { edit_item(dvc, dvc->GetSelection()); });
delete_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Interface_Hotkeys::OnDeleteButton, this); 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_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 = new wxDataViewCtrl(this, -1);
dvc->AssociateModel(model.get()); dvc->AssociateModel(model.get());
@ -412,14 +417,6 @@ 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&) {
wxDataViewItem sel = dvc->GetSelection(); wxDataViewItem sel = dvc->GetSelection();
dvc->ExpandAncestors(sel); 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&) { void Interface_Hotkeys::OnUpdateFilter(wxCommandEvent&) {
model->SetFilter(quick_search->GetValue()); 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 preferences page
Backup::Backup(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Backup")) { Backup::Backup(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Backup")) {
wxFlexGridSizer *save = PageSizer(_("Automatic Save")); wxFlexGridSizer *save = PageSizer(_("Automatic Save"));

View File

@ -74,15 +74,11 @@ void VisualToolVectorClip::SetToolbar(wxToolBar *toolBar) {
toolBar->ToggleTool(BUTTON_DRAG, true); toolBar->ToggleTool(BUTTON_DRAG, true);
toolBar->Realize(); toolBar->Realize();
toolBar->Show(true); 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()); SetMode(features.empty());
#undef ICON #undef ICON
} }
void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) {
SetMode(event.GetId() - BUTTON_DRAG);
}
void VisualToolVectorClip::SetMode(int new_mode) { void VisualToolVectorClip::SetMode(int new_mode) {
// Manually enforce radio behavior as we want one selection in the bar // Manually enforce radio behavior as we want one selection in the bar
// rather than one per group // rather than one per group

View File

@ -67,7 +67,4 @@ class VisualToolVectorClip : public VisualTool<VisualToolVectorClipDraggableFeat
public: public:
VisualToolVectorClip(VideoDisplay *parent, agi::Context *context); VisualToolVectorClip(VideoDisplay *parent, agi::Context *context);
void SetToolbar(wxToolBar *tb); void SetToolbar(wxToolBar *tb);
/// Subtoolbar button click handler
void OnSubTool(wxCommandEvent &event);
}; };