From 5b212fd0806d808af00ab4b3ff6e941fdb3b9758 Mon Sep 17 00:00:00 2001 From: Giuseppe Penone Date: Fri, 18 Aug 2023 21:00:35 +0100 Subject: [PATCH] added option 'recent_docs' in config.cfg to be set to false in order to not remember the recent documents (#2330) --- src/ct/ct_actions_file.cc | 25 +++++++++++++++++++-- src/ct/ct_config.cc | 45 ++++++++++++++++++++------------------ src/ct/ct_config.h | 2 +- src/ct/ct_main_win.cc | 3 +++ src/ct/ct_pref_dlg_misc.cc | 8 +++++-- 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/ct/ct_actions_file.cc b/src/ct/ct_actions_file.cc index d02947fa0..396ac0bfd 100644 --- a/src/ct/ct_actions_file.cc +++ b/src/ct/ct_actions_file.cc @@ -277,15 +277,36 @@ void CtActions::preferences_import() _pCtConfig->update_user_style(n); } _pCtConfig->toolbarUiList = ctConfigImported.toolbarUiList; - _pCtConfig->systrayOn = ctConfigImported.systrayOn; + if (ctConfigImported.systrayOn != _pCtConfig->systrayOn) { + // this we have to apply immediately because it affects the way the app quits + if (ctConfigImported.systrayOn) { + _pCtMainWin->get_status_icon()->set_visible(true); +#if defined(_WIN32) + _pCtConfig->systrayOn = true; // windows does support the systray +#else // !_WIN32 + _pCtConfig->systrayOn = CtDialogs::question_dialog(_("Has the System Tray appeared on the panel?"), *_pCtMainWin); +#endif // !_WIN32 + if (_pCtConfig->systrayOn) { + _pCtMainWin->signal_app_apply_for_each_window([](CtMainWin* win) { win->menu_set_visible_exit_app(true); }); + } + else { + CtDialogs::warning_dialog(_("Your system does not support the System Tray"), *_pCtMainWin); + } + } + else { + _pCtConfig->systrayOn = false; + _pCtMainWin->get_status_icon()->set_visible(false); + _pCtMainWin->signal_app_apply_for_each_window([](CtMainWin* win) { win->menu_set_visible_exit_app(false); }); + } + } _pCtConfig->startOnSystray = ctConfigImported.startOnSystray; - _pCtConfig->useAppInd = ctConfigImported.useAppInd; _pCtConfig->autosaveOn = ctConfigImported.autosaveOn; _pCtConfig->autosaveVal = ctConfigImported.autosaveVal; _pCtConfig->bookmarksInTopMenu = ctConfigImported.bookmarksInTopMenu; _pCtConfig->checkVersion = ctConfigImported.checkVersion; _pCtConfig->wordCountOn = ctConfigImported.wordCountOn; _pCtConfig->reloadDocLast = ctConfigImported.reloadDocLast; + _pCtConfig->rememberRecentDocs = ctConfigImported.rememberRecentDocs; _pCtConfig->winTitleShowDocDir = ctConfigImported.winTitleShowDocDir; _pCtConfig->nodeNameHeaderShowFullPath = ctConfigImported.nodeNameHeaderShowFullPath; _pCtConfig->modTimeSentinel = ctConfigImported.modTimeSentinel; diff --git a/src/ct/ct_config.cc b/src/ct/ct_config.cc index 9ccc41125..d9ef322f1 100644 --- a/src/ct/ct_config.cc +++ b/src/ct/ct_config.cc @@ -181,24 +181,27 @@ void CtConfig::_populate_keyfile_from_data() { // [state] _currentGroup = "state"; - guint i{0}; - for (const fs::path& filepath : recentDocsFilepaths) { - snprintf(_tempKey, _maxTempKeySize, "doc_%d", i); - _uKeyFile->set_string(_currentGroup, _tempKey, filepath.string()); - const CtRecentDocsRestore::iterator mapIt = recentDocsRestore.find(filepath.string()); - if (mapIt != recentDocsRestore.end()) { - snprintf(_tempKey, _maxTempKeySize, "visit_%d", i); - _uKeyFile->set_string(_currentGroup, _tempKey, mapIt->second.visited_nodes); - snprintf(_tempKey, _maxTempKeySize, "expcol_%d", i); - _uKeyFile->set_string(_currentGroup, _tempKey, mapIt->second.exp_coll_str); - snprintf(_tempKey, _maxTempKeySize, "nodep_%d", i); - _uKeyFile->set_string(_currentGroup, _tempKey, mapIt->second.node_path); - snprintf(_tempKey, _maxTempKeySize, "curs_%d", i); - _uKeyFile->set_integer(_currentGroup, _tempKey, mapIt->second.cursor_pos); - snprintf(_tempKey, _maxTempKeySize, "vscr_%d", i); - _uKeyFile->set_integer(_currentGroup, _tempKey, mapIt->second.v_adj_val); + if (rememberRecentDocs or reloadDocLast) { + guint i{0}; + for (const fs::path& filepath : recentDocsFilepaths) { + snprintf(_tempKey, _maxTempKeySize, "doc_%d", i); + _uKeyFile->set_string(_currentGroup, _tempKey, filepath.string()); + const CtRecentDocsRestore::iterator mapIt = recentDocsRestore.find(filepath.string()); + if (mapIt != recentDocsRestore.end()) { + snprintf(_tempKey, _maxTempKeySize, "visit_%d", i); + _uKeyFile->set_string(_currentGroup, _tempKey, mapIt->second.visited_nodes); + snprintf(_tempKey, _maxTempKeySize, "expcol_%d", i); + _uKeyFile->set_string(_currentGroup, _tempKey, mapIt->second.exp_coll_str); + snprintf(_tempKey, _maxTempKeySize, "nodep_%d", i); + _uKeyFile->set_string(_currentGroup, _tempKey, mapIt->second.node_path); + snprintf(_tempKey, _maxTempKeySize, "curs_%d", i); + _uKeyFile->set_integer(_currentGroup, _tempKey, mapIt->second.cursor_pos); + snprintf(_tempKey, _maxTempKeySize, "vscr_%d", i); + _uKeyFile->set_integer(_currentGroup, _tempKey, mapIt->second.v_adj_val); + } + if (not rememberRecentDocs) break; + ++i; } - ++i; } _uKeyFile->set_boolean(_currentGroup, "toolbar_visible", toolbarVisible); _uKeyFile->set_boolean(_currentGroup, "statusbar_visible", statusbarVisible); @@ -368,13 +371,13 @@ void CtConfig::_populate_keyfile_from_data() _uKeyFile->set_string(_currentGroup, "toolbar_ui_list", toolbarUiList); _uKeyFile->set_boolean(_currentGroup, "systray", systrayOn); _uKeyFile->set_boolean(_currentGroup, "start_on_systray", startOnSystray); - //_uKeyFile->set_boolean(_currentGroup, "use_appind", useAppInd); _uKeyFile->set_boolean(_currentGroup, "autosave_on", autosaveOn); _uKeyFile->set_integer(_currentGroup, "autosave_val", autosaveVal); _uKeyFile->set_boolean(_currentGroup, "bookm_top_menu", bookmarksInTopMenu); _uKeyFile->set_boolean(_currentGroup, "check_version", checkVersion); _uKeyFile->set_boolean(_currentGroup, "word_count", wordCountOn); _uKeyFile->set_boolean(_currentGroup, "reload_doc_last", reloadDocLast); + _uKeyFile->set_boolean(_currentGroup, "recent_docs", rememberRecentDocs); _uKeyFile->set_boolean(_currentGroup, "win_title_doc_dir", winTitleShowDocDir); _uKeyFile->set_boolean(_currentGroup, "nn_header_full_path", nodeNameHeaderShowFullPath); _uKeyFile->set_boolean(_currentGroup, "mod_time_sentinel", modTimeSentinel); @@ -682,9 +685,8 @@ void CtConfig::_populate_data_from_keyfile() _populate_string_from_keyfile("toolbar_ui_list", &toolbarUiList); _populate_bool_from_keyfile("systray", &systrayOn); _populate_bool_from_keyfile("start_on_systray", &startOnSystray); - _populate_bool_from_keyfile("use_appind", &useAppInd); - if (useAppInd) { - // if coming from pygtk2 version that supports appindicator which we currently do not + if (savedFromPyGtk) { + // if coming from pygtk2 version that supports appindicator which we currently do not, must re-enable systrayOn = false; startOnSystray = false; } @@ -694,6 +696,7 @@ void CtConfig::_populate_data_from_keyfile() _populate_bool_from_keyfile("check_version", &checkVersion); _populate_bool_from_keyfile("word_count", &wordCountOn); _populate_bool_from_keyfile("reload_doc_last", &reloadDocLast); + _populate_bool_from_keyfile("recent_docs", &rememberRecentDocs); _populate_bool_from_keyfile("win_title_doc_dir", &winTitleShowDocDir); _populate_bool_from_keyfile("nn_header_full_path", &nodeNameHeaderShowFullPath); _populate_bool_from_keyfile("mod_time_sentinel", &modTimeSentinel); diff --git a/src/ct/ct_config.h b/src/ct/ct_config.h index fd412f461..8b100cb11 100644 --- a/src/ct/ct_config.h +++ b/src/ct/ct_config.h @@ -219,12 +219,12 @@ class CtConfig bool bookmarksInTopMenu{true}; bool systrayOn{false}; bool startOnSystray{false}; - bool useAppInd{false}; bool autosaveOn{true}; int autosaveVal{1}; bool checkVersion{false}; bool wordCountOn{false}; bool reloadDocLast{true}; + bool rememberRecentDocs{true}; bool winTitleShowDocDir{true}; bool nodeNameHeaderShowFullPath{true}; bool modTimeSentinel{false}; diff --git a/src/ct/ct_main_win.cc b/src/ct/ct_main_win.cc index 4aed1a709..404470a15 100644 --- a/src/ct/ct_main_win.cc +++ b/src/ct/ct_main_win.cc @@ -557,6 +557,9 @@ void CtMainWin::menu_set_bookmark_menu_items() void CtMainWin::menu_set_items_recent_documents() { + if (not _pCtConfig->rememberRecentDocs) { + return; + } sigc::slot recent_doc_open_action = [&](const std::string& filepath){ if (Glib::file_test(filepath, Glib::FILE_TEST_EXISTS)) { if (file_open(filepath, ""/*node*/, ""/*anchor*/)) { diff --git a/src/ct/ct_pref_dlg_misc.cc b/src/ct/ct_pref_dlg_misc.cc index 669edc808..7e03e1ae6 100644 --- a/src/ct/ct_pref_dlg_misc.cc +++ b/src/ct/ct_pref_dlg_misc.cc @@ -1,7 +1,7 @@ /* * ct_pref_dlg_misc.cc * - * Copyright 2009-2022 + * Copyright 2009-2023 * Giuseppe Penone * Evgenii Gurianov * @@ -155,13 +155,17 @@ Gtk::Widget* CtPrefDlg::build_tab_misc() checkbutton_systray->signal_toggled().connect([this, checkbutton_systray, checkbutton_start_on_systray](){ if (checkbutton_systray->get_active()) { _pCtMainWin->get_status_icon()->set_visible(true); +#if defined(_WIN32) + _pConfig->systrayOn = true; // windows does support the systray +#else // !_WIN32 _pConfig->systrayOn = CtDialogs::question_dialog(_("Has the System Tray appeared on the panel?"), *this); +#endif // !_WIN32 if (_pConfig->systrayOn) { checkbutton_start_on_systray->set_sensitive(true); apply_for_each_window([](CtMainWin* win) { win->menu_set_visible_exit_app(true); }); } else { - CtDialogs::warning_dialog(_("Your system does not support the System Tray"), *_pCtMainWin); + CtDialogs::warning_dialog(_("Your system does not support the System Tray"), *this); checkbutton_systray->set_active(false); } }