Skip to content

Commit baecbf6

Browse files
committed
Merge from 3.x: PR #3620
Fixes #2415
2 parents 46c9dbd + 1003be3 commit baecbf6

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

Diff for: spyder/config/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@
404404
'editor/go to previous file': 'Ctrl+Tab',
405405
'editor/go to next file': 'Ctrl+Shift+Tab',
406406
'editor/new file': "Ctrl+N",
407+
'editor/open last closed':"Ctrl+Shift+T",
407408
'editor/open file': "Ctrl+O",
408409
'editor/save file': "Ctrl+S",
409410
'editor/save all': "Ctrl+Alt+S",

Diff for: spyder/plugins/editor.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from spyder.utils import codeanalysis, encoding, programs, sourcecode
3939
from spyder.utils import icon_manager as ima
4040
from spyder.utils.introspection.manager import IntrospectionManager
41-
from spyder.utils.qthelpers import add_actions, create_action
41+
from spyder.utils.qthelpers import create_action, add_actions
4242
from spyder.widgets.findreplace import FindReplace
4343
from spyder.widgets.editor import (EditorMainWindow, EditorSplitter,
4444
EditorStack, Printer)
@@ -633,6 +633,12 @@ def get_plugin_actions(self):
633633
self.register_shortcut(self.new_action, context="Editor",
634634
name="New file", add_sc_to_tip=True)
635635

636+
self.open_last_closed_action = create_action(self, _("O&pen last closed"),
637+
tip=_("Open last closed"),
638+
triggered=self.open_last_closed)
639+
self.register_shortcut(self.open_last_closed_action, context="Editor",
640+
name="Open last closed")
641+
636642
self.open_action = create_action(self, _("&Open..."),
637643
icon=ima.icon('fileopen'), tip=_("Open file"),
638644
triggered=self.load,
@@ -984,6 +990,7 @@ def get_plugin_actions(self):
984990
file_menu_actions = [self.new_action,
985991
None,
986992
self.open_action,
993+
self.open_last_closed_action,
987994
self.recent_file_menu,
988995
None,
989996
None,
@@ -1614,7 +1621,7 @@ def __add_recent_file(self, fname):
16141621
self.recent_files.insert(0, fname)
16151622
if len(self.recent_files) > self.get_option('max_recent_files'):
16161623
self.recent_files.pop(-1)
1617-
1624+
16181625
def _clone_file_everywhere(self, finfo):
16191626
"""Clone file (*src_editor* widget) in all editorstacks
16201627
Cloning from the first editorstack in which every single new editor
@@ -1948,7 +1955,17 @@ def replace(self):
19481955
"""Replace slot"""
19491956
editorstack = self.get_current_editorstack()
19501957
editorstack.find_widget.show_replace()
1951-
1958+
1959+
def open_last_closed(self):
1960+
""" Reopens the last closed tab."""
1961+
editorstack = self.get_current_editorstack()
1962+
last_closed_files = editorstack.get_last_closed_files()
1963+
if (len(last_closed_files) > 0):
1964+
file_to_open = last_closed_files[0]
1965+
last_closed_files.remove(file_to_open)
1966+
editorstack.set_last_closed_files(last_closed_files)
1967+
self.load(file_to_open)
1968+
19521969
#------ Explorer widget
19531970
def close_file_from_name(self, filename):
19541971
"""Close file from its name"""

Diff for: spyder/widgets/editor.py

+19
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ def __init__(self, parent, actions):
421421
# Local shortcuts
422422
self.shortcuts = self.create_shortcuts()
423423

424+
#For opening last closed tabs
425+
self.last_closed_files = []
426+
424427
def create_shortcuts(self):
425428
"""Create local shortcuts"""
426429
# --- Configurable shortcuts
@@ -1189,6 +1192,8 @@ def close_file(self, index=None, force=False):
11891192
new_index -= 1
11901193
self.set_stack_index(new_index)
11911194

1195+
self.add_last_closed_file(finfo.filename)
1196+
11921197
if self.get_stack_count() == 0 and self.create_new_file_if_empty:
11931198
self.sig_new_file[()].emit()
11941199
return False
@@ -1212,6 +1217,20 @@ def close_all_but_this(self):
12121217
self.close_all_right()
12131218
for i in range(0, self.get_stack_count()-1 ):
12141219
self.close_file(0)
1220+
1221+
def add_last_closed_file(self, fname):
1222+
"""Add to last closed file list."""
1223+
if fname in self.last_closed_files:
1224+
self.last_closed_files.remove(fname)
1225+
self.last_closed_files.insert(0, fname)
1226+
if len(self.last_closed_files) > 10:
1227+
self.last_closed_files.pop(-1)
1228+
1229+
def get_last_closed_files(self):
1230+
return self.last_closed_files
1231+
1232+
def set_last_closed_files(self, fnames):
1233+
self.last_closed_files = fnames
12151234

12161235
#------ Save
12171236
def save_if_changed(self, cancelable=False, index=None):

0 commit comments

Comments
 (0)