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: Deactivate editor actions when Tab Swither is shown #5094

Merged
merged 4 commits into from
Aug 31, 2017
Merged
Changes from all 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
77 changes: 43 additions & 34 deletions spyder/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class TabSwitcherWidget(QListWidget):

def __init__(self, parent, stack_history, tabs):
QListWidget.__init__(self, parent)
self.setWindowFlags(Qt.SubWindow | Qt.FramelessWindowHint)
self.setWindowFlags(Qt.SubWindow | Qt.FramelessWindowHint | Qt.Dialog)

self.editor = parent
self.stack_history = stack_history
Expand All @@ -349,12 +349,16 @@ def __init__(self, parent, stack_history, tabs):
self.set_dialog_position()
self.setCurrentRow(0)

config_shortcut(lambda: self.select_row(-1), context='Editor',
name='Go to previous file', parent=self)
config_shortcut(lambda: self.select_row(1), context='Editor',
name='Go to next file', parent=self)

def load_data(self):
"""Fill ListWidget with the tabs texts.

Add elements in inverse order of stack_history.
"""

for index in reversed(self.stack_history):
text = self.tabs.tabText(index)
text = text.replace('&', '')
Expand All @@ -367,10 +371,13 @@ def item_selected(self, item=None):
item = self.currentItem()

# stack history is in inverse order
index = self.stack_history[-(self.currentRow()+1)]

self.editor.set_stack_index(index)
self.editor.current_changed(index)
try:
index = self.stack_history[-(self.currentRow()+1)]
except IndexError:
pass
else:
self.editor.set_stack_index(index)
self.editor.current_changed(index)
self.hide()

def select_row(self, steps):
Expand All @@ -383,11 +390,33 @@ def select_row(self, steps):

def set_dialog_position(self):
"""Positions the tab switcher in the top-center of the editor."""
parent = self.parent()
left = parent.geometry().width()/2 - self.width()/2
top = 0
left = self.editor.geometry().width()/2 - self.width()/2
top = self.editor.tabs.tabBar().geometry().height()

self.move(self.editor.mapToGlobal(QPoint(left, top)))

def keyReleaseEvent(self, event):
"""Reimplement Qt method.

Handle "most recent used" tab behavior,
When ctrl is released and tab_switcher is visible, tab will be changed.
"""
if self.isVisible():
qsc = get_shortcut(context='Editor', name='Go to next file')

for key in qsc.split('+'):
key = key.lower()
if ((key == 'ctrl' and event.key() == Qt.Key_Control) or
(key == 'alt' and event.key() == Qt.Key_Alt)):
self.item_selected()
event.accept()

self.move(left, top + self.tabs.tabBar().geometry().height())
def keyPressEvent(self, event):
"""Reimplement Qt method to allow cyclic behavior."""
if event.key() == Qt.Key_Down:
self.select_row(1)
elif event.key() == Qt.Key_Up:
self.select_row(-1)


class EditorStack(QWidget):
Expand Down Expand Up @@ -1696,12 +1725,11 @@ def tab_navigation_mru(self, forward=True):
True: move to next file
False: move to previous file
"""
if self.tabs_switcher is None or not self.tabs_switcher.isVisible():
self.tabs_switcher = TabSwitcherWidget(self, self.stack_history,
self.tabs)
self.tabs_switcher.show()

self.tabs_switcher = TabSwitcherWidget(self, self.stack_history,
self.tabs)
self.tabs_switcher.show()
self.tabs_switcher.select_row(1 if forward else -1)
self.tabs_switcher.setFocus()

def focus_changed(self):
"""Editor focus has changed"""
Expand Down Expand Up @@ -2200,25 +2228,6 @@ def dropEvent(self, event):
editor.insert_text( source.text() )
event.acceptProposedAction()

def keyReleaseEvent(self, event):
"""Reimplement Qt method.

Handle "most recent used" tab behavior,
When ctrl is released and tab_switcher is visible, tab will be changed.
"""
if self.tabs_switcher is not None and self.tabs_switcher.isVisible():
qsc = get_shortcut(context='Editor', name='Go to next file')

for key in qsc.split('+'):
key = key.lower()
if ((key == 'ctrl' and event.key() == Qt.Key_Control) or
(key == 'alt' and event.key() == Qt.Key_Alt)):
self.tabs_switcher.item_selected()
self.tabs_switcher = None
return

super(EditorStack, self).keyReleaseEvent(event)


class EditorSplitter(QSplitter):
def __init__(self, parent, plugin, menu_actions, first=False,
Expand Down