kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #15999
[PATCH/RFC] Transfer user settings to child frames
Attached is a patch to import settings from a parent frame to child
frames. This is in response to a bug reported in IRC that the
warp-on-zoom behaviour in pcbnew was not being transferred to modedit.
This patch provides a generic way of importing settings from a wxWindow
parent in impure virtual EDA_BASE_FRAME::ImportFrameSettings() method.
EDA_BASE_FRAME derivatives can then override this to import settings
that they know about from the parent frame.
This also fixes the issue in other EDA_DRAW_FRAME children, such as the
module browser in pcbnew and the symbol browser in eeschema.
I have added an overridden method like this for EDA_DRAW_FRAME, which
transfers the settings GetEnableZoomNoCenter, GetMiddleButtonPanLimited,
GetEnableAutoPan and GetEnableMiddleButtonPan.
This method is then called from KIWAY::Player(), on creation. However, I
am not sure when best to send settings changes when the child frame
exists already - should this be push out to child frames whenever
settings are changed, in order to maintain consistency between a parent
and the children? At the moment, you have to close the child and re-open
to get the changes. Adding the call to ImportFrameSettings() in the
Player() function also for no-create calls won't help if the user
Alt-Tabs to the other window rather than requesting it via KiWay.
Incidentally, I changed EDA_DRAW_PANEL::GetCanvas() to be a const
method, because as a getter method, it should not be able to change the
object.
Cheers,
John
diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp
index e5d1c1b..0bc94b0 100644
--- a/common/draw_frame.cpp
+++ b/common/draw_frame.cpp
@@ -1246,3 +1246,19 @@ void EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
}
}
+
+void EDA_DRAW_FRAME::ImportFrameSettings( const wxWindow& aSrc )
+{
+ // import drawing settings from a EDA_DRAW_FRAME source
+ if ( const EDA_DRAW_FRAME* srcFrame = dynamic_cast<const EDA_DRAW_FRAME*>( &aSrc ) )
+ {
+ const EDA_DRAW_PANEL* srcCanvas = srcFrame->GetCanvas();
+ EDA_DRAW_PANEL* canvas = GetCanvas();
+
+ // transfer settings to the child frame
+ canvas->SetEnableZoomNoCenter( srcCanvas->GetEnableZoomNoCenter() );
+ canvas->SetMiddleButtonPanLimited( srcCanvas->GetMiddleButtonPanLimited() );
+ canvas->SetEnableAutoPan( srcCanvas->GetEnableAutoPan() );
+ canvas->SetEnableMiddleButtonPan( srcCanvas->GetEnableMiddleButtonPan() );
+ }
+}
diff --git a/common/kiway.cpp b/common/kiway.cpp
index 2e3de4f..14fb199 100644
--- a/common/kiway.cpp
+++ b/common/kiway.cpp
@@ -298,6 +298,9 @@ KIWAY_PLAYER* KIWAY::Player( FRAME_T aFrameType, bool doCreate )
);
wxASSERT( frame );
+ // import any relevant settings from the parent
+ frame->ImportFrameSettings( *m_top );
+
return m_player[aFrameType] = frame;
}
}
diff --git a/include/draw_frame.h b/include/draw_frame.h
index e58fced..d547c14 100644
--- a/include/draw_frame.h
+++ b/include/draw_frame.h
@@ -279,7 +279,7 @@ public:
bool ShowPageLimits() const { return m_showPageLimits; }
void SetShowPageLimits( bool aShow ) { m_showPageLimits = aShow; }
- EDA_DRAW_PANEL* GetCanvas() { return m_canvas; }
+ EDA_DRAW_PANEL* GetCanvas() const { return m_canvas; }
virtual wxString GetScreenDesc() const;
@@ -629,6 +629,11 @@ public:
void SaveSettings( wxConfigBase* aCfg ); // override virtual
/**
+ * Transfer draw panel window user settings from a parent to a child
+ */
+ void ImportFrameSettings( const wxWindow& aSrc ); // override virtual
+
+ /**
* Append a message to the message panel.
*
* This helper method checks to make sure the message panel exists in
diff --git a/include/wxstruct.h b/include/wxstruct.h
index 4b0c56a..4f7b310 100644
--- a/include/wxstruct.h
+++ b/include/wxstruct.h
@@ -252,6 +252,16 @@ public:
virtual void SaveProjectSettings( bool aAskForSave ) {};
/**
+ * Function ImportFrameSettings
+ * Copy relevant settings from another frame
+ *
+ * Override this to call the relevant getter/setters for your particular
+ * frame type.
+ * @param aSrc the frame to copy settings from
+ */
+ virtual void ImportFrameSettings( const wxWindow& aSrc ) {}
+
+ /**
* Function OnSelectPreferredEditor
* Open a dialog to select the editor that will used in KiCad
* to edit or display files (reports ... )
Follow ups