changeset 1463:25168240a247

added function to reload external editors at any time eliminated init_after_global_options()
author nadvornik
date Fri, 20 Mar 2009 09:46:35 +0000
parents 75721f22155c
children 1b3751ac4743
files src/editors.c src/layout.c src/layout_util.c src/layout_util.h src/main.c src/main.h src/rcfile.c src/typedefs.h
diffstat 8 files changed, 64 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/editors.c	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/editors.c	Fri Mar 20 09:46:35 2009 +0000
@@ -167,8 +167,10 @@
 		{
 		/* We only consider desktop entries of Application type */
 		g_key_file_free(key_file);
+		g_free(type);
 		return FALSE;
 		}
+	g_free(type);
 	
 	editor = g_new0(EditorDescription, 1);
 	
@@ -334,10 +336,11 @@
 	gchar **split_dirs;
 	gint i;
 	
-	if (!editors)
+	if (editors)
 		{
-		editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free);
+		g_hash_table_destroy(editors);
 		}
+	editors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)editor_description_free);
 
 	xdg_data_dirs = getenv("XDG_DATA_DIRS");
 	if (xdg_data_dirs && xdg_data_dirs[0])
--- a/src/layout.c	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/layout.c	Fri Mar 20 09:46:35 2009 +0000
@@ -1758,7 +1758,7 @@
 	if (lw->ui_manager) g_object_unref(lw->ui_manager);
 	lw->ui_manager = NULL;
 	lw->action_group = NULL;
-	lw->action_group_external = NULL;
+	lw->action_group_editors = NULL;
 
 	gtk_container_remove(GTK_CONTAINER(lw->main_box), lw->group_box);
 	lw->group_box = NULL;
--- a/src/layout_util.c	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/layout_util.c	Fri Mar 20 09:46:35 2009 +0000
@@ -1666,7 +1666,13 @@
 	GList *editors_list;
 	GList *work;
 	GList *old_path;
-	GString *desc = g_string_new(
+	GString *desc;
+	
+	lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
+	gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
+
+	/* lw->action_group_editors contains translated entries, no translate func is required */
+	desc = g_string_new(
 				"<ui>"
 				"  <menubar name='MainMenu'>");
 
@@ -1684,7 +1690,7 @@
 			{
 			entry.stock_id = editor->key;
 			}
-		gtk_action_group_add_actions(lw->action_group_external, &entry, 1, lw);
+		gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
 		
 		path = layout_actions_editor_menu_path(editor);
 		layout_actions_editor_add(desc, path, old_path);
@@ -1701,7 +1707,9 @@
 				"</ui>" );
 
 	error = NULL;
-	if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
+	
+	lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
+	if (!lw->ui_editors_id)
 		{
 		g_message("building menus failed: %s", error->message);
 		g_error_free(error);
@@ -1719,8 +1727,6 @@
 
 	lw->action_group = gtk_action_group_new("MenuActions");
 	gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
-	lw->action_group_external = gtk_action_group_new("MenuActionsExternal");
-	/* lw->action_group_external contains translated entries, no translate func is required */
 
 	gtk_action_group_add_actions(lw->action_group,
 				     menu_entries, G_N_ELEMENTS(menu_entries), lw);
@@ -1739,7 +1745,6 @@
 	lw->ui_manager = gtk_ui_manager_new();
 	gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
 	gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
-	gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_external, 1);
 
 	error = NULL;
 	if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
@@ -1757,6 +1762,32 @@
 	layout_copy_path_update(lw);
 }
 
+void layout_editors_reload_all(void)
+{
+	GList *work;
+
+	work = layout_window_list;
+	while (work)
+		{
+		LayoutWindow *lw = work->data;
+		work = work->next;
+
+		gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
+		gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
+		g_object_unref(lw->action_group_editors);
+		}
+	
+	editor_load_descriptions();
+	
+	work = layout_window_list;
+	while (work)
+		{
+		LayoutWindow *lw = work->data;
+		work = work->next;
+		layout_actions_setup_editors(lw);
+		}
+}
+
 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
 {
 	GtkAccelGroup *group;
--- a/src/layout_util.h	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/layout_util.h	Fri Mar 20 09:46:35 2009 +0000
@@ -30,6 +30,7 @@
 
 void layout_copy_path_update_all(void);
 
+void layout_editors_reload_all(void);
 void layout_actions_setup(LayoutWindow *lw);
 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window);
 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw);
--- a/src/main.c	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/main.c	Fri Mar 20 09:46:35 2009 +0000
@@ -675,15 +675,6 @@
 	exit_program_final();
 }
 
-void init_after_global_options(void)
-{
-	filter_add_defaults();
-	filter_rebuild(); 
-
-	editor_load_descriptions();
-}
-
-
 /* This code is supposed to handle situation when a file mmaped by image_loader 
  * or by exif loader is truncated by some other process.
  * This is probably not completely correct according to posix, because
@@ -788,8 +779,14 @@
 	options = init_options(NULL);
 	setup_default_options(options);
 
-	/* load_options calls init_after_global_options() after it parses global options, we have to call it here if it fails*/
-	if (!load_options(options)) init_after_global_options();
+	if (!load_options(options))
+		{
+		/* load_options calls these functions after it parses global options, we have to call it here if it fails */
+		filter_add_defaults();
+		filter_rebuild(); 
+
+		editor_load_descriptions();
+		}
 
 	/* handle missing config file and commandline additions*/
 	if (!layout_window_list) 
--- a/src/main.h	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/main.h	Fri Mar 20 09:46:35 2009 +0000
@@ -136,8 +136,6 @@
 
 void exit_program(void);
 
-void init_after_global_options(void);
-
 #define CASE_SORT(a, b) ( (options->file_sort.case_sensitive) ? strcmp((a), (b)) : strcasecmp((a), (b)) )
 
 
--- a/src/rcfile.c	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/rcfile.c	Fri Mar 20 09:46:35 2009 +0000
@@ -775,8 +775,7 @@
 struct _GQParserData
 {
 	GList *parse_func_stack;
-	gboolean startup; /* reading config for the first time - add commandline and call init_after_global_options() */
-	gboolean global_found;
+	gboolean startup; /* reading config for the first time - add commandline and defaults */
 };
 
 
@@ -816,8 +815,8 @@
 
 static void options_parse_filter_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
 {
-	if (!parser_data->startup) filter_rebuild(); 
-	/* else this is called in init_after_global_options */
+	if (parser_data->startup) filter_add_defaults();
+	filter_rebuild(); 
 }
 
 static void options_parse_keyword_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
@@ -882,6 +881,12 @@
 		}
 }
 
+static void options_parse_global_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
+{
+	/* on startup there are no layout windows and this just loads the editors */
+	layout_editors_reload_all();
+}
+
 static void options_parse_pane_exif(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error)
 {
 	GtkWidget *pane = data;
@@ -990,17 +995,10 @@
 	if (g_ascii_strcasecmp(element_name, "global") == 0)
 		{
 		load_global_params(attribute_names, attribute_values);
-		options_parse_func_push(parser_data, options_parse_global, NULL, NULL);
+		options_parse_func_push(parser_data, options_parse_global, options_parse_global_end, NULL);
 		return;
 		}
 	
-	if (parser_data->startup && !parser_data->global_found)
-		{
-		DEBUG_1(" global end");
-		parser_data->global_found = TRUE;
-		init_after_global_options();
-		}
-	
 	if (g_ascii_strcasecmp(element_name, "layout") == 0)
 		{
 		LayoutWindow *lw;
--- a/src/typedefs.h	Thu Mar 19 22:58:28 2009 +0000
+++ b/src/typedefs.h	Fri Mar 20 09:46:35 2009 +0000
@@ -547,7 +547,8 @@
 	/* menus, path selector */
 
 	GtkActionGroup *action_group;
-	GtkActionGroup *action_group_external;
+	GtkActionGroup *action_group_editors;
+	guint ui_editors_id;
 	GtkUIManager *ui_manager;
 	guint toolbar_merge_id;
 	GList *toolbar_actions;