libedit: preselect active component when switching

This commit is contained in:
Chris Pavlina 2017-01-30 16:53:48 -05:00
parent 0f7785760f
commit 1d83e23927
4 changed files with 36 additions and 14 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2015 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015-2017 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
@ -445,6 +445,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
const wxTreeItemId root_id = m_tree->AddRoot( wxEmptyString );
const TREE_NODE* first_match = NULL;
const TREE_NODE* preselected_node = NULL;
bool override_preselect = false;
for( TREE_NODE* node : m_nodes )
{
@ -470,16 +471,26 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
node->TreeId = m_tree->AppendItem( node->Parent ? node->Parent->TreeId : root_id,
node_text );
// If we are a nicely scored alias, we want to have it visible. Also, if there
// is only a single library in this container, we want to have it unfolded
// (example: power library).
if( node->Type == TREE_NODE::TYPE_ALIAS
&& ( node->MatchScore > kLowestDefaultScore || m_libraries_added == 1 ) )
// If there is only a single library in this container, we want to have it
// unfolded (example: power library, libedit)
if( node->Type == TREE_NODE::TYPE_ALIAS && m_libraries_added == 1 )
{
m_tree->Expand( node->TreeId );
if( first_match == NULL )
first_match = node;
}
// If we are a nicely scored alias, we want to have it visible.
if( node->Type == TREE_NODE::TYPE_ALIAS && ( node->MatchScore > kLowestDefaultScore ) )
{
m_tree->Expand( node->TreeId );
if( first_match == NULL )
first_match = node; // First, highest scoring: the "I am feeling lucky" element.
// The user is searching, don't preselect!
override_preselect = true;
}
// The first node that matches our pre-select criteria is choosen. 'First node'
@ -497,12 +508,12 @@ void COMPONENT_TREE_SEARCH_CONTAINER::UpdateSearchTerm( const wxString& aSearch
preselected_node = node;
}
if( first_match ) // Highest score search match pre-selected.
if( first_match && ( !preselected_node || override_preselect ) )
{
m_tree->SelectItem( first_match->TreeId );
m_tree->EnsureVisible( first_match->TreeId );
}
else if( preselected_node ) // No search, so history item preselected.
else if( preselected_node )
{
m_tree->SelectItem( preselected_node->TreeId );
m_tree->EnsureVisible( preselected_node->TreeId );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2017 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
@ -101,7 +101,8 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const SCHLIB_FILTER* aFilte
int& aHistoryLastUnit,
bool aUseLibBrowser,
int* aUnit,
int* aConvert )
int* aConvert,
const wxString& aHighlight )
{
wxString dialogTitle;
PART_LIBS* libs = Prj().SchLibs();
@ -152,6 +153,9 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const SCHLIB_FILTER* aFilte
search_container.SetPreselectNode( aHistoryList[0], aHistoryLastUnit );
}
if( !aHighlight.IsEmpty() )
search_container.SetPreselectNode( aHighlight, /* aUnit */ 0 );
const int deMorgan = aConvert ? *aConvert : 1;
dialogTitle.Printf( _( "Choose Component (%d items loaded)" ), search_container.GetComponentsCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, &search_container, deMorgan );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2017 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
@ -122,12 +122,16 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
return;
}
// Get the name of the current part to preselect it
LIB_PART* current_part = GetCurPart();
wxString part_name = current_part ? current_part->GetName() : wxString( wxEmptyString );
wxArrayString dummyHistoryList;
int dummyLastUnit;
SCHLIB_FILTER filter;
filter.LoadFrom( lib->GetName() );
cmp_name = SelectComponentFromLibrary( &filter, dummyHistoryList, dummyLastUnit,
true, NULL, NULL );
true, NULL, NULL, part_name );
if( cmp_name.IsEmpty() )
return;

View File

@ -4,7 +4,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2015-2016 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2015-2017 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
@ -135,6 +135,8 @@ public:
* @param aUseLibBrowser bool to call the library viewer to select the component
* @param aUnit a pointer to int to return the selected unit (if any)
* @param aConvert a pointer to int to return the selected De Morgan shape (if any)
* @param aHighlight name of component to highlight in the list.
* highlights none if there isn't one by that name
*
* @return the component name
*/
@ -143,7 +145,8 @@ public:
int& aHistoryLastUnit,
bool aUseLibBrowser,
int* aUnit,
int* aConvert );
int* aConvert,
const wxString& aHighlight = wxEmptyString );
protected: