From 4cad021ef41a34a5291102dbeea588c86451eab4 Mon Sep 17 00:00:00 2001 From: Josue Huaroto Date: Thu, 13 Jul 2023 14:10:31 +0000 Subject: [PATCH] Add Open preferences folder button in Preferences Dialog --- common/eda_base_frame.cpp | 2 +- common/widgets/paged_dialog.cpp | 29 ++++++++++++++++++++- eeschema/dialogs/dialog_schematic_setup.cpp | 2 +- include/widgets/paged_dialog.h | 4 ++- pcbnew/dialogs/dialog_board_setup.cpp | 2 +- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index a2c0540abe..9603e4efb9 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -1059,7 +1059,7 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent { wxBeginBusyCursor( wxHOURGLASS_CURSOR ); - PAGED_DIALOG dlg( this, _( "Preferences" ), true, wxEmptyString, wxSize( 980, 560 ) ); + PAGED_DIALOG dlg( this, _( "Preferences" ), true, true, wxEmptyString, wxSize( 980, 560 ) ); dlg.SetEvtHandlerEnabled( false ); diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index cfa262b5cf..003a06f0d3 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -32,6 +32,10 @@ #include #include +#include + +#include + #include // Maps from dialogTitle <-> pageTitle for keeping track of last-selected pages. @@ -40,7 +44,7 @@ std::map g_lastPage; std::map g_lastParentPage; -PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aShowReset, +PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aShowReset, bool aShowOpenFolder, const wxString& aAuxiliaryAction, const wxSize& aInitialSize ) : DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, aInitialSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ), @@ -80,6 +84,13 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aSho m_buttonsSizer->Add( m_resetButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); } + if( aShowOpenFolder ) + { + m_openPreferencesButton = new wxButton( this, wxID_ANY, _( "Open preferences folder" ) ); + m_buttonsSizer->Add( m_openPreferencesButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT, 5 ); + } + + if( !aAuxiliaryAction.IsEmpty() ) { m_auxiliaryButton = new wxButton( this, wxID_ANY, aAuxiliaryAction ); @@ -116,6 +127,11 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aSho m_resetButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onResetButton, this ); } + if( m_openPreferencesButton ) + { + m_openPreferencesButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onOpenPreferencesButton, this ); + } + m_treebook->Bind( wxEVT_CHAR_HOOK, &PAGED_DIALOG::onCharHook, this ); m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::onPageChanged, this ); m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::onPageChanging, this ); @@ -183,6 +199,11 @@ PAGED_DIALOG::~PAGED_DIALOG() m_resetButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onResetButton, this ); } + if( m_openPreferencesButton ) + { + m_openPreferencesButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::onOpenPreferencesButton, this ); + } + m_treebook->Unbind( wxEVT_CHAR_HOOK, &PAGED_DIALOG::onCharHook, this ); m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::onPageChanged, this ); m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::onPageChanging, this ); @@ -479,3 +500,9 @@ void PAGED_DIALOG::onResetButton( wxCommandEvent& aEvent ) panel->ProcessWindowEvent( resetCommand ); } } + +void PAGED_DIALOG::onOpenPreferencesButton( wxCommandEvent& aEvent ) +{ + wxString dir( SETTINGS_MANAGER::GetUserSettingsPath() ); + LaunchExternal( dir ); +} diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 5680ac6ebc..0a72eb2d69 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -37,7 +37,7 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : - PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, + PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, false, _( "Import Settings from Another Project..." ), wxSize( 920, 460 ) ), m_frame( aFrame ) { diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index 005d380594..925d42c1c2 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -31,7 +31,7 @@ class WX_TREEBOOK; class PAGED_DIALOG : public DIALOG_SHIM { public: - PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aShowReset, + PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aShowReset, bool aShowOpenFolder, const wxString& aAuxiliaryAction = wxEmptyString, const wxSize& aInitialSize = wxDefaultSize ); ~PAGED_DIALOG() override; @@ -60,6 +60,7 @@ protected: virtual void onAuxiliaryAction( wxCommandEvent& aEvent ) { aEvent.Skip(); } virtual void onResetButton( wxCommandEvent& aEvent ); + virtual void onOpenPreferencesButton( wxCommandEvent& aEvent ); virtual void onPageChanged( wxBookCtrlEvent& aEvent ); virtual void onPageChanging( wxBookCtrlEvent& aEvent ); virtual void onCharHook( wxKeyEvent& aEvent ); @@ -67,6 +68,7 @@ protected: WX_TREEBOOK* m_treebook; wxButton* m_auxiliaryButton; wxButton* m_resetButton; + wxButton* m_openPreferencesButton; wxButton* m_cancelButton; WX_INFOBAR* m_infoBar; diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index 5573c952ad..b9c6fd4841 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -51,7 +51,7 @@ std::mutex DIALOG_BOARD_SETUP::g_Mutex; #define RESOLVE_PAGE( T, pageIndex ) static_cast( m_treebook->ResolvePage( pageIndex ) ) DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : - PAGED_DIALOG( aFrame, _( "Board Setup" ), false, + PAGED_DIALOG( aFrame, _( "Board Setup" ), false, false, _( "Import Settings from Another Board..." ), wxSize( 980, 600 ) ), m_frame( aFrame ), m_layers( nullptr ),