From 1d83e23927413265761c8c160698a54abbd0f7b1 Mon Sep 17 00:00:00 2001 From: Chris Pavlina Date: Mon, 30 Jan 2017 16:53:48 -0500 Subject: [PATCH] libedit: preselect active component when switching --- eeschema/component_tree_search_container.cpp | 27 ++++++++++++++------ eeschema/getpart.cpp | 8 ++++-- eeschema/libedit.cpp | 8 ++++-- eeschema/sch_base_frame.h | 7 +++-- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/eeschema/component_tree_search_container.cpp b/eeschema/component_tree_search_container.cpp index 8159568731..ad7649a981 100644 --- a/eeschema/component_tree_search_container.cpp +++ b/eeschema/component_tree_search_container.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Henner Zeller - * 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 ); diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 5a922f126e..958bc1006f 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2012 Wayne Stambaugh - * 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 ); diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index b76170e555..c22deaea94 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2013 Wayne Stambaugh - * 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; diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index fe8ef783ca..2f96696025 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -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 - * 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: