From: John Darrington Date: Tue, 3 Apr 2007 10:08:59 +0000 (+0000) Subject: Implemented the recently used files menus. X-Git-Tag: v0.6.0~506 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe3a0a8896cc9f099196f0d0228bb0cfa688c34a;p=pspp-builds.git Implemented the recently used files menus. --- diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index b2790bf1..3a578f7e 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,9 @@ +2007-04-03 John Darrington + + * data-editor.c data-editor.glade helper.h syntax-editor.c + syntax-editor.h : Implemented the File->Recently_Used_ menus. + + 2007-03-31 John Darrington * data-editor.c data-editor.glade data-editor.h dialog-common.c diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 81ebfb3c..5a0f8358 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -54,6 +54,7 @@ static void register_data_editor_actions (struct data_editor *de); static void insert_variable (GtkCheckMenuItem *m, gpointer data); + /* Switch between the VAR SHEET and the DATA SHEET */ enum {PAGE_DATA_SHEET = 0, PAGE_VAR_SHEET}; @@ -115,6 +116,56 @@ disable_edit_clear (GtkWidget *w, gint x, gint y, gpointer data) return FALSE; } +static void open_data_file (const gchar *, struct data_editor *); + + + +#if RECENT_LISTS_AVAILABLE + +static void +on_recent_data_select (GtkMenuShell *menushell, gpointer user_data) +{ + gchar *file; + + struct data_editor *de = user_data; + + gchar *uri = + gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell)); + + file = g_filename_from_uri (uri, NULL, NULL); + + g_free (uri); + + open_data_file (file, de); + + g_free (file); +} + +static void +on_recent_files_select (GtkMenuShell *menushell, gpointer user_data) +{ + gchar *file; + + struct syntax_editor *se ; + + gchar *uri = + gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell)); + + file = g_filename_from_uri (uri, NULL, NULL); + + g_free (uri); + + se = (struct syntax_editor *) + window_create (WINDOW_SYNTAX, file); + + load_editor_from_file (se, file, NULL); + + g_free (file); +} + +#endif + + /* Create a new data editor. @@ -211,6 +262,45 @@ new_data_editor (void) G_CALLBACK (gtk_action_activate), de->action_data_open); + +#if RECENT_LISTS_AVAILABLE + { + GtkRecentManager *rm = gtk_recent_manager_get_default (); + GtkWidget *recent_data = get_widget_assert (de->xml, "file_recent-data"); + GtkWidget *recent_files = get_widget_assert (de->xml, "file_recent-files"); + + GtkWidget *menu = gtk_recent_chooser_menu_new_for_manager (rm); + + GtkRecentFilter *filter = gtk_recent_filter_new (); + + gtk_recent_filter_add_pattern (filter, "*.sav"); + gtk_recent_filter_add_pattern (filter, "*.SAV"); + + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter); + + gtk_widget_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); + + + filter = gtk_recent_filter_new (); + menu = gtk_recent_chooser_menu_new_for_manager (rm); + + 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_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); + } +#endif + g_signal_connect (get_widget_assert (de->xml,"file_new_syntax"), "activate", G_CALLBACK (new_syntax_window), @@ -1009,6 +1099,26 @@ new_file (GtkAction *action, struct editor_window *e) } +static void +open_data_file (const gchar *file_name, struct data_editor *de) +{ + struct getl_interface *sss; + struct string filename; + + ds_init_cstr (&filename, file_name); + + gen_quoted_string (&filename); + + sss = create_syntax_string_source ("GET FILE=%s.", + ds_cstr (&filename)); + + execute_syntax (sss); + ds_destroy (&filename); + + window_set_name_from_filename ((struct editor_window *) de, file_name); +} + + /* Callback for the data_open action. Prompts for a filename and opens it */ static void @@ -1045,23 +1155,24 @@ open_data_dialog (GtkAction *action, struct data_editor *de) { case GTK_RESPONSE_ACCEPT: { - struct getl_interface *sss; - struct string filename; g_free (de->file_name); de->file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - ds_init_cstr (&filename, de->file_name); + open_data_file (de->file_name, de); - gen_quoted_string (&filename); +#if RECENT_LISTS_AVAILABLE + { + GtkRecentManager *manager = gtk_recent_manager_get_default(); + gchar *uri = g_filename_to_uri (de->file_name, NULL, NULL); - sss = create_syntax_string_source ("GET FILE=%s.", - ds_cstr (&filename)); + if ( ! gtk_recent_manager_add_item (manager, uri)) + g_warning ("Could not add item %s to recent list\n",uri); - execute_syntax (sss); - ds_destroy (&filename); + g_free (uri); + } +#endif - window_set_name_from_filename (e, de->file_name); } break; default: @@ -1070,7 +1181,3 @@ open_data_dialog (GtkAction *action, struct data_editor *de) gtk_widget_destroy (dialog); } - - - - diff --git a/src/ui/gui/data-editor.glade b/src/ui/gui/data-editor.glade index 71e977be..8761fc93 100644 --- a/src/ui/gui/data-editor.glade +++ b/src/ui/gui/data-editor.glade @@ -87,6 +87,28 @@ True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Recently Used Da_ta + True + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Recently Used _Files + True + + True @@ -442,13 +464,12 @@ True False Recall - pspp-recent-dialogs + gtk-missing-image False - True @@ -664,25 +685,25 @@ 1 2 - + True - True + False + False + 25 - 1 - 2 + GTK_FILL - + True - False - False - 25 + True - GTK_FILL + 1 + 2 @@ -1213,63 +1234,63 @@ 2 1 - + True - - - True - Width: - GTK_JUSTIFY_RIGHT - - - False - False - GTK_PACK_END - - + 0 + Decimal Places: + GTK_JUSTIFY_RIGHT + 1 + 2 GTK_FILL - GTK_FILL + - + 25 - True True 1 2 - 1 - 2 - + 25 + True True 1 2 + 1 + 2 - + True - 0 - Decimal Places: - GTK_JUSTIFY_RIGHT + + + True + Width: + GTK_JUSTIFY_RIGHT + + + False + False + GTK_PACK_END + + - 1 - 2 GTK_FILL - + GTK_FILL @@ -1356,28 +1377,50 @@ 2 5 - + True - True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_ETCHED_IN + 5 - + True + False True - False - False + True + gtk-add + True + + + + + True + False + True + True + gtk-apply + True + + + 1 + + + + + True + False + True + True + gtk-remove + True + + 2 + - 1 - 2 1 2 GTK_FILL - GTK_FILL @@ -1389,63 +1432,63 @@ 5 4 - + True - - - 85 - True - True - - - False - False - 1 - - + 0 + Value: - 1 - 2 GTK_FILL - GTK_FILL + - + True - True + 0 + Value Label: - 1 - 2 1 2 + GTK_FILL - + True - 0 - Value Label: + True + 1 + 2 1 2 - GTK_FILL - + True - 0 - Value: + + + 85 + True + True + + + False + False + 1 + + + 1 + 2 GTK_FILL - + GTK_FILL @@ -1455,50 +1498,28 @@ - + True - 5 - - - True - False - True - True - gtk-add - True - - - - - True - False - True - True - gtk-apply - True - - - 1 - - + True + GTK_POLICY_NEVER + GTK_POLICY_AUTOMATIC + GTK_SHADOW_ETCHED_IN - + True - False True - True - gtk-remove - True + False + False - - 2 - + 1 + 2 1 2 GTK_FILL + GTK_FILL @@ -1584,143 +1605,48 @@ 2 2 - + True + 5 + 5 + GTK_BUTTONBOX_START - + True True - _Range plus one optional discrete missing value - True - False - True - no_missing + True + gtk-ok + True + + + + + True + True + True + gtk-cancel + True - False - False + 1 - + True - 5 - - - True - - - True - - - True - _Low: - True - mv-low - - - False - False - 20 - - - - - 75 - True - True - - - False - 1 - - - - - - - True - - - True - _High: - True - mv-high - - - False - False - - - - - 75 - True - True - - - 5 - 1 - - - - - False - 20 - 1 - - - - - - - - - - - - - True - - - True - Di_screte value: - True - mv-discrete - - - False - False - 20 - - - - - 75 - True - True - - - False - 1 - - - - - 1 - - + True + True + gtk-help + True - 1 + 2 + 1 2 - 1 - 2 - GTK_FILL @@ -1826,48 +1752,143 @@ - + True - 5 - 5 - GTK_BUTTONBOX_START - - - True - True - True - gtk-ok - True - - - + True True - True - gtk-cancel - True + _Range plus one optional discrete missing value + True + False + True + no_missing - 1 + False + False - + True - True - True - gtk-help - True + 5 + + + True + + + True + + + True + _Low: + True + mv-low + + + False + False + 20 + + + + + 75 + True + True + + + False + 1 + + + + + + + True + + + True + _High: + True + mv-high + + + False + False + + + + + 75 + True + True + + + 5 + 1 + + + + + False + 20 + 1 + + + + + + + + + + + + + True + + + True + Di_screte value: + True + mv-discrete + + + False + False + 20 + + + + + 75 + True + True + + + False + 1 + + + + + 1 + + - 2 + 1 - 1 2 + 1 + 2 + GTK_FILL diff --git a/src/ui/gui/helper.h b/src/ui/gui/helper.h index 079f6d92..038eeb2f 100644 --- a/src/ui/gui/helper.h +++ b/src/ui/gui/helper.h @@ -29,6 +29,15 @@ #include #include + +/* + GtkRecentChooserMenu was added in 2.10.0 + but it didn't support GtkRecentFilters until + 2.10.2 +*/ +#define RECENT_LISTS_AVAILABLE GTK_CHECK_VERSION (2, 10, 2) + + /* Formats a value according to FORMAT The returned string must be freed when no longer required */ gchar * value_to_text (union value v, struct fmt_spec format); diff --git a/src/ui/gui/syntax-editor.c b/src/ui/gui/syntax-editor.c index 024181e6..fc9a4401 100644 --- a/src/ui/gui/syntax-editor.c +++ b/src/ui/gui/syntax-editor.c @@ -466,7 +466,7 @@ save_editor_to_file (struct syntax_editor *se, /* Loads the buffer from the file called FILENAME */ -static gboolean +gboolean load_editor_from_file (struct syntax_editor *se, const gchar *filename, GError **err) @@ -492,6 +492,9 @@ load_editor_from_file (struct syntax_editor *se, gtk_text_buffer_insert (buffer, &iter, text, -1); + + + window_set_name_from_filename ((struct editor_window *)se, filename); gtk_text_buffer_set_modified (buffer, FALSE); @@ -536,6 +539,19 @@ open_syntax_window (GtkMenuItem *menuitem, gpointer parent) window_create (WINDOW_SYNTAX, file_name); load_editor_from_file (se, file_name, NULL); + +#if RECENT_LISTS_AVAILABLE + { + GtkRecentManager *manager = gtk_recent_manager_get_default(); + gchar *uri = g_filename_to_uri (file_name, NULL, NULL); + + if ( ! gtk_recent_manager_add_item (manager, uri)) + g_warning ("Could not add item %s to recent list\n",uri); + + g_free (uri); + } +#endif + } gtk_widget_destroy (dialog); diff --git a/src/ui/gui/syntax-editor.h b/src/ui/gui/syntax-editor.h index 0d366831..7e8a40e2 100644 --- a/src/ui/gui/syntax-editor.h +++ b/src/ui/gui/syntax-editor.h @@ -41,5 +41,7 @@ void new_syntax_window (GtkMenuItem *, gpointer); void open_syntax_window (GtkMenuItem *, gpointer); - +gboolean load_editor_from_file (struct syntax_editor *se, + const gchar *filename, + GError **err); #endif