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: Add a file switcher instance #46

Merged
merged 9 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion spyder_notebook/notebookplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from spyder.utils.qthelpers import (create_action, create_toolbutton,
add_actions)
from spyder.widgets.tabs import Tabs
from spyder.widgets.fileswitcher import FileSwitcher
from spyder.plugins import SpyderPluginWidget

# Local imports
Expand All @@ -48,6 +49,7 @@ class NotebookPlugin(SpyderPluginWidget):
def __init__(self, parent):
SpyderPluginWidget.__init__(self, parent)

self.fileswitcher_dlg = None
self.tabwidget = None
self.menu_actions = None

Expand All @@ -61,6 +63,10 @@ def __init__(self, parent):

layout = QVBoxLayout()

filelist_btn = create_toolbutton(self, icon=ima.icon('filelist'),
tip=_("File list management"),
triggered=self.open_fileswitcher_dlg)
Copy link
Member

Choose a reason for hiding this comment

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

Please align the last two lines here to ( in the first line


new_notebook_btn = create_toolbutton(self,
icon=ima.icon('project_expanded'),
tip=_('Open a new notebook'),
Expand All @@ -71,7 +77,8 @@ def __init__(self, parent):
menu_btn.setMenu(self.menu)
menu_btn.setPopupMode(menu_btn.InstantPopup)
add_actions(self.menu, self.menu_actions)
corner_widgets = {Qt.TopRightCorner: [new_notebook_btn, menu_btn]}
corner_widgets = {Qt.TopRightCorner: [filelist_btn,
new_notebook_btn, menu_btn]}
self.tabwidget = Tabs(self, menu=self.menu, actions=self.menu_actions,
corner_widgets=corner_widgets)

Expand Down Expand Up @@ -277,3 +284,23 @@ def move_tab(self, index_from, index_to):
"""
client = self.clients.pop(index_from)
self.clients.insert(index_to, client)

def set_stack_index(self, index):
"""Set the index of the current notebook."""
self.tabwidget.setCurrentIndex(index)

def open_fileswitcher_dlg(self):
"""Open notebook list management dialog box."""
if not self.tabwidget.count():
return
if self.fileswitcher_dlg is not None and \
self.fileswitcher_dlg.is_visible:
self.fileswitcher_dlg.hide()
self.fileswitcher_dlg.is_visible = False
return
self.fileswitcher_dlg = FileSwitcher(self, self.tabwidget, self.clients)
self.fileswitcher_dlg.sig_goto_file.connect(self.set_stack_index)
self.fileswitcher_dlg.sig_close_file.connect(self.close_client)
self.fileswitcher_dlg.show()
self.fileswitcher_dlg.is_visible = True

10 changes: 6 additions & 4 deletions spyder_notebook/widgets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ class NotebookClient(QWidget):
def __init__(self, plugin, name):
super(NotebookClient, self).__init__(plugin)

self.name = name
if os.name == 'nt':
name = name.replace('/','\\')
self.filename = name
Copy link
Member

Choose a reason for hiding this comment

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

Please leave this as it was, i.e. self.name = name

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, it's fine as you wrote it :-)

Copy link
Member

Choose a reason for hiding this comment

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

But to be consistent, you should change name to filename in create_new_client


self.file_url = None
self.server_url = None
Expand Down Expand Up @@ -143,7 +145,7 @@ def add_token(self, url):
def register(self, server_info):
"""Register attributes that can be computed with the server info."""
# Path relative to the server directory
self.path = os.path.relpath(self.name,
self.path = os.path.relpath(self.filename,
start=server_info['notebook_dir'])

# Replace backslashes on Windows
Expand Down Expand Up @@ -174,11 +176,11 @@ def load_notebook(self):
self.go_to(self.file_url)

def get_name(self):
return self.name
return self.filename

def get_short_name(self):
"""Get a short name for the notebook."""
sname = osp.basename(self.name)
sname = osp.basename(self.filename)
if len(sname) > 15:
sname = sname[:15]
return sname
Expand Down