31#include <magic_enum.hpp>
32#include <wx/listctrl.h>
133 const std::vector<TOOL_ACTION*>& aTools,
134 const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls ) :
174 m_actionFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
206 [&](
const char* aPrefix ) ->
bool
208 return name.rfind( aPrefix, 0 ) == 0;
213 if( hasPrefix(
"3DViewer." ) )
220 if( hasPrefix(
"common." ) )
225 return !framePrefix.empty() && hasPrefix( framePrefix.c_str() );
235 for(
const TOOLBAR_LOC& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
238 std::optional<TOOLBAR_CONFIGURATION> tbConfig =
m_appTbSettings->DefaultToolbarConfig( tb );
240 if( !tbConfig.has_value() )
259 wxArrayString tbChoices;
265 for(
const TOOLBAR_LOC& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
268 std::optional<TOOLBAR_CONFIGURATION> tbConfig =
m_appTbSettings->GetToolbarConfig( tb );
270 if( !tbConfig.has_value() )
280 wxString::Format(
"Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
282 tbChoices.Add( tbName->second );
313 if( currentTb.has_value() )
316 std::set<std::string> seenControls;
320 auto& items =
config.m_toolbarItems;
322 items.erase( std::remove_if( items.begin(), items.end(),
325 if( item.m_Type != TOOLBAR_ITEM_TYPE::CONTROL )
328 return !seenControls.insert( item.m_ControlName ).second;
346 wxTreeItemIdValue mainCookie;
353 while( mainId.IsOk() )
355 wxTreeItemData* treeData =
m_toolbarTree->GetItemData( mainId );
359 wxCHECK2( tbData,
continue );
384 wxTreeItemIdValue childCookie;
385 wxTreeItemId childId =
m_toolbarTree->GetFirstChild( mainId, childCookie );
387 while( childId.IsOk() )
389 wxTreeItemData* childTreeData =
m_toolbarTree->GetItemData( childId );
393 wxCHECK2( childTbData,
break );
395 switch( childTbData->
GetType() )
401 wxASSERT_MSG(
false,
"Invalid entry in a group" );
409 childId =
m_toolbarTree->GetNextChild( mainId, childCookie );
414 config.AppendGroup( grpConfig );
447 switch( item.m_Type )
453 m_toolbarTree->AppendItem( root,
_(
"Separator" ), -1, -1, sepTreeItem );
461 spacerTreeItem->
SetSize( item.m_Size );
462 m_toolbarTree->AppendItem( root, wxString::Format(
_(
"Spacer: %i" ), item.m_Size ), -1, -1,
473 wxASSERT_MSG(
false, wxString::Format(
"Unable to find control %s", item.m_ControlName ) );
479 controlTreeItem->
SetControl( controlIter->second );
480 m_toolbarTree->AppendItem( root, controlIter->second->GetUiName(), -1, -1, controlTreeItem );
491 wxASSERT_MSG(
false, wxString::Format(
"Unable to find tool %s", item.m_ActionName ) );
499 toolTreeItem->
SetAction( toolIter->second );
505 imgIdx = imgMap->second;
507 m_toolbarTree->AppendItem( root, toolIter->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
515 groupTreeItem->
SetName( item.m_GroupName );
517 wxTreeItemId groupId =
m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1, groupTreeItem );
518 bool haveVisibleGroupItems =
false;
527 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.
m_ActionName ) );
535 toolTreeItem->
SetAction( toolMap->second );
541 imgIdx = imgMap->second;
543 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
545 haveVisibleGroupItems =
true;
548 if( !haveVisibleGroupItems )
558 wxTreeItemIdValue temp;
559 wxTreeItemId firstItem =
m_toolbarTree->GetFirstChild( root, temp );
561 if( firstItem.IsOk() )
571 const int c_defSize = 24;
581 m_actionsList->InsertColumn( 0,
"", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
592 entry.
label = tool->GetFriendlyName();
593 entry.
tooltip = tool->GetDescription();
611 entry.
label = control->GetUiName();
612 entry.
tooltip = control->GetDescription();
614 entry.
search_text = entry.
label.Upper() + wxS(
" " ) + control->GetDescription().Upper();
621 return a.label.CmpNoCase( b.label ) < 0;
630 const wxString& aFilter )
const
632 if( aFilter.IsEmpty() )
635 return aEntry.
search_text.Contains( aFilter.Upper() );
658 item.SetText( entry.
label );
659 item.SetFont( listFont );
660 item.SetData(
static_cast<long>( idx ) );
667 m_actionsList->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
677 wxTreeItemId newItem;
683 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
687 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
689 if( secondParent.IsOk() )
716 wxString label = wxString::Format(
"Spacer: %i", treeItem->
GetSize() );
718 wxTreeItemId newItem;
724 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
729 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
731 if( secondParent.IsOk() )
738 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
757 wxTreeItemId newItem;
763 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
768 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
770 if( secondParent.IsOk() )
777 newItem =
m_toolbarTree->InsertItem( parent, selItem,
_(
"Separator" ), -1, -1, treeItem );
835 if( !item.IsOk() && prev.IsOk() )
858 long actionIdx =
m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
892 imgIdx = imgMap->second;
897 wxTreeItemId newItem;
906 newItem =
m_toolbarTree->AppendItem( selItem, entry.
label, imgIdx, -1, toolTreeItem );
911 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
912 newItem =
m_toolbarTree->InsertItem( parent, selItem, entry.
label, imgIdx, -1, toolTreeItem );
927 if( ++actionIdx < m_actionsList->GetItemCount() )
928 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
944 if( aEvent.Leaving() )
952 long item =
m_actionsList->HitTest( aEvent.GetPosition(), flags );
956 long entryIdx =
static_cast<long>(
m_actionsList->GetItemData( item ) );
958 if( entryIdx >= 0 && entryIdx <
static_cast<long>(
m_actionEntries.size() ) )
964 if(
const wxString& tooltip =
m_actionEntries[entryIdx].tooltip; tooltip.IsEmpty() )
984 wxTreeItemId
id =
event.GetItem();
992 switch( tbData->GetType() )
1013 wxTreeItemId
id =
event.GetItem();
1030 if( event.IsEditCancelled() )
1033 wxTreeItemId
id =
event.GetItem();
1039 if( event.GetLabel().Strip( wxString::both ).IsEmpty() )
1045 tbData->SetName( event.GetLabel() );
1058 if( currentTb.has_value() )
1061 int idx =
event.GetInt();
1073 wxCommandEvent
dummy;
1085 auto& items =
config.m_toolbarItems;
1087 items.erase( std::remove_if( items.begin(), items.end(),
1090 return item.m_Type == TOOLBAR_ITEM_TYPE::CONTROL
1091 && item.m_ControlName == aControlName;
1102 if( !rootId.IsOk() )
1105 std::vector<wxTreeItemId> toDelete;
1106 wxTreeItemIdValue cookie;
1108 for( wxTreeItemId
id =
m_toolbarTree->GetFirstChild( rootId, cookie );
1119 toDelete.push_back(
id );
1123 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
static std::string FrameNamespacePrefix(FRAME_T aFrameType)
Return the action-name namespace prefix (e.g.
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.
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.