#include "ui_fileops.h"
#include "ui_menu.h"
#include "ui_misc.h"
+#include "rcfile.h"
/*
{
bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION);
}
- options->layout.panels.sort.mode_state = sd->mode;
}
/* this takes control of src_list */
static void bar_sort_set_action(SortData *sd, SortActionType action, const gchar *filter_key)
{
- options->layout.panels.sort.action_state = sd->action = action;
+ sd->action = action;
if (action == BAR_SORT_FILTER)
{
if (!filter_key) filter_key = "";
sd->filter_key = filter_key;
- g_free(options->layout.panels.sort.action_filter);
- options->layout.panels.sort.action_filter = g_strdup(filter_key);
}
else
{
sd->filter_key = NULL;
- g_free(options->layout.panels.sort.action_filter);
- options->layout.panels.sort.action_filter = g_strdup("");
}
}
static void bar_sort_set_selection(SortData *sd, SortSelectionType selection)
{
- options->layout.panels.sort.selection_state = sd->selection = selection;
+ sd->selection = selection;
}
static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data)
g_free(sd);
}
-GtkWidget *bar_sort_new(LayoutWindow *lw)
+static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, SortModeType mode, SortSelectionType selection, const gchar *filter_key)
{
SortData *sd;
GtkWidget *buttongrp;
GtkWidget *label;
GtkWidget *tbar;
GtkWidget *combo;
- SortModeType mode;
GList *editors_list, *work;
gboolean have_filter;
sd->lw = lw;
- mode = CLAMP(options->layout.panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1);
- sd->action = CLAMP(options->layout.panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1);
+ sd->action = action;
- if (sd->action == BAR_SORT_FILTER &&
- (!options->layout.panels.sort.action_filter || !options->layout.panels.sort.action_filter[0]))
+ if (sd->action == BAR_SORT_FILTER && (!filter_key || !filter_key[0]))
+ {
sd->action = BAR_SORT_COPY;
+ }
- sd->selection = CLAMP(options->layout.panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1);
+ sd->selection = selection;
sd->undo_src = NULL;
sd->undo_dest = NULL;
if (!editor_is_filter(editor->key)) continue;
- if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, options->layout.panels.sort.action_filter) == 0)
+ if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, filter_key) == 0)
{
bar_sort_set_action(sd, sd->action, editor->key);
select = TRUE;
return sd->vbox;
}
+
+GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values)
+{
+ GtkWidget *bar;
+
+ gboolean enabled = TRUE;
+ gint action = 0;
+ gint mode = 0;
+ gint selection = 0;
+ gchar *filter_key = NULL;
+
+ while (attribute_names && *attribute_names)
+ {
+ const gchar *option = *attribute_names++;
+ const gchar *value = *attribute_values++;
+
+ if (READ_BOOL_FULL("enabled", enabled)) continue;
+ if (READ_INT_CLAMP_FULL("action", action, 0, BAR_SORT_ACTION_COUNT - 1)) continue;
+ if (READ_INT_CLAMP_FULL("mode", mode, 0, BAR_SORT_MODE_COUNT - 1)) continue;
+ if (READ_INT_CLAMP_FULL("selection", selection, 0, BAR_SORT_SELECTION_COUNT - 1)) continue;
+ if (READ_CHAR_FULL("filter_key", filter_key)) continue;
+
+ DEBUG_1("unknown attribute %s = %s", option, value);
+ }
+ bar = bar_sort_new(lw, action, mode, selection, filter_key);
+
+ g_free(filter_key);
+ if (enabled) gtk_widget_show(bar);
+ return bar;
+}
+
+GtkWidget *bar_sort_new_default(LayoutWindow *lw)
+{
+ return bar_sort_new_from_config(lw, NULL, NULL);
+}
+
+void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent)
+{
+ SortData *sd;
+
+ if (!bar) return;
+ sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data");
+ if (!sd) return;
+
+ WRITE_STRING("<bar_sort\n");
+ indent++;
+ write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar));
+ WRITE_INT(*sd, mode);
+ WRITE_INT(*sd, action);
+ WRITE_INT(*sd, selection);
+ WRITE_CHAR(*sd, filter_key);
+ indent--;
+ WRITE_STRING("/>\n");
+}
+
+
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
#define BAR_SORT_H
-GtkWidget *bar_sort_new(LayoutWindow *lw);
+GtkWidget *bar_sort_new_default(LayoutWindow *lw);
+GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values);
void bar_sort_close(GtkWidget *bar);
+void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent);
#endif
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
#include "metadata.h"
#include "rcfile.h"
#include "bar.h"
+#include "bar_sort.h"
#ifdef HAVE_LIRC
#include "lirc.h"
WRITE_SEPARATOR();
WRITE_BOOL(*layout, toolbar_hidden);
-
- WRITE_BOOL(*layout, panels.sort.enabled);
- WRITE_INT(*layout, panels.sort.action_state);
- WRITE_INT(*layout, panels.sort.mode_state);
- WRITE_INT(*layout, panels.sort.selection_state);
- WRITE_CHAR(*layout, panels.sort.action_filter);
}
layout_write_attributes(&lw->options, outstr, indent + 1);
WRITE_STRING(">\n");
+ bar_sort_write_config(lw->bar_sort, outstr, indent + 1);
bar_write_config(lw->bar, outstr, indent + 1);
WRITE_STRING("</layout>\n");
if (READ_BOOL(*layout, tools_restore_state)) continue;
if (READ_BOOL(*layout, toolbar_hidden)) continue;
- /* panels */
- if (READ_BOOL(*layout, panels.sort.enabled)) continue;
- if (READ_INT(*layout, panels.sort.action_state)) continue;
- if (READ_INT(*layout, panels.sort.mode_state)) continue;
- if (READ_INT(*layout, panels.sort.selection_state)) continue;
- if (READ_CHAR(*layout, panels.sort.action_filter)) continue;
-
-
DEBUG_1("unknown attribute %s = %s", option, value);
}
#define MENU_EDIT_ACTION_OFFSET 16
static gboolean layout_bar_enabled(LayoutWindow *lw);
+static gboolean layout_bar_sort_enabled(LayoutWindow *lw);
/*
*-----------------------------------------------------------------------------
{
LayoutWindow *lw = data;
- if (lw->options.panels.sort.enabled == gtk_toggle_action_get_active(action)) return;
+ if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return;
layout_exit_fullscreen(lw);
layout_bar_sort_toggle(lw);
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
action = gtk_action_group_get_action(lw->action_group, "SBarSort");
- gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.sort.enabled);
+ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
// bar_info_selection(lw->bar_info, count - 1);
}
+static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
+{
+ return lw->bar_sort && GTK_WIDGET_VISIBLE(lw->bar_sort);
+}
+
+
static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
{
LayoutWindow *lw = data;
lw->bar_sort = NULL;
- if (lw->utility_box)
- {
- /* destroyed from within itself */
- lw->options.panels.sort.enabled = FALSE;
+/*
+ do not call layout_util_sync_views(lw) here
+ this is called either when whole layout is destroyed - no need for update
+ or when the bar is replaced - sync is called by upper function at the end of whole operation
- layout_util_sync_views(lw);
- }
+*/
}
-static void layout_bar_sort_new(LayoutWindow *lw)
+static void layout_bar_sort_set_default(LayoutWindow *lw)
{
+ GtkWidget *bar;
+
if (!lw->utility_box) return;
- lw->bar_sort = bar_sort_new(lw);
- g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
- G_CALLBACK(layout_bar_sort_destroyed), lw);
- lw->options.panels.sort.enabled = TRUE;
-
- gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
- gtk_widget_show(lw->bar_sort);
+ bar = bar_sort_new_default(lw);
+
+ layout_bar_sort_set(lw, bar);
}
static void layout_bar_sort_close(LayoutWindow *lw)
bar_sort_close(lw->bar_sort);
lw->bar_sort = NULL;
}
- lw->options.panels.sort.enabled = FALSE;
+}
+
+void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
+{
+ if (!lw->utility_box) return;
+
+ layout_bar_sort_close(lw); /* if any */
+
+ if (!bar) return;
+ lw->bar_sort = bar;
+
+ g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
+ G_CALLBACK(layout_bar_sort_destroyed), lw);
+
+ gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
}
void layout_bar_sort_toggle(LayoutWindow *lw)
{
- if (lw->options.panels.sort.enabled)
+ if (layout_bar_sort_enabled(lw))
{
- layout_bar_sort_close(lw);
+ gtk_widget_hide(lw->bar_sort);
}
else
{
- layout_bar_sort_new(lw);
+ if (!lw->bar_sort)
+ {
+ layout_bar_sort_set_default(lw);
+ }
+ gtk_widget_show(lw->bar_sort);
}
+ layout_util_sync_views(lw);
}
void layout_bars_new_image(LayoutWindow *lw)
gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0);
gtk_widget_show(image);
- if (lw->options.panels.sort.enabled)
- {
- layout_bar_sort_new(lw);
- }
-
return lw->utility_box;
}
void layout_bar_toggle(LayoutWindow *lw);
void layout_bar_set(LayoutWindow *lw, GtkWidget *bar);
-void layout_bar_exif_toggle(LayoutWindow *lw);
void layout_bar_sort_toggle(LayoutWindow *lw);
+void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar);
void layout_bars_new_image(LayoutWindow *lw);
void layout_bars_new_selection(LayoutWindow *lw, gint count);
options->open_recent_list_maxsize = 10;
options->place_dialogs_under_mouse = FALSE;
- options->layout.panels.sort.action_state = 0;
- options->layout.panels.sort.enabled = FALSE;
- options->layout.panels.sort.mode_state = 0;
- options->layout.panels.sort.selection_state = 0;
- options->layout.panels.sort.action_filter = NULL;
-
options->progressive_key_scrolling = TRUE;
options->metadata.enable_metadata_dirs = FALSE;
*dest = *src;
dest->order = g_strdup(src->order);
dest->home_path = g_strdup(src->home_path);
- dest->panels.sort.action_filter = g_strdup(src->panels.sort.action_filter);
}
void free_layout_options_content(LayoutOptions *dest)
{
if (dest->order) g_free(dest->order);
if (dest->home_path) g_free(dest->home_path);
- if (dest->panels.sort.action_filter) g_free(dest->panels.sort.action_filter);
}
static void sync_options_with_current_state(ConfOptions *options)
#include "bar_exif.h"
#include "bar_histogram.h"
#include "bar_keywords.h"
+#include "bar_sort.h"
#include "editors.h"
#include "filefilter.h"
#include "misc.h"
layout_bar_set(lw, bar);
options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar);
}
+ else if (g_ascii_strcasecmp(element_name, "bar_sort") == 0)
+ {
+ GtkWidget *bar = bar_sort_new_from_config(lw, attribute_names, attribute_values);
+ layout_bar_sort_set(lw, bar);
+ options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL);
+ }
else
{
DEBUG_1("unexpected in <layout>: <%s>", element_name);
gboolean toolbar_hidden;
gchar *home_path;
-
- /* panels */
- struct {
- struct {
- gboolean enabled;
- gint mode_state;
- gint action_state;
- gint selection_state;
- gchar *action_filter;
- } sort;
- } panels;
-
};
struct _LayoutWindow