From e6dd95e83a15a52889db02db81d05994798f1bbf Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 22 Jan 2021 23:17:32 -0500 Subject: [PATCH] Create a default user projects folder --- common/paths.cpp | 14 ++++++++++++++ eeschema/files-io.cpp | 3 ++- include/paths.h | 1 + kicad/project_tree_pane.cpp | 5 +++-- pcbnew/dialogs/dialog_gendrill.cpp | 3 ++- pcbnew/files.cpp | 7 ++++--- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/common/paths.cpp b/common/paths.cpp index 74af62b10a..050978dc18 100644 --- a/common/paths.cpp +++ b/common/paths.cpp @@ -17,6 +17,7 @@ wxString PATHS::GetUserScriptingPath() return tmp.GetFullPath(); } + wxString PATHS::GetUserTemplatesPath() { wxFileName tmp; @@ -26,5 +27,18 @@ wxString PATHS::GetUserTemplatesPath() tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() ); tmp.AppendDir( "templates" ); + return tmp.GetFullPath(); +} + + +wxString PATHS::GetDefaultUserProjectsPath() +{ + wxFileName tmp; + + tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsDir() ); + tmp.AppendDir( "kicad" ); + tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() ); + tmp.AppendDir( "projects" ); + return tmp.GetFullPath(); } \ No newline at end of file diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index f8a3e82872..a3e6594807 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -60,6 +60,7 @@ #include #include #include +#include bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) { @@ -90,7 +91,7 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) savePath = GetMruPath(); if( !savePath.IsOk() || !savePath.IsDirWritable() ) - savePath = wxStandardPaths::Get().GetDocumentsDir(); + savePath = PATHS::GetDefaultUserProjectsPath(); } wxFileDialog dlg( this, _( "Schematic Files" ), savePath.GetPath(), diff --git a/include/paths.h b/include/paths.h index 2c0f7f05fa..35d8b453ed 100644 --- a/include/paths.h +++ b/include/paths.h @@ -7,6 +7,7 @@ class PATHS public: static wxString GetUserScriptingPath(); static wxString GetUserTemplatesPath(); + static wxString GetDefaultUserProjectsPath(); }; #endif \ No newline at end of file diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index 3ad61a63a7..e6b97d55b6 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "project_tree_item.h" #include "project_tree.h" @@ -201,7 +202,7 @@ void PROJECT_TREE_PANE::onOpenDirectory( wxCommandEvent& event ) // As a last resort use the user's documents folder. if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) ) - curr_dir = wxStandardPaths::Get().GetDocumentsDir(); + curr_dir = PATHS::GetDefaultUserProjectsPath(); if( !curr_dir.IsEmpty() ) curr_dir += wxFileName::GetPathSeparator(); @@ -540,7 +541,7 @@ void PROJECT_TREE_PANE::ReCreateTreePrj() if( !fn.IsOk() ) { fn.Clear(); - fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() ); + fn.SetPath( PATHS::GetDefaultUserProjectsPath() ); fn.SetName( NAMELESS_PROJECT ); fn.SetExt( ProjectFileExtension ); prjReset = true; diff --git a/pcbnew/dialogs/dialog_gendrill.cpp b/pcbnew/dialogs/dialog_gendrill.cpp index 84975244c7..b158f62c19 100644 --- a/pcbnew/dialogs/dialog_gendrill.cpp +++ b/pcbnew/dialogs/dialog_gendrill.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -422,7 +423,7 @@ void DIALOG_GENDRILL::OnGenReportFile( wxCommandEvent& event ) defaultPath = Prj().AbsolutePath( defaultPath ); if( defaultPath.IsEmpty() ) - defaultPath = wxStandardPaths::Get().GetDocumentsDir(); + defaultPath = PATHS::GetDefaultUserProjectsPath(); wxFileDialog dlg( this, _( "Save Drill Report File" ), defaultPath, fn.GetFullName(), ReportFileWildcard(), wxFD_SAVE ); diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 3fe51efab5..11245a1f44 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -167,7 +168,7 @@ bool AskLoadBoardFileName( wxWindow* aParent, int* aCtl, wxString* aFileName, bo } else { - path = wxStandardPaths::Get().GetDocumentsDir(); + path = PATHS::GetDefaultUserProjectsPath(); // leave name empty } @@ -419,7 +420,7 @@ bool PCB_EDIT_FRAME::Files_io_from_id( int id ) savePath = GetMruPath(); if( !savePath.IsOk() || !savePath.IsDirWritable() ) - savePath = wxStandardPaths::Get().GetDocumentsDir(); + savePath = PATHS::GetDefaultUserProjectsPath(); } wxFileName fn( savePath.GetPath(), orig_name, KiCadPcbFileExtension ); @@ -1040,7 +1041,7 @@ bool PCB_EDIT_FRAME::doAutoSave() if( GetBoard()->GetFileName().IsEmpty() ) { - tmpFileName = wxFileName( wxStandardPaths::Get().GetDocumentsDir(), wxT( "noname" ), + tmpFileName = wxFileName( PATHS::GetDefaultUserProjectsPath(), wxT( "noname" ), KiCadPcbFileExtension ); GetBoard()->SetFileName( tmpFileName.GetFullPath() ); }