From 493216692841163c883be29bcd31b7bc76612a69 Mon Sep 17 00:00:00 2001
From: Oliver <oliver.henry.walters@gmail.com>
Date: Thu, 2 Feb 2017 21:38:34 +1100
Subject: [PATCH] libedit: Improved selection process for DeleteComponent

- Reused SelectComponent dialog
- Reduced selection to current library only
- Ability to filter component for deletion
---
 eeschema/libedit.cpp | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp
index c22deae..8e37b8e 100644
--- a/eeschema/libedit.cpp
+++ b/eeschema/libedit.cpp
@@ -45,6 +45,9 @@
 #include <template_fieldnames.h>
 #include <wildcards_and_files_ext.h>
 
+#include <dialog_choose_component.h>
+#include <component_tree_search_container.h>
+
 #include <dialogs/dialog_lib_new_component.h>
 
 
@@ -533,30 +536,33 @@ void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event )
         }
     }
 
-    lib->GetAliasNames( nameList );
+    COMPONENT_TREE_SEARCH_CONTAINER search_container( Prj().SchLibs() );
+
+    search_container.AddLibrary( *lib );
+
+    wxString dialogTitle;
+    dialogTitle.Printf( _( "Delete Component (%u items loaded)" ), search_container.GetComponentsCount() );
 
-    if( nameList.IsEmpty() )
+    DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, &search_container, m_convert );
+
+    if( dlg.ShowModal() == wxID_CANCEL )
     {
-        msg.Printf( _( "Part library '%s' is empty." ), GetChars( lib->GetName() ) );
-        wxMessageBox( msg, _( "Delete Entry Error" ), wxID_OK | wxICON_EXCLAMATION, this );
         return;
     }
 
-    msg.Printf( _( "Select one of %d components to delete\nfrom library '%s'." ),
-                int( nameList.GetCount() ),
-                GetChars( lib->GetName() ) );
-
-    wxSingleChoiceDialog dlg( this, msg, _( "Delete Part" ), nameList );
+    LIB_ALIAS* const alias = dlg.GetSelectedAlias( &m_unit );
 
-    if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
+    if( !alias || !alias->GetLib() )
+    {
         return;
+    }
 
-    libEntry = lib->FindAlias( dlg.GetStringSelection() );
+    libEntry = lib->FindAlias( alias->GetName() );
 
     if( !libEntry )
     {
         msg.Printf( _( "Entry '%s' not found in library '%s'." ),
-                    GetChars( dlg.GetStringSelection() ),
+                    GetChars( alias->GetName() ),
                     GetChars( lib->GetName() ) );
         DisplayError( this, msg );
         return;
-- 
1.9.5.msysgit.0

