You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2007-2017 KiCad Developers, see CHANGELOG.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <fctsys.h>
  25. #include <gr_basic.h>
  26. #include <class_drawpanel.h>
  27. #include <confirm.h>
  28. #include <sch_component.h>
  29. #include <lib_edit_frame.h>
  30. #include <class_library.h>
  31. #include <symbol_lib_table.h>
  32. #include <template_fieldnames.h>
  33. #include <dialog_edit_one_field.h>
  34. #include <lib_manager.h>
  35. #include <widgets/symbol_tree_pane.h>
  36. #include <widgets/lib_tree.h>
  37. void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
  38. {
  39. wxString newFieldValue;
  40. wxString caption;
  41. if( aField == NULL )
  42. return;
  43. LIB_PART* parent = aField->GetParent();
  44. wxCHECK( parent, /* void */ );
  45. // Editing the component value field is equivalent to creating a new component based
  46. // on the current component. Set the dialog message to inform the user.
  47. if( aField->GetId() == VALUE )
  48. caption = _( "Edit Component Name" );
  49. else
  50. caption.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
  51. DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField );
  52. // The dialog may invoke a kiway player for footprint fields
  53. // so we must use a quasimodal dialog.
  54. if( dlg.ShowQuasiModal() != wxID_OK )
  55. return;
  56. newFieldValue = LIB_ID::FixIllegalChars( dlg.GetText(), LIB_ID::ID_SCH );
  57. wxString oldFieldValue = aField->GetFullText( m_unit );
  58. bool renamed = aField->GetId() == VALUE && newFieldValue != oldFieldValue;
  59. if( renamed )
  60. {
  61. wxString msg;
  62. wxString lib = GetCurLib();
  63. // Test the current library for name conflicts
  64. if( !lib.empty() && m_libMgr->PartExists( newFieldValue, lib ) )
  65. {
  66. msg.Printf( _(
  67. "The name \"%s\" conflicts with an existing entry in the symbol library \"%s\"." ),
  68. newFieldValue, lib );
  69. DisplayErrorMessage( this, msg );
  70. return;
  71. }
  72. SaveCopyInUndoList( parent, UR_LIB_RENAME );
  73. parent->SetName( newFieldValue );
  74. if( !parent->HasAlias( m_aliasName ) )
  75. m_aliasName = newFieldValue;
  76. m_libMgr->UpdatePartAfterRename( parent, oldFieldValue, lib );
  77. // Reselect the renamed part
  78. m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newFieldValue ) );
  79. }
  80. if( !aField->InEditMode() && !renamed )
  81. SaveCopyInUndoList( parent );
  82. dlg.UpdateField( aField );
  83. m_canvas->Refresh();
  84. OnModify();
  85. UpdateAliasSelectList();
  86. }