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 <board_commit.h>
#include <widgets/progress_reporter.h>
#include <wx/event.h>
#include <tool/tool_manager.h>
#include <bitmaps.h>
#include "pcb_actions.h"
@ -65,9 +66,7 @@ void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller )
BOARD_COMMIT commit( this );
ZONE_FILLER filler( frame()->GetBoard(), &commit );
filler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( aCaller,
_( "Checking Zones" ),
4 ) );
filler.InstallNewProgressReporter( aCaller, _( "Checking Zones" ), 4 );
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 )
{
std::vector<ZONE_CONTAINER*> toFill;
@ -87,9 +93,7 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
toFill.push_back(zone);
ZONE_FILLER filler( board(), &commit );
filler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( aCaller,
_( "Fill All Zones" ),
4 ) );
filler.InstallNewProgressReporter( aCaller, _( "Fill All Zones" ), 4 );
if( filler.Fill( toFill ) )
getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty = false;
@ -97,11 +101,8 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
canvas()->Refresh();
// 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
// (which will bring it back inside the window if it was outside). While sometimes mildly
// annoying, it does fix the more-often annoying loss of keybard focus.
VECTOR2D cursor = getViewControls()->GetRawCursorPosition( false );
getViewControls()->SetCursorPosition( cursor, true, true );
// here doesn't work, so we delay it to an idle event.
canvas()->Bind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
}
@ -126,9 +127,7 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent )
}
ZONE_FILLER filler( board(), &commit );
filler.SetProgressReporter( std::make_unique<WX_PROGRESS_REPORTER>( frame(),
_( "Fill Zone" ),
4 ) );
filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 );
filler.Fill( toFill );
canvas()->Refresh();

View File

@ -53,6 +53,9 @@ public:
int ZoneUnfillAll( const TOOL_EVENT& aEvent );
private:
///> Refocuses on an idle event (used after the Progress Reporter messes up the focus)
void singleShotRefocus( wxIdleEvent& );
///> Sets up handlers for various events.
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;
}
void ZONE_FILLER::SetProgressReporter( std::unique_ptr<WX_PROGRESS_REPORTER>&& aReporter )
{
m_uniqueReporter = std::move( aReporter );
m_uniqueReporter = std::make_unique<WX_PROGRESS_REPORTER>( aParent, aTitle, aNumPhases );
m_progressReporter = m_uniqueReporter.get();
}

View File

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

View File

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