changeset 1511:73cecf473802

startup path options simplified and moved to layout options
author nadvornik
date Sat, 04 Apr 2009 21:14:34 +0000
parents ad5018434476
children 0a1266bde95b
files src/layout.c src/options.c src/options.h src/preferences.c src/rcfile.c src/typedefs.h
diffstat 6 files changed, 69 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/src/layout.c	Sat Apr 04 20:20:17 2009 +0000
+++ b/src/layout.c	Sat Apr 04 21:14:34 2009 +0000
@@ -2032,6 +2032,25 @@
 	gtk_entry_set_text(GTK_ENTRY(lc->home_path_entry), layout_get_path(lc->lw));
 }
 
+static void startup_path_set_current_cb(GtkWidget *widget, gpointer data)
+{
+	LayoutConfig *lc = data;
+	lc->options.startup_path = STARTUP_PATH_CURRENT;
+}
+
+static void startup_path_set_last_cb(GtkWidget *widget, gpointer data)
+{
+	LayoutConfig *lc = data;
+	lc->options.startup_path = STARTUP_PATH_LAST;
+}
+
+static void startup_path_set_home_cb(GtkWidget *widget, gpointer data)
+{
+	LayoutConfig *lc = data;
+	lc->options.startup_path = STARTUP_PATH_HOME;
+}
+
+
 /*
 static void layout_config_save_cb(GtkWidget *widget, gpointer data)
 {
@@ -2115,9 +2134,10 @@
 	gtk_container_add(GTK_CONTAINER(frame), vbox);
 	gtk_widget_show(vbox);
 
+
 	group = pref_group_new(vbox, FALSE, _("General options"), GTK_ORIENTATION_VERTICAL);
 
-	pref_label_new(group, _("Home button path (empty to use your home directory)"));
+	pref_label_new(group, _("Home path (empty to use your home directory)"));
 	hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
 
 	tabcomp = tab_completion_new(&lc->home_path_entry, lc->options.home_path, NULL, NULL);
@@ -2128,11 +2148,21 @@
 	button = pref_button_new(hbox, NULL, _("Use current"), FALSE,
 				 G_CALLBACK(home_path_set_current_cb), lc);
 
-	group = pref_group_new(vbox, FALSE, _("Behavior"), GTK_ORIENTATION_VERTICAL);
-
 	pref_checkbox_new_int(group, _("Show date in directories list view"),
 			      lc->options.show_directory_date, &lc->options.show_directory_date);
 
+	group = pref_group_new(vbox, FALSE, _("Start-up directory:"), GTK_ORIENTATION_VERTICAL);
+
+	button = pref_radiobutton_new(group, NULL, _("No change"),
+				      (lc->options.startup_path == STARTUP_PATH_CURRENT),
+				      G_CALLBACK(startup_path_set_current_cb), lc);
+	button = pref_radiobutton_new(group, button, _("Restore last path"),
+				      (lc->options.startup_path == STARTUP_PATH_LAST),
+				      G_CALLBACK(startup_path_set_last_cb), lc);
+	button = pref_radiobutton_new(group, button, _("Home path"),
+				      (lc->options.startup_path == STARTUP_PATH_HOME),
+				      G_CALLBACK(startup_path_set_home_cb), lc);
+
 	group = pref_group_new(vbox, FALSE, _("Layout"), GTK_ORIENTATION_VERTICAL);
 
 	lc->layout_widget = layout_config_new();
@@ -2174,11 +2204,8 @@
 	lw->options.image_overlay.histogram_channel = histogram->histogram_channel;
 	lw->options.image_overlay.histogram_mode = histogram->histogram_mode;
 
-//	if (options->startup.restore_path && options->startup.use_last_path)
-//		{
-//		g_free(options->startup.path);
-//		options->startup.path = g_strdup(layout_get_path(NULL));
-//		}
+	g_free(lw->options.last_path);
+	lw->options.last_path = g_strdup(layout_get_path(lw));
 }
 
 void layout_apply_options(LayoutWindow *lw, LayoutOptions *lop)
@@ -2406,6 +2433,8 @@
 	WRITE_NL(); WRITE_BOOL(*layout, show_thumbnails);
 	WRITE_NL(); WRITE_BOOL(*layout, show_directory_date);
 	WRITE_NL(); WRITE_CHAR(*layout, home_path);
+	WRITE_NL(); WRITE_CHAR(*layout, last_path);
+	WRITE_NL(); WRITE_UINT(*layout, startup_path);
 	WRITE_SEPARATOR();
 
 	WRITE_NL(); WRITE_INT(*layout, main_window.x);
@@ -2477,6 +2506,8 @@
 		if (READ_BOOL(*layout, show_thumbnails)) continue;
 		if (READ_BOOL(*layout, show_directory_date)) continue;
 		if (READ_CHAR(*layout, home_path)) continue;
+		if (READ_CHAR(*layout, last_path)) continue;
+		if (READ_UINT_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue;
 
 		/* window positions */
 
@@ -2519,6 +2550,23 @@
 		}
 }
 
+static void layout_config_startup_path(LayoutOptions *lop, gchar **path)
+{
+	switch (lop->startup_path)
+		{
+		case STARTUP_PATH_LAST:
+			*path = (lop->last_path && isdir(lop->last_path)) ? g_strdup(lop->last_path) : get_current_dir();
+			break;
+		case STARTUP_PATH_HOME:
+			*path = (lop->home_path && isdir(lop->home_path)) ? g_strdup(lop->home_path) : g_strdup(homedir());
+			break;
+		default:
+			*path = get_current_dir();
+			break;
+		}
+}	
+
+
 static void layout_config_commandline(LayoutOptions *lop, gchar **path)
 {
 	if (command_line->startup_blank)
@@ -2533,14 +2581,7 @@
 		{
 		*path = g_strdup(command_line->path);
 		}
-	else if (options->startup.restore_path && options->startup.path && isdir(options->startup.path))
-		{
-		*path = g_strdup(options->startup.path);
-		}
-	else
-		{
-		*path = get_current_dir();
-		}
+	else layout_config_startup_path(lop, path);
 	
 	if (command_line->tools_show)
 		{
@@ -2567,13 +2608,9 @@
 		{
 		layout_config_commandline(&lop, &path);
 		}
-	else if (options->startup.restore_path && options->startup.path && isdir(options->startup.path))
+	else 
 		{
-		path = g_strdup(options->startup.path);
-		}
-	else
-		{
-		path = get_current_dir();
+		layout_config_startup_path(&lop, &path);
 		}
 
 	lw = layout_new_with_geometry(NULL, &lop, use_commandline ? command_line->geometry : NULL);
--- a/src/options.c	Sat Apr 04 20:20:17 2009 +0000
+++ b/src/options.c	Sat Apr 04 21:14:34 2009 +0000
@@ -113,10 +113,6 @@
 	options->slideshow.random = FALSE;
 	options->slideshow.repeat = FALSE;
 
-	options->startup.path = NULL;
-	options->startup.restore_path = FALSE;
-	options->startup.use_last_path = FALSE;
-
 	options->thumbnails.cache_into_dirs = FALSE;
 	options->thumbnails.enable_caching = TRUE;
 	options->thumbnails.fast = TRUE;
@@ -173,6 +169,7 @@
 	dest->id = g_strdup(src->id);
 	dest->order = g_strdup(src->order);
 	dest->home_path = g_strdup(src->home_path);
+	dest->last_path = g_strdup(src->last_path);
 }
 
 void free_layout_options_content(LayoutOptions *dest)
@@ -180,6 +177,7 @@
 	g_free(dest->id);
 	g_free(dest->order);
 	g_free(dest->home_path);
+	g_free(dest->last_path);
 }
 
 LayoutOptions *init_layout_options(LayoutOptions *options)
@@ -230,12 +228,6 @@
 					       &options->color_profile.input_type,
 					       &options->color_profile.screen_type,
 					       &options->color_profile.use_image);
-
-		if (options->startup.restore_path && options->startup.use_last_path)
-			{
-			g_free(options->startup.path);
-			options->startup.path = g_strdup(layout_get_path(lw));
-			}
 		}
 
 }
--- a/src/options.h	Sat Apr 04 20:20:17 2009 +0000
+++ b/src/options.h	Sat Apr 04 21:14:34 2009 +0000
@@ -37,13 +37,6 @@
 	gboolean save_window_positions;
 	gboolean tools_restore_state;
 
-	/* start up */
-	struct {
-		gboolean restore_path;
-		gboolean use_last_path;
-		gchar *path;
-	} startup;
-
 	/* file ops */
 	struct {
 		gboolean enable_in_place_rename;
--- a/src/preferences.c	Sat Apr 04 20:20:17 2009 +0000
+++ b/src/preferences.c	Sat Apr 04 21:14:34 2009 +0000
@@ -96,7 +96,6 @@
 #endif
 
 static GtkWidget *configwindow = NULL;
-static GtkWidget *startup_path_entry;
 static GtkListStore *filter_store = NULL;
 
 static GtkWidget *safe_delete_path_entry;
@@ -117,11 +116,6 @@
  *-----------------------------------------------------------------------------
  */
 
-static void startup_path_set_current(GtkWidget *widget, gpointer data)
-{
-	gtk_entry_set_text(GTK_ENTRY(startup_path_entry), layout_get_path(NULL));
-}
-
 static void zoom_mode_cb(GtkWidget *widget, gpointer data)
 {
 	if (GTK_TOGGLE_BUTTON (widget)->active)
@@ -231,10 +225,6 @@
 	if (options->file_sort.case_sensitive != c_options->file_sort.case_sensitive) refresh = TRUE;
 	if (options->file_filter.disable != c_options->file_filter.disable) refresh = TRUE;
 
-	options->startup.restore_path = c_options->startup.restore_path;
-	options->startup.use_last_path = c_options->startup.use_last_path;
-	config_entry_to_option(startup_path_entry, &options->startup.path, remove_trailing_slash);
-
 	options->file_ops.confirm_delete = c_options->file_ops.confirm_delete;
 	options->file_ops.enable_delete_key = c_options->file_ops.enable_delete_key;
 	options->file_ops.safe_delete_enable = c_options->file_ops.safe_delete_enable;
@@ -913,42 +903,16 @@
 /* general options tab */
 static void config_tab_general(GtkWidget *notebook)
 {
-	GtkWidget *hbox;
 	GtkWidget *vbox;
-	GtkWidget *subvbox;
 	GtkWidget *group;
 	GtkWidget *subgroup;
 	GtkWidget *button;
-	GtkWidget *tabcomp;
 	GtkWidget *ct_button;
 	GtkWidget *table;
 	GtkWidget *spin;
 
 	vbox = scrolled_notebook_page(notebook, _("General"));
 
-	group = pref_group_new(vbox, FALSE, _("Startup"), GTK_ORIENTATION_VERTICAL);
-
-	button = pref_checkbox_new_int(group, _("Restore folder on startup"),
-				       options->startup.restore_path, &c_options->startup.restore_path);
-
-	subvbox = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
-	pref_checkbox_link_sensitivity(button, subvbox);
-
-	hbox = pref_box_new(subvbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
-
-	tabcomp = tab_completion_new(&startup_path_entry, options->startup.path, NULL, NULL);
-	tab_completion_add_select_button(startup_path_entry, NULL, TRUE);
-	gtk_box_pack_start(GTK_BOX(hbox), tabcomp, TRUE, TRUE, 0);
-	gtk_widget_show(tabcomp);
-
-	button = pref_button_new(hbox, NULL, _("Use current"), FALSE,
-				 G_CALLBACK(startup_path_set_current), NULL);
-
-	button = pref_checkbox_new_int(subvbox, _("Use last path"),
-				       options->startup.use_last_path, &c_options->startup.use_last_path);
-	pref_checkbox_link_sensitivity_swap(button, hbox);
-
-
 	group = pref_group_new(vbox, FALSE, _("Thumbnails"), GTK_ORIENTATION_VERTICAL);
 
 	table = pref_table_new(group, 2, 2, FALSE, FALSE);
--- a/src/rcfile.c	Sat Apr 04 20:20:17 2009 +0000
+++ b/src/rcfile.c	Sat Apr 04 21:14:34 2009 +0000
@@ -283,13 +283,6 @@
 	WRITE_NL(); WRITE_BOOL(*options, save_window_positions);
 	WRITE_NL(); WRITE_BOOL(*options, tools_restore_state);
 
-//	WRITE_SUBTITLE("Startup Options");
-
-	WRITE_NL(); WRITE_BOOL(*options, startup.restore_path);
-	WRITE_NL(); WRITE_BOOL(*options, startup.use_last_path);
-	WRITE_NL(); WRITE_CHAR(*options, startup.path);
-
-
 //	WRITE_SUBTITLE("File operations Options");
 
 	WRITE_NL(); WRITE_BOOL(*options, file_ops.enable_in_place_rename);
@@ -601,15 +594,6 @@
 		if (READ_BOOL(*options, save_window_positions)) continue;
 		if (READ_BOOL(*options, tools_restore_state)) continue;
 
-		/* startup options */
-		
-		if (READ_BOOL(*options, startup.restore_path)) continue;
-
-		if (READ_BOOL(*options, startup.use_last_path)) continue;
-
-		if (READ_CHAR(*options, startup.path)) continue;
-	
-
 		/* properties dialog options */
 		if (READ_CHAR(*options, properties.tabs_order)) continue;
 
--- a/src/typedefs.h	Sat Apr 04 20:20:17 2009 +0000
+++ b/src/typedefs.h	Sat Apr 04 21:14:34 2009 +0000
@@ -174,6 +174,11 @@
 	METADATA_FORMATTED	= 1  /* for display only */
 } MetadataFormat;
 
+typedef enum {
+	STARTUP_PATH_CURRENT	= 0,
+	STARTUP_PATH_LAST,
+	STARTUP_PATH_HOME,
+} StartUpPath;
 
 #define MAX_SPLIT_IMAGES 4
 
@@ -530,6 +535,9 @@
 	gboolean info_pixel_hidden;
 
 	gchar *home_path;
+	gchar *last_path;
+
+	StartUpPath startup_path;
 };
 
 struct _LayoutWindow