Skip to content

Commit 76ca074

Browse files
committed
buttons/views: Add panel folding for DM and stream panels.
1 parent f090ebf commit 76ca074

File tree

2 files changed

+90
-27
lines changed

2 files changed

+90
-27
lines changed

zulipterminal/ui_tools/buttons.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -142,30 +142,40 @@ def __init__(self, *, controller: Any, count: int) -> None:
142142

143143

144144
class DMPanelButton(TopButton):
145-
def __init__(self, *, controller: Any, count: int) -> None:
145+
def __init__(
146+
self, *, controller: Any, count: int, show_function: Callable[[], Any]
147+
) -> None:
146148
button_text = f"Direct messages [{primary_key_for_command('ALL_PM')}]"
147149

148150
super().__init__(
149151
controller=controller,
150152
label_markup=(None, button_text),
151153
prefix_markup=("title", DIRECT_MESSAGE_MARKER),
152154
suffix_markup=("unread_count", ""),
153-
show_function=controller.narrow_to_all_pm,
155+
show_function=show_function,
154156
count=count,
155157
)
156158

159+
def activate(self, key: Any) -> None:
160+
self.show_function()
161+
157162

158163
class StreamPanelButton(TopButton):
159-
def __init__(self, *, controller: Any, count: int) -> None:
160-
button_text = "Stream messages "
164+
def __init__(
165+
self, *, controller: Any, count: int, show_function: Callable[[], Any]
166+
) -> None:
167+
button_text = "Stream messages [S]"
161168
super().__init__(
162169
controller=controller,
163170
label_markup=(None, button_text),
164171
suffix_markup=("unread_count", ""),
165-
show_function=lambda: None,
172+
show_function=show_function,
166173
count=count,
167174
)
168175

176+
def activate(self, key: Any) -> None:
177+
self.show_function()
178+
169179

170180
class MentionedButton(TopButton):
171181
def __init__(self, *, controller: Any, count: int) -> None:

zulipterminal/ui_tools/views.py

+75-22
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,32 @@ def read_message(self, index: int = -1) -> None:
307307

308308

309309
class DMPanel(urwid.Pile):
310-
def __init__(self, submenu_view: List[Any], view: Any) -> None:
310+
def __init__(
311+
self,
312+
submenu_view: Optional[List[Any]],
313+
view: Any,
314+
show_function: Callable[[], Any],
315+
) -> None:
311316
self.view = view
312317
count = self.view.model.unread_counts.get("all_pms", 0)
313318
self.view.pm_button = DMPanelButton(
314-
controller=self.view.controller, count=count
319+
controller=self.view.controller, count=count, show_function=show_function
315320
)
316321

317-
self._contents = [
318-
("pack", self.view.pm_button),
319-
("pack", urwid.Divider(div_char=SECTION_DIVIDER_LINE)),
320-
submenu_view,
321-
]
322+
if submenu_view:
323+
self._contents = [
324+
("pack", self.view.pm_button),
325+
("pack", urwid.Divider(div_char=SECTION_DIVIDER_LINE)),
326+
submenu_view,
327+
]
328+
focus_item = 2
329+
else:
330+
self._contents = [
331+
("pack", self.view.pm_button),
332+
]
333+
focus_item = 0
322334

323-
super().__init__(self.contents)
335+
super().__init__(self.contents, focus_item=focus_item)
324336

325337

326338
class DMView(urwid.Frame):
@@ -347,19 +359,35 @@ def __init__(self) -> None:
347359

348360

349361
class StreamPanel(urwid.Pile):
350-
def __init__(self, submenu_view: List[Any], view: Any) -> None:
362+
def __init__(
363+
self,
364+
submenu_view: Optional[List[Any]],
365+
view: Any,
366+
show_function: Callable[[], Any],
367+
) -> None:
351368
self.view = view
352369
count = self.view.model.unread_counts.get("all_stream_msg", 0)
353370
self.view.stream_button = StreamPanelButton(
354-
controller=self.view.controller, count=count
371+
controller=self.view.controller,
372+
count=count,
373+
show_function=show_function,
355374
)
356-
self._contents = [
357-
("pack", self.view.stream_button),
358-
("pack", urwid.Divider(div_char=SECTION_DIVIDER_LINE)),
359-
submenu_view,
360-
]
361375

362-
super().__init__(self.contents, focus_item=2)
376+
if submenu_view:
377+
self._contents = [
378+
("pack", self.view.stream_button),
379+
("pack", urwid.Divider(div_char=SECTION_DIVIDER_LINE)),
380+
submenu_view,
381+
]
382+
focus_item = 2
383+
else:
384+
self._contents = [
385+
("pack", self.view.stream_button),
386+
("pack", urwid.Divider(div_char=SECTION_DIVIDER_LINE)),
387+
]
388+
focus_item = 0
389+
390+
super().__init__(self.contents, focus_item=focus_item)
363391

364392

365393
class StreamsView(urwid.Frame):
@@ -833,14 +861,15 @@ def __init__(self, view: Any) -> None:
833861
self.controller = view.controller
834862
self.menu_v = self.menu_view()
835863
self.dm_v = self.dms_view()
836-
self.dm_panel = self.dms_panel(self.dm_v)
864+
self.dm_panel = self.dms_panel(None)
837865
self.stream_v = self.streams_view()
838866
self.stream_panel = self.streams_panel(self.stream_v)
839867
self.is_in_topic_view = False
868+
self.is_in_dm_panel_view = False
840869
contents = [
841870
(3, self.menu_v),
842871
("pack", urwid.Divider(COLUMN_TITLE_BAR_LINE)),
843-
self.dm_panel,
872+
("pack", self.dm_panel),
844873
("pack", urwid.Divider(COLUMN_TITLE_BAR_LINE)),
845874
self.stream_panel,
846875
]
@@ -869,11 +898,15 @@ def menu_view(self) -> Any:
869898
return w
870899

871900
def streams_panel(self, submenu_view: Any) -> Any:
872-
self.view.stream_p = StreamPanel(submenu_view, self.view)
901+
self.view.stream_p = StreamPanel(
902+
submenu_view, self.view, show_function=self.show_stream_panel
903+
)
873904
return self.view.stream_p
874905

875906
def dms_panel(self, submenu_view: Any) -> Any:
876-
self.view.dm_p = DMPanel(submenu_view, self.view)
907+
self.view.dm_p = DMPanel(
908+
submenu_view, self.view, show_function=self.show_dm_panel
909+
)
877910
return self.view.dm_p
878911

879912
def dms_view(self) -> Any:
@@ -1012,10 +1045,26 @@ def show_topic_view(self, stream_button: Any) -> None:
10121045
self.options(height_type="weight"),
10131046
)
10141047

1048+
def show_dm_panel(self) -> None:
1049+
self.dm_panel = self.dms_panel(self.dm_v)
1050+
self.contents[2] = (self.dm_panel, self.options(height_type="weight"))
1051+
self.stream_panel = self.streams_panel(None)
1052+
self.contents[4] = (self.stream_panel, self.options(height_type="pack"))
1053+
self.focus_position = 2
1054+
self.is_in_dm_panel_view = True
1055+
1056+
def show_stream_panel(self) -> None:
1057+
self.stream_panel = self.streams_panel(self.stream_v)
1058+
self.contents[4] = (self.stream_panel, self.options(height_type="weight"))
1059+
self.dm_panel = self.dms_panel(None)
1060+
self.contents[2] = (self.dm_panel, self.options(height_type="pack"))
1061+
self.focus_position = 4
1062+
self.is_in_dm_panel_view = False
1063+
10151064
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
1016-
if is_command_key("SEARCH_STREAMS", key) or is_command_key(
1065+
if (is_command_key("SEARCH_STREAMS", key) or is_command_key(
10171066
"SEARCH_TOPICS", key
1018-
):
1067+
)) and not self.is_in_dm_panel_view:
10191068
self.focus_position = 4
10201069
self.view.stream_p.focus_position = 2
10211070
if self.is_in_topic_view:
@@ -1025,6 +1074,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
10251074
return key
10261075
elif is_command_key("GO_RIGHT", key):
10271076
self.view.show_left_panel(visible=False)
1077+
elif is_command_key("ALL_PM", key):
1078+
self.show_dm_panel()
1079+
elif key == "S":
1080+
self.show_stream_panel()
10281081
return super().keypress(size, key)
10291082

10301083

0 commit comments

Comments
 (0)