[gedit] Reopen recently closed tab



commit efc9e8d90b420f5f67aef7800370d0eca10478dd
Author: ghugesagar <ghugesss gmail com>
Date:   Wed Feb 19 17:53:38 2014 +0530

    Reopen recently closed tab
    
    Add a ctrl+shift+T shortcuts that reopens the tab that was most recently
    closed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684377

 gedit/gedit-app.c            |    2 ++
 gedit/gedit-commands-file.c  |   15 +++++++++++++++
 gedit/gedit-commands.h       |    3 +++
 gedit/gedit-window-private.h |    2 ++
 gedit/gedit-window.c         |   38 +++++++++++++++++++++++++++++++++++++-
 gedit/gedit-window.h         |    2 ++
 6 files changed, 61 insertions(+), 1 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index a283adc..dbdba3a 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -505,6 +505,8 @@ gedit_app_startup (GApplication *application)
        gtk_application_add_accelerator (GTK_APPLICATION (application),
                                         "<Primary>T", "win.new-tab", NULL);
        gtk_application_add_accelerator (GTK_APPLICATION (application),
+                                        "<Primary><Shift>T", "win.reopen-closed-tab", NULL);
+       gtk_application_add_accelerator (GTK_APPLICATION (application),
                                         "<Primary>W", "win.close", NULL);
        gtk_application_add_accelerator (GTK_APPLICATION (application),
                                         "<Primary><Shift>W", "win.close-all", NULL);
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index cf3783c..259e4b6 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -489,6 +489,21 @@ _gedit_cmd_file_open (GSimpleAction *action,
        gtk_widget_show (open_dialog);
 }
 
+void
+_gedit_cmd_file_reopen_closed_tab (GSimpleAction *action,
+                                   GVariant      *parameter,
+                                   gpointer      user_data)
+{
+       GeditWindow *window = GEDIT_WINDOW (user_data);
+       GFile *file;
+
+       file = _gedit_window_pop_last_closed_doc (window);
+       if (file != NULL)
+       {
+               gedit_commands_load_location (window, file, NULL, 0, 0);
+       }
+}
+
 /* File saving */
 
 static gboolean
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 9a309e7..e7ea827 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -70,6 +70,9 @@ void          _gedit_cmd_file_save_tab                (GeditTab    *tab,
                                                         GeditWindow *window);
 void           _gedit_cmd_file_save_as_tab             (GeditTab    *tab,
                                                         GeditWindow *window);
+void           _gedit_cmd_file_reopen_closed_tab       (GSimpleAction *action,
+                                                        GVariant      *parameter,
+                                                        gpointer       user_data);
 void           _gedit_cmd_file_save                    (GSimpleAction *action,
                                                          GVariant      *parameter,
                                                          gpointer       user_data);
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index a78d455..14807e1 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -105,6 +105,8 @@ struct _GeditWindowPrivate
 
        gchar          *direct_save_uri;
 
+       GSList         *closed_docs_stack;
+
 #ifdef OS_OSX
        GtkOSXApplicationMenuGroup *mac_menu_group;
 #endif
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 91f7055..9224954 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -1948,6 +1948,9 @@ update_sensitivity_according_to_open_tabs (GeditWindow *window,
        action = g_action_map_lookup_action (G_ACTION_MAP (window), "save-as");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), num_tabs > 0);
 
+       action = g_action_map_lookup_action (G_ACTION_MAP (window), "reopen-closed-tab");
+       g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (window->priv->closed_docs_stack != NULL));
+
        action = g_action_map_lookup_action (G_ACTION_MAP (window), "print");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), num_tabs > 0);
 
@@ -2086,12 +2089,41 @@ on_tab_added (GeditMultiNotebook *multi,
 }
 
 static void
+push_last_closed_doc (GeditWindow   *window,
+                      GeditDocument *doc)
+{
+       GeditWindowPrivate *priv = window->priv;
+       GFile *f;
+
+       f = gedit_document_get_location (doc);
+       if (f != NULL)
+       {
+               priv->closed_docs_stack = g_slist_prepend (priv->closed_docs_stack, f);
+       }
+}
+
+GFile *
+_gedit_window_pop_last_closed_doc (GeditWindow *window)
+{
+       GeditWindowPrivate *priv = window->priv;
+       GFile *f = NULL;
+
+       if (window->priv->closed_docs_stack != NULL)
+       {
+               f = priv->closed_docs_stack->data;
+               priv->closed_docs_stack = g_slist_remove (priv->closed_docs_stack, f);
+       }
+
+       return f;
+}
+
+static void
 on_tab_removed (GeditMultiNotebook *multi,
                GeditNotebook      *notebook,
                GeditTab           *tab,
                GeditWindow        *window)
 {
-       GeditView     *view;
+       GeditView *view;
        GeditDocument *doc;
        gint num_notebooks;
        gint num_tabs;
@@ -2180,6 +2212,8 @@ on_tab_removed (GeditMultiNotebook *multi,
 
        if (!window->priv->dispose_has_run)
        {
+               push_last_closed_doc (window, doc);
+
                if ((!window->priv->removing_tabs &&
                    gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 0) ||
                    num_tabs == 0)
@@ -2667,6 +2701,7 @@ static GActionEntry win_entries[] = {
        { "new-tab", _gedit_cmd_file_new },
        { "open", _gedit_cmd_file_open },
        { "revert", _gedit_cmd_file_revert },
+       { "reopen-closed-tab", _gedit_cmd_file_reopen_closed_tab },
        { "save", _gedit_cmd_file_save },
        { "save-as", _gedit_cmd_file_save_as },
        { "save-all", _gedit_cmd_file_save_all },
@@ -2715,6 +2750,7 @@ gedit_window_init (GeditWindow *window)
        window->priv->dispose_has_run = FALSE;
        window->priv->fullscreen_controls = NULL;
        window->priv->direct_save_uri = NULL;
+       window->priv->closed_docs_stack = NULL;
        window->priv->editor_settings = g_settings_new ("org.gnome.gedit.preferences.editor");
        window->priv->ui_settings = g_settings_new ("org.gnome.gedit.preferences.ui");
 
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index d916477..5f8befb 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -164,6 +164,8 @@ gboolean     _gedit_window_is_fullscreen            (GeditWindow         *window);
 
 GList          *_gedit_window_get_all_tabs             (GeditWindow         *window);
 
+GFile          *_gedit_window_pop_last_closed_doc      (GeditWindow         *window);
+
 /* these are in gedit-window because of screen safety */
 void            _gedit_recent_add                      (GeditWindow         *window,
                                                         GFile               *location,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]