Add existing label popup to properties dialog.

Fixes: lp:1639719
* https://bugs.launchpad.net/kicad/+bug/1639719

Fixes: lp:1778330
* https://bugs.launchpad.net/kicad/+bug/1778330

(cherry picked from commit 14ebff6)
This commit is contained in:
Jeff Young 2018-06-27 14:21:26 +01:00
parent da69a7cd9c
commit f72842405a
4 changed files with 184 additions and 62 deletions

View File

@ -56,12 +56,9 @@ public:
void SetTitle( const wxString& aTitle ) override
{
// This class is shared for numerous tasks: a couple of
// single line labels and multi-line text fields.
// Often the desired size of the multi-line text field editor
// is larger than is needed for the single line label.
// Therefore the session retained sizes of these dialogs needs
// to be class independent, make them title dependent.
// This class is shared for numerous tasks: a couple of single line labels and
// multi-line text fields. Since the desired size of the multi-line text field editor
// is often larger, we retain separate sizes based on the dialog titles.
switch( m_CurrentText->Type() )
{
case SCH_GLOBAL_LABEL_T:
@ -87,15 +84,12 @@ private:
SCH_EDIT_FRAME* m_Parent;
SCH_TEXT* m_CurrentText;
wxTextCtrl* m_activeTextCtrl;
wxWindow* m_activeTextCtrl;
wxTextEntry* m_activeTextEntry;
UNIT_BINDER m_textSize;
};
/* Edit the properties of the text (Label, Global label, graphic text).. )
* pointed by "aTextStruct"
*/
void SCH_EDIT_FRAME::EditSchematicText( SCH_TEXT* aTextItem )
{
if( aTextItem == NULL )
@ -114,7 +108,7 @@ const int maxSize = (int)( 250 * IU_PER_MM );
DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTextItem ) :
DIALOG_LABEL_EDITOR_BASE( aParent ),
m_textSize( aParent, m_SizeTitle, m_TextSizeCtrl, m_staticSizeUnits, false, minSize, maxSize )
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeLabel, false, minSize, maxSize )
{
m_Parent = aParent;
m_CurrentText = aTextItem;
@ -134,24 +128,40 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe
break;
case SCH_SHEET_PIN_T:
SetTitle( _( "Hierarchical Sheet Pin Properties." ) );
SetTitle( _( "Hierarchical Sheet Pin Properties" ) );
break;
default:
m_Label->SetLabel( _( "Text:" ) );
SetTitle( _( "Text Properties" ) );
break;
}
if( m_CurrentText->IsMultilineAllowed() )
{
m_activeTextCtrl = m_textLabelMultiLine;
m_textLabelSingleLine->Show( false );
m_activeTextCtrl = m_valueMultiLine;
m_activeTextEntry = m_valueMultiLine;
m_textControlSizer->AddGrowableRow( 0 );
m_valueSingleLine->Show( false );
m_valueCombo->Show( false );
}
else if( m_CurrentText->Type() == SCH_GLOBAL_LABEL_T || m_CurrentText->Type() == SCH_LABEL_T )
{
m_activeTextCtrl = m_valueCombo;
m_activeTextEntry = m_valueCombo;
m_valueSingleLine->Show( false );
m_valueMultiLine->Show( false );
}
else
{
m_activeTextCtrl = m_textLabelSingleLine;
m_textLabelMultiLine->Show( false );
m_activeTextCtrl = m_valueSingleLine;
m_activeTextEntry = m_valueSingleLine;
m_valueCombo->Show( false );
m_valueMultiLine->Show( false );
}
SetInitialFocus( m_activeTextCtrl );
@ -167,9 +177,7 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe
// wxTextCtrls fail to generate wxEVT_CHAR events when the wxTE_MULTILINE flag is set,
// so we have to listen to wxEVT_CHAR_HOOK events instead.
m_textLabelMultiLine->Connect( wxEVT_CHAR_HOOK,
wxKeyEventHandler( DIALOG_LABEL_EDITOR::OnCharHook ),
NULL, this );
m_valueMultiLine->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_LABEL_EDITOR::OnCharHook ), nullptr, this );
// Now all widgets have the size fixed, call FinishDialogSettings
FinishDialogSettings();
@ -178,9 +186,7 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe
DIALOG_LABEL_EDITOR::~DIALOG_LABEL_EDITOR()
{
m_textLabelMultiLine->Disconnect( wxEVT_CHAR_HOOK,
wxKeyEventHandler( DIALOG_LABEL_EDITOR::OnCharHook ),
NULL, this );
m_valueMultiLine->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_LABEL_EDITOR::OnCharHook ), nullptr, this );
}
@ -210,7 +216,22 @@ bool DIALOG_LABEL_EDITOR::TransferDataToWindow()
if( !wxDialog::TransferDataToWindow() )
return false;
m_activeTextCtrl->SetValue( m_CurrentText->GetText() );
m_activeTextEntry->SetValue( m_CurrentText->GetText() );
if( m_valueCombo->IsShown() )
{
// Load the combobox with the existing labels of the same type
wxArrayString existingLabels;
SCH_SCREENS allScreens;
for( SCH_SCREEN* screen = allScreens.GetFirst(); screen; screen = allScreens.GetNext() )
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
if( item->Type() == m_CurrentText->Type() )
existingLabels.push_back( static_cast<SCH_TEXT*>( item )->GetText() );
existingLabels.Sort();
m_valueCombo->Append( existingLabels );
}
// Set text options:
int orientation = mapOrientation( m_CurrentText->Type(), m_CurrentText->GetLabelSpinStyle() );
@ -285,7 +306,7 @@ bool DIALOG_LABEL_EDITOR::TransferDataFromWindow()
m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentText->GetBoundingBox() );
text = m_activeTextCtrl->GetValue();
text = m_activeTextEntry->GetValue();
if( !text.IsEmpty() )
m_CurrentText->SetText( text );
@ -301,7 +322,6 @@ bool DIALOG_LABEL_EDITOR::TransferDataFromWindow()
m_CurrentText->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
if( m_TextShape )
/// @todo move cast to widget
m_CurrentText->SetShape( static_cast<PINSHEETLABEL_SHAPE>( m_TextShape->GetSelection() ) );
int style = m_TextStyle->GetSelection();

View File

@ -18,47 +18,51 @@ DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID
m_textControlSizer = new wxFlexGridSizer( 2, 2, 3, 3 );
m_textControlSizer->AddGrowableCol( 1 );
m_textControlSizer->AddGrowableRow( 0 );
m_textControlSizer->SetFlexibleDirection( wxBOTH );
m_textControlSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticText1 = new wxStaticText( this, wxID_ANY, _("&Text:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->Wrap( -1 );
m_staticText1->SetToolTip( _("Enter the text to be used within the schematic") );
m_Label = new wxStaticText( this, wxID_ANY, _("Label:"), wxDefaultPosition, wxDefaultSize, 0 );
m_Label->Wrap( -1 );
m_Label->SetToolTip( _("Enter the text to be used within the schematic") );
m_textControlSizer->Add( m_staticText1, 0, wxALIGN_TOP|wxRIGHT|wxTOP, 3 );
m_textControlSizer->Add( m_Label, 0, wxALIGN_TOP|wxRIGHT|wxTOP, 3 );
wxBoxSizer* bSizeText;
bSizeText = new wxBoxSizer( wxVERTICAL );
m_textLabelSingleLine = new wxTextCtrl( this, wxID_VALUESINGLE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxTE_RICH );
m_textLabelSingleLine->SetMinSize( wxSize( 360,-1 ) );
m_valueSingleLine = new wxTextCtrl( this, wxID_VALUESINGLE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxTE_RICH );
m_valueSingleLine->SetMinSize( wxSize( 360,-1 ) );
m_textLabelSingleLine->SetValidator( wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, &m_labelText ) );
m_valueSingleLine->SetValidator( wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, &m_labelText ) );
bSizeText->Add( m_textLabelSingleLine, 0, wxBOTTOM|wxEXPAND|wxLEFT, 3 );
bSizeText->Add( m_valueSingleLine, 0, wxBOTTOM|wxEXPAND|wxLEFT, 3 );
m_textLabelMultiLine = new wxTextCtrl( this, wxID_VALUEMULTI, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
m_textLabelMultiLine->SetMinSize( wxSize( 480,72 ) );
m_valueMultiLine = new wxTextCtrl( this, wxID_VALUEMULTI, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
m_valueMultiLine->SetMinSize( wxSize( 480,72 ) );
bSizeText->Add( m_textLabelMultiLine, 1, wxBOTTOM|wxEXPAND|wxLEFT, 3 );
bSizeText->Add( m_valueMultiLine, 1, wxBOTTOM|wxEXPAND|wxLEFT, 3 );
m_valueCombo = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER );
m_valueCombo->SetValidator( wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, &m_comboText ) );
bSizeText->Add( m_valueCombo, 0, wxEXPAND|wxBOTTOM|wxLEFT, 5 );
m_textControlSizer->Add( bSizeText, 1, wxEXPAND, 3 );
m_SizeTitle = new wxStaticText( this, wxID_ANY, _("&Size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_SizeTitle->Wrap( -1 );
m_textControlSizer->Add( m_SizeTitle, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT, 3 );
m_textSizeLabel = new wxStaticText( this, wxID_ANY, _("Text Size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_textSizeLabel->Wrap( -1 );
m_textControlSizer->Add( m_textSizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT, 3 );
wxBoxSizer* bSizeCtrlSizer;
bSizeCtrlSizer = new wxBoxSizer( wxHORIZONTAL );
m_TextSizeCtrl = new wxTextCtrl( this, wxID_SIZE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizeCtrlSizer->Add( m_TextSizeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxTOP, 3 );
m_textSizeCtrl = new wxTextCtrl( this, wxID_SIZE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizeCtrlSizer->Add( m_textSizeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxTOP, 3 );
m_staticSizeUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticSizeUnits->Wrap( -1 );
bSizeCtrlSizer->Add( m_staticSizeUnits, 0, wxALIGN_CENTER_VERTICAL|wxTOP, 2 );
m_textSizeUnits = new wxStaticText( this, wxID_ANY, _("units"), wxDefaultPosition, wxDefaultSize, 0 );
m_textSizeUnits->Wrap( -1 );
bSizeCtrlSizer->Add( m_textSizeUnits, 0, wxALIGN_CENTER_VERTICAL|wxTOP, 2 );
m_textControlSizer->Add( bSizeCtrlSizer, 1, wxEXPAND, 3 );
@ -105,12 +109,14 @@ DIALOG_LABEL_EDITOR_BASE::DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID
bMainSizer->Fit( this );
// Connect Events
m_textLabelSingleLine->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
m_valueSingleLine->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
m_valueCombo->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
}
DIALOG_LABEL_EDITOR_BASE::~DIALOG_LABEL_EDITOR_BASE()
{
// Disconnect Events
m_textLabelSingleLine->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
m_valueSingleLine->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
m_valueCombo->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_LABEL_EDITOR_BASE::OnEnterKey ), NULL, this );
}

View File

@ -141,7 +141,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">&amp;Text:</property>
<property name="label">Label:</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -149,7 +149,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText1</property>
<property name="name">m_Label</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -241,7 +241,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size">360,-1</property>
<property name="moveable">1</property>
<property name="name">m_textLabelSingleLine</property>
<property name="name">m_valueSingleLine</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -332,7 +332,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size">480,72</property>
<property name="moveable">1</property>
<property name="name">m_textLabelMultiLine</property>
<property name="name">m_valueMultiLine</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -383,6 +383,99 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxComboBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="choices"></property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_valueCombo</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selection">-1</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="subclass">; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type">wxString</property>
<property name="validator_style">wxFILTER_EXCLUDE_CHAR_LIST</property>
<property name="validator_type">wxTextValidator</property>
<property name="validator_variable">m_comboText</property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnCombobox"></event>
<event name="OnComboboxCloseup"></event>
<event name="OnComboboxDropdown"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnText"></event>
<event name="OnTextEnter">OnEnterKey</event>
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
@ -417,7 +510,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">&amp;Size:</property>
<property name="label">Text Size:</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -425,7 +518,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_SizeTitle</property>
<property name="name">m_textSizeLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -517,7 +610,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_TextSizeCtrl</property>
<property name="name">m_textSizeCtrl</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -608,7 +701,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticSizeUnits</property>
<property name="name">m_textSizeUnits</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>

View File

@ -20,6 +20,7 @@
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/valtext.h>
#include <wx/combobox.h>
#include <wx/sizer.h>
#include <wx/radiobox.h>
#include <wx/button.h>
@ -43,12 +44,13 @@ class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM
};
wxFlexGridSizer* m_textControlSizer;
wxStaticText* m_staticText1;
wxTextCtrl* m_textLabelSingleLine;
wxTextCtrl* m_textLabelMultiLine;
wxStaticText* m_SizeTitle;
wxTextCtrl* m_TextSizeCtrl;
wxStaticText* m_staticSizeUnits;
wxStaticText* m_Label;
wxTextCtrl* m_valueSingleLine;
wxTextCtrl* m_valueMultiLine;
wxComboBox* m_valueCombo;
wxStaticText* m_textSizeLabel;
wxTextCtrl* m_textSizeCtrl;
wxStaticText* m_textSizeUnits;
wxRadioBox* m_TextOrient;
wxRadioBox* m_TextStyle;
wxRadioBox* m_TextShape;
@ -62,6 +64,7 @@ class DIALOG_LABEL_EDITOR_BASE : public DIALOG_SHIM
public:
wxString m_labelText;
wxString m_comboText;
DIALOG_LABEL_EDITOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_LABEL_EDITOR_BASE();