kicad-source/include/tool/ui/toolbar_configuration.h
2025-02-28 01:57:37 +00:00

124 lines
3.2 KiB
C++

/*
* 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_ */