Skip to content

Commit

Permalink
added option 'recent_docs' in config.cfg to be set to false in order …
Browse files Browse the repository at this point in the history
…to not remember the recent documents (#2330)
  • Loading branch information
giuspen committed Aug 18, 2023
1 parent 9470744 commit 5b212fd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 26 deletions.
25 changes: 23 additions & 2 deletions src/ct/ct_actions_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 24 additions & 21 deletions src/ct/ct_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ct/ct_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
3 changes: 3 additions & 0 deletions src/ct/ct_main_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<void, const std::string&> recent_doc_open_action = [&](const std::string& filepath){
if (Glib::file_test(filepath, Glib::FILE_TEST_EXISTS)) {
if (file_open(filepath, ""/*node*/, ""/*anchor*/)) {
Expand Down
8 changes: 6 additions & 2 deletions src/ct/ct_pref_dlg_misc.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_pref_dlg_misc.cc
*
* Copyright 2009-2022
* Copyright 2009-2023
* Giuseppe Penone <giuspen@gmail.com>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 5b212fd

Please sign in to comment.