KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_toolbar_customization.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <bitmaps.h>
32
33#include <magic_enum.hpp>
34#include <wx/listctrl.h>
35#include <wx/menu.h>
36#include <widgets/ui_common.h>
37
38// Simple IDs for the split button menu
39enum
40{
41 ID_SEPARATOR_MENU = ( wxID_HIGHEST + 5 ),
44};
45
46
47static std::map<TOOLBAR_LOC, wxString> s_toolbarNameMap = {
48 { TOOLBAR_LOC::LEFT, _( "Left" ) },
49 { TOOLBAR_LOC::RIGHT, _( "Right" ) },
50 { TOOLBAR_LOC::TOP_MAIN, _( "Top main" ) },
51 { TOOLBAR_LOC::TOP_AUX, _( "Top auxiliary" ) }
52};
53
54
55class TOOLBAR_TREE_ITEM_DATA : public wxTreeItemData
56{
57public:
59 m_type( TOOLBAR_ITEM_TYPE::SEPARATOR ), // Init m_type to something
60 m_action( nullptr ),
61 m_control( nullptr ),
62 m_size( 0 )
63 { }
64
66 m_type( aType ),
67 m_action( nullptr ),
68 m_control( nullptr ),
69 m_size( 0 )
70 { }
71
73 m_type( aType ),
74 m_action( nullptr ),
75 m_control( nullptr ),
76 m_size( aSize )
77 {
78 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
79 }
80
81 TOOLBAR_TREE_ITEM_DATA( TOOLBAR_ITEM_TYPE aType, wxString aName ) :
82 m_type( aType ),
83 m_action( nullptr ),
84 m_control( nullptr ),
85 m_size( 0 ),
86 m_name( aName )
87 {
88 wxASSERT( aType == TOOLBAR_ITEM_TYPE::CONTROL
89 || aType == TOOLBAR_ITEM_TYPE::TB_GROUP );
90 }
91
92 void SetAction( TOOL_ACTION* aAction ) { m_action = aAction; }
94 {
95 wxASSERT( m_type == TOOLBAR_ITEM_TYPE::TOOL );
96 return m_action;
97 }
98
99 void SetControl( ACTION_TOOLBAR_CONTROL* aControl ) { m_control = aControl; }
101 {
102 wxASSERT( m_type == TOOLBAR_ITEM_TYPE::CONTROL );
103 return m_control;
104 }
105
106 void SetName( const wxString& aName ) { m_name = aName; }
107 const wxString& GetName() const { return m_name; }
108
109 void SetSize( int aSize ) { m_size = aSize; }
110 int GetSize() const { return m_size; }
111
112 TOOLBAR_ITEM_TYPE GetType() const { return m_type; }
113
114private:
115 // Item type
117
118 // Tool properties (can be one or the other, but never both)
121
122 // Spacer properties
124
125 // Group/control properties
126 wxString m_name;
127};
128
129
131 TOOLBAR_SETTINGS* aTbSettings,
132 const std::vector<TOOL_ACTION*>& aTools,
133 const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls ) :
135 m_appSettings( aCfg ),
136 m_appTbSettings( aTbSettings ),
138 m_firstControlId( -1 )
139{
140 // Copy the tools and controls into the internal maps
141 for( auto& tool : aTools )
142 m_availableTools.emplace( tool->GetName(), tool );
143
144 for( auto& control : aControls )
145 m_availableControls.emplace( control->GetName(), control );
146
147 // Configure the Ui elements
152
153 m_insertButton->SetLabel( _( "Insert Separator" ) );
154 //m_insertButton->SetWidthPadding( 4 );
155
156 // Populate the browse library options
157 wxMenu* insertMenu = m_insertButton->GetSplitButtonMenu();
158
159 insertMenu->Append( ID_SPACER_MENU, _( "Insert Spacer" ) );
160 insertMenu->Append( ID_GROUP_MENU, _( "Insert Group" ) );
161
162 insertMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_TOOLBAR_CUSTOMIZATION::onSpacerPress,
163 this, ID_SPACER_MENU );
164 insertMenu->Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_TOOLBAR_CUSTOMIZATION::onGroupPress,
165 this, ID_GROUP_MENU );
166
167 // This is the button only press for the browse button instead of the menu
169
170 // TODO (ISM): Enable draging
171 m_btnToolMoveDown->Enable( false );
172 m_btnToolMoveUp->Enable( false );
173}
174
175
179
180
182{
183 // Go over every toolbar and initialize things
184 for( auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
185 {
186 // Create a shadow toolbar
187 auto tbConfig = m_appTbSettings->DefaultToolbarConfig( tb );
188
189 if( tbConfig.has_value() )
190 m_toolbars[tb] = tbConfig.value();
191 }
192
193 // Populate the toolbar view with the default toolbar
194 m_tbChoice->SetSelection( 0 );
195
196 auto firstTb = magic_enum::enum_cast<TOOLBAR_LOC>( 0 );
197
198 if( firstTb.has_value() )
199 m_currentToolbar = firstTb.value();
200
202
203}
204
205
207{
208 wxArrayString tbChoices;
209
210 // Go over every toolbar and initialize things
211 for( auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
212 {
213 // Create a shadow toolbar
214 auto tbConfig = m_appTbSettings->GetToolbarConfig( tb );
215
216 if( tbConfig.has_value() )
217 m_toolbars.emplace( tb, tbConfig.value() );
218
219 // Setup the UI name
220 const auto& tbName = s_toolbarNameMap.find( tb );
221
222 wxASSERT_MSG( tbName != s_toolbarNameMap.end(),
223 wxString::Format( "Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
224
225 tbChoices.Add( tbName->second );
226 }
227
228 m_tbChoice->Set( tbChoices );
229
230 // Always populate the actions before the toolbars, that way the icons are available
232
233 // Populate the toolbar view
234 m_tbChoice->SetSelection( 0 );
235
236 auto firstTb = magic_enum::enum_cast<TOOLBAR_LOC>( 0 );
237
238 if( firstTb.has_value() )
239 m_currentToolbar = firstTb.value();
240
242
243 // Sync the enable/disable control
244 enableCustomControls( m_appSettings->m_CustomToolbars );
245 m_customToolbars->SetValue( m_appSettings->m_CustomToolbars );
246
247 return true;
248}
249
250
252{
253 m_appSettings->m_CustomToolbars = m_customToolbars->GetValue();
254
255 // Store the current toolbar
256 std::optional<TOOLBAR_CONFIGURATION> currentTb = parseToolbarTree();
257
258 if( currentTb.has_value() )
259 m_toolbars[m_currentToolbar] = currentTb.value();
260
261 // Write the shadow toolbars with changes back to the app toolbar settings
262 for( const auto& [loc, config] : m_toolbars )
263 m_appTbSettings->SetStoredToolbarConfig( loc, config );
264
265 return true;
266}
267
268
269std::optional<TOOLBAR_CONFIGURATION> PANEL_TOOLBAR_CUSTOMIZATION::parseToolbarTree()
270{
272
273 wxTreeItemId mainId;
274 wxTreeItemId rootId = m_toolbarTree->GetRootItem();
275 wxTreeItemIdValue mainCookie;
276
277 if( !rootId.IsOk() )
278 return std::nullopt;
279
280 mainId = m_toolbarTree->GetFirstChild( rootId, mainCookie );
281
282 while( mainId.IsOk() )
283 {
284 wxTreeItemData* treeData = m_toolbarTree->GetItemData( mainId );
285
286 TOOLBAR_TREE_ITEM_DATA* tbData = dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( treeData );
287
288 wxCHECK2( tbData, continue );
289
290 switch( tbData->GetType() )
291 {
293 config.AppendSpacer( tbData->GetSize() );
294 break;
295
297 config.AppendSeparator();
298 break;
299
301 config.AppendControl( tbData->GetControl()->GetName() );
302 break;
303
305 config.AppendAction( *( tbData->GetAction() ) );
306 break;
307
309 TOOLBAR_GROUP_CONFIG grpConfig( tbData->GetName() );
310
311 if( m_toolbarTree->ItemHasChildren( mainId ) )
312 {
313 wxTreeItemIdValue childCookie;
314 wxTreeItemId childId = m_toolbarTree->GetFirstChild( mainId, childCookie );
315
316 while( childId.IsOk() )
317 {
318 wxTreeItemData* childTreeData = m_toolbarTree->GetItemData( childId );
319
320 TOOLBAR_TREE_ITEM_DATA* childTbData = dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( childTreeData );
321
322 wxCHECK2( childTbData, break );
323
324 switch( childTbData->GetType() )
325 {
330 wxASSERT_MSG( false, "Invalid entry in a group" );
331 break;
332
334 grpConfig.AddAction( *( childTbData->GetAction() ) );
335 break;
336 }
337
338 childId = m_toolbarTree->GetNextChild( mainId, childCookie );
339 }
340 }
341
342 config.AppendGroup( grpConfig );
343 }
344
345 mainId = m_toolbarTree->GetNextChild( rootId, mainCookie );
346 }
347
348 return config;
349}
350
351
353{
354 m_toolbarTree->DeleteAllItems();
356
357 const auto& it = m_toolbars.find( m_currentToolbar );
358
359 if( it == m_toolbars.end() )
360 {
361 // Disable the controls and bail out - no toolbar here
362 enableToolbarControls( false );
363 return;
364 }
365
366 // Ensure the controls are enabled
367 enableToolbarControls( true );
368
369 TOOLBAR_CONFIGURATION toolbar = it->second;
370
371 wxTreeItemId root = m_toolbarTree->AddRoot( "Toolbar" );
372
373 for( const TOOLBAR_ITEM& item : toolbar.GetToolbarItems() )
374 {
375 switch( item.m_Type )
376 {
378 {
379 // Add a separator
381 m_toolbarTree->AppendItem( root, _( "Separator" ), -1, -1, sepTreeItem );
382 break;
383 }
384
386 {
387 // Add a spacer
389 spacerTreeItem->SetSize( item.m_Size );
390 m_toolbarTree->AppendItem( root, wxString::Format( _( "Spacer: %i" ), item.m_Size ), -1, -1,
391 spacerTreeItem );
392 break;
393 }
394
396 {
397 auto controlIter = m_availableControls.find( item.m_ControlName );
398
399 if( controlIter == m_availableControls.end() )
400 {
401 wxASSERT_MSG( false, wxString::Format( "Unable to find control %s", item.m_ControlName ) );
402 continue;
403 }
404
405 // Add a control
407 controlTreeItem->SetControl( controlIter->second );
408 m_toolbarTree->AppendItem( root, controlIter->second->GetUiName(), -1, -1, controlTreeItem );
409 break;
410 }
411
413 {
414 // Add a tool
415 auto toolIter = m_availableTools.find( item.m_ActionName );
416
417 if( toolIter == m_availableTools.end() )
418 {
419 wxASSERT_MSG( false, wxString::Format( "Unable to find tool %s", item.m_ActionName ) );
420 continue;
421 }
422
424 toolTreeItem->SetAction( toolIter->second );
425
426 int imgIdx = -1;
427 auto imgMap = m_actionImageListMap.find( item.m_ActionName );
428
429 if( imgMap != m_actionImageListMap.end() )
430 imgIdx = imgMap->second;
431
432 m_toolbarTree->AppendItem( root, toolIter->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
433 break;
434 }
435
437 {
438 // Add a group of items to the toolbar
440 groupTreeItem->SetName( item.m_GroupName );
441
442 wxTreeItemId groupId = m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1, groupTreeItem );
443
444 // Add the elements below the group
445 for( const TOOLBAR_ITEM& groupItem : item.m_GroupItems )
446 {
447 auto toolMap = m_availableTools.find( groupItem.m_ActionName );
448
449 if( toolMap == m_availableTools.end() )
450 {
451 wxASSERT_MSG( false, wxString::Format( "Unable to find group tool %s", groupItem.m_ActionName ) );
452 continue;
453 }
454
456 toolTreeItem->SetAction( toolMap->second );
457
458 int imgIdx = -1;
459 auto imgMap = m_actionImageListMap.find( groupItem.m_ActionName );
460
461 if( imgMap != m_actionImageListMap.end() )
462 imgIdx = imgMap->second;
463
464 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
465 }
466
467 break;
468 }
469 }
470 }
471
472 m_toolbarTree->ExpandAll();
473
474 wxTreeItemIdValue temp;
475 wxTreeItemId firstItem = m_toolbarTree->GetFirstChild( root, temp );
476
477 if( firstItem.IsOk() )
478 {
479 m_toolbarTree->SelectItem( firstItem );
480 m_toolbarTree->EnsureVisible( firstItem );
481 }
482}
483
484
486{
487 const int c_defSize = 24; // Default icon size for toolbar actions
488
489 // Clear all existing information for the actions
490 m_actionImageListMap.clear();
492
493 // Prep the control
494 m_actionsList->DeleteAllItems();
495 m_actionsList->DeleteAllColumns();
496 m_actionsList->InsertColumn( 0, "", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
497
498 wxFont listFont = KIUI::GetInfoFont( this );
499
500 int itemIdx = 0;
501
502 for( const auto& [k, tool] : m_availableTools )
503 {
504 if( tool->CheckToolbarState( TOOLBAR_STATE::HIDDEN ) )
505 continue;
506
507 wxListItem item;
508 item.SetText( tool->GetFriendlyName() );
509 item.SetFont( listFont );
510 item.SetData( static_cast<void*>( tool ) );
511 item.SetId( itemIdx++ );
512
513 if( tool->GetIcon() != BITMAPS::INVALID_BITMAP )
514 {
515 int imgIdx = m_actionImageBundleVector.size();
516 m_actionImageBundleVector.push_back( KiBitmapBundleDef( tool->GetIcon(), c_defSize ) );
517 m_actionImageListMap.emplace( tool->GetName(), imgIdx );
518
519 item.SetImage( imgIdx );
520 }
521 else
522 {
523 item.SetImage( -1 ); // Required on MSW
524 }
525
526 m_actionsList->InsertItem( item );
527 }
528
529 m_firstControlId = itemIdx;
530
531 for( const auto& [k, control] : m_availableControls )
532 {
533 wxListItem item;
534 item.SetText( control->GetUiName() );
535 item.SetFont( listFont );
536 item.SetData( static_cast<void*>( control ) );
537 item.SetId( itemIdx++ );
538 item.SetImage( -1 ); // Required on MSW
539
540 m_actionsList->InsertItem( item );
541 }
542
543 m_actionsList->SetSmallImages( m_actionImageBundleVector );
544
545 // This must be done after adding everything to the list to make the columns wide enough
546 m_actionsList->SetColumnWidth( 0, wxLIST_AUTOSIZE );
547}
548
549
550void PANEL_TOOLBAR_CUSTOMIZATION::onGroupPress( wxCommandEvent& aEvent )
551{
553
554 wxTreeItemId newItem;
555 wxTreeItemId selItem = m_toolbarTree->GetSelection();
556
557 if( selItem.IsOk() )
558 {
559 // Can't add a group onto a group
560 wxTreeItemId parent = m_toolbarTree->GetItemParent( selItem );
561
562 if( parent.IsOk() )
563 {
564 wxTreeItemId secondParent = m_toolbarTree->GetItemParent( parent );
565
566 if( secondParent.IsOk() )
567 {
568 delete treeItem;
569 return;
570 }
571 }
572
573 newItem = m_toolbarTree->InsertItem( m_toolbarTree->GetRootItem(), selItem, treeItem->GetName(),
574 -1, -1, treeItem );
575 }
576 else
577 {
578 newItem = m_toolbarTree->AppendItem( m_toolbarTree->GetRootItem(), treeItem->GetName(), -1, -1,
579 treeItem );
580 }
581
582 if( newItem.IsOk() )
583 {
584 m_toolbarTree->SelectItem( newItem );
585 m_toolbarTree->EnsureVisible( newItem );
586 }
587}
588
589
590void PANEL_TOOLBAR_CUSTOMIZATION::onSpacerPress( wxCommandEvent& aEvent )
591{
593
594 wxString label = wxString::Format( "Spacer: %i", treeItem->GetSize() );
595
596 wxTreeItemId newItem;
597 wxTreeItemId selItem = m_toolbarTree->GetSelection();
598
599 if( selItem.IsOk() )
600 {
601 // Insert after the current selection at the same level
602 wxTreeItemId parent = m_toolbarTree->GetItemParent( selItem );
603
604 // Can't insert a spacer in a group yet
605 if( parent.IsOk() )
606 {
607 wxTreeItemId secondParent = m_toolbarTree->GetItemParent( parent );
608
609 if( secondParent.IsOk() )
610 {
611 delete treeItem;
612 return;
613 }
614 }
615
616 newItem = m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
617 }
618 else
619 {
620 newItem = m_toolbarTree->AppendItem( m_toolbarTree->GetRootItem(), label, -1, -1, treeItem );
621 }
622
623 if( newItem.IsOk() )
624 {
625 m_toolbarTree->SelectItem( newItem );
626 m_toolbarTree->EnsureVisible( newItem );
627 }
628}
629
630
632{
634
635 wxTreeItemId newItem;
636 wxTreeItemId selItem = m_toolbarTree->GetSelection();
637
638 if( selItem.IsOk() )
639 {
640 // Insert after the current selection at the same level
641 wxTreeItemId parent = m_toolbarTree->GetItemParent( selItem );
642
643 // Can't insert a separator in a group yet
644 if( parent.IsOk() )
645 {
646 wxTreeItemId secondParent = m_toolbarTree->GetItemParent( parent );
647
648 if( secondParent.IsOk() )
649 {
650 delete treeItem;
651 return;
652 }
653 }
654
655 newItem = m_toolbarTree->InsertItem( parent, selItem, _( "Separator" ), -1, -1, treeItem );
656 }
657 else
658 {
659 newItem = m_toolbarTree->AppendItem( m_toolbarTree->GetRootItem(), _( "Separator" ), -1, -1, treeItem );
660 }
661
662 if( newItem.IsOk() )
663 {
664 m_toolbarTree->SelectItem( newItem );
665 m_toolbarTree->EnsureVisible( newItem );
666 }
667}
668
669
671{
672 enableCustomControls( event.IsChecked() );
673}
674
675
677{
678 m_tbChoice->Enable( enable );
679 enableToolbarControls( enable );
680}
681
682
684{
685 m_toolbarTree->Enable( enable );
686 m_btnAddTool->Enable( enable );
687 m_btnToolDelete->Enable( enable );
688
689 m_btnToolMoveDown->Enable( enable );
690 m_btnToolMoveUp->Enable( enable );
691 m_actionsList->Enable( enable );
692 m_insertButton->Enable( enable );
693}
694
695
696void PANEL_TOOLBAR_CUSTOMIZATION::onToolDelete( wxCommandEvent& event )
697{
698 wxTreeItemId item = m_toolbarTree->GetSelection();
699
700 if( !item.IsOk() )
701 return;
702
703 // The tree control defaults to nothing selected if you delete the item
704 // at the last place, so we have to manually get the itme immediately before
705 // the one we will delete, and then select it if nothing is selected.
706 wxTreeItemId prev = m_toolbarTree->GetPrevSibling( item );
707
708 m_toolbarTree->Delete( item );
709
710 item = m_toolbarTree->GetSelection();
711
712 if( !item.IsOk() && prev.IsOk() )
713 {
714 m_toolbarTree->SelectItem( prev );
715 m_toolbarTree->EnsureVisible( prev );
716 }
717}
718
719
720void PANEL_TOOLBAR_CUSTOMIZATION::onToolMoveUp( wxCommandEvent& event )
721{
722 m_toolbarTree->MoveItemUp( m_toolbarTree->GetSelection() );
723}
724
725
727{
728 m_toolbarTree->MoveItemDown( m_toolbarTree->GetSelection() );
729}
730
731
733{
734 // Get the selected item
735 long actionIdx = m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
736
737 // Nothing is selected, bail out
738 if( actionIdx < 0 )
739 return;
740
741 // This is needed because GetItemData returns a wxUIntPtr, which is actually size_t...
742 void* v = ( void* ) m_actionsList->GetItemData( actionIdx );
743 TOOL_ACTION* action = nullptr;
744 ACTION_TOOLBAR_CONTROL* control = nullptr;
745
746 if( actionIdx < (int) m_firstControlId )
747 action = static_cast<TOOL_ACTION*>( v );
748 else
749 control = static_cast<ACTION_TOOLBAR_CONTROL*>( v );
750
751 // Build the item to add
754 toolTreeItem->SetAction( action );
755 toolTreeItem->SetControl( control );
756
757 int imgIdx = -1;
758
759 if( action )
760 {
761 auto imgMap = m_actionImageListMap.find( action->GetName() );
762
763 if( imgMap != m_actionImageListMap.end() )
764 imgIdx = imgMap->second;
765 }
766
767 // Actually add the item
768 wxString label = action ? action->GetFriendlyName() : control->GetUiName();
769 wxTreeItemId selItem = m_toolbarTree->GetSelection();
770 wxTreeItemId newItem;
771
772 if( selItem.IsOk() )
773 {
775 dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( m_toolbarTree->GetItemData( selItem ) );
776
777 if( data && data->GetType() == TOOLBAR_ITEM_TYPE::TB_GROUP )
778 {
779 // Insert into the end of the group
780 newItem = m_toolbarTree->AppendItem( selItem, label, imgIdx, -1, toolTreeItem );
781 }
782 else
783 {
784 // Insert after the current selection at the same level
785 wxTreeItemId parent = m_toolbarTree->GetItemParent( selItem );
786 newItem = m_toolbarTree->InsertItem( parent, selItem, label, imgIdx, -1, toolTreeItem );
787 }
788 }
789 else
790 {
791 // Insert at the root level if there is no selection
792 newItem = m_toolbarTree->AppendItem( m_toolbarTree->GetRootItem(), label, imgIdx, -1, toolTreeItem );
793 }
794
795 if( newItem.IsOk() )
796 {
797 m_toolbarTree->SelectItem( newItem );
798 m_toolbarTree->EnsureVisible( newItem );
799
800 // Move the action to the next available one, to be nice
801 if( ++actionIdx < m_actionsList->GetItemCount() )
802 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
803 }
804}
805
806
808{
809 wxTreeItemId id = event.GetItem();
810
811 if( id.IsOk() )
812 {
813 wxTreeItemData* treeData = m_toolbarTree->GetItemData( id );
814
815 if( TOOLBAR_TREE_ITEM_DATA* tbData = dynamic_cast<TOOLBAR_TREE_ITEM_DATA*>( treeData ) )
816 {
817 switch( tbData->GetType() )
818 {
822 // Don't let these be edited
823 event.Veto();
824 break;
825
828 // Do nothing here
829 break;
830 }
831 }
832 }
833}
834
835
837{
838
839}
840
841
843{
844 // Store the current toolbar
845 std::optional<TOOLBAR_CONFIGURATION> currentTb = parseToolbarTree();
846
847 if( currentTb.has_value() )
848 m_toolbars[m_currentToolbar] = currentTb.value();
849
850 // Populate the new one
851 auto newTb = magic_enum::enum_cast<TOOLBAR_LOC>( event.GetInt() );
852
853 if( newTb.has_value() )
854 {
855 m_currentToolbar = newTb.value();
857 }
858}
859
860
862{
863 wxCommandEvent dummy;
865}
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Constructs and returns a bitmap bundle for the given icon ID, with the default bitmap size being aDef...
Definition bitmap.cpp:116
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ INVALID_BITMAP
Class to hold basic information about controls that can be added to the toolbars.
const std::string & GetName() const
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
PANEL_TOOLBAR_CUSTOMIZATION_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void onSpacerPress(wxCommandEvent &aEvent)
wxVector< wxBitmapBundle > m_actionImageBundleVector
void onTbChoiceSelect(wxCommandEvent &event) override
void onTreeEndLabelEdit(wxTreeEvent &event) override
void onTreeBeginLabelEdit(wxTreeEvent &event) override
void onToolDelete(wxCommandEvent &event) override
std::map< TOOLBAR_LOC, TOOLBAR_CONFIGURATION > m_toolbars
void onGroupPress(wxCommandEvent &aEvent)
void onSeparatorPress(wxCommandEvent &aEvent)
void ResetPanel() override
Reset the contents of this panel.
PANEL_TOOLBAR_CUSTOMIZATION(wxWindow *aParent, APP_SETTINGS_BASE *aCfg, TOOLBAR_SETTINGS *aTbSettings, const std::vector< TOOL_ACTION * > &aTools, const std::vector< ACTION_TOOLBAR_CONTROL * > &aControls)
std::map< std::string, int > m_actionImageListMap
void onBtnAddAction(wxCommandEvent &event) override
std::map< std::string, TOOL_ACTION * > m_availableTools
std::map< std::string, ACTION_TOOLBAR_CONTROL * > m_availableControls
std::optional< TOOLBAR_CONFIGURATION > parseToolbarTree()
void onCustomizeTbCb(wxCommandEvent &event) override
void onToolMoveDown(wxCommandEvent &event) override
void onListItemActivated(wxListEvent &event) override
void onToolMoveUp(wxCommandEvent &event) override
std::vector< TOOLBAR_ITEM > GetToolbarItems() const
TOOLBAR_GROUP_CONFIG & AddAction(std::string aActionName)
std::vector< TOOLBAR_ITEM > m_GroupItems
std::string m_ActionName
void SetName(const wxString &aName)
void SetAction(TOOL_ACTION *aAction)
void SetControl(ACTION_TOOLBAR_CONTROL *aControl)
TOOLBAR_TREE_ITEM_DATA(TOOLBAR_ITEM_TYPE aType)
TOOLBAR_TREE_ITEM_DATA(TOOLBAR_ITEM_TYPE aType, int aSize)
TOOLBAR_TREE_ITEM_DATA(TOOLBAR_ITEM_TYPE aType, wxString aName)
TOOLBAR_ITEM_TYPE GetType() const
ACTION_TOOLBAR_CONTROL * GetControl() const
Represent a single user action.
const std::string & GetName() const
Return name of the action.
wxString GetFriendlyName() const
Return the translated user-friendly name of the action.
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
static std::map< TOOLBAR_LOC, wxString > s_toolbarNameMap
std::vector< FAB_LAYER_COLOR > dummy
@ HIDDEN
Action is hidden from the toolbar.
Definition tool_action.h:63
@ RIGHT
Toolbar on the right side of the canvas.
@ LEFT
Toolbar on the left side of the canvas.
@ TOP_AUX
Toolbar on the top of the canvas.
@ TOP_MAIN
Toolbar on the top of the canvas.
Functions to provide common constants and other functions to assist in making a consistent UI.
#define SEPARATOR