# HG changeset patch
# User nadvornik
# Date 1238336444 0
# Node ID 9c16a93a0fdf8cb2dce19e8cfc1722e9338bf3b4
# Parent 7cb24fdf07c027c623e0acd2baf912d08e2048dd
improved sidebar configuration
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/bar.c
--- a/src/bar.c Sun Mar 29 10:36:13 2009 +0000
+++ b/src/bar.c Sun Mar 29 14:20:44 2009 +0000
@@ -36,17 +36,127 @@
PaneType type;
gchar *id;
gchar *title;
+ const gchar *config;
};
+static const gchar default_config_histogram[] =
+""
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_title[] =
+""
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_keywords[] =
+""
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_comment[] =
+""
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_exif[] =
+""
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_file_info[] =
+""
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_location[] =
+""
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+"";
+
+static const gchar default_config_copyright[] =
+""
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+" "
+"";
+
static const KnownPanes known_panes[] = {
/* default sidebar */
- {PANE_HISTOGRAM, "histogram", N_("Histogram")},
- {PANE_COMMENT, "title", N_("Title")},
- {PANE_KEYWORDS, "keywords", N_("Keywords")},
- {PANE_COMMENT, "comment", N_("Comment")},
- {PANE_EXIF, "exif", N_("Exif")},
+ {PANE_HISTOGRAM, "histogram", N_("Histogram"), default_config_histogram},
+ {PANE_COMMENT, "title", N_("Title"), default_config_title},
+ {PANE_KEYWORDS, "keywords", N_("Keywords"), default_config_keywords},
+ {PANE_COMMENT, "comment", N_("Comment"), default_config_comment},
+ {PANE_EXIF, "exif", N_("Exif"), default_config_exif},
+/* other pre-configured panes */
+ {PANE_EXIF, "file_info", N_("File info"), default_config_file_info},
+ {PANE_EXIF, "location", N_("Location"), default_config_location},
+ {PANE_EXIF, "copyright", N_("Copyright"), default_config_copyright},
- {PANE_UNDEF, NULL, NULL}
+ {PANE_UNDEF, NULL, NULL, NULL}
};
typedef struct _BarData BarData;
@@ -61,7 +171,7 @@
gint width;
};
-static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up)
+static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up, gboolean single_step)
{
GtkWidget *expander = data;
GtkWidget *box;
@@ -73,8 +183,15 @@
gtk_container_child_get(GTK_CONTAINER(box), expander, "position", &pos, NULL);
- pos = up ? (pos - 1) : (pos + 1);
- if (pos < 0) pos = 0;
+ if (single_step)
+ {
+ pos = up ? (pos - 1) : (pos + 1);
+ if (pos < 0) pos = 0;
+ }
+ else
+ {
+ pos = up ? 0 : -1;
+ }
gtk_box_reorder_child(GTK_BOX(box), expander, pos);
}
@@ -82,32 +199,105 @@
static void bar_expander_move_up_cb(GtkWidget *widget, gpointer data)
{
- bar_expander_move(widget, data, TRUE);
+ bar_expander_move(widget, data, TRUE, TRUE);
}
static void bar_expander_move_down_cb(GtkWidget *widget, gpointer data)
{
- bar_expander_move(widget, data, FALSE);
+ bar_expander_move(widget, data, FALSE, TRUE);
+}
+
+static void bar_expander_move_top_cb(GtkWidget *widget, gpointer data)
+{
+ bar_expander_move(widget, data, TRUE, FALSE);
+}
+
+static void bar_expander_move_bottom_cb(GtkWidget *widget, gpointer data)
+{
+ bar_expander_move(widget, data, FALSE, FALSE);
+}
+
+static void bar_expander_delete_cb(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *expander = data;
+ gtk_widget_destroy(expander);
+}
+
+static void bar_expander_add_cb(GtkWidget *widget, gpointer data)
+{
+ //GtkWidget *bar = data;
+ const KnownPanes *pane = known_panes;
+ const gchar *id = g_object_get_data(G_OBJECT(widget), "pane_add_id");
+ const gchar *config;
+
+ if (!id) return;
+
+ while (pane->id)
+ {
+ if (strcmp(pane->id, id) == 0) break;
+ pane++;
+ }
+ if (!pane->id) return;
+
+ config = bar_pane_get_default_config(id);
+ if (config) load_config_from_buf(config, strlen(config), FALSE);
+
}
-static void bar_expander_menu_popup(GtkWidget *data)
+static void bar_menu_popup(GtkWidget *widget)
{
GtkWidget *menu;
+ GtkWidget *bar;
+ GtkWidget *expander;
+ const KnownPanes *pane = known_panes;
+ BarData *bd;
+ bd = g_object_get_data(G_OBJECT(widget), "bar_data");
+ if (bd)
+ {
+ expander = NULL;
+ bar = widget;
+ }
+ else
+ {
+ expander = widget;
+ bar = widget->parent;
+ while (bar && !g_object_get_data(G_OBJECT(bar), "bar_data"))
+ bar = bar->parent;
+ if (!bar) return;
+ }
+
menu = popup_menu_short_lived();
- menu_item_add_stock(menu, _("Move _up"), GTK_STOCK_GO_UP, G_CALLBACK(bar_expander_move_up_cb), data);
- menu_item_add_stock(menu, _("Move _down"), GTK_STOCK_GO_DOWN, G_CALLBACK(bar_expander_move_down_cb), data);
- gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, data, 0, GDK_CURRENT_TIME);
+ if (expander)
+ {
+ menu_item_add_stock(menu, _("Move to _top"), GTK_STOCK_GOTO_TOP, G_CALLBACK(bar_expander_move_top_cb), expander);
+ menu_item_add_stock(menu, _("Move _up"), GTK_STOCK_GO_UP, G_CALLBACK(bar_expander_move_up_cb), expander);
+ menu_item_add_stock(menu, _("Move _down"), GTK_STOCK_GO_DOWN, G_CALLBACK(bar_expander_move_down_cb), expander);
+ menu_item_add_stock(menu, _("Move to _bottom"), GTK_STOCK_GOTO_BOTTOM, G_CALLBACK(bar_expander_move_bottom_cb), expander);
+ menu_item_add_divider(menu);
+ menu_item_add_stock(menu, _("Delete"), GTK_STOCK_DELETE, G_CALLBACK(bar_expander_delete_cb), expander);
+ menu_item_add_divider(menu);
+ }
+
+ while (pane->id)
+ {
+ GtkWidget *item;
+ item = menu_item_add_stock(menu, _(pane->title), GTK_STOCK_ADD, G_CALLBACK(bar_expander_add_cb), bar);
+ g_object_set_data(G_OBJECT(item), "pane_add_id", pane->id);
+ pane++;
+ }
+
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, bar, 0, GDK_CURRENT_TIME);
}
-static gboolean bar_expander_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean bar_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
{
if (bevent->button == MOUSE_BUTTON_RIGHT)
{
- bar_expander_menu_popup(widget);
+ bar_menu_popup(widget);
return TRUE;
}
return FALSE;
@@ -288,7 +478,7 @@
gtk_box_pack_start(GTK_BOX(bd->vbox), expander, FALSE, TRUE, 0);
- g_signal_connect(expander, "button_press_event", G_CALLBACK(bar_expander_menu_cb), bd);
+ g_signal_connect(expander, "button_press_event", G_CALLBACK(bar_menu_cb), bd);
gtk_container_add(GTK_CONTAINER(expander), pane);
@@ -300,24 +490,17 @@
}
-static void bar_populate_default(GtkWidget *bar)
+void bar_populate_default(GtkWidget *bar)
{
- GtkWidget *widget;
+ const gchar *populate_id[] = {"histogram", "title", "keywords", "comment", "exif", NULL};
+ const gchar **id = populate_id;
- widget = bar_pane_histogram_new("histogram", _("Histogram"), 80, TRUE, HCHAN_RGB, 0);
- bar_add(bar, widget);
-
- widget = bar_pane_comment_new("title", _("Title"), "Xmp.dc.title", TRUE, 40);
- bar_add(bar, widget);
-
- widget = bar_pane_keywords_new("keywords", _("Keywords"), KEYWORD_KEY, TRUE);
- bar_add(bar, widget);
-
- widget = bar_pane_comment_new("comment", _("Comment"), "Xmp.dc.description", TRUE, 150);
- bar_add(bar, widget);
-
- widget = bar_pane_exif_new("exif", _("Exif"), TRUE, TRUE);
- bar_add(bar, widget);
+ while (*id)
+ {
+ const gchar *config = bar_pane_get_default_config(*id);
+ if (config) load_config_from_buf(config, strlen(config), FALSE);
+ id++;
+ }
}
static void bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
@@ -373,6 +556,8 @@
g_signal_connect(G_OBJECT(bd->widget), "size-allocate",
G_CALLBACK(bar_size_allocate), bd);
+ g_signal_connect(G_OBJECT(bd->widget), "button_press_event", G_CALLBACK(bar_menu_cb), bd);
+
bd->width = SIDEBAR_DEFAULT_WIDTH;
gtk_widget_set_size_request(bd->widget, bd->width, -1);
@@ -404,16 +589,6 @@
return bd->widget;
}
-GtkWidget *bar_new_default(LayoutWindow *lw)
-{
- GtkWidget *bar = bar_new(lw);
-
- bar_populate_default(bar);
-
- gtk_widget_show(bar);
-
- return bar;
-}
GtkWidget *bar_update_from_config(GtkWidget *bar, const gchar **attribute_names, const gchar **attribute_values)
{
@@ -478,5 +653,18 @@
*title = g_strdup(_(pane->title));
return TRUE;
}
+
+const gchar *bar_pane_get_default_config(const gchar *id)
+{
+ const KnownPanes *pane = known_panes;
+
+ while (pane->id)
+ {
+ if (strcmp(pane->id, id) == 0) break;
+ pane++;
+ }
+ if (!pane->id) return NULL;
+ return pane->config;
+}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/bar.h
--- a/src/bar.h Sun Mar 29 10:36:13 2009 +0000
+++ b/src/bar.h Sun Mar 29 14:20:44 2009 +0000
@@ -43,7 +43,6 @@
GtkWidget *bar_new(LayoutWindow *lw);
-GtkWidget *bar_new_default(LayoutWindow *lw);
GtkWidget *bar_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values);
GtkWidget *bar_update_from_config(GtkWidget *bar, const gchar **attribute_names, const gchar **attribute_values);
@@ -51,6 +50,8 @@
void bar_write_config(GtkWidget *bar, GString *outstr, gint indent);
+void bar_populate_default(GtkWidget *bar);
+
void bar_add(GtkWidget *bar, GtkWidget *pane);
GtkWidget *bar_find_pane_by_id(GtkWidget *bar, PaneType type, const gchar *id);
@@ -64,5 +65,7 @@
GtkWidget *bar_pane_expander_title(const gchar *title);
void bar_update_expander(GtkWidget *pane);
gboolean bar_pane_translate_title(PaneType type, const gchar *id, gchar **title);
+const gchar *bar_pane_get_default_config(const gchar *id);
+
#endif
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/layout_util.c
--- a/src/layout_util.c Sun Mar 29 10:36:13 2009 +0000
+++ b/src/layout_util.c Sun Mar 29 14:20:44 2009 +0000
@@ -2030,9 +2030,11 @@
if (!lw->utility_box) return;
- bar = bar_new_default(lw);
+ bar = bar_new(lw);
layout_bar_set(lw, bar);
+
+ bar_populate_default(bar);
}
static void layout_bar_close(LayoutWindow *lw)
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/options.c
--- a/src/options.c Sun Mar 29 10:36:13 2009 +0000
+++ b/src/options.c Sun Mar 29 14:20:44 2009 +0000
@@ -247,7 +247,7 @@
sync_options_with_current_state(options);
rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
- save_options_to(rc_path, options);
+ save_config_to_file(rc_path, options);
g_free(rc_path);
}
@@ -259,13 +259,13 @@
if (isdir(GQ_SYSTEM_WIDE_DIR))
{
rc_path = g_build_filename(GQ_SYSTEM_WIDE_DIR, RC_FILE_NAME, NULL);
- success = load_options_from(rc_path, options, TRUE);
+ success = load_config_from_file(rc_path, TRUE);
DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
g_free(rc_path);
}
rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL);
- success = load_options_from(rc_path, options, TRUE);
+ success = load_config_from_file(rc_path, TRUE);
DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed");
g_free(rc_path);
return(success);
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/rcfile.c
--- a/src/rcfile.c Sun Mar 29 10:36:13 2009 +0000
+++ b/src/rcfile.c Sun Mar 29 14:20:44 2009 +0000
@@ -486,7 +486,7 @@
*-----------------------------------------------------------------------------
*/
-gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
+gboolean save_config_to_file(const gchar *utf8_path, ConfOptions *options)
{
SecureSaveInfo *ssi;
gchar *rc_pathl;
@@ -1167,19 +1167,12 @@
*-----------------------------------------------------------------------------
*/
-gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolean startup)
+gboolean load_config_from_buf(const gchar *buf, gsize size, gboolean startup)
{
- gsize size;
- gchar *buf;
GMarkupParseContext *context;
gboolean ret = TRUE;
GQParserData *parser_data;
- if (g_file_get_contents(utf8_path, &buf, &size, NULL) == FALSE)
- {
- return FALSE;
- }
-
parser_data = g_new0(GQParserData, 1);
parser_data->startup = startup;
@@ -1195,8 +1188,22 @@
g_free(parser_data);
+ g_markup_parse_context_free(context);
+ return ret;
+}
+
+gboolean load_config_from_file(const gchar *utf8_path, gboolean startup)
+{
+ gsize size;
+ gchar *buf;
+ gboolean ret = TRUE;
+
+ if (g_file_get_contents(utf8_path, &buf, &size, NULL) == FALSE)
+ {
+ return FALSE;
+ }
+ ret = load_config_from_buf(buf, size, startup);
g_free(buf);
- g_markup_parse_context_free(context);
return ret;
}
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/rcfile.h
--- a/src/rcfile.h Sun Mar 29 10:36:13 2009 +0000
+++ b/src/rcfile.h Sun Mar 29 14:20:44 2009 +0000
@@ -73,8 +73,10 @@
void options_parse_func_set_data(GQParserData *parser_data, gpointer data);
-gboolean save_options_to(const gchar *utf8_path, ConfOptions *options);
-gboolean load_options_from(const gchar *utf8_path, ConfOptions *options, gboolean startup);
+gboolean save_config_to_file(const gchar *utf8_path, ConfOptions *options);
+
+gboolean load_config_from_buf(const gchar *buf, gsize size, gboolean startup);
+gboolean load_config_from_file(const gchar *utf8_path, gboolean startup);
#endif
diff -r 7cb24fdf07c0 -r 9c16a93a0fdf src/remote.c
--- a/src/remote.c Sun Mar 29 10:36:13 2009 +0000
+++ b/src/remote.c Sun Mar 29 14:20:44 2009 +0000
@@ -506,7 +506,7 @@
if (isfile(filename))
{
- load_options_from(filename, options, FALSE);
+ load_config_from_file(filename, FALSE);
}
else
{