Performance improvements for multi-page dialogs.

This commit is contained in:
Jeff Young 2024-03-10 10:46:26 +00:00
parent 821063e5b1
commit a12d79cd13
13 changed files with 54 additions and 43 deletions

View File

@ -35,8 +35,8 @@
SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces,
bool aSingleLine,
std::function<void( wxKeyEvent& )> onAcceptHandler,
std::function<void( wxStyledTextEvent& )> onCharAddedHandler ) :
std::function<void( wxKeyEvent& )> onAcceptFn,
std::function<void( wxStyledTextEvent& )> onCharAddedFn ) :
m_te( aScintilla ),
m_braces( aBraces ),
m_lastCaretPos( -1 ),
@ -44,8 +44,8 @@ SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString
m_lastSelEnd( -1 ),
m_suppressAutocomplete( false ),
m_singleLine( aSingleLine ),
m_onAcceptHandler( onAcceptHandler ),
m_onCharAddedHandler( onCharAddedHandler )
m_onAcceptFn( std::move( onAcceptFn ) ),
m_onCharAddedFn( std::move( onCharAddedFn ) )
{
// Always use LF as eol char, regardless the platform
m_te->SetEOLMode( wxSTC_EOL_LF );
@ -174,7 +174,7 @@ bool isCtrlSlash( wxKeyEvent& aEvent )
void SCINTILLA_TRICKS::onChar( wxStyledTextEvent& aEvent )
{
m_onCharAddedHandler( aEvent );
m_onCharAddedFn( aEvent );
}
@ -237,7 +237,7 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
wxStyledTextEvent event;
event.SetKey( ' ' );
event.SetModifiers( wxMOD_CONTROL );
m_onCharAddedHandler( event );
m_onCharAddedFn( event );
return;
}
@ -248,7 +248,7 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
&& ( m_singleLine || aEvent.ShiftDown() ) )
{
m_onAcceptHandler( aEvent );
m_onAcceptFn( aEvent );
}
else if( ConvertSmartQuotesAndDashes( &c ) )
{
@ -542,8 +542,8 @@ void SCINTILLA_TRICKS::onScintillaUpdateUI( wxStyledTextEvent& aEvent )
}
void SCINTILLA_TRICKS::DoTextVarAutocomplete( std::function<void( const wxString& crossRef,
wxArrayString* tokens )> aTokenProvider )
void SCINTILLA_TRICKS::DoTextVarAutocomplete(
const std::function<void( const wxString& xRef, wxArrayString* tokens )>& getTokensFn )
{
wxArrayString autocompleteTokens;
int text_pos = m_te->GetCurrentPos();
@ -564,13 +564,13 @@ void SCINTILLA_TRICKS::DoTextVarAutocomplete( std::function<void( const wxString
if( textVarRef( refStart ) )
{
partial = m_te->GetRange( start, text_pos );
aTokenProvider( m_te->GetRange( refStart, start-1 ), &autocompleteTokens );
getTokensFn( m_te->GetRange( refStart, start-1 ), &autocompleteTokens );
}
}
else if( textVarRef( start ) )
{
partial = m_te->GetTextRange( start, text_pos );
aTokenProvider( wxEmptyString, &autocompleteTokens );
getTokensFn( wxEmptyString, &autocompleteTokens );
}
DoAutocomplete( partial, autocompleteTokens );

View File

@ -60,12 +60,12 @@ wxSize GRID_CELL_ESCAPED_TEXT_RENDERER::GetBestSize( wxGrid & aGrid, wxGridCellA
//-------- GRID_CELL_STC_EDITOR -----------------------------------------------------------------
//
GRID_CELL_STC_EDITOR::GRID_CELL_STC_EDITOR( bool aIgnoreCase,
std::function<void( wxStyledTextEvent&,
SCINTILLA_TRICKS* )> aOnChar ) :
GRID_CELL_STC_EDITOR::GRID_CELL_STC_EDITOR(
bool aIgnoreCase,
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn ) :
m_scintillaTricks( nullptr ),
m_ignoreCase( aIgnoreCase ),
m_onChar( aOnChar )
m_onCharFn( std::move( onCharFn ) )
{ }
@ -92,15 +92,15 @@ void GRID_CELL_STC_EDITOR::Create( wxWindow* aParent, wxWindowID aId, wxEvtHandl
m_scintillaTricks = new SCINTILLA_TRICKS(
stc_ctrl(), wxEmptyString, true,
// onAccept handler
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
HandleReturn( aEvent );
},
// onCharAdded handler
// onCharFn
[this]( wxStyledTextEvent& aEvent )
{
m_onChar( aEvent, m_scintillaTricks );
m_onCharFn( aEvent, m_scintillaTricks );
} );
stc_ctrl()->Bind( wxEVT_KILL_FOCUS, &GRID_CELL_STC_EDITOR::onFocusLoss, this );

View File

@ -71,6 +71,7 @@ DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const
m_fieldId = VALUE_FIELD;
m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ), true,
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );

View File

@ -45,6 +45,7 @@ DIALOG_LIB_TEXT_PROPERTIES::DIALOG_LIB_TEXT_PROPERTIES( SYMBOL_EDIT_FRAME* aPare
COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ), false,
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );

View File

@ -72,6 +72,7 @@ DIALOG_LIB_TEXTBOX_PROPERTIES::DIALOG_LIB_TEXTBOX_PROPERTIES( SYMBOL_EDIT_FRAME*
#endif
m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrl, wxT( "{}" ), false,
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );

View File

@ -80,12 +80,14 @@ DIALOG_TABLE_PROPERTIES::DIALOG_TABLE_PROPERTIES( SCH_EDIT_FRAME* aFrame, SCH_TA
else
{
attr->SetEditor( new GRID_CELL_STC_EDITOR( true,
// onCharFn
[this]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
{
aScintillaTricks->DoTextVarAutocomplete(
[this]( const wxString& crossRef, wxArrayString* tokens )
// getTokensFn
[this]( const wxString& xRef, wxArrayString* tokens )
{
getContextualTextVars( crossRef, tokens );
getContextualTextVars( xRef, tokens );
} );
} ) );
}

View File

@ -94,19 +94,20 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_ITE
#endif
m_scintillaTricks = new SCINTILLA_TRICKS( m_textCtrl, wxT( "{}" ), false,
// onAccept handler
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
},
// onCharAdded handler
// onCharFn
[this]( wxStyledTextEvent& aEvent )
{
m_scintillaTricks->DoTextVarAutocomplete(
[this]( const wxString& crossRef, wxArrayString* tokens )
// getTokensFn
[this]( const wxString& xRef, wxArrayString* tokens )
{
getContextualTextVars( crossRef, tokens );
getContextualTextVars( xRef, tokens );
} );
} );

View File

@ -46,8 +46,8 @@ public:
wxStyledTextCtrl* Scintilla() const { return m_te; }
void DoTextVarAutocomplete( std::function<void( const wxString& crossRef,
wxArrayString* tokens )> aTokenProvider );
void DoTextVarAutocomplete(
const std::function<void( const wxString& xRef, wxArrayString* tokens )>& getTokensFn );
void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
@ -75,8 +75,8 @@ protected:
// stop handling (including monospaced font).
// Process <return> in singleLine, and <shift> + <return> irrespective.
std::function<void( wxKeyEvent& aEvent )> m_onAcceptHandler;
std::function<void( wxStyledTextEvent& aEvent )> m_onCharAddedHandler;
std::function<void( wxKeyEvent& aEvent )> m_onAcceptFn;
std::function<void( wxStyledTextEvent& aEvent )> m_onCharAddedFn;
};
#endif // SCINTILLA_TRICKS_H

View File

@ -49,13 +49,13 @@ class GRID_CELL_STC_EDITOR : public wxGridCellEditor
{
public:
GRID_CELL_STC_EDITOR( bool aIgnoreCase,
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> aOnChar );
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn );
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_STC_EDITOR( m_ignoreCase, m_onChar );
return new GRID_CELL_STC_EDITOR( m_ignoreCase, m_onCharFn );
}
wxString GetValue() const override;
@ -76,7 +76,7 @@ protected:
bool m_ignoreCase;
wxString m_value;
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> m_onChar;
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> m_onCharFn;
};

View File

@ -89,9 +89,10 @@ DIALOG_TABLE_PROPERTIES::DIALOG_TABLE_PROPERTIES( PCB_BASE_EDIT_FRAME* aFrame, P
[this, cell]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
{
aScintillaTricks->DoTextVarAutocomplete(
[this, cell]( const wxString& crossRef, wxArrayString* tokens )
// getTokensFn
[this, cell]( const wxString& xRef, wxArrayString* tokens )
{
m_frame->GetContextualTextVars( cell, crossRef, tokens );
m_frame->GetContextualTextVars( cell, xRef, tokens );
} );
} ) );
}

View File

@ -72,18 +72,19 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, PC
#endif
m_scintillaTricks = new SCINTILLA_TRICKS( m_MultiLineText, wxT( "{}" ), false,
// onAccept handler
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
},
// onCharAdded handler
// onCharFn
[this]( wxStyledTextEvent& aEvent )
{
m_scintillaTricks->DoTextVarAutocomplete(
[this]( const wxString& crossRef, wxArrayString* tokens )
// getTokensFn
[this]( const wxString& xRef, wxArrayString* tokens )
{
m_frame->GetContextualTextVars( m_item, crossRef, tokens );
m_frame->GetContextualTextVars( m_item, xRef, tokens );
} );
} );

View File

@ -56,18 +56,19 @@ DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES( PCB_BASE_EDIT_FRAME* aPare
#endif
m_scintillaTricks = new SCINTILLA_TRICKS( m_MultiLineText, wxT( "{}" ), false,
// onAccept handler
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
},
// onCharAdded handler
// onCharFn
[this]( wxStyledTextEvent& aEvent )
{
m_scintillaTricks->DoTextVarAutocomplete(
[this]( const wxString& crossRef, wxArrayString* tokens )
// getTokensFn
[this]( const wxString& xRef, wxArrayString* tokens )
{
m_frame->GetContextualTextVars( m_textBox, crossRef, tokens );
m_frame->GetContextualTextVars( m_textBox, xRef, tokens );
} );
} );

View File

@ -48,11 +48,13 @@ PANEL_SETUP_RULES::PANEL_SETUP_RULES( wxWindow* aParentWindow, PCB_EDIT_FRAME* a
m_helpWindow( nullptr )
{
m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ), false,
// onAcceptFn
[this]( wxKeyEvent& aEvent )
{
wxPostEvent( PAGED_DIALOG::GetDialog( this ),
wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
},
// onCharFn
[this]( wxStyledTextEvent& aEvent )
{
onScintillaCharAdded( aEvent );