From 85810510f43ebfc65330ab703bc12c557413435a Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 27 Feb 2025 02:51:29 +0000 Subject: [PATCH] Tweak toolbar settings a bit * Manage the settings using the settings manager for better lifetimes * Better architect the internals and JSON to make it easier to identify the various tool types --- 3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp | 2 +- 3d-viewer/3d_viewer/toolbars_3d.h | 2 +- common/advanced_config.cpp | 4 +- .../dialogs/panel_toolbar_customization.cpp | 130 ++++++++--------- common/eda_base_frame.cpp | 21 ++- common/settings/settings_manager.cpp | 3 + common/tool/action_toolbar.cpp | 64 ++++----- common/tool/ui/toolbar_configuration.cpp | 135 +++++++++++------- cvpcb/cvpcb_mainframe.cpp | 3 +- cvpcb/display_footprints_frame.cpp | 2 +- cvpcb/toolbars_cvpcb.h | 2 +- cvpcb/toolbars_display_footprints.h | 2 +- eeschema/eeschema.cpp | 22 ++- eeschema/sch_edit_frame.cpp | 2 +- eeschema/sim/simulator_frame.cpp | 3 +- eeschema/sim/toolbars_simulator_frame.h | 2 +- eeschema/symbol_editor/symbol_edit_frame.cpp | 2 +- .../symbol_editor/toolbars_symbol_editor.h | 2 +- eeschema/symbol_viewer_frame.cpp | 2 +- eeschema/toolbars_sch_editor.h | 2 +- eeschema/toolbars_symbol_viewer.h | 2 +- gerbview/gerbview.cpp | 21 +++ gerbview/gerbview_frame.cpp | 2 +- gerbview/toolbars_gerber.h | 2 +- include/eda_base_frame.h | 4 +- include/settings/json_settings.h | 1 + include/settings/settings_manager.h | 45 ++++++ include/tool/ui/toolbar_configuration.h | 104 ++++++++++---- kicad/kicad_manager_frame.cpp | 2 +- kicad/toolbars_kicad_manager.h | 2 +- pagelayout_editor/pl_editor.cpp | 21 +++ pagelayout_editor/pl_editor_frame.cpp | 2 +- pagelayout_editor/toolbars_pl_editor.h | 2 +- pcbnew/footprint_edit_frame.cpp | 2 +- pcbnew/footprint_viewer_frame.cpp | 2 +- pcbnew/footprint_wizard_frame.cpp | 2 +- pcbnew/pcb_edit_frame.cpp | 2 +- pcbnew/pcbnew.cpp | 43 +++++- pcbnew/toolbars_footprint_editor.cpp | 2 +- pcbnew/toolbars_footprint_editor.h | 2 +- pcbnew/toolbars_footprint_viewer.h | 2 +- pcbnew/toolbars_footprint_wizard.h | 2 +- pcbnew/toolbars_pcb_editor.cpp | 27 +--- pcbnew/toolbars_pcb_editor.h | 2 +- 44 files changed, 463 insertions(+), 242 deletions(-) diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp index 17ebe8e952..79566a957f 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp @@ -149,7 +149,7 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent ReCreateMenuBar(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "3d_viewer-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/3d-viewer/3d_viewer/toolbars_3d.h b/3d-viewer/3d_viewer/toolbars_3d.h index 6bb568b65d..ec7e19f0b5 100644 --- a/3d-viewer/3d_viewer/toolbars_3d.h +++ b/3d-viewer/3d_viewer/toolbars_3d.h @@ -29,7 +29,7 @@ class EDA_3D_VIEWER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: EDA_3D_VIEWER_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "3d_viewer" ) + TOOLBAR_SETTINGS( "3d_viewer-toolbars" ) {} ~EDA_3D_VIEWER_TOOLBAR_SETTINGS() {} diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index a44d0f68d8..0b267de866 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -603,8 +603,8 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) m_GitProjectStatusRefreshInterval, 0, 100000 ) ); configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ConfigurableToolbars, - &m_ConfigurableToolbars, - m_ConfigurableToolbars ) ); + &m_ConfigurableToolbars, + m_ConfigurableToolbars ) ); // Special case for trace mask setting...we just grab them and set them immediately // Because we even use wxLogTrace inside of advanced config diff --git a/common/dialogs/panel_toolbar_customization.cpp b/common/dialogs/panel_toolbar_customization.cpp index e5c6f5b880..772b04f865 100644 --- a/common/dialogs/panel_toolbar_customization.cpp +++ b/common/dialogs/panel_toolbar_customization.cpp @@ -41,27 +41,15 @@ enum }; -enum class TOOLBAR_TREE_ITEM_TYPE -{ - TOOL, - GROUP, - SPACER, - SEPARATOR -}; - class TOOLBAR_TREE_ITEM_DATA : public wxTreeItemData { public: - TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE aType ) : + TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE aType ) : wxTreeItemData(), m_name( "" ), m_action( nullptr ), m_type( aType ) - { - // Hard-code the name for the separator - if( aType == TOOLBAR_TREE_ITEM_TYPE::SEPARATOR ) - m_name = "separator"; - } + {} void SetAction( TOOL_ACTION* aAction ) { m_action = aAction; } TOOL_ACTION* GetAction() const { return m_action; } @@ -69,13 +57,17 @@ public: void SetName( std::string aName ) { m_name = aName; } std::string GetName() const { return m_name; } - TOOLBAR_TREE_ITEM_TYPE GetType() const { return m_type; } + void SetToolbarItem( TOOLBAR_ITEM& aItem ) { m_item = aItem; } + TOOLBAR_ITEM GetToolbarItem() const { return m_item; } + + TOOLBAR_ITEM_TYPE GetType() const { return m_type; } private: std::string m_name; TOOL_ACTION* m_action; + TOOLBAR_ITEM m_item; - TOOLBAR_TREE_ITEM_TYPE m_type; + TOOLBAR_ITEM_TYPE m_type; }; @@ -154,6 +146,8 @@ bool PANEL_TOOLBAR_CUSTOMIZATION::TransferDataToWindow() bool PANEL_TOOLBAR_CUSTOMIZATION::TransferDataFromWindow() { + m_appSettings->m_CustomToolbars = m_customToolbars->GetValue(); + return true; } @@ -167,30 +161,67 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree( const TOOLBAR_CONFIGURATI for( auto& item : aToolbar.GetToolbarItems() ) { - if( item == "separator" ) + switch( item.m_Type ) { - // Add a separator - TOOLBAR_TREE_ITEM_DATA* sepTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE::SEPARATOR ); - m_toolbarTree->AppendItem( root, "Separator", -1, -1, sepTreeItem ); - } - else if( item.starts_with( "group" ) ) - { - // Add a group of items to the toolbar - const TOOLBAR_GROUP_CONFIG* groupConfig = aToolbar.GetGroup( item ); - - if( !groupConfig ) + case TOOLBAR_ITEM_TYPE::SEPARATOR: { - wxASSERT_MSG( false, wxString::Format( "Unable to find group %s", item ) ); + // Add a separator + TOOLBAR_TREE_ITEM_DATA* sepTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::SEPARATOR ); + sepTreeItem->SetToolbarItem( item ); + m_toolbarTree->AppendItem( root, "Separator", -1, -1, sepTreeItem ); + break; + } + + case TOOLBAR_ITEM_TYPE::SPACER: + { + // Add a spacer + TOOLBAR_TREE_ITEM_DATA* spacerTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::SPACER ); + spacerTreeItem->SetToolbarItem( item ); + m_toolbarTree->AppendItem( root, wxString::Format( "Spacer: %s", item.m_Size ), -1, -1, spacerTreeItem ); + break; + } + + case TOOLBAR_ITEM_TYPE::CONTROL: + // TODO + break; + + case TOOLBAR_ITEM_TYPE::TOOL: + { + // Add a tool + auto toolMap = m_availableTools.find( item.m_ActionName ); + + if( toolMap == m_availableTools.end() ) + { + wxASSERT_MSG( false, wxString::Format( "Unable to find tool %s", item.m_ActionName ) ); continue; } - TOOLBAR_TREE_ITEM_DATA* groupTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE::GROUP ); - groupTreeItem->SetName( item ); + TOOLBAR_TREE_ITEM_DATA* toolTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::TOOL ); + toolTreeItem->SetName( item.m_ActionName ); + toolTreeItem->SetAction( toolMap->second ); + toolTreeItem->SetToolbarItem( item ); - wxTreeItemId groupId = m_toolbarTree->AppendItem( root, item, -1, -1, groupTreeItem ); + int imgIdx = -1; + auto imgMap = m_actionImageListMap.find( item.m_ActionName ); + + if( imgMap != m_actionImageListMap.end() ) + imgIdx = imgMap->second; + + m_toolbarTree->AppendItem( root, toolMap->second->GetFriendlyName(), + imgIdx, -1, toolTreeItem ); + break; + } + + case TOOLBAR_ITEM_TYPE::GROUP: + { + // Add a group of items to the toolbar + TOOLBAR_TREE_ITEM_DATA* groupTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::GROUP ); + groupTreeItem->SetToolbarItem( item ); + + wxTreeItemId groupId = m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1, groupTreeItem ); // Add the elements below the group - for( auto& groupItem : groupConfig->GetGroupItems() ) + for( auto& groupItem : item.m_GroupItems ) { auto toolMap = m_availableTools.find( groupItem ); @@ -200,7 +231,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree( const TOOLBAR_CONFIGURATI continue; } - TOOLBAR_TREE_ITEM_DATA* toolTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE::TOOL ); + TOOLBAR_TREE_ITEM_DATA* toolTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::TOOL ); toolTreeItem->SetName( groupItem ); toolTreeItem->SetAction( toolMap->second ); @@ -213,39 +244,8 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree( const TOOLBAR_CONFIGURATI m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem ); } - } - else if( item.starts_with( "control" ) ) - { - // Add a custom control to the toolbar - - } - else if( item.starts_with( "spacer" ) ) - { - - } - else - { - // Add a tool - auto toolMap = m_availableTools.find( item ); - - if( toolMap == m_availableTools.end() ) - { - wxASSERT_MSG( false, wxString::Format( "Unable to find tool %s", item ) ); - continue; + break; } - - TOOLBAR_TREE_ITEM_DATA* toolTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE::TOOL ); - toolTreeItem->SetName( item ); - toolTreeItem->SetAction( toolMap->second ); - - int imgIdx = -1; - auto imgMap = m_actionImageListMap.find( item ); - - if( imgMap != m_actionImageListMap.end() ) - imgIdx = imgMap->second; - - m_toolbarTree->AppendItem( root, toolMap->second->GetFriendlyName(), - imgIdx, -1, toolTreeItem ); } } diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index f8d0ac43a9..c0cb71da68 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -514,7 +514,6 @@ ACTION_TOOLBAR_CONTROL_FACTORY* EDA_BASE_FRAME::GetCustomToolbarControlFactory( void EDA_BASE_FRAME::configureToolbars() { - m_toolbarSettings->LoadFromFile( Pgm().GetSettingsManager().GetToolbarSettingsPath() ); } @@ -522,7 +521,7 @@ void EDA_BASE_FRAME::RecreateToolbars() { wxWindowUpdateLocker dummy( this ); - wxASSERT( m_toolbarSettings.get() ); + wxASSERT( m_toolbarSettings ); std::optional tbConfig; @@ -1300,6 +1299,9 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) ); + if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars ) + book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_TOOLBARS ), _( "Toolbars" ) ); + if( GetFrameType() == FRAME_SCH ) expand.push_back( (int) book->GetPageCount() ); @@ -1339,6 +1341,10 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent book->AddLazySubPage( LAZY_CTOR( PANEL_FP_ORIGINS_AXES ), _( "Origins & Axes" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) ); + + if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars ) + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_TOOLBARS ), _( "Toolbars" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_FIELDS ), _( "Footprint Defaults" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_GRAPHICS_VALUES ), _( "Graphics Defaults" ) ); @@ -1363,6 +1369,10 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent book->AddPage( new wxPanel( book ), _( "3D Viewer" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) ); + + if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars ) + book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_TOOLBARS ), _( "Toolbars" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) ); } @@ -1385,6 +1395,10 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) ); + + if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars ) + book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_TOOLBARS ), _( "Toolbars" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_GRIDS ), _( "Grids" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) ); @@ -1410,6 +1424,9 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent book->AddLazySubPage( LAZY_CTOR( PANEL_DS_GRIDS ), _( "Grids" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) ); + if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars ) + book->AddLazySubPage( LAZY_CTOR( PANEL_DS_TOOLBARS ), _( "Toolbars" ) ); + book->AddLazyPage( []( wxWindow* aParent ) -> wxWindow* { diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 022f194850..72694085fb 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -458,6 +458,9 @@ wxString SETTINGS_MANAGER::GetPathForSettingsFile( JSON_SETTINGS* aSettings ) case SETTINGS_LOC::COLORS: return GetColorSettingsPath(); + case SETTINGS_LOC::TOOLBARS: + return GetToolbarSettingsPath(); + case SETTINGS_LOC::NONE: return ""; diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index 96816044e1..095818fe67 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -265,79 +265,73 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) // Remove existing tools ClearToolbar(); - std::vector items = aConfig.GetToolbarItems(); + std::vector items = aConfig.GetToolbarItems(); // Add all the items to the toolbar - for( auto& actionName : items ) + for( auto& item : items ) { - if( actionName == "separator" ) + switch( item.m_Type ) { - // Add a separator + case TOOLBAR_ITEM_TYPE::SEPARATOR: AddScaledSeparator( GetParent() ); - } - else if( actionName.starts_with( "group" ) ) - { - // Add a group of items to the toolbar - const TOOLBAR_GROUP_CONFIG* groupConfig = aConfig.GetGroup( actionName ); + break; - if( !groupConfig ) + case TOOLBAR_ITEM_TYPE::SPACER: + AddSpacer( item.m_Size ); + break; + + case TOOLBAR_ITEM_TYPE::GROUP: { - wxASSERT_MSG( false, wxString::Format( "Unable to find group %s", actionName ) ); - continue; - } - + // Add a group of items to the toolbar std::vector tools; - for( auto& groupItem : groupConfig->GetGroupItems() ) + for( auto& groupItem : item.m_GroupItems ) { TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( groupItem ); if( !action ) { - wxASSERT_MSG( false, wxString::Format( "Unable to find group tool %s", actionName ) ); + wxASSERT_MSG( false, wxString::Format( "Unable to find group tool %s", groupItem ) ); continue; } tools.push_back( action ); } - AddGroup( std::make_unique( groupConfig->GetName(), tools ) ); - } - else if( actionName.starts_with( "control" ) ) - { + AddGroup( std::make_unique( item.m_GroupName.ToStdString(), tools ) ); + break; + } + + case TOOLBAR_ITEM_TYPE::CONTROL: + { // Add a custom control to the toolbar EDA_BASE_FRAME* frame = static_cast( GetParent() ); - ACTION_TOOLBAR_CONTROL_FACTORY* factory = frame->GetCustomToolbarControlFactory( actionName ); + ACTION_TOOLBAR_CONTROL_FACTORY* factory = frame->GetCustomToolbarControlFactory( item.m_ControlName ); if( !factory ) { - wxASSERT_MSG( false, wxString::Format( "Unable to find control factory for %s", actionName ) ); + wxASSERT_MSG( false, wxString::Format( "Unable to find control factory for %s", item.m_ControlName ) ); continue; } // The factory functions are responsible for adding the controls to the toolbar themselves (*factory)( this ); - } - else if( actionName.starts_with( "spacer" ) ) - { - // Extract the spacer size from the text, it is the form "spacer:x", with "x" being the size - int sep = actionName.find_last_of( ":" ); - int spacerSize = std::stoi( actionName.substr( sep+1 ) ); + break; + } - AddSpacer( spacerSize ); - } - else - { - // Assume anything else is an action - TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( actionName ); + case TOOLBAR_ITEM_TYPE::TOOL: + { + TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( item.m_ActionName ); if( !action ) { - wxASSERT_MSG( false, wxString::Format( "Unable to find toolbar tool %s", actionName ) ); + wxASSERT_MSG( false, wxString::Format( "Unable to find toolbar tool %s", item.m_ActionName ) ); continue; } Add( *action ); + break; + } } } diff --git a/common/tool/ui/toolbar_configuration.cpp b/common/tool/ui/toolbar_configuration.cpp index c36fd5c651..296ed63185 100644 --- a/common/tool/ui/toolbar_configuration.cpp +++ b/common/tool/ui/toolbar_configuration.cpp @@ -34,35 +34,47 @@ const int toolbarSchemaVersion = 1; void to_json( nlohmann::json& aJson, const TOOLBAR_CONFIGURATION& aConfig ) { - nlohmann::json groups = nlohmann::json::array(); + aJson = nlohmann::json::array(); - // Serialize the group object - for( const TOOLBAR_GROUP_CONFIG& grp : aConfig.m_toolbarGroups ) + for( const TOOLBAR_ITEM& item : aConfig.m_toolbarItems ) { - nlohmann::json jsGrp = { - { "name", grp.m_groupName } + nlohmann::json jsItem = { + { "type", magic_enum::enum_name( item.m_Type ) } }; - nlohmann::json grpItems = nlohmann::json::array(); + switch( item.m_Type ) + { + case TOOLBAR_ITEM_TYPE::SEPARATOR: + // Nothing to add for a separator + break; - for( const auto& it : grp.m_groupItems ) - grpItems.push_back( it ); + case TOOLBAR_ITEM_TYPE::SPACER: + jsItem["size"] = item.m_Size; + break; - jsGrp["items"] = grpItems; + case TOOLBAR_ITEM_TYPE::CONTROL: + jsItem["name"] = item.m_ControlName; + break; - groups.push_back( jsGrp ); + case TOOLBAR_ITEM_TYPE::TOOL: + jsItem["name"] = item.m_ActionName; + break; + + case TOOLBAR_ITEM_TYPE::GROUP: + jsItem["group_name"] = item.m_GroupName; + + nlohmann::json grpItems = nlohmann::json::array(); + + for( const auto& it : item.m_GroupItems ) + grpItems.push_back( it ); + + jsItem["group_items"] = grpItems; + + break; + } + + aJson.push_back( jsItem ); } - - // Serialize the items - nlohmann::json tbItems = nlohmann::json::array(); - - for( const auto& it : aConfig.m_toolbarItems ) - tbItems.push_back( it ); - - aJson = { - { "groups", groups }, - { "items", tbItems } - }; } @@ -72,47 +84,70 @@ void from_json( const nlohmann::json& aJson, TOOLBAR_CONFIGURATION& aConfig ) return; aConfig.m_toolbarItems.clear(); - aConfig.m_toolbarGroups.clear(); - // Deserialize the groups - if( aJson.contains( "groups" ) && aJson.at( "groups" ).is_array()) + if( aJson.is_array() ) { - for( const nlohmann::json& grp : aJson.at( "groups" ) ) + for( const nlohmann::json& item : aJson ) { - std::string name = ""; + TOOLBAR_ITEM tbItem; - if( grp.contains( "name" ) ) - name = grp.at( "name" ).get(); - - TOOLBAR_GROUP_CONFIG cfg( name ); - - // Deserialize the items - if( grp.contains( "items" ) ) + if( item.contains( "type" ) ) { - for( const nlohmann::json& it : grp.at( "items" ) ) - { - if( it.is_string() ) - cfg.m_groupItems.push_back( it.get() ); - } - } - aConfig.m_toolbarGroups.push_back( cfg ); - } - } + auto type = magic_enum::enum_cast( item["type"].get(), + magic_enum::case_insensitive ); - // Deserialize the items - if( aJson.contains( "items" ) ) - { - for( const nlohmann::json& it : aJson.at( "items" ) ) - { - if( it.is_string() ) - aConfig.m_toolbarItems.push_back( it.get() ); + if( type.has_value() ) + tbItem.m_Type = type.value(); + } + + switch( tbItem.m_Type ) + { + case TOOLBAR_ITEM_TYPE::SEPARATOR: + // Nothing to read for a separator + break; + + case TOOLBAR_ITEM_TYPE::SPACER: + if( item.contains( "size" ) ) + tbItem.m_Size = item["size"].get(); + + break; + + case TOOLBAR_ITEM_TYPE::CONTROL: + if( item.contains( "name" ) ) + tbItem.m_ControlName = item["name"].get(); + + break; + + case TOOLBAR_ITEM_TYPE::TOOL: + if( item.contains( "name" ) ) + tbItem.m_ActionName = item["name"].get(); + + break; + + case TOOLBAR_ITEM_TYPE::GROUP: + if( item.contains( "group_name" ) ) + tbItem.m_GroupName = item["group_name"].get(); + + if( item.contains( "group_items" ) ) + { + for( const nlohmann::json& it : item["group_items"].at( "group_items" ) ) + { + if( it.is_string() ) + tbItem.m_GroupItems.push_back( it.get() ); + } + } + break; + } + + // We just directly add the item to the config + aConfig.m_toolbarItems.push_back( tbItem ); } } } TOOLBAR_SETTINGS::TOOLBAR_SETTINGS( const wxString& aFullPath ) : - JSON_SETTINGS( aFullPath, SETTINGS_LOC::NONE, toolbarSchemaVersion ) + JSON_SETTINGS( aFullPath, SETTINGS_LOC::TOOLBARS, toolbarSchemaVersion ) { m_params.emplace_back( new PARAM_LAMBDA( "toolbars", [&]() -> nlohmann::json diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 9d41e38fd8..cb65c74b73 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -93,7 +94,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : setupTools(); setupUIConditions(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "cvpcb-toolbars" ); configureToolbars(); RecreateToolbars(); ReCreateMenuBar(); diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 17f4321532..46152a4bfc 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -116,7 +116,7 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa setupUIConditions(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "display_footprints-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/cvpcb/toolbars_cvpcb.h b/cvpcb/toolbars_cvpcb.h index acbef3b4e2..76085ac499 100644 --- a/cvpcb/toolbars_cvpcb.h +++ b/cvpcb/toolbars_cvpcb.h @@ -36,7 +36,7 @@ class CVPCB_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: CVPCB_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "cvpcb" ) + TOOLBAR_SETTINGS( "cvpcb-toolbars" ) {} ~CVPCB_TOOLBAR_SETTINGS() {} diff --git a/cvpcb/toolbars_display_footprints.h b/cvpcb/toolbars_display_footprints.h index 386f0bdda2..a2af2e6cd8 100644 --- a/cvpcb/toolbars_display_footprints.h +++ b/cvpcb/toolbars_display_footprints.h @@ -29,7 +29,7 @@ class DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "display-footprints" ) + TOOLBAR_SETTINGS( "display_footprints-toolbars" ) {} ~DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS() {} diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 13f83e1e78..f4c6fcda7b 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -259,6 +259,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER return new PANEL_SYM_EDITING_OPTIONS( aParent, this, frame ); } + case PANEL_SYM_TOOLBARS: + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings( "symbol_editor" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "symbol_editor-toolbars" ); + + std::vector actions; + std::vector controls; + + for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) + actions.push_back( action ); + + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + controls.push_back( control ); + + return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); + } + case PANEL_SYM_COLORS: return new PANEL_SYM_COLOR_SETTINGS( aParent ); @@ -314,8 +332,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER case PANEL_SCH_TOOLBARS: { SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings( "eeschema" ); - TOOLBAR_SETTINGS* tb = new SCH_EDIT_TOOLBAR_SETTINGS(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings( "eeschema" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "eeschema-toolbars" ); std::vector actions; std::vector controls; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 6c4a302a7b..2afc57876b 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -191,7 +191,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : setupUIConditions(); ReCreateMenuBar(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "eeschema-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/eeschema/sim/simulator_frame.cpp b/eeschema/sim/simulator_frame.cpp index 5983b3922f..f410fa19d3 100644 --- a/eeschema/sim/simulator_frame.cpp +++ b/eeschema/sim/simulator_frame.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include @@ -169,7 +170,7 @@ SIMULATOR_FRAME::SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : // was created. m_tbTopMain->SetToolManager( m_toolManager ); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "sim-toolbars" ); configureToolbars(); RecreateToolbars(); ReCreateMenuBar(); diff --git a/eeschema/sim/toolbars_simulator_frame.h b/eeschema/sim/toolbars_simulator_frame.h index 90236d7948..4c22c0f936 100644 --- a/eeschema/sim/toolbars_simulator_frame.h +++ b/eeschema/sim/toolbars_simulator_frame.h @@ -29,7 +29,7 @@ class SIMULATOR_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: SIMULATOR_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "sim" ) + TOOLBAR_SETTINGS( "sim-toolbars" ) {} ~SIMULATOR_TOOLBAR_SETTINGS() {} diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 58b93f18b1..d95bd7cf3a 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -181,7 +181,7 @@ SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : ReCreateMenuBar(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "symbol_editor-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/eeschema/symbol_editor/toolbars_symbol_editor.h b/eeschema/symbol_editor/toolbars_symbol_editor.h index 04532ddc66..ba11c2a0b7 100644 --- a/eeschema/symbol_editor/toolbars_symbol_editor.h +++ b/eeschema/symbol_editor/toolbars_symbol_editor.h @@ -29,7 +29,7 @@ class SYMBOL_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: SYMBOL_EDIT_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "symbol_editor" ) + TOOLBAR_SETTINGS( "symbol_editor-toolbars" ) {} ~SYMBOL_EDIT_TOOLBAR_SETTINGS() {} diff --git a/eeschema/symbol_viewer_frame.cpp b/eeschema/symbol_viewer_frame.cpp index 23c18a2dea..9f23ff9255 100644 --- a/eeschema/symbol_viewer_frame.cpp +++ b/eeschema/symbol_viewer_frame.cpp @@ -143,7 +143,7 @@ SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent ) : setupTools(); setupUIConditions(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "symbol_viewer-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/eeschema/toolbars_sch_editor.h b/eeschema/toolbars_sch_editor.h index ef107008d2..7b926381d0 100644 --- a/eeschema/toolbars_sch_editor.h +++ b/eeschema/toolbars_sch_editor.h @@ -29,7 +29,7 @@ class SCH_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: SCH_EDIT_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "eeschema" ) + TOOLBAR_SETTINGS( "eeschema-toolbars" ) {} ~SCH_EDIT_TOOLBAR_SETTINGS diff --git a/eeschema/toolbars_symbol_viewer.h b/eeschema/toolbars_symbol_viewer.h index 1cd45f7c07..de4edbddf8 100644 --- a/eeschema/toolbars_symbol_viewer.h +++ b/eeschema/toolbars_symbol_viewer.h @@ -30,7 +30,7 @@ class SYMBOL_VIEWER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: SYMBOL_VIEWER_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "symbol_viewer" ) + TOOLBAR_SETTINGS( "symbol_viewer-toolbars" ) {} ~SYMBOL_VIEWER_TOOLBAR_SETTINGS() {} diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index c07d3765c9..741ca09dfd 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -44,6 +44,9 @@ #include #include +#include +#include + using json = nlohmann::json; @@ -91,6 +94,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER case PANEL_GBR_COLORS: return new PANEL_GERBVIEW_COLOR_SETTINGS( aParent ); + case PANEL_GBR_TOOLBARS: + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + GERBVIEW_SETTINGS* cfg = mgr.GetAppSettings( "gerbview" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "gerbview-toolbars" ); + + std::vector actions; + std::vector controls; + + for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) + actions.push_back( action ); + + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + controls.push_back( control ); + + return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); + } + default: ; } diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 836c6cf669..d95617ded5 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -150,7 +150,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) : setupUIConditions(); ReCreateMenuBar(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "gerbview-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/gerbview/toolbars_gerber.h b/gerbview/toolbars_gerber.h index 4d8185037e..b6aaef9bdc 100644 --- a/gerbview/toolbars_gerber.h +++ b/gerbview/toolbars_gerber.h @@ -40,7 +40,7 @@ class GERBVIEW_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: GERBVIEW_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "gerbview" ) + TOOLBAR_SETTINGS( "gerbview-toolbars" ) {} ~GERBVIEW_TOOLBAR_SETTINGS() {} diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 4cfd07b39d..c136d90daa 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -830,8 +830,8 @@ private: */ std::map m_acceptedExts; - // Toolbar Settings - std::unique_ptr m_toolbarSettings; + // Toolbar Settings - this is not owned by the frame + TOOLBAR_SETTINGS* m_toolbarSettings; // Toolbar UI elements ACTION_TOOLBAR* m_tbTopMain; diff --git a/include/settings/json_settings.h b/include/settings/json_settings.h index ede3a2ab3a..5281d9f0eb 100644 --- a/include/settings/json_settings.h +++ b/include/settings/json_settings.h @@ -55,6 +55,7 @@ enum class SETTINGS_LOC { USER, ///< The main config directory (e.g. ~/.config/kicad/) PROJECT, ///< The settings directory inside a project folder COLORS, ///< The color scheme directory (e.g. ~/.config/kicad/colors/) + TOOLBARS, ///< The toolbar directory (e.g. ~/.config/kicad/toolbars/) NESTED, ///< Not stored in a file, but inside another JSON_SETTINGS NONE, ///< No directory prepended, full path in filename (used for PROJECT_FILE) }; diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index ea15dd30da..912fffa66e 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -144,6 +144,51 @@ public: return ret; } + /** + * Return a handle to the given toolbar settings + * + * If the settings have already been loaded, returns the existing pointer. + * If the settings have not been loaded, creates a new object owned by the + * settings manager and returns a pointer to it. + * + * @tparam T is a type derived from TOOLBAR_SETTINGS. + * @param aFilename is used to find the correct settings under clang (where + * RTTI doesn't work across compile boundaries). + * @return a pointer to a loaded settings object. + */ + template + T* GetToolbarSettings( const wxString& aFilename ) + { + T* ret = nullptr; + +#if defined(__clang__) + auto it = std::find_if( m_settings.begin(), m_settings.end(), + [&]( const std::unique_ptr& aSettings ) + { + return aSettings->GetFilename() == aFilename; + } ); +#else + auto it = std::find_if( m_settings.begin(), m_settings.end(), + []( const std::unique_ptr& aSettings ) + { + return dynamic_cast( aSettings.get() ); + } ); +#endif + + if( it != m_settings.end() ) + { + // Do NOT use dynamic_cast here. CLang will think it's the wrong class across + // compile boundaries and return nullptr. + ret = static_cast( it->get() ); + } + else + { + ret = RegisterSettings( new T ); + } + + return ret; + } + /** * Retrieve a color settings object that applications can read colors from. * diff --git a/include/tool/ui/toolbar_configuration.h b/include/tool/ui/toolbar_configuration.h index 10c94d42ca..a457ef48d4 100644 --- a/include/tool/ui/toolbar_configuration.h +++ b/include/tool/ui/toolbar_configuration.h @@ -33,18 +33,67 @@ #include #include +enum class TOOLBAR_ITEM_TYPE +{ + TOOL, + GROUP, + SPACER, + CONTROL, + SEPARATOR +}; + +class KICOMMON_API TOOLBAR_ITEM +{ +public: + TOOLBAR_ITEM() + { } + + TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType ) : + m_Type( aType ) + { } + + TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, int aSize ) : + m_Type( aType ), + m_Size( aSize ) + { + wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER ); + } + + TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, std::string aName ) : + m_Type( aType ) + { + if( aType == TOOLBAR_ITEM_TYPE::CONTROL ) + m_ControlName = aName; + else if( aType == TOOLBAR_ITEM_TYPE::TOOL ) + m_ActionName = aName; + } + +public: + TOOLBAR_ITEM_TYPE m_Type; + + // Control properties + std::string m_ControlName; + + // Tool properties + std::string m_ActionName; + + // Spacer properties + int m_Size; + + // Group properties + wxString m_GroupName; + std::vector m_GroupItems; +}; class KICOMMON_API TOOLBAR_GROUP_CONFIG { public: - - TOOLBAR_GROUP_CONFIG( std::string aName ) : + TOOLBAR_GROUP_CONFIG( wxString aName ) : m_groupName( aName ) { - wxASSERT_MSG( aName.starts_with( "group" ), "Toolbar group names must start with \"group\"" ); } - const std::string& GetName() const + const wxString& GetName() const { return m_groupName; } @@ -69,7 +118,7 @@ public: public: // These are public to write the JSON, but are lower-cased to encourage people not to directly // access them and treat them as private. - std::string m_groupName; + wxString m_groupName; std::vector m_groupItems; }; @@ -82,75 +131,64 @@ public: TOOLBAR_CONFIGURATION& AppendAction( std::string aActionName ) { - m_toolbarItems.push_back( aActionName ); + m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName ); return *this; } TOOLBAR_CONFIGURATION& AppendAction( const TOOL_ACTION& aAction ) { - m_toolbarItems.push_back( aAction.GetName() ); + m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() ); return *this; } TOOLBAR_CONFIGURATION& AppendSeparator() { - m_toolbarItems.push_back( "separator" ); + m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SEPARATOR ); return *this; } TOOLBAR_CONFIGURATION& AppendSpacer( int aSize ) { - m_toolbarItems.push_back( "spacer:" + std::to_string( aSize ) ); + m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SPACER, aSize ); return *this; } TOOLBAR_CONFIGURATION& AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup ) { - m_toolbarGroups.push_back( aGroup ); - m_toolbarItems.push_back( aGroup.GetName() ); + TOOLBAR_ITEM item( TOOLBAR_ITEM_TYPE::GROUP ); + item.m_GroupName = aGroup.GetName(); + item.m_GroupItems = aGroup.GetGroupItems(); + + m_toolbarItems.push_back( item ); return *this; } - TOOLBAR_CONFIGURATION& AppendControl( std::string aControlName ) { - m_toolbarItems.push_back( aControlName ); + m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControlName ); return *this; } TOOLBAR_CONFIGURATION& AppendControl( const ACTION_TOOLBAR_CONTROL& aControl ) { - m_toolbarItems.push_back( aControl.GetName() ); + m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControl.GetName() ); return *this; } - std::vector GetToolbarItems() const + std::vector GetToolbarItems() const { return m_toolbarItems; } - const TOOLBAR_GROUP_CONFIG* GetGroup( const std::string& aGroupName ) const - { - for( const TOOLBAR_GROUP_CONFIG& group : m_toolbarGroups ) - { - if( group.GetName() == aGroupName ) - return &group; - } - - return nullptr; - } - void Clear() { m_toolbarItems.clear(); - m_toolbarGroups.clear(); } public: // These are public to write the JSON, but are lower-cased to encourage people not to directly // access them and treat them as private. - std::vector m_toolbarItems; - std::vector m_toolbarGroups; + std::vector m_toolbarItems; }; @@ -184,6 +222,14 @@ public: */ std::optional GetToolbarConfig( TOOLBAR_LOC aToolbar, bool aForceDefault ); + /** + * Set a configuration for the toolbar. + */ + void SetToolbarConfig( TOOLBAR_LOC aToolbar, TOOLBAR_CONFIGURATION& aConfig ) + { + m_toolbars[aToolbar] = aConfig; + } + protected: // The toolbars - only public to aid in JSON serialization/deserialization std::map m_toolbars; diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 836bac33f3..0c9039864c 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -202,7 +202,7 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl setupTools(); setupUIConditions(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "kicad-toolbars" ); configureToolbars(); RecreateToolbars(); ReCreateMenuBar(); diff --git a/kicad/toolbars_kicad_manager.h b/kicad/toolbars_kicad_manager.h index 94b30cd894..5ac59271d0 100644 --- a/kicad/toolbars_kicad_manager.h +++ b/kicad/toolbars_kicad_manager.h @@ -29,7 +29,7 @@ class KICAD_MANAGER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: KICAD_MANAGER_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "kicad" ) + TOOLBAR_SETTINGS( "kicad-toolbars" ) {} ~KICAD_MANAGER_TOOLBAR_SETTINGS() {} diff --git a/pagelayout_editor/pl_editor.cpp b/pagelayout_editor/pl_editor.cpp index d0899d6bf6..df761a1799 100644 --- a/pagelayout_editor/pl_editor.cpp +++ b/pagelayout_editor/pl_editor.cpp @@ -35,6 +35,9 @@ #include #include +#include +#include + #include "pl_editor_frame.h" #include "pl_editor_settings.h" @@ -85,6 +88,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER case PANEL_DS_COLORS: return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent ); + case PANEL_DS_TOOLBARS: + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings( "pl_editor" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "pl_editor-toolbars" ); + + std::vector actions; + std::vector controls; + + for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) + actions.push_back( action ); + + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + controls.push_back( control ); + + return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); + } + default: ; } diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index daf474dd5c..573f07196d 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -136,7 +136,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : setupUIConditions(); ReCreateMenuBar(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "pl_editor-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/pagelayout_editor/toolbars_pl_editor.h b/pagelayout_editor/toolbars_pl_editor.h index ca97657ef1..263237a66e 100644 --- a/pagelayout_editor/toolbars_pl_editor.h +++ b/pagelayout_editor/toolbars_pl_editor.h @@ -36,7 +36,7 @@ public: class PL_EDITOR_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: - PL_EDITOR_TOOLBAR_SETTINGS() : TOOLBAR_SETTINGS( "pl_editor" ) + PL_EDITOR_TOOLBAR_SETTINGS() : TOOLBAR_SETTINGS( "pl_editor-toolbars" ) {} ~PL_EDITOR_TOOLBAR_SETTINGS() {} diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index b0c41c1d7c..217519eb5c 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -165,7 +165,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : initLibraryTree(); m_treePane = new FOOTPRINT_TREE_PANE( this ); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "fpedit-toolbars" ); configureToolbars(); RecreateToolbars(); ReCreateLayerBox( false ); diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 73573a4aea..00628b5fa6 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -220,7 +220,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent setupUIConditions(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "fpviewer-toolbars" ); configureToolbars(); RecreateToolbars(); ReCreateMenuBar(); diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 1cc814e20d..26cd5d0f4e 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -152,7 +152,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); // Create the toolbars - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "fpwizard-toolbars" ); configureToolbars(); RecreateToolbars(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 150281afda..0516cdcd64 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -268,7 +268,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : setupTools(); setupUIConditions(); - m_toolbarSettings = std::make_unique(); + m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings( "pcbnew-toolbars" ); configureToolbars(); RecreateToolbars(); PrepareLayerIndicator( true ); diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 4446e50264..11b6d347a8 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -67,8 +67,9 @@ #include "pcbnew_jobs_handler.h" #include -#include +#include <3d_viewer/toolbars_3d.h> #include +#include #include @@ -233,6 +234,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER return new PANEL_FP_EDITOR_GRAPHICS_DEFAULTS( aParent, this ); } + case PANEL_FP_TOOLBARS: + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings( "fpedit" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "fpedit-toolbars" ); + + std::vector actions; + std::vector controls; + + for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) + actions.push_back( action ); + + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + controls.push_back( control ); + + return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); + } + case PANEL_FP_COLORS: return new PANEL_FP_EDITOR_COLOR_SETTINGS( aParent ); @@ -300,8 +319,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER case PANEL_PCB_TOOLBARS: { SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - PCBNEW_SETTINGS* cfg = mgr.GetAppSettings( "pcbnew" ); - TOOLBAR_SETTINGS* tb = new PCB_EDIT_TOOLBAR_SETTINGS(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings( "pcbnew" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "pcbnew-toolbars" ); std::vector actions; std::vector controls; @@ -327,6 +346,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER case PANEL_3DV_RAYTRACING: return new PANEL_3D_RAYTRACING_OPTIONS( aParent ); + case PANEL_3DV_TOOLBARS: + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings( "3d_viewer" ); + TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings( "3d_viewer-toolbars" ); + + std::vector actions; + std::vector controls; + + for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) + actions.push_back( action ); + + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + controls.push_back( control ); + + return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); + } + default: return nullptr; } diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 1eac05cf4e..86207b2d12 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -100,7 +100,7 @@ std::optional FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo .AppendAction( PCB_ACTIONS::placeText ) .AppendAction( PCB_ACTIONS::drawTextBox ) .AppendAction( PCB_ACTIONS::drawTable ) - .AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbDimensions" ) + .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Dimension objects" ) ) .AddAction( PCB_ACTIONS::drawOrthogonalDimension ) .AddAction( PCB_ACTIONS::drawAlignedDimension ) .AddAction( PCB_ACTIONS::drawCenterDimension ) diff --git a/pcbnew/toolbars_footprint_editor.h b/pcbnew/toolbars_footprint_editor.h index 9d7e497534..568b9dc4f9 100644 --- a/pcbnew/toolbars_footprint_editor.h +++ b/pcbnew/toolbars_footprint_editor.h @@ -29,7 +29,7 @@ class FOOTPRINT_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: FOOTPRINT_EDIT_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "fpedit" ) + TOOLBAR_SETTINGS( "fpedit-toolbars" ) {} ~FOOTPRINT_EDIT_TOOLBAR_SETTINGS() {} diff --git a/pcbnew/toolbars_footprint_viewer.h b/pcbnew/toolbars_footprint_viewer.h index 32212cd376..85e14df51b 100644 --- a/pcbnew/toolbars_footprint_viewer.h +++ b/pcbnew/toolbars_footprint_viewer.h @@ -29,7 +29,7 @@ class FOOTPRINT_VIEWER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: FOOTPRINT_VIEWER_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "fpviewer" ) + TOOLBAR_SETTINGS( "fpviewer-toolbars" ) {} ~FOOTPRINT_VIEWER_TOOLBAR_SETTINGS() {} diff --git a/pcbnew/toolbars_footprint_wizard.h b/pcbnew/toolbars_footprint_wizard.h index 7834cf217a..2eb6226bf8 100644 --- a/pcbnew/toolbars_footprint_wizard.h +++ b/pcbnew/toolbars_footprint_wizard.h @@ -29,7 +29,7 @@ class FOOTPRINT_WIZARD_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: FOOTPRINT_WIZARD_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "fpwizard" ) + TOOLBAR_SETTINGS( "fpwizard-toolbars" ) {} ~FOOTPRINT_WIZARD_TOOLBAR_SETTINGS() {} diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index cefe7828db..129b6bd558 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -191,10 +191,10 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo config.AppendSeparator() .AppendAction( PCB_ACTIONS::placeFootprint ) - .AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbRouting" ) + .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track routing tools" ) ) .AddAction( PCB_ACTIONS::routeSingleTrack ) .AddAction( PCB_ACTIONS::routeDiffPair ) ) - .AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbTune" ) + .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track tuning tools" ) ) .AddAction( PCB_ACTIONS::tuneSingleTrack ) .AddAction( PCB_ACTIONS::tuneDiffPair ) .AddAction( PCB_ACTIONS::tuneSkew ) ) @@ -213,7 +213,7 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo .AppendAction( PCB_ACTIONS::placeText ) .AppendAction( PCB_ACTIONS::drawTextBox ) .AppendAction( PCB_ACTIONS::drawTable ) - .AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbDimensions" ) + .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Dimension objects" ) ) .AddAction( PCB_ACTIONS::drawOrthogonalDimension ) .AddAction( PCB_ACTIONS::drawAlignedDimension ) .AddAction( PCB_ACTIONS::drawCenterDimension ) @@ -222,9 +222,8 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo .AppendAction( ACTIONS::deleteTool ); config.AppendSeparator() - .AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbOrigins" ) + .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "PCB origins" ) ) .AddAction( ACTIONS::gridSetOrigin ) - .AddAction( PCB_ACTIONS::tuneDiffPair ) .AddAction( PCB_ACTIONS::drillOrigin ) ) .AppendAction( ACTIONS::measureTool ); @@ -433,24 +432,6 @@ void PCB_EDIT_FRAME::configureToolbars() }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory ); - -/* - TOOLBAR_SETTINGS tb( "pcbnew-toolbars" ); - - if( m_tbConfigLeft.has_value() ) - tb.m_Toolbars.emplace( "left", m_tbConfigLeft.value() ); - - if( m_tbConfigRight.has_value() ) - tb.m_Toolbars.emplace( "right", m_tbConfigRight.value() ); - - if( m_tbConfigTopAux.has_value() ) - tb.m_Toolbars.emplace( "top_aux", m_tbConfigTopAux.value() ); - - if( m_tbConfigTopMain.has_value() ) - tb.m_Toolbars.emplace( "top_main", m_tbConfigTopMain.value() ); - - tb.SaveToFile( SETTINGS_MANAGER::GetToolbarSettingsPath(), true ); - */ } diff --git a/pcbnew/toolbars_pcb_editor.h b/pcbnew/toolbars_pcb_editor.h index 4846927847..28e6b216d1 100644 --- a/pcbnew/toolbars_pcb_editor.h +++ b/pcbnew/toolbars_pcb_editor.h @@ -37,7 +37,7 @@ class PCB_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS { public: PCB_EDIT_TOOLBAR_SETTINGS() : - TOOLBAR_SETTINGS( "pcbnew" ) + TOOLBAR_SETTINGS( "pcbnew-toolbars" ) {} ~PCB_EDIT_TOOLBAR_SETTINGS() {}