Commit 26b20cad authored by charras's avatar charras

Better label dialog editor. Libedit: now, cannot change the component name to...

Better label dialog editor. Libedit: now, cannot change the component name to an existing alias name (eeschema crashes when happens)
parent 07ddb9cb
......@@ -8,7 +8,7 @@
#include "appl_wxstruct.h"
#define BUILD_VERSION wxT("(20090504-unstable)")
#define BUILD_VERSION wxT("(20090513-unstable)")
wxString g_BuildVersion
......
......@@ -21,9 +21,8 @@
int DialogLabelEditor::ShowModally( WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText )
{
int ret;
bool multiline = CurrentText->m_MultilineAllowed;
DialogLabelEditor* dialog = new DialogLabelEditor( parent, CurrentText, multiline );
DialogLabelEditor* dialog = new DialogLabelEditor( parent, CurrentText );
// doing any post construction resizing is better done here than in
// OnInitDialog() since it tends to flash/redraw the dialog less.
......@@ -36,11 +35,12 @@ int DialogLabelEditor::ShowModally( WinEDA_SchematicFrame* parent, SCH_TEXT * C
DialogLabelEditor::DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT* CurrentText,bool multiline ) :
DialogLabelEditor_Base( parent,wxID_ANY,multiline )
DialogLabelEditor::DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT* CurrentText ) :
DialogLabelEditor_Base( parent )
{
m_Parent = parent;
m_CurrentText = CurrentText;
init();
}
......@@ -48,6 +48,17 @@ void DialogLabelEditor::init()
{
wxString msg;
if( m_CurrentText->m_MultilineAllowed )
{
m_TextLabel = m_textCtrlMultiline;
m_TextLabelSingleline->Show(false);
}
else
{
m_TextLabel = m_TextLabelSingleline;
m_textCtrlMultiline->Show(false);
}
m_TextLabel->SetValue( m_CurrentText->m_Text );
m_TextLabel->SetFocus();
......
......@@ -15,10 +15,11 @@ class DialogLabelEditor : public DialogLabelEditor_Base
private:
WinEDA_SchematicFrame * m_Parent;
SCH_TEXT * m_CurrentText;
wxTextCtrl* m_TextLabel;
protected:
// these are protected so that the static ShowModally() gets used.
DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText, bool multiline);
DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText);
~DialogLabelEditor(){};
......
......@@ -9,26 +9,27 @@
///////////////////////////////////////////////////////////////////////////
DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id, bool multiline,const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxHORIZONTAL );
bSizerTextCtrl = new wxBoxSizer( wxVERTICAL );
bMainSizer = new wxBoxSizer( wxVERTICAL );
m_staticText1 = new wxStaticText( this, wxID_ANY, _("Text"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText1->Wrap( -1 );
bSizerTextCtrl->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
bMainSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_TextLabelSingleline = new wxTextCtrl( this, wxID_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
m_TextLabelSingleline->SetToolTip( _("Enter the text to be used within the schematic") );
bMainSizer->Add( m_TextLabelSingleline, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
if (multiline)
m_TextLabel = new wxTextCtrl( this, wxID_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_MULTILINE );
else
m_TextLabel = new wxTextCtrl( this, wxID_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
m_TextLabel->SetToolTip( _("Enter the text to be used within the schematic") );
m_textCtrlMultiline = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_PROCESS_ENTER );
m_textCtrlMultiline->SetToolTip( _("Enter the text to be used within the schematic") );
m_textCtrlMultiline->SetMinSize( wxSize( -1,60 ) );
bSizerTextCtrl->Add( m_TextLabel, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
bMainSizer->Add( m_textCtrlMultiline, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
wxBoxSizer* m_OptionsSizer;
m_OptionsSizer = new wxBoxSizer( wxHORIZONTAL );
......@@ -51,10 +52,6 @@ DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id,
m_TextShape->SetSelection( 0 );
m_OptionsSizer->Add( m_TextShape, 1, wxALL, 5 );
bSizerTextCtrl->Add( m_OptionsSizer, 1, wxEXPAND, 5 );
bMainSizer->Add( bSizerTextCtrl, 5, wxEXPAND, 5 );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
......@@ -66,7 +63,7 @@ DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id,
bSizer4->Add( m_TextSize, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
bSizer4->Add( 8, 8, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
bSizer4->Add( 8, 8, 0, wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
m_buttonOK = new wxButton( this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_buttonOK, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
......@@ -74,13 +71,15 @@ DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id,
m_buttonCANCEL = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer4->Add( m_buttonCANCEL, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
bMainSizer->Add( bSizer4, 1, 0, 5 );
m_OptionsSizer->Add( bSizer4, 1, 0, 5 );
bMainSizer->Add( m_OptionsSizer, 1, wxEXPAND, 5 );
this->SetSizer( bMainSizer );
this->Layout();
// Connect Events
m_TextLabel->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DialogLabelEditor_Base::onEnterKey ), NULL, this );
m_TextLabelSingleline->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DialogLabelEditor_Base::onEnterKey ), NULL, this );
m_buttonOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogLabelEditor_Base::OnButtonOKClick ), NULL, this );
m_buttonCANCEL->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogLabelEditor_Base::OnButtonCANCEL_Click ), NULL, this );
}
......@@ -88,7 +87,7 @@ DialogLabelEditor_Base::DialogLabelEditor_Base( wxWindow* parent, wxWindowID id,
DialogLabelEditor_Base::~DialogLabelEditor_Base()
{
// Disconnect Events
m_TextLabel->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DialogLabelEditor_Base::onEnterKey ), NULL, this );
m_TextLabelSingleline->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DialogLabelEditor_Base::onEnterKey ), NULL, this );
m_buttonOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogLabelEditor_Base::OnButtonOKClick ), NULL, this );
m_buttonCANCEL->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogLabelEditor_Base::OnButtonCANCEL_Click ), NULL, this );
}
......@@ -32,7 +32,7 @@
<property name="minimum_size"></property>
<property name="name">DialogLabelEditor_Base</property>
<property name="pos"></property>
<property name="size">600,216</property>
<property name="size">526,281</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass"></property>
<property name="title">Text Editor</property>
......@@ -73,17 +73,8 @@
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bMainSizer</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">5</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerTextCtrl</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">protected</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
......@@ -150,7 +141,7 @@
<property name="maximum_size"></property>
<property name="maxlength">0</property>
<property name="minimum_size"></property>
<property name="name">m_TextLabel</property>
<property name="name">m_TextLabelSingleline</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size"></property>
......@@ -190,6 +181,61 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="bg"></property>
<property name="context_help"></property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="maxlength">0</property>
<property name="minimum_size">-1,60</property>
<property name="name">m_textCtrlMultiline</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxTE_MULTILINE|wxTE_PROCESS_ENTER</property>
<property name="subclass"></property>
<property name="tooltip">Enter the text to be used within the schematic</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="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"></event>
<event name="OnTextMaxLen"></event>
<event name="OnTextURL"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
......@@ -361,10 +407,6 @@
<event name="OnUpdateUI"></event>
</object>
</object>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag"></property>
......@@ -482,7 +524,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxALIGN_CENTER_HORIZONTAL</property>
<property name="flag">wxALIGN_CENTER_HORIZONTAL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="spacer" expanded="1">
<property name="height">8</property>
......@@ -599,4 +641,6 @@
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>
......@@ -18,8 +18,8 @@
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/radiobox.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
......@@ -38,9 +38,9 @@ class DialogLabelEditor_Base : public wxDialog
wxID_SIZE,
};
wxBoxSizer* bSizerTextCtrl;
wxStaticText* m_staticText1;
wxTextCtrl* m_TextLabel;
wxTextCtrl* m_TextLabelSingleline;
wxTextCtrl* m_textCtrlMultiline;
wxRadioBox* m_TextOrient;
wxRadioBox* m_TextStyle;
wxRadioBox* m_TextShape;
......@@ -57,7 +57,7 @@ class DialogLabelEditor_Base : public wxDialog
public:
DialogLabelEditor_Base( wxWindow* parent, wxWindowID id = wxID_ANY, bool multiline=false, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 600,216 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DialogLabelEditor_Base( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Text Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 526,281 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DialogLabelEditor_Base();
};
......
......@@ -21,10 +21,12 @@
/* Routines locales */
static void ShowMoveField( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
/* if the field is the reference, return reference like schematic, i.e U -> U? or U?A
* or the field text for others
*/
static wxString ReturnFieldFullText( LibDrawField* aField);
static wxString ReturnFieldFullText( LibDrawField* aField );
/* Variables locales */
extern int CurrentUnit;
......@@ -82,9 +84,9 @@ void WinEDA_LibeditFrame::StartMoveField( wxDC* DC, LibDrawField* field )
/* if the field is the reference, return reference like schematic, i.e U -> U? or U?A
* or the field text for others
*/
static wxString ReturnFieldFullText( LibDrawField* aField)
static wxString ReturnFieldFullText( LibDrawField* aField )
{
if ( aField->m_FieldId != REFERENCE )
if( aField->m_FieldId != REFERENCE )
return aField->m_Text;
wxString text = aField->m_Text;
......@@ -106,6 +108,7 @@ static wxString ReturnFieldFullText( LibDrawField* aField)
return text;
}
/*****************************************************************/
/* Routine d'affichage du texte 'Field' en cours de deplacement. */
/* Routine normalement attachee au curseur */
......@@ -228,7 +231,7 @@ void WinEDA_LibeditFrame::EditField( wxDC* DC, LibDrawField* Field )
break;
case VALUE:
title = wxT( "Value:" );
title = wxT( "Component Name / Value:" );
color = ReturnLayerColor( LAYER_VALUEPART );
break;
......@@ -244,6 +247,26 @@ void WinEDA_LibeditFrame::EditField( wxDC* DC, LibDrawField* Field )
Get_Message( title, _( "Edit field" ), Text, this );
Text.Replace( wxT( " " ), wxT( "_" ) );
/* If the value is changed, this is equivalent to create a new component from the old one
* So we must check for an existing alias of this "new" component
* and change the value only if there is no existing alias with the same name
* for this component
*/
if( Field->m_FieldId == VALUE )
{
/* test for an existing name in alias list: */
for( unsigned ii = 0; ii < CurrentLibEntry->m_AliasList.GetCount(); ii += ALIAS_NEXT )
{
wxString aliasname = CurrentLibEntry->m_AliasList[ii + ALIAS_NAME];
if( Text.CmpNoCase( aliasname ) == 0 )
{
DisplayError( this,
_( "This name is an existing alias of the component\nAborting" ), 10 );
return;
}
}
}
GRSetDrawMode( DC, g_XorMode );
DrawGraphicText( DrawPanel, DC, wxPoint( Field->m_Pos.x, -Field->m_Pos.y ),
color, ReturnFieldFullText( Field ),
......@@ -380,20 +403,22 @@ LibEDA_BaseStruct* WinEDA_LibeditFrame::LocateItemUsingCursor()
if( CurrentLibEntry == NULL )
return NULL;
if( (DrawEntry == NULL) || (DrawEntry->m_Flags == 0) )
{ // Simple localisation des elements
if( (DrawEntry == NULL) || (DrawEntry->m_Flags == 0) ) // Simple localisation des elements
{
DrawEntry = LocatePin(
GetScreen()->m_Curseur, CurrentLibEntry, CurrentUnit, CurrentConvert );
if( DrawEntry == NULL )
{
DrawEntry = CurrentDrawItem = LocateDrawItem( (SCH_SCREEN*) GetScreen(),
GetScreen()->m_MousePosition, CurrentLibEntry, CurrentUnit,
GetScreen()->m_MousePosition,
CurrentLibEntry, CurrentUnit,
CurrentConvert, LOCATE_ALL_DRAW_ITEM );
}
if( DrawEntry == NULL )
{
DrawEntry = CurrentDrawItem = LocateDrawItem( (SCH_SCREEN*) GetScreen(),
GetScreen()->m_Curseur, CurrentLibEntry, CurrentUnit,
GetScreen()->m_Curseur, CurrentLibEntry,
CurrentUnit,
CurrentConvert, LOCATE_ALL_DRAW_ITEM );
}
if( DrawEntry == NULL )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment