From 57a60a32f58f69abd93c2088de445cfe7dc91d40 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh <stambaughw@gmail.com> Date: Thu, 20 Jun 2019 15:18:43 -0400 Subject: [PATCH] KiCad: fix project tree open in system path bug. Don't pass relative paths to the system file manager. The current working directory may not be the current project path which may end up opening the system file manager in an unexpected folder. Fallback to the user's document folder when a valid project path is not found. --- kicad/tree_project_frame.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 177c71925a..62a565d269 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr - * 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 @@ -218,19 +218,17 @@ void TREE_PROJECT_FRAME::OnOpenDirectory( wxCommandEvent& event ) root = m_TreeProject->GetSelection(); } - wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() ); - // Ask for the new sub directory name wxString curr_dir = treeData->GetDir(); - if( !curr_dir.IsEmpty() ) // A subdir is selected + if( curr_dir.IsEmpty() ) { - // Make this subdir name relative to the current path. - // It will be more easy to read by the user, in the next dialog - wxFileName fn; - fn.AssignDir( curr_dir ); - fn.MakeRelativeTo( prj_dir ); - curr_dir = fn.GetPath(); + // Use project path if the tree view path was empty. + curr_dir = wxPathOnly( m_Parent->GetProjectFileName() ); + + // As a last resort use the user's documents folder. + if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) ) + curr_dir = wxStandardPaths::Get().GetDocumentsDir(); if( !curr_dir.IsEmpty() ) curr_dir += wxFileName::GetPathSeparator(); @@ -294,7 +292,7 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) if( wxMkdir( full_dirname ) ) { - // the new itel will be added by the file watcher + // the new item will be added by the file watcher // AddItemToTreeProject( subdir, root ); } } @@ -390,9 +388,6 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type ) } -/* - * Return the wxFileDialog wildcard string for the selected file type. - */ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type ) { wxString ext;