← Back to team overview

kicad-developers team mailing list archive

[PATCH] Move PostCommandMenuEvent to EDA_BASE_FRAME

 

Hi,

This is a small patch to move PostCommandMenuEvent up to
EDA_BASE_FRAME, from PCB_BASE_EDIT_FRAME.

This function has nothing intristic to PCB edit frames, it would apply
to any frame. I'd like to use it for code that works in both Pcbnew
and Cvpcb, which have EDA_BASE_FRAME as the first suitable common
ancestor (KIWAY_PLAYER is first, but that's not really suitable for
menu event code).

I'm submitting this ahead of the code that uses it, because it's
logically separate and stands alone, and it touches common headers: if
the make_unique patch goes in alongside, this will avoid a
double-recompile for anyone pulling both at once!

Cheers,

John
From f8c76db985a90fbf5e209317e04011028b95e4de Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Tue, 17 Jan 2017 13:57:53 +0800
Subject: [PATCH] Move PostCommandMenuEvent to EDA_BASE_FRAME

There is nothing PCB-frame-specific about this function,
it is equally applicable to an frame, for example
PCB_EDIT_FRAME and CVPCB_MAINFRAME, which have EDA_BASE_FRAME
as the nearest common ancestor, except KIWAY_PLAYER,
which is not really concerned with this kind of UI event method.
---
 common/basicframe.cpp          | 15 +++++++++++++++
 include/wxstruct.h             |  9 +++++++++
 pcbnew/pcb_base_edit_frame.cpp | 15 ---------------
 pcbnew/pcb_base_edit_frame.h   |  2 --
 4 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/common/basicframe.cpp b/common/basicframe.cpp
index 45ad2f4d8..417bbc6ed 100644
--- a/common/basicframe.cpp
+++ b/common/basicframe.cpp
@@ -631,3 +631,18 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName,
         wxRemoveFile( autoSaveFileName.GetFullPath() );
     }
 }
+
+
+bool EDA_BASE_FRAME::PostCommandMenuEvent( int evt_type )
+{
+    if( evt_type != 0 )
+    {
+        wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
+        evt.SetEventObject( this );
+        evt.SetId( evt_type );
+        wxPostEvent( this, evt );
+        return true;
+    }
+
+    return false;
+}
diff --git a/include/wxstruct.h b/include/wxstruct.h
index 1292150b4..35d4af924 100644
--- a/include/wxstruct.h
+++ b/include/wxstruct.h
@@ -406,6 +406,15 @@ public:
      * redraws the menus and what not in current language.
      */
     virtual void ShowChangedLanguage();
+
+
+    /**
+     * Function PostCommandMenuEvent
+     *
+     * Post a menu event to the frame, which can be used to trigger actions
+     * bound to menu items.
+     */
+    bool PostCommandMenuEvent( int evt_type );
 };
 
 
diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp
index 3383c5388..2580985b9 100644
--- a/pcbnew/pcb_base_edit_frame.cpp
+++ b/pcbnew/pcb_base_edit_frame.cpp
@@ -39,21 +39,6 @@ void PCB_BASE_EDIT_FRAME::SetRotationAngle( int aRotationAngle )
 }
 
 
-bool PCB_BASE_EDIT_FRAME::PostCommandMenuEvent( int evt_type )
-{
-    if( evt_type != 0 )
-    {
-        wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
-        evt.SetEventObject( this );
-        evt.SetId( evt_type );
-        wxPostEvent( this, evt );
-        return true;
-    }
-
-    return false;
-}
-
-
 void PCB_BASE_EDIT_FRAME::UseGalCanvas( bool aEnable )
 {
     PCB_BASE_FRAME::UseGalCanvas( aEnable );
diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h
index db6f31066..ef68feebd 100644
--- a/pcbnew/pcb_base_edit_frame.h
+++ b/pcbnew/pcb_base_edit_frame.h
@@ -156,8 +156,6 @@ public:
      */
     void SetRotationAngle( int aRotationAngle );
 
-    bool PostCommandMenuEvent( int evt_type );
-
     ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
     void UseGalCanvas( bool aEnable ) override;
 
-- 
2.11.0


Follow ups