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 ) );
208 auto hasPrefix = [&](
const char* aPrefix ) ->
bool
210 return name.rfind( aPrefix, 0 ) == 0;
215 if( hasPrefix(
"3DViewer." ) )
222 if( hasPrefix(
"common." ) )
240 default:
return false;
251 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
256 if( !tbConfig.has_value() )
275 wxArrayString tbChoices;
281 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
286 if( !tbConfig.has_value() )
296 wxString::Format(
"Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
298 tbChoices.Add( tbName->second );
329 if( currentTb.has_value() )
332 std::set<std::string> seenControls;
336 auto& items =
config.m_toolbarItems;
338 items.erase( std::remove_if( items.begin(), items.end(),
341 if( item.m_Type != TOOLBAR_ITEM_TYPE::CONTROL )
344 return !seenControls.insert( item.m_ControlName ).second;
362 wxTreeItemIdValue mainCookie;
369 while( mainId.IsOk() )
371 wxTreeItemData* treeData =
m_toolbarTree->GetItemData( mainId );
375 wxCHECK2( tbData,
continue );
400 wxTreeItemIdValue childCookie;
401 wxTreeItemId childId =
m_toolbarTree->GetFirstChild( mainId, childCookie );
403 while( childId.IsOk() )
405 wxTreeItemData* childTreeData =
m_toolbarTree->GetItemData( childId );
409 wxCHECK2( childTbData,
break );
411 switch( childTbData->
GetType() )
417 wxASSERT_MSG(
false,
"Invalid entry in a group" );
425 childId =
m_toolbarTree->GetNextChild( mainId, childCookie );
429 config.AppendGroup( grpConfig );
462 switch( item.m_Type )
468 m_toolbarTree->AppendItem( root,
_(
"Separator" ), -1, -1, sepTreeItem );
476 spacerTreeItem->
SetSize( item.m_Size );
477 m_toolbarTree->AppendItem( root, wxString::Format(
_(
"Spacer: %i" ), item.m_Size ), -1, -1,
488 wxASSERT_MSG(
false, wxString::Format(
"Unable to find control %s", item.m_ControlName ) );
494 controlTreeItem->
SetControl( controlIter->second );
495 m_toolbarTree->AppendItem( root, controlIter->second->GetUiName(), -1, -1, controlTreeItem );
506 wxASSERT_MSG(
false, wxString::Format(
"Unable to find tool %s", item.m_ActionName ) );
514 toolTreeItem->
SetAction( toolIter->second );
520 imgIdx = imgMap->second;
522 m_toolbarTree->AppendItem( root, toolIter->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
530 groupTreeItem->
SetName( item.m_GroupName );
532 wxTreeItemId groupId =
m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1, groupTreeItem );
533 bool haveVisibleGroupItems =
false;
542 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.
m_ActionName ) );
550 toolTreeItem->
SetAction( toolMap->second );
556 imgIdx = imgMap->second;
558 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
560 haveVisibleGroupItems =
true;
563 if( !haveVisibleGroupItems )
573 wxTreeItemIdValue temp;
574 wxTreeItemId firstItem =
m_toolbarTree->GetFirstChild( root, temp );
576 if( firstItem.IsOk() )
586 const int c_defSize = 24;
596 m_actionsList->InsertColumn( 0,
"", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
607 entry.
label = tool->GetFriendlyName();
608 entry.
tooltip = tool->GetDescription();
626 entry.
label = control->GetUiName();
627 entry.
tooltip = control->GetDescription();
629 entry.
search_text = entry.
label.Upper() + wxS(
" " ) + control->GetDescription().Upper();
636 return a.label.CmpNoCase( b.label ) < 0;
645 const wxString& aFilter )
const
647 if( aFilter.IsEmpty() )
650 return aEntry.
search_text.Contains( aFilter.Upper() );
673 item.SetText( entry.
label );
674 item.SetFont( listFont );
675 item.SetData(
static_cast<long>( idx ) );
682 m_actionsList->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
692 wxTreeItemId newItem;
698 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
702 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
704 if( secondParent.IsOk() )
732 wxString label = wxString::Format(
"Spacer: %i", treeItem->
GetSize() );
734 wxTreeItemId newItem;
740 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
745 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
747 if( secondParent.IsOk() )
754 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
773 wxTreeItemId newItem;
779 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
784 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
786 if( secondParent.IsOk() )
793 newItem =
m_toolbarTree->InsertItem( parent, selItem,
_(
"Separator" ), -1, -1, treeItem );
851 if( !item.IsOk() && prev.IsOk() )
874 long actionIdx =
m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
908 imgIdx = imgMap->second;
913 wxTreeItemId newItem;
923 newItem =
m_toolbarTree->AppendItem( selItem, entry.
label, imgIdx, -1, toolTreeItem );
928 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
929 newItem =
m_toolbarTree->InsertItem( parent, selItem, entry.
label, imgIdx, -1, toolTreeItem );
944 if( ++actionIdx < m_actionsList->GetItemCount() )
945 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
961 if( aEvent.Leaving() )
969 long item =
m_actionsList->HitTest( aEvent.GetPosition(), flags );
973 long entryIdx =
static_cast<long>(
m_actionsList->GetItemData( item ) );
975 if( entryIdx >= 0 && entryIdx <
static_cast<long>(
m_actionEntries.size() ) )
981 if(
const wxString& tooltip =
m_actionEntries[entryIdx].tooltip; tooltip.IsEmpty() )
1001 wxTreeItemId
id =
event.GetItem();
1005 wxTreeItemData* treeData =
m_toolbarTree->GetItemData(
id );
1009 switch( tbData->GetType() )
1039 if( currentTb.has_value() )
1042 int idx =
event.GetInt();
1054 wxCommandEvent
dummy;
1066 auto& items =
config.m_toolbarItems;
1068 items.erase( std::remove_if( items.begin(), items.end(),
1071 return item.m_Type == TOOLBAR_ITEM_TYPE::CONTROL
1072 && item.m_ControlName == aControlName;
1083 if( !rootId.IsOk() )
1086 std::vector<wxTreeItemId> toDelete;
1087 wxTreeItemIdValue cookie;
1089 for( wxTreeItemId
id =
m_toolbarTree->GetFirstChild( rootId, cookie );
1101 toDelete.push_back(
id );
1105 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.