Skip to content

PR: Add Ctrl+Shift+T shortcut to reopen the last closed Editor tab #3620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@
'max_recent_files': 20,
'save_all_before_run': True,
'focus_to_editor': True,
'onsave_analysis': False
'onsave_analysis': False,
'last_closed_files': []
}),
('historylog',
{
Expand Down
10 changes: 7 additions & 3 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ def __add_recent_file(self, fname):
self.recent_files.insert(0, fname)
if len(self.recent_files) > self.get_option('max_recent_files'):
self.recent_files.pop(-1)

def _clone_file_everywhere(self, finfo):
"""Clone file (*src_editor* widget) in all editorstacks
Cloning from the first editorstack in which every single new editor
Expand Down Expand Up @@ -1945,8 +1945,12 @@ def replace(self):
@Slot()
def open_last_closed(self):
""" Reopens the last closed tab """
file_to_open = self.recent_files[-1]
self.load(file_to_open)
last_closed_files = CONF.get('editor','last_closed_files')
if (len(last_closed_files) > 0):
file_to_open = last_closed_files[0]
last_closed_files.remove(file_to_open)
CONF.set('editor','last_closed_files',last_closed_files)
self.load(file_to_open)

#------ Explorer widget
def close_file_from_name(self, filename):
Expand Down
19 changes: 19 additions & 0 deletions spyder/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
QWidget)

# Local imports
from spyder.config.main import CONF
from spyder.config.base import _, DEBUG, STDERR, STDOUT
from spyder.config.gui import (config_shortcut, fixed_shortcut,
RUN_CELL_SHORTCUT,
Expand Down Expand Up @@ -423,6 +424,9 @@ def __init__(self, parent, actions):
# Local shortcuts
self.shortcuts = self.create_shortcuts()

#For opening last closed tabs
self.last_closed_files = CONF.get('editor', 'last_closed_files')

def create_shortcuts(self):
"""Create local shortcuts"""
# --- Configurable shortcuts
Expand Down Expand Up @@ -1168,6 +1172,9 @@ def close_file(self, index=None, force=False):
new_index -= 1
self.set_stack_index(new_index)

self.add_last_closed_file(finfo.filename)
print("ultimosss:", self.last_closed_files)

if self.get_stack_count() == 0 and self.create_new_file_if_empty:
self.sig_new_file[()].emit()
return False
Expand All @@ -1191,6 +1198,18 @@ def close_all_but_this(self):
self.close_all_right()
for i in range(0, self.get_stack_count()-1 ):
self.close_file(0)

def add_last_closed_file(self, fname):
"""Add to last closed file list"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings are sentences so a . is needed at the end :-)

"""Add to last closed file list."""

if fname is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this if really needed?

return
if fname in self.last_closed_files:
self.last_closed_files.remove(fname)
self.last_closed_files.insert(0, fname)
if len(self.last_closed_files) > CONF.get('editor','max_recent_files'):
self.last_closed_files.pop(-1)
CONF.set('editor', 'last_closed_files', self.last_closed_files)
print("last closed files:", [rf.split("/")[-1] for rf in self.last_closed_files])

#------ Save
def save_if_changed(self, cancelable=False, index=None):
Expand Down