Skip to content

Commit 923a836

Browse files
srdeotarseneiljp
authored andcommitted
views: Add TopicInfoView to show pop up menu to change topic settings.
1 parent 17be9ed commit 923a836

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

zulipterminal/ui_tools/views.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import urwid
1212
from typing_extensions import Literal
1313

14-
from zulipterminal.api_types import EditPropagateMode
14+
from zulipterminal.api_types import RESOLVED_TOPIC_PREFIX, EditPropagateMode
1515
from zulipterminal.config.keys import (
1616
HELP_CATEGORIES,
1717
KEY_BINDINGS,
@@ -24,6 +24,7 @@
2424
CHECK_MARK,
2525
COLUMN_TITLE_BAR_LINE,
2626
PINNED_STREAMS_DIVIDER,
27+
STREAM_TOPIC_SEPARATOR,
2728
)
2829
from zulipterminal.config.ui_mappings import (
2930
BOT_TYPE_BY_ID,
@@ -1480,6 +1481,59 @@ def keypress(self, size: urwid_Size, key: str) -> str:
14801481
return super().keypress(size, key)
14811482

14821483

1484+
class TopicInfoView(PopUpView):
1485+
def __init__(self, controller: Any, stream_id: int, topic: str) -> None:
1486+
self.stream_id = stream_id
1487+
self.controller = controller
1488+
stream = controller.model.stream_dict[stream_id]
1489+
self.topic_name = topic
1490+
stream_name = stream["name"]
1491+
self.resolve_topic_btn_lbl = ""
1492+
1493+
title = f"{stream_name} {STREAM_TOPIC_SEPARATOR} {self.topic_name}"
1494+
1495+
topic_info_content = [] # type: PopUpViewTableContent
1496+
1497+
popup_width, column_widths = self.calculate_table_widths(
1498+
topic_info_content, len(title)
1499+
)
1500+
1501+
if self.topic_name.startswith(RESOLVED_TOPIC_PREFIX):
1502+
self.resolve_topic_setting_btn_lbl = "Unresolve Topic"
1503+
else:
1504+
self.resolve_topic_setting_btn_lbl = "Resolve Topic"
1505+
resolve_topic_setting = urwid.Button(
1506+
self.resolve_topic_setting_btn_lbl,
1507+
self.toggle_resolve_status,
1508+
)
1509+
1510+
curs_pos = len(self.resolve_topic_setting_btn_lbl) + 1
1511+
resolve_topic_setting._w = urwid.AttrMap(
1512+
urwid.SelectableIcon(
1513+
self.resolve_topic_setting_btn_lbl, cursor_position=curs_pos
1514+
),
1515+
None,
1516+
"selected",
1517+
)
1518+
popup_width = max(
1519+
popup_width,
1520+
len(resolve_topic_setting.label) + 4,
1521+
)
1522+
1523+
self.widgets = self.make_table_with_categories(
1524+
topic_info_content, column_widths
1525+
)
1526+
1527+
self.widgets.append(resolve_topic_setting)
1528+
super().__init__(controller, self.widgets, "TOPIC_INFO", popup_width, title)
1529+
1530+
def toggle_resolve_status(self, args: Any) -> None:
1531+
self.controller.model.un_resolve_topic(
1532+
stream_id=self.stream_id, topic_name=self.topic_name
1533+
)
1534+
self.controller.exit_popup()
1535+
1536+
14831537
class StreamMembersView(PopUpView):
14841538
def __init__(self, controller: Any, stream_id: int) -> None:
14851539
self.stream_id = stream_id

0 commit comments

Comments
 (0)