KiCad PCB EDA Suite
WIDGET_HOTKEY_LIST Class Reference

#include <widget_hotkey_list.h>

Inheritance diagram for WIDGET_HOTKEY_LIST:

Public Member Functions

 WIDGET_HOTKEY_LIST (wxWindow *aParent, HOTKEY_STORE &aHotkeyStore, bool aReadOnly)
 Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST. More...
 
void ApplyFilterString (const wxString &aFilterStr)
 Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show. More...
 
void ResetAllHotkeys (bool aResetToDefault)
 Set hotkeys in the control to default or original values. More...
 
bool TransferDataToControl ()
 Method TransferDataToControl Load the hotkey data from the store into the control. More...
 
bool TransferDataFromControl ()
 Method TransferDataFromControl Save the hotkey data from the control. More...
 

Static Public Member Functions

static long MapKeypressToKeycode (const wxKeyEvent &aEvent)
 Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey. More...
 

Protected Member Functions

void editItem (wxTreeListItem aItem)
 Method editItem Prompt the user for a new hotkey given a list item. More...
 
void resetItem (wxTreeListItem aItem, int aResetId)
 Method resetItem Reset the item to either the default, the value when the dialog was opened, or none. More...
 
void onActivated (wxTreeListEvent &aEvent)
 Method onActivated Handle activation of a row. More...
 
void onContextMenu (wxTreeListEvent &aEvent)
 Method onContextMenu Handle right-click on a row. More...
 
void onMenu (wxCommandEvent &aEvent)
 Method onMenu Handle activation of a context menu item. More...
 
bool resolveKeyConflicts (TOOL_ACTION *aAction, long aKey)
 Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict between keys. More...
 

Private Member Functions

WIDGET_HOTKEY_CLIENT_DATAgetHKClientData (wxTreeListItem aItem)
 Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid. More...
 
WIDGET_HOTKEY_CLIENT_DATAgetExpectedHkClientData (wxTreeListItem aItem)
 Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found. More...
 
void updateFromClientData ()
 Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects. More...
 
void updateShownItems (const wxString &aFilterStr)
 Method updateShownItems. More...
 
void changeHotkey (HOTKEY &aHotkey, long aKey)
 Attempt to change the given hotkey to the given key code. More...
 
void updateColumnWidths ()
 Recalculates column widths after model has changed. More...
 

Private Attributes

HOTKEY_STOREm_hk_store
 
bool m_readOnly
 
std::unordered_map< long, wxString > m_reservedHotkeys
 
wxTreeListItem m_context_menu_item
 

Detailed Description

Definition at line 41 of file widget_hotkey_list.h.

Constructor & Destructor Documentation

◆ WIDGET_HOTKEY_LIST()

WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST ( wxWindow *  aParent,
HOTKEY_STORE aHotkeyStore,
bool  aReadOnly 
)

Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST.

Parameters
aParent- parent widget
aHotkeys- EDA_HOTKEY_CONFIG data - a hotkey store is constructed from this.

Definition at line 455 of file widget_hotkey_list.cpp.

456  :
457  wxTreeListCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
458  m_hk_store( aHotkeyStore ),
459  m_readOnly( aReadOnly )
460 {
461  wxString command_header = _( "Command" );
462 
463  if( !m_readOnly )
464  command_header << wxT( " " ) << _( "(double-click to edit)" );
465 
466  AppendColumn( command_header, 450, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
467  AppendColumn( _( "Hotkey" ), 120, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
468  AppendColumn( _( "Description" ), 900, wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE );
469 
470 
471 #if defined( __WXGTK__ )// && !wxCHECK_VERSION( 3, 1, 0 )
472  // Automatic column widths are broken in wxGTK 3.0.x; set min widths to ensure visibility
473  // They are also broken in wxGTK 3.1.4
474 
475  wxDataViewCtrl* dv = GetDataView();
476 
477  wxString longKey = wxT( "Ctrl+Alt+Shift+X" );
478  int pad = 20;
479 
480  dv->GetColumn( 0 )->SetMinWidth( dv->GetMainWindow()->GetTextExtent( command_header ).x + pad );
481  dv->GetColumn( 1 )->SetMinWidth( dv->GetMainWindow()->GetTextExtent( longKey ).x + pad );
482 
483  CallAfter( [&]()
484  {
485  GetDataView()->Update();
486  } );
487  #endif
488 
489  std::vector<wxString> reserved_keys =
490  {
491  wxT( "Ctrl+Tab" ),
492  wxT( "Ctrl+Shift+Tab" )
493  };
494 
495  for( auto& key : reserved_keys )
496  {
497  long code = KeyCodeFromKeyName( key );
498 
499  if( code )
500  m_reservedHotkeys[code] = key;
501  else
502  {
503  wxLogWarning( wxT( "Unknown reserved keycode %s\n" ), key );
504  }
505  }
506 
507  GetDataView()->SetIndent( 10 );
508 
509  if( !m_readOnly )
510  {
511  // The event only apply if the widget is in editable mode
512  Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::onActivated, this );
513  Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::onContextMenu, this );
514  Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::onMenu, this );
515  }
516 }
std::unordered_map< long, wxString > m_reservedHotkeys
void onActivated(wxTreeListEvent &aEvent)
Method onActivated Handle activation of a row.
void onContextMenu(wxTreeListEvent &aEvent)
Method onContextMenu Handle right-click on a row.
HOTKEY_STORE & m_hk_store
int KeyCodeFromKeyName(const wxString &keyname)
Return the key code from its user-friendly key name (ie: "Ctrl+M").
#define _(s)
void onMenu(wxCommandEvent &aEvent)
Method onMenu Handle activation of a context menu item.

References _, KeyCodeFromKeyName(), m_readOnly, m_reservedHotkeys, onActivated(), onContextMenu(), onMenu(), and pad.

Member Function Documentation

◆ ApplyFilterString()

void WIDGET_HOTKEY_LIST::ApplyFilterString ( const wxString &  aFilterStr)

Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show.

Parameters
aFilterStrthe string to filter by

Definition at line 519 of file widget_hotkey_list.cpp.

520 {
521  updateShownItems( aFilterStr );
522 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

Referenced by PANEL_HOTKEYS_EDITOR::OnFilterSearch().

◆ changeHotkey()

void WIDGET_HOTKEY_LIST::changeHotkey ( HOTKEY aHotkey,
long  aKey 
)
private

Attempt to change the given hotkey to the given key code.

If the hotkey conflicts, the user is prompted to change anyway (and in doing so, unset the conflicting key), or cancel the attempt.

Parameters
aHotkeythe change-able hotkey to try to change
aKeythe key code to change it to

Definition at line 311 of file widget_hotkey_list.cpp.

312 {
313  // See if this key code is handled in hotkeys names list
314  bool exists;
315  KeyNameFromKeyCode( aKey, &exists );
316 
317  if( exists && aHotkey.m_EditKeycode != aKey )
318  {
319  if( aKey == 0 || resolveKeyConflicts( aHotkey.m_Actions[ 0 ], aKey ) )
320  aHotkey.m_EditKeycode = aKey;
321  }
322 }
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
bool resolveKeyConflicts(TOOL_ACTION *aAction, long aKey)
Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
int m_EditKeycode
Definition: hotkey_store.h:37

References KeyNameFromKeyCode(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, and resolveKeyConflicts().

Referenced by editItem(), and resetItem().

◆ editItem()

void WIDGET_HOTKEY_LIST::editItem ( wxTreeListItem  aItem)
protected

Method editItem Prompt the user for a new hotkey given a list item.

Definition at line 325 of file widget_hotkey_list.cpp.

326 {
328 
329  if( !hkdata )
330  return;
331 
332  wxString name = GetItemText( aItem, 0 );
333  wxString current_key = GetItemText( aItem, 1 );
334 
335  wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( this, name, current_key );
336  long key = MapKeypressToKeycode( key_event );
337 
338  if( key )
339  {
340  auto it = m_reservedHotkeys.find( key );
341 
342  if( it != m_reservedHotkeys.end() )
343  {
344  wxString msg = wxString::Format(
345  _( "'%s' is a reserved hotkey in KiCad and cannot be assigned." ),
346  it->second );
347 
348  DisplayErrorMessage( this, msg );
349  return;
350  }
351 
352  changeHotkey( hkdata->GetChangedHotkey(), key );
354  }
355 }
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.
void changeHotkey(HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
std::unordered_map< long, wxString > m_reservedHotkeys
static wxKeyEvent PromptForKey(wxWindow *aParent, const wxString &aName, const wxString &aCurrentKey)
WIDGET_HOTKEY_CLIENT_DATA * getExpectedHkClientData(wxTreeListItem aItem)
Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Store the hotkey change data associated with each row.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const char * name
Definition: DXF_plotter.cpp:56

References _, changeHotkey(), DisplayErrorMessage(), Format(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), m_reservedHotkeys, MapKeypressToKeycode(), name, HK_PROMPT_DIALOG::PromptForKey(), and updateFromClientData().

Referenced by onActivated(), and onMenu().

◆ getExpectedHkClientData()

WIDGET_HOTKEY_CLIENT_DATA * WIDGET_HOTKEY_LIST::getExpectedHkClientData ( wxTreeListItem  aItem)
private

Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.

This is for use when the data not being present indicates an error.

Definition at line 271 of file widget_hotkey_list.cpp.

272 {
273  const auto hkdata = getHKClientData( aItem );
274 
275  // This probably means a hotkey-only action is being attempted on
276  // a row that is not a hotkey (like a section heading)
277  wxASSERT_MSG( hkdata != nullptr, wxT( "No hotkey data found for list item" ) );
278 
279  return hkdata;
280 }
WIDGET_HOTKEY_CLIENT_DATA * getHKClientData(wxTreeListItem aItem)
Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...

References getHKClientData().

Referenced by editItem(), and resetItem().

◆ getHKClientData()

WIDGET_HOTKEY_CLIENT_DATA * WIDGET_HOTKEY_LIST::getHKClientData ( wxTreeListItem  aItem)
private

Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid.

Definition at line 257 of file widget_hotkey_list.cpp.

258 {
259  if( aItem.IsOk() )
260  {
261  wxClientData* data = GetItemData( aItem );
262 
263  if( data )
264  return static_cast<WIDGET_HOTKEY_CLIENT_DATA*>( data );
265  }
266 
267  return nullptr;
268 }

Referenced by getExpectedHkClientData(), onContextMenu(), and updateFromClientData().

◆ MapKeypressToKeycode()

long WIDGET_HOTKEY_LIST::MapKeypressToKeycode ( const wxKeyEvent &  aEvent)
static

Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.

Definition at line 609 of file widget_hotkey_list.cpp.

610 {
611  long key = aEvent.GetKeyCode();
612  bool is_tab = aEvent.IsKeyInCategory( WXK_CATEGORY_TAB );
613 
614  if( key == WXK_ESCAPE )
615  {
616  return 0;
617  }
618  else
619  {
620  if( key >= 'a' && key <= 'z' ) // convert to uppercase
621  key = key + ('A' - 'a');
622 
623  // Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
624  // to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
625  if( !is_tab && aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
626  key += 'A' - 1;
627 
628  /* Disallow shift for keys that have two keycodes on them (e.g. number and
629  * punctuation keys) leaving only the "letter keys" of A-Z, tab and space
630  * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
631  * and Ctrl-( and Ctrl-5 (FR layout).
632  * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
633  */
634  bool keyIsLetter = key >= 'A' && key <= 'Z';
635 
636  if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 || key == 9 || key == 32 ) )
637  key |= MD_SHIFT;
638 
639  if( aEvent.ControlDown() )
640  key |= MD_CTRL;
641 
642  if( aEvent.AltDown() )
643  key |= MD_ALT;
644 
645  return key;
646  }
647 }

References MD_ALT, MD_CTRL, and MD_SHIFT.

Referenced by editItem().

◆ onActivated()

void WIDGET_HOTKEY_LIST::onActivated ( wxTreeListEvent &  aEvent)
protected

Method onActivated Handle activation of a row.

Definition at line 378 of file widget_hotkey_list.cpp.

379 {
380  editItem( aEvent.GetItem());
381 }
void editItem(wxTreeListItem aItem)
Method editItem Prompt the user for a new hotkey given a list item.

References editItem().

Referenced by WIDGET_HOTKEY_LIST().

◆ onContextMenu()

void WIDGET_HOTKEY_LIST::onContextMenu ( wxTreeListEvent &  aEvent)
protected

Method onContextMenu Handle right-click on a row.

Definition at line 384 of file widget_hotkey_list.cpp.

385 {
386  // Save the active event for use in OnMenu
387  m_context_menu_item = aEvent.GetItem();
388 
389  wxMenu menu;
390 
392 
393  // Some actions only apply if the row is hotkey data
394  if( hkdata )
395  {
396  menu.Append( ID_EDIT_HOTKEY, _( "Edit..." ) );
397  menu.Append( ID_RESET, _( "Undo Changes" ) );
398  menu.Append( ID_CLEAR, _( "Clear Assigned Hotkey" ) );
399  menu.Append( ID_DEFAULT, _( "Restore Default" ) );
400  menu.Append( wxID_SEPARATOR );
401 
402  PopupMenu( &menu );
403  }
404 }
wxTreeListItem m_context_menu_item
Store the hotkey change data associated with each row.
#define _(s)
WIDGET_HOTKEY_CLIENT_DATA * getHKClientData(wxTreeListItem aItem)
Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...

References _, getHKClientData(), ID_CLEAR, ID_DEFAULT, ID_EDIT_HOTKEY, ID_RESET, and m_context_menu_item.

Referenced by WIDGET_HOTKEY_LIST().

◆ onMenu()

void WIDGET_HOTKEY_LIST::onMenu ( wxCommandEvent &  aEvent)
protected

Method onMenu Handle activation of a context menu item.

Definition at line 407 of file widget_hotkey_list.cpp.

408 {
409  switch( aEvent.GetId() )
410  {
412  break;
413 
414  case ID_RESET:
415  case ID_CLEAR:
416  case ID_DEFAULT:resetItem( m_context_menu_item, aEvent.GetId());
417  break;
418 
419  default:
420  wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
421  }
422 }
void editItem(wxTreeListItem aItem)
Method editItem Prompt the user for a new hotkey given a list item.
wxTreeListItem m_context_menu_item
void resetItem(wxTreeListItem aItem, int aResetId)
Method resetItem Reset the item to either the default, the value when the dialog was opened,...

References editItem(), ID_CLEAR, ID_DEFAULT, ID_EDIT_HOTKEY, ID_RESET, m_context_menu_item, and resetItem().

Referenced by WIDGET_HOTKEY_LIST().

◆ ResetAllHotkeys()

void WIDGET_HOTKEY_LIST::ResetAllHotkeys ( bool  aResetToDefault)

Set hotkeys in the control to default or original values.

Parameters
aResetToDefaultif true, reset to the defaults inherent to the hotkeys, else reset to the value they had when the dialog was invoked.

Definition at line 525 of file widget_hotkey_list.cpp.

526 {
527  Freeze();
528 
529  // Reset all the hotkeys, not just the ones shown
530  // Should not need to check conflicts, as the state we're about
531  // to set to a should be consistent
532  if( aResetToDefault )
534  else
536 
539 
540  Thaw();
541 }
HOTKEY_STORE & m_hk_store
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
void ResetAllHotkeysToDefault()
Reset every hotkey in the store to the default values.
void updateColumnWidths()
Recalculates column widths after model has changed.
void ResetAllHotkeysToOriginal()
Resets every hotkey to the original values.

References m_hk_store, HOTKEY_STORE::ResetAllHotkeysToDefault(), HOTKEY_STORE::ResetAllHotkeysToOriginal(), updateColumnWidths(), and updateFromClientData().

Referenced by PANEL_HOTKEYS_EDITOR::installButtons(), and PANEL_HOTKEYS_EDITOR::ResetPanel().

◆ resetItem()

void WIDGET_HOTKEY_LIST::resetItem ( wxTreeListItem  aItem,
int  aResetId 
)
protected

Method resetItem Reset the item to either the default, the value when the dialog was opened, or none.

Definition at line 358 of file widget_hotkey_list.cpp.

359 {
361 
362  if( !hkdata )
363  return;
364 
365  HOTKEY& changed_hk = hkdata->GetChangedHotkey();
366 
367  if( aResetId == ID_RESET )
368  changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetHotKey() );
369  else if( aResetId == ID_CLEAR )
370  changeHotkey( changed_hk, 0 );
371  else if( aResetId == ID_DEFAULT )
372  changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetDefaultHotKey() );
373 
375 }
void changeHotkey(HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
WIDGET_HOTKEY_CLIENT_DATA * getExpectedHkClientData(wxTreeListItem aItem)
Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Store the hotkey change data associated with each row.
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), ID_CLEAR, ID_DEFAULT, ID_RESET, HOTKEY::m_Actions, and updateFromClientData().

Referenced by onMenu().

◆ resolveKeyConflicts()

bool WIDGET_HOTKEY_LIST::resolveKeyConflicts ( TOOL_ACTION aAction,
long  aKey 
)
protected

Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict between keys.

The key code should already have been checked that it's not for the same entry as it's current in, or else this method will prompt for the self-change.

The method will do conflict resolution depending on aSectionTag. g_CommonSectionTag means the key code must only be checked with the aSectionTag section and g_CommonSectionTag section.

Parameters
aKey- key to check
aActionName- name of the action into which the key is proposed to be installed
Returns
true iff the user accepted the overwrite or no conflict existed

Definition at line 425 of file widget_hotkey_list.cpp.

426 {
427  HOTKEY* conflictingHotKey = nullptr;
428 
429  m_hk_store.CheckKeyConflicts( aAction, aKey, &conflictingHotKey );
430 
431  if( !conflictingHotKey )
432  return true;
433 
434  TOOL_ACTION* conflictingAction = conflictingHotKey->m_Actions[ 0 ];
435  wxString msg = wxString::Format( _( "'%s' is already assigned to '%s' in section '%s'. "
436  "Are you sure you want to change its assignment?" ),
437  KeyNameFromKeyCode( aKey ),
438  conflictingAction->GetLabel(),
439  HOTKEY_STORE::GetSectionName( conflictingAction ) );
440 
441  wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );
442 
443  if( dlg.ShowModal() == wxID_YES )
444  {
445  // Reset the other hotkey
446  conflictingHotKey->m_EditKeycode = 0;
448  return true;
449  }
450 
451  return false;
452 }
HOTKEY_STORE & m_hk_store
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
#define _(s)
bool CheckKeyConflicts(TOOL_ACTION *aAction, long aKey, HOTKEY **aConflict)
Check whether the given key conflicts with anything in this store.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
wxString GetLabel() const
Definition: tool_action.cpp:83
Represent a single user action.
Definition: tool_action.h:67
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int m_EditKeycode
Definition: hotkey_store.h:37
static wxString GetSectionName(TOOL_ACTION *aAction)

References _, HOTKEY_STORE::CheckKeyConflicts(), Format(), TOOL_ACTION::GetLabel(), HOTKEY_STORE::GetSectionName(), KeyNameFromKeyCode(), HOTKEY::m_Actions, HOTKEY::m_EditKeycode, m_hk_store, and updateFromClientData().

Referenced by changeHotkey().

◆ TransferDataFromControl()

bool WIDGET_HOTKEY_LIST::TransferDataFromControl ( )

Method TransferDataFromControl Save the hotkey data from the control.

Returns
true iff the operation was successful

Definition at line 602 of file widget_hotkey_list.cpp.

603 {
605  return true;
606 }
void SaveAllHotkeys()
Persist all changes to hotkeys in the store to the underlying data structures.
HOTKEY_STORE & m_hk_store

References m_hk_store, and HOTKEY_STORE::SaveAllHotkeys().

Referenced by PANEL_HOTKEYS_EDITOR::TransferDataFromWindow().

◆ TransferDataToControl()

bool WIDGET_HOTKEY_LIST::TransferDataToControl ( )

Method TransferDataToControl Load the hotkey data from the store into the control.

Returns
true iff the operation was successful

Definition at line 544 of file widget_hotkey_list.cpp.

545 {
546  updateShownItems( "" );
548 
549  return true;
550 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.
void updateColumnWidths()
Recalculates column widths after model has changed.

References updateColumnWidths(), and updateShownItems().

Referenced by PANEL_HOTKEYS_EDITOR::ImportHotKeys(), and PANEL_HOTKEYS_EDITOR::TransferDataToWindow().

◆ updateColumnWidths()

void WIDGET_HOTKEY_LIST::updateColumnWidths ( )
private

Recalculates column widths after model has changed.

Definition at line 553 of file widget_hotkey_list.cpp.

554 {
555  wxDataViewColumn* col = GetDataView()->GetColumn( 0 );
556  col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
557  col->SetWidth( col->GetWidth() );
558 
559 #if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
560  col->SetResizeable( true );
561 #endif
562 
563  col = GetDataView()->GetColumn( 1 );
564  col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
565  col->SetWidth( col->GetWidth() );
566 
567 #if defined( __WXGTK__ ) && !wxCHECK_VERSION( 3, 1, 0 )
568  col->SetResizeable( true );
569 #endif
570 }

Referenced by ResetAllHotkeys(), and TransferDataToControl().

◆ updateFromClientData()

void WIDGET_HOTKEY_LIST::updateFromClientData ( )
private

Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects.

Definition at line 283 of file widget_hotkey_list.cpp.

284 {
285  for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
286  {
288 
289  if( hkdata )
290  {
291  const HOTKEY& changed_hk = hkdata->GetChangedHotkey();
292  wxString label = changed_hk.m_Actions[ 0 ]->GetLabel();
293  wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode );
294  wxString description = changed_hk.m_Actions[ 0 ]->GetDescription( false );
295 
296  if( label.IsEmpty() )
297  label = changed_hk.m_Actions[ 0 ]->GetName();
298 
299  // mark unsaved changes
300  if( changed_hk.m_EditKeycode != changed_hk.m_Actions[ 0 ]->GetHotKey() )
301  label += wxT( " *" );
302 
303  SetItemText( i, 0, label );
304  SetItemText( i, 1, key_text);
305  SetItemText( i, 2, description );
306  }
307  }
308 }
Store the hotkey change data associated with each row.
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:36
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int m_EditKeycode
Definition: hotkey_store.h:37
WIDGET_HOTKEY_CLIENT_DATA * getHKClientData(wxTreeListItem aItem)
Method getHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...

References WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getHKClientData(), GetNextItem(), KeyNameFromKeyCode(), HOTKEY::m_Actions, and HOTKEY::m_EditKeycode.

Referenced by editItem(), ResetAllHotkeys(), resetItem(), resolveKeyConflicts(), and updateShownItems().

◆ updateShownItems()

void WIDGET_HOTKEY_LIST::updateShownItems ( const wxString &  aFilterStr)
private

Method updateShownItems.

Update the items shown in the widget based on a given filter string.

Parameters
aFilterStrthe string to filter with. Empty means no filter.

Definition at line 573 of file widget_hotkey_list.cpp.

574 {
575  Freeze();
576  DeleteAllItems();
577 
578  HOTKEY_FILTER filter( aFilterStr );
579 
580  for( HOTKEY_SECTION& section: m_hk_store.GetSections() )
581  {
582  // Create parent tree item
583  wxTreeListItem parent = AppendItem( GetRootItem(), section.m_SectionName );
584 
585  for( HOTKEY& hotkey: section.m_HotKeys )
586  {
587  if( filter.FilterMatches( hotkey ) )
588  {
589  wxTreeListItem item = AppendItem( parent, wxEmptyString );
590  SetItemData( item, new WIDGET_HOTKEY_CLIENT_DATA( hotkey ) );
591  }
592  }
593 
594  Expand( parent );
595  }
596 
598  Thaw();
599 }
HOTKEY_STORE & m_hk_store
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Store the hotkey change data associated with each row.
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
Manage logic for filtering hotkeys based on user input.

References filter, HOTKEY_STORE::GetSections(), m_hk_store, and updateFromClientData().

Referenced by ApplyFilterString(), and TransferDataToControl().

Member Data Documentation

◆ m_context_menu_item

wxTreeListItem WIDGET_HOTKEY_LIST::m_context_menu_item
private

Definition at line 188 of file widget_hotkey_list.h.

Referenced by onContextMenu(), and onMenu().

◆ m_hk_store

HOTKEY_STORE& WIDGET_HOTKEY_LIST::m_hk_store
private

◆ m_readOnly

bool WIDGET_HOTKEY_LIST::m_readOnly
private

Definition at line 184 of file widget_hotkey_list.h.

Referenced by WIDGET_HOTKEY_LIST().

◆ m_reservedHotkeys

std::unordered_map<long, wxString> WIDGET_HOTKEY_LIST::m_reservedHotkeys
private

Definition at line 186 of file widget_hotkey_list.h.

Referenced by editItem(), and WIDGET_HOTKEY_LIST().


The documentation for this class was generated from the following files: