Save Footprint chooser size and location.

(We're using a FRAME to mimic a dialog, so we need some of the
DIALOG_SHIM logic inside it.)

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15807
This commit is contained in:
Jeff Young 2023-11-03 10:34:00 +00:00
parent 50ff5e616f
commit 92ae0f4793
3 changed files with 63 additions and 1 deletions

View File

@ -113,7 +113,8 @@ public:
void OnModify();
/** Force the position of the dialog to a new position
/**
* Force the position of the dialog to a new position
* @param aNewPosition is the new forced position
*/
void SetPosition( const wxPoint& aNewPosition );

View File

@ -32,6 +32,7 @@
#include <settings/settings_manager.h>
#include <footprint_editor_settings.h>
#include <footprint_chooser_frame.h>
#include "wx/display.h"
static wxArrayString s_FootprintHistoryList;
@ -306,6 +307,57 @@ bool FOOTPRINT_CHOOSER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent
}
static wxRect s_dialogRect( 0, 0, 0, 0 );
void FOOTPRINT_CHOOSER_FRAME::SetPosition( const wxPoint& aNewPosition )
{
PCB_BASE_FRAME::SetPosition( aNewPosition );
s_dialogRect.SetPosition( aNewPosition );
}
bool FOOTPRINT_CHOOSER_FRAME::Show( bool show )
{
bool ret;
// Show or hide the window. If hiding, save current position and size.
// If showing, use previous position and size.
if( show )
{
#ifndef __WINDOWS__
PCB_BASE_FRAME::Raise(); // Needed on OS X and some other window managers (i.e. Unity)
#endif
ret = PCB_BASE_FRAME::Show( show );
// returns a zeroed-out default wxRect if none existed before.
wxRect savedDialogRect = s_dialogRect;
if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
{
SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
std::max( wxWindow::GetSize().x, savedDialogRect.GetSize().x ),
std::max( wxWindow::GetSize().y, savedDialogRect.GetSize().y ),
0 );
}
// Be sure that the dialog appears in a visible area
// (the dialog position might have been stored at the time when it was
// shown on another display)
if( wxDisplay::GetFromWindow( this ) == wxNOT_FOUND )
Centre();
}
else
{
s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
ret = PCB_BASE_FRAME::Show( show );
}
return ret;
}
void FOOTPRINT_CHOOSER_FRAME::OnPaint( wxPaintEvent& aEvent )
{
if( m_firstPaintEvent )

View File

@ -52,6 +52,15 @@ public:
void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
/**
* Force the position of the dialog to a new position. This mimics the DIALOG_SHIM
* implementation.
* @param aNewPosition is the new forced position
*/
void SetPosition( const wxPoint& aNewPosition );
bool Show( bool show ) override;
protected:
FOOTPRINT_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent );