Skip to content

Commit dbe6447

Browse files
preetmishraneiljp
authored andcommitted
views: Extend PopUpConfirmationView to accept location parameter.
The parameter is useful for prompts that have long descriptions.
1 parent 369a00d commit dbe6447

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

zulipterminal/ui_tools/views.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,16 @@ def __init__(self, controller: Any, title: str) -> None:
12561256
super().__init__(controller, body, "MARKDOWN_HELP", popup_width, title, header)
12571257

12581258

1259+
PopUpConfirmationViewLocation = Literal["top-left", "center"]
1260+
1261+
12591262
class PopUpConfirmationView(urwid.Overlay):
12601263
def __init__(
1261-
self, controller: Any, question: Any, success_callback: Callable[[], None]
1264+
self,
1265+
controller: Any,
1266+
question: Any,
1267+
success_callback: Callable[[], None],
1268+
location: PopUpConfirmationViewLocation = "top-left",
12621269
):
12631270
self.controller = controller
12641271
self.success_callback = success_callback
@@ -1268,19 +1275,31 @@ def __init__(
12681275
no._w = urwid.AttrMap(urwid.SelectableIcon("No", 4), None, "selected")
12691276
display_widget = urwid.GridFlow([yes, no], 3, 5, 1, "center")
12701277
wrapped_widget = urwid.WidgetWrap(display_widget)
1271-
prompt = urwid.LineBox(
1272-
urwid.ListBox(
1273-
urwid.SimpleFocusListWalker([question, urwid.Divider(), wrapped_widget])
1274-
)
1275-
)
1278+
widgets = [question, urwid.Divider(), wrapped_widget]
1279+
prompt = urwid.LineBox(urwid.ListBox(urwid.SimpleFocusListWalker(widgets)))
1280+
1281+
if location == "top-left":
1282+
align = "left"
1283+
valign = "top"
1284+
width = LEFT_WIDTH + 1
1285+
height = 8
1286+
else:
1287+
align = "center"
1288+
valign = "middle"
1289+
1290+
max_cols, max_rows = controller.maximum_popup_dimensions()
1291+
# +2 to compensate for the LineBox characters.
1292+
width = min(max_cols, max(question.pack()[0], len("Yes"), len("No"))) + 2
1293+
height = min(max_rows, sum(widget.rows((width,)) for widget in widgets)) + 2
1294+
12761295
urwid.Overlay.__init__(
12771296
self,
12781297
prompt,
12791298
self.controller.view,
1280-
align="left",
1281-
valign="top",
1282-
width=LEFT_WIDTH + 1,
1283-
height=8,
1299+
align=align,
1300+
valign=valign,
1301+
width=width,
1302+
height=height,
12841303
)
12851304

12861305
def exit_popup_yes(self, args: Any) -> None:

0 commit comments

Comments
 (0)