Action to convert between vertical and horizontal splits
This commit is contained in:
parent
36fda90814
commit
c31a39a052
@ -241,6 +241,14 @@ def disable_ligatures_in(func, rest):
|
||||
return func, [where, strategy]
|
||||
|
||||
|
||||
@func_with_args('layout_action')
|
||||
def layout_action(func, rest):
|
||||
parts = rest.split(maxsplit=1)
|
||||
if not parts:
|
||||
raise ValueError('layout_action must have at least one argument')
|
||||
return func, [parts[0], tuple(parts[1:])]
|
||||
|
||||
|
||||
def parse_marker_spec(ftype, parts):
|
||||
flags = re.UNICODE
|
||||
if ftype in ('text', 'itext', 'regex', 'iregex'):
|
||||
|
||||
@ -457,6 +457,9 @@ class Layout: # {{{
|
||||
yield all_borders
|
||||
else:
|
||||
yield no_borders
|
||||
|
||||
def layout_action(self, action_name, args, all_windows, active_window_idx):
|
||||
pass
|
||||
# }}}
|
||||
|
||||
|
||||
@ -1363,6 +1366,27 @@ class Splits(Layout):
|
||||
else:
|
||||
p2.two = w1
|
||||
|
||||
def layout_action(self, action_name, args, all_windows, active_window_idx):
|
||||
if action_name == 'rotate':
|
||||
args = args or ('90',)
|
||||
try:
|
||||
amt = int(args[0])
|
||||
except Exception:
|
||||
amt = 90
|
||||
if amt not in (90, 180, 270):
|
||||
amt = 90
|
||||
rotate = amt in (90, 270)
|
||||
swap = amt in (180, 270)
|
||||
w = all_windows[active_window_idx]
|
||||
wid = w.overlay_for or w.id
|
||||
pair = self.pairs_root.pair_for_window(wid)
|
||||
if pair is not None and not pair.is_redundant:
|
||||
if rotate:
|
||||
pair.horizontal = not pair.horizontal
|
||||
if swap:
|
||||
pair.one, pair.two = pair.two, pair.one
|
||||
return True
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
|
||||
@ -236,6 +236,15 @@ class Tab: # {{{
|
||||
if self.current_layout.remove_all_biases():
|
||||
self.relayout()
|
||||
|
||||
def layout_action(self, action_name, args):
|
||||
ret = self.current_layout.layout_action(action_name, args, self.windows, self.active_window_idx)
|
||||
if ret is None:
|
||||
ring_bell()
|
||||
return
|
||||
if isinstance(ret, int) and not isinstance(ret, bool):
|
||||
self.active_window_idx = ret
|
||||
self.relayout()
|
||||
|
||||
def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None, env=None, allow_remote_control=False):
|
||||
if cmd is None:
|
||||
if use_shell:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user