From 620c2af356914d041be441dec5bd8143b9afd273 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 19 Mar 2018 12:44:00 -0400 Subject: [PATCH] KiCad: fix template folder load bug. Add a check to see if the folder selected by the user contains a project template meta data folder and use that folder instead of assuming that it is a folder containing sub-folders with project templates. The normal behavior is preserved when no meta data folder is detected. Fixes lp:1751465 https://bugs.launchpad.net/kicad/+bug/1751465 --- kicad/dialogs/dialog_template_selector.cpp | 53 ++++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/kicad/dialogs/dialog_template_selector.cpp b/kicad/dialogs/dialog_template_selector.cpp index b2fa1e4530..35f7dcf19b 100644 --- a/kicad/dialogs/dialog_template_selector.cpp +++ b/kicad/dialogs/dialog_template_selector.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 Brian Sidebotham - * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2018 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 @@ -46,8 +46,10 @@ TEMPLATE_WIDGET::TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* a // wxWidgets_3.xx way of doing the same... // Bind(wxEVT_LEFT_DOWN, &TEMPLATE_WIDGET::OnMouse, this ); - m_bitmapIcon->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( TEMPLATE_WIDGET::OnMouse ), NULL, this ); - m_staticTitle->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( TEMPLATE_WIDGET::OnMouse ), NULL, this ); + m_bitmapIcon->Connect( wxEVT_LEFT_DOWN, + wxMouseEventHandler( TEMPLATE_WIDGET::OnMouse ), NULL, this ); + m_staticTitle->Connect( wxEVT_LEFT_DOWN, + wxMouseEventHandler( TEMPLATE_WIDGET::OnMouse ), NULL, this ); // We're not selected until we're clicked Unselect(); @@ -97,7 +99,7 @@ void DIALOG_TEMPLATE_SELECTOR::onNotebookResize(wxSizeEvent& event) m_panels[i]->SetSize( m_notebook->GetSize().GetWidth() - 6, 140 ); m_panels[i]->m_SizerBase->FitInside( m_panels[i] ); m_panels[i]->m_scrolledWindow->SetSize( m_panels[i]->GetSize().GetWidth() - 6, - m_panels[i]->GetSize().GetHeight() - 6 ); + m_panels[i]->GetSize().GetHeight() - 6 ); m_panels[i]->m_SizerChoice->FitInside( m_panels[i]->m_scrolledWindow ); } m_notebook->Refresh(); @@ -105,6 +107,7 @@ void DIALOG_TEMPLATE_SELECTOR::onNotebookResize(wxSizeEvent& event) event.Skip(); } + void DIALOG_TEMPLATE_SELECTOR::OnPageChange( wxNotebookEvent& event ) { int page = event.GetSelection(); @@ -118,7 +121,9 @@ DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent ) : DIALOG_TEMPLATE_SELECTOR_BASE( aParent ) { m_htmlWin->SetPage( _( "

Template Selector

" ) ); - m_notebook->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_TEMPLATE_SELECTOR::onNotebookResize ), NULL, this ); + m_notebook->Connect( wxEVT_SIZE, + wxSizeEventHandler( DIALOG_TEMPLATE_SELECTOR::onNotebookResize ), + NULL, this ); m_selectedWidget = NULL; } @@ -132,6 +137,7 @@ void DIALOG_TEMPLATE_SELECTOR::SetWidget( TEMPLATE_WIDGET* aWidget ) SetHtml( m_selectedWidget->GetTemplate()->GetHtmlFile() ); } + void DIALOG_TEMPLATE_SELECTOR::AddTemplate( int aPage, PROJECT_TEMPLATE* aTemplate ) { TEMPLATE_WIDGET* w = new TEMPLATE_WIDGET( m_panels[aPage]->m_scrolledWindow, this ); @@ -142,7 +148,7 @@ void DIALOG_TEMPLATE_SELECTOR::AddTemplate( int aPage, PROJECT_TEMPLATE* aTempla m_panels[aPage]->SetSize( m_notebook->GetSize().GetWidth() - 6, 140 ); m_panels[aPage]->m_SizerBase->FitInside( m_panels[aPage] ); m_panels[aPage]->m_scrolledWindow->SetSize( m_panels[aPage]->GetSize().GetWidth() - 6, - m_panels[aPage]->GetSize().GetHeight() - 6 ); + m_panels[aPage]->GetSize().GetHeight() - 6 ); m_panels[aPage]->m_SizerChoice->FitInside( m_panels[aPage]->m_scrolledWindow ); m_notebook->Refresh(); @@ -154,6 +160,7 @@ PROJECT_TEMPLATE* DIALOG_TEMPLATE_SELECTOR::GetSelectedTemplate() return m_selectedWidget? m_selectedWidget->GetTemplate() : NULL; } + void DIALOG_TEMPLATE_SELECTOR::AddTemplatesPage( const wxString& aTitle, wxFileName& aPath ) { wxNotebookPage* newPage = new wxNotebookPage( m_notebook, wxID_ANY ); @@ -172,30 +179,36 @@ void DIALOG_TEMPLATE_SELECTOR::AddTemplatesPage( const wxString& aTitle, wxFileN buildPageContent( path, m_notebook->GetPageCount() - 1 ); } + void DIALOG_TEMPLATE_SELECTOR::buildPageContent( const wxString& aPath, int aPage ) { // Get a list of files under the template path to include as choices... - wxArrayString files; wxDir dir; if( dir.Open( aPath ) ) { - wxDir sub_dir; - wxString sub_name; - - bool cont = dir.GetFirst( &sub_name, wxEmptyString, wxDIR_DIRS ); - while( cont ) + if( dir.HasSubDirs( "meta" ) ) { - wxString sub_full = aPath + sub_name; - if( sub_dir.Open( sub_full ) ) + AddTemplate( aPage, new PROJECT_TEMPLATE( aPath ) ); + } + else + { + wxDir sub_dir; + wxString sub_name; + + bool cont = dir.GetFirst( &sub_name, wxEmptyString, wxDIR_DIRS ); + + while( cont ) { - files.Add( sub_name ); + wxString sub_full = aPath + sub_name; - PROJECT_TEMPLATE* pt = new PROJECT_TEMPLATE( sub_full ); - AddTemplate( aPage, pt ); + if( sub_dir.Open( sub_full ) ) + { + AddTemplate( aPage, new PROJECT_TEMPLATE( sub_full ) ); + } + + cont = dir.GetNext( &sub_name ); } - - cont = dir.GetNext( &sub_name ); } } } @@ -270,5 +283,5 @@ void DIALOG_TEMPLATE_SELECTOR::replaceCurrentPage() void DIALOG_TEMPLATE_SELECTOR::OnHtmlLinkActivated( wxHtmlLinkEvent& event ) { wxString url = event.GetLinkInfo().GetHref(); - wxLaunchDefaultBrowser( url); + wxLaunchDefaultBrowser( url ); }