|
11 | 11 | import urwid
|
12 | 12 | from typing_extensions import Literal
|
13 | 13 |
|
14 |
| -from zulipterminal.api_types import EditPropagateMode |
| 14 | +from zulipterminal.api_types import RESOLVED_TOPIC_PREFIX, EditPropagateMode |
15 | 15 | from zulipterminal.config.keys import (
|
16 | 16 | HELP_CATEGORIES,
|
17 | 17 | KEY_BINDINGS,
|
|
24 | 24 | CHECK_MARK,
|
25 | 25 | COLUMN_TITLE_BAR_LINE,
|
26 | 26 | PINNED_STREAMS_DIVIDER,
|
| 27 | + STREAM_TOPIC_SEPARATOR, |
27 | 28 | )
|
28 | 29 | from zulipterminal.config.ui_mappings import (
|
29 | 30 | BOT_TYPE_BY_ID,
|
@@ -1480,6 +1481,59 @@ def keypress(self, size: urwid_Size, key: str) -> str:
|
1480 | 1481 | return super().keypress(size, key)
|
1481 | 1482 |
|
1482 | 1483 |
|
| 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 | + |
1483 | 1537 | class StreamMembersView(PopUpView):
|
1484 | 1538 | def __init__(self, controller: Any, stream_id: int) -> None:
|
1485 | 1539 | self.stream_id = stream_id
|
|
0 commit comments