Remember keywords layout
[geeqie.git] / src / bar_keywords.c
index 0eee90c..febed42 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <glib/gprintf.h>
@@ -238,20 +247,69 @@ void bar_pane_keywords_set_fd(GtkWidget *pane, FileData *fd)
        bar_pane_keywords_update(pkd);
 }
 
+void bar_keyword_tree_get_expanded_cb(GtkTreeView *keyword_treeview, GtkTreePath *path,  gpointer data)
+{
+       GList **expanded = data;
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       gchar *path_string;
+
+       model = gtk_tree_view_get_model(GTK_TREE_VIEW(keyword_treeview));
+       gtk_tree_model_get_iter(model, &iter, path);
+
+       path_string = gtk_tree_model_get_string_from_iter(model, &iter);
+
+       *expanded = g_list_append(*expanded, g_strdup(path_string));
+       g_free(path_string);
+}
+
+static void bar_pane_keywords_entry_write_config(gchar *entry, GString *outstr, gint indent)
+{
+       struct {
+               gchar *path;
+       } expand;
+
+       expand.path = entry;
+
+       WRITE_NL(); WRITE_STRING("<expanded ");
+       WRITE_CHAR(expand, path);
+       WRITE_STRING("/>");
+}
+
 static void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gint indent)
 {
        PaneKeywordsData *pkd;
+       GList *path_expanded = NULL;
 
        pkd = g_object_get_data(G_OBJECT(pane), "pane_data");
        if (!pkd) return;
 
+       pkd->height = options->info_keywords.height;
+
        WRITE_NL(); WRITE_STRING("<pane_keywords ");
        write_char_option(outstr, indent, "id", pkd->pane.id);
        write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pkd->pane.title)));
        WRITE_BOOL(pkd->pane, expanded);
        WRITE_CHAR(*pkd, key);
        WRITE_INT(*pkd, height);
-       WRITE_STRING("/>");
+       WRITE_STRING(">");
+       indent++;
+
+       gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
+                                                               (bar_keyword_tree_get_expanded_cb), &path_expanded);
+
+       g_list_first(path_expanded);
+       while (path_expanded)
+               {
+               bar_pane_keywords_entry_write_config(path_expanded->data, outstr, indent);
+               g_free(path_expanded->data);
+               path_expanded = path_expanded->next;
+               }
+       g_list_free(path_expanded);
+
+       indent--;
+       WRITE_NL();
+       WRITE_STRING("</pane_keywords>");
 }
 
 gint bar_pane_keywords_event(GtkWidget *bar, GdkEvent *event)
@@ -872,14 +930,14 @@ static void bar_pane_keywords_edit_dialog(PaneKeywordsData *pkd, gboolean edit_e
        pkd->click_tpath = NULL;
        cdd->edit_existing = edit_existing;
 
-       cdd->gd = gd = generic_dialog_new(name ? _("Edit keyword") : _("Add keywords"), "keyword_edit",
+       cdd->gd = gd = generic_dialog_new(name ? _("Edit keyword") : _("New keyword"), "keyword_edit",
                                pkd->widget, TRUE,
                                bar_pane_keywords_edit_cancel_cb, cdd);
        g_signal_connect(G_OBJECT(gd->dialog), "destroy",
                         G_CALLBACK(bar_pane_keywords_edit_destroy_cb), cdd);
 
 
-       generic_dialog_add_message(gd, NULL, name ? _("Configure keyword") : _("Add keyword"), NULL);
+       generic_dialog_add_message(gd, NULL, name ? _("Configure keyword") : _("New keyword"), NULL);
 
        generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
                                  bar_pane_keywords_edit_ok_cb, TRUE);
@@ -1140,7 +1198,7 @@ static void bar_pane_keywords_menu_popup(GtkWidget *widget, PaneKeywordsData *pk
 
        menu = popup_menu_short_lived();
 
-       menu_item_add_stock(menu, _("Add keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd);
+       menu_item_add_stock(menu, _("New keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd);
 
        menu_item_add_divider(menu);
 
@@ -1439,6 +1497,7 @@ GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, cons
                log_printf("unknown attribute %s = %s\n", option, value);
                }
 
+       options->info_keywords.height = height;
        bar_pane_translate_title(PANE_KEYWORDS, id, &title);
        ret = bar_pane_keywords_new(id, title, key, expanded, height);
        g_free(id);
@@ -1482,4 +1541,27 @@ void bar_pane_keywords_update_from_config(GtkWidget *pane, const gchar **attribu
 }
 
 
+void bar_pane_keywords_entry_add_from_config(GtkWidget *pane, const gchar **attribute_names, const gchar **attribute_values)
+{
+       PaneKeywordsData *pkd;
+       gchar *path = NULL;
+       GtkTreePath *tree_path;
+
+       pkd = g_object_get_data(G_OBJECT(pane), "pane_data");
+       if (!pkd) return;
+
+       while (*attribute_names)
+               {
+               const gchar *option = *attribute_names++;
+               const gchar *value = *attribute_values++;
+
+               if (READ_CHAR_FULL("path", path))
+                       {
+                       tree_path = gtk_tree_path_new_from_string(path);
+                       gtk_tree_view_expand_to_path(GTK_TREE_VIEW(pkd->keyword_treeview), tree_path);
+                       continue;
+                       }
+               log_printf("unknown attribute %s = %s\n", option, value);
+               }
+}
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */