From 81a8605e0439ec95c3b65abb1b32bbb247a38cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 16 Jul 2024 16:25:34 -0300 Subject: [PATCH] Rename Auto Save to Session Snapshot --- projects/linux/ee.creator.user | 10 ++-- src/tools/ecode/appconfig.cpp | 78 ++++++++++++++++---------------- src/tools/ecode/appconfig.hpp | 11 +++-- src/tools/ecode/ecode.cpp | 18 ++++---- src/tools/ecode/ecode.hpp | 2 +- src/tools/ecode/settingsmenu.cpp | 14 +++--- 6 files changed, 69 insertions(+), 64 deletions(-) diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 34689fbe5..8ca56e7a0 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -1118,10 +1118,12 @@ eepp-ui-hello-world-debug ProjectExplorer.CustomExecutableRunConfiguration - false - 1 + true + 0 false - true + 1 + 1 + false false %{buildDir}../../../bin/ diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 58bff8c05..83bd53308 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -175,7 +175,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, workspace.restoreLastSession = ini.getValueB( "workspace", "restore_last_session", false ); workspace.checkForUpdatesAtStartup = ini.getValueB( "workspace", "check_for_updates_at_startup", true ); - workspace.autoSave = ini.getValueB( "workspace", "auto_save", true ); + workspace.sessionSnapshot = ini.getValueB( "workspace", "session_snapshot", true ); std::map pluginsEnabled; const auto& creators = pluginManager->getDefinitions(); @@ -315,7 +315,7 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValueB( "workspace", "restore_last_session", workspace.restoreLastSession ); ini.setValueB( "workspace", "check_for_updates_at_startup", workspace.checkForUpdatesAtStartup ); - ini.setValueB( "workspace", "auto_save", workspace.autoSave ); + ini.setValueB( "workspace", "session_snapshot", workspace.sessionSnapshot ); const auto& pluginsEnabled = pluginManager->getPluginsEnabled(); for ( const auto& plugin : pluginsEnabled ) @@ -401,7 +401,7 @@ json saveNode( Node* node ) { void AppConfig::saveProject( std::string projectFolder, UICodeEditorSplitter* editorSplitter, const std::string& configPath, const ProjectDocumentConfig& docConfig, const ProjectBuildConfiguration& buildConfig, bool onlyIfNeeded, - bool autoSave ) { + bool sessionSnapshot ) { FileSystem::dirAddSlashAtEnd( projectFolder ); std::string projectsPath( configPath + "projects" + FileSystem::getOSSlash() ); if ( !FileSystem::fileExists( projectsPath ) ) @@ -439,7 +439,7 @@ void AppConfig::saveProject( std::string projectFolder, UICodeEditorSplitter* ed } else { cfg.writeFile(); } - if ( !autoSave ) + if ( !sessionSnapshot ) return; std::string statePath( projectsPath + "state" ); if ( !FileSystem::fileExists( statePath ) && !FileSystem::makeDir( statePath ) ) @@ -524,7 +524,7 @@ void AppConfig::editorLoadedCounter( ecode::App* app ) { void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j, UITabWidget* curTabWidget, ecode::App* app, - const std::vector& autoSaveFiles ) { + const std::vector& sessionSnapshotFiles ) { if ( j["type"] == "tabwidget" ) { Int64 currentPage = j["current_page"]; size_t totalToLoad = j["files"].size(); @@ -555,19 +555,21 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j, editorLoadedCounter( app ); } else { - auto autoSaveIt = std::find_if( - autoSaveFiles.begin(), autoSaveFiles.end(), - [&path]( const AutoSaveFile& file ) { return file.fspath == path; } ); + auto snapshotSaveIt = + std::find_if( sessionSnapshotFiles.begin(), sessionSnapshotFiles.end(), + [&path]( const SessionSnapshotFile& file ) { + return file.fspath == path; + } ); std::string loadPath( path ); - AutoSaveFile autoSaveFile; - if ( autoSaveIt != autoSaveFiles.end() ) - autoSaveFile = *autoSaveIt; + SessionSnapshotFile snapshotFile; + if ( snapshotSaveIt != sessionSnapshotFiles.end() ) + snapshotFile = *snapshotSaveIt; editorSplitter->loadAsyncFileFromPathInNewTab( path, [this, curTabWidget, selection, totalToLoad, currentPage, app, path, - autoSaveFile]( UICodeEditor* editor, const std::string& ) { + snapshotFile]( UICodeEditor* editor, const std::string& ) { if ( !editor->getDocument().getSelection().isValid() || editor->getDocument().getSelection() == TextRange( { 0, 0 }, { 0, 0 } ) ) { @@ -579,18 +581,18 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j, curTabWidget->setTabSelected( eeclamp( currentPage, 0, curTabWidget->getTabCount() - 1 ) ); - if ( !autoSaveFile.cachePath.empty() ) { + if ( !snapshotFile.cachePath.empty() ) { TextDocument& doc = editor->getDocument(); auto diskFileInfo = doc.getFileInfo(); TextDocument cachedDoc; - cachedDoc.loadFromFile( autoSaveFile.cachePath ); + cachedDoc.loadFromFile( snapshotFile.cachePath ); doc.selectAll(); doc.textInput( cachedDoc.getText() ); doc.setSelection( selection ); doc.resetUndoRedo(); doc.setDirtyUntilSave(); editor->scrollToCursor(); - if ( diskFileInfo.getModificationTime() > autoSaveFile.fsmtime ) + if ( diskFileInfo.getModificationTime() > snapshotFile.fsmtime ) app->createDocDirtyAlert( editor, false ); } @@ -616,9 +618,9 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j, if ( nullptr == splitter ) return; - loadDocuments( editorSplitter, j["first"], curTabWidget, app, autoSaveFiles ); + loadDocuments( editorSplitter, j["first"], curTabWidget, app, sessionSnapshotFiles ); UITabWidget* tabWidget = splitter->getLastWidget()->asType(); - loadDocuments( editorSplitter, j["last"], tabWidget, app, autoSaveFiles ); + loadDocuments( editorSplitter, j["last"], tabWidget, app, sessionSnapshotFiles ); splitter->setSplitPartition( StyleSheetLength( j["split"] ) ); } @@ -626,7 +628,7 @@ void AppConfig::loadDocuments( UICodeEditorSplitter* editorSplitter, json j, void AppConfig::loadProject( std::string projectFolder, UICodeEditorSplitter* editorSplitter, const std::string& configPath, ProjectDocumentConfig& docConfig, - ecode::App* app, bool autoSave ) { + ecode::App* app, bool sessionSnapshot ) { FileSystem::dirAddSlashAtEnd( projectFolder ); std::string projectsPath( configPath + "projects" + FileSystem::getOSSlash() ); MD5::Result hash = MD5::fromString( projectFolder ); @@ -661,8 +663,8 @@ void AppConfig::loadProject( std::string projectFolder, UICodeEditorSplitter* ed app->getProjectBuildManager()->setConfig( prjCfg ); } - std::vector autoSaveFiles; - if ( autoSave ) { + std::vector sessionSnapshotFiles; + if ( sessionSnapshot ) { std::string projectStatePath( projectsPath + "state" + FileSystem::getOSSlash() + hash.toHexString() + FileSystem::getOSSlash() + "state.json" ); @@ -674,16 +676,16 @@ void AppConfig::loadProject( std::string projectFolder, UICodeEditorSplitter* ed j = json::parse( stateStr ); if ( !j.is_discarded() && j.is_array() ) { for ( const auto& jobj : j ) { - AutoSaveFile autoSaveFile; - autoSaveFile.cachePath = jobj.value( "cachepath", "" ); - if ( autoSaveFile.cachePath.empty() ) + SessionSnapshotFile snapshotFile; + snapshotFile.cachePath = jobj.value( "cachepath", "" ); + if ( snapshotFile.cachePath.empty() ) continue; - autoSaveFile.fspath = jobj.value( "fspath", "" ); - autoSaveFile.fsmtime = jobj.value( "fsmtime", 0 ); - autoSaveFile.fshash = jobj.value( "fshash", "" ); - autoSaveFile.name = jobj.value( "name", "" ); - autoSaveFile.selection = jobj.value( "selection", "" ); - autoSaveFiles.emplace_back( std::move( autoSaveFile ) ); + snapshotFile.fspath = jobj.value( "fspath", "" ); + snapshotFile.fsmtime = jobj.value( "fsmtime", 0 ); + snapshotFile.fshash = jobj.value( "fshash", "" ); + snapshotFile.name = jobj.value( "name", "" ); + snapshotFile.selection = jobj.value( "selection", "" ); + sessionSnapshotFiles.emplace_back( std::move( snapshotFile ) ); } } } catch ( const json::exception& e ) { @@ -704,22 +706,22 @@ void AppConfig::loadProject( std::string projectFolder, UICodeEditorSplitter* ed } if ( !j.is_discarded() ) { editorsToLoad = countTotalEditors( j ); - loadDocuments( editorSplitter, j, curTabWidget, app, autoSaveFiles ); + loadDocuments( editorSplitter, j, curTabWidget, app, sessionSnapshotFiles ); } } - for ( const auto& autoSaveFile : autoSaveFiles ) { - if ( !autoSaveFile.fspath.empty() || autoSaveFile.name.empty() || - autoSaveFile.cachePath.empty() ) + for ( const auto& snapshotFile : sessionSnapshotFiles ) { + if ( !snapshotFile.fspath.empty() || snapshotFile.name.empty() || + snapshotFile.cachePath.empty() ) continue; editorSplitter->loadAsyncFileFromPathInNewTab( - autoSaveFile.cachePath, - [autoSaveFile]( UICodeEditor* editor, const std::string& ) { + snapshotFile.cachePath, + [snapshotFile]( UICodeEditor* editor, const std::string& ) { TextDocument& doc = editor->getDocument(); - auto selection = TextRange::fromString( autoSaveFile.selection ); - doc.setDefaultFileName( autoSaveFile.name ); - doc.changeFilePath( autoSaveFile.name ); + auto selection = TextRange::fromString( snapshotFile.selection ); + doc.setDefaultFileName( snapshotFile.name ); + doc.changeFilePath( snapshotFile.name ); doc.setDirtyUntilSave(); doc.setSelection( selection ); doc.resetUndoRedo(); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index c68dae823..fb3b21ee4 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -165,14 +165,14 @@ struct TerminalConfig { struct WorkspaceConfig { bool restoreLastSession{ false }; bool checkForUpdatesAtStartup{ true }; - bool autoSave{ true }; + bool sessionSnapshot{ true }; }; struct LanguagesExtensions { std::map priorities; }; -struct AutoSaveFile { +struct SessionSnapshotFile { std::string cachePath; std::string fspath; Uint64 fsmtime{ 0 }; @@ -213,17 +213,18 @@ class AppConfig { void saveProject( std::string projectFolder, UICodeEditorSplitter* editorSplitter, const std::string& configPath, const ProjectDocumentConfig& docConfig, const ProjectBuildConfiguration& buildConfig, bool onlyIfNeeded, - bool autoSave ); + bool sessionSnapshot ); void loadProject( std::string projectFolder, UICodeEditorSplitter* editorSplitter, const std::string& configPath, ProjectDocumentConfig& docConfig, - ecode::App* app, bool autoSave ); + ecode::App* app, bool sessionSnapshot ); protected: Int64 editorsToLoad{ 0 }; void loadDocuments( UICodeEditorSplitter* editorSplitter, json j, UITabWidget* curTabWidget, - ecode::App* app, const std::vector& autoSaveFiles ); + ecode::App* app, + const std::vector& sessionSnapshotFiles ); void editorLoadedCounter( ecode::App* app ); }; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 476e9c50a..218486c0c 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -54,7 +54,7 @@ void appLoop() { } bool App::onCloseRequestCallback( EE::Window::Window* ) { - if ( mSplitter->isAnyEditorDirty() && !mConfig.workspace.autoSave ) { + if ( mSplitter->isAnyEditorDirty() && !mConfig.workspace.sessionSnapshot ) { if ( mCloseMsgBox ) return false; mCloseMsgBox = UIMessageBox::New( @@ -2209,12 +2209,12 @@ bool App::isUnlockedCommand( const std::string& command ) { return std::find( cmds.begin(), cmds.end(), command ) != cmds.end(); } -void App::saveProject( bool onlyIfNeeded, bool autoSaveEnabled ) { +void App::saveProject( bool onlyIfNeeded, bool sessionSnapshotEnabled ) { if ( !mCurrentProject.empty() ) { - mConfig.saveProject( mCurrentProject, mSplitter, mConfigPath, mProjectDocConfig, - mProjectBuildManager ? mProjectBuildManager->getConfig() - : ProjectBuildConfiguration(), - onlyIfNeeded, autoSaveEnabled && mConfig.workspace.autoSave ); + mConfig.saveProject( + mCurrentProject, mSplitter, mConfigPath, mProjectDocConfig, + mProjectBuildManager ? mProjectBuildManager->getConfig() : ProjectBuildConfiguration(), + onlyIfNeeded, sessionSnapshotEnabled && mConfig.workspace.sessionSnapshot ); } } @@ -2273,7 +2273,7 @@ void App::closeFolder() { if ( mProjectBuildManager ) mProjectBuildManager.reset(); - if ( mSplitter->isAnyEditorDirty() && !mConfig.workspace.autoSave ) { + if ( mSplitter->isAnyEditorDirty() && !mConfig.workspace.sessionSnapshot ) { UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, i18n( "confirm_close_folder", @@ -3237,7 +3237,7 @@ 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 ) + if ( mConfig.workspace.sessionSnapshot && !openClean ) loadFolder( getPlaygroundPath() ); updateOpenRecentFolderBtn(); @@ -3367,7 +3367,7 @@ void App::loadFolder( const std::string& path ) { mProjectBuildManager = std::make_unique( rpath, mThreadPool, mSidePanel, this ); mConfig.loadProject( rpath, mSplitter, mConfigPath, mProjectDocConfig, this, - mConfig.workspace.autoSave ); + mConfig.workspace.sessionSnapshot ); Log::info( "Load project took: %.2f ms", projClock.getElapsedTime().asMilliseconds() ); loadFileSystemMatcher( rpath ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 5a37b925a..254b0870d 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -457,7 +457,7 @@ class App : public UICodeEditorSplitter::Client { const std::string& getFileToOpen() const; - void saveProject( bool onlyIfNeeded = false, bool autoSaveEnabled = true ); + void saveProject( bool onlyIfNeeded = false, bool sessionSnapshotEnabled = true ); std::pair generateConfigPath(); diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 5ea1432c1..43d8dd791 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -641,14 +641,14 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->setId( "autoreload_on_disk_change" ); mGlobalMenu - ->addCheckBox( i18n( "auto_save_documents", "Auto-Save Open Documents" ), - mApp->getConfig().workspace.autoSave ) + ->addCheckBox( i18n( "session_snapshot", "Session Snapshot & Periodic Backup" ), + mApp->getConfig().workspace.sessionSnapshot ) ->setTooltipText( - i18n( "auto_save_documents_desc", - "When auto-save open documents is enabled the editor will keep\n" + i18n( "session_snapshot_desc", + "When session snapshot is enabled the editor will keep\n" "the document buffer changes between sessions, even if they are not saved\n" "before exiting the program." ) ) - ->setId( "auto_save_documents" ); + ->setId( "session_snapshot" ); mGlobalMenu->addSeparator(); @@ -678,8 +678,8 @@ UIMenu* SettingsMenu::createDocumentMenu() { mApp->getConfig().doc.autoDetectIndentType = item->isActive(); } else if ( "autoreload_on_disk_change" == id ) { mApp->getConfig().editor.autoReloadOnDiskChange = item->isActive(); - } else if ( "auto_save_documents" == id ) { - mApp->getConfig().workspace.autoSave = item->isActive(); + } else if ( "session_snapshot" == id ) { + mApp->getConfig().workspace.sessionSnapshot = item->isActive(); } } else if ( "line_breaking_column" == id ) { mApp->setLineBreakingColumn();