Mercurial > geeqie
comparison src/layout_util.c @ 1736:8e64965c1d92
load desktop files in idle time
- scanning all desktop files takes a lot of time because of hdd seek
- this change moves the scanning to idle time
- the editors appears in the menus some time after startup
https://sourceforge.net/tracker/index.php?func=detail&aid=2852522&group_id=222125&atid=1054680
author | nadvornik |
---|---|
date | Sun, 06 Sep 2009 14:01:03 +0000 |
parents | 6cae2af8fdd1 |
children | a9af670f47d2 |
comparison
equal
deleted
inserted
replaced
1735:6cae2af8fdd1 | 1736:8e64965c1d92 |
---|---|
1799 GList *editors_list; | 1799 GList *editors_list; |
1800 GList *work; | 1800 GList *work; |
1801 GList *old_path; | 1801 GList *old_path; |
1802 GString *desc; | 1802 GString *desc; |
1803 | 1803 |
1804 if (lw->action_group_editors) | |
1805 { | |
1806 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors); | |
1807 g_object_unref(lw->action_group_editors); | |
1808 } | |
1804 lw->action_group_editors = gtk_action_group_new("MenuActionsExternal"); | 1809 lw->action_group_editors = gtk_action_group_new("MenuActionsExternal"); |
1805 gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1); | 1810 gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1); |
1806 | 1811 |
1807 /* lw->action_group_editors contains translated entries, no translate func is required */ | 1812 /* lw->action_group_editors contains translated entries, no translate func is required */ |
1808 desc = g_string_new( | 1813 desc = g_string_new( |
1822 editor->name, | 1827 editor->name, |
1823 editor->hotkey, | 1828 editor->hotkey, |
1824 editor->comment ? editor->comment : editor->name, | 1829 editor->comment ? editor->comment : editor->name, |
1825 G_CALLBACK(layout_menu_edit_cb) }; | 1830 G_CALLBACK(layout_menu_edit_cb) }; |
1826 | 1831 |
1827 if (editor->icon && register_theme_icon_as_stock(editor->key, editor->icon)) | 1832 if (editor->icon) |
1828 { | 1833 { |
1829 entry.stock_id = editor->key; | 1834 entry.stock_id = editor->key; |
1830 } | 1835 } |
1831 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw); | 1836 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw); |
1832 | 1837 |
1925 DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time()); | 1930 DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time()); |
1926 layout_actions_add_window(lw, lw->window); | 1931 layout_actions_add_window(lw, lw->window); |
1927 DEBUG_1("%s layout_actions_setup: end", get_exec_time()); | 1932 DEBUG_1("%s layout_actions_setup: end", get_exec_time()); |
1928 } | 1933 } |
1929 | 1934 |
1930 void layout_editors_reload_all(void) | 1935 static gint layout_editors_reload_idle_id = -1; |
1936 static GList *layout_editors_desktop_files = NULL; | |
1937 | |
1938 static gboolean layout_editors_reload_idle_cb(gpointer data) | |
1939 { | |
1940 if (!layout_editors_desktop_files) | |
1941 { | |
1942 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time()); | |
1943 layout_editors_desktop_files = editor_get_desktop_files(); | |
1944 return TRUE; | |
1945 } | |
1946 | |
1947 editor_read_desktop_file(layout_editors_desktop_files->data); | |
1948 g_free(layout_editors_desktop_files->data); | |
1949 layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files); | |
1950 | |
1951 | |
1952 if (!layout_editors_desktop_files) | |
1953 { | |
1954 GList *work; | |
1955 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time()); | |
1956 editor_table_finish(); | |
1957 | |
1958 work = layout_window_list; | |
1959 while (work) | |
1960 { | |
1961 LayoutWindow *lw = work->data; | |
1962 work = work->next; | |
1963 layout_actions_setup_editors(lw); | |
1964 } | |
1965 | |
1966 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time()); | |
1967 | |
1968 layout_editors_reload_idle_id = -1; | |
1969 return FALSE; | |
1970 } | |
1971 return TRUE; | |
1972 } | |
1973 | |
1974 void layout_editors_reload_start(void) | |
1931 { | 1975 { |
1932 GList *work; | 1976 GList *work; |
1933 | 1977 |
1934 DEBUG_1("%s layout_editors_reload_all: start", get_exec_time()); | 1978 DEBUG_1("%s layout_editors_reload_start", get_exec_time()); |
1979 | |
1980 if (layout_editors_reload_idle_id != -1) | |
1981 { | |
1982 g_source_remove(layout_editors_reload_idle_id); | |
1983 string_list_free(layout_editors_desktop_files); | |
1984 } | |
1935 | 1985 |
1936 work = layout_window_list; | 1986 work = layout_window_list; |
1937 while (work) | 1987 while (work) |
1938 { | 1988 { |
1939 LayoutWindow *lw = work->data; | 1989 LayoutWindow *lw = work->data; |
1940 work = work->next; | 1990 work = work->next; |
1941 | 1991 |
1942 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id); | 1992 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id); |
1943 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors); | 1993 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors); |
1944 g_object_unref(lw->action_group_editors); | 1994 g_object_unref(lw->action_group_editors); |
1945 } | 1995 lw->action_group_editors = NULL; |
1946 | 1996 } |
1947 DEBUG_1("%s layout_editors_reload_all: editor_load_descriptions", get_exec_time()); | 1997 editor_table_clear(); |
1948 editor_load_descriptions(); | 1998 layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, NULL); |
1949 | 1999 } |
1950 DEBUG_1("%s layout_editors_reload_all: setup_editors", get_exec_time()); | 2000 |
1951 work = layout_window_list; | 2001 void layout_editors_reload_finish(void) |
1952 while (work) | 2002 { |
1953 { | 2003 if (layout_editors_reload_idle_id != -1) |
1954 LayoutWindow *lw = work->data; | 2004 { |
1955 work = work->next; | 2005 DEBUG_1("%s layout_editors_reload_finish", get_exec_time()); |
1956 layout_actions_setup_editors(lw); | 2006 g_source_remove(layout_editors_reload_idle_id); |
1957 } | 2007 while (layout_editors_reload_idle_id != -1) |
1958 DEBUG_1("%s layout_editors_reload_all: end", get_exec_time()); | 2008 { |
2009 layout_editors_reload_idle_cb(NULL); | |
2010 } | |
2011 } | |
1959 } | 2012 } |
1960 | 2013 |
1961 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window) | 2014 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window) |
1962 { | 2015 { |
1963 GtkAccelGroup *group; | 2016 GtkAccelGroup *group; |
2030 break; | 2083 break; |
2031 default: | 2084 default: |
2032 break; | 2085 break; |
2033 } | 2086 } |
2034 | 2087 |
2088 | |
2089 if (g_str_has_suffix(action, ".desktop")) | |
2090 { | |
2091 /* this may be called before the external editors are read | |
2092 create a dummy action for now */ | |
2093 | |
2094 if (!lw->action_group_editors) | |
2095 { | |
2096 lw->action_group_editors = gtk_action_group_new("MenuActionsExternal"); | |
2097 gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1); | |
2098 } | |
2099 if (!gtk_action_group_get_action(lw->action_group_editors, action)) | |
2100 { | |
2101 GtkActionEntry entry = { action, | |
2102 GTK_STOCK_MISSING_IMAGE, | |
2103 action, | |
2104 NULL, | |
2105 NULL, | |
2106 NULL }; | |
2107 DEBUG_1("Creating temporary action %s", action); | |
2108 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw); | |
2109 } | |
2110 } | |
2035 gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action, action, GTK_UI_MANAGER_TOOLITEM, FALSE); | 2111 gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action, action, GTK_UI_MANAGER_TOOLITEM, FALSE); |
2036 lw->toolbar_actions[type] = g_list_append(lw->toolbar_actions[type], g_strdup(action)); | 2112 lw->toolbar_actions[type] = g_list_append(lw->toolbar_actions[type], g_strdup(action)); |
2037 } | 2113 } |
2038 | 2114 |
2039 | 2115 |