From 7f4f5f2882737280f4138b9bb6d5cfdb567279a5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 16 Apr 2022 23:55:19 +0100 Subject: [PATCH] Save and re-load query string in Choose Symbol dialog. While this has been requested on its own, it's primarily done here because wxWidgets decided to send a SEARCH_CANCEL from a wxSearchCtrl when hitting if the search control holes the empty string. This causes us to not do a symbol instert in the Chooser dialog. Fixes https://gitlab.com/kicad/code/kicad/issues/10169 Fixes https://gitlab.com/kicad/code/kicad/issues/7699 --- common/widgets/lib_tree.cpp | 14 +++++++++++++- eeschema/dialogs/dialog_choose_symbol.cpp | 8 +++++++- eeschema/dialogs/dialog_choose_symbol.h | 4 +++- include/widgets/lib_tree.h | 8 +++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index 25d8f0ff65..f8654cfdb4 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.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) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2022 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 @@ -207,6 +207,18 @@ void LIB_TREE::ExpandLibId( const LIB_ID& aLibId ) } +void LIB_TREE::SetSearchString( const wxString& aSearchString ) +{ + m_query_ctrl->SetValue( aSearchString ); +} + + +wxString LIB_TREE::GetSearchString() const +{ + return m_query_ctrl->GetValue(); +} + + void LIB_TREE::Regenerate( bool aKeepState ) { STATE current; diff --git a/eeschema/dialogs/dialog_choose_symbol.cpp b/eeschema/dialogs/dialog_choose_symbol.cpp index 67497def57..955ce3f407 100644 --- a/eeschema/dialogs/dialog_choose_symbol.cpp +++ b/eeschema/dialogs/dialog_choose_symbol.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) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2022 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 @@ -47,6 +47,8 @@ std::mutex DIALOG_CHOOSE_SYMBOL::g_Mutex; +wxString DIALOG_CHOOSE_SYMBOL::g_searchString; + DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxString& aTitle, wxObjectDataPtr& aAdapter, @@ -130,6 +132,8 @@ DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxStr aAdapter->FinishTreeInitialization(); + m_tree->SetSearchString( g_searchString ); + m_hsplitter->SetSashGravity( 0.8 ); m_hsplitter->SetMinimumPaneSize( 20 ); m_hsplitter->SplitVertically( treePanel, ConstructRightPanel( m_hsplitter ) ); @@ -235,6 +239,8 @@ DIALOG_CHOOSE_SYMBOL::~DIALOG_CHOOSE_SYMBOL() m_dbl_click_timer->Stop(); delete m_dbl_click_timer; + g_searchString = m_tree->GetSearchString(); + if( m_browser_button ) { m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, diff --git a/eeschema/dialogs/dialog_choose_symbol.h b/eeschema/dialogs/dialog_choose_symbol.h index fbba5b84d8..d79cd03755 100644 --- a/eeschema/dialogs/dialog_choose_symbol.h +++ b/eeschema/dialogs/dialog_choose_symbol.h @@ -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) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2022 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 @@ -203,6 +203,8 @@ public: static std::mutex g_Mutex; protected: + static wxString g_searchString; + wxTimer* m_dbl_click_timer; SYMBOL_PREVIEW_WIDGET* m_symbol_preview; wxButton* m_browser_button; diff --git a/include/widgets/lib_tree.h b/include/widgets/lib_tree.h index 8b415399de..ead6edd4a0 100644 --- a/include/widgets/lib_tree.h +++ b/include/widgets/lib_tree.h @@ -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) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2022 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 @@ -97,6 +97,12 @@ public: */ void ExpandLibId( const LIB_ID& aLibId ); + /** + * Save/restore search string. + */ + void SetSearchString( const wxString& aSearchString ); + wxString GetSearchString() const; + /** * Regenerate the tree. */