Skip to content
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

PR: Create a unique instance of the file switcher attached to the main window #4626

Merged
merged 11 commits into from
Jun 21, 2017
60 changes: 59 additions & 1 deletion spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
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 @@ -322,6 +323,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 @@ -551,6 +555,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 @@ -826,7 +850,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 @@ -2720,6 +2746,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
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,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 @@ -1032,8 +1016,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 @@ -1044,11 +1026,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 @@ -1183,6 +1165,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 @@ -1504,6 +1488,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 @@ -1776,16 +1765,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
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,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
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this instance of the file switcher here? I mean, can we remove it given that we have now a single and global instance?

Copy link
Member Author

@dalthviz dalthviz Jun 20, 2017

Choose a reason for hiding this comment

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

I left this for the windows that the editor could create, but I think it is possible to attach that windows to the file switcher too.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but how is the file switcher called for those windows?

Copy link
Member Author

Choose a reason for hiding this comment

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

As it is in this moment for those windows only by clicking in the action of the menu.

Copy link
Member

Choose a reason for hiding this comment

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

@goanpeca, what do you think? should we leave it or remove it?

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm not a strong opinion either way :-|

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now then ;-)


Expand All @@ -782,6 +783,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 @@ -1104,8 +1109,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
Loading