/*
- * 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>
guint idle_id; /* event source id */
FileData *fd;
gchar *key;
+ gint height;
+
+ GList *expanded_rows;
};
typedef struct _ConfDialogData ConfDialogData;
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_STRING("/>");
+ WRITE_INT(*pkd, height);
+ 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)
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);
GtkTreeModel *keyword_tree;
+ string_list_free(pkd->expanded_rows);
+ pkd->expanded_rows = NULL;
+ gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
+ (bar_keyword_tree_get_expanded_cb), &pkd->expanded_rows);
+
pkd->hide_unchecked = FALSE;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
bar_keyword_tree_sync(pkd);
}
+static void bar_pane_keywords_revert_cb(GtkWidget *menu_widget, gpointer data)
+{
+ PaneKeywordsData *pkd = data;
+ GList *work;
+ GtkTreePath *tree_path;
+ gchar *path;
+
+ gtk_tree_view_collapse_all(GTK_TREE_VIEW(pkd->keyword_treeview));
+
+ work = pkd->expanded_rows;
+ while (work)
+ {
+ path = work->data;
+ tree_path = gtk_tree_path_new_from_string(path);
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(pkd->keyword_treeview), tree_path);
+ work = work->next;
+ gtk_tree_path_free(tree_path);
+ }
+
+ bar_keyword_tree_sync(pkd);
+}
+
static void bar_pane_keywords_expand_checked_cb(GtkWidget *menu_widget, gpointer data)
{
PaneKeywordsData *pkd = data;
gtk_tree_model_foreach(model, bar_keyword_tree_expand_if_set_cb, pkd);
}
+static void bar_pane_keywords_collapse_all_cb(GtkWidget *menu_widget, gpointer data)
+{
+ PaneKeywordsData *pkd = data;
+
+ string_list_free(pkd->expanded_rows);
+ pkd->expanded_rows = NULL;
+ gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(pkd->keyword_treeview),
+ (bar_keyword_tree_get_expanded_cb), &pkd->expanded_rows);
+
+ gtk_tree_view_collapse_all(GTK_TREE_VIEW(pkd->keyword_treeview));
+
+ bar_keyword_tree_sync(pkd);
+}
+
+static void bar_pane_keywords_revert_hidden_cb(GtkWidget *menu_widget, gpointer data)
+{
+ PaneKeywordsData *pkd = data;
+ GtkTreeModel *model;
+ GtkTreeModel *keyword_tree;
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));
+ keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));
+
+ keyword_revert_hidden_in(GTK_TREE_STORE(keyword_tree), model);
+
+ bar_keyword_tree_sync(pkd);
+}
+
static void bar_pane_keywords_collapse_unchecked_cb(GtkWidget *menu_widget, gpointer data)
{
PaneKeywordsData *pkd = data;
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);
menu_item_add(menu, _("Expand checked"), G_CALLBACK(bar_pane_keywords_expand_checked_cb), pkd);
menu_item_add(menu, _("Collapse unchecked"), G_CALLBACK(bar_pane_keywords_collapse_unchecked_cb), pkd);
menu_item_add(menu, _("Hide unchecked"), G_CALLBACK(bar_pane_keywords_hide_unchecked_cb), pkd);
+ menu_item_add(menu, _("Revert all hidden"), G_CALLBACK(bar_pane_keywords_revert_hidden_cb), pkd);
+ menu_item_add_divider(menu);
menu_item_add(menu, _("Show all"), G_CALLBACK(bar_pane_keywords_show_all_cb), pkd);
+ menu_item_add(menu, _("Collapse all"), G_CALLBACK(bar_pane_keywords_collapse_all_cb), pkd);
+ menu_item_add(menu, _("Revert"), G_CALLBACK(bar_pane_keywords_revert_cb), pkd);
+ menu_item_add_divider(menu);
submenu = gtk_menu_new();
item = menu_item_add(menu, _("On any change"), NULL, NULL);
{
PaneKeywordsData *pkd = data;
- if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);
+ string_list_free(pkd->expanded_rows);
+ if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);
if (pkd->idle_id) g_source_remove(pkd->idle_id);
file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd);
}
-static GtkWidget *bar_pane_keywords_new(const gchar *id, const gchar *title, const gchar *key, gboolean expanded)
+static GtkWidget *bar_pane_keywords_new(const gchar *id, const gchar *title, const gchar *key, gboolean expanded, gint height)
{
PaneKeywordsData *pkd;
GtkWidget *hbox;
pkd->pane.expanded = expanded;
+ pkd->height = height;
pkd->key = g_strdup(key);
pkd->expand_checked = TRUE;
+ pkd->expanded_rows = NULL;
hbox = gtk_hbox_new(FALSE, PREF_PAD_GAP);
g_object_set_data(G_OBJECT(pkd->widget), "pane_data", pkd);
g_signal_connect(G_OBJECT(pkd->widget), "destroy",
G_CALLBACK(bar_pane_keywords_destroy), pkd);
+ gtk_widget_set_size_request(pkd->widget, -1, height);
gtk_widget_show(hbox);
scrolled = gtk_scrolled_window_new(NULL, NULL);
gchar *title = NULL;
gchar *key = g_strdup(COMMENT_KEY);
gboolean expanded = TRUE;
+ gint height = 200;
GtkWidget *ret;
while (*attribute_names)
if (READ_CHAR_FULL("title", title)) continue;
if (READ_CHAR_FULL("key", key)) continue;
if (READ_BOOL_FULL("expanded", expanded)) continue;
+ if (READ_INT_FULL("height", height)) continue;
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);
+ ret = bar_pane_keywords_new(id, title, key, expanded, height);
g_free(id);
g_free(title);
g_free(key);
}
+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);
+ gtk_tree_path_free(tree_path);
+ pkd->expanded_rows = g_list_append(pkd->expanded_rows, g_strdup(path));
+ continue;
+ }
+ log_printf("unknown attribute %s = %s\n", option, value);
+ }
+}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */