A better hack for the post-ProgressReporter-loss-of-focus issue.

This commit is contained in:
Jeff Young 2019-07-14 12:06:30 +01:00
parent 5091f08f71
commit fe188489c7
5 changed files with 22 additions and 30 deletions

View File

@ -28,6 +28,7 @@
#include <connectivity/connectivity_data.h> #include <connectivity/connectivity_data.h>
#include <board_commit.h> #include <board_commit.h>
#include <widgets/progress_reporter.h> #include <widgets/progress_reporter.h>
#include <wx/event.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <bitmaps.h> #include <bitmaps.h>
#include "pcb_actions.h" #include "pcb_actions.h"
@ -65,9 +66,7 @@ void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller )
BOARD_COMMIT commit( this ); BOARD_COMMIT commit( this );
ZONE_FILLER filler( frame()->GetBoard(), &commit ); ZONE_FILLER filler( frame()->GetBoard(), &commit );
filler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( aCaller, filler.InstallNewProgressReporter( aCaller, _( "Checking Zones" ), 4 );
_( "Checking Zones" ),
4 ) );
if( filler.Fill( toFill, true ) ) if( filler.Fill( toFill, true ) )
{ {
@ -77,6 +76,13 @@ void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller )
} }
void ZONE_FILLER_TOOL::singleShotRefocus( wxIdleEvent& )
{
canvas()->SetFocus();
canvas()->Unbind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
}
void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller ) void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
{ {
std::vector<ZONE_CONTAINER*> toFill; std::vector<ZONE_CONTAINER*> toFill;
@ -87,9 +93,7 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
toFill.push_back(zone); toFill.push_back(zone);
ZONE_FILLER filler( board(), &commit ); ZONE_FILLER filler( board(), &commit );
filler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( aCaller, filler.InstallNewProgressReporter( aCaller, _( "Fill All Zones" ), 4 );
_( "Fill All Zones" ),
4 ) );
if( filler.Fill( toFill ) ) if( filler.Fill( toFill ) )
getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty = false; getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty = false;
@ -97,11 +101,8 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
canvas()->Refresh(); canvas()->Refresh();
// wxWidgets has keyboard focus issues after the progress reporter. Re-setting the focus // wxWidgets has keyboard focus issues after the progress reporter. Re-setting the focus
// does not fix them; moving the mouse does. Here we warp the mouse to its existing location // here doesn't work, so we delay it to an idle event.
// (which will bring it back inside the window if it was outside). While sometimes mildly canvas()->Bind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
// annoying, it does fix the more-often annoying loss of keybard focus.
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( false );
getViewControls()->SetCursorPosition( cursor, true, true );
} }
@ -126,9 +127,7 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent )
} }
ZONE_FILLER filler( board(), &commit ); ZONE_FILLER filler( board(), &commit );
filler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( frame(), filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 );
_( "Fill Zone" ),
4 ) );
filler.Fill( toFill ); filler.Fill( toFill );
canvas()->Refresh(); canvas()->Refresh();

View File

@ -53,6 +53,9 @@ public:
int ZoneUnfillAll( const TOOL_EVENT& aEvent ); int ZoneUnfillAll( const TOOL_EVENT& aEvent );
private: private:
///> Refocuses on an idle event (used after the Progress Reporter messes up the focus)
void singleShotRefocus( wxIdleEvent& );
///> Sets up handlers for various events. ///> Sets up handlers for various events.
void setTransitions() override; void setTransitions() override;
}; };

View File

@ -91,15 +91,10 @@ ZONE_FILLER::~ZONE_FILLER()
} }
void ZONE_FILLER::SetProgressReporter( WX_PROGRESS_REPORTER* aReporter ) void ZONE_FILLER::InstallNewProgressReporter( wxWindow* aParent, const wxString& aTitle,
int aNumPhases )
{ {
m_progressReporter = aReporter; m_uniqueReporter = std::make_unique<WX_PROGRESS_REPORTER>( aParent, aTitle, aNumPhases );
}
void ZONE_FILLER::SetProgressReporter( std::unique_ptr<WX_PROGRESS_REPORTER>&& aReporter )
{
m_uniqueReporter = std::move( aReporter );
m_progressReporter = m_uniqueReporter.get(); m_progressReporter = m_uniqueReporter.get();
} }

View File

@ -42,8 +42,7 @@ public:
ZONE_FILLER( BOARD* aBoard, COMMIT* aCommit = nullptr ); ZONE_FILLER( BOARD* aBoard, COMMIT* aCommit = nullptr );
~ZONE_FILLER(); ~ZONE_FILLER();
void SetProgressReporter( WX_PROGRESS_REPORTER* aReporter ); void InstallNewProgressReporter( wxWindow* aParent, const wxString& aTitle, int aNumPhases );
void SetProgressReporter( std::unique_ptr<WX_PROGRESS_REPORTER>&& aReporter );
bool Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck = false ); bool Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck = false );
private: private:

View File

@ -137,12 +137,8 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE_CONTAINER* aZone )
if( zones_to_refill.size() ) if( zones_to_refill.size() )
{ {
ZONE_FILLER filler ( GetBoard() ); ZONE_FILLER filler ( GetBoard() );
wxString title; wxString title = wxString::Format( _( "Refill %d Zones" ), (int) zones_to_refill.size() );
title.Printf( _( "Refill %d Zones" ), (int)zones_to_refill.size() ); filler.InstallNewProgressReporter( this, title, 4 );
std::unique_ptr<WX_PROGRESS_REPORTER> progressReporter(
new WX_PROGRESS_REPORTER( this, title, 4 ) );
filler.SetProgressReporter( progressReporter.get() );
filler.Fill( zones_to_refill ); filler.Fill( zones_to_refill );
} }