KiCad PCB EDA Suite
WIDGET_HOTKEY_LIST Class Reference

#include <widget_hotkey_list.h>

Inheritance diagram for WIDGET_HOTKEY_LIST:
TWO_COLUMN_TREE_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...
 
void SetRubberBandColumn (int aRubberBandColumn)
 Set the column number that will "rubber-band" (expand with available space). More...
 
void SetClampedMinWidth (int aClampedMinWidth)
 Set the minimum width of the non-rubber-band column. More...
 
void AutosizeColumns ()
 Recompute column sizes. 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)
 Method ResetItem Reset the item to the original from the dialog was created. More...
 
void ResetItemToDefault (wxTreeListItem aItem)
 Method ResetItemToDefault Reset the item to the default value. 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...
 
bool ResolveKeyConflicts (long aKey, const wxString &aSectionTag)
 Method ResolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict between keys. More...
 
int MemoWidthFor (const wxString &aStr)
 Memoized version of wx WidthFor(), which returns the width in pixels required to display a string. More...
 

Protected Attributes

int m_rubber_band_column
 
int m_clamped_min_width
 

Static Protected Attributes

static std::map< wxString, int > m_width_cache
 

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_DATAGetSelHKClientData ()
 Method GetSelHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the item being edited, or NULL if none is selected. 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 (CHANGED_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
 

Detailed Description

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

511  : TWO_COLUMN_TREE_LIST( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
512  m_hk_store( aHotkeyStore ),
513  m_readOnly( aReadOnly )
514 {
515  wxString command_header = _( "Command" );
516 
517  if( !m_readOnly )
518  command_header << " " << _( "(double-click to edit)" );
519 
520  AppendColumn( command_header );
521  AppendColumn( _( "Hotkey" ) );
522  SetRubberBandColumn( 0 );
524 
525  if( !m_readOnly )
526  {
527  // The event only apply if the widget is in editable mode
528  Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this );
529  Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this );
530  Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this );
531  }
532 }
void OnActivated(wxTreeListEvent &aEvent)
Method OnActivated Handle activation of a row.
TWO_COLUMN_TREE_LIST(wxWindow *aParent, wxWindowID aID, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxTL_DEFAULT_STYLE, const wxString &aName=wxTreeListCtrlNameStr)
Create a TWO_COLUMN_TREE_LIST.
void OnMenu(wxCommandEvent &aEvent)
Method OnMenu Handle activation of a context menu item.
static const int HOTKEY_MIN_WIDTH
Minimum width of the hotkey column.
HOTKEY_STORE & m_hk_store
void SetClampedMinWidth(int aClampedMinWidth)
Set the minimum width of the non-rubber-band column.
void SetRubberBandColumn(int aRubberBandColumn)
Set the column number that will "rubber-band" (expand with available space).
void OnContextMenu(wxTreeListEvent &aEvent)
Method OnContextMenu Handle right-click on a row.

References HOTKEY_MIN_WIDTH, m_readOnly, OnActivated(), OnContextMenu(), OnMenu(), TWO_COLUMN_TREE_LIST::SetClampedMinWidth(), and TWO_COLUMN_TREE_LIST::SetRubberBandColumn().

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

536 {
537  updateShownItems( aFilterStr );
538 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

Referenced by PANEL_HOTKEYS_EDITOR::OnFilterSearch().

◆ AutosizeColumns()

void TWO_COLUMN_TREE_LIST::AutosizeColumns ( )
inherited

Recompute column sizes.

This should be called after adding columns. There is no need to call this in an OnSize handler - this CALLS the OnSize handler.

Definition at line 49 of file two_column_tree_list.cpp.

50 {
51  wxSizeEvent dummy;
52  OnSize( dummy );
53 }
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
void OnSize(wxSizeEvent &aEvent)
Override buggy wxTreeListCtrl size handler.

References dummy(), and TWO_COLUMN_TREE_LIST::OnSize().

◆ changeHotkey()

void WIDGET_HOTKEY_LIST::changeHotkey ( CHANGED_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 340 of file widget_hotkey_list.cpp.

341 {
342  // See if this key code is handled in hotkeys names list
343  bool exists;
344  KeyNameFromKeyCode( aKey, &exists );
345 
346  auto& curr_hk = aHotkey.GetCurrentValue();
347 
348  if( exists && curr_hk.m_KeyCode != aKey )
349  {
350  const auto& tag = aHotkey.GetSectionTag();
351  bool can_update = ResolveKeyConflicts( aKey, tag );
352 
353  if( can_update )
354  {
355  curr_hk.m_KeyCode = aKey;
356  }
357  }
358 }
EDA_HOTKEY & GetCurrentValue()
Definition: hotkey_store.h:48
bool ResolveKeyConflicts(long aKey, const wxString &aSectionTag)
Method ResolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
const wxString & GetSectionTag() const
Definition: hotkey_store.h:86

References CHANGED_HOTKEY::GetCurrentValue(), CHANGED_HOTKEY::GetSectionTag(), KeyNameFromKeyCode(), and ResolveKeyConflicts().

Referenced by EditItem(), ResetItem(), and ResetItemToDefault().

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

362 {
364 
365  if( !hkdata )
366  return;
367 
368  wxString name = GetItemText( aItem, 0 );
369  wxString current_key = GetItemText( aItem, 1 );
370 
371  wxKeyEvent key_event = HK_PROMPT_DIALOG::PromptForKey( GetParent(), name, current_key );
372  long key = MapKeypressToKeycode( key_event );
373 
374  if( key )
375  {
376  changeHotkey( hkdata->GetChangedHotkey(), key );
378  }
379 }
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.
CHANGED_HOTKEY & GetChangedHotkey()
void changeHotkey(CHANGED_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...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
const char * name
Definition: DXF_plotter.cpp:61

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

301 {
302  const auto hkdata = GetHKClientData( aItem );
303 
304  // This probably means a hotkey-only action is being attempted on
305  // a row that is not a hotkey (like a section heading)
306  wxASSERT_MSG( hkdata != nullptr, "No hotkey data found for list item" );
307 
308  return hkdata;
309 }
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(), ResetItem(), and ResetItemToDefault().

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

273 {
274  if( aItem.IsOk() )
275  {
276  wxClientData* data = GetItemData( aItem );
277 
278  if( !data )
279  {
280  return NULL;
281  }
282  else
283  {
284  return static_cast<WIDGET_HOTKEY_CLIENT_DATA*>( data );
285  }
286  }
287  else
288  {
289  return NULL;
290  }
291 }

Referenced by getExpectedHkClientData(), GetSelHKClientData(), OnContextMenu(), and UpdateFromClientData().

◆ GetSelHKClientData()

WIDGET_HOTKEY_CLIENT_DATA * WIDGET_HOTKEY_LIST::GetSelHKClientData ( )
private

Method GetSelHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the item being edited, or NULL if none is selected.

Definition at line 294 of file widget_hotkey_list.cpp.

295 {
296  return GetHKClientData( GetSelection() );
297 }
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().

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

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

References GR_KB_ALT, GR_KB_CTRL, and GR_KB_SHIFT.

Referenced by EditItem().

◆ MemoWidthFor()

int TWO_COLUMN_TREE_LIST::MemoWidthFor ( const wxString &  aStr)
protectedinherited

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

This function is REALLY SLOW on macOS.

Definition at line 123 of file two_column_tree_list.cpp.

124 {
125  int width;
126  auto found = m_width_cache.find( aStr );
127 
128  if( found == m_width_cache.end() )
129  {
130  width = WidthFor( aStr );
131  m_width_cache[aStr] = width;
132  }
133  else
134  {
135  width = found->second;
136  }
137 
138  return width;
139 }
static std::map< wxString, int > m_width_cache

References TWO_COLUMN_TREE_LIST::m_width_cache.

Referenced by TWO_COLUMN_TREE_LIST::OnSize().

◆ OnActivated()

void WIDGET_HOTKEY_LIST::OnActivated ( wxTreeListEvent &  aEvent)
protected

Method OnActivated Handle activation of a row.

Definition at line 411 of file widget_hotkey_list.cpp.

412 {
413  EditItem( aEvent.GetItem() );
414 }
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 417 of file widget_hotkey_list.cpp.

418 {
419  // Save the active event for use in OnMenu
420  m_context_menu_item = aEvent.GetItem();
421 
422  wxMenu menu;
423 
425 
426  // Some actions only apply if the row is hotkey data
427  if( hkdata )
428  {
429  menu.Append( ID_EDIT, _( "Edit..." ) );
430  menu.Append( ID_RESET, _( "Undo Changes" ) );
431  menu.Append( ID_DEFAULT, _( "Restore Default" ) );
432  menu.Append( wxID_SEPARATOR );
433  }
434 
435  menu.Append( ID_RESET_ALL, _( "Undo All Changes" ) );
436  menu.Append( ID_DEFAULT_ALL, _( "Restore All to Default" ) );
437 
438  PopupMenu( &menu );
439 }
wxTreeListItem m_context_menu_item
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
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_DEFAULT, ID_DEFAULT_ALL, ID_EDIT, ID_RESET, ID_RESET_ALL, 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 442 of file widget_hotkey_list.cpp.

443 {
444  switch( aEvent.GetId() )
445  {
446  case ID_EDIT:
448  break;
449 
450  case ID_RESET:
452  break;
453 
454  case ID_DEFAULT:
456  break;
457 
458  case ID_RESET_ALL:
459  ResetAllHotkeys( false );
460  break;
461 
462  case ID_DEFAULT_ALL:
463  ResetAllHotkeys( true );
464  break;
465 
466  default:
467  wxFAIL_MSG( wxT( "Unknown ID in context menu event" ) );
468  }
469 }
void ResetItemToDefault(wxTreeListItem aItem)
Method ResetItemToDefault Reset the item to the default value.
wxTreeListItem m_context_menu_item
void ResetItem(wxTreeListItem aItem)
Method ResetItem Reset the item to the original from the dialog was created.
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.
void ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.

References EditItem(), ID_DEFAULT, ID_DEFAULT_ALL, ID_EDIT, ID_RESET, ID_RESET_ALL, m_context_menu_item, ResetAllHotkeys(), ResetItem(), and ResetItemToDefault().

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.

◆ 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 hotkeym, else reset to the value they had when the dialog was invoked.

Definition at line 541 of file widget_hotkey_list.cpp.

542 {
543  Freeze();
544 
545  // Reset all the hotkeys, not just the ones shown
546  // Should not need to check conflicts, as the state we're about
547  // to set to a should be consistent
548  if( aResetToDefault )
549  {
551  }
552  else
553  {
555  }
556 
558  Thaw();
559 }
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(), and OnMenu().

◆ ResetItem()

void WIDGET_HOTKEY_LIST::ResetItem ( wxTreeListItem  aItem)
protected

Method ResetItem Reset the item to the original from the dialog was created.

Definition at line 382 of file widget_hotkey_list.cpp.

383 {
385 
386  if( !hkdata )
387  return;
388 
389  auto& changed_hk = hkdata->GetChangedHotkey();
390  const auto& orig_hk = changed_hk.GetOriginalValue();
391 
392  changeHotkey( changed_hk, orig_hk.m_KeyCode );
394 }
CHANGED_HOTKEY & GetChangedHotkey()
void changeHotkey(CHANGED_HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
const EDA_HOTKEY & GetOriginalValue() const
Gets the original value of the hotkey.
Definition: hotkey_store.h:64
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...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), CHANGED_HOTKEY::GetOriginalValue(), and UpdateFromClientData().

Referenced by OnMenu().

◆ ResetItemToDefault()

void WIDGET_HOTKEY_LIST::ResetItemToDefault ( wxTreeListItem  aItem)
protected

Method ResetItemToDefault Reset the item to the default value.

Definition at line 397 of file widget_hotkey_list.cpp.

398 {
400 
401  if( !hkdata )
402  return;
403 
404  auto& changed_hk = hkdata->GetChangedHotkey();
405 
406  changeHotkey( changed_hk, changed_hk.GetCurrentValue().GetDefaultKeyCode() );
408 }
CHANGED_HOTKEY & GetChangedHotkey()
void changeHotkey(CHANGED_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...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.

References changeHotkey(), WIDGET_HOTKEY_CLIENT_DATA::GetChangedHotkey(), getExpectedHkClientData(), and UpdateFromClientData().

Referenced by OnMenu().

◆ ResolveKeyConflicts()

bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts ( long  aKey,
const wxString &  aSectionTag 
)
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
aSectionTag- section tag into which the key is proposed to be installed
Returns
true iff the user accepted the overwrite or no conflict existed

Definition at line 472 of file widget_hotkey_list.cpp.

473 {
474  EDA_HOTKEY* conflicting_key = nullptr;
475  EDA_HOTKEY_CONFIG* conflicting_section = nullptr;
476 
477  m_hk_store.CheckKeyConflicts( aKey, aSectionTag, &conflicting_key, &conflicting_section );
478 
479  if( conflicting_key != nullptr )
480  {
481  wxString info = wxGetTranslation( conflicting_key->m_InfoMsg );
482  wxString msg = wxString::Format(
483  _( "\"%s\" is already assigned to \"%s\" in section \"%s\". Are you sure you want "
484  "to change its assignment?" ),
485  KeyNameFromKeyCode( aKey ), GetChars( info ),
486  *(conflicting_section->m_Title) );
487 
488  wxMessageDialog dlg( GetParent(), msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );
489 
490  if( dlg.ShowModal() == wxID_YES )
491  {
492  // Reset the other hotkey
493  conflicting_key->m_KeyCode = 0;
495  return true;
496  }
497  else
498  {
499  return false;
500  }
501  }
502  else
503  {
504  return true;
505  }
506 }
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:94
HOTKEY_STORE & m_hk_store
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
wxString m_InfoMsg
Definition: hotkeys_basic.h:66
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:100
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
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
wxString * m_Title
Definition: hotkeys_basic.h:99
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
bool CheckKeyConflicts(long aKey, const wxString &aSectionTag, EDA_HOTKEY **aConfKey, EDA_HOTKEY_CONFIG **aConfSect)
Check whether the given key conflicts with anything in this store.

References HOTKEY_STORE::CheckKeyConflicts(), Format(), GetChars(), KeyNameFromKeyCode(), m_hk_store, EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, EDA_HOTKEY_CONFIG::m_Title, and UpdateFromClientData().

Referenced by changeHotkey().

◆ SetClampedMinWidth()

void TWO_COLUMN_TREE_LIST::SetClampedMinWidth ( int  aClampedMinWidth)
inlineinherited

Set the minimum width of the non-rubber-band column.

Definition at line 65 of file two_column_tree_list.h.

66  {
67  m_clamped_min_width = aClampedMinWidth;
68  }

References TWO_COLUMN_TREE_LIST::m_clamped_min_width.

Referenced by WIDGET_HOTKEY_LIST().

◆ SetRubberBandColumn()

void TWO_COLUMN_TREE_LIST::SetRubberBandColumn ( int  aRubberBandColumn)
inlineinherited

Set the column number that will "rubber-band" (expand with available space).

As this is a TWO column tree list, this must be zero or one.

Definition at line 57 of file two_column_tree_list.h.

58  {
59  m_rubber_band_column = aRubberBandColumn;
60  }

References TWO_COLUMN_TREE_LIST::m_rubber_band_column.

Referenced by WIDGET_HOTKEY_LIST().

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

599 {
601  return true;
602 }
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 562 of file widget_hotkey_list.cpp.

563 {
564  updateShownItems( "" );
565  return true;
566 }
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.

References updateShownItems().

Referenced by 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 312 of file widget_hotkey_list.cpp.

313 {
314  for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
315  {
317 
318  if( hkdata )
319  {
320  const auto& changed_hk = hkdata->GetChangedHotkey();
321  const EDA_HOTKEY& hk = changed_hk.GetCurrentValue();
322 
323  wxString key_text = KeyNameFromKeyCode( hk.m_KeyCode );
324 
325  // mark unsaved changes
326  if( changed_hk.HasUnsavedChange() )
327  key_text += " *";
328 
329  SetItemText( i, 0, wxGetTranslation( hk.m_InfoMsg ) );
330  SetItemText( i, 1, key_text);
331  }
332  }
333 
334  // Trigger a resize in case column widths have changed
335  wxSizeEvent dummy_evt;
336  TWO_COLUMN_TREE_LIST::OnSize( dummy_evt );
337 }
CHANGED_HOTKEY & GetChangedHotkey()
Class 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.
wxString m_InfoMsg
Definition: hotkeys_basic.h:66
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
size_t i
Definition: json11.cpp:597
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...
void OnSize(wxSizeEvent &aEvent)
Override buggy wxTreeListCtrl size handler.
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(), i, KeyNameFromKeyCode(), EDA_HOTKEY::m_InfoMsg, EDA_HOTKEY::m_KeyCode, and TWO_COLUMN_TREE_LIST::OnSize().

Referenced by EditItem(), ResetAllHotkeys(), ResetItem(), ResetItemToDefault(), 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 569 of file widget_hotkey_list.cpp.

570 {
571  Freeze();
572  DeleteAllItems();
573 
574  HOTKEY_FILTER filter( aFilterStr );
575 
576  for( auto& section: m_hk_store.GetSections() )
577  {
578  // Create parent tree item
579  wxTreeListItem parent = AppendItem( GetRootItem(), section.m_name );
580 
581  for( auto& hotkey: section.m_hotkeys )
582  {
583  if( filter.FilterMatches( hotkey.GetCurrentValue() ) )
584  {
585  wxTreeListItem item = AppendItem( parent, wxEmptyString );
586  SetItemData( item, new WIDGET_HOTKEY_CLIENT_DATA( hotkey ) );
587  }
588  }
589 
590  Expand( parent );
591  }
592 
594  Thaw();
595 }
HOTKEY_STORE & m_hk_store
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
SECTION_LIST & GetSections()
Get the list of sections managed by this store.
Class 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 TWO_COLUMN_TREE_LIST::m_clamped_min_width
protectedinherited

◆ m_context_menu_item

wxTreeListItem WIDGET_HOTKEY_LIST::m_context_menu_item
private

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

Referenced by WIDGET_HOTKEY_LIST().

◆ m_rubber_band_column

int TWO_COLUMN_TREE_LIST::m_rubber_band_column
protectedinherited

◆ m_width_cache

std::map< wxString, int > TWO_COLUMN_TREE_LIST::m_width_cache
staticprotectedinherited

Definition at line 93 of file two_column_tree_list.h.

Referenced by TWO_COLUMN_TREE_LIST::MemoWidthFor().


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