Add command tab_move (gm/gl/gr)
This commit is contained in:
parent
87e94a2c68
commit
4e7eb41cb9
9
TODO
9
TODO
@ -287,15 +287,6 @@ tab-handling
|
|||||||
C-Tab
|
C-Tab
|
||||||
Toggle between current and last focused tab (command toggle_tab, aliases: ttab)
|
Toggle between current and last focused tab (command toggle_tab, aliases: ttab)
|
||||||
|
|
||||||
[n]gm
|
|
||||||
Move current tab to position [n] or to first position if n is omitted. (command tab_move, aliases: tabm).
|
|
||||||
|
|
||||||
[n]gl
|
|
||||||
Move current tab [n] positions left. (command tab_move_left, aliases: tabl).
|
|
||||||
|
|
||||||
[n]gr
|
|
||||||
Move current tab [n] positions right. (command tab_move_right, aliases: tabr).
|
|
||||||
|
|
||||||
gt
|
gt
|
||||||
Show all open tabs. (command buffers, aliases: bu).
|
Show all open tabs. (command buffers, aliases: bu).
|
||||||
|
|
||||||
|
@ -549,6 +549,9 @@ DATA = OrderedDict([
|
|||||||
('d', 'tabclose'),
|
('d', 'tabclose'),
|
||||||
('co', 'only'),
|
('co', 'only'),
|
||||||
('T', 'focus_tab'),
|
('T', 'focus_tab'),
|
||||||
|
('gm', 'tab_move'),
|
||||||
|
('gl', 'tab_move -'),
|
||||||
|
('gr', 'tab_move +'),
|
||||||
('J', 'tabnext'),
|
('J', 'tabnext'),
|
||||||
('K', 'tabprev'),
|
('K', 'tabprev'),
|
||||||
('r', 'reload'),
|
('r', 'reload'),
|
||||||
|
@ -387,6 +387,47 @@ class TabbedBrowser(TabWidget):
|
|||||||
message.error("There's no tab with index {}!".format(idx))
|
message.error("There's no tab with index {}!".format(idx))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@cmdutils.register(instance='mainwindow.tabs')
|
||||||
|
def tab_move(self, direction=None, count=None):
|
||||||
|
"""Move the current tab.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
direction: + or - for relative moving, None for absolute.
|
||||||
|
count: If moving absolutely: New position (or first).
|
||||||
|
If moving relatively: Offset.
|
||||||
|
"""
|
||||||
|
cur_idx = self.currentIndex()
|
||||||
|
if direction is None:
|
||||||
|
# absolute move
|
||||||
|
if count is None:
|
||||||
|
new_idx = 0
|
||||||
|
elif count == 0:
|
||||||
|
new_idx = self.count() - 1
|
||||||
|
else:
|
||||||
|
new_idx = count - 1
|
||||||
|
elif direction in '+-':
|
||||||
|
# relative move
|
||||||
|
if count is None:
|
||||||
|
message.error("Count must be given for relative moving!")
|
||||||
|
return
|
||||||
|
if direction == '-':
|
||||||
|
new_idx = cur_idx - count
|
||||||
|
elif direction == '+':
|
||||||
|
new_idx = cur_idx + count
|
||||||
|
else:
|
||||||
|
message.error("Invalid direction '{}'!".format(direction))
|
||||||
|
return
|
||||||
|
if not 0 <= new_idx < self.count():
|
||||||
|
message.error("Can't move tab to position {}!".format(new_idx))
|
||||||
|
return
|
||||||
|
tab = self.currentWidget()
|
||||||
|
icon = self.tabIcon(cur_idx)
|
||||||
|
label = self.tabText(cur_idx)
|
||||||
|
self.removeTab(cur_idx)
|
||||||
|
self.insertTab(new_idx, tab, icon, label)
|
||||||
|
self.setCurrentIndex(new_idx)
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
"""Update tab config when config was changed."""
|
"""Update tab config when config was changed."""
|
||||||
|
Loading…
Reference in New Issue
Block a user