Naming conventions.

This commit is contained in:
Jeff Young 2020-12-12 03:24:49 +00:00
parent 42d96fcadc
commit 65f9212f46
3 changed files with 142 additions and 129 deletions

View File

@ -249,7 +249,7 @@ private:
}; };
WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::GetHKClientData( wxTreeListItem aItem ) WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::getHKClientData( wxTreeListItem aItem )
{ {
if( aItem.IsOk() ) if( aItem.IsOk() )
{ {
@ -265,7 +265,7 @@ WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::GetHKClientData( wxTreeListItem a
WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::getExpectedHkClientData( wxTreeListItem aItem ) WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::getExpectedHkClientData( wxTreeListItem aItem )
{ {
const auto hkdata = GetHKClientData( aItem ); const auto hkdata = getHKClientData( aItem );
// This probably means a hotkey-only action is being attempted on // This probably means a hotkey-only action is being attempted on
// a row that is not a hotkey (like a section heading) // a row that is not a hotkey (like a section heading)
@ -275,11 +275,11 @@ WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::getExpectedHkClientData( wxTreeLi
} }
void WIDGET_HOTKEY_LIST::UpdateFromClientData() void WIDGET_HOTKEY_LIST::updateFromClientData()
{ {
for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) ) for( wxTreeListItem i = GetFirstItem(); i.IsOk(); i = GetNextItem( i ) )
{ {
WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( i ); WIDGET_HOTKEY_CLIENT_DATA* hkdata = getHKClientData( i );
if( hkdata ) if( hkdata )
{ {
@ -311,13 +311,13 @@ void WIDGET_HOTKEY_LIST::changeHotkey( HOTKEY& aHotkey, long aKey )
if( exists && aHotkey.m_EditKeycode != aKey ) if( exists && aHotkey.m_EditKeycode != aKey )
{ {
if( aKey == 0 || ResolveKeyConflicts( aHotkey.m_Actions[ 0 ], aKey ) ) if( aKey == 0 || resolveKeyConflicts( aHotkey.m_Actions[ 0 ], aKey ) )
aHotkey.m_EditKeycode = aKey; aHotkey.m_EditKeycode = aKey;
} }
} }
void WIDGET_HOTKEY_LIST::EditItem( wxTreeListItem aItem ) void WIDGET_HOTKEY_LIST::editItem( wxTreeListItem aItem )
{ {
WIDGET_HOTKEY_CLIENT_DATA* hkdata = getExpectedHkClientData( aItem ); WIDGET_HOTKEY_CLIENT_DATA* hkdata = getExpectedHkClientData( aItem );
@ -333,12 +333,12 @@ void WIDGET_HOTKEY_LIST::EditItem( wxTreeListItem aItem )
if( key ) if( key )
{ {
changeHotkey( hkdata->GetChangedHotkey(), key ); changeHotkey( hkdata->GetChangedHotkey(), key );
UpdateFromClientData(); updateFromClientData();
} }
} }
void WIDGET_HOTKEY_LIST::ResetItem( wxTreeListItem aItem, int aResetId ) void WIDGET_HOTKEY_LIST::resetItem( wxTreeListItem aItem, int aResetId )
{ {
WIDGET_HOTKEY_CLIENT_DATA* hkdata = getExpectedHkClientData( aItem ); WIDGET_HOTKEY_CLIENT_DATA* hkdata = getExpectedHkClientData( aItem );
@ -354,24 +354,24 @@ void WIDGET_HOTKEY_LIST::ResetItem( wxTreeListItem aItem, int aResetId )
else if( aResetId == ID_DEFAULT ) else if( aResetId == ID_DEFAULT )
changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetDefaultHotKey() ); changeHotkey( changed_hk, changed_hk.m_Actions[ 0 ]->GetDefaultHotKey() );
UpdateFromClientData(); updateFromClientData();
} }
void WIDGET_HOTKEY_LIST::OnActivated( wxTreeListEvent& aEvent ) void WIDGET_HOTKEY_LIST::onActivated( wxTreeListEvent& aEvent )
{ {
EditItem( aEvent.GetItem() ); editItem( aEvent.GetItem());
} }
void WIDGET_HOTKEY_LIST::OnContextMenu( wxTreeListEvent& aEvent ) void WIDGET_HOTKEY_LIST::onContextMenu( wxTreeListEvent& aEvent )
{ {
// Save the active event for use in OnMenu // Save the active event for use in OnMenu
m_context_menu_item = aEvent.GetItem(); m_context_menu_item = aEvent.GetItem();
wxMenu menu; wxMenu menu;
WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( m_context_menu_item ); WIDGET_HOTKEY_CLIENT_DATA* hkdata = getHKClientData( m_context_menu_item );
// Some actions only apply if the row is hotkey data // Some actions only apply if the row is hotkey data
if( hkdata ) if( hkdata )
@ -387,18 +387,16 @@ void WIDGET_HOTKEY_LIST::OnContextMenu( wxTreeListEvent& aEvent )
} }
void WIDGET_HOTKEY_LIST::OnMenu( wxCommandEvent& aEvent ) void WIDGET_HOTKEY_LIST::onMenu( wxCommandEvent& aEvent )
{ {
switch( aEvent.GetId() ) switch( aEvent.GetId() )
{ {
case ID_EDIT_HOTKEY: case ID_EDIT_HOTKEY:editItem( m_context_menu_item );
EditItem( m_context_menu_item );
break; break;
case ID_RESET: case ID_RESET:
case ID_CLEAR: case ID_CLEAR:
case ID_DEFAULT: case ID_DEFAULT:resetItem( m_context_menu_item, aEvent.GetId());
ResetItem( m_context_menu_item, aEvent.GetId() );
break; break;
default: default:
@ -407,7 +405,7 @@ void WIDGET_HOTKEY_LIST::OnMenu( wxCommandEvent& aEvent )
} }
bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts( TOOL_ACTION* aAction, long aKey ) bool WIDGET_HOTKEY_LIST::resolveKeyConflicts( TOOL_ACTION* aAction, long aKey )
{ {
HOTKEY* conflictingHotKey = nullptr; HOTKEY* conflictingHotKey = nullptr;
@ -429,7 +427,7 @@ bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts( TOOL_ACTION* aAction, long aKey )
{ {
// Reset the other hotkey // Reset the other hotkey
conflictingHotKey->m_EditKeycode = 0; conflictingHotKey->m_EditKeycode = 0;
UpdateFromClientData(); updateFromClientData();
return true; return true;
} }
@ -456,9 +454,9 @@ WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkey
if( !m_readOnly ) if( !m_readOnly )
{ {
// The event only apply if the widget is in editable mode // The event only apply if the widget is in editable mode
Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this ); Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::onActivated, this );
Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this ); Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::onContextMenu, this );
Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this ); Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::onMenu, this );
} }
} }
@ -481,7 +479,7 @@ void WIDGET_HOTKEY_LIST::ResetAllHotkeys( bool aResetToDefault )
else else
m_hk_store.ResetAllHotkeysToOriginal(); m_hk_store.ResetAllHotkeysToOriginal();
UpdateFromClientData(); updateFromClientData();
wxDataViewColumn* col = GetDataView()->GetColumn( 0 ); wxDataViewColumn* col = GetDataView()->GetColumn( 0 );
col->SetWidth( wxCOL_WIDTH_AUTOSIZE ); col->SetWidth( wxCOL_WIDTH_AUTOSIZE );
@ -535,7 +533,7 @@ void WIDGET_HOTKEY_LIST::updateShownItems( const wxString& aFilterStr )
Expand( parent ); Expand( parent );
} }
UpdateFromClientData(); updateFromClientData();
Thaw(); Thaw();
} }

View File

@ -39,97 +39,6 @@ class WIDGET_HOTKEY_CLIENT_DATA;
class WIDGET_HOTKEY_LIST : public wxTreeListCtrl class WIDGET_HOTKEY_LIST : public wxTreeListCtrl
{ {
HOTKEY_STORE& m_hk_store;
bool m_readOnly;
wxTreeListItem m_context_menu_item;
/**
* Method GetHKClientData
* Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid.
*/
WIDGET_HOTKEY_CLIENT_DATA* GetHKClientData( wxTreeListItem aItem );
/**
* 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.
*/
WIDGET_HOTKEY_CLIENT_DATA* getExpectedHkClientData( wxTreeListItem aItem );
/**
* Method UpdateFromClientData
* Refresh the visible text on the widget from the rows' client data objects.
*/
void UpdateFromClientData();
/**
* Method updateShownItems
*
* Update the items shown in the widget based on a given filter string.
*
* @param aFilterStr the string to filter with. Empty means no filter.
*/
void updateShownItems( const wxString& aFilterStr );
/**
* 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.
*
* @param aHotkey the change-able hotkey to try to change
* @param aKey the key code to change it to
*/
void changeHotkey( HOTKEY& aHotkey, long aKey );
protected:
/**
* Method EditItem
* Prompt the user for a new hotkey given a list item.
*/
void EditItem( wxTreeListItem aItem );
/**
* Method ResetItem
* Reset the item to either the default, the value when the dialog was opened, or none.
*/
void ResetItem( wxTreeListItem aItem, int aResetId );
/**
* Method OnActivated
* Handle activation of a row.
*/
void OnActivated( wxTreeListEvent& aEvent );
/**
* Method OnContextMenu
* Handle right-click on a row.
*/
void OnContextMenu( wxTreeListEvent& aEvent );
/**
* Method OnMenu
* Handle activation of a context menu item.
*/
void OnMenu( wxCommandEvent& aEvent );
/**
* 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.
*
* @param aKey - key to check
* @param aActionName - name of the action into which the key is proposed to be installed
*
* @return true iff the user accepted the overwrite or no conflict existed
*/
bool ResolveKeyConflicts( TOOL_ACTION* aAction, long aKey );
public: public:
/** /**
* Constructor WIDGET_HOTKEY_LIST * Constructor WIDGET_HOTKEY_LIST
@ -176,6 +85,99 @@ public:
* Map a keypress event to the correct key code for use as a hotkey. * Map a keypress event to the correct key code for use as a hotkey.
*/ */
static long MapKeypressToKeycode( const wxKeyEvent& aEvent ); static long MapKeypressToKeycode( const wxKeyEvent& aEvent );
protected:
/**
* Method editItem
* Prompt the user for a new hotkey given a list item.
*/
void editItem( wxTreeListItem aItem );
/**
* Method resetItem
* Reset the item to either the default, the value when the dialog was opened, or none.
*/
void resetItem( wxTreeListItem aItem, int aResetId );
/**
* Method onActivated
* Handle activation of a row.
*/
void onActivated( wxTreeListEvent& aEvent );
/**
* Method onContextMenu
* Handle right-click on a row.
*/
void onContextMenu( wxTreeListEvent& aEvent );
/**
* Method onMenu
* Handle activation of a context menu item.
*/
void onMenu( wxCommandEvent& aEvent );
/**
* 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.
*
* @param aKey - key to check
* @param aActionName - name of the action into which the key is proposed to be installed
*
* @return true iff the user accepted the overwrite or no conflict existed
*/
bool resolveKeyConflicts( TOOL_ACTION* aAction, long aKey );
private:
/**
* Method getHKClientData
* Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid.
*/
WIDGET_HOTKEY_CLIENT_DATA* getHKClientData( wxTreeListItem aItem );
/**
* 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.
*/
WIDGET_HOTKEY_CLIENT_DATA* getExpectedHkClientData( wxTreeListItem aItem );
/**
* Method updateFromClientData
* Refresh the visible text on the widget from the rows' client data objects.
*/
void updateFromClientData();
/**
* Method updateShownItems
*
* Update the items shown in the widget based on a given filter string.
*
* @param aFilterStr the string to filter with. Empty means no filter.
*/
void updateShownItems( const wxString& aFilterStr );
/**
* 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.
*
* @param aHotkey the change-able hotkey to try to change
* @param aKey the key code to change it to
*/
void changeHotkey( HOTKEY& aHotkey, long aKey );
private:
HOTKEY_STORE& m_hk_store;
bool m_readOnly;
wxTreeListItem m_context_menu_item;
}; };
#endif // __widget_hotkey_list__ #endif // __widget_hotkey_list__

View File

@ -38,7 +38,8 @@ class UNIT_BINDER;
class WIDGET_SAVE_RESTORE class WIDGET_SAVE_RESTORE
{ {
public: public:
WIDGET_SAVE_RESTORE( bool& aValidFlag ) : m_valid( aValidFlag ) WIDGET_SAVE_RESTORE( bool& aValidFlag ) :
m_valid( aValidFlag )
{ {
} }
@ -116,27 +117,33 @@ private:
}; };
union CONTROL { union CONTROL {
CONTROL( wxCheckBox* aCtrl ) : m_checkbox( aCtrl ) CONTROL( wxCheckBox* aCtrl ) :
m_checkbox( aCtrl )
{ {
} }
CONTROL( wxChoice* aCtrl ) : m_choice( aCtrl ) CONTROL( wxChoice* aCtrl ) :
m_choice( aCtrl )
{ {
} }
CONTROL( wxNotebook* aCtrl ) : m_notebook( aCtrl ) CONTROL( wxNotebook* aCtrl ) :
m_notebook( aCtrl )
{ {
} }
CONTROL( wxRadioBox* aCtrl ) : m_radiobox( aCtrl ) CONTROL( wxRadioBox* aCtrl ) :
m_radiobox( aCtrl )
{ {
} }
CONTROL( wxTextCtrl* aCtrl ) : m_textctrl( aCtrl ) CONTROL( wxTextCtrl* aCtrl ) :
m_textctrl( aCtrl )
{ {
} }
CONTROL( UNIT_BINDER* aCtrl ) : m_unit_binder( aCtrl ) CONTROL( UNIT_BINDER* aCtrl ) :
m_unit_binder( aCtrl )
{ {
} }
@ -149,19 +156,23 @@ private:
}; };
union DATA { union DATA {
DATA( long* aDest ) : m_long( aDest ) DATA( long* aDest ) :
m_long( aDest )
{ {
} }
DATA( bool* aDest ) : m_bool( aDest ) DATA( bool* aDest ) :
m_bool( aDest )
{ {
} }
DATA( wxString* aDest ) : m_str( aDest ) DATA( wxString* aDest ) :
m_str( aDest )
{ {
} }
DATA( double* aDest ) : m_double( aDest ) DATA( double* aDest ) :
m_double( aDest )
{ {
} }
@ -177,8 +188,10 @@ private:
struct WIDGET_CTRL_T struct WIDGET_CTRL_T
{ {
template <typename CTRL_T, typename DEST_T> template <typename CTRL_T, typename DEST_T>
WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) :
: m_type( aType ), m_control( &aCtrl ), m_dest( &aDest ) m_type( aType ),
m_control( &aCtrl ),
m_dest( &aDest )
{ {
} }