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

View file

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

View file

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

View file

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

View file

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

2
ui.hh
View file

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