From 11b1919bcfe3a81283f3e81223ddc4dcc0525a0f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 6 Jul 2024 14:49:41 +1000 Subject: [PATCH] Extensions: resolve popup glitches when dropping URL's Use UILayout::template_popup_confirm to replace workarounds that didn't work very well. - Resolve "Add Repository..." button in the dialog not closing the popup when pressed. - Add a "Cancel" button while the remote resository data is downloading. - Remove the hack to scale the UILayout to hide the existing confirm/cancel buttons. Resolves #124098. --- .../addons_core/bl_pkg/bl_extension_ops.py | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/addons_core/bl_pkg/bl_extension_ops.py b/scripts/addons_core/bl_pkg/bl_extension_ops.py index 6b21cbe3823..964d649c4da 100644 --- a/scripts/addons_core/bl_pkg/bl_extension_ops.py +++ b/scripts/addons_core/bl_pkg/bl_extension_ops.py @@ -258,26 +258,17 @@ class OperatorNonBlockingSyncHelper: self.completed = True return - layout = _operator_draw_hide_buttons_hack(op.layout) + layout = op.layout text, icon = update_ui_text() layout.label(text=text, icon=icon) + # Only show a "Cancel" button while the update is in progress. + layout.template_popup_confirm("", text="", cancel_text="Cancel") # ----------------------------------------------------------------------------- # Internal Utilities # -def _operator_draw_hide_buttons_hack(layout): - # EVIL! There is no good way to hide button on operator dialogs, - # so use a bad way (scale them to oblivion!) - # This could be supported by the internals, for now it's not though. - col = layout.column() - y = 1000.0 - col.scale_y = y - layout.scale_y = 1.0 / y - return col - - def _sequence_split_with_job_limit(items, job_limit): # When only one job is allowed at a time, there is no advantage to splitting the sequence. if job_limit == 1: @@ -2898,7 +2889,7 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn): *, errors, ): - layout = _operator_draw_hide_buttons_hack(self.layout) + layout = self.layout icon = 'ERROR' for error in errors: if isinstance(error, str): @@ -2906,6 +2897,9 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn): else: error(layout) icon = 'BLANK1' + + # Only show a "Close" button since this is only showing a message. + layout.template_popup_confirm("", text="", cancel_text="Close") return True # Pass 3: add-repository (terminating). @@ -2918,7 +2912,7 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn): url_split = remote_url.partition("://") url_for_display = url_split[2] if url_split[2] else remote_url - layout = _operator_draw_hide_buttons_hack(self.layout) + layout = self.layout col = layout.column(align=True) col.label(text="The dropped extension comes from an unknown repository.") col.label(text="If you trust its source, add the repository and try again.") @@ -2932,7 +2926,7 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn): col.label(text="Alternatively download the extension to Install from Disk.") layout.operator_context = 'INVOKE_DEFAULT' - props = layout.operator("preferences.extension_repo_add", text="Add Repository...") + props = layout.template_popup_confirm("preferences.extension_repo_add", text="Add Repository...") props.remote_url = remote_url return True