From bbd7b354ac93654bb5d03eb814cf2e4850280fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 14 Jan 2023 13:33:33 -0300 Subject: [PATCH] Closes SpartanJ/ecode#6. Added support to restore the last session at startup. --- src/tools/ecode/appconfig.cpp | 4 ++++ src/tools/ecode/appconfig.hpp | 5 +++++ src/tools/ecode/ecode.cpp | 17 +++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index dcd538215..ef77cacf3 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -123,6 +123,8 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, term.fontSize = ini.getValue( "terminal", "font_size", "11dp" ); term.colorScheme = ini.getValue( "terminal", "colorscheme", "eterm" ); + workspace.restoreLastSession = ini.getValueB( "workspace", "restore_last_session", false ); + std::map pluginsEnabled; const auto& creators = pluginManager->getDefinitions(); for ( const auto& creator : creators ) @@ -226,6 +228,8 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValueI( "window", "multisamples", context.Multisamples ); ini.setValueI( "window", "frameratelimit", context.FrameRateLimit ); + ini.setValueB( "workspace", "restore_last_session", workspace.restoreLastSession ); + const auto& pluginsEnabled = pluginManager->getPluginsEnabled(); for ( const auto& plugin : pluginsEnabled ) ini.setValueB( "plugins", plugin.first, plugin.second ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index 58ee99715..105bb6909 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -104,6 +104,10 @@ struct TerminalConfig { StyleSheetLength fontSize{ 11, StyleSheetLength::Dp }; }; +struct WorkspaceConfig { + bool restoreLastSession{ false }; +}; + struct AppConfig { WindowStateConfig windowState; ContextSettings context; @@ -117,6 +121,7 @@ struct AppConfig { FileInfo iniInfo; SearchBarConfig searchBarConfig; GlobalSearchBarConfig globalSearchBarConfig; + WorkspaceConfig workspace; void load( const std::string& confPath, std::string& keybindingsPath, std::string& initColorScheme, std::vector& recentFiles, diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 80f6874ce..865fc5baf 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -595,16 +595,23 @@ void App::updateRecentFolders() { menu->add( file ); menu->addSeparator(); menu->add( i18n( "clear_menu", "Clear Menu" ) )->setId( "clear-menu" ); + menu->addCheckBox( + i18n( "restore_last_session_at_startup", "Restart last session at startup" ) ) + ->setActive( mConfig.workspace.restoreLastSession ) + ->setId( "restore-last-session-at-startup" ); menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; const std::string& id = event->getNode()->asType()->getId(); - if ( id != "clear-menu" ) { - const String& txt = event->getNode()->asType()->getText(); - loadFolder( txt ); - } else { + if ( id == "clear-menu" ) { mRecentFolders.clear(); updateRecentFolders(); + } else if ( id == "restore-last-session-at-startup" ) { + mConfig.workspace.restoreLastSession = + event->getNode()->asType()->isActive(); + } else { + const String& txt = event->getNode()->asType()->getText(); + loadFolder( txt ); } } ); } @@ -3397,6 +3404,8 @@ void App::initProjectTreeView( const std::string& path ) { } } } + } else if ( mConfig.workspace.restoreLastSession && !mRecentFolders.empty() ) { + loadFolder( mRecentFolders[0] ); } else if ( !mIsBundledApp ) { loadFolder( "." ); }