Skip to content

Commit f90c012

Browse files
committed
Merge from 3.x: PR #5221
Fixes #5057
2 parents bdcfd2a + 983aa58 commit f90c012

File tree

5 files changed

+57
-26
lines changed

5 files changed

+57
-26
lines changed

Diff for: spyder/app/mainwindow.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,7 @@ def open_fileswitcher(self, symbol=False):
27922792
return
27932793
if symbol:
27942794
self.fileswitcher.plugin = self.editor
2795+
self.fileswitcher.set_search_text('@')
27952796
else:
27962797
self.fileswitcher.set_search_text('')
27972798
self.fileswitcher.show()
@@ -2800,21 +2801,16 @@ def open_fileswitcher(self, symbol=False):
28002801
def open_symbolfinder(self):
28012802
"""Open symbol list management dialog box."""
28022803
self.open_fileswitcher(symbol=True)
2803-
self.fileswitcher.set_search_text('@')
2804-
self.fileswitcher.setup()
28052804

28062805
def add_to_fileswitcher(self, plugin, tabs, data, icon):
28072806
"""Add a plugin to the File Switcher."""
28082807
if self.fileswitcher is None:
28092808
self.fileswitcher = FileSwitcher(self, plugin, tabs, data, icon)
2810-
self.fileswitcher.sig_goto_file.connect(
2811-
plugin.get_current_tab_manager().set_stack_index
2812-
)
28132809
else:
28142810
self.fileswitcher.add_plugin(plugin, tabs, data, icon)
2815-
self.fileswitcher.sig_goto_file.connect(
2816-
plugin.get_current_tab_manager().set_stack_index
2817-
)
2811+
2812+
self.fileswitcher.sig_goto_file.connect(
2813+
plugin.get_current_tab_manager().set_stack_index)
28182814

28192815
# ---- Check for Spyder Updates
28202816
def _check_updates_ready(self):

Diff for: spyder/plugins/editor.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1328,10 +1328,17 @@ def save_focus_editorstack(self):
13281328
if win.isAncestorOf(editorstack):
13291329
self.set_last_focus_editorstack(win, editorstack)
13301330

1331-
#------ Handling editorstacks
1331+
# ------ Handling editorstacks
13321332
def register_editorstack(self, editorstack):
13331333
self.editorstacks.append(editorstack)
13341334
self.register_widget_shortcuts(editorstack)
1335+
if len(self.editorstacks) > 1 and self.main is not None:
1336+
# The first editostack is registered automatically with Spyder's
1337+
# main window through the `register_plugin` method. Only additional
1338+
# editors added by splitting need to be registered.
1339+
# See Issue #5057.
1340+
self.main.fileswitcher.sig_goto_file.connect(
1341+
editorstack.set_stack_index)
13351342

13361343
if self.isAncestorOf(editorstack):
13371344
# editorstack is a child of the Editor plugin
@@ -2422,11 +2429,11 @@ def go_to_next_cursor_position(self):
24222429
self.__move_cursor_position(1)
24232430

24242431
@Slot()
2425-
def go_to_line(self):
2432+
def go_to_line(self, line=None):
24262433
"""Open 'go to line' dialog"""
24272434
editorstack = self.get_current_editorstack()
24282435
if editorstack is not None:
2429-
editorstack.go_to_line()
2436+
editorstack.go_to_line(line)
24302437

24312438
@Slot()
24322439
def set_or_clear_breakpoint(self):

Diff for: spyder/utils/editor.py

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def goto_line(self, line, column=0, move=True, word=''):
131131
:return: The new text cursor
132132
:rtype: QtGui.QTextCursor
133133
"""
134+
line = min(line, self.line_count())
134135
text_cursor = self._move_cursor_to(line)
135136
if column:
136137
text_cursor.movePosition(text_cursor.Right, text_cursor.MoveAnchor,

Diff for: spyder/widgets/editor.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,15 @@ def get_current_tab_manager(self):
851851
"""Get the widget with the TabWidget attribute."""
852852
return self
853853

854-
def go_to_line(self):
854+
def go_to_line(self, line=None):
855855
"""Go to line dialog"""
856-
if self.data:
857-
self.get_current_editor().exec_gotolinedialog()
856+
if line is not None:
857+
# When this method is called from the flileswitcher, a line
858+
# number is specified, so there is no need for the dialog.
859+
self.get_current_editor().go_to_line(line)
860+
else:
861+
if self.data:
862+
self.get_current_editor().exec_gotolinedialog()
858863

859864
def set_or_clear_breakpoint(self):
860865
"""Set/clear breakpoint"""

Diff for: spyder/widgets/fileswitcher.py

+34-12
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def __init__(self, parent, plugin, tabs, data, icon):
295295
@property
296296
def widgets(self):
297297
widgets = []
298-
for tabs, plugin in self.plugins_tabs:
298+
for plugin in self.plugins_instances:
299+
tabs = self.get_plugin_tabwidget(plugin)
299300
widgets += [(tabs.widget(index), plugin) for
300301
index in range(tabs.count())]
301302
return widgets
@@ -321,14 +322,16 @@ def save_status(self):
321322
@property
322323
def paths(self):
323324
paths = []
324-
for da, icon in self.plugins_data:
325+
for plugin in self.plugins_instances:
326+
da = self.get_plugin_data(plugin)
325327
paths += [getattr(td, 'filename', None) for td in da]
326328
return paths
327329

328330
@property
329331
def filenames(self):
330332
filenames = []
331-
for da, icon in self.plugins_data:
333+
for plugin in self.plugins_instances:
334+
da = self.get_plugin_data(plugin)
332335
filenames += [os.path.basename(getattr(td,
333336
'filename',
334337
None)) for td in da]
@@ -526,18 +529,37 @@ def get_stack_index(self, stack_index, plugin_index):
526529
return real_index
527530

528531
# --- Helper methods: Widget
532+
def get_plugin_data(self, plugin):
533+
"""Get the data object of the plugin's current tab manager."""
534+
# The data object is named "data" in the editor plugin while it is
535+
# named "clients" in the notebook plugin.
536+
try:
537+
data = plugin.get_current_tab_manager().data
538+
except AttributeError:
539+
data = plugin.get_current_tab_manager().clients
540+
541+
return data
542+
543+
def get_plugin_tabwidget(self, plugin):
544+
"""Get the tabwidget of the plugin's current tab manager."""
545+
# The tab widget is named "tabs" in the editor plugin while it is
546+
# named "tabwidget" in the notebook plugin.
547+
try:
548+
tabwidget = plugin.get_current_tab_manager().tabs
549+
except AttributeError:
550+
tabwidget = plugin.get_current_tab_manager().tabwidget
551+
552+
return tabwidget
553+
529554
def get_widget(self, index=None, path=None, tabs=None):
530555
"""Get widget by index.
531-
556+
532557
If no tabs and index specified the current active widget is returned.
533558
"""
534-
if index and tabs:
535-
return tabs.widget(index)
536-
elif path and tabs:
559+
if (index and tabs) or (path and tabs):
537560
return tabs.widget(index)
538561
elif self.plugin:
539-
index = self.plugins_instances.index(self.plugin)
540-
return self.plugins_tabs[index][0].currentWidget()
562+
return self.get_plugin_tabwidget(self.plugin).currentWidget()
541563
else:
542564
return self.plugins_tabs[0][0].currentWidget()
543565

@@ -558,9 +580,8 @@ def goto_line(self, line_number):
558580
"""Go to specified line number in current active editor."""
559581
if line_number:
560582
line_number = int(line_number)
561-
editor = self.get_widget()
562583
try:
563-
editor.go_to_line(min(line_number, editor.get_line_count()))
584+
self.plugin.go_to_line(line_number)
564585
except AttributeError:
565586
pass
566587

@@ -616,6 +637,8 @@ def setup_file_list(self, filter_text, current_path):
616637
# Get optional line number
617638
if trying_for_line_number:
618639
filter_text, line_number = filter_text.split(':')
640+
if line_number == '':
641+
line_number = None
619642
# Get all the available filenames
620643
scores = get_search_scores('', self.filenames,
621644
template="<b>{0}</b>")
@@ -626,7 +649,6 @@ def setup_file_list(self, filter_text, current_path):
626649
scores = get_search_scores(filter_text, self.filenames,
627650
template="<b>{0}</b>")
628651

629-
630652
# Get max width to determine if shortpaths should be used
631653
max_width = self.get_item_size(paths)[0]
632654
self.fix_size(paths)

0 commit comments

Comments
 (0)