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
This commit is contained in:
Ian McInerney 2025-02-27 02:51:29 +00:00
parent ab114c4159
commit 85810510f4
44 changed files with 463 additions and 242 deletions

View File

@ -149,7 +149,7 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent
ReCreateMenuBar(); ReCreateMenuBar();
m_toolbarSettings = std::make_unique<EDA_3D_VIEWER_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<EDA_3D_VIEWER_TOOLBAR_SETTINGS>( "3d_viewer-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -29,7 +29,7 @@ class EDA_3D_VIEWER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
EDA_3D_VIEWER_TOOLBAR_SETTINGS() : EDA_3D_VIEWER_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "3d_viewer" ) TOOLBAR_SETTINGS( "3d_viewer-toolbars" )
{} {}
~EDA_3D_VIEWER_TOOLBAR_SETTINGS() {} ~EDA_3D_VIEWER_TOOLBAR_SETTINGS() {}

View File

@ -603,8 +603,8 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
m_GitProjectStatusRefreshInterval, 0, 100000 ) ); m_GitProjectStatusRefreshInterval, 0, 100000 ) );
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ConfigurableToolbars, 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 // Special case for trace mask setting...we just grab them and set them immediately
// Because we even use wxLogTrace inside of advanced config // Because we even use wxLogTrace inside of advanced config

View File

@ -41,27 +41,15 @@ enum
}; };
enum class TOOLBAR_TREE_ITEM_TYPE
{
TOOL,
GROUP,
SPACER,
SEPARATOR
};
class TOOLBAR_TREE_ITEM_DATA : public wxTreeItemData class TOOLBAR_TREE_ITEM_DATA : public wxTreeItemData
{ {
public: public:
TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE aType ) : TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE aType ) :
wxTreeItemData(), wxTreeItemData(),
m_name( "" ), m_name( "" ),
m_action( nullptr ), m_action( nullptr ),
m_type( aType ) 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; } void SetAction( TOOL_ACTION* aAction ) { m_action = aAction; }
TOOL_ACTION* GetAction() const { return m_action; } TOOL_ACTION* GetAction() const { return m_action; }
@ -69,13 +57,17 @@ public:
void SetName( std::string aName ) { m_name = aName; } void SetName( std::string aName ) { m_name = aName; }
std::string GetName() const { return m_name; } 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: private:
std::string m_name; std::string m_name;
TOOL_ACTION* m_action; 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() bool PANEL_TOOLBAR_CUSTOMIZATION::TransferDataFromWindow()
{ {
m_appSettings->m_CustomToolbars = m_customToolbars->GetValue();
return true; return true;
} }
@ -167,30 +161,67 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree( const TOOLBAR_CONFIGURATI
for( auto& item : aToolbar.GetToolbarItems() ) for( auto& item : aToolbar.GetToolbarItems() )
{ {
if( item == "separator" ) switch( item.m_Type )
{ {
// Add a separator case TOOLBAR_ITEM_TYPE::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 )
{ {
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; continue;
} }
TOOLBAR_TREE_ITEM_DATA* groupTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_TREE_ITEM_TYPE::GROUP ); TOOLBAR_TREE_ITEM_DATA* toolTreeItem = new TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE::TOOL );
groupTreeItem->SetName( item ); 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 // Add the elements below the group
for( auto& groupItem : groupConfig->GetGroupItems() ) for( auto& groupItem : item.m_GroupItems )
{ {
auto toolMap = m_availableTools.find( groupItem ); auto toolMap = m_availableTools.find( groupItem );
@ -200,7 +231,7 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree( const TOOLBAR_CONFIGURATI
continue; 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->SetName( groupItem );
toolTreeItem->SetAction( toolMap->second ); toolTreeItem->SetAction( toolMap->second );
@ -213,39 +244,8 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateToolbarTree( const TOOLBAR_CONFIGURATI
m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(),
imgIdx, -1, toolTreeItem ); imgIdx, -1, toolTreeItem );
} }
} break;
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;
} }
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 );
} }
} }

View File

@ -514,7 +514,6 @@ ACTION_TOOLBAR_CONTROL_FACTORY* EDA_BASE_FRAME::GetCustomToolbarControlFactory(
void EDA_BASE_FRAME::configureToolbars() void EDA_BASE_FRAME::configureToolbars()
{ {
m_toolbarSettings->LoadFromFile( Pgm().GetSettingsManager().GetToolbarSettingsPath() );
} }
@ -522,7 +521,7 @@ void EDA_BASE_FRAME::RecreateToolbars()
{ {
wxWindowUpdateLocker dummy( this ); wxWindowUpdateLocker dummy( this );
wxASSERT( m_toolbarSettings.get() ); wxASSERT( m_toolbarSettings );
std::optional<TOOLBAR_CONFIGURATION> tbConfig; std::optional<TOOLBAR_CONFIGURATION> 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_EDIT_OPTIONS ), _( "Editing Options" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) ); 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 ) if( GetFrameType() == FRAME_SCH )
expand.push_back( (int) book->GetPageCount() ); 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_ORIGINS_AXES ), _( "Origins & Axes" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) ); 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_FIELDS ), _( "Footprint Defaults" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_GRAPHICS_VALUES ), book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_GRAPHICS_VALUES ),
_( "Graphics Defaults" ) ); _( "Graphics Defaults" ) );
@ -1363,6 +1369,10 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent
book->AddPage( new wxPanel( book ), _( "3D Viewer" ) ); book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) ); 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_OPENGL ), _( "Realtime Renderer" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing 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->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) ); 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_GRIDS ), _( "Grids" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_EXCELLON_OPTIONS ), book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_EXCELLON_OPTIONS ),
_( "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_GRIDS ), _( "Grids" ) );
book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) );
if( ADVANCED_CFG::GetCfg().m_ConfigurableToolbars )
book->AddLazySubPage( LAZY_CTOR( PANEL_DS_TOOLBARS ), _( "Toolbars" ) );
book->AddLazyPage( book->AddLazyPage(
[]( wxWindow* aParent ) -> wxWindow* []( wxWindow* aParent ) -> wxWindow*
{ {

View File

@ -458,6 +458,9 @@ wxString SETTINGS_MANAGER::GetPathForSettingsFile( JSON_SETTINGS* aSettings )
case SETTINGS_LOC::COLORS: case SETTINGS_LOC::COLORS:
return GetColorSettingsPath(); return GetColorSettingsPath();
case SETTINGS_LOC::TOOLBARS:
return GetToolbarSettingsPath();
case SETTINGS_LOC::NONE: case SETTINGS_LOC::NONE:
return ""; return "";

View File

@ -265,79 +265,73 @@ void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig )
// Remove existing tools // Remove existing tools
ClearToolbar(); ClearToolbar();
std::vector<std::string> items = aConfig.GetToolbarItems(); std::vector<TOOLBAR_ITEM> items = aConfig.GetToolbarItems();
// Add all the items to the toolbar // 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() ); AddScaledSeparator( GetParent() );
} break;
else if( actionName.starts_with( "group" ) )
{
// Add a group of items to the toolbar
const TOOLBAR_GROUP_CONFIG* groupConfig = aConfig.GetGroup( actionName );
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 ) ); // Add a group of items to the toolbar
continue;
}
std::vector<const TOOL_ACTION*> tools; std::vector<const TOOL_ACTION*> tools;
for( auto& groupItem : groupConfig->GetGroupItems() ) for( auto& groupItem : item.m_GroupItems )
{ {
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( groupItem ); TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( groupItem );
if( !action ) 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; continue;
} }
tools.push_back( action ); tools.push_back( action );
} }
AddGroup( std::make_unique<ACTION_GROUP>( groupConfig->GetName(), tools ) ); AddGroup( std::make_unique<ACTION_GROUP>( item.m_GroupName.ToStdString(), tools ) );
} break;
else if( actionName.starts_with( "control" ) ) }
{
case TOOLBAR_ITEM_TYPE::CONTROL:
{
// Add a custom control to the toolbar // Add a custom control to the toolbar
EDA_BASE_FRAME* frame = static_cast<EDA_BASE_FRAME*>( GetParent() ); EDA_BASE_FRAME* frame = static_cast<EDA_BASE_FRAME*>( GetParent() );
ACTION_TOOLBAR_CONTROL_FACTORY* factory = frame->GetCustomToolbarControlFactory( actionName ); ACTION_TOOLBAR_CONTROL_FACTORY* factory = frame->GetCustomToolbarControlFactory( item.m_ControlName );
if( !factory ) 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; continue;
} }
// The factory functions are responsible for adding the controls to the toolbar themselves // The factory functions are responsible for adding the controls to the toolbar themselves
(*factory)( this ); (*factory)( this );
} break;
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 ) );
AddSpacer( spacerSize ); case TOOLBAR_ITEM_TYPE::TOOL:
} {
else TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( item.m_ActionName );
{
// Assume anything else is an action
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( actionName );
if( !action ) 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; continue;
} }
Add( *action ); Add( *action );
break;
}
} }
} }

View File

@ -34,35 +34,47 @@ const int toolbarSchemaVersion = 1;
void to_json( nlohmann::json& aJson, const TOOLBAR_CONFIGURATION& aConfig ) 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_ITEM& item : aConfig.m_toolbarItems )
for( const TOOLBAR_GROUP_CONFIG& grp : aConfig.m_toolbarGroups )
{ {
nlohmann::json jsGrp = { nlohmann::json jsItem = {
{ "name", grp.m_groupName } { "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 ) case TOOLBAR_ITEM_TYPE::SPACER:
grpItems.push_back( it ); 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; return;
aConfig.m_toolbarItems.clear(); aConfig.m_toolbarItems.clear();
aConfig.m_toolbarGroups.clear();
// Deserialize the groups if( aJson.is_array() )
if( aJson.contains( "groups" ) && aJson.at( "groups" ).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" ) ) if( item.contains( "type" ) )
name = grp.at( "name" ).get<std::string>();
TOOLBAR_GROUP_CONFIG cfg( name );
// Deserialize the items
if( grp.contains( "items" ) )
{ {
for( const nlohmann::json& it : grp.at( "items" ) ) auto type = magic_enum::enum_cast<TOOLBAR_ITEM_TYPE>( item["type"].get<std::string>(),
{ magic_enum::case_insensitive );
if( it.is_string() )
cfg.m_groupItems.push_back( it.get<std::string>() );
}
}
aConfig.m_toolbarGroups.push_back( cfg );
}
}
// Deserialize the items if( type.has_value() )
if( aJson.contains( "items" ) ) tbItem.m_Type = type.value();
{ }
for( const nlohmann::json& it : aJson.at( "items" ) )
{ switch( tbItem.m_Type )
if( it.is_string() ) {
aConfig.m_toolbarItems.push_back( it.get<std::string>() ); 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<int>();
break;
case TOOLBAR_ITEM_TYPE::CONTROL:
if( item.contains( "name" ) )
tbItem.m_ControlName = item["name"].get<std::string>();
break;
case TOOLBAR_ITEM_TYPE::TOOL:
if( item.contains( "name" ) )
tbItem.m_ActionName = item["name"].get<std::string>();
break;
case TOOLBAR_ITEM_TYPE::GROUP:
if( item.contains( "group_name" ) )
tbItem.m_GroupName = item["group_name"].get<wxString>();
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<std::string>() );
}
}
break;
}
// We just directly add the item to the config
aConfig.m_toolbarItems.push_back( tbItem );
} }
} }
} }
TOOLBAR_SETTINGS::TOOLBAR_SETTINGS( const wxString& aFullPath ) : 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<nlohmann::json>( "toolbars", m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "toolbars",
[&]() -> nlohmann::json [&]() -> nlohmann::json

View File

@ -47,6 +47,7 @@
#include <cvpcb_association.h> #include <cvpcb_association.h>
#include <cvpcb_id.h> #include <cvpcb_id.h>
#include <cvpcb_mainframe.h> #include <cvpcb_mainframe.h>
#include <settings/settings_manager.h>
#include <settings/cvpcb_settings.h> #include <settings/cvpcb_settings.h>
#include <display_footprints_frame.h> #include <display_footprints_frame.h>
#include <kiplatform/ui.h> #include <kiplatform/ui.h>
@ -93,7 +94,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
setupTools(); setupTools();
setupUIConditions(); setupUIConditions();
m_toolbarSettings = std::make_unique<CVPCB_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<CVPCB_TOOLBAR_SETTINGS>( "cvpcb-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();
ReCreateMenuBar(); ReCreateMenuBar();

View File

@ -116,7 +116,7 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa
setupUIConditions(); setupUIConditions();
m_toolbarSettings = std::make_unique<DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS>( "display_footprints-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -36,7 +36,7 @@ class CVPCB_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
CVPCB_TOOLBAR_SETTINGS() : CVPCB_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "cvpcb" ) TOOLBAR_SETTINGS( "cvpcb-toolbars" )
{} {}
~CVPCB_TOOLBAR_SETTINGS() {} ~CVPCB_TOOLBAR_SETTINGS() {}

View File

@ -29,7 +29,7 @@ class DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS() : DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "display-footprints" ) TOOLBAR_SETTINGS( "display_footprints-toolbars" )
{} {}
~DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS() {} ~DISPLAY_FOOTPRINTS_TOOLBAR_SETTINGS() {}

View File

@ -259,6 +259,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
return new PANEL_SYM_EDITING_OPTIONS( aParent, this, frame ); 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_SETTINGS>( "symbol_editor" );
TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<SYMBOL_EDIT_TOOLBAR_SETTINGS>( "symbol_editor-toolbars" );
std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> 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: case PANEL_SYM_COLORS:
return new PANEL_SYM_COLOR_SETTINGS( aParent ); return new PANEL_SYM_COLOR_SETTINGS( aParent );
@ -314,8 +332,8 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
case PANEL_SCH_TOOLBARS: case PANEL_SCH_TOOLBARS:
{ {
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" ); APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
TOOLBAR_SETTINGS* tb = new SCH_EDIT_TOOLBAR_SETTINGS(); TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<SCH_EDIT_TOOLBAR_SETTINGS>( "eeschema-toolbars" );
std::vector<TOOL_ACTION*> actions; std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> controls; std::vector<ACTION_TOOLBAR_CONTROL*> controls;

View File

@ -191,7 +191,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
setupUIConditions(); setupUIConditions();
ReCreateMenuBar(); ReCreateMenuBar();
m_toolbarSettings = std::make_unique<SCH_EDIT_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<SCH_EDIT_TOOLBAR_SETTINGS>( "eeschema-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -58,6 +58,7 @@
#include <eeschema_settings.h> #include <eeschema_settings.h>
#include <advanced_config.h> #include <advanced_config.h>
#include <sim/toolbars_simulator_frame.h> #include <sim/toolbars_simulator_frame.h>
#include <settings/settings_manager.h>
#include <memory> #include <memory>
@ -169,7 +170,7 @@ SIMULATOR_FRAME::SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
// was created. // was created.
m_tbTopMain->SetToolManager( m_toolManager ); m_tbTopMain->SetToolManager( m_toolManager );
m_toolbarSettings = std::make_unique<SIMULATOR_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<SIMULATOR_TOOLBAR_SETTINGS>( "sim-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();
ReCreateMenuBar(); ReCreateMenuBar();

View File

@ -29,7 +29,7 @@ class SIMULATOR_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
SIMULATOR_TOOLBAR_SETTINGS() : SIMULATOR_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "sim" ) TOOLBAR_SETTINGS( "sim-toolbars" )
{} {}
~SIMULATOR_TOOLBAR_SETTINGS() {} ~SIMULATOR_TOOLBAR_SETTINGS() {}

View File

@ -181,7 +181,7 @@ SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
ReCreateMenuBar(); ReCreateMenuBar();
m_toolbarSettings = std::make_unique<SYMBOL_EDIT_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<SYMBOL_EDIT_TOOLBAR_SETTINGS>( "symbol_editor-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -29,7 +29,7 @@ class SYMBOL_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
SYMBOL_EDIT_TOOLBAR_SETTINGS() : SYMBOL_EDIT_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "symbol_editor" ) TOOLBAR_SETTINGS( "symbol_editor-toolbars" )
{} {}
~SYMBOL_EDIT_TOOLBAR_SETTINGS() {} ~SYMBOL_EDIT_TOOLBAR_SETTINGS() {}

View File

@ -143,7 +143,7 @@ SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
setupTools(); setupTools();
setupUIConditions(); setupUIConditions();
m_toolbarSettings = std::make_unique<SYMBOL_VIEWER_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<SYMBOL_VIEWER_TOOLBAR_SETTINGS>( "symbol_viewer-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -29,7 +29,7 @@ class SCH_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
SCH_EDIT_TOOLBAR_SETTINGS() : SCH_EDIT_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "eeschema" ) TOOLBAR_SETTINGS( "eeschema-toolbars" )
{} {}
~SCH_EDIT_TOOLBAR_SETTINGS ~SCH_EDIT_TOOLBAR_SETTINGS

View File

@ -30,7 +30,7 @@ class SYMBOL_VIEWER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
SYMBOL_VIEWER_TOOLBAR_SETTINGS() : SYMBOL_VIEWER_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "symbol_viewer" ) TOOLBAR_SETTINGS( "symbol_viewer-toolbars" )
{} {}
~SYMBOL_VIEWER_TOOLBAR_SETTINGS() {} ~SYMBOL_VIEWER_TOOLBAR_SETTINGS() {}

View File

@ -44,6 +44,9 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <wx/ffile.h> #include <wx/ffile.h>
#include <dialogs/panel_toolbar_customization.h>
#include <toolbars_gerber.h>
using json = nlohmann::json; using json = nlohmann::json;
@ -91,6 +94,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
case PANEL_GBR_COLORS: case PANEL_GBR_COLORS:
return new PANEL_GERBVIEW_COLOR_SETTINGS( aParent ); return new PANEL_GERBVIEW_COLOR_SETTINGS( aParent );
case PANEL_GBR_TOOLBARS:
{
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
GERBVIEW_SETTINGS* cfg = mgr.GetAppSettings<GERBVIEW_SETTINGS>( "gerbview" );
TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<GERBVIEW_TOOLBAR_SETTINGS>( "gerbview-toolbars" );
std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> 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: default:
; ;
} }

View File

@ -150,7 +150,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
setupUIConditions(); setupUIConditions();
ReCreateMenuBar(); ReCreateMenuBar();
m_toolbarSettings = std::make_unique<GERBVIEW_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<GERBVIEW_TOOLBAR_SETTINGS>( "gerbview-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -40,7 +40,7 @@ class GERBVIEW_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
GERBVIEW_TOOLBAR_SETTINGS() : GERBVIEW_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "gerbview" ) TOOLBAR_SETTINGS( "gerbview-toolbars" )
{} {}
~GERBVIEW_TOOLBAR_SETTINGS() {} ~GERBVIEW_TOOLBAR_SETTINGS() {}

View File

@ -830,8 +830,8 @@ private:
*/ */
std::map<const wxString, TOOL_ACTION*> m_acceptedExts; std::map<const wxString, TOOL_ACTION*> m_acceptedExts;
// Toolbar Settings // Toolbar Settings - this is not owned by the frame
std::unique_ptr<TOOLBAR_SETTINGS> m_toolbarSettings; TOOLBAR_SETTINGS* m_toolbarSettings;
// Toolbar UI elements // Toolbar UI elements
ACTION_TOOLBAR* m_tbTopMain; ACTION_TOOLBAR* m_tbTopMain;

View File

@ -55,6 +55,7 @@ enum class SETTINGS_LOC {
USER, ///< The main config directory (e.g. ~/.config/kicad/) USER, ///< The main config directory (e.g. ~/.config/kicad/)
PROJECT, ///< The settings directory inside a project folder PROJECT, ///< The settings directory inside a project folder
COLORS, ///< The color scheme directory (e.g. ~/.config/kicad/colors/) 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 NESTED, ///< Not stored in a file, but inside another JSON_SETTINGS
NONE, ///< No directory prepended, full path in filename (used for PROJECT_FILE) NONE, ///< No directory prepended, full path in filename (used for PROJECT_FILE)
}; };

View File

@ -144,6 +144,51 @@ public:
return ret; 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<typename T>
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<JSON_SETTINGS>& aSettings )
{
return aSettings->GetFilename() == aFilename;
} );
#else
auto it = std::find_if( m_settings.begin(), m_settings.end(),
[]( const std::unique_ptr<JSON_SETTINGS>& aSettings )
{
return dynamic_cast<T*>( 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<T*>( it->get() );
}
else
{
ret = RegisterSettings( new T );
}
return ret;
}
/** /**
* Retrieve a color settings object that applications can read colors from. * Retrieve a color settings object that applications can read colors from.
* *

View File

@ -33,18 +33,67 @@
#include <tool/action_toolbar.h> #include <tool/action_toolbar.h>
#include <tool/tool_action.h> #include <tool/tool_action.h>
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<std::string> m_GroupItems;
};
class KICOMMON_API TOOLBAR_GROUP_CONFIG class KICOMMON_API TOOLBAR_GROUP_CONFIG
{ {
public: public:
TOOLBAR_GROUP_CONFIG( wxString aName ) :
TOOLBAR_GROUP_CONFIG( std::string aName ) :
m_groupName( 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; return m_groupName;
} }
@ -69,7 +118,7 @@ public:
public: public:
// These are public to write the JSON, but are lower-cased to encourage people not to directly // These are public to write the JSON, but are lower-cased to encourage people not to directly
// access them and treat them as private. // access them and treat them as private.
std::string m_groupName; wxString m_groupName;
std::vector<std::string> m_groupItems; std::vector<std::string> m_groupItems;
}; };
@ -82,75 +131,64 @@ public:
TOOLBAR_CONFIGURATION& AppendAction( std::string aActionName ) TOOLBAR_CONFIGURATION& AppendAction( std::string aActionName )
{ {
m_toolbarItems.push_back( aActionName ); m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
return *this; return *this;
} }
TOOLBAR_CONFIGURATION& AppendAction( const TOOL_ACTION& aAction ) 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; return *this;
} }
TOOLBAR_CONFIGURATION& AppendSeparator() TOOLBAR_CONFIGURATION& AppendSeparator()
{ {
m_toolbarItems.push_back( "separator" ); m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SEPARATOR );
return *this; return *this;
} }
TOOLBAR_CONFIGURATION& AppendSpacer( int aSize ) 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; return *this;
} }
TOOLBAR_CONFIGURATION& AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup ) TOOLBAR_CONFIGURATION& AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup )
{ {
m_toolbarGroups.push_back( aGroup ); TOOLBAR_ITEM item( TOOLBAR_ITEM_TYPE::GROUP );
m_toolbarItems.push_back( aGroup.GetName() ); item.m_GroupName = aGroup.GetName();
item.m_GroupItems = aGroup.GetGroupItems();
m_toolbarItems.push_back( item );
return *this; return *this;
} }
TOOLBAR_CONFIGURATION& AppendControl( std::string aControlName ) TOOLBAR_CONFIGURATION& AppendControl( std::string aControlName )
{ {
m_toolbarItems.push_back( aControlName ); m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControlName );
return *this; return *this;
} }
TOOLBAR_CONFIGURATION& AppendControl( const ACTION_TOOLBAR_CONTROL& aControl ) 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; return *this;
} }
std::vector<std::string> GetToolbarItems() const std::vector<TOOLBAR_ITEM> GetToolbarItems() const
{ {
return m_toolbarItems; 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() void Clear()
{ {
m_toolbarItems.clear(); m_toolbarItems.clear();
m_toolbarGroups.clear();
} }
public: public:
// These are public to write the JSON, but are lower-cased to encourage people not to directly // These are public to write the JSON, but are lower-cased to encourage people not to directly
// access them and treat them as private. // access them and treat them as private.
std::vector<std::string> m_toolbarItems; std::vector<TOOLBAR_ITEM> m_toolbarItems;
std::vector<TOOLBAR_GROUP_CONFIG> m_toolbarGroups;
}; };
@ -184,6 +222,14 @@ public:
*/ */
std::optional<TOOLBAR_CONFIGURATION> GetToolbarConfig( TOOLBAR_LOC aToolbar, bool aForceDefault ); std::optional<TOOLBAR_CONFIGURATION> 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: protected:
// The toolbars - only public to aid in JSON serialization/deserialization // The toolbars - only public to aid in JSON serialization/deserialization
std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars; std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars;

View File

@ -202,7 +202,7 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl
setupTools(); setupTools();
setupUIConditions(); setupUIConditions();
m_toolbarSettings = std::make_unique<KICAD_MANAGER_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<KICAD_MANAGER_TOOLBAR_SETTINGS>( "kicad-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();
ReCreateMenuBar(); ReCreateMenuBar();

View File

@ -29,7 +29,7 @@ class KICAD_MANAGER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
KICAD_MANAGER_TOOLBAR_SETTINGS() : KICAD_MANAGER_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "kicad" ) TOOLBAR_SETTINGS( "kicad-toolbars" )
{} {}
~KICAD_MANAGER_TOOLBAR_SETTINGS() {} ~KICAD_MANAGER_TOOLBAR_SETTINGS() {}

View File

@ -35,6 +35,9 @@
#include <dialogs/panel_pl_editor_color_settings.h> #include <dialogs/panel_pl_editor_color_settings.h>
#include <dialogs/panel_grid_settings.h> #include <dialogs/panel_grid_settings.h>
#include <dialogs/panel_toolbar_customization.h>
#include <toolbars_pl_editor.h>
#include "pl_editor_frame.h" #include "pl_editor_frame.h"
#include "pl_editor_settings.h" #include "pl_editor_settings.h"
@ -85,6 +88,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
case PANEL_DS_COLORS: case PANEL_DS_COLORS:
return new PANEL_PL_EDITOR_COLOR_SETTINGS( aParent ); 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_SETTINGS>( "pl_editor" );
TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<PL_EDITOR_TOOLBAR_SETTINGS>( "pl_editor-toolbars" );
std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> 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: default:
; ;
} }

View File

@ -136,7 +136,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
setupUIConditions(); setupUIConditions();
ReCreateMenuBar(); ReCreateMenuBar();
m_toolbarSettings = std::make_unique<PL_EDITOR_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<PL_EDITOR_TOOLBAR_SETTINGS>( "pl_editor-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -36,7 +36,7 @@ public:
class PL_EDITOR_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS class PL_EDITOR_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
PL_EDITOR_TOOLBAR_SETTINGS() : TOOLBAR_SETTINGS( "pl_editor" ) PL_EDITOR_TOOLBAR_SETTINGS() : TOOLBAR_SETTINGS( "pl_editor-toolbars" )
{} {}
~PL_EDITOR_TOOLBAR_SETTINGS() {} ~PL_EDITOR_TOOLBAR_SETTINGS() {}

View File

@ -165,7 +165,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
initLibraryTree(); initLibraryTree();
m_treePane = new FOOTPRINT_TREE_PANE( this ); m_treePane = new FOOTPRINT_TREE_PANE( this );
m_toolbarSettings = std::make_unique<FOOTPRINT_EDIT_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<FOOTPRINT_EDIT_TOOLBAR_SETTINGS>( "fpedit-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();
ReCreateLayerBox( false ); ReCreateLayerBox( false );

View File

@ -220,7 +220,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
setupUIConditions(); setupUIConditions();
m_toolbarSettings = std::make_unique<FOOTPRINT_VIEWER_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<FOOTPRINT_VIEWER_TOOLBAR_SETTINGS>( "fpviewer-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();
ReCreateMenuBar(); ReCreateMenuBar();

View File

@ -152,7 +152,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent
m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
// Create the toolbars // Create the toolbars
m_toolbarSettings = std::make_unique<FOOTPRINT_WIZARD_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<FOOTPRINT_WIZARD_TOOLBAR_SETTINGS>( "fpwizard-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();

View File

@ -268,7 +268,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
setupTools(); setupTools();
setupUIConditions(); setupUIConditions();
m_toolbarSettings = std::make_unique<PCB_EDIT_TOOLBAR_SETTINGS>(); m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<PCB_EDIT_TOOLBAR_SETTINGS>( "pcbnew-toolbars" );
configureToolbars(); configureToolbars();
RecreateToolbars(); RecreateToolbars();
PrepareLayerIndicator( true ); PrepareLayerIndicator( true );

View File

@ -67,8 +67,9 @@
#include "pcbnew_jobs_handler.h" #include "pcbnew_jobs_handler.h"
#include <dialogs/panel_toolbar_customization.h> #include <dialogs/panel_toolbar_customization.h>
#include <toolbars_pcb_editor.h> #include <3d_viewer/toolbars_3d.h>
#include <toolbars_footprint_editor.h> #include <toolbars_footprint_editor.h>
#include <toolbars_pcb_editor.h>
#include <wx/crt.h> #include <wx/crt.h>
@ -233,6 +234,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
return new PANEL_FP_EDITOR_GRAPHICS_DEFAULTS( aParent, this ); return new PANEL_FP_EDITOR_GRAPHICS_DEFAULTS( aParent, this );
} }
case PANEL_FP_TOOLBARS:
{
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<FOOTPRINT_EDIT_TOOLBAR_SETTINGS>( "fpedit-toolbars" );
std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> 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: case PANEL_FP_COLORS:
return new PANEL_FP_EDITOR_COLOR_SETTINGS( aParent ); 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: case PANEL_PCB_TOOLBARS:
{ {
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
PCBNEW_SETTINGS* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" ); APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
TOOLBAR_SETTINGS* tb = new PCB_EDIT_TOOLBAR_SETTINGS(); TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<PCB_EDIT_TOOLBAR_SETTINGS>( "pcbnew-toolbars" );
std::vector<TOOL_ACTION*> actions; std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> controls; std::vector<ACTION_TOOLBAR_CONTROL*> controls;
@ -327,6 +346,24 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
case PANEL_3DV_RAYTRACING: case PANEL_3DV_RAYTRACING:
return new PANEL_3D_RAYTRACING_OPTIONS( aParent ); return new PANEL_3D_RAYTRACING_OPTIONS( aParent );
case PANEL_3DV_TOOLBARS:
{
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
APP_SETTINGS_BASE* cfg = mgr.GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" );
TOOLBAR_SETTINGS* tb = mgr.GetToolbarSettings<EDA_3D_VIEWER_TOOLBAR_SETTINGS>( "3d_viewer-toolbars" );
std::vector<TOOL_ACTION*> actions;
std::vector<ACTION_TOOLBAR_CONTROL*> 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: default:
return nullptr; return nullptr;
} }

View File

@ -100,7 +100,7 @@ std::optional<TOOLBAR_CONFIGURATION> FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo
.AppendAction( PCB_ACTIONS::placeText ) .AppendAction( PCB_ACTIONS::placeText )
.AppendAction( PCB_ACTIONS::drawTextBox ) .AppendAction( PCB_ACTIONS::drawTextBox )
.AppendAction( PCB_ACTIONS::drawTable ) .AppendAction( PCB_ACTIONS::drawTable )
.AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbDimensions" ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Dimension objects" ) )
.AddAction( PCB_ACTIONS::drawOrthogonalDimension ) .AddAction( PCB_ACTIONS::drawOrthogonalDimension )
.AddAction( PCB_ACTIONS::drawAlignedDimension ) .AddAction( PCB_ACTIONS::drawAlignedDimension )
.AddAction( PCB_ACTIONS::drawCenterDimension ) .AddAction( PCB_ACTIONS::drawCenterDimension )

View File

@ -29,7 +29,7 @@ class FOOTPRINT_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
FOOTPRINT_EDIT_TOOLBAR_SETTINGS() : FOOTPRINT_EDIT_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "fpedit" ) TOOLBAR_SETTINGS( "fpedit-toolbars" )
{} {}
~FOOTPRINT_EDIT_TOOLBAR_SETTINGS() {} ~FOOTPRINT_EDIT_TOOLBAR_SETTINGS() {}

View File

@ -29,7 +29,7 @@ class FOOTPRINT_VIEWER_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
FOOTPRINT_VIEWER_TOOLBAR_SETTINGS() : FOOTPRINT_VIEWER_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "fpviewer" ) TOOLBAR_SETTINGS( "fpviewer-toolbars" )
{} {}
~FOOTPRINT_VIEWER_TOOLBAR_SETTINGS() {} ~FOOTPRINT_VIEWER_TOOLBAR_SETTINGS() {}

View File

@ -29,7 +29,7 @@ class FOOTPRINT_WIZARD_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
FOOTPRINT_WIZARD_TOOLBAR_SETTINGS() : FOOTPRINT_WIZARD_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "fpwizard" ) TOOLBAR_SETTINGS( "fpwizard-toolbars" )
{} {}
~FOOTPRINT_WIZARD_TOOLBAR_SETTINGS() {} ~FOOTPRINT_WIZARD_TOOLBAR_SETTINGS() {}

View File

@ -191,10 +191,10 @@ std::optional<TOOLBAR_CONFIGURATION> PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo
config.AppendSeparator() config.AppendSeparator()
.AppendAction( PCB_ACTIONS::placeFootprint ) .AppendAction( PCB_ACTIONS::placeFootprint )
.AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbRouting" ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track routing tools" ) )
.AddAction( PCB_ACTIONS::routeSingleTrack ) .AddAction( PCB_ACTIONS::routeSingleTrack )
.AddAction( PCB_ACTIONS::routeDiffPair ) ) .AddAction( PCB_ACTIONS::routeDiffPair ) )
.AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbTune" ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track tuning tools" ) )
.AddAction( PCB_ACTIONS::tuneSingleTrack ) .AddAction( PCB_ACTIONS::tuneSingleTrack )
.AddAction( PCB_ACTIONS::tuneDiffPair ) .AddAction( PCB_ACTIONS::tuneDiffPair )
.AddAction( PCB_ACTIONS::tuneSkew ) ) .AddAction( PCB_ACTIONS::tuneSkew ) )
@ -213,7 +213,7 @@ std::optional<TOOLBAR_CONFIGURATION> PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo
.AppendAction( PCB_ACTIONS::placeText ) .AppendAction( PCB_ACTIONS::placeText )
.AppendAction( PCB_ACTIONS::drawTextBox ) .AppendAction( PCB_ACTIONS::drawTextBox )
.AppendAction( PCB_ACTIONS::drawTable ) .AppendAction( PCB_ACTIONS::drawTable )
.AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbDimensions" ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Dimension objects" ) )
.AddAction( PCB_ACTIONS::drawOrthogonalDimension ) .AddAction( PCB_ACTIONS::drawOrthogonalDimension )
.AddAction( PCB_ACTIONS::drawAlignedDimension ) .AddAction( PCB_ACTIONS::drawAlignedDimension )
.AddAction( PCB_ACTIONS::drawCenterDimension ) .AddAction( PCB_ACTIONS::drawCenterDimension )
@ -222,9 +222,8 @@ std::optional<TOOLBAR_CONFIGURATION> PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo
.AppendAction( ACTIONS::deleteTool ); .AppendAction( ACTIONS::deleteTool );
config.AppendSeparator() config.AppendSeparator()
.AppendGroup( TOOLBAR_GROUP_CONFIG( "group.pcbOrigins" ) .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "PCB origins" ) )
.AddAction( ACTIONS::gridSetOrigin ) .AddAction( ACTIONS::gridSetOrigin )
.AddAction( PCB_ACTIONS::tuneDiffPair )
.AddAction( PCB_ACTIONS::drillOrigin ) ) .AddAction( PCB_ACTIONS::drillOrigin ) )
.AppendAction( ACTIONS::measureTool ); .AppendAction( ACTIONS::measureTool );
@ -433,24 +432,6 @@ void PCB_EDIT_FRAME::configureToolbars()
}; };
RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory ); 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 );
*/
} }

View File

@ -37,7 +37,7 @@ class PCB_EDIT_TOOLBAR_SETTINGS : public TOOLBAR_SETTINGS
{ {
public: public:
PCB_EDIT_TOOLBAR_SETTINGS() : PCB_EDIT_TOOLBAR_SETTINGS() :
TOOLBAR_SETTINGS( "pcbnew" ) TOOLBAR_SETTINGS( "pcbnew-toolbars" )
{} {}
~PCB_EDIT_TOOLBAR_SETTINGS() {} ~PCB_EDIT_TOOLBAR_SETTINGS() {}