diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index ee4e925fb5..6e266d43a6 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -35,6 +35,48 @@ std::map g_lastPage; std::map g_lastParentPage; +PAGED_TREEBOOK::PAGED_TREEBOOK( wxWindow* parent, wxWindowID id, const wxPoint& pos, + const wxSize& size, long style, const wxString& name ) + : wxTreebook( parent, id, pos, size, style, name ) +{ + GetTreeCtrl()->Bind( wxEVT_TREE_SEL_CHANGING, &PAGED_TREEBOOK::OnTreeSelChanging, this ); +} + + +void PAGED_TREEBOOK::OnTreeSelChanging( wxTreeEvent& aEvent ) +{ + wxTreeItemId pageId = aEvent.GetItem(); + + for( size_t i = 0; i < m_groupEntries.size(); ++i ) + { + if( m_groupEntries[i] == pageId ) + { + aEvent.Veto(); + + wxTreeItemIdValue cookie; + wxTreeItemId firstSubPage = GetTreeCtrl()->GetFirstChild( pageId, cookie ); + + if( firstSubPage.IsOk() ) + { + GetTreeCtrl()->SelectItem( firstSubPage, true ); + } + break; + } + } +} + + +bool PAGED_TREEBOOK::AddGroupEntry( const wxString& text, int imageId ) +{ + bool add = AddPage( new wxPanel(this), text, false, imageId ); + + wxTreeItemId newId = m_treeIds.back(); + m_groupEntries.push_back(newId); + + return add; +} + + PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aUseReset, const wxString& aAuxiliaryAction ) : DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize, @@ -49,7 +91,7 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aUse auto mainSizer = new wxBoxSizer( wxVERTICAL ); SetSizer( mainSizer ); - m_treebook = new wxTreebook( this, wxID_ANY ); + m_treebook = new PAGED_TREEBOOK( this, wxID_ANY ); mainSizer->Add( m_treebook, 1, wxEXPAND|wxLEFT|wxTOP, 10 ); auto line = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 7f45c8f03e..06acf79abe 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -62,15 +62,15 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog(). */ - m_treebook->AddPage( new wxPanel( this ), _( "General" ) ); + m_treebook->AddGroupEntry( _( "General" ) ); m_treebook->AddSubPage( m_formatting, _( "Formatting" ) ); m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) ); - m_treebook->AddPage( new wxPanel( this ), _( "Electrical Rules" ) ); + m_treebook->AddGroupEntry( _( "Electrical Rules" ) ); m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) ); m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) ); - m_treebook->AddPage( new wxPanel( this ), _( "Project" ) ); + m_treebook->AddGroupEntry( _( "Project" ) ); m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) ); m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index c3e0693c28..5aa876f8b5 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -219,9 +219,9 @@ COLOR4D GetInvisibleItemColor() void SCH_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) { - wxTreebook* book = aParent->GetTreebook(); + PAGED_TREEBOOK* book = aParent->GetTreebook(); - book->AddPage( new wxPanel( book ), _( "Eeschema" ) ); + book->AddGroupEntry( _( "Eeschema" ) ); book->AddSubPage( new PANEL_EESCHEMA_DISPLAY_OPTIONS( this, book ), _( "Display Options" ) ); book->AddSubPage( new PANEL_EESCHEMA_SETTINGS( this, book ), _( "Editing Options" ) ); book->AddSubPage( new PANEL_EESCHEMA_COLOR_SETTINGS( this, book ), _( "Colors" ) ); @@ -425,9 +425,9 @@ void SCH_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) void LIB_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) { - wxTreebook* book = aParent->GetTreebook(); + PAGED_TREEBOOK* book = aParent->GetTreebook(); - book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) ); + book->AddGroupEntry( _( "Symbol Editor" ) ); book->AddSubPage( new PANEL_GAL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) ); book->AddSubPage( new PANEL_LIBEDIT_SETTINGS( this, book ), _( "Editing Options" ) ); book->AddSubPage( new PANEL_LIBEDIT_COLOR_SETTINGS( this, book ), _( "Colors" ) ); diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index f1c4e3e846..68a7190740 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -1137,9 +1137,9 @@ void GERBVIEW_FRAME::ActivateGalCanvas() void GERBVIEW_FRAME::InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) { - wxTreebook* book = aParent->GetTreebook(); + PAGED_TREEBOOK* book = aParent->GetTreebook(); - book->AddPage( new wxPanel( book ), _( "Gerbview" ) ); + book->AddGroupEntry( _( "Gerbview" ) ); book->AddSubPage( new PANEL_GERBVIEW_DISPLAY_OPTIONS( this, book ), _( "Display Options" ) ); book->AddSubPage( new PANEL_GERBVIEW_SETTINGS( this, book ), _( "Editing Options" ) ); diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index 0d5e732a71..c9c419ea73 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -25,6 +25,22 @@ #include +class PAGED_TREEBOOK : public wxTreebook +{ +public: + PAGED_TREEBOOK( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = wxBK_DEFAULT, + const wxString& name = wxEmptyString ); + + bool AddGroupEntry( const wxString& text, int imageId = NO_IMAGE ); + +protected: + void OnTreeSelChanging( wxTreeEvent& aEvent ); + + wxVector m_groupEntries; +}; + + class PAGED_DIALOG : public DIALOG_SHIM { private: @@ -42,7 +58,7 @@ public: const wxString& aAuxiliaryAction = wxEmptyString ); ~PAGED_DIALOG() override; - wxTreebook* GetTreebook() { return m_treebook; } + PAGED_TREEBOOK* GetTreebook() { return m_treebook; } void SetInitialPage( const wxString& aPage, const wxString& aParentPage = wxEmptyString ); @@ -62,8 +78,9 @@ protected: void OnResetButton( wxCommandEvent& aEvent ); void OnUpdateUI( wxUpdateUIEvent& event ); void OnPageChange( wxBookCtrlEvent& event ); + void OnPageChanging( wxBookCtrlEvent& aEvent ); - wxTreebook* m_treebook; + PAGED_TREEBOOK* m_treebook; wxButton* m_auxiliaryButton; wxButton* m_resetButton; }; diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index 39635f497f..077b0ea232 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -67,23 +67,23 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog(). */ - m_treebook->AddPage( new wxPanel( this ), _( "Board Stackup" ) ); + m_treebook->AddGroupEntry( _( "Board Stackup" ) ); m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) ); m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) ); // Change this value if m_physicalStackup is not the page 2 of m_treebook m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel - m_treebook->AddPage( new wxPanel( this ), _( "Defaults" ) ); + m_treebook->AddGroupEntry( _( "Defaults" ) ); m_treebook->AddSubPage( m_textAndGraphics, _( "Text & Graphics" ) ); m_treebook->AddSubPage( m_tracksAndVias, _( "Tracks & Vias" ) ); m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) ); - m_treebook->AddPage( new wxPanel( this ), _( "Design Rules" ) ); + m_treebook->AddGroupEntry( _( "Design Rules" ) ); m_treebook->AddSubPage( m_constraints, _( "Constraints" ) ); m_treebook->AddSubPage( m_rules, _( "Rules" ) ); m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) ); - m_treebook->AddPage( new wxPanel( this ), _( "Project" ) ); + m_treebook->AddGroupEntry( _( "Project" ) ); m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) ); m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) ); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 8ee69cedc5..e4519b895c 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -824,9 +824,9 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateLayerAlpha( wxUpdateUIEvent & ) void FOOTPRINT_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) { - wxTreebook* book = aParent->GetTreebook(); + PAGED_TREEBOOK* book = aParent->GetTreebook(); - book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) ); + book->AddGroupEntry( _( "Footprint Editor" ) ); book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) ); book->AddSubPage( new PANEL_MODEDIT_COLOR_SETTINGS( this, book ), _( "Colors" ) ); book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) ); diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 3f64575787..bb6c9df5f4 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -66,9 +66,9 @@ void PCB_EDIT_FRAME::On3DShapeLibWizard( wxCommandEvent& event ) void PCB_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) { - wxTreebook* book = aParent->GetTreebook(); + PAGED_TREEBOOK* book = aParent->GetTreebook(); - book->AddPage( new wxPanel( book ), _( "Pcbnew" ) ); + book->AddGroupEntry( _( "Pcbnew" ) ); book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) ); book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) ); book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );