From 60a96b9d8b1d69d1979c9e290ab019549ef3493f Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 30 Sep 2009 23:02:10 +0200 Subject: [PATCH] Implement 'Open last session' menu item --- midori/main.c | 37 ++++++++++++++++++++++++++++++++++++- midori/midori-browser.c | 9 +++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/midori/main.c b/midori/main.c index 2111c31d..738e7f94 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1350,6 +1350,32 @@ midori_load_extensions (gpointer data) return FALSE; } +static void +midori_browser_action_last_session_activate_cb (GtkAction* action, + MidoriBrowser* browser) +{ + KatzeArray* old_session = katze_array_new (KATZE_TYPE_ITEM); + gchar* config_file = build_config_filename ("session.old.xbel"); + GError* error = NULL; + if (midori_array_from_file (old_session, config_file, "xbel", &error)) + { + guint i = 0; + KatzeItem* item; + while ((item = katze_array_get_nth_item (old_session, i++))) + midori_browser_add_item (browser, item); + } + else + { + g_warning (_("The session couldn't be loaded: %s\n"), error->message); + /* FIXME: Show a graphical dialog */ + g_error_free (error); + } + g_free (config_file); + gtk_action_set_sensitive (action, FALSE); + g_signal_handlers_disconnect_by_func (action, + midori_browser_action_last_session_activate_cb, browser); +} + static gboolean midori_load_session (gpointer data) { @@ -1364,10 +1390,19 @@ midori_load_session (gpointer data) gchar** command = g_object_get_data (G_OBJECT (app), "execute-command"); browser = midori_app_create_browser (app); + config_file = build_config_filename ("session.old.xbel"); + if (g_file_test (config_file, G_FILE_TEST_EXISTS)) + { + GtkActionGroup* action_group = midori_browser_get_action_group (browser); + GtkAction* action = gtk_action_group_get_action (action_group, "LastSession"); + g_signal_connect (action, "activate", + G_CALLBACK (midori_browser_action_last_session_activate_cb), browser); + gtk_action_set_sensitive (action, TRUE); + } midori_app_add_browser (app, browser); gtk_widget_show (GTK_WIDGET (browser)); - config_file = build_config_filename ("accels"); + katze_assign (config_file, build_config_filename ("accels")); if (is_writable (config_file)) g_signal_connect_after (gtk_accel_map_get (), "changed", G_CALLBACK (accel_map_changed_cb), NULL); diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 02975253..ca880138 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2694,6 +2694,10 @@ _action_window_populate_popup (GtkAction* action, GtkWidget* menuitem = gtk_separator_menu_item_new (); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem); gtk_widget_show (menuitem); + menuitem = gtk_action_create_menu_item ( + _action_by_name (browser, "LastSession")); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem); + gtk_widget_show (menuitem); menuitem = gtk_action_create_menu_item ( _action_by_name (browser, "TabCurrent")); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem); @@ -4495,6 +4499,9 @@ static const GtkActionEntry entries[] = { { "TabCurrent", NULL, N_("Focus _Current Tab"), "Home", N_("Focus the current tab"), G_CALLBACK (_action_tab_current_activate) }, + { "LastSession", NULL, + N_("Open last _session"), NULL, + N_("Open the tabs saved in the last session"), NULL }, { "Help", NULL, N_("_Help") }, { "HelpContents", GTK_STOCK_HELP, @@ -4761,6 +4768,7 @@ static const gchar* ui_markup = "" "" "" + "" "" "" "" @@ -5219,6 +5227,7 @@ midori_browser_init (MidoriBrowser* browser) #endif _action_set_sensitive (browser, "EncodingCustom", FALSE); _action_set_sensitive (browser, "SelectionSourceView", FALSE); + _action_set_sensitive (browser, "LastSession", FALSE); /* Create the navigationbar */ browser->navigationbar = gtk_ui_manager_get_widget ( -- 2.39.5