Propagate project path as a T_FSPath

This commit is contained in:
Emmanuel BENOîT 2017-12-27 14:15:49 +01:00
parent 1e55dbb4d9
commit 3f6c61cfd3
7 changed files with 21 additions and 36 deletions

View file

@ -10,26 +10,17 @@ A_ProjectPathListener::~A_ProjectPathListener( ) {}
/*= T_Project ================================================================*/
void T_Project::setBasePath(
T_String const& path ) noexcept
T_FSPath const& path ) noexcept
{
if ( !path || path[ path.length( ) - 1 ] != '/' ) {
setBasePathInternal( path );
} else {
setBasePathInternal( path.substr( 0 , path.length( ) - 1 ) );
}
}
void T_Project::setBasePathInternal(
T_String path ) noexcept
{
if ( ( path && basePath_ == path )
|| ( !path && basePath_ == "." ) ) {
assert( path.isValid( ) );
if ( basePath_ == path ) {
return;
}
if ( !path ) {
basePath_ = T_String::Pooled( "." );
if ( path.isRelative( ) ) {
basePath_ = ( Filesystem::Cwd( ) + path ).canonical( );
} else {
basePath_ = std::move( path );
basePath_ = path.canonical( );
}
const auto n{ listeners_.size( ) };
@ -43,15 +34,11 @@ void T_Project::setBasePathInternal(
T_String T_Project::pathOf(
T_String const& file ) const noexcept
{
T_StringBuilder sb;
sb << basePath_ << '/' << file;
return std::move( sb );
return ( basePath_ + T_FSPath{ file } ).canonical( ).toString( );
}
T_String T_Project::pathOf(
char const* file ) const noexcept
{
T_StringBuilder sb;
sb << basePath_ << '/' << file;
return std::move( sb );
return ( basePath_ + T_FSPath{ file } ).canonical( ).toString( );
}

View file

@ -18,12 +18,12 @@ class A_ProjectPathListener
struct T_Project
{
explicit T_Project( T_String const& path ) noexcept
explicit T_Project( T_FSPath const& path ) noexcept
{ setBasePath( path ); }
void setBasePath( T_String const& path ) noexcept;
void setBasePath( T_FSPath const& path ) noexcept;
T_String const& basePath( ) const noexcept
T_FSPath const& basePath( ) const noexcept
{ return basePath_; }
T_String pathOf( T_String const& file ) const noexcept;
@ -35,10 +35,8 @@ struct T_Project
{ listeners_.remove( listener ); }
private:
T_String basePath_;
T_FSPath basePath_;
ebcl::T_Set< A_ProjectPathListener* > listeners_{
ebcl::UseTag< ebcl::ArrayBacked< 16 > >( )
};
void setBasePathInternal( T_String path ) noexcept;
};

View file

@ -19,7 +19,7 @@ struct CommonData_
T_ScriptManager ops;
T_UndoManager undo;
CommonData_( T_String const& path ) noexcept
CommonData_( T_FSPath const& path ) noexcept
: project{ path }
{}
};
@ -31,7 +31,7 @@ std::aligned_storage_t< sizeof( CommonData_ ) , alignof( CommonData_ ) > Instanc
/*----------------------------------------------------------------------------*/
void Common::Init(
T_String const& path ) noexcept
T_FSPath const& path ) noexcept
{
new ((char*)&Instance_) CommonData_( path );
}

View file

@ -13,7 +13,7 @@ class T_UndoManager;
struct Common
{
static void Init( T_String const& path = {} ) noexcept;
static void Init( T_FSPath const& path = {} ) noexcept;
static void Shutdown( ) noexcept;
static T_Project& Project( ) noexcept;

View file

@ -22,7 +22,7 @@ struct T_Main
{
static constexpr uint32_t ResizeDelay = 50;
T_Main( char const* path );
explicit T_Main( T_FSPath const& path );
~T_Main( );
void mainLoop( );
@ -45,7 +45,7 @@ struct T_Main
/*----------------------------------------------------------------------------*/
T_Main::T_Main( char const* const path )
T_Main::T_Main( T_FSPath const& path )
{
UI::Init( path );
prevSize = ImVec2( -1 , -1 );
@ -208,7 +208,7 @@ int main( int argc , char** argv )
}
const T_FSPath rpp{ ( pp.isRelative( ) ? ( cwd + pp ) : pp ).canonical( ) };
T_Main m{ argc < 2 ? "." : argv[ 1 ] };
T_Main m{ rpp };
m.mainLoop( );
return 0;
}

2
ui.cc
View file

@ -43,7 +43,7 @@ std::aligned_storage_t< sizeof( UIData_ ) , alignof( UIData_ ) > Instance_;
/*----------------------------------------------------------------------------*/
void UI::Init( T_String const& path ) noexcept
void UI::Init( T_FSPath const& path ) noexcept
{
Common::Init( path );
new ((char*)&Instance_) UIData_( );

2
ui.hh
View file

@ -15,7 +15,7 @@ struct T_UISync;
struct UI
{
public:
static void Init( T_String const& path = {} ) noexcept;
static void Init( T_FSPath const& path = {} ) noexcept;
static void Shutdown( ) noexcept;
static T_UIApp& Main( ) noexcept;