Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Maintain position in topic list when toggling topic list (issue #617) #1275

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def __init__(
controller: Any,
view: Any,
count: int,
curr_topic_name: Any = None,
) -> None:
# FIXME Is having self.stream_id the best way to do this?
# (self.stream_id is used elsewhere)
Expand All @@ -188,7 +189,7 @@ def __init__(
self.model = controller.model
self.count = count
self.view = view

self.curr_topic_name = curr_topic_name
for entry in view.palette:
if entry[0] is None:
background = entry[5] if len(entry) > 4 else entry[2]
Expand Down Expand Up @@ -237,7 +238,7 @@ def mark_unmuted(self, unread_count: int) -> None:

def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("TOGGLE_TOPIC", key):
self.view.left_panel.show_topic_view(self)
self.view.left_panel.show_topic_view(self, self.curr_topic_name)
elif is_command_key("TOGGLE_MUTE_STREAM", key):
self.controller.stream_muting_confirmation_popup(
self.stream_id, self.stream_name
Expand Down Expand Up @@ -348,7 +349,7 @@ def mark_muted(self) -> None:
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("TOGGLE_TOPIC", key):
# Exit topic view
self.view.left_panel.show_stream_view()
self.view.left_panel.show_stream_view(self.topic_name, self.stream_id)
return super().keypress(size, key)


Expand Down
48 changes: 40 additions & 8 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,11 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:

class TopicsView(urwid.Frame):
def __init__(
self, topics_btn_list: List[Any], view: Any, stream_button: Any
self,
topics_btn_list: List[Any],
view: Any,
stream_button: Any,
curr_topic_name: Any = None,
) -> None:
self.view = view
self.log = urwid.SimpleFocusListWalker(topics_btn_list)
Expand All @@ -423,6 +427,11 @@ def __init__(
self.header_list = urwid.Pile(
[self.stream_button, urwid.Divider("─"), self.topic_search_box]
)
if curr_topic_name is not None:
for i, topic in enumerate(self.log):
if topic.topic_name == curr_topic_name:
self.log.set_focus(i)

super().__init__(
self.list_box,
header=urwid.LineBox(
Expand Down Expand Up @@ -818,13 +827,22 @@ def menu_view(self) -> Any:
w = urwid.ListBox(urwid.SimpleFocusListWalker(menu_btn_list))
return w

def streams_view(self) -> Any:
def streams_view(self, topic_name: Any = None, stream_id: Any = None) -> Any:
streams_btn_list = [
StreamButton(
properties=stream,
controller=self.controller,
view=self.view,
count=self.model.unread_counts["streams"].get(stream["id"], 0),
curr_topic_name=topic_name,
)
if stream['id'] == stream_id
else StreamButton(
properties=stream,
controller=self.controller,
view=self.view,
count=self.model.unread_counts["streams"].get(stream["id"], 0),
curr_topic_name=None,
)
for stream in self.view.pinned_streams
]
Expand All @@ -838,6 +856,15 @@ def streams_view(self) -> Any:
controller=self.controller,
view=self.view,
count=self.model.unread_counts["streams"].get(stream["id"], 0),
curr_topic_name=topic_name,
)
if stream['id'] == stream_id
else StreamButton(
properties=stream,
controller=self.controller,
view=self.view,
count=self.model.unread_counts["streams"].get(stream["id"], 0),
curr_topic_name=None,
)
for stream in self.view.unpinned_streams
]
Expand All @@ -864,7 +891,7 @@ def streams_view(self) -> Any:
)
return w

def topics_view(self, stream_button: Any) -> Any:
def topics_view(self, stream_button: Any, curr_topic_name: Any = None) -> Any:
stream_id = stream_button.stream_id
topics = self.model.topics_in_stream(stream_id)
topics_btn_list = [
Expand All @@ -880,7 +907,9 @@ def topics_view(self, stream_button: Any) -> Any:
for topic in topics
]

self.view.topic_w = TopicsView(topics_btn_list, self.view, stream_button)
self.view.topic_w = TopicsView(
topics_btn_list, self.view, stream_button, curr_topic_name
)
w = urwid.LineBox(
self.view.topic_w,
title="Topics",
Expand All @@ -907,14 +936,17 @@ def update_stream_view(self) -> None:
if not self.is_in_topic_view:
self.show_stream_view()

def show_stream_view(self) -> None:
def show_stream_view(self, topic_name: Any = None, stream_name: Any = None) -> None:
self.is_in_topic_view = False
self.contents[1] = (self.stream_v, self.options(height_type="weight"))
self.contents[1] = (
self.stream_v(topic_name, stream_name),
self.options(height_type="weight"),
)

def show_topic_view(self, stream_button: Any) -> None:
def show_topic_view(self, stream_button: Any, curr_topic_name: Any) -> None:
self.is_in_topic_view = True
self.contents[1] = (
self.topics_view(stream_button),
self.topics_view(stream_button, curr_topic_name),
self.options(height_type="weight"),
)

Expand Down