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

Conversation

dalthviz
Copy link
Member

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 and set_stack_index method. The set_stack_index method should be placed in the widget that manages the tabs.

@dalthviz dalthviz added this to the v3.2 milestone Jun 20, 2017
@dalthviz dalthviz self-assigned this Jun 20, 2017
@dalthviz dalthviz requested review from ccordoba12 and goanpeca June 20, 2017 21:08
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 ;-)

@ccordoba12
Copy link
Member

Please merge with 3.x to fix errors in our tests.

@ccordoba12 ccordoba12 changed the title PR: Unique instance of the file switcher PR: Create a unique instance of the file switcher attached to the main window Jun 20, 2017
self.open_fileswitcher_dlg()
self.fileswitcher_dlg.set_search_text('@')

def add_to_fileswitcher(self, tabs, data, plugin):
Copy link
Member

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?

Copy link
Member

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):

Copy link
Member Author

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

Copy link
Member

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)


# 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):
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 change this to be

def __init__(self, parent, plugin, tabs, data):


def add_to_fileswitcher(self, plugin, tabs, data):
"""Add a plugin to the File Switcher."""
if self.fileswitcher_dlg == None:
Copy link
Member

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.

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]
Copy link
Member

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.

Copy link
Member Author

@dalthviz dalthviz Jun 21, 2017

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?

Copy link
Member

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.

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]
Copy link
Member

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.

@@ -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."""
Copy link
Member

Choose a reason for hiding this comment

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

Saves -> Save

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

fileswitcher_dlg -> fileswitcher

@@ -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):
Copy link
Member

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

self.fileswitcher_dlg.show()
self.fileswitcher_dlg.is_visible = True

def open_symbolfinder_dlg(self):
Copy link
Member

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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

fileswitcher_dlg -> fileswitcher

@ccordoba12
Copy link
Member

@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:

  1. TextFileIcon for the Editor.
  2. FileIcon for the Notebook.
  3. ipython_console for our consoles (when we implement this, so not for this PR).

@@ -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')
Copy link
Member

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.

@ccordoba12
Copy link
Member

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 shorten_paths function of widgets/fileswitcher.py.

@dalthviz, please play with that function to see if you can improve it to display more characters.

title = self.widgets[index][1].get_plugin_title().split(' - ')
if plugin != title[0]:
plugin = title[0]
text += '<big><b>' + plugin + '</b></big><br>'
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 add some vertical separation between the plugin title and its list of files/tabs.

@ccordoba12
Copy link
Member

@dalthviz, please post a screenshot to see how is this looking :-)

def open_symbolfinder(self):
"""Open symbol list management dialog box."""
self.open_fileswitcher()
self.fileswitcher.set_search_text('@')
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@dalthviz
Copy link
Member Author

Preview:

fileswitch

@ccordoba12
Copy link
Member

Why don't the icons for the file and symbol switchers appear in the File toolbar in your screenshot?

@dalthviz
Copy link
Member Author

I didn't add the actions in the file_toolbar_actions list. The last commit do that 👍

@ccordoba12
Copy link
Member

I think this is ready, great work @dalthviz!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants