-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :-|
There was a problem hiding this comment.
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 ;-)
Please merge with 3.x to fix errors in our tests. |
spyder/app/mainwindow.py
Outdated
self.open_fileswitcher_dlg() | ||
self.fileswitcher_dlg.set_search_text('@') | ||
|
||
def add_to_fileswitcher(self, tabs, data, plugin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be data
for the Notebook or the IPython console?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's None
, so in this case we should change the signature of this function to be
def add_to_fileswitcher(self, plugin, tabs, data=None):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the Notebook data
is self.clients
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then let's change the signature anyway to be
def add_to_fileswitcher(self, plugin, tabs, data)
spyder/widgets/fileswitcher.py
Outdated
|
||
# Constants that define the mode in which the list widget is working | ||
# FILE_MODE is for a list of files, SYMBOL_MODE if for a list of symbols | ||
# in a given file when using the '@' symbol. | ||
FILE_MODE, SYMBOL_MODE = [1, 2] | ||
|
||
def __init__(self, parent, tabs, data): | ||
def __init__(self, parent, tabs, data, plugin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to be
def __init__(self, parent, plugin, tabs, data):
spyder/app/mainwindow.py
Outdated
|
||
def add_to_fileswitcher(self, plugin, tabs, data): | ||
"""Add a plugin to the File Switcher.""" | ||
if self.fileswitcher_dlg == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention when comparing with None
is:
if self.fileswitcher_dlg is None:
Please change it to be this way.
spyder/widgets/fileswitcher.py
Outdated
return [getattr(td, 'newly_created', False) for td in self.data] | ||
return [getattr(td, | ||
'newly_created', | ||
False) for da in self.plugins_data for td in da] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too complex to have it as list comprehension. Please simplify it using two list comprehensions instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this would work?:
save_status = []
for da in self.plugins_data:
save_status += [getattr(td, 'newly_created', False) for td in da]
return save_status
Also, I should do this for the widgets
, paths
and filenames
properties, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that works too.
Also, I should do this for the widgets, paths and filenames properties, right?
Yep.
spyder/widgets/fileswitcher.py
Outdated
return [getattr(td, 'filename', None) for td in self.data] | ||
return [getattr(td, | ||
'filename', | ||
None) for da in self.plugins_data for td in da] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment applies here: please use two list comprehensions.
spyder/widgets/fileswitcher.py
Outdated
@@ -335,13 +340,13 @@ def set_search_text(self, _str): | |||
self.edit.setText(_str) | |||
|
|||
def save_initial_state(self): | |||
"""Saves initial cursors and initial active editor.""" | |||
"""Saves initial cursors and initial active widget.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saves -> Save
spyder/app/mainwindow.py
Outdated
@@ -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_dlg = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileswitcher_dlg -> fileswitcher
spyder/app/mainwindow.py
Outdated
@@ -2720,6 +2745,36 @@ def show_tour(self, index): | |||
self.tour.set_tour(index, frames, self) | |||
self.tour.start_tour() | |||
|
|||
# ---- Global File Switcher | |||
def open_fileswitcher_dlg(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open_fileswitcher_dlg -> open_fileswitcher
spyder/app/mainwindow.py
Outdated
self.fileswitcher_dlg.show() | ||
self.fileswitcher_dlg.is_visible = True | ||
|
||
def open_symbolfinder_dlg(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open_symbolfinder_dlg -> open_symbolfinder
spyder/widgets/editor.py
Outdated
@@ -766,9 +766,9 @@ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileswitcher_dlg -> fileswitcher
@dalthviz, I also think we need to define here a different icon for the files/tabs of each plugin. So when a plugin registers to the file switcher, it needs to tell it which icon is going to use. For now let's use these icons:
|
spyder/plugins/editor.py
Outdated
@@ -1183,6 +1164,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, | |||
icon='TextFileIcon') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be the name of the icon, but the icon returned by our icon manager, i.e.
icon=ima.icon('TextFileIcon'))
Please change this to reflect that.
The last thing to address here is that now we can increase the number of characters displayed in each file path. That number is determined in the @dalthviz, please play with that function to see if you can improve it to display more characters. |
spyder/widgets/fileswitcher.py
Outdated
title = self.widgets[index][1].get_plugin_title().split(' - ') | ||
if plugin != title[0]: | ||
plugin = title[0] | ||
text += '<big><b>' + plugin + '</b></big><br>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some vertical separation between the plugin title and its list of files/tabs.
@dalthviz, please post a screenshot to see how is this looking :-) |
spyder/app/mainwindow.py
Outdated
def open_symbolfinder(self): | ||
"""Open symbol list management dialog box.""" | ||
self.open_fileswitcher() | ||
self.fileswitcher.set_search_text('@') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When opening the symbol switcher we should give focus to the Editor because it has no meaning for the other plugins, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Why don't the icons for the file and symbol switchers appear in the File toolbar in your screenshot? |
I didn't add the actions in the |
I think this is ready, great work @dalthviz! |
Fixes #4575
A plugin could be attached to the file switcher by using the
add_to_fileswitcher
method of the Main Window. Also, the plugin needs to implement two methods:get_current_tab_manager
andset_stack_index
method. Theset_stack_index
method should be placed in the widget that manages the tabs.