Skip to content

Commit

Permalink
Merge pull request #3946 from rlaverde/move-tabs
Browse files Browse the repository at this point in the history
PR: Make Editor tabs movable
  • Loading branch information
ccordoba12 authored Jan 31, 2017
2 parents 6d2cd29 + 2228e83 commit 5c8a694
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
3 changes: 1 addition & 2 deletions spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@
'occurrence_highlighting': True,
'occurrence_highlighting/timeout': 1500,
'always_remove_trailing_spaces': False,
'fullpath_sorting': True,
'show_tab_bar': True,
'max_recent_files': 20,
'save_all_before_run': True,
Expand Down Expand Up @@ -656,7 +655,7 @@
# or if you want to *rename* options, then you need to do a MAJOR update in
# version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '32.0.0'
CONF_VERSION = '33.0.0'

# Main configuration instance
try:
Expand Down
22 changes: 19 additions & 3 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,9 @@ def setup_page(self):

interface_group = QGroupBox(_("Interface"))
newcb = self.create_checkbox
fpsorting_box = newcb(_("Sort files according to full path"),
'fullpath_sorting')
showtabbar_box = newcb(_("Show tab bar"), 'show_tab_bar')

interface_layout = QVBoxLayout()
interface_layout.addWidget(fpsorting_box)
interface_layout.addWidget(showtabbar_box)
interface_group.setLayout(interface_layout)

Expand Down Expand Up @@ -1303,6 +1300,7 @@ def register_editorstack(self, editorstack):
editorstack.sig_prev_edit_pos.connect(self.go_to_last_edit_location)
editorstack.sig_prev_cursor.connect(self.go_to_previous_cursor_position)
editorstack.sig_next_cursor.connect(self.go_to_next_cursor_position)
editorstack.tabs.tabBar().tabMoved.connect(self.move_editorstack_data)

def unregister_editorstack(self, editorstack):
"""Removing editorstack only if it's not the last remaining"""
Expand Down Expand Up @@ -2641,3 +2639,21 @@ def set_create_new_file_if_empty(self, value):
"""Change the value of create_new_file_if_empty"""
for editorstack in self.editorstacks:
editorstack.create_new_file_if_empty = value

def move_editorstack_data(self, start, end):
"""Move editorstack.data to be synchronized when tabs are moved."""
if start < 0 or end < 0:
return
else:
steps = abs(end - start)
direction = (end-start) // steps # +1 for right, -1 for left

for editorstack in self.editorstacks :
data = editorstack.data
editorstack.blockSignals(True)

for i in range(start, end, direction):
data[i], data[i+direction] = data[i+direction], data[i]

editorstack.blockSignals(False)
editorstack.refresh()
20 changes: 7 additions & 13 deletions spyder/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,15 @@ def setup_editorstack(self, parent, layout):
corner_widgets=corner_widgets)
self.tabs.tabBar().setObjectName('plugin-tab')
self.tabs.set_close_function(self.close_file)
self.tabs.setMovable(True)

if hasattr(self.tabs, 'setDocumentMode') \
and not sys.platform == 'darwin':
# Don't set document mode to true on OSX because it generates
# a crash when the editor is detached from the main window
# Fixes Issue 561
self.tabs.setDocumentMode(True)
self.tabs.currentChanged.connect(self.current_changed)
self.tabs.currentChanged.connect(self.current_changed_tabs)

if sys.platform == 'darwin':
tab_container = QWidget()
Expand Down Expand Up @@ -926,7 +927,6 @@ def set_fullpath_sorting_enabled(self, state):
self.fullpath_sorting_enabled = state
if self.data:
finfo = self.data[self.get_stack_index()]
self.data.sort(key=self.__get_sorting_func())
new_index = self.data.index(finfo)
self.__repopulate_stack()
self.set_stack_index(new_index)
Expand Down Expand Up @@ -1005,16 +1005,8 @@ def get_tab_tip(self, filename, is_modified=None, is_readonly=None):
else:
return text % (osp.basename(filename), osp.dirname(filename))

def __get_sorting_func(self):
if self.fullpath_sorting_enabled:
return lambda item: osp.join(osp.dirname(item.filename),
'_'+osp.basename(item.filename))
else:
return lambda item: osp.basename(item.filename)

def add_to_data(self, finfo, set_current):
self.data.append(finfo)
self.data.sort(key=self.__get_sorting_func())
index = self.data.index(finfo)
editor = finfo.editor
self.tabs.insertTab(index, editor, self.get_tab_text(index))
Expand Down Expand Up @@ -1051,7 +1043,6 @@ def rename_in_data(self, index, new_filename):
set_new_index = index == self.get_stack_index()
current_fname = self.get_current_filename()
finfo.filename = new_filename
self.data.sort(key=self.__get_sorting_func())
new_index = self.data.index(finfo)
self.__repopulate_stack()
if set_new_index:
Expand Down Expand Up @@ -1449,14 +1440,17 @@ def get_todo_results(self):
if self.data:
return self.data[self.get_stack_index()].todo_results

def current_changed(self, index):
def current_changed_tabs(self, index):
self.current_changed(index, set_focus=False)

def current_changed(self, index, set_focus=True):
"""Stack index has changed"""
# count = self.get_stack_count()
# for btn in (self.filelist_btn, self.previous_btn, self.next_btn):
# btn.setEnabled(count > 1)

editor = self.get_current_editor()
if index != -1:
if index != -1 and set_focus:
editor.setFocus()
if DEBUG_EDITOR:
print("setfocusto:", editor, file=STDOUT)
Expand Down

0 comments on commit 5c8a694

Please sign in to comment.