← Back to team overview

kicad-developers team mailing list archive

[PATCH] Use the OS Documents folder for default project instead of CWD

 

Hi all,

This recent bug complains about the default project path being in a
read-only directory on Windows:
https://bugs.launchpad.net/kicad/+bug/1463510

The attached patch changes the default project folder to wx's
GetDocumentsDir(), which should translate to "$HOME", "...\My Documents"
(Win), or "~/Documents" (Mac).
I tested it solely on Ubuntu.

There could be more scenarios where we want to do the same. I tried to
extend this behaviour to Eeschema's standalone mode for starters, tell me
if more needs be done.

However the behaviour of writing to some default directory without asking
is unsettling. I suppose most noname.pro / noname.sch wouldn't exist if a
"Save as" popup was shown the first time.

Martin
From 0ed4dd0b95284baba8475144566cfaa0dddb74c2 Mon Sep 17 00:00:00 2001
From: Martin d'Allens <martin.dallens@xxxxxxxxx>
Date: Sun, 14 Jun 2015 18:10:23 +0200
Subject: [PATCH 2/2] Use the OS Documents folder for default project instead
 of CWD (bug #1463510)

---
 eeschema/schframe.cpp        | 10 +++++-----
 kicad/kicad.cpp              |  4 ++--
 kicad/tree_project_frame.cpp |  3 ++-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp
index 769d6cd..142c8bb 100644
--- a/eeschema/schframe.cpp
+++ b/eeschema/schframe.cpp
@@ -27,6 +27,7 @@
  */
 
 #include <fctsys.h>
+#include <wx/stdpaths.h>
 #include <kiface_i.h>
 #include <pgm_base.h>
 #include <gr_basic.h>
@@ -330,7 +331,8 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ):
     m_showAxis = false;                 // true to show axis
     m_showBorderAndTitleBlock = true;   // true to show sheet references
     m_CurrentSheet = new SCH_SHEET_PATH;
-    m_DefaultSchematicFileName = NAMELESS_PROJECT;
+    m_DefaultSchematicFileName = wxStandardPaths::Get().GetDocumentsDir() + wxFileName::GetPathSeparator();
+    m_DefaultSchematicFileName += NAMELESS_PROJECT;
     m_DefaultSchematicFileName += wxT( ".sch" );
     m_showAllPins = false;
     m_previewPosition = wxDefaultPosition;
@@ -910,8 +912,7 @@ void SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile( wxCommandEvent& event )
 
 void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
 {
-//  wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
-    wxString pro_dir = wxGetCwd();
+    wxString pro_dir = wxStandardPaths::Get().GetDocumentsDir();
 
     wxFileDialog dlg( this, _( "New Schematic" ), pro_dir,
                       wxEmptyString, SchematicFileWildcard,
@@ -943,8 +944,7 @@ void SCH_EDIT_FRAME::OnNewProject( wxCommandEvent& event )
 
 void SCH_EDIT_FRAME::OnLoadProject( wxCommandEvent& event )
 {
-//  wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
-    wxString pro_dir = wxGetCwd();
+    wxString pro_dir = wxStandardPaths::Get().GetDocumentsDir();
 
     wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir,
                       wxEmptyString, SchematicFileWildcard,
diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp
index 4f497e2..08852eb 100644
--- a/kicad/kicad.cpp
+++ b/kicad/kicad.cpp
@@ -162,7 +162,7 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp )
         {
             GetFileHistory().RemoveFileFromHistory( 0 );
 
-            wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT,
+            wxFileName namelessProject( wxStandardPaths::Get().GetDocumentsDir(), NAMELESS_PROJECT,
                                         ProjectFileExtension );
 
             frame->SetProjectFileName( namelessProject.GetFullPath() );
@@ -181,7 +181,7 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp )
     }
     else	// there is no history
     {
-            wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT,
+            wxFileName namelessProject( wxStandardPaths::Get().GetDocumentsDir(), NAMELESS_PROJECT,
                                         ProjectFileExtension );
 
             frame->SetProjectFileName( namelessProject.GetFullPath() );
diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp
index c02d681..cfb4d01 100644
--- a/kicad/tree_project_frame.cpp
+++ b/kicad/tree_project_frame.cpp
@@ -29,6 +29,7 @@
  */
 
 #include <fctsys.h>
+#include <wx/stdpaths.h>
 #include <confirm.h>
 #include <gestfich.h>
 #include <pgm_base.h>
@@ -592,7 +593,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
     if( !fn.IsOk() )
     {
         fn.Clear();
-        fn.SetPath( ::wxGetCwd() );
+        fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
         fn.SetName( NAMELESS_PROJECT );
         fn.SetExt( ProjectFileExtension );
     }
-- 
2.1.4


Follow ups