summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2013-03-03 12:26:30 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2013-03-03 13:50:19 +0000
commit987ac94d0615e6558807924e04ec3890cc50ea97 (patch)
treed34878cd5044ae39dc2c2c45ba24d1d3a60c139f /alot
parentc841d22dd703978109a6fa855dc22b444a2896a9 (diff)
implement Threadbuffer.focus_foo methods
to move the focus depending on the outmost tree of messages (not the inner nested threes..)
Diffstat (limited to 'alot')
-rw-r--r--alot/buffers.py63
-rw-r--r--alot/commands/thread.py19
2 files changed, 68 insertions, 14 deletions
diff --git a/alot/buffers.py b/alot/buffers.py
index ac91f30f..48feb5f0 100644
--- a/alot/buffers.py
+++ b/alot/buffers.py
@@ -44,7 +44,7 @@ class Buffer(object):
pass
def keypress(self, size, key):
- return self.body.keypress(size, key)
+ return self.body.keypress(size, key)
def cleanup(self):
"""called before buffer is closed"""
@@ -367,22 +367,77 @@ class ThreadBuffer(Buffer):
for pos in self._tree.positions():
yield self._tree[pos]
+ # needed for ui.get_deep_focus..
def get_focus(self):
return self.body.get_focus()
def get_focus_position(self):
- return self._sanitize_position((self.get_selected_mid(),))
+ return self._sanitize_position((self.get_selected_mid(),))
def focus_first(self):
self.body.set_focus(self._nested_tree.root)
def _sanitize_position(self, pos):
- return self._nested_tree._sanitize_position(pos, self._nested_tree._tree)
+ return self._nested_tree._sanitize_position(pos, self._nested_tree._tree)
def focus_parent(self):
mid = self.get_selected_mid()
newpos = self._tree.parent_position(mid)
- self.body.set_focus(self._sanitize_position((newpos,)))
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ self.body.set_focus(newpos)
+
+ def focus_first_reply(self):
+ mid = self.get_selected_mid()
+ newpos = self._tree.first_child_position(mid)
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ self.body.set_focus(newpos)
+
+ def focus_last_reply(self):
+ mid = self.get_selected_mid()
+ newpos = self._tree.last_child_position(mid)
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ self.body.set_focus(newpos)
+
+ def focus_next_sibling(self):
+ mid = self.get_selected_mid()
+ newpos = self._tree.next_sibling_position(mid)
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ self.body.set_focus(newpos)
+
+ def focus_prev_sibling(self):
+ mid = self.get_selected_mid()
+ localroot = self._sanitize_position((mid,))
+ if localroot == self.get_focus()[1]:
+ newpos = self._tree.prev_sibling_position(mid)
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ else:
+ newpos = localroot
+ if newpos is not None:
+ self.body.set_focus(newpos)
+
+ def focus_next(self):
+ mid = self.get_selected_mid()
+ newpos = self._tree.next_position(mid)
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ self.body.set_focus(newpos)
+
+ def focus_prev(self):
+ mid = self.get_selected_mid()
+ localroot = self._sanitize_position((mid,))
+ if localroot == self.get_focus()[1]:
+ newpos = self._tree.prev_position(mid)
+ if newpos is not None:
+ newpos = self._sanitize_position((newpos,))
+ else:
+ newpos = localroot
+ if newpos is not None:
+ self.body.set_focus(newpos)
def expand(self, msgpos):
MT = self._tree[msgpos]
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 23fcf786..51783206 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -834,28 +834,27 @@ class OpenAttachmentCommand(Command):
'help':'up, down, page up, page down, first'})])
class MoveFocusCommand(MoveCommand):
def apply(self, ui):
- # TODO: use thread here to move in topmost message subtree only
logging.debug(self.movement)
- tbox = ui.current_buffer.body
+ tbuffer = ui.current_buffer
if self.movement == 'parent':
- ui.current_buffer.focus_parent()
+ tbuffer.focus_parent()
elif self.movement == 'first reply':
- tbox.focus_first_child()
+ tbuffer.focus_first_child()
elif self.movement == 'last reply':
- tbox.focus_last_child()
+ tbuffer.focus_last_child()
elif self.movement == 'next sibling':
- tbox.focus_next_sibling()
+ tbuffer.focus_next_sibling()
elif self.movement == 'previous sibling':
- tbox.focus_prev_sibling()
+ tbuffer.focus_prev_sibling()
elif self.movement == 'next':
- tbox.focus_next()
+ tbuffer.focus_next()
elif self.movement == 'previous':
- tbox.focus_prev()
+ tbuffer.focus_prev()
else:
MoveCommand.apply(self, ui)
# TODO add 'next matching' if threadbuffer stores the original query string
# TODO: add next by date..
- tbox.refresh()
+ tbuffer.body.refresh()
@registerCommand(MODE, 'select')