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.

104 lines
3.4 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 <sch_draw_panel.h>
  27. #include <confirm.h>
  28. #include <sch_view.h>
  29. #include <sch_component.h>
  30. #include <lib_edit_frame.h>
  31. #include <class_library.h>
  32. #include <symbol_lib_table.h>
  33. #include <template_fieldnames.h>
  34. #include <dialog_edit_one_field.h>
  35. #include <lib_manager.h>
  36. #include <widgets/symbol_tree_pane.h>
  37. #include <widgets/lib_tree.h>
  38. void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
  39. {
  40. wxString newFieldValue;
  41. wxString caption;
  42. if( aField == NULL )
  43. return;
  44. LIB_PART* parent = aField->GetParent();
  45. wxCHECK( parent, /* void */ );
  46. // Editing the component value field is equivalent to creating a new component based
  47. // on the current component. Set the dialog message to inform the user.
  48. if( aField->GetId() == VALUE )
  49. caption = _( "Edit Component Name" );
  50. else
  51. caption.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
  52. DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField );
  53. // The dialog may invoke a kiway player for footprint fields
  54. // so we must use a quasimodal dialog.
  55. if( dlg.ShowQuasiModal() != wxID_OK )
  56. return;
  57. newFieldValue = LIB_ID::FixIllegalChars( dlg.GetText(), LIB_ID::ID_SCH );
  58. wxString oldFieldValue = aField->GetFullText( m_unit );
  59. bool renamed = aField->GetId() == VALUE && newFieldValue != oldFieldValue;
  60. if( renamed )
  61. {
  62. wxString msg;
  63. wxString lib = GetCurLib();
  64. // Test the current library for name conflicts
  65. if( !lib.empty() && m_libMgr->PartExists( newFieldValue, lib ) )
  66. {
  67. msg.Printf( _(
  68. "The name \"%s\" conflicts with an existing entry in the symbol library \"%s\"." ),
  69. newFieldValue, lib );
  70. DisplayErrorMessage( this, msg );
  71. return;
  72. }
  73. SaveCopyInUndoList( parent, UR_LIB_RENAME );
  74. parent->SetName( newFieldValue );
  75. m_libMgr->UpdatePartAfterRename( parent, oldFieldValue, lib );
  76. // Reselect the renamed part
  77. m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newFieldValue ) );
  78. }
  79. if( !aField->InEditMode() && !renamed )
  80. SaveCopyInUndoList( parent );
  81. dlg.UpdateField( aField );
  82. GetCanvas()->GetView()->Update( aField );
  83. GetCanvas()->Refresh();
  84. OnModify();
  85. }