← Back to team overview

kicad-developers team mailing list archive

[RFC/PATCH] Reset To Default button for Hotkeys Editor

 

Hello,
I generated and attached only one patch as Jean-Pierre suggested.

Have a nice day!
Jan Dolezal

---Original message---
Re: [Kicad-developers] [PATCH 3/3] Action for "Defaults" button in "Hotkey Editor" dialog (lp:1395442)

On 03/28/2016 09:29 PM, Chris Pavlina wrote:
> Personally I prefer the patches as separate commits like this - I find it
> easier to review in small chunks, and easier to give useful feedback if
> something is wrong. It's trivial to commit them together anyway (just apply all > of them in sequence with 'patch', or if you use git and git-am just squash the
> commits with a rebase).
>
> On Mon, Mar 28, 2016 at 07:55:05PM +0200, jp charras wrote:
>> Le 28/03/2016 01:01, Jan Dolezal a écrit :
>>> ---
>>>   common/dialogs/dialog_hotkeys_editor.cpp |  1 +
>>>   common/widgets/widget_hotkey_list.cpp    | 20 ++++++++++++++++++++
>>>   include/widgets/widget_hotkey_list.h     |  7 +++++++
>>>   3 files changed, 28 insertions(+)
>>>
>>
>> Patches inside mails are never easy to apply.
>> Please, generate only one patch, and send us as attached file.
>>
>> Thanks.
>>
>>
>> --
>> Jean-Pierre CHARRAS
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
>From 9ade44359fe4779efe9d7c23c7b091a500cee815 Mon Sep 17 00:00:00 2001
From: Jan Dolezal <dolezj21@xxxxxxxxxxx>
Date: Tue, 29 Mar 2016 00:24:27 +0200
Subject: [PATCH] Add "Defaults" button to the "Hoteky Editor" dialog
 (lp:1395442)

The dialog is available from "Preferences->Hotkeys->Edit Hotkeys" in
Part Library Editor, Pcbnew, Footprint Editor, GerbView, Pl_Editor and
KiCad main program.
---
 common/dialogs/dialog_hotkeys_editor.cpp      |  5 ++
 common/dialogs/dialog_hotkeys_editor_base.cpp |  7 ++-
 common/dialogs/dialog_hotkeys_editor_base.fbp | 88 +++++++++++++++++++++++++++
 common/dialogs/dialog_hotkeys_editor_base.h   |  4 +-
 common/hotkeys_basic.cpp                      |  6 +-
 common/widgets/widget_hotkey_list.cpp         | 20 ++++++
 include/dialog_hotkeys_editor.h               |  8 +++
 include/hotkeys_basic.h                       |  3 +
 include/widgets/widget_hotkey_list.h          |  7 +++
 9 files changed, 144 insertions(+), 4 deletions(-)

diff --git a/common/dialogs/dialog_hotkeys_editor.cpp b/common/dialogs/dialog_hotkeys_editor.cpp
index 96a8d3b..eed8f1a 100644
--- a/common/dialogs/dialog_hotkeys_editor.cpp
+++ b/common/dialogs/dialog_hotkeys_editor.cpp
@@ -84,3 +84,8 @@ void HOTKEYS_EDITOR_DIALOG::ResetClicked( wxCommandEvent& aEvent )
 {
     m_hotkeyListCtrl->TransferDataToControl();
 }
+
+void HOTKEYS_EDITOR_DIALOG::DefaultsClicked( wxCommandEvent& aEvent )
+{
+    m_hotkeyListCtrl->TransferDefaultsToControl();
+}
diff --git a/common/dialogs/dialog_hotkeys_editor_base.cpp b/common/dialogs/dialog_hotkeys_editor_base.cpp
index 5373ac5..4fc60f4 100644
--- a/common/dialogs/dialog_hotkeys_editor_base.cpp
+++ b/common/dialogs/dialog_hotkeys_editor_base.cpp
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Dec 28 2015)
+// C++ code generated with wxFormBuilder (version Jun 17 2015)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -28,6 +28,9 @@ HOTKEYS_EDITOR_DIALOG_BASE::HOTKEYS_EDITOR_DIALOG_BASE( wxWindow* parent, wxWind
 	m_resetButton = new wxButton( this, wxID_RESET, _("Reset"), wxDefaultPosition, wxDefaultSize, 0 );
 	b_buttonsSizer->Add( m_resetButton, 0, wxALL|wxEXPAND, 5 );
 	
+	m_defaultButton = new wxButton( this, wxID_ANY, _("Defaults"), wxDefaultPosition, wxDefaultSize, 0 );
+	b_buttonsSizer->Add( m_defaultButton, 0, wxALL|wxEXPAND, 5 );
+	
 	
 	b_buttonsSizer->Add( 0, 0, 1, wxEXPAND, 5 );
 	
@@ -49,11 +52,13 @@ HOTKEYS_EDITOR_DIALOG_BASE::HOTKEYS_EDITOR_DIALOG_BASE( wxWindow* parent, wxWind
 	
 	// Connect Events
 	m_resetButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::ResetClicked ), NULL, this );
+	m_defaultButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::DefaultsClicked ), NULL, this );
 }
 
 HOTKEYS_EDITOR_DIALOG_BASE::~HOTKEYS_EDITOR_DIALOG_BASE()
 {
 	// Disconnect Events
 	m_resetButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::ResetClicked ), NULL, this );
+	m_defaultButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::DefaultsClicked ), NULL, this );
 	
 }
diff --git a/common/dialogs/dialog_hotkeys_editor_base.fbp b/common/dialogs/dialog_hotkeys_editor_base.fbp
index 6a096fa..3c66e1b 100644
--- a/common/dialogs/dialog_hotkeys_editor_base.fbp
+++ b/common/dialogs/dialog_hotkeys_editor_base.fbp
@@ -353,6 +353,94 @@
                                 <event name="OnUpdateUI"></event>
                             </object>
                         </object>
+                        <object class="sizeritem" expanded="0">
+                            <property name="border">5</property>
+                            <property name="flag">wxALL|wxEXPAND</property>
+                            <property name="proportion">0</property>
+                            <object class="wxButton" expanded="0">
+                                <property name="BottomDockable">1</property>
+                                <property name="LeftDockable">1</property>
+                                <property name="RightDockable">1</property>
+                                <property name="TopDockable">1</property>
+                                <property name="aui_layer"></property>
+                                <property name="aui_name"></property>
+                                <property name="aui_position"></property>
+                                <property name="aui_row"></property>
+                                <property name="best_size"></property>
+                                <property name="bg"></property>
+                                <property name="caption"></property>
+                                <property name="caption_visible">1</property>
+                                <property name="center_pane">0</property>
+                                <property name="close_button">1</property>
+                                <property name="context_help"></property>
+                                <property name="context_menu">1</property>
+                                <property name="default">0</property>
+                                <property name="default_pane">0</property>
+                                <property name="dock">Dock</property>
+                                <property name="dock_fixed">0</property>
+                                <property name="docking">Left</property>
+                                <property name="enabled">1</property>
+                                <property name="fg"></property>
+                                <property name="floatable">1</property>
+                                <property name="font"></property>
+                                <property name="gripper">0</property>
+                                <property name="hidden">0</property>
+                                <property name="id">wxID_ANY</property>
+                                <property name="label">Defaults</property>
+                                <property name="max_size"></property>
+                                <property name="maximize_button">0</property>
+                                <property name="maximum_size"></property>
+                                <property name="min_size"></property>
+                                <property name="minimize_button">0</property>
+                                <property name="minimum_size"></property>
+                                <property name="moveable">1</property>
+                                <property name="name">m_defaultButton</property>
+                                <property name="pane_border">1</property>
+                                <property name="pane_position"></property>
+                                <property name="pane_size"></property>
+                                <property name="permission">protected</property>
+                                <property name="pin_button">1</property>
+                                <property name="pos"></property>
+                                <property name="resize">Resizable</property>
+                                <property name="show">1</property>
+                                <property name="size"></property>
+                                <property name="style"></property>
+                                <property name="subclass"></property>
+                                <property name="toolbar_pane">0</property>
+                                <property name="tooltip"></property>
+                                <property name="validator_data_type"></property>
+                                <property name="validator_style">wxFILTER_NONE</property>
+                                <property name="validator_type">wxDefaultValidator</property>
+                                <property name="validator_variable"></property>
+                                <property name="window_extra_style"></property>
+                                <property name="window_name"></property>
+                                <property name="window_style"></property>
+                                <event name="OnButtonClick">DefaultsClicked</event>
+                                <event name="OnChar"></event>
+                                <event name="OnEnterWindow"></event>
+                                <event name="OnEraseBackground"></event>
+                                <event name="OnKeyDown"></event>
+                                <event name="OnKeyUp"></event>
+                                <event name="OnKillFocus"></event>
+                                <event name="OnLeaveWindow"></event>
+                                <event name="OnLeftDClick"></event>
+                                <event name="OnLeftDown"></event>
+                                <event name="OnLeftUp"></event>
+                                <event name="OnMiddleDClick"></event>
+                                <event name="OnMiddleDown"></event>
+                                <event name="OnMiddleUp"></event>
+                                <event name="OnMotion"></event>
+                                <event name="OnMouseEvents"></event>
+                                <event name="OnMouseWheel"></event>
+                                <event name="OnPaint"></event>
+                                <event name="OnRightDClick"></event>
+                                <event name="OnRightDown"></event>
+                                <event name="OnRightUp"></event>
+                                <event name="OnSetFocus"></event>
+                                <event name="OnSize"></event>
+                                <event name="OnUpdateUI"></event>
+                            </object>
+                        </object>
                         <object class="sizeritem" expanded="1">
                             <property name="border">5</property>
                             <property name="flag">wxEXPAND</property>
diff --git a/common/dialogs/dialog_hotkeys_editor_base.h b/common/dialogs/dialog_hotkeys_editor_base.h
index a59f560..3d4a880 100644
--- a/common/dialogs/dialog_hotkeys_editor_base.h
+++ b/common/dialogs/dialog_hotkeys_editor_base.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Dec 28 2015)
+// C++ code generated with wxFormBuilder (version Jun 17 2015)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -40,12 +40,14 @@ class HOTKEYS_EDITOR_DIALOG_BASE : public DIALOG_SHIM
 		wxStaticText* m_staticText1;
 		wxPanel* m_panelHotkeys;
 		wxButton* m_resetButton;
+		wxButton* m_defaultButton;
 		wxStdDialogButtonSizer* m_sdbSizer;
 		wxButton* m_sdbSizerOK;
 		wxButton* m_sdbSizerCancel;
 		
 		// Virtual event handlers, overide them in your derived class
 		virtual void ResetClicked( wxCommandEvent& event ) { event.Skip(); }
+		virtual void DefaultsClicked( wxCommandEvent& event ) { event.Skip(); }
 		
 	
 	public:
diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp
index 04dfd7f..40e7a82 100644
--- a/common/hotkeys_basic.cpp
+++ b/common/hotkeys_basic.cpp
@@ -55,7 +55,8 @@ wxString g_CommonSectionTag( wxT( "[common]" ) );
  * file.
  */
 
-EDA_HOTKEY::EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent )
+EDA_HOTKEY::EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent ) :
+    m_DefaultKeyCode( keycode )         // initialize DefaultKeyCode
 {
     m_KeyCode = keycode;            // Key code (ascii value for ascii keys
 
@@ -69,7 +70,8 @@ EDA_HOTKEY::EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int i
 }
 
 
-EDA_HOTKEY::EDA_HOTKEY( const EDA_HOTKEY* base )
+EDA_HOTKEY::EDA_HOTKEY( const EDA_HOTKEY* base ) :
+    m_DefaultKeyCode( base->m_DefaultKeyCode ) // initialize DefaultKeyCode
 {
     m_KeyCode     = base->m_KeyCode;
     m_InfoMsg     = base->m_InfoMsg;
diff --git a/common/widgets/widget_hotkey_list.cpp b/common/widgets/widget_hotkey_list.cpp
index ebab4f5..d5c1517 100644
--- a/common/widgets/widget_hotkey_list.cpp
+++ b/common/widgets/widget_hotkey_list.cpp
@@ -575,6 +575,26 @@ void WIDGET_HOTKEY_LIST::InstallOnPanel( wxPanel* aPanel )
 }
 
 
+bool WIDGET_HOTKEY_LIST::TransferDefaultsToControl()
+{
+    Freeze();
+
+    for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
+    {
+        WIDGET_HOTKEY_CLIENT_DATA* hkdata = GetHKClientData( item );
+        if( hkdata == NULL)
+            continue;
+
+        hkdata->GetHotkey().ResetKeyCodeToDefault();
+    }
+
+    UpdateFromClientData();
+    Thaw();
+
+    return true;
+}
+
+
 bool WIDGET_HOTKEY_LIST::TransferDataToControl()
 {
     Freeze();
diff --git a/include/dialog_hotkeys_editor.h b/include/dialog_hotkeys_editor.h
index 801bea9..3107b61 100644
--- a/include/dialog_hotkeys_editor.h
+++ b/include/dialog_hotkeys_editor.h
@@ -66,6 +66,14 @@ private:
      * @param aEvent is the button press event, unused
      */
     void ResetClicked( wxCommandEvent& aEvent );
+
+    /**
+     * Function DefaultsClicked
+     * Set the hotkeys to the default values (values after installation)
+     *
+     * @param aEvent is the button press event, unused
+     */
+    void DefaultsClicked( wxCommandEvent& aEvent );
 };
 
 /**
diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h
index 089fcce..b08311b 100644
--- a/include/hotkeys_basic.h
+++ b/include/hotkeys_basic.h
@@ -56,6 +56,8 @@ extern wxString g_CommonSectionTag;
  */
 class EDA_HOTKEY
 {
+private:
+    const int m_DefaultKeyCode; // Key code assigned upon object construction, to be used as default value
 public:
     int      m_KeyCode;      // Key code (ascii value for ascii keys or wxWidgets code for function key
     wxString m_InfoMsg;      // info message.
@@ -65,6 +67,7 @@ public:
 public:
     EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent = 0 );
     EDA_HOTKEY( const EDA_HOTKEY* base);
+    void ResetKeyCodeToDefault() { m_KeyCode = m_DefaultKeyCode; }
 };
 
 
diff --git a/include/widgets/widget_hotkey_list.h b/include/widgets/widget_hotkey_list.h
index bfaf010..60e78fb 100644
--- a/include/widgets/widget_hotkey_list.h
+++ b/include/widgets/widget_hotkey_list.h
@@ -178,6 +178,13 @@ public:
     void InstallOnPanel( wxPanel* aPanel );
 
     /**
+     * Method TransferDefaultsToControl
+     * Set hotkeys in the control to default values.
+     * @return true iff the operation was successful
+     */
+    bool TransferDefaultsToControl();
+
+    /**
      * Method TransferDataToControl
      * Load the hotkey data into the control. It is safe to call this multiple times,
      * for example to reset the control.
-- 
1.9.1


Follow ups