Unify text edit dialog behavior
This makes the pcbnew multiline text editor natively accept tabs in the same manner as eeschema and extracts key handling routines to the shim to allow undo/redo. Also allows Ctrl-Y under Linux in addition to other platforms. While not as popular as Ctrl-Shift-Z, it is utilized for Redo in some contexts
This commit is contained in:
parent
3bd38ec245
commit
90b5cd3032
|
@ -236,27 +236,15 @@ bool DIALOG_LABEL_EDITOR::TransferDataToWindow()
|
|||
/*!
|
||||
* wxEVT_COMMAND_ENTER event handler for single-line control
|
||||
*/
|
||||
|
||||
void DIALOG_LABEL_EDITOR::OnEnterKey( wxCommandEvent& aEvent )
|
||||
{
|
||||
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
|
||||
}
|
||||
|
||||
|
||||
static bool isCtrl( int aChar, const wxKeyEvent& e )
|
||||
{
|
||||
return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown();
|
||||
}
|
||||
|
||||
static bool isShiftCtrl( int aChar, const wxKeyEvent& e )
|
||||
{
|
||||
return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && e.ShiftDown() && !e.MetaDown();
|
||||
}
|
||||
|
||||
/*!
|
||||
* wxEVT_CHAR_HOOK event handler for multi-line control
|
||||
*/
|
||||
|
||||
void DIALOG_LABEL_EDITOR::OnCharHook( wxKeyEvent& aEvt )
|
||||
{
|
||||
if( aEvt.GetKeyCode() == WXK_TAB )
|
||||
|
@ -275,27 +263,23 @@ void DIALOG_LABEL_EDITOR::OnCharHook( wxKeyEvent& aEvt )
|
|||
m_valueMultiLine->Tab();
|
||||
}
|
||||
}
|
||||
else if( m_valueMultiLine->IsShown() && isCtrl( 'Z', aEvt ) )
|
||||
else if( m_valueMultiLine->IsShown() && IsCtrl( 'Z', aEvt ) )
|
||||
{
|
||||
m_valueMultiLine->Undo();
|
||||
}
|
||||
#if defined( __WXMAC__ )
|
||||
else if( m_valueMultiLine->IsShown() && isShiftCtrl( 'Z', aEvt ) )
|
||||
#else
|
||||
else if( m_valueMultiLine->IsShown() && isCtrl( 'Y', aEvt ) )
|
||||
#endif
|
||||
else if( m_valueMultiLine->IsShown() && ( IsShiftCtrl( 'Z', aEvt ) || IsCtrl( 'Y', aEvt ) ) )
|
||||
{
|
||||
m_valueMultiLine->Redo();
|
||||
}
|
||||
else if( isCtrl( 'X', aEvt ) )
|
||||
else if( IsCtrl( 'X', aEvt ) )
|
||||
{
|
||||
m_valueMultiLine->Cut();
|
||||
}
|
||||
else if( isCtrl( 'C', aEvt ) )
|
||||
else if( IsCtrl( 'C', aEvt ) )
|
||||
{
|
||||
m_valueMultiLine->Copy();
|
||||
}
|
||||
else if( isCtrl( 'V', aEvt ) )
|
||||
else if( IsCtrl( 'V', aEvt ) )
|
||||
{
|
||||
m_valueMultiLine->Paste();
|
||||
}
|
||||
|
|
|
@ -134,6 +134,16 @@ public:
|
|||
|
||||
EDA_UNITS_T GetUserUnits() const { return m_units; }
|
||||
|
||||
static bool IsCtrl( int aChar, const wxKeyEvent& e )
|
||||
{
|
||||
return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown();
|
||||
}
|
||||
|
||||
static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
|
||||
{
|
||||
return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && e.ShiftDown() && !e.MetaDown();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
|
|
@ -205,15 +205,39 @@ void DIALOG_TEXT_PROPERTIES::OnCharHook( wxKeyEvent& aEvent )
|
|||
{
|
||||
if( aEvent.GetKeyCode() == WXK_TAB )
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
if( !aEvent.ShiftDown() )
|
||||
flags |= wxNavigationKeyEvent::IsForward;
|
||||
|
||||
if( aEvent.ControlDown() )
|
||||
flags |= wxNavigationKeyEvent::WinChange;
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
NavigateIn( flags );
|
||||
if( !aEvent.ShiftDown() )
|
||||
flags |= wxNavigationKeyEvent::IsForward;
|
||||
|
||||
NavigateIn( flags );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MultiLineText->Tab();
|
||||
}
|
||||
}
|
||||
else if( m_MultiLineText->IsShown() && IsCtrl( 'Z', aEvent ) )
|
||||
{
|
||||
m_MultiLineText->Undo();
|
||||
}
|
||||
else if( m_MultiLineText->IsShown() && ( IsShiftCtrl( 'Z', aEvent ) || IsCtrl( 'Y', aEvent ) ) )
|
||||
{
|
||||
m_MultiLineText->Redo();
|
||||
}
|
||||
else if( IsCtrl( 'X', aEvent ) )
|
||||
{
|
||||
m_MultiLineText->Cut();
|
||||
}
|
||||
else if( IsCtrl( 'C', aEvent ) )
|
||||
{
|
||||
m_MultiLineText->Copy();
|
||||
}
|
||||
else if( IsCtrl( 'V', aEvent ) )
|
||||
{
|
||||
m_MultiLineText->Paste();
|
||||
}
|
||||
else if( aEvent.GetKeyCode() == WXK_RETURN )
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version Oct 26 2018)
|
||||
// C++ code generated with wxFormBuilder (version Apr 23 2019)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
|
@ -25,11 +25,39 @@ DIALOG_TEXT_PROPERTIES_BASE::DIALOG_TEXT_PROPERTIES_BASE( wxWindow* parent, wxWi
|
|||
textLabel->Wrap( -1 );
|
||||
m_MultiLineSizer->Add( textLabel, 0, wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
m_MultiLineText = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
|
||||
m_MultiLineText = new wxStyledTextCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
|
||||
m_MultiLineText->SetUseTabs( true );
|
||||
m_MultiLineText->SetTabWidth( 4 );
|
||||
m_MultiLineText->SetIndent( 4 );
|
||||
m_MultiLineText->SetTabIndents( false );
|
||||
m_MultiLineText->SetBackSpaceUnIndents( false );
|
||||
m_MultiLineText->SetViewEOL( false );
|
||||
m_MultiLineText->SetViewWhiteSpace( false );
|
||||
m_MultiLineText->SetMarginWidth( 2, 0 );
|
||||
m_MultiLineText->SetIndentationGuides( true );
|
||||
m_MultiLineText->SetMarginWidth( 1, 0 );
|
||||
m_MultiLineText->SetMarginWidth( 0, 0 );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS );
|
||||
m_MultiLineText->MarkerSetBackground( wxSTC_MARKNUM_FOLDER, wxColour( wxT("BLACK") ) );
|
||||
m_MultiLineText->MarkerSetForeground( wxSTC_MARKNUM_FOLDER, wxColour( wxT("WHITE") ) );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS );
|
||||
m_MultiLineText->MarkerSetBackground( wxSTC_MARKNUM_FOLDEROPEN, wxColour( wxT("BLACK") ) );
|
||||
m_MultiLineText->MarkerSetForeground( wxSTC_MARKNUM_FOLDEROPEN, wxColour( wxT("WHITE") ) );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUS );
|
||||
m_MultiLineText->MarkerSetBackground( wxSTC_MARKNUM_FOLDEREND, wxColour( wxT("BLACK") ) );
|
||||
m_MultiLineText->MarkerSetForeground( wxSTC_MARKNUM_FOLDEREND, wxColour( wxT("WHITE") ) );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUS );
|
||||
m_MultiLineText->MarkerSetBackground( wxSTC_MARKNUM_FOLDEROPENMID, wxColour( wxT("BLACK") ) );
|
||||
m_MultiLineText->MarkerSetForeground( wxSTC_MARKNUM_FOLDEROPENMID, wxColour( wxT("WHITE") ) );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY );
|
||||
m_MultiLineText->MarkerDefine( wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY );
|
||||
m_MultiLineText->SetSelBackground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
|
||||
m_MultiLineText->SetSelForeground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
|
||||
m_MultiLineText->SetToolTip( _("Enter the text placed on selected layer.") );
|
||||
m_MultiLineText->SetMinSize( wxSize( 400,60 ) );
|
||||
|
||||
m_MultiLineSizer->Add( m_MultiLineText, 1, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
|
||||
m_MultiLineSizer->Add( m_MultiLineText, 1, wxEXPAND | wxALL, 5 );
|
||||
|
||||
|
||||
bMainSizer->Add( m_MultiLineSizer, 20, wxEXPAND|wxALL, 10 );
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<property name="file">dialog_text_properties_base</property>
|
||||
<property name="first_id">1000</property>
|
||||
<property name="help_provider">none</property>
|
||||
<property name="image_path_wrapper_function_name"></property>
|
||||
<property name="indent_with_spaces"></property>
|
||||
<property name="internationalize">1</property>
|
||||
<property name="name">DIALOG_TEXT_PROPERTIES_BASE</property>
|
||||
|
@ -25,6 +26,7 @@
|
|||
<property name="skip_php_events">1</property>
|
||||
<property name="skip_python_events">1</property>
|
||||
<property name="ui_table">UI</property>
|
||||
<property name="use_array_enum">0</property>
|
||||
<property name="use_enum">0</property>
|
||||
<property name="use_microsoft_bom">0</property>
|
||||
<object class="Dialog" expanded="1">
|
||||
|
@ -129,11 +131,11 @@
|
|||
<property name="wrap">-1</property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
<object class="sizeritem" expanded="1">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</property>
|
||||
<property name="flag">wxEXPAND | wxALL</property>
|
||||
<property name="proportion">1</property>
|
||||
<object class="wxTextCtrl" expanded="0">
|
||||
<object class="wxStyledTextCtrl" expanded="1">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
<property name="RightDockable">1</property>
|
||||
|
@ -142,6 +144,7 @@
|
|||
<property name="aui_name"></property>
|
||||
<property name="aui_position"></property>
|
||||
<property name="aui_row"></property>
|
||||
<property name="backspace_unindents">0</property>
|
||||
<property name="best_size"></property>
|
||||
<property name="bg"></property>
|
||||
<property name="caption"></property>
|
||||
|
@ -157,14 +160,16 @@
|
|||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="folding">0</property>
|
||||
<property name="font"></property>
|
||||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="indentation_guides">1</property>
|
||||
<property name="line_numbers">0</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="maxlength">0</property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size">400,60</property>
|
||||
|
@ -179,15 +184,14 @@
|
|||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style">wxTE_MULTILINE</property>
|
||||
<property name="subclass"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="tab_indents">0</property>
|
||||
<property name="tab_width">4</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip">Enter the text placed on selected layer.</property>
|
||||
<property name="validator_data_type"></property>
|
||||
<property name="validator_style">wxFILTER_NONE</property>
|
||||
<property name="validator_type">wxDefaultValidator</property>
|
||||
<property name="validator_variable"></property>
|
||||
<property name="value"></property>
|
||||
<property name="use_tabs">1</property>
|
||||
<property name="view_eol">0</property>
|
||||
<property name="view_whitespace">0</property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version Oct 26 2018)
|
||||
// C++ code generated with wxFormBuilder (version Apr 23 2019)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
|
@ -19,8 +19,9 @@ class PCB_LAYER_BOX_SELECTOR;
|
|||
#include <wx/font.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/stc/stc.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/choice.h>
|
||||
#include <wx/bmpcbox.h>
|
||||
#include <wx/checkbox.h>
|
||||
|
@ -41,7 +42,7 @@ class DIALOG_TEXT_PROPERTIES_BASE : public DIALOG_SHIM
|
|||
|
||||
protected:
|
||||
wxBoxSizer* m_MultiLineSizer;
|
||||
wxTextCtrl* m_MultiLineText;
|
||||
wxStyledTextCtrl* m_MultiLineText;
|
||||
wxBoxSizer* m_SingleLineSizer;
|
||||
wxStaticText* m_TextLabel;
|
||||
wxTextCtrl* m_SingleLineText;
|
||||
|
|
Loading…
Reference in New Issue