Start trying to shuffle around path management

This commit is contained in:
Marek Roszko 2021-01-22 21:23:37 -05:00
parent 330da52f0c
commit 28c6967dbc
9 changed files with 80 additions and 4 deletions

View File

@ -367,6 +367,7 @@ set( COMMON_SRCS
netclass.cpp
observable.cpp
origin_transforms.cpp
paths.cpp
printout.cpp
project.cpp
properties.cpp

30
common/paths.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <wx/filename.h>
#include <wx/string.h>
#include <kiplatform/environment.h>
#include <paths.h>
#include <settings/settings_manager.h>
wxString PATHS::GetUserScriptingPath()
{
wxFileName tmp;
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsDir() );
tmp.AppendDir( "kicad" );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
tmp.AppendDir( "scripting" );
return tmp.GetFullPath();
}
wxString PATHS::GetUserTemplatesPath()
{
wxFileName tmp;
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsDir() );
tmp.AppendDir( "kicad" );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
tmp.AppendDir( "templates" );
return tmp.GetFullPath();
}

View File

@ -52,9 +52,11 @@
#include <gestfich.h>
#include <hotkeys_basic.h>
#include <id.h>
#include <kiplatform/environment.h>
#include <lockfile.h>
#include <macros.h>
#include <menus_helpers.h>
#include <paths.h>
#include <pgm_base.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
@ -402,9 +404,7 @@ bool PGM_BASE::InitPgm()
else
{
// Default user template path.
tmpFileName.AssignDir( wxStandardPaths::Get().GetDocumentsDir() );
tmpFileName.AppendDir( "kicad" );
tmpFileName.AppendDir( "template" );
tmpFileName.AssignDir( PATHS::GetUserTemplatesPath() );
envVarItem.SetDefinedExternally( false );
}

12
include/paths.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef PATHS_H
#define PATHS_H
class PATHS
{
public:
static wxString GetUserScriptingPath();
static wxString GetUserTemplatesPath();
};
#endif

View File

@ -44,4 +44,10 @@ bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
{
// placeholder, we "nerf" behavior if its a network path so return false by default
return false;
}
wxString KIPLATFORM::ENV::GetDocumentsDir()
{
return wxStandardPaths::Get().GetDocumentsDir();
}

View File

@ -43,5 +43,15 @@ namespace KIPLATFORM
* @return true if given path is on a network location
*/
bool IsNetworkPath( const wxString& aPath );
/**
* Retrieves the operating system specific path for a given path type
*
* @param aType is the type of path
*
* @return Path for the given aPath
*/
wxString GetDocumentsDir();
}
}

View File

@ -20,6 +20,8 @@
#include <kiplatform/environment.h>
#include <wx/intl.h>
#include <wx/filename.h>
#include <wx/stdpaths.h>
#include <wx/string.h>
#include <Windows.h>
@ -55,4 +57,10 @@ bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
{
return ::PathIsNetworkPathW( aPath.wc_str() );
}
wxString KIPLATFORM::ENV::GetDocumentsDir()
{
return wxStandardPaths::Get().GetDocumentsDir();
}

View File

@ -49,4 +49,10 @@ bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
{
// placeholder, we "nerf" behavior if its a network path so return false by default
return false;
}
wxString KIPLATFORM::ENV::GetDocumentsDir()
{
return wxStandardPaths::Get().GetDocumentsDir();
}

View File

@ -37,9 +37,12 @@
#include <trace_helpers.h>
#include <kicad_string.h>
#include <paths.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <kiplatform/environment.h>
#include <wx/app.h>
#include <config.h>
@ -669,7 +672,7 @@ wxString PyScriptingPath( bool aUserPath )
//@todo This should this be a user configurable variable eg KISCRIPT?
if( aUserPath )
{
path = SETTINGS_MANAGER::GetUserSettingsPath() + wxT( "/scripting" );
path = PATHS::GetUserScriptingPath();
}
else
{