From 69f110b47489c53d9542a544c3546cbcbbeeb23c Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Sun, 26 Jan 2020 21:52:58 +0100 Subject: [PATCH] Make [P]in action toggle save of hashtag timeline If currently viewed timeline is saved, [P] unsaves it. --- toot/tui/app.py | 10 +++++++--- toot/tui/overlays.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/toot/tui/app.py b/toot/tui/app.py index de482a3..d9e02a1 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -213,12 +213,16 @@ class TUI(urwid.Frame): def _thread(timeline, status): self.show_thread(status) - def _save(timeline, status): + def _toggle_save(timeline, status): if not timeline.name.startswith("#"): return hashtag = timeline.name[1:] assert isinstance(local, bool), local - self.config.setdefault("timelines", {})[hashtag] = {"local": local} + timelines = self.config.setdefault("timelines", {}) + if hashtag in timelines: + del timelines[hashtag] + else: + timelines[hashtag] = {"local": local} config.save_config(self.config) timeline = Timeline(name, statuses) @@ -227,7 +231,7 @@ class TUI(urwid.Frame): urwid.connect_signal(timeline, "next", _next) urwid.connect_signal(timeline, "close", _close) urwid.connect_signal(timeline, "thread", _thread) - urwid.connect_signal(timeline, "save", _save) + urwid.connect_signal(timeline, "save", _toggle_save) return timeline diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index 121693a..d4ef1de 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -145,7 +145,7 @@ class Help(urwid.Padding): yield urwid.Divider() yield urwid.Text(h(" [Q] - quit toot")) yield urwid.Text(h(" [G] - go to - switch timelines")) - yield urwid.Text(h(" [P] - save (pin) current timeline")) + yield urwid.Text(h(" [P] - save/unsave (pin) current timeline")) yield urwid.Text(h(" [H] - show this help")) yield urwid.Divider() yield urwid.Text(("bold", "Status keys"))