Skip to content

Commit

Permalink
Merge from 3.x: PR #4626
Browse files Browse the repository at this point in the history
Fixes #4575
  • Loading branch information
ccordoba12 committed Jun 21, 2017
2 parents 38411ad + de6e249 commit feb8058
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 92 deletions.
60 changes: 59 additions & 1 deletion spyder/app/mainwindow.py
Expand Up @@ -150,6 +150,7 @@
from spyder.utils.introspection import module_completion
from spyder.utils.programs import is_module_installed
from spyder.utils.misc import select_port
from spyder.widgets.fileswitcher import FileSwitcher

#==============================================================================
# Local gui imports
Expand Down Expand Up @@ -321,6 +322,9 @@ def signal_handler(signum, frame=None):
# Tour # TODO: Should I consider it a plugin?? or?
self.tour = None
self.tours_available = None

# File switcher
self.fileswitcher = None

# Check for updates Thread and Worker, refereces needed to prevent
# segfaulting
Expand Down Expand Up @@ -550,6 +554,26 @@ def setup(self):
"Use next layout")
self.register_shortcut(self.toggle_previous_layout_action, "_",
"Use previous layout")
# File switcher shortcuts
self.file_switcher_action = create_action(
self,
_('File switcher...'),
icon=ima.icon('filelist'),
tip=_('Fast switch between files'),
triggered=self.open_fileswitcher,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.file_switcher_action, context="_",
name="File switcher")
self.symbol_finder_action = create_action(
self, _('Symbol finder...'),
icon=ima.icon('symbol_find'),
tip=_('Fast symbol search in file'),
triggered=self.open_symbolfinder,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.symbol_finder_action, context="_",
name="symbol finder", add_sc_to_tip=True)
self.file_toolbar_actions = [self.file_switcher_action,
self.symbol_finder_action]

def create_edit_action(text, tr_text, icon):
textseq = text.split(' ')
Expand Down Expand Up @@ -825,7 +849,9 @@ def create_edit_action(text, tr_text, icon):
context=Qt.ApplicationShortcut)
self.register_shortcut(restart_action, "_", "Restart")

self.file_menu_actions += [None, restart_action, quit_action]
self.file_menu_actions += [self.file_switcher_action,
self.symbol_finder_action, None,
restart_action, quit_action]
self.set_splash("")

self.debug_print(" ..widgets")
Expand Down Expand Up @@ -2722,6 +2748,38 @@ def show_tour(self, index):
self.tour.set_tour(index, frames, self)
self.tour.start_tour()

# ---- Global File Switcher
def open_fileswitcher(self, symbol=False):
"""Open file list management dialog box."""
if self.fileswitcher is not None and \
self.fileswitcher.is_visible:
self.fileswitcher.hide()
self.fileswitcher.is_visible = False
return
if symbol:
self.fileswitcher.plugin = self.editor
self.fileswitcher.setup()
self.fileswitcher.show()
self.fileswitcher.is_visible = True

def open_symbolfinder(self):
"""Open symbol list management dialog box."""
self.open_fileswitcher(symbol=True)
self.fileswitcher.set_search_text('@')

def add_to_fileswitcher(self, plugin, tabs, data, icon):
"""Add a plugin to the File Switcher."""
if self.fileswitcher is None:
self.fileswitcher = FileSwitcher(self, plugin, tabs, data, icon)
self.fileswitcher.sig_goto_file.connect(
plugin.get_current_tab_manager().set_stack_index
)
else:
self.fileswitcher.add_plugin(plugin, tabs, data, icon)
self.fileswitcher.sig_goto_file.connect(
plugin.get_current_tab_manager().set_stack_index
)

# ---- Check for Spyder Updates
def _check_updates_ready(self):
"""Called by WorkerUpdates when ready"""
Expand Down
45 changes: 12 additions & 33 deletions spyder/plugins/editor.py
Expand Up @@ -665,22 +665,6 @@ def get_plugin_actions(self):
self.register_shortcut(self.open_action, context="Editor",
name="Open file", add_sc_to_tip=True)

self.file_switcher_action = create_action(self, _('File switcher...'),
icon=ima.icon('filelist'),
tip=_('Fast switch between files'),
triggered=self.call_file_switcher,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.file_switcher_action, context="_",
name="File switcher", add_sc_to_tip=True)

self.symbol_finder_action = create_action(self, _('Symbol finder...'),
icon=ima.icon('symbol_find'),
tip=_('Fast symbol search in file'),
triggered=self.call_symbol_finder,
context=Qt.ApplicationShortcut)
self.register_shortcut(self.symbol_finder_action, context="_",
name="symbol finder", add_sc_to_tip=True)

self.revert_action = create_action(self, _("&Revert"),
icon=ima.icon('revert'), tip=_("Revert file from disk"),
triggered=self.revert)
Expand Down Expand Up @@ -1045,8 +1029,6 @@ def get_plugin_actions(self):
self.save_all_action,
save_as_action,
save_copy_as_action,
self.file_switcher_action,
self.symbol_finder_action,
self.revert_action,
MENU_SEPARATOR,
print_preview_action,
Expand All @@ -1057,11 +1039,11 @@ def get_plugin_actions(self):
MENU_SEPARATOR]

self.main.file_menu_actions += file_menu_actions
file_toolbar_actions = [self.new_action, self.open_action,
self.save_action, self.save_all_action,
self.file_switcher_action,
self.symbol_finder_action]
self.main.file_toolbar_actions += file_toolbar_actions
file_toolbar_actions = ([self.new_action, self.open_action,
self.save_action, self.save_all_action] +
self.main.file_toolbar_actions)

self.main.file_toolbar_actions = file_toolbar_actions

# ---- Find menu/toolbar construction ----
self.main.search_menu_actions = [find_action,
Expand Down Expand Up @@ -1197,6 +1179,8 @@ def register_plugin(self):
if not editorstack.data:
self.__load_temp_file()
self.main.add_dockwidget(self)
self.main.add_to_fileswitcher(self, editorstack.tabs, editorstack.data,
ima.icon('TextFileIcon'))

def update_font(self):
"""Update font from Preferences"""
Expand Down Expand Up @@ -1522,6 +1506,11 @@ def set_path(self):
self.introspector.change_extra_path(
self.main.get_spyder_pythonpath())

#------ FileSwitcher API
def get_current_tab_manager(self):
"""Get the widget with the TabWidget attribute."""
return self.get_current_editorstack()

#------ Refresh methods
def refresh_file_dependent_actions(self):
"""Enable/disable file dependent actions
Expand Down Expand Up @@ -1794,16 +1783,6 @@ def edit_template(self):
"""Edit new file template"""
self.load(self.TEMPLATE_PATH)

@Slot()
def call_file_switcher(self):
if self.editorstacks:
self.get_current_editorstack().open_fileswitcher_dlg()

@Slot()
def call_symbol_finder(self):
if self.editorstacks:
self.get_current_editorstack().open_symbolfinder_dlg()

def update_recent_file_menu(self):
"""Update recent file menu"""
recent_files = []
Expand Down
14 changes: 10 additions & 4 deletions spyder/widgets/editor.py
Expand Up @@ -774,9 +774,10 @@ def open_fileswitcher_dlg(self):
self.fileswitcher_dlg.hide()
self.fileswitcher_dlg.is_visible = False
return
self.fileswitcher_dlg = FileSwitcher(self, self.tabs, self.data)
self.fileswitcher_dlg = FileSwitcher(self, self, self.tabs, self.data,
ima.icon('TextFileIcon'))
self.fileswitcher_dlg.sig_goto_file.connect(self.set_stack_index)
self.fileswitcher_dlg.sig_close_file.connect(self.close_file)
self.fileswitcher_dlg.setup()
self.fileswitcher_dlg.show()
self.fileswitcher_dlg.is_visible = True

Expand All @@ -790,6 +791,10 @@ def update_fileswitcher_dlg(self):
if self.fileswitcher_dlg:
self.fileswitcher_dlg.setup()

def get_current_tab_manager(self):
"""Get the widget with the TabWidget attribute."""
return self

def go_to_line(self):
"""Go to line dialog"""
if self.data:
Expand Down Expand Up @@ -1124,8 +1129,9 @@ def get_current_editor(self):
def get_stack_count(self):
return self.tabs.count()

def set_stack_index(self, index):
self.tabs.setCurrentIndex(index)
def set_stack_index(self, index, instance=None):
if instance == self or instance == None:
self.tabs.setCurrentIndex(index)

def set_tabbar_visible(self, state):
self.tabs.tabBar().setVisible(state)
Expand Down

0 comments on commit feb8058

Please sign in to comment.