2016-01-16 01:56:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Chris Pavlina <pavlina.chris@gmail.com>
|
2017-02-19 02:39:55 +00:00
|
|
|
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-01-16 01:56:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __widget_hotkey_list__
|
|
|
|
#define __widget_hotkey_list__
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <wx/treelist.h>
|
2020-03-26 16:06:37 +00:00
|
|
|
#include <wx/dataview.h>
|
2016-01-16 01:56:57 +00:00
|
|
|
|
|
|
|
#include <hotkeys_basic.h>
|
2018-09-26 14:26:26 +00:00
|
|
|
#include <hotkey_store.h>
|
2016-01-16 01:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WIDGET_HOTKEY_CLIENT_DATA;
|
|
|
|
|
2020-03-26 16:06:37 +00:00
|
|
|
class WIDGET_HOTKEY_LIST : public wxTreeListCtrl
|
2016-01-16 01:56:57 +00:00
|
|
|
{
|
2020-12-12 03:24:49 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor WIDGET_HOTKEY_LIST
|
|
|
|
* Create a WIDGET_HOTKEY_LIST.
|
|
|
|
*
|
|
|
|
* @param aParent - parent widget
|
|
|
|
* @param aHotkeys - EDA_HOTKEY_CONFIG data - a hotkey store is constructed
|
|
|
|
* from this.
|
|
|
|
*/
|
|
|
|
WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, bool aReadOnly );
|
2020-03-26 16:06:37 +00:00
|
|
|
|
2016-01-16 01:56:57 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method ApplyFilterString
|
|
|
|
* Apply a filter string to the hotkey list, selecting which hotkeys
|
|
|
|
* to show.
|
|
|
|
*
|
|
|
|
* @param aFilterStr the string to filter by
|
2016-01-16 01:56:57 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void ApplyFilterString( const wxString& aFilterStr );
|
2016-01-16 01:56:57 +00:00
|
|
|
|
2018-09-27 13:44:03 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Set hotkeys in the control to default or original values.
|
|
|
|
* @param aResetToDefault if true, reset to the defaults inherent to the hotkeys, else
|
|
|
|
* reset to the value they had when the dialog was invoked.
|
2018-09-27 13:44:03 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void ResetAllHotkeys( bool aResetToDefault );
|
2018-09-27 13:44:03 +00:00
|
|
|
|
2016-01-16 01:56:57 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method TransferDataToControl
|
|
|
|
* Load the hotkey data from the store into the control.
|
|
|
|
* @return true iff the operation was successful
|
2016-01-16 01:56:57 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
bool TransferDataToControl();
|
2016-01-16 01:56:57 +00:00
|
|
|
|
2018-08-01 09:15:05 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method TransferDataFromControl
|
|
|
|
* Save the hotkey data from the control.
|
|
|
|
* @return true iff the operation was successful
|
2018-08-01 09:15:05 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
bool TransferDataFromControl();
|
2018-08-01 09:15:05 +00:00
|
|
|
|
2018-09-27 12:31:24 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Static method MapKeypressToKeycode
|
|
|
|
* Map a keypress event to the correct key code for use as a hotkey.
|
2018-09-27 12:31:24 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
static long MapKeypressToKeycode( const wxKeyEvent& aEvent );
|
2018-09-27 12:31:24 +00:00
|
|
|
|
2016-01-16 01:56:57 +00:00
|
|
|
protected:
|
2016-01-16 01:58:53 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method editItem
|
2016-01-16 01:58:53 +00:00
|
|
|
* Prompt the user for a new hotkey given a list item.
|
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void editItem( wxTreeListItem aItem );
|
2016-01-16 01:58:53 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method resetItem
|
2019-06-14 10:55:54 +00:00
|
|
|
* Reset the item to either the default, the value when the dialog was opened, or none.
|
2016-01-16 01:58:53 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void resetItem( wxTreeListItem aItem, int aResetId );
|
2016-03-30 18:51:47 +00:00
|
|
|
|
2016-01-16 01:56:57 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method onActivated
|
2016-01-16 01:57:10 +00:00
|
|
|
* Handle activation of a row.
|
2016-01-16 01:56:57 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void onActivated( wxTreeListEvent& aEvent );
|
2016-01-16 01:56:57 +00:00
|
|
|
|
2016-01-16 01:58:53 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method onContextMenu
|
2016-01-16 01:58:53 +00:00
|
|
|
* Handle right-click on a row.
|
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void onContextMenu( wxTreeListEvent& aEvent );
|
2016-01-16 01:58:53 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method onMenu
|
2016-01-16 01:58:53 +00:00
|
|
|
* Handle activation of a context menu item.
|
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void onMenu( wxCommandEvent& aEvent );
|
2016-01-16 01:58:53 +00:00
|
|
|
|
2016-01-16 01:56:57 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method resolveKeyConflicts
|
2020-03-26 16:06:37 +00:00
|
|
|
* 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.
|
2016-01-16 01:56:57 +00:00
|
|
|
*
|
|
|
|
* The method will do conflict resolution depending on aSectionTag.
|
2021-06-09 19:32:58 +00:00
|
|
|
* g_CommonSectionTag means the key code must only be checked with the aSectionTag section
|
2020-03-26 16:06:37 +00:00
|
|
|
* and g_CommonSectionTag section.
|
2016-01-16 01:56:57 +00:00
|
|
|
*
|
|
|
|
* @param aKey - key to check
|
2019-06-09 21:57:23 +00:00
|
|
|
* @param aActionName - name of the action into which the key is proposed to be installed
|
2016-01-16 01:56:57 +00:00
|
|
|
*
|
|
|
|
* @return true iff the user accepted the overwrite or no conflict existed
|
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
bool resolveKeyConflicts( TOOL_ACTION* aAction, long aKey );
|
2016-01-16 01:56:57 +00:00
|
|
|
|
2020-12-12 03:24:49 +00:00
|
|
|
private:
|
2016-01-16 01:56:57 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method getHKClientData
|
|
|
|
* Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid.
|
2016-01-16 01:56:57 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
WIDGET_HOTKEY_CLIENT_DATA* getHKClientData( wxTreeListItem aItem );
|
2016-01-16 01:56:57 +00:00
|
|
|
|
2018-08-01 09:15:05 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* 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.
|
2018-08-01 09:15:05 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
WIDGET_HOTKEY_CLIENT_DATA* getExpectedHkClientData( wxTreeListItem aItem );
|
2018-08-01 09:15:05 +00:00
|
|
|
|
2016-03-29 16:35:24 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* Method updateFromClientData
|
|
|
|
* Refresh the visible text on the widget from the rows' client data objects.
|
2016-03-29 16:35:24 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void updateFromClientData();
|
2016-03-29 16:35:24 +00:00
|
|
|
|
2016-01-16 01:56:57 +00:00
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* 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.
|
2016-01-16 01:56:57 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void updateShownItems( const wxString& aFilterStr );
|
2016-01-16 01:56:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-12 03:24:49 +00:00
|
|
|
* 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
|
2016-01-16 01:56:57 +00:00
|
|
|
*/
|
2020-12-12 03:24:49 +00:00
|
|
|
void changeHotkey( HOTKEY& aHotkey, long aKey );
|
2016-01-16 01:58:31 +00:00
|
|
|
|
2020-12-17 01:51:18 +00:00
|
|
|
/**
|
|
|
|
* Recalculates column widths after model has changed
|
|
|
|
*/
|
|
|
|
void updateColumnWidths();
|
|
|
|
|
2020-12-12 03:24:49 +00:00
|
|
|
private:
|
|
|
|
HOTKEY_STORE& m_hk_store;
|
|
|
|
bool m_readOnly;
|
|
|
|
|
|
|
|
wxTreeListItem m_context_menu_item;
|
2016-01-16 01:56:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __widget_hotkey_list__
|