redo mark function
parent
315a249ef6
commit
ab1550c09c
|
@ -793,7 +793,7 @@ class App(object):
|
|||
"""
|
||||
if self.mode == "thread":
|
||||
# mark the current position in this thread before going back to the index
|
||||
mark()
|
||||
self.mark()
|
||||
|
||||
self.body.attr_map = {None: "default"}
|
||||
self.mode = "index"
|
||||
|
@ -859,7 +859,7 @@ class App(object):
|
|||
self.walker += self.make_message_body(message)
|
||||
self.set_default_header()
|
||||
self.set_default_footer()
|
||||
self.goto_post(mark(thread_id))
|
||||
self.goto_mark(thread_id)
|
||||
|
||||
|
||||
def toggle_client_pin(self):
|
||||
|
@ -983,10 +983,10 @@ class App(object):
|
|||
self.last_index_pos = self.get_focus_post(True).thread["thread_id"]
|
||||
self.index()
|
||||
else:
|
||||
mark()
|
||||
self.mark()
|
||||
thread = self.thread["thread_id"]
|
||||
self.thread_load(None, thread)
|
||||
self.goto_post(mark(thread))
|
||||
self.goto_mark(thread)
|
||||
self.temp_footer_message("Refreshed content!", 1)
|
||||
|
||||
|
||||
|
@ -1021,10 +1021,31 @@ class App(object):
|
|||
width=30, height=6)
|
||||
|
||||
else:
|
||||
mark()
|
||||
self.mark()
|
||||
self.index()
|
||||
|
||||
|
||||
def mark(self, thread_id=None):
|
||||
if self.mode != "thread":
|
||||
return
|
||||
|
||||
if thread_id is None:
|
||||
thread_id = self.thread['thread_id']
|
||||
pos = self.get_focus_post()
|
||||
mark(thread_id, pos, default=0)
|
||||
return pos
|
||||
|
||||
|
||||
def goto_mark(self, thread_id=None):
|
||||
if self.mode != "thread":
|
||||
return
|
||||
|
||||
if thread_id is None:
|
||||
thread_id = self.thread['thread_id']
|
||||
pos = mark(thread_id, default=0)
|
||||
self.goto_post(pos)
|
||||
|
||||
|
||||
def get_focus_post(self, return_widget=False):
|
||||
pos = self.box.get_focus_path()[0]
|
||||
if self.mode == "thread":
|
||||
|
@ -2501,11 +2522,16 @@ def bbjrc(mode, **params):
|
|||
return values
|
||||
|
||||
|
||||
def mark(directive=True):
|
||||
def mark(key, value=None, default=None):
|
||||
"""
|
||||
Set and retrieve positional marks for threads.
|
||||
Sets a value in the markfile and returns the old value (or default).
|
||||
This uses a seperate file from the preferences
|
||||
to keep it free from clutter.
|
||||
|
||||
The key must be a string, and the value must be
|
||||
json-encodable. If value isn't provided (or is None)
|
||||
then this doesn't set anything and it is only a
|
||||
read operation.
|
||||
"""
|
||||
try:
|
||||
with open(markpath, "r") as _in:
|
||||
|
@ -2513,19 +2539,14 @@ def mark(directive=True):
|
|||
except FileNotFoundError:
|
||||
values = {}
|
||||
|
||||
if directive == True and app.mode == "thread":
|
||||
pos = app.get_focus_post()
|
||||
values[app.thread["thread_id"]] = pos
|
||||
old = values.get(key, default)
|
||||
|
||||
if value is not None and value != old:
|
||||
values[key] = value
|
||||
with open(markpath, "w") as _out:
|
||||
json.dump(values, _out)
|
||||
return pos
|
||||
|
||||
elif isinstance(directive, str):
|
||||
try:
|
||||
return values[directive]
|
||||
except KeyError:
|
||||
return 0
|
||||
|
||||
return old
|
||||
|
||||
def load_client_pins():
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue