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 ) :
142 for(
auto& tool : aTools )
145 for(
auto& control : aControls )
176 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." ) )
227 return !framePrefix.empty() && hasPrefix( framePrefix.c_str() );
237 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
242 if( !tbConfig.has_value() )
261 wxArrayString tbChoices;
267 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
272 if( !tbConfig.has_value() )
282 wxString::Format(
"Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
284 tbChoices.Add( tbName->second );
315 if( currentTb.has_value() )
318 std::set<std::string> seenControls;
322 auto& items =
config.m_toolbarItems;
324 items.erase( std::remove_if( items.begin(), items.end(),
327 if( item.m_Type != TOOLBAR_ITEM_TYPE::CONTROL )
330 return !seenControls.insert( item.m_ControlName ).second;
348 wxTreeItemIdValue mainCookie;
355 while( mainId.IsOk() )
357 wxTreeItemData* treeData =
m_toolbarTree->GetItemData( mainId );
361 wxCHECK2( tbData,
continue );
386 wxTreeItemIdValue childCookie;
387 wxTreeItemId childId =
m_toolbarTree->GetFirstChild( mainId, childCookie );
389 while( childId.IsOk() )
391 wxTreeItemData* childTreeData =
m_toolbarTree->GetItemData( childId );
395 wxCHECK2( childTbData,
break );
397 switch( childTbData->
GetType() )
403 wxASSERT_MSG(
false,
"Invalid entry in a group" );
411 childId =
m_toolbarTree->GetNextChild( mainId, childCookie );
416 config.AppendGroup( grpConfig );
449 switch( item.m_Type )
455 m_toolbarTree->AppendItem( root,
_(
"Separator" ), -1, -1, sepTreeItem );
463 spacerTreeItem->
SetSize( item.m_Size );
464 m_toolbarTree->AppendItem( root, wxString::Format(
_(
"Spacer: %i" ), item.m_Size ), -1, -1,
475 wxASSERT_MSG(
false, wxString::Format(
"Unable to find control %s", item.m_ControlName ) );
481 controlTreeItem->
SetControl( controlIter->second );
482 m_toolbarTree->AppendItem( root, controlIter->second->GetUiName(), -1, -1, controlTreeItem );
493 wxASSERT_MSG(
false, wxString::Format(
"Unable to find tool %s", item.m_ActionName ) );
501 toolTreeItem->
SetAction( toolIter->second );
507 imgIdx = imgMap->second;
509 m_toolbarTree->AppendItem( root, toolIter->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
517 groupTreeItem->
SetName( item.m_GroupName );
519 wxTreeItemId groupId =
m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1, groupTreeItem );
520 bool haveVisibleGroupItems =
false;
529 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.
m_ActionName ) );
537 toolTreeItem->
SetAction( toolMap->second );
543 imgIdx = imgMap->second;
545 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
547 haveVisibleGroupItems =
true;
550 if( !haveVisibleGroupItems )
560 wxTreeItemIdValue temp;
561 wxTreeItemId firstItem =
m_toolbarTree->GetFirstChild( root, temp );
563 if( firstItem.IsOk() )
573 const int c_defSize = 24;
583 m_actionsList->InsertColumn( 0,
"", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
594 entry.
label = tool->GetFriendlyName();
595 entry.
tooltip = tool->GetDescription();
613 entry.
label = control->GetUiName();
614 entry.
tooltip = control->GetDescription();
616 entry.
search_text = entry.
label.Upper() + wxS(
" " ) + control->GetDescription().Upper();
623 return a.label.CmpNoCase( b.label ) < 0;
632 const wxString& aFilter )
const
634 if( aFilter.IsEmpty() )
637 return aEntry.
search_text.Contains( aFilter.Upper() );
660 item.SetText( entry.
label );
661 item.SetFont( listFont );
662 item.SetData(
static_cast<long>( idx ) );
669 m_actionsList->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
679 wxTreeItemId newItem;
685 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
689 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
691 if( secondParent.IsOk() )
719 wxString label = wxString::Format(
"Spacer: %i", treeItem->
GetSize() );
721 wxTreeItemId newItem;
727 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
732 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
734 if( secondParent.IsOk() )
741 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
760 wxTreeItemId newItem;
766 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
771 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
773 if( secondParent.IsOk() )
780 newItem =
m_toolbarTree->InsertItem( parent, selItem,
_(
"Separator" ), -1, -1, treeItem );
838 if( !item.IsOk() && prev.IsOk() )
861 long actionIdx =
m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
895 imgIdx = imgMap->second;
900 wxTreeItemId newItem;
910 newItem =
m_toolbarTree->AppendItem( selItem, entry.
label, imgIdx, -1, toolTreeItem );
915 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
916 newItem =
m_toolbarTree->InsertItem( parent, selItem, entry.
label, imgIdx, -1, toolTreeItem );
931 if( ++actionIdx < m_actionsList->GetItemCount() )
932 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
948 if( aEvent.Leaving() )
956 long item =
m_actionsList->HitTest( aEvent.GetPosition(), flags );
960 long entryIdx =
static_cast<long>(
m_actionsList->GetItemData( item ) );
962 if( entryIdx >= 0 && entryIdx <
static_cast<long>(
m_actionEntries.size() ) )
968 if(
const wxString& tooltip =
m_actionEntries[entryIdx].tooltip; tooltip.IsEmpty() )
988 wxTreeItemId
id =
event.GetItem();
996 switch( tbData->GetType() )
1017 wxTreeItemId
id =
event.GetItem();
1034 if( event.IsEditCancelled() )
1037 wxTreeItemId
id =
event.GetItem();
1043 if( event.GetLabel().Strip( wxString::both ).IsEmpty() )
1049 tbData->SetName( event.GetLabel() );
1062 if( currentTb.has_value() )
1065 int idx =
event.GetInt();
1077 wxCommandEvent
dummy;
1089 auto& items =
config.m_toolbarItems;
1091 items.erase( std::remove_if( items.begin(), items.end(),
1094 return item.m_Type == TOOLBAR_ITEM_TYPE::CONTROL
1095 && item.m_ControlName == aControlName;
1106 if( !rootId.IsOk() )
1109 std::vector<wxTreeItemId> toDelete;
1110 wxTreeItemIdValue cookie;
1112 for( wxTreeItemId
id =
m_toolbarTree->GetFirstChild( rootId, cookie );
1124 toDelete.push_back(
id );
1128 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.