Initial toolbar reconfigurability settings

This commit is contained in:
Ian McInerney 2025-02-13 22:41:32 +00:00
parent c24dbc17bf
commit df15db3236
5 changed files with 237 additions and 0 deletions

View File

@ -39,6 +39,7 @@
#include <tool/tool_event.h>
#include <tool/tool_interactive.h>
#include <tool/tool_manager.h>
#include <tool/ui/toolbar_configuration.h>
#include <widgets/bitmap_button.h>
#include <widgets/wx_aui_art_providers.h>
#include <wx/popupwin.h>
@ -237,6 +238,69 @@ ACTION_TOOLBAR::~ACTION_TOOLBAR()
}
void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig )
{
// Remove existing tools
Clear();
std::vector<std::string> items = aConfig.GetToolbarItems();
for( auto& toolName : items )
{
if( toolName == "separator" )
{
// Add a separator
AddScaledSeparator();
}
else if( toolName.starts_with( "group" ) )
{
// Add a group of items to the toolbar
std::optional<TOOLBAR_GROUP_CONFIG&> groupConfigOpt = aConfig.GetGroup( toolName );
if( !groupConfigOpt.has_value() )
{
wxASSERT_MSG( false, wxString::Format( "Unable to find group %s", toolName ) );
continue;
}
TOOLBAR_GROUP_CONFIG& groupConfig = groupConfigOpt.value();
std::vector<const TOOL_ACTION*> tools;
for( auto& groupItem : groupConfig.GetGroupItems() )
{
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindTool( toolName );
if( !tool )
{
wxASSERT_MSG( false, wxString::Format( "Unable to find group tool %s", toolName ) );
continue;
}
tools.push_back( action );
}
ACTION_GROUP* group = new ACTION_GROUP( groupConfig.GetName(), tools );
AddGroup( group );
}
else
{
// Assume anything else is a tool
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindTool( toolName );
if( !tool )
{
wxASSERT_MSG( false, wxString::Format( "Unable to find toolbar tool %s", toolName ) );
continue;
}
Add( action );
}
}
}
void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction )
{
wxASSERT_MSG( !aAction.CheckToolbarState( TOOLBAR_STATE::HIDDEN ),

View File

@ -0,0 +1,31 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* @author Ian McInerney
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <nlohmann/json.hpp>
#include <action_toolbar.h>
#include <tools/ui/toolbar_configuration.h>
///! Update the schema version whenever a migration is required
const int toolbarSchemaVersion = 1;

View File

@ -166,6 +166,13 @@ public:
std::vector<std::pair<wxString, bool>> actions;
};
struct TOOLBARS
{
TOOLBAR_CONFIGURATION m_HToolbarConfig;
TOOLBAR_CONFIGURATION m_VToolbarConfig;
TOOLBAR_CONFIGURATION m_optToolbarConfig;
}
APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion );
virtual ~APP_SETTINGS_BASE() {}
@ -195,6 +202,8 @@ public:
WINDOW_SETTINGS m_Window;
TOOLBARS m_Toolbars;
/// Active color theme name.
wxString m_ColorTheme;

View File

@ -39,6 +39,7 @@ class BITMAP_BUTTON;
class EDA_BASE_FRAME;
class TOOL_ACTION;
class TOOL_MANAGER;
class TOOLBAR_CONFIGURATION;
/**
* A group of actions that will be displayed together on a toolbar palette.
@ -265,6 +266,14 @@ public:
*/
void SelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
/**
* Replace the contents of this toolbar with the configuration given in
* @c aConfig.
*
* @param aConfig is the configuration to apply to the toolbar
*/
void ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig );
/**
* Update the toolbar item width of a control using its best size.
*

View File

@ -0,0 +1,124 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
* @author Ian McInerney
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef TOOLBAR_CONFIGURATION_H_
#define TOOLBAR_CONFIGURATION_H_
#include <optional>
#include <string>
#include <vector>
#include <settings/json_settings.h>
#include <tool/tool_action.h>
class KICOMMON_API TOOLBAR_GROUP_CONFIG
{
TOOLBAR_GROUP_CONFIG( const std::string& aName ) :
m_groupName( aName )
{
wxASSERT_MSG( aName.starts_with( "group" ), "Toolbar group names must start with \"group\"" );
}
const std::string& GetName() const
{
retrun m_groupName;
}
void AddAction( std::string aActionName )
{
m_groupItems.append( aActionName );
}
void AddAction( const TOOL_ACTION& aAction )
{
m_groupItems.append( aAction.GetName() );
}
std::vector<std::string> GetGroupItems() const
{
return m_groupItems;
}
private:
std::string m_groupName;
std::vector<std::string> m_groupItems;
};
class KICOMMON_API TOOLBAR_CONFIGURATION
{
TOOLBAR_CONFIGURATION() {}
virtual ~TOOLBAR_CONFIGURATION() {}
void AppendAction( std::string aActionName )
{
m_toolbarItems.append( aActionName );
}
void AppendAction( const TOOL_ACTION& aAction )
{
m_toolbarItems.append( aAction.GetName() );
}
void AppendSeparator()
{
m_toolbarItems.append( "separator" );
}
void AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup )
{
std::string& name = aGroup.GetName();
m_toolbarGroups[name] = aGroup;
m_toolbarItems.append( name );
}
std::vector<std::string> GetToolbarItems() const
{
return m_toolbarItems;
}
std::optional<TOOLBAR_GROUP_CONFIG&> GetGroup( const std::string& aGroupName )
{
for( auto& group : m_toolbarGroups )
{
if( group.GetName() == aGroupName )
return group;
}
return std::nullopt;
}
void Clear()
{
m_toolbarItems.clear();
m_toolbarGroups.clear();
}
private:
std::vector<std::string> m_toolbarItems;
std::vector<TOOLBAR_GROUP_CONFIG> m_toolbarGroups;
};
#endif /* TOOLBAR_CONFIGURATION_H_ */