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...
 
void OnSize (wxSizeEvent &aEvent)
 Function OnSize Handle resizing of the control. More...
 
int MemoWidthFor (const wxString &aStr)
 Memoized version of wxWidthFor(), which returns the width in pixels required to display a string. 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...
 

Private Attributes

HOTKEY_STOREm_hk_store
 
bool m_readOnly
 
wxTreeListItem m_context_menu_item
 
int m_rubber_band_column
 
int m_clamped_min_width
 

Static Private Attributes

static std::map< wxString, int > m_width_cache
 

Detailed Description

Definition at line 40 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 547 of file widget_hotkey_list.cpp.

549  : wxTreeListCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
550  m_hk_store( aHotkeyStore ),
551  m_readOnly( aReadOnly ),
554 {
555  wxString command_header = _( "Command" );
556 
557  if( !m_readOnly )
558  command_header << " " << _( "(double-click to edit)" );
559 
560  AppendColumn( command_header );
561  AppendColumn( _( "Hotkey" ) );
562  GetDataView()->SetIndent( 10 );
563 
564  if( !m_readOnly )
565  {
566  // The event only apply if the widget is in editable mode
567  Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this );
568  Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this );
569  Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this );
570  }
571 
572  Bind( wxEVT_SIZE, &WIDGET_HOTKEY_LIST::OnSize, this );
573 }
void OnActivated(wxTreeListEvent &aEvent)
Method OnActivated Handle activation of a row.
void OnMenu(wxCommandEvent &aEvent)
Method OnMenu Handle activation of a context menu item.
void OnSize(wxSizeEvent &aEvent)
Function OnSize Handle resizing of the control.
static const int HOTKEY_MIN_WIDTH
Minimum width of the hotkey column.
HOTKEY_STORE & m_hk_store
#define _(s)
Definition: 3d_actions.cpp:33
void OnContextMenu(wxTreeListEvent &aEvent)
Method OnContextMenu Handle right-click on a row.

References _, m_readOnly, OnActivated(), OnContextMenu(), OnMenu(), and OnSize().

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 576 of file widget_hotkey_list.cpp.

577 {
578  updateShownItems( aFilterStr );
579 }
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 327 of file widget_hotkey_list.cpp.

328 {
329  // See if this key code is handled in hotkeys names list
330  bool exists;
331  KeyNameFromKeyCode( aKey, &exists );
332 
333  if( exists && aHotkey.m_EditKeycode != aKey )
334  {
335  if( aKey == 0 || ResolveKeyConflicts( aHotkey.m_Actions[ 0 ], aKey ) )
336  aHotkey.m_EditKeycode = aKey;
337  }
338 }
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...
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
int m_EditKeycode
Definition: hotkey_store.h:36

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 341 of file widget_hotkey_list.cpp.

342 {
344 
345  if( !hkdata )
346  return;
347 
348  wxString name = GetItemText( aItem, 0 );
349  wxString current_key = GetItemText( aItem, 1 );
350 
351  wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( GetParent(), name, current_key );
352  long key = MapKeypressToKeycode( key_event );
353 
354  if( key )
355  {
356  changeHotkey( hkdata->GetChangedHotkey(), key );
358  }
359 }
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.
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...
WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
const char * name
Definition: DXF_plotter.cpp:60

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), 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 285 of file widget_hotkey_list.cpp.

286 {
287  const auto hkdata = GetHKClientData( aItem );
288 
289  // This probably means a hotkey-only action is being attempted on
290  // a row that is not a hotkey (like a section heading)
291  wxASSERT_MSG( hkdata != nullptr, "No hotkey data found for list item" );
292 
293  return hkdata;
294 }
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 271 of file widget_hotkey_list.cpp.

272 {
273  if( aItem.IsOk() )
274  {
275  wxClientData* data = GetItemData( aItem );
276 
277  if( data )
278  return static_cast<WIDGET_HOTKEY_CLIENT_DATA*>( data );
279  }
280 
281  return nullptr;
282 }

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 642 of file widget_hotkey_list.cpp.

643 {
644  long key = aEvent.GetKeyCode();
645 
646  if( key == WXK_ESCAPE )
647  {
648  return 0;
649  }
650  else
651  {
652  if( key >= 'a' && key <= 'z' ) // convert to uppercase
653  key = key + ('A' - 'a');
654 
655  // Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
656  // to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
657  if( aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
658  key += 'A' - 1;
659 
660  /* Disallow shift for keys that have two keycodes on them (e.g. number and
661  * punctuation keys) leaving only the "letter keys" of A-Z.
662  * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
663  * and Ctrl-( and Ctrl-5 (FR layout).
664  * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
665  */
666  bool keyIsLetter = key >= 'A' && key <= 'Z';
667 
668  if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 ) )
669  key |= MD_SHIFT;
670 
671  if( aEvent.ControlDown() )
672  key |= MD_CTRL;
673 
674  if( aEvent.AltDown() )
675  key |= MD_ALT;
676 
677  return key;
678  }
679 }

References MD_ALT, MD_CTRL, and MD_SHIFT.

Referenced by EditItem().

◆ MemoWidthFor()

int WIDGET_HOTKEY_LIST::MemoWidthFor ( const wxString &  aStr)
protected

Memoized version of wxWidthFor(), which returns the width in pixels required to display a string.

The wx version is REALLY SLOW on macOS.

Definition at line 498 of file widget_hotkey_list.cpp.

499 {
500  int width;
501  auto found = m_width_cache.find( aStr );
502 
503  if( found == m_width_cache.end() )
504  {
505  width = WidthFor( aStr );
506  m_width_cache[aStr] = width;
507  }
508  else
509  {
510  width = found->second;
511  }
512 
513  return width;
514 }
static std::map< wxString, int > m_width_cache

References m_width_cache.

Referenced by OnSize().

◆ OnActivated()

void WIDGET_HOTKEY_LIST::OnActivated ( wxTreeListEvent &  aEvent)
protected

Method OnActivated Handle activation of a row.

Definition at line 382 of file widget_hotkey_list.cpp.

383 {
384  EditItem( aEvent.GetItem() );
385 }
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 388 of file widget_hotkey_list.cpp.

389 {
390  // Save the active event for use in OnMenu
391  m_context_menu_item = aEvent.GetItem();
392 
393  wxMenu menu;
394 
396 
397  // Some actions only apply if the row is hotkey data
398  if( hkdata )
399  {
400  menu.Append( ID_EDIT_HOTKEY, _( "Edit..." ) );
401  menu.Append( ID_RESET, _( "Undo Changes" ) );
402  menu.Append( ID_CLEAR, _( "Clear Assigned Hotkey" ) );
403  menu.Append( ID_DEFAULT, _( "Restore Default" ) );
404  menu.Append( wxID_SEPARATOR );
405 
406  PopupMenu( &menu );
407  }
408 }
wxTreeListItem m_context_menu_item
WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
#define _(s)
Definition: 3d_actions.cpp:33
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 411 of file widget_hotkey_list.cpp.

412 {
413  switch( aEvent.GetId() )
414  {
415  case ID_EDIT_HOTKEY:
417  break;
418 
419  case ID_RESET:
420  case ID_CLEAR:
421  case ID_DEFAULT:
422  ResetItem( m_context_menu_item, aEvent.GetId() );
423  break;
424 
425  default:
426  wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
427  }
428 }
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,...
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.

References EditItem(), ID_CLEAR, ID_DEFAULT, ID_EDIT_HOTKEY, ID_RESET, m_context_menu_item, and ResetItem().

Referenced by WIDGET_HOTKEY_LIST().

◆ OnSize()

void WIDGET_HOTKEY_LIST::OnSize ( wxSizeEvent &  aEvent)
protected

Function OnSize Handle resizing of the control.

Overrides the buggy wxTreeListCtrl::OnSize.

Definition at line 431 of file widget_hotkey_list.cpp.

432 {
433  wxDataViewCtrl* view = GetDataView();
434 
435  if( !view )
436  return;
437 
438  wxRect rect = GetClientRect();
439  view->SetSize( rect );
440 
441 #ifdef wxHAS_GENERIC_DATAVIEWCTRL
442  {
443  wxWindow* win_view = GetView();
444  win_view->Refresh();
445  win_view->Update();
446  }
447 #endif
448 
449  // Find the maximum width of both columns
450  int clamped_column = ( m_rubber_band_column == 0 ) ? 1 : 0;
451  int clamped_column_width = 0;
452  int rubber_max_width = 0;
453 
454  for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
455  {
456  const wxString& text = GetItemText( item, clamped_column );
457  int width = WidthFor( text );
458 
459  if( clamped_column == 0 )
460  {
461  width += 4 * view->GetIndent();
462  }
463 
464  if( width > clamped_column_width )
465  clamped_column_width = width;
466 
467  width = MemoWidthFor( GetItemText( item, m_rubber_band_column ) );
468  if( width > rubber_max_width )
469  rubber_max_width = width;
470  }
471 
472  if( clamped_column_width < m_clamped_min_width )
473  clamped_column_width = m_clamped_min_width;
474 
475  // Rubber column width is only limited if the rubber column is on the LEFT.
476  // If on the right, let the horiz scrollbar show.
477 
478  int rubber_width = 0;
479 
480  if( m_rubber_band_column == 0 )
481  rubber_width = rect.width - clamped_column_width - HORIZ_MARGIN;
482  else
483  rubber_width = rubber_max_width;
484 
485  if( rubber_width <= 0 )
486  rubber_width = 1;
487 
488  wxASSERT( m_rubber_band_column == 0 || m_rubber_band_column == 1 );
489 
490  if( GetColumnCount() >= 2 )
491  {
492  SetColumnWidth( m_rubber_band_column, rubber_width );
493  SetColumnWidth( clamped_column, clamped_column_width );
494  }
495 }
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
static const int HORIZ_MARGIN
Extra margin to compensate for vertical scrollbar.
int MemoWidthFor(const wxString &aStr)
Memoized version of wxWidthFor(), which returns the width in pixels required to display a string.

References GetNextItem(), HORIZ_MARGIN, m_clamped_min_width, m_rubber_band_column, and MemoWidthFor().

Referenced by UpdateFromClientData(), and 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 582 of file widget_hotkey_list.cpp.

583 {
584  Freeze();
585 
586  // Reset all the hotkeys, not just the ones shown
587  // Should not need to check conflicts, as the state we're about
588  // to set to a should be consistent
589  if( aResetToDefault )
591  else
593 
595  Thaw();
596 }
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 ResetAllHotkeysToOriginal()
Resets every hotkey to the original values.

References m_hk_store, HOTKEY_STORE::ResetAllHotkeysToDefault(), HOTKEY_STORE::ResetAllHotkeysToOriginal(), and UpdateFromClientData().

Referenced by PANEL_HOTKEYS_EDITOR::installButtons().

◆ 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 362 of file widget_hotkey_list.cpp.

363 {
365 
366  if( !hkdata )
367  return;
368 
369  auto& changed_hk = hkdata->GetChangedHotkey();
370 
371  if( aResetId == ID_RESET )
372  changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetHotKey() );
373  else if( aResetId == ID_CLEAR )
374  changeHotkey( changed_hk, 0 );
375  else if( aResetId == ID_DEFAULT )
376  changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetDefaultHotKey() );
377 
379 }
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...
WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), ID_CLEAR, ID_DEFAULT, ID_RESET, 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 checkd 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 517 of file widget_hotkey_list.cpp.

518 {
519  HOTKEY* conflictingHotKey = nullptr;
520 
521  m_hk_store.CheckKeyConflicts( aAction, aKey, &conflictingHotKey );
522 
523  if( !conflictingHotKey )
524  return true;
525 
526  TOOL_ACTION* conflictingAction = conflictingHotKey->m_Actions[ 0 ];
527  wxString msg = wxString::Format( _( "\"%s\" is already assigned to \"%s\" in section \"%s\". "
528  "Are you sure you want to change its assignment?" ),
529  KeyNameFromKeyCode( aKey ),
530  conflictingAction->GetLabel(),
531  HOTKEY_STORE::GetSectionName( conflictingAction ) );
532 
533  wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );
534 
535  if( dlg.ShowModal() == wxID_YES )
536  {
537  // Reset the other hotkey
538  conflictingHotKey->m_EditKeycode = 0;
540  return true;
541  }
542 
543  return false;
544 }
HOTKEY_STORE & m_hk_store
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
bool CheckKeyConflicts(TOOL_ACTION *aAction, long aKey, HOTKEY **aConflict)
Check whether the given key conflicts with anything in this store.
std::vector< TOOL_ACTION * > m_Actions
Definition: hotkey_store.h:35
wxString GetLabel() const
Definition: tool_action.cpp:69
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
TOOL_ACTION.
Definition: tool_action.h:46
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
int m_EditKeycode
Definition: hotkey_store.h:36
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 635 of file widget_hotkey_list.cpp.

636 {
638  return true;
639 }
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 599 of file widget_hotkey_list.cpp.

600 {
601  updateShownItems( "" );
602  return true;
603 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

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

◆ 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 297 of file widget_hotkey_list.cpp.

298 {
299  for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
300  {
302 
303  if( hkdata )
304  {
305  const auto& changed_hk = hkdata->GetChangedHotkey();
306  wxString label = changed_hk.m_Actions[ 0 ]->GetLabel();
307  wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode );
308 
309  if( label.IsEmpty() )
310  label = changed_hk.m_Actions[ 0 ]->GetName();
311 
312  // mark unsaved changes
313  if( changed_hk.m_EditKeycode != changed_hk.m_Actions[ 0 ]->GetHotKey() )
314  key_text += " *";
315 
316  SetItemText( i, 0, label );
317  SetItemText( i, 1, key_text);
318  }
319  }
320 
321  // Trigger a resize in case column widths have changed
322  wxSizeEvent dummy_evt;
323  OnSize( dummy_evt );
324 }
void OnSize(wxSizeEvent &aEvent)
Function OnSize Handle resizing of the control.
WIDGET_HOTKEY_CLIENT_DATA Stores 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:35
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...
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...

References WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), GetHKClientData(), GetNextItem(), KeyNameFromKeyCode(), HOTKEY::m_Actions, and OnSize().

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 606 of file widget_hotkey_list.cpp.

607 {
608  Freeze();
609  DeleteAllItems();
610 
611  HOTKEY_FILTER filter( aFilterStr );
612 
613  for( HOTKEY_SECTION& section: m_hk_store.GetSections() )
614  {
615  // Create parent tree item
616  wxTreeListItem parent = AppendItem( GetRootItem(), section.m_SectionName );
617 
618  for( HOTKEY& hotkey: section.m_HotKeys )
619  {
620  if( filter.FilterMatches( hotkey ) )
621  {
622  wxTreeListItem item = AppendItem( parent, wxEmptyString );
623  SetItemData( item, new WIDGET_HOTKEY_CLIENT_DATA( hotkey ) );
624  }
625  }
626 
627  Expand( parent );
628  }
629 
631  Thaw();
632 }
HOTKEY_STORE & m_hk_store
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
HOTKEY_FILTER.

References HOTKEY_FILTER::FilterMatches(), HOTKEY_STORE::GetSections(), m_hk_store, and UpdateFromClientData().

Referenced by ApplyFilterString(), and TransferDataToControl().

Member Data Documentation

◆ m_clamped_min_width

int WIDGET_HOTKEY_LIST::m_clamped_min_width
private

Definition at line 48 of file widget_hotkey_list.h.

Referenced by OnSize().

◆ m_context_menu_item

wxTreeListItem WIDGET_HOTKEY_LIST::m_context_menu_item
private

Definition at line 45 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 43 of file widget_hotkey_list.h.

Referenced by WIDGET_HOTKEY_LIST().

◆ m_rubber_band_column

int WIDGET_HOTKEY_LIST::m_rubber_band_column
private

Definition at line 47 of file widget_hotkey_list.h.

Referenced by OnSize().

◆ m_width_cache

std::map< wxString, int > WIDGET_HOTKEY_LIST::m_width_cache
staticprivate

Definition at line 50 of file widget_hotkey_list.h.

Referenced by MemoWidthFor().


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