Make sure that libraries are always sorted consistently.

Fixes #1847481 | https://gitlab.com/kicad/code/kicad/issues/1847481
This commit is contained in:
Jeff Young 2019-12-02 21:52:14 +00:00
parent d4816d843d
commit 9b36489270
5 changed files with 22 additions and 60 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -23,10 +23,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file displlst.cpp
*/
#include <fctsys.h>
#include <macros.h>
#include <eda_draw_frame.h>
@ -46,11 +42,9 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl
const std::vector<wxArrayString>& aItemList,
const wxString& aSelection,
void( *aCallBackFunction )( wxString&, void* ),
void* aCallBackFunctionData,
bool aSortList, bool aShowHeaders ) :
void* aCallBackFunctionData ) :
EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
{
m_sortList = aSortList;
m_cb_func = aCallBackFunction;
m_cb_data = aCallBackFunctionData;
m_itemsListCp = &aItemList;
@ -59,7 +53,7 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl
initDialog( aItemHeaders, aSelection );
if( !aShowHeaders )
if( aItemHeaders.IsEmpty() )
m_listBox->SetSingleStyle( wxLC_NO_HEADER, true );
// DIALOG_SHIM needs a unique hash_key because classname is not sufficient
@ -111,12 +105,6 @@ void EDA_LIST_DIALOG::initDialog( const wxArrayString& aItemHeaders, const wxStr
}
void EDA_LIST_DIALOG::SetFilterHint( const wxString& aHint )
{
m_filterBox->SetHint( aHint );
}
void EDA_LIST_DIALOG::SetListLabel( const wxString& aLabel )
{
m_listLabel->SetLabel( aLabel );
@ -148,8 +136,7 @@ void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event )
}
}
if( m_sortList )
sortList();
sortList();
}
@ -219,8 +206,7 @@ void EDA_LIST_DIALOG::InsertItems( const std::vector< wxArrayString >& itemList,
}
}
if( m_sortList )
sortList();
sortList();
}

View File

@ -97,25 +97,24 @@ wxString LIB_EDIT_FRAME::SelectLibraryFromList()
itemsToDisplay.push_back( item );
}
wxString old_lib_name = prj.GetRString( PROJECT::SCH_LIB_SELECT );
wxString oldLibName = prj.GetRString( PROJECT::SCH_LIB_SELECT );
EDA_LIST_DIALOG dlg( this, _( "Select Symbol Library" ), headers, itemsToDisplay,
old_lib_name );
EDA_LIST_DIALOG dlg( this, _( "Select Symbol Library" ), headers, itemsToDisplay, oldLibName );
if( dlg.ShowModal() != wxID_OK )
return wxEmptyString;
wxString libname = dlg.GetTextSelection();
wxString libName = dlg.GetTextSelection();
if( !libname.empty() )
if( !libName.empty() )
{
if( prj.SchSymbolLibTable()->HasLibrary( libname ) )
prj.SetRString( PROJECT::SCH_LIB_SELECT, libname );
if( prj.SchSymbolLibTable()->HasLibrary( libName ) )
prj.SetRString( PROJECT::SCH_LIB_SELECT, libName );
else
libname = wxEmptyString;
libName = wxEmptyString;
}
return libname;
return libName;
}
@ -400,9 +399,6 @@ void LIB_EDIT_FRAME::savePartAs()
std::vector< wxArrayString > itemsToDisplay;
std::vector< wxString > libNicknames = tbl->GetLogicalLibs();
headers.Add( _( "Nickname" ) );
headers.Add( _( "Description" ) );
for( const auto& name : libNicknames )
{
wxArrayString item;
@ -411,8 +407,7 @@ void LIB_EDIT_FRAME::savePartAs()
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, _( "Save Copy of Symbol" ), headers, itemsToDisplay, old_lib,
nullptr, nullptr, /* sort */ false, /* show headers */ false );
EDA_LIST_DIALOG dlg( this, _( "Save Copy of Symbol" ), headers, itemsToDisplay, old_lib );
dlg.SetListLabel( _( "Save in library:" ) );
dlg.SetOKLabel( _( "Save" ) );

View File

@ -39,8 +39,6 @@ void ConvertMarkdown2Html( const wxString& aMarkdownInput, wxString& aHtmlOutput
class EDA_DRAW_FRAME;
#define SORT_LIST true
/**
* class EDA_LIST_DIALOG
*
@ -58,25 +56,21 @@ public:
* Constructor:
* @param aParent Pointer to the parent window.
* @param aTitle = The title shown on top.
* @param aItemHeaders is an array containing the column header names for the dialog.
* @param aItemHeaders an optional array containing the column header names for the dialog.
* @param aItemList = A wxArrayString of the list of elements.
* @param aRefText = An item name if an item must be preselected.
* @param aCallBackFunction = callback function to display comments
* @param aCallBackFunctionData = a pointer to pass to @a aCallBackFunction
* @param aSortList = true to sort list items by alphabetic order.
* @param aShowHeaders = true if the list should have headers.
*/
EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemHeaders,
const std::vector<wxArrayString>& aItemList,
const wxString& aRefText,
void (* aCallBackFunction)( wxString& text, void* data ) = NULL,
void* aCallBackFunctionData = NULL,
bool aSortList = false, bool aShowHeaders = true );
void* aCallBackFunctionData = NULL );
// ~EDA_LIST_DIALOG() {}
void SetFilterHint( const wxString& aHint );
void SetListLabel( const wxString& aLabel );
void SetOKLabel( const wxString& aLabel );
@ -100,7 +94,6 @@ private:
void initDialog( const wxArrayString& aItemHeaders,
const wxString& aSelection);
void sortList();
bool m_sortList;
void (* m_cb_func)( wxString& text, void* data );
void* m_cb_data;
const std::vector<wxArrayString>* m_itemsListCp;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -21,19 +21,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file librairi.cpp
* @brief Manage module (footprint) libraries.
*/
#include <wx/ffile.h>
#include <wx/stdpaths.h>
#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <confirm.h>
#include <kicad_string.h>
#include <gestfich.h>
#include <pcb_edit_frame.h>
#include <dialog_helpers.h>
#include <filter_reader.h>
@ -46,7 +39,6 @@
#include <class_board.h>
#include <class_module.h>
#include <board_commit.h>
#include <pcbnew.h>
#include <footprint_edit_frame.h>
#include <wildcards_and_files_ext.h>
#include <kicad_plugin.h>
@ -890,19 +882,15 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( MODULE* aModule )
std::vector<wxArrayString> itemsToDisplay;
std::vector<wxString> nicknames = tbl->GetLogicalLibs();
headers.Add( _( "Nickname" ) );
headers.Add( _( "Description" ) );
for( unsigned i = 0; i < nicknames.size(); i++ )
for( const wxString& nickname : nicknames )
{
wxArrayString item;
item.Add( nicknames[i] );
item.Add( tbl->GetDescription( nicknames[i] ) );
item.Add( nickname );
item.Add( tbl->GetDescription( nickname ) );
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName,
nullptr, nullptr, /* sort */ false, /* show headers */ false );
EDA_LIST_DIALOG dlg( this, FMT_SAVE_MODULE, headers, itemsToDisplay, libraryName );
dlg.SetListLabel( _( "Save in library:" ) );
dlg.SetOKLabel( _( "Save" ) );

View File

@ -364,7 +364,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprintFromBoard( BOARD* aPcb )
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString, NULL, NULL, SORT_LIST );
EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString );
if( dlg.ShowModal() == wxID_OK )
fpname = dlg.GetTextSelection();