[gnome-commander/get_rid_of_xml] Store open file list tabs in GKeyfile
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/get_rid_of_xml] Store open file list tabs in GKeyfile
- Date: Wed, 26 Sep 2018 07:50:04 +0000 (UTC)
commit 398ddd2db488cc3711125591f423a3fe571001b8
Author: Uwe Scholz <u scholz83 gmx de>
Date: Wed Sep 26 09:17:59 2018 +0200
Store open file list tabs in GKeyfile
src/gnome-cmd-data.cc | 88 ++++++++++++++++++++++++++++++++++++++++++
src/gnome-cmd-data.h | 6 +++
src/gnome-cmd-file-selector.cc | 8 ++++
src/gnome-cmd-file-selector.h | 2 +
4 files changed, 104 insertions(+)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index cf83f179..3c89878e 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1746,6 +1746,91 @@ void GnomeCmdData::save_advrename_profiles (const gchar *fname)
g_free (path);
}
+
+/**
+ * Save tabs of a FileSelectorID in a given GKeyFile
+ */
+static void safe_tabs(GKeyFile* keyFile, enum FileSelectorID side)
+{
+ static gint counter = 1;
+
+ bool left = true;
+ if (side == LEFT)
+ left = true;
+ else if (side == RIGHT)
+ left = RIGHT;
+
+ GnomeCmdFileSelector gnomeCmdFileSelector = *main_win->fs(side);
+ GList *tabs = gnomeCmdFileSelector.GetTabs();
+
+ for (GList *i=tabs; i; i=i->next)
+ {
+ string alias = to_string(counter);
+ if (gnome_cmd_data.options.save_tabs_on_exit)
+ {
+ GnomeCmdFileList *fl = (GnomeCmdFileList *) gtk_bin_get_child (GTK_BIN (i->data));
+ if (GNOME_CMD_FILE_LIST (fl) && gnome_cmd_con_is_local (fl->con))
+ {
+ g_key_file_set_string(keyFile, alias.c_str(), TAB_PATH, GNOME_CMD_FILE
(fl->cwd)->get_real_path());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_LEFT, left);
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_SORT, fl->get_sort_column());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_ASC, fl->get_sort_order());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_LOCK, fl->locked);
+ }
+ }
+ else
+ {
+ if (gnome_cmd_data.options.save_dirs_on_exit)
+ {
+ GnomeCmdFileList *fl = (GnomeCmdFileList *) gtk_bin_get_child (GTK_BIN (i->data));
+ if (GNOME_CMD_FILE_LIST (fl) && gnome_cmd_con_is_local (fl->con) &&
(fl==gnomeCmdFileSelector.file_list() || fl->locked))
+ {
+ g_key_file_set_string(keyFile, alias.c_str(), TAB_PATH, GNOME_CMD_FILE
(fl->cwd)->get_real_path());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_LEFT, left);
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_SORT, fl->get_sort_column());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_ASC, fl->get_sort_order());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_LOCK, fl->locked);
+ }
+ }
+ else
+ {
+ GnomeCmdFileList *fl = (GnomeCmdFileList *) gtk_bin_get_child (GTK_BIN (i->data));
+ if (GNOME_CMD_FILE_LIST (fl) && gnome_cmd_con_is_local (fl->con) && fl->locked)
+ {
+ g_key_file_set_string(keyFile, alias.c_str(), TAB_PATH, GNOME_CMD_FILE
(fl->cwd)->get_real_path());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_LEFT, left);
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_SORT, fl->get_sort_column());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_ASC, fl->get_sort_order());
+ g_key_file_set_boolean(keyFile, alias.c_str(), TAB_LOCK, fl->locked);
+ }
+ }
+ }
+ counter++;
+ }
+ g_list_free (tabs);
+}
+
+
+/**
+ * Save panes layout in the given file by means of GKeyFile.
+ */
+static void save_pane_layout(const gchar *fname)
+{
+ gchar *path = config_dir ?
+ g_build_filename (config_dir, fname, NULL) :
+ g_build_filename (g_get_home_dir (), "." PACKAGE, fname, NULL);
+ GKeyFile *keyFile;
+ keyFile = g_key_file_new ();
+
+ safe_tabs(keyFile, LEFT);
+ safe_tabs(keyFile, RIGHT);
+
+ gcmd_key_file_save_to_file (path, keyFile);
+ g_key_file_free(keyFile);
+ g_free (path);
+}
+
+
/**
* Save favourite applications in the given file by means of GKeyFile.
*/
@@ -3500,6 +3585,7 @@ void GnomeCmdData::load()
// Convert xml to keyfiles by using the save methods.
save_advrename_profiles(ADVRENAME_CONFIG_FILENAME);
+ save_pane_layout(TABS_LAYOUT_FILENAME);
// Move gnome-commander.xml to gnome-commander.xml.deprecated
gchar *xml_cfg_path_old = config_dir ? g_build_filename (config_dir, PACKAGE ".xml", NULL) :
g_build_filename (g_get_home_dir (), "." PACKAGE, PACKAGE ".xml", NULL);
@@ -3882,6 +3968,7 @@ void GnomeCmdData::save()
save_devices (DEVICES_FILENAME);
save_fav_apps (FAV_APPS_FILENAME);
save_advrename_profiles(ADVRENAME_CONFIG_FILENAME);
+ save_pane_layout(TABS_LAYOUT_FILENAME);
save_intviewer_defaults();
save_auto_load_plugins();
@@ -4248,3 +4335,4 @@ XML::xstream &operator << (XML::xstream &xml, GnomeCmdData::BookmarksConfig &cfg
return xml;
}
+
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 28e37c6a..ef3c2fa4 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -225,6 +225,12 @@ GcmdSettings *gcmd_settings_new (void);
#define FAV_APPS_HANDLES_URIS "handles_uris"
#define FAV_APPS_HANDLES_MULTIPLE "handles_multiple"
#define FAV_APPS_REQUIRES_TERMINAL "requires_terminal"
+#define TABS_LAYOUT_FILENAME "file-list-tabs"
+#define TAB_PATH "path"
+#define TAB_LEFT "left"
+#define TAB_SORT "sort"
+#define TAB_ASC "asc"
+#define TAB_LOCK "lock"
struct GnomeCmdConRemote;
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index 9241cc27..ecafb6c2 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -1633,3 +1633,11 @@ XML::xstream &operator << (XML::xstream &xml, GnomeCmdFileSelector &fs)
return xml;
}
+
+
+GList* GnomeCmdFileSelector::GetTabs()
+{
+ GList *tabs = gtk_container_get_children (*this->notebook);
+
+ return tabs;
+}
\ No newline at end of file
diff --git a/src/gnome-cmd-file-selector.h b/src/gnome-cmd-file-selector.h
index e5f113d5..254cd713 100644
--- a/src/gnome-cmd-file-selector.h
+++ b/src/gnome-cmd-file-selector.h
@@ -94,6 +94,7 @@ struct GnomeCmdFileSelector
void close_tab(gint n) { if (notebook->size()>1) notebook->remove_page(n); }
void update_tab_label(GnomeCmdFileList *fl);
+ GnomeCmdFileList get_gnome_cmd_file_list(GnomeCmdFileSelector &fs);
void show_filter();
void update_files();
@@ -110,6 +111,7 @@ struct GnomeCmdFileSelector
gboolean key_pressed(GdkEventKey *event);
friend XML::xstream &operator << (XML::xstream &xml, GnomeCmdFileSelector &fs);
+ GList* GetTabs();
};
inline GnomeCmdFileList *GnomeCmdFileSelector::file_list(gint n) const
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]