From c63fa6ff31f6582da1e5382f56a3c23d3fda0f65 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 27 Jan 2014 19:29:26 -0600 Subject: [PATCH] Add EDA_BASE_FRAME::Show() and call SaveSettings() only from there for all derived wxFrames. Remove calls to SaveSettings() elsewhere. --- 3d-viewer/3d_frame.cpp | 2 -- common/basicframe.cpp | 37 +++++++++++++++++++------- cvpcb/class_DisplayFootprintsFrame.cpp | 1 - cvpcb/cvframe.cpp | 1 - eeschema/libeditframe.cpp | 1 - eeschema/schframe.cpp | 1 - eeschema/viewlib_frame.cpp | 2 -- gerbview/gerbview_frame.cpp | 1 - include/wxstruct.h | 23 ++++++++++++---- kicad/mainframe.cpp | 2 -- pagelayout_editor/pl_editor_frame.cpp | 6 ++--- pcbnew/dialogs/dialog_design_rules.cpp | 7 +++-- pcbnew/footprint_wizard_frame.cpp | 2 -- pcbnew/github/github_plugin.cpp | 2 +- pcbnew/moduleframe.cpp | 1 - pcbnew/modview_frame.cpp | 10 ++++--- pcbnew/pcbframe.cpp | 3 +-- 17 files changed, 61 insertions(+), 41 deletions(-) diff --git a/3d-viewer/3d_frame.cpp b/3d-viewer/3d_frame.cpp index 41e75cccb5..e523d4118f 100644 --- a/3d-viewer/3d_frame.cpp +++ b/3d-viewer/3d_frame.cpp @@ -141,8 +141,6 @@ void EDA_3D_FRAME::Exit3DFrame( wxCommandEvent& event ) void EDA_3D_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - SaveSettings(); - if( Parent() ) Parent()->m_Draw3DFrame = NULL; diff --git a/common/basicframe.cpp b/common/basicframe.cpp index 882b3a1528..98238b78df 100644 --- a/common/basicframe.cpp +++ b/common/basicframe.cpp @@ -51,13 +51,13 @@ #define DEFAULT_AUTO_SAVE_INTERVAL 600 -const wxChar* traceAutoSave = wxT( "KicadAutoSave" ); +const wxChar traceAutoSave[] = wxT( "KicadAutoSave" ); /// Configuration file entry name for auto save interval. -static const wxChar* entryAutoSaveInterval = wxT( "AutoSaveInterval" ); +static const wxChar entryAutoSaveInterval[] = wxT( "AutoSaveInterval" ); /// Configuration file entry for wxAuiManger perspective. -static const wxChar* entryPerspective = wxT( "Perspective" ); +static const wxChar entryPerspective[] = wxT( "Perspective" ); @@ -141,6 +141,19 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent ) } +bool EDA_BASE_FRAME::Show( bool show ) +{ + if( !show ) // closing + { + SaveSettings(); // virtual, wxFrame specific + } + + int ret = wxFrame::Show( show ); + + return ret; +} + + void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent ) { if( !doAutoSave() ) @@ -231,7 +244,7 @@ void EDA_BASE_FRAME::SaveSettings() wxString text; wxConfig* config = wxGetApp().GetSettings(); - if( ( config == NULL ) || IsIconized() ) + if( !config || IsIconized() ) return; m_FrameSize = GetSize(); @@ -258,10 +271,15 @@ void EDA_BASE_FRAME::SaveSettings() config->Write( text, m_autoSaveInterval ); } - // Once this is fully implemented, wxAuiManager will be used to maintain the persistance of - // the main frame and all it's managed windows and all of the legacy frame persistence - // position code can be removed. - config->Write( m_FrameName + entryPerspective, m_auimgr.SavePerspective() ); + // Once this is fully implemented, wxAuiManager will be used to maintain + // the persistance of the main frame and all it's managed windows and + // all of the legacy frame persistence position code can be removed. + wxString perspective = m_auimgr.SavePerspective(); + + // printf( "perspective(%s): %s\n", + // TO_UTF8( m_FrameName + entryPerspective ), TO_UTF8( perspective ) ); + + config->Write( m_FrameName + entryPerspective, perspective ); } @@ -270,6 +288,7 @@ void EDA_BASE_FRAME::PrintMsg( const wxString& text ) SetStatusText( text ); } + void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, wxFileHistory * aFileHistory ) { @@ -283,7 +302,7 @@ void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type, - wxFileHistory * aFileHistory ) + wxFileHistory* aFileHistory ) { wxString fn, msg; size_t i; diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index 244712d5a9..4c0b4e266a 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -158,7 +158,6 @@ void DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow( wxCloseEvent& event ) if( m_Draw3DFrame ) m_Draw3DFrame->Close( true ); - SaveSettings(); Destroy(); } diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 1115b5f2c9..d984c8bb40 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -337,7 +337,6 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) m_DisplayFootprintFrame->Close( true ); m_modified = false; - SaveSettings(); Destroy(); return; } diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index fbbddde564..e0459b09f5 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -375,7 +375,6 @@ void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) } } - SaveSettings(); Destroy(); } diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index bc2d8d3125..72e43f4cc2 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -505,7 +505,6 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) /* all sub sheets are deleted, only the main sheet is usable */ m_CurrentSheet->Clear(); - SaveSettings(); Destroy(); } diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 4bb29af226..315c3987f0 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -250,8 +250,6 @@ LIB_VIEW_FRAME* LIB_VIEW_FRAME::GetActiveLibraryViewer() void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - SaveSettings(); - if( m_semaphore ) { m_semaphore->Post(); diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 0aaeef6917..62fdf0c130 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -177,7 +177,6 @@ GERBVIEW_FRAME::~GERBVIEW_FRAME() void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - SaveSettings(); Destroy(); } diff --git a/include/wxstruct.h b/include/wxstruct.h index 8684e94899..448cd4b344 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -101,7 +101,7 @@ enum ID_DRAWFRAME_TYPE /// Custom trace mask to enable and disable auto save tracing. -extern const wxChar* traceAutoSave; +extern const wxChar traceAutoSave[]; /** @@ -175,7 +175,18 @@ public: * @warning If you override this function in a derived class, make sure you call * down to this or the auto save feature will be disabled. */ - virtual bool ProcessEvent( wxEvent& aEvent ); + bool ProcessEvent( wxEvent& aEvent ); // overload wxFrame::ProcessEvent() + + /** + * Function Show + * hooks the wxFrame close scenario so we can grab the window size and position + * in the wxFrame specific SaveSettings() function. SaveSettings() is + * called for all derived wxFrames in this base class overload. Calling it + * from a destructor is deprecated since the wxFrame's position is not available + * in the destructor on linux. In other words, don't call SaveSettings() anywhere, + * except in this one function. + */ + bool Show( bool show ); // overload wxFrame::Show() void SetAutoSaveInterval( int aInterval ) { m_autoSaveInterval = aInterval; } @@ -216,11 +227,13 @@ public: virtual void LoadSettings(); /** - * Save common frame parameters from configuration. + * Save common frame parameters to configuration data file. * * The method is virtual so you can override it to save frame specific - * parameters. Don't forget to call the base method or your frames won't - * remember their positions and sizes. + * parameters. Don't forget to call the base class's SaveSettings() from + * your derived SaveSettings() otherwise the frames won't remember their + * positions and sizes. The virtual call to SaveSettings is done safely + * only in EDA_BASE_FRAME::Show( bool ). */ virtual void SaveSettings(); diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 4eb5863b7a..b0934d450a 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -164,8 +164,6 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event ) Event.SetCanVeto( true ); - SaveSettings(); - // Close the help frame if( wxGetApp().GetHtmlHelpController() ) { diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 2c0b99ca26..f1f378deee 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -194,6 +194,7 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event ) GetChars( filename ) ); int ii = DisplayExitDialog( this, msg ); + switch( ii ) { case wxID_CANCEL: @@ -228,12 +229,11 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event ) } } - SaveSettings(); - wxGetApp().SaveCurrentSetupValues( m_configSettings ); - // do not show the window because we do not want any paint event Show( false ); + wxGetApp().SaveCurrentSetupValues( m_configSettings ); + // On Linux, m_propertiesPagelayout must be destroyed // before deleting the main frame to avoid a crash when closing m_propertiesPagelayout->Destroy(); diff --git a/pcbnew/dialogs/dialog_design_rules.cpp b/pcbnew/dialogs/dialog_design_rules.cpp index eecd0956b3..e5325943fe 100644 --- a/pcbnew/dialogs/dialog_design_rules.cpp +++ b/pcbnew/dialogs/dialog_design_rules.cpp @@ -28,7 +28,7 @@ */ -/* functions relatives to the design rules editor +/* functions relative to the design rules editor */ #include #include @@ -46,10 +46,9 @@ #include #include - // Column labels for net lists -#define NET_TITLE _( "Net" ) -#define CLASS_TITLE _( "Class" ) +#define NET_TITLE _( "Net" ) +#define CLASS_TITLE _( "Class" ) // Field Positions on rules grid enum { diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 60db77a323..5eb4370ce6 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -304,8 +304,6 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME() */ void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - SaveSettings(); - if( m_Semaphore ) { m_Semaphore->Post(); diff --git a/pcbnew/github/github_plugin.cpp b/pcbnew/github/github_plugin.cpp index 2f675b4963..28e9efb6ea 100644 --- a/pcbnew/github/github_plugin.cpp +++ b/pcbnew/github/github_plugin.cpp @@ -29,7 +29,7 @@ While exploring the possibility of local caching of the zip file, I discovered this command to retrieve the time stamp of the last commit into any particular repo: - $time curl -I -i https://api.github.com/repos/KiCad/Mounting_Holes.pretty + $time curl -I -i https://api.github.com/repos/KiCad/Mounting_Holes.pretty/commits This gets just the header to what would otherwise return information on the repo in JSON format, and is reasonably faster than actually getting the repo diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 1c9da5ed87..02b2f52958 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -384,7 +384,6 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) } //close the editor - SaveSettings(); Destroy(); } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 7857580afe..b54e2b0de3 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -163,10 +163,13 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, // Ensure all layers and items are visible: GetBoard()->SetVisibleAlls(); SetScreen( new PCB_SCREEN( GetPageSizeIU() ) ); + GetScreen()->m_Center = true; // Center coordinate origins on screen. LoadSettings(); + SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); + GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); ReCreateHToolbar(); @@ -239,9 +242,12 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, m_auimgr.GetPane( m_mainToolBar ).BestSize( tbsize ); } - // Set min size (overwrite params read in LoadPerspective(), is any) +#if 0 // no. + + // Set min size (overwrite params read in LoadPerspective(), if any) m_auimgr.GetPane( m_libList ).MinSize( minsize ); m_auimgr.GetPane( m_footprintList ).MinSize( minsize ); +#endif // after changing something to the aui manager, // call Update()() to reflect the changes @@ -260,8 +266,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME() { - SaveSettings(); - if( m_Draw3DFrame ) m_Draw3DFrame->Destroy(); } diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 575dff6f27..62dab6ff16 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -708,8 +708,6 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) wxMessageBox( msg, wxGetApp().GetAppName(), wxOK | wxICON_ERROR, this ); } - SaveSettings(); - // Delete board structs and undo/redo lists, to avoid crash on exit // when deleting some structs (mainly in undo/redo lists) too late Clear_Pcb( false ); @@ -717,6 +715,7 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) // do not show the window because ScreenPcb will be deleted and we do not // want any paint event Show( false ); + Destroy(); }