changeset 491:4a9570cd06f8

Save sort manager state to rc file.
author zas_
date Tue, 22 Apr 2008 23:53:24 +0000
parents 2b85ad4c59bd
children dead6fb690c5
files src/bar_sort.c src/globals.c src/rcfile.c src/typedefs.h
diffstat 4 files changed, 48 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_sort.c	Tue Apr 22 22:45:51 2008 +0000
+++ b/src/bar_sort.c	Tue Apr 22 23:53:24 2008 +0000
@@ -34,18 +34,21 @@
 
 typedef enum {
 	BAR_SORT_MODE_FOLDER = 0,
-	BAR_SORT_MODE_COLLECTION
+	BAR_SORT_MODE_COLLECTION,
+	BAR_SORT_MODE_COUNT
 } SortModeType;
 
 typedef enum {
-	BAR_SORT_COPY,
+	BAR_SORT_COPY = 0,
 	BAR_SORT_MOVE,
-	BAR_SORT_LINK
+	BAR_SORT_LINK,
+	BAR_SORT_ACTION_COUNT
 } SortActionType;
 
 typedef enum {
-	BAR_SORT_SELECTION_IMAGE,
-	BAR_SORT_SELECTION_SELECTED
+	BAR_SORT_SELECTION_IMAGE = 0,
+	BAR_SORT_SELECTION_SELECTED,
+	BAR_SORT_SELECTION_COUNT
 } SortSelectionType;
 
 typedef struct _SortData SortData;
@@ -78,11 +81,6 @@
 #define SORT_KEY_COLLECTIONS "sort_manager_collections"
 
 
-static gint bar_sort_mode_state = BAR_SORT_MODE_FOLDER;
-static gint bar_sort_action_state = BAR_SORT_COPY;
-static gint bar_sort_selection_state = BAR_SORT_SELECTION_IMAGE;
-
-
 static void bar_sort_undo_set(SortData *sd, GList *src_list, FileData *src, const gchar *dest);
 static void bar_sort_add_close(SortData *sd);
 
@@ -168,6 +166,7 @@
 		{
 		bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION);
 		}
+	options->panels.sort.mode_state = sd->mode;
 }
 
 /* this takes control of src_list */
@@ -220,6 +219,8 @@
 				g_free(buf);
 				}
 			break;
+		default: 
+			break;
 		}
 
 	layout_refresh(sd->lw);
@@ -301,6 +302,8 @@
 				g_free(buf);
 				}
 			break;
+		default:
+			break;
 		}
 
 	g_list_free(list);
@@ -319,6 +322,8 @@
 		case BAR_SORT_SELECTION_SELECTED:
 			list = layout_selection_list(sd->lw);
 			break;
+		default:
+			break;
 		}
 
 	if (!list)
@@ -357,39 +362,49 @@
 		}
 }
 
+static void bar_sort_set_action(SortData *sd, SortActionType action)
+{
+	options->panels.sort.action_state = sd->action = action;
+}
+
 static void bar_sort_set_copy_cb(GtkWidget *button, gpointer data)
 {
 	SortData *sd = data;
 	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return;
-	sd->action = BAR_SORT_COPY;
+	bar_sort_set_action(sd, BAR_SORT_COPY);
 }
 
 static void bar_sort_set_move_cb(GtkWidget *button, gpointer data)
 {
 	SortData *sd = data;
 	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return;
-	sd->action = BAR_SORT_MOVE;
+	bar_sort_set_action(sd, BAR_SORT_MOVE);
 }
 
 static void bar_sort_set_link_cb(GtkWidget *button, gpointer data)
 {
 	SortData *sd = data;
 	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return;
-	sd->action = BAR_SORT_LINK;
+	bar_sort_set_action(sd, BAR_SORT_LINK);
+}
+
+static void bar_sort_set_selection(SortData *sd, SortSelectionType selection)
+{
+	options->panels.sort.selection_state = sd->selection = selection;
 }
 
 static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data)
 {
 	SortData *sd = data;
 	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return;
-	sd->selection = BAR_SORT_SELECTION_IMAGE;
+	bar_sort_set_selection(sd, BAR_SORT_SELECTION_IMAGE);
 }
 
 static void bar_sort_set_selection_selected_cb(GtkWidget *button, gpointer data)
 {
 	SortData *sd = data;
 	if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return;
-	sd->selection = BAR_SORT_SELECTION_SELECTED;
+	bar_sort_set_selection(sd, BAR_SORT_SELECTION_SELECTED);
 }
 
 static void bar_sort_add_close(SortData *sd)
@@ -534,9 +549,6 @@
 	SortData *sd = data;
 
 	bar_sort_add_close(sd);
-	bar_sort_mode_state = sd->mode;
-	bar_sort_action_state = sd->action;
-	bar_sort_selection_state = sd->selection;
 
 	g_free(sd->undo_src);
 	g_free(sd->undo_dest);
@@ -550,14 +562,17 @@
 	GtkWidget *label;
 	GtkWidget *tbar;
 	GtkWidget *combo;
+	SortModeType mode;
 
 	if (!lw) return NULL;
 
 	sd = g_new0(SortData, 1);
 
 	sd->lw = lw;
-	sd->action = bar_sort_action_state;
-	sd->selection = bar_sort_selection_state;
+
+	mode = CLAMP(options->panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1);
+	sd->action = CLAMP(options->panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1);
+	sd->selection = CLAMP(options->panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1);
 	sd->undo_src = NULL;
 	sd->undo_dest = NULL;
 
@@ -616,7 +631,7 @@
 					      G_CALLBACK(bar_sort_undo_cb), sd);
 
 	sd->mode = -1;
-	bar_sort_mode_sync(sd, bar_sort_mode_state);
+	bar_sort_mode_sync(sd, mode);
 	gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sd->mode);
 
 	return sd->vbox;
--- a/src/globals.c	Tue Apr 22 22:45:51 2008 +0000
+++ b/src/globals.c	Tue Apr 22 23:53:24 2008 +0000
@@ -111,7 +111,10 @@
 	options->panels.exif.width = PANEL_DEFAULT_WIDTH;
 	options->panels.info.enabled = FALSE;
 	options->panels.info.width = PANEL_DEFAULT_WIDTH;
+	options->panels.sort.action_state = 0;
 	options->panels.sort.enabled = FALSE;
+	options->panels.sort.mode_state = 0;
+	options->panels.sort.selection_state = 0;
 
 	options->progressive_key_scrolling = FALSE;
 	options->show_icon_names = TRUE;
--- a/src/rcfile.c	Tue Apr 22 22:45:51 2008 +0000
+++ b/src/rcfile.c	Tue Apr 22 23:53:24 2008 +0000
@@ -376,6 +376,9 @@
 	WRITE_BOOL(panels.info.enabled);
 	WRITE_INT(panels.info.width);
 	WRITE_BOOL(panels.sort.enabled);
+	WRITE_INT(panels.sort.action_state);
+	WRITE_INT(panels.sort.mode_state);
+	WRITE_INT(panels.sort.selection_state);
 
 	WRITE_SUBTITLE("Image Options");
 
@@ -668,6 +671,9 @@
 		READ_BOOL(panels.info.enabled);
 		READ_INT_CLAMP(panels.info.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH);
 		READ_BOOL(panels.sort.enabled);
+		READ_INT(panels.sort.action_state);
+		READ_INT(panels.sort.mode_state);
+		READ_INT(panels.sort.selection_state);
 
 		/* image options */
 		if (strcasecmp(option, "image.zoom_mode") == 0)
--- a/src/typedefs.h	Tue Apr 22 22:45:51 2008 +0000
+++ b/src/typedefs.h	Tue Apr 22 23:53:24 2008 +0000
@@ -915,6 +915,9 @@
 
 		struct {
 			gint enabled;
+			gint mode_state;
+			gint action_state;
+			gint selection_state;
 		} sort;
 	} panels;