34#include <magic_enum.hpp>
35#include <wx/listctrl.h>
136 const std::vector<TOOL_ACTION*>& aTools,
137 const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls ) :
145 for(
auto& tool : aTools )
148 for(
auto& control : aControls )
179 m_actionFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
211 auto hasPrefix = [&](
const char* aPrefix ) ->
bool
213 return name.rfind( aPrefix, 0 ) == 0;
218 if( hasPrefix(
"3DViewer." ) )
225 if( hasPrefix(
"common." ) )
243 default:
return false;
254 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
259 if( !tbConfig.has_value() )
278 wxArrayString tbChoices;
284 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
289 if( !tbConfig.has_value() )
299 wxString::Format(
"Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
301 tbChoices.Add( tbName->second );
332 if( currentTb.has_value() )
335 std::set<std::string> seenControls;
339 auto& items =
config.m_toolbarItems;
341 items.erase( std::remove_if( items.begin(), items.end(),
344 if( item.m_Type != TOOLBAR_ITEM_TYPE::CONTROL )
347 return !seenControls.insert( item.m_ControlName ).second;
365 wxTreeItemIdValue mainCookie;
372 while( mainId.IsOk() )
374 wxTreeItemData* treeData =
m_toolbarTree->GetItemData( mainId );
378 wxCHECK2( tbData,
continue );
403 wxTreeItemIdValue childCookie;
404 wxTreeItemId childId =
m_toolbarTree->GetFirstChild( mainId, childCookie );
406 while( childId.IsOk() )
408 wxTreeItemData* childTreeData =
m_toolbarTree->GetItemData( childId );
412 wxCHECK2( childTbData,
break );
414 switch( childTbData->
GetType() )
420 wxASSERT_MSG(
false,
"Invalid entry in a group" );
428 childId =
m_toolbarTree->GetNextChild( mainId, childCookie );
433 config.AppendGroup( grpConfig );
466 switch( item.m_Type )
472 m_toolbarTree->AppendItem( root,
_(
"Separator" ), -1, -1, sepTreeItem );
480 spacerTreeItem->
SetSize( item.m_Size );
481 m_toolbarTree->AppendItem( root, wxString::Format(
_(
"Spacer: %i" ), item.m_Size ), -1, -1,
492 wxASSERT_MSG(
false, wxString::Format(
"Unable to find control %s", item.m_ControlName ) );
498 controlTreeItem->
SetControl( controlIter->second );
499 m_toolbarTree->AppendItem( root, controlIter->second->GetUiName(), -1, -1, controlTreeItem );
510 wxASSERT_MSG(
false, wxString::Format(
"Unable to find tool %s", item.m_ActionName ) );
518 toolTreeItem->
SetAction( toolIter->second );
524 imgIdx = imgMap->second;
526 m_toolbarTree->AppendItem( root, toolIter->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
534 groupTreeItem->
SetName( item.m_GroupName );
536 wxTreeItemId groupId =
m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1, groupTreeItem );
537 bool haveVisibleGroupItems =
false;
546 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.
m_ActionName ) );
554 toolTreeItem->
SetAction( toolMap->second );
560 imgIdx = imgMap->second;
562 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
564 haveVisibleGroupItems =
true;
567 if( !haveVisibleGroupItems )
577 wxTreeItemIdValue temp;
578 wxTreeItemId firstItem =
m_toolbarTree->GetFirstChild( root, temp );
580 if( firstItem.IsOk() )
590 const int c_defSize = 24;
600 m_actionsList->InsertColumn( 0,
"", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
611 entry.
label = tool->GetFriendlyName();
612 entry.
tooltip = tool->GetDescription();
630 entry.
label = control->GetUiName();
631 entry.
tooltip = control->GetDescription();
633 entry.
search_text = entry.
label.Upper() + wxS(
" " ) + control->GetDescription().Upper();
640 return a.label.CmpNoCase( b.label ) < 0;
649 const wxString& aFilter )
const
651 if( aFilter.IsEmpty() )
654 return aEntry.
search_text.Contains( aFilter.Upper() );
677 item.SetText( entry.
label );
678 item.SetFont( listFont );
679 item.SetData(
static_cast<long>( idx ) );
686 m_actionsList->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
696 wxTreeItemId newItem;
702 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
706 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
708 if( secondParent.IsOk() )
736 wxString label = wxString::Format(
"Spacer: %i", treeItem->
GetSize() );
738 wxTreeItemId newItem;
744 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
749 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
751 if( secondParent.IsOk() )
758 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
777 wxTreeItemId newItem;
783 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
788 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
790 if( secondParent.IsOk() )
797 newItem =
m_toolbarTree->InsertItem( parent, selItem,
_(
"Separator" ), -1, -1, treeItem );
855 if( !item.IsOk() && prev.IsOk() )
878 long actionIdx =
m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
912 imgIdx = imgMap->second;
917 wxTreeItemId newItem;
927 newItem =
m_toolbarTree->AppendItem( selItem, entry.
label, imgIdx, -1, toolTreeItem );
932 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
933 newItem =
m_toolbarTree->InsertItem( parent, selItem, entry.
label, imgIdx, -1, toolTreeItem );
948 if( ++actionIdx < m_actionsList->GetItemCount() )
949 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
965 if( aEvent.Leaving() )
973 long item =
m_actionsList->HitTest( aEvent.GetPosition(), flags );
977 long entryIdx =
static_cast<long>(
m_actionsList->GetItemData( item ) );
979 if( entryIdx >= 0 && entryIdx <
static_cast<long>(
m_actionEntries.size() ) )
985 if(
const wxString& tooltip =
m_actionEntries[entryIdx].tooltip; tooltip.IsEmpty() )
1005 wxTreeItemId
id =
event.GetItem();
1009 wxTreeItemData* treeData =
m_toolbarTree->GetItemData(
id );
1013 switch( tbData->GetType() )
1034 wxTreeItemId
id =
event.GetItem();
1051 if( event.IsEditCancelled() )
1054 wxTreeItemId
id =
event.GetItem();
1060 if( event.GetLabel().Strip( wxString::both ).IsEmpty() )
1066 tbData->SetName( event.GetLabel() );
1079 if( currentTb.has_value() )
1082 int idx =
event.GetInt();
1094 wxCommandEvent
dummy;
1106 auto& items =
config.m_toolbarItems;
1108 items.erase( std::remove_if( items.begin(), items.end(),
1111 return item.m_Type == TOOLBAR_ITEM_TYPE::CONTROL
1112 && item.m_ControlName == aControlName;
1123 if( !rootId.IsOk() )
1126 std::vector<wxTreeItemId> toDelete;
1127 wxTreeItemIdValue cookie;
1129 for( wxTreeItemId
id =
m_toolbarTree->GetFirstChild( rootId, cookie );
1141 toDelete.push_back(
id );
1145 for(
const wxTreeItemId&
id : toDelete )
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Constructs and returns a bitmap bundle for the given icon ID, with the default bitmap size being aDef...
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
static TOOL_ACTION zoomRedraw
static TOOL_ACTION zoomOutCenter
static TOOL_ACTION zoomFitScreen
static TOOL_ACTION zoomInCenter
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ FRAME_SCH_SYMBOL_EDITOR
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
std::vector< FAB_LAYER_COLOR > dummy
ACTION_TOOLBAR_CONTROL * control
Functions to provide common constants and other functions to assist in making a consistent UI.