From: John Darrington Date: Mon, 2 Mar 2009 10:47:07 +0000 (+0900) Subject: Rewrote the recent file manager stuff X-Git-Tag: v0.7.3~268 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55077868a3eb1776432bcb46a3627cc8e0ee54db;p=pspp-builds.git Rewrote the recent file manager stuff --- diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index e2424cf0..b17b1913 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -314,13 +314,34 @@ on_weight_change (GObject *o, gint weight_index, gpointer data) } } -/* Puts FILE_NAME into the recent list. - If it's already in the list, it moves it to the top -*/ +#if 0 static void -add_most_recent (const char *file_name) +dump_rm (GtkRecentManager *rm) { + GList *items = gtk_recent_manager_get_items (rm); + + GList *i; + + g_print ("Recent Items:\n"); + for (i = items; i; i = i->next) + { + GtkRecentInfo *ri = i->data; + + g_print ("Item: %s (Mime: %s) (Desc: %s) (URI: %s)\n", + gtk_recent_info_get_short_name (ri), + gtk_recent_info_get_mime_type (ri), + gtk_recent_info_get_description (ri), + gtk_recent_info_get_uri (ri) + ); + + + gtk_recent_info_unref (ri); + } + + g_list_free (items); } +#endif + void psppire_data_window_load_file (PsppireDataWindow *de, @@ -339,7 +360,7 @@ psppire_data_window_load_file (PsppireDataWindow *de, if (execute_syntax (sss) ) { psppire_window_set_filename (PSPPIRE_WINDOW (de), file_name); - add_most_recent (file_name); + add_most_recent (file_name, the_recent_mgr); } psppire_window_set_unsaved (PSPPIRE_WINDOW (de), FALSE); @@ -872,7 +893,8 @@ create_var_sheet_variable_popup_menu (PsppireDataWindow *de) static void -on_recent_data_select (GtkMenuShell *menushell, gpointer user_data) +on_recent_data_select (GtkMenuShell *menushell, + gpointer user_data) { gchar *file; PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data); @@ -1563,53 +1585,56 @@ psppire_data_window_init (PsppireDataWindow *de) G_CALLBACK (regression_dialog), de); } - -#if 0 { - GtkRecentManager *rm = gtk_recent_manager_get_default (); - GtkAction *recent_data = get_action_assert (de->builder, "file_recent-data"); - GtkAction *recent_files = get_action_assert (de->builder, "file_recent-files"); -#if 0 - GtkWidget *recent_separator = get_widget_assert (de->builder, "file_separator1"); -#endif + GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER)); - GtkWidget *menu = gtk_recent_chooser_menu_new_for_manager (rm); + GtkWidget *recent_data = + gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-data"); - GtkRecentFilter *filter = gtk_recent_filter_new (); + GtkWidget *recent_files = + gtk_ui_manager_get_widget (uim,"/ui/menubar/file/file_recent-files"); -#if 0 - gtk_widget_show (recent_data); - gtk_widget_show (recent_files); - gtk_widget_show (recent_separator); -#endif - gtk_recent_filter_add_pattern (filter, "*.sav"); - gtk_recent_filter_add_pattern (filter, "*.SAV"); + GtkWidget *menu_data = + gtk_recent_chooser_menu_new_for_manager (the_recent_mgr); + + GtkWidget *menu_files = + gtk_recent_chooser_menu_new_for_manager (the_recent_mgr); + + { + GtkRecentFilter *filter = gtk_recent_filter_new (); + + gtk_recent_filter_add_pattern (filter, "*.sav"); + gtk_recent_filter_add_pattern (filter, "*.SAV"); + gtk_recent_filter_add_pattern (filter, "*.por"); + gtk_recent_filter_add_pattern (filter, "*.POR"); - gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_data), filter); + } - gtk_action_set_sensitive (recent_data, TRUE); - g_signal_connect (menu, "selection-done", - G_CALLBACK (on_recent_data_select), de); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu_data); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_data), menu); + g_signal_connect (menu_data, "selection-done", + G_CALLBACK (on_recent_data_select), + de); - filter = gtk_recent_filter_new (); - menu = gtk_recent_chooser_menu_new_for_manager (rm); + { + GtkRecentFilter *filter = gtk_recent_filter_new (); - gtk_recent_filter_add_pattern (filter, "*.sps"); - gtk_recent_filter_add_pattern (filter, "*.SPS"); + gtk_recent_filter_add_pattern (filter, "*.sps"); + gtk_recent_filter_add_pattern (filter, "*.SPS"); - gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu_files), filter); + } - gtk_widget_set_sensitive (recent_files, TRUE); - g_signal_connect (menu, "selection-done", - G_CALLBACK (on_recent_files_select), de); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu_files); + + g_signal_connect (menu_files, "selection-done", + G_CALLBACK (on_recent_files_select), + de); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (recent_files), menu); } -#endif g_signal_connect (get_action_assert (de->builder,"file_new_syntax"), "activate", diff --git a/src/ui/gui/psppire-output-window.c b/src/ui/gui/psppire-output-window.c index 3e6b2e44..7f7d2765 100644 --- a/src/ui/gui/psppire-output-window.c +++ b/src/ui/gui/psppire-output-window.c @@ -248,7 +248,7 @@ psppire_output_window_init (PsppireOutputWindow *window) NULL); { - GtkUIManager *uim = GTK_UI_MANAGER (get_action_assert (xml, "uimanager1")); + GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER)); PSPPIRE_WINDOW (window)->menu = GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar1/windows_menuitem/windows_minimise-all")->parent); diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index ae9c1a42..b735f35c 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -28,6 +28,7 @@ #include "psppire-data-window.h" #include "psppire-window-register.h" +#include "psppire.h" #include "about.h" #include "psppire-syntax-window.h" #include "syntax-editor-source.h" @@ -395,7 +396,9 @@ open_syntax_window (GtkMenuItem *menuitem, gpointer parent) GtkWidget *se = psppire_syntax_window_new (); if ( psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file_name, NULL) ) - ; + { + add_most_recent (file_name, the_recent_mgr); + } gtk_widget_show (se); } @@ -527,7 +530,7 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window) { - GtkUIManager *uim = GTK_UI_MANAGER (get_action_assert (xml, "uimanager1")); + GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER)); PSPPIRE_WINDOW (window)->menu = GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar2/windows/windows_minimise_all")->parent); diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index b7529ed0..407ba973 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -545,3 +546,19 @@ psppire_window_save (PsppireWindow *w) i->save (w); } + + +/* Puts FILE_NAME into the recent list. + If it's already in the list, it moves it to the top +*/ +void +add_most_recent (const char *file_name, GtkRecentManager *rm) +{ + gchar *uri = g_filename_to_uri (file_name, NULL, NULL); + + if ( uri ) + gtk_recent_manager_add_item (rm, uri); + + g_free (uri); +} + diff --git a/src/ui/gui/psppire-window.h b/src/ui/gui/psppire-window.h index 88574293..e3da271e 100644 --- a/src/ui/gui/psppire-window.h +++ b/src/ui/gui/psppire-window.h @@ -24,6 +24,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -106,6 +107,9 @@ gint psppire_window_query_save (PsppireWindow *); void psppire_window_save (PsppireWindow *w); +void add_most_recent (const char *file_name, GtkRecentManager *rm); + + G_END_DECLS #endif /* __PSPPIRE_WINDOW_H__ */ diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index 8a23346c..dbba57b6 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -60,6 +60,7 @@ #include +GtkRecentManager *the_recent_mgr = 0; PsppireDataStore *the_data_store = 0; PsppireVarStore *the_var_store = 0; @@ -147,6 +148,9 @@ initialize (struct command_line_processor *clp, int argc, char **argv) journal_enable (); textdomain (PACKAGE); + + the_recent_mgr = gtk_recent_manager_get_default (); + the_data_window = psppire_data_window_new (); command_line_processor_replace_aux (clp, &post_init_argp, the_source_stream); diff --git a/src/ui/gui/psppire.h b/src/ui/gui/psppire.h index a2cba9bb..0d990119 100644 --- a/src/ui/gui/psppire.h +++ b/src/ui/gui/psppire.h @@ -22,6 +22,7 @@ struct command_line_processor ; extern const struct argp non_option_argp ; +extern GtkRecentManager *the_recent_mgr; void initialize (struct command_line_processor *, int argc, char **argv); void de_initialize (void);