|
10 | 10 | import urwid |
11 | 11 | from typing_extensions import Literal |
12 | 12 |
|
13 | | -from zulipterminal.api_types import EditPropagateMode, Message |
| 13 | +from zulipterminal.api_types import RESOLVED_TOPIC_PREFIX, EditPropagateMode, Message |
14 | 14 | from zulipterminal.config.keys import ( |
15 | 15 | HELP_CATEGORIES, |
16 | 16 | KEY_BINDINGS, |
|
25 | 25 | COLUMN_TITLE_BAR_LINE, |
26 | 26 | PINNED_STREAMS_DIVIDER, |
27 | 27 | SECTION_DIVIDER_LINE, |
| 28 | + STREAM_TOPIC_SEPARATOR, |
28 | 29 | ) |
29 | 30 | from zulipterminal.config.ui_mappings import ( |
30 | 31 | BOT_TYPE_BY_ID, |
@@ -1569,6 +1570,65 @@ def keypress(self, size: urwid_Size, key: str) -> str: |
1569 | 1570 | return super().keypress(size, key) |
1570 | 1571 |
|
1571 | 1572 |
|
| 1573 | +class TopicInfoView(PopUpView): |
| 1574 | + def __init__(self, controller: Any, stream_id: int, topic: str) -> None: |
| 1575 | + self.stream_id = stream_id |
| 1576 | + self.controller = controller |
| 1577 | + stream = controller.model.stream_dict[stream_id] |
| 1578 | + self.topic_name = topic |
| 1579 | + stream_name = stream["name"] |
| 1580 | + |
| 1581 | + title = f"{stream_name} {STREAM_TOPIC_SEPARATOR} {self.topic_name}" |
| 1582 | + |
| 1583 | + topic_info_content: PopUpViewTableContent = [] |
| 1584 | + |
| 1585 | + popup_width, column_widths = self.calculate_table_widths( |
| 1586 | + topic_info_content, len(title) |
| 1587 | + ) |
| 1588 | + |
| 1589 | + if self.topic_name.startswith(RESOLVED_TOPIC_PREFIX): |
| 1590 | + self.resolve_topic_setting_btn_lbl = "Unresolve Topic" |
| 1591 | + else: |
| 1592 | + self.resolve_topic_setting_btn_lbl = "Resolve Topic" |
| 1593 | + resolve_topic_setting = urwid.Button( |
| 1594 | + self.resolve_topic_setting_btn_lbl, |
| 1595 | + self.toggle_resolve_status, |
| 1596 | + ) |
| 1597 | + |
| 1598 | + curs_pos = len(self.resolve_topic_setting_btn_lbl) + 1 |
| 1599 | + # This shifts the cursor present over the first character of |
| 1600 | + # resolve_topic_button_setting label to last character + 1 so that it isn't |
| 1601 | + # visible |
| 1602 | + |
| 1603 | + resolve_topic_setting._w = urwid.AttrMap( |
| 1604 | + urwid.SelectableIcon( |
| 1605 | + self.resolve_topic_setting_btn_lbl, cursor_position=curs_pos |
| 1606 | + ), |
| 1607 | + None, |
| 1608 | + "selected", |
| 1609 | + ) |
| 1610 | + |
| 1611 | + # Manual because calculate_table_widths does not support buttons. |
| 1612 | + # Add 4 to button label to accommodate the buttons itself. |
| 1613 | + popup_width = max( |
| 1614 | + popup_width, |
| 1615 | + len(resolve_topic_setting.label) + 4, |
| 1616 | + ) |
| 1617 | + |
| 1618 | + self.widgets = self.make_table_with_categories( |
| 1619 | + topic_info_content, column_widths |
| 1620 | + ) |
| 1621 | + |
| 1622 | + self.widgets.append(resolve_topic_setting) |
| 1623 | + super().__init__(controller, self.widgets, "TOPIC_INFO", popup_width, title) |
| 1624 | + |
| 1625 | + def toggle_resolve_status(self, args: Any) -> None: |
| 1626 | + self.controller.model.toggle_topic_resolve_status( |
| 1627 | + stream_id=self.stream_id, topic_name=self.topic_name |
| 1628 | + ) |
| 1629 | + self.controller.exit_popup() |
| 1630 | + |
| 1631 | + |
1572 | 1632 | class MsgInfoView(PopUpView): |
1573 | 1633 | def __init__( |
1574 | 1634 | self, |
|
0 commit comments