From ac3f6735f6a57efe77da7e5afd3b0188915d79ff Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 13 Jun 2021 14:39:24 +0200 Subject: [PATCH] feat(modulo): improve wizard main buttons --- espanso-modulo/src/sys/wizard/wizard.cpp | 36 ++++++++++++++++++-- espanso-modulo/src/sys/wizard/wizard.fbp | 1 + espanso-modulo/src/sys/wizard/wizard_gui.cpp | 2 ++ espanso-modulo/src/sys/wizard/wizard_gui.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/espanso-modulo/src/sys/wizard/wizard.cpp b/espanso-modulo/src/sys/wizard/wizard.cpp index 262d577..22b4be0 100644 --- a/espanso-modulo/src/sys/wizard/wizard.cpp +++ b/espanso-modulo/src/sys/wizard/wizard.cpp @@ -85,6 +85,7 @@ class DerivedFrame : public WizardFrame { protected: void check_timer_tick( wxTimerEvent& event ); + void on_page_changed( wxBookCtrlEvent& event ); void welcome_start_clicked(wxCommandEvent &event); void navigate_to_next_page_or_close(); @@ -102,7 +103,7 @@ DerivedFrame::DerivedFrame(wxWindow *parent) // Load the first page int page = find_next_page(-1); if (page >= 0) { - this->m_simplebook->ChangeSelection(page); + this->m_simplebook->SetSelection(page); } else { Close(true); } @@ -112,7 +113,7 @@ void DerivedFrame::navigate_to_next_page_or_close() { int current_page = this->m_simplebook->GetSelection(); int page = find_next_page(current_page); if (page >= 0) { - this->m_simplebook->ChangeSelection(page); + this->m_simplebook->SetSelection(page); } else { Close(true); } @@ -133,6 +134,37 @@ void DerivedFrame::check_timer_tick( wxTimerEvent& event ) { } } +void DerivedFrame::on_page_changed( wxBookCtrlEvent& event ) { + int current_page = this->m_simplebook->GetSelection(); + switch (current_page) { + case WELCOME_PAGE_INDEX: + { + this->welcome_start_button->SetDefault(); + break; + } + case MOVE_BUNDLE_PAGE_INDEX: + { + this->move_bundle_quit_button->SetDefault(); + break; + } + case MIGRATE_PAGE_INDEX: + { + this->migrate_backup_and_migrate_button->SetDefault(); + break; + } + case ADD_PATH_PAGE_INDEX: + { + this->add_path_continue_button->SetDefault(); + break; + } + case ACCESSIBILITY_PAGE_INDEX: + { + this->accessibility_enable_button->SetDefault(); + break; + } + } +} + bool WizardApp::OnInit() { diff --git a/espanso-modulo/src/sys/wizard/wizard.fbp b/espanso-modulo/src/sys/wizard/wizard.fbp index 2a30de9..85d65be 100644 --- a/espanso-modulo/src/sys/wizard/wizard.fbp +++ b/espanso-modulo/src/sys/wizard/wizard.fbp @@ -123,6 +123,7 @@ + on_page_changed a page 0 diff --git a/espanso-modulo/src/sys/wizard/wizard_gui.cpp b/espanso-modulo/src/sys/wizard/wizard_gui.cpp index 3a16b57..de40940 100644 --- a/espanso-modulo/src/sys/wizard/wizard_gui.cpp +++ b/espanso-modulo/src/sys/wizard/wizard_gui.cpp @@ -276,6 +276,7 @@ WizardFrame::WizardFrame( wxWindow* parent, wxWindowID id, const wxString& title // Connect Events this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( WizardFrame::check_timer_tick ) ); + m_simplebook->Connect( wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED, wxBookCtrlEventHandler( WizardFrame::on_page_changed ), NULL, this ); welcome_start_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::welcome_start_clicked ), NULL, this ); move_bundle_quit_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::move_bundle_quit_clicked ), NULL, this ); migrate_compatibility_mode_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::migrate_compatibility_mode_clicked ), NULL, this ); @@ -288,6 +289,7 @@ WizardFrame::~WizardFrame() { // Disconnect Events this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( WizardFrame::check_timer_tick ) ); + m_simplebook->Disconnect( wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED, wxBookCtrlEventHandler( WizardFrame::on_page_changed ), NULL, this ); welcome_start_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::welcome_start_clicked ), NULL, this ); move_bundle_quit_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::move_bundle_quit_clicked ), NULL, this ); migrate_compatibility_mode_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WizardFrame::migrate_compatibility_mode_clicked ), NULL, this ); diff --git a/espanso-modulo/src/sys/wizard/wizard_gui.h b/espanso-modulo/src/sys/wizard/wizard_gui.h index 5a88b58..c05f850 100644 --- a/espanso-modulo/src/sys/wizard/wizard_gui.h +++ b/espanso-modulo/src/sys/wizard/wizard_gui.h @@ -79,6 +79,7 @@ class WizardFrame : public wxFrame // Virtual event handlers, overide them in your derived class virtual void check_timer_tick( wxTimerEvent& event ) { event.Skip(); } + virtual void on_page_changed( wxBookCtrlEvent& event ) { event.Skip(); } virtual void welcome_start_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void move_bundle_quit_clicked( wxCommandEvent& event ) { event.Skip(); } virtual void migrate_compatibility_mode_clicked( wxCommandEvent& event ) { event.Skip(); }