[gnome-commander/ConfigurableFileListColumns: 6/9] Implement new gsettings array for storing file list column layout



commit 2fe4bea56f2dedbd45010917c93b1de6ddc53828
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Fri May 3 22:40:03 2019 +0200

    Implement new gsettings array for storing file list column layout

 data/org.gnome.gnome-commander.gschema.xml |  9 ++++++
 src/gnome-cmd-data.cc                      | 52 ++++++++++++++++++++++++++++++
 src/gnome-cmd-data.h                       | 17 ++++++++++
 src/gnome-cmd-file-selector.h              |  2 +-
 src/gnome-cmd-main-win.cc                  |  1 +
 5 files changed, 80 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.gnome-commander.gschema.xml b/data/org.gnome.gnome-commander.gschema.xml
index 92cb79ab..ed817551 100644
--- a/data/org.gnome.gnome-commander.gschema.xml
+++ b/data/org.gnome.gnome-commander.gschema.xml
@@ -296,6 +296,14 @@
           This setting defines the height of the options dialog window.
       </description>
     </key>
+    <key name="file-list-columns" type="a(uub)">
+      <!-- column id, column width, visibility -->
+      
<default>[(0,16,true),(1,140,true),(2,40,true),(3,240,false),(4,70,true),(5,150,true),(6,70,true),(7,50,true),(8,50,true)]</default>
+      <summary>Columns in the main window tabs</summary>
+      <description>
+          This list defines the width and the visibility of the main window tab columns.
+      </description>
+    </key>
     <key name="column-width-icon" type="u">
       <default>16</default>
       <summary>Width of icon column</summary>
@@ -495,6 +503,7 @@
     </key>
     <key name="file-list-tabs" type="a(syybb)">
       <default>[]</default>
+      <!-- realPath, fileSelectorId, sort_column, sort_order, locked -->
       <summary>List of file tabs</summary>
       <description>
           The entries in this list are used for restoring the tabs from the last session.
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index aafd38b9..a6bfcfa6 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1577,6 +1577,27 @@ void GnomeCmdData::save_bookmarks()
 }
 
 
+void GnomeCmdData::save_file_list_columns()
+{
+    GVariantBuilder* gVariantBuilder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+    g_variant_builder_init (gVariantBuilder, G_VARIANT_TYPE_ARRAY);
+
+    for (int ii = GnomeCmdFileList::COLUMN_ICON; ii < GnomeCmdFileList::NUM_COLUMNS; ii++)
+    {
+        g_variant_builder_add (gVariantBuilder, GCMD_SETTINGS_FILE_LIST_COLUMN_FORMAT_STRING,
+                               fileListColumnLayouts[ii].position,
+                               fileListColumnLayouts[ii].width,
+                               fileListColumnLayouts[ii].visibility
+                              );
+    }
+
+    GVariant* fileListColumnsToStore = g_variant_builder_end (gVariantBuilder);
+    g_settings_set_value(options.gcmd_settings->general, GCMD_SETTINGS_FILE_LIST_COLUMNS, 
fileListColumnsToStore);
+
+    g_variant_builder_unref(gVariantBuilder);
+}
+
+
 gboolean GnomeCmdData::add_bookmark_to_gvariant_builder(GVariantBuilder *gVariantBuilder, std::string 
bookmarkGroupName, GnomeCmdCon *con)
 {
     if (!con)
@@ -2229,6 +2250,35 @@ void GnomeCmdData::load_bookmarks()
 }
 
 
+void GnomeCmdData::load_file_list_columns()
+{
+    auto *gVariantFileListColumns = g_settings_get_value (options.gcmd_settings->general, 
GCMD_SETTINGS_FILE_LIST_COLUMNS);
+
+    g_autoptr(GVariantIter) iter1 {nullptr};
+
+    g_variant_get (gVariantFileListColumns, GCMD_SETTINGS_FILE_LIST_COLUMNS_FORMAT_STRING, &iter1);
+
+    guint position {0};
+    guint width {0};
+    gboolean visible {true};
+    guint counter {0};
+
+    while (g_variant_iter_loop (iter1,
+            GCMD_SETTINGS_FILE_LIST_COLUMN_FORMAT_STRING,
+            &position,
+            &width,
+            &visible))
+    {
+        fileListColumnLayouts[counter].position = position;
+        fileListColumnLayouts[counter].width = width;
+        fileListColumnLayouts[counter].visibility = visible;
+        counter++;
+    }
+
+    g_variant_unref(gVariantFileListColumns);
+}
+
+
 /**
  * This method reads the gsettings section of the advance rename tool
  */
@@ -3413,6 +3463,7 @@ void GnomeCmdData::load()
     load_keybindings        ();
     load_fav_apps           ();
     load_directory_history  ();
+    load_file_list_columns  ();
 
     priv->con_list->unlock();
 
@@ -3588,6 +3639,7 @@ void GnomeCmdData::save()
     save_advrename_profiles         ();
     save_intviewer_defaults         ();
     save_auto_load_plugins          ();
+    save_file_list_columns          ();
 
     g_settings_sync ();
 }
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 54babdb7..76cca3c3 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -120,6 +120,9 @@ GcmdSettings *gcmd_settings_new (void);
 #define GCMD_SETTINGS_ADVRENAME_PROFILES_FORMAT_STRING "a(ssuiuuuasasab)"
 #define GCMD_SETTINGS_FILE_LIST_TABS                  "file-list-tabs"
 #define GCMD_SETTINGS_FILE_LIST_TAB_FORMAT_STRING     "(syybb)"
+#define GCMD_SETTINGS_FILE_LIST_COLUMNS               "file-list-columns"
+#define GCMD_SETTINGS_FILE_LIST_COLUMN_FORMAT_STRING  "(uub)"
+#define GCMD_SETTINGS_FILE_LIST_COLUMNS_FORMAT_STRING "a(uub)"
 #define GCMD_SETTINGS_DEVICES                         "devices"
 #define GCMD_SETTINGS_DEVICES_FORMAT_STRING           "(ssss)"
 #define GCMD_SETTINGS_FAV_APPS                        "favorite-apps"
@@ -600,6 +603,17 @@ struct GnomeCmdData
         gint width {400}, height {250};
     };
 
+    /**
+     * This struct holds information about the position, width and
+     * visibility of a column in the file lists.
+     */
+    struct FileListColumnLayout
+    {
+        guint position;
+        guint width;
+        gboolean visibility;
+    };
+
     typedef std::pair<std::string,triple<GnomeCmdFileList::ColumnID,GtkSortType,gboolean> > Tab;
 
     static GSettingsSchemaSource* GetGlobalSchemaSource();
@@ -658,6 +672,7 @@ struct GnomeCmdData
 
     guint                        dev_icon_size {16};
     guint                        fs_col_width[GnomeCmdFileList::NUM_COLUMNS];
+    FileListColumnLayout         fileListColumnLayouts[GnomeCmdFileList::NUM_COLUMNS];
     guint                        gui_update_rate;
 
     GList                       *cmdline_history;
@@ -696,6 +711,8 @@ struct GnomeCmdData
     void save_search_profiles ();
     void save_bookmarks();
     void load_bookmarks();
+    void load_file_list_columns ();
+    void save_file_list_columns ();
     void save();
     gboolean gnome_cmd_data_parse_color (const gchar *spec, GdkColor *color);
     gboolean set_color_if_valid_key_value(GdkColor *color, GSettings *settings, const char *key);
diff --git a/src/gnome-cmd-file-selector.h b/src/gnome-cmd-file-selector.h
index 42791116..58f395ef 100644
--- a/src/gnome-cmd-file-selector.h
+++ b/src/gnome-cmd-file-selector.h
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file gnome-cmd-file-selector.h
  * @copyright (C) 2001-2006 Marcus Bjurman\n
  * @copyright (C) 2007-2012 Piotr Eljasiak\n
diff --git a/src/gnome-cmd-main-win.cc b/src/gnome-cmd-main-win.cc
index e6d891f3..1bd2c60d 100644
--- a/src/gnome-cmd-main-win.cc
+++ b/src/gnome-cmd-main-win.cc
@@ -539,6 +539,7 @@ static void on_fs_list_resize_column (GtkCList *clist, gint column, gint width,
     {
         column_resize_lock = TRUE;
         gnome_cmd_data.fs_col_width[column] = width;
+        gnome_cmd_data.fileListColumnLayouts[column].width = width;
         gtk_clist_set_column_width (other_clist, column, width);
         column_resize_lock = FALSE;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]