Finished implementing auto-save (SpartanJ/ecode#220).

This commit is contained in:
Martín Lucas Golini
2024-07-16 16:10:04 -03:00
parent 8ce9e7045b
commit 106466dc61
3 changed files with 23 additions and 5 deletions

View File

@@ -533,7 +533,7 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j,
std::string path( file["path"] );
if ( !FileSystem::fileExists( path ) ) {
editorLoadedCounter( app );
return;
continue;
}
TextRanges selection( TextRanges::fromString( file["selection"] ) );
UITab* tab = nullptr;

View File

@@ -522,6 +522,7 @@ bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool s
mLanguagesPath = mConfigPath + "languages";
mThemesPath = mConfigPath + "themes";
mScriptsPath = mConfigPath + "scripts";
mPlaygroundPath = mConfigPath + "playground";
mColorSchemesPath = mConfigPath + "editor" + FileSystem::getOSSlash() + "colorschemes" +
FileSystem::getOSSlash();
mTerminalManager = std::make_unique<TerminalManager>( this );
@@ -546,6 +547,10 @@ bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool s
FileSystem::makeDir( mScriptsPath );
FileSystem::dirAddSlashAtEnd( mScriptsPath );
if ( !FileSystem::fileExists( mPlaygroundPath ) )
FileSystem::makeDir( mPlaygroundPath );
FileSystem::dirAddSlashAtEnd( mPlaygroundPath );
mLogsPath = mConfigPath + "ecode.log";
#ifndef EE_DEBUG
@@ -702,6 +707,10 @@ void App::onFileDropped( String file ) {
codeEditor = d.second;
tab = d.first;
}
} else {
auto d = mSplitter->createEditorInNewTab();
codeEditor = d.second;
tab = d.first;
}
loadFileFromPath( file, false, codeEditor,
@@ -3228,6 +3237,9 @@ void App::initProjectTreeView( std::string path, bool openClean ) {
} else if ( mConfig.workspace.restoreLastSession && !mRecentFolders.empty() && !openClean ) {
loadFolder( mRecentFolders[0] );
} else {
if ( mConfig.workspace.autoSave && !openClean )
loadFolder( getPlaygroundPath() );
updateOpenRecentFolderBtn();
if ( getConfig().ui.welcomeScreen ) {
@@ -3340,7 +3352,8 @@ void App::loadFolder( const std::string& path ) {
mStatusBar->setVisible( mConfig.ui.showStatusBar );
}
mProjectViewEmptyCont->setVisible( false );
mProjectViewEmptyCont->setVisible( path == getPlaygroundPath() );
mProjectTreeView->setVisible( !mProjectViewEmptyCont->isVisible() );
std::string rpath( FileSystem::getRealPath( path ) );
FileSystem::dirAddSlashAtEnd( rpath );
@@ -3375,9 +3388,11 @@ void App::loadFolder( const std::string& path ) {
if ( mFileSystemListener )
mFileSystemListener->setFileSystemModel( mFileSystemModel );
insertRecentFolder( rpath );
cleanUpRecentFolders();
updateRecentFolders();
if ( rpath != getPlaygroundPath() ) {
insertRecentFolder( rpath );
cleanUpRecentFolders();
updateRecentFolders();
}
mSettings->updateProjectSettingsMenu();
if ( mSplitter->getCurWidget() )

View File

@@ -463,6 +463,8 @@ class App : public UICodeEditorSplitter::Client {
const std::string getScriptsPath() const { return mScriptsPath; }
const std::string& getPlaygroundPath() const { return mPlaygroundPath; }
bool isAnyStatusBarSectionVisible() const;
void createDocDirtyAlert( UICodeEditor* editor, bool showEnableAutoReload = true );
@@ -504,6 +506,7 @@ class App : public UICodeEditorSplitter::Client {
std::string mLogsPath;
std::string mi18nPath;
std::string mScriptsPath;
std::string mPlaygroundPath;
Float mDisplayDPI{ 96 };
std::shared_ptr<ThreadPool> mThreadPool;
std::shared_ptr<ProjectDirectoryTree> mDirTree;