Commit efc9e8d9 authored by ghugesagar's avatar ghugesagar Committed by Paolo Borelli

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
parent a2a37bec
......@@ -504,6 +504,8 @@ gedit_app_startup (GApplication *application)
"<Primary><Shift>L", "win.save-all", NULL);
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),
......
......@@ -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
......
......@@ -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);
......
......@@ -105,6 +105,8 @@ struct _GeditWindowPrivate
gchar *direct_save_uri;
GSList *closed_docs_stack;
#ifdef OS_OSX
GtkOSXApplicationMenuGroup *mac_menu_group;
#endif
......
......@@ -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);
......@@ -2085,13 +2088,42 @@ on_tab_added (GeditMultiNotebook *multi,
g_signal_emit (G_OBJECT (window), signals[TAB_ADDED], 0, tab);
}
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");
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment