Extensions: show a dialog when dropping a URL while offline
The dialog notifies the user that online access is required with a button to go to the system preferences. See #120665.
This commit is contained in:
@@ -2349,14 +2349,44 @@ class BlPkgShowOnlinePreference(Operator):
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
wm = context.window_manager
|
||||
prefs = context.preferences
|
||||
|
||||
bpy.ops.screen.userpref_show('INVOKE_DEFAULT', section='SYSTEM')
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
# NOTE: this is a wrapper for `bl_pkg.extensions_show_online_prefs`.
|
||||
# It exists *only* show a dialog.
|
||||
class BlPkgShowOnlinePreferencePopup(Operator):
|
||||
"""Show system preferences "Network" panel to allow online access"""
|
||||
bl_idname = "bl_pkg.extensions_show_online_prefs_popup"
|
||||
bl_label = ""
|
||||
bl_options = {'INTERNAL'}
|
||||
|
||||
def execute(self, context):
|
||||
bpy.ops.screen.userpref_show('INVOKE_DEFAULT', section='SYSTEM')
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.window_manager
|
||||
wm.invoke_props_dialog(
|
||||
self,
|
||||
width=400,
|
||||
confirm_text="Go to Settings",
|
||||
title="Install Extension",
|
||||
)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
lines = (
|
||||
"Please turn Online Access on the System settings.",
|
||||
"",
|
||||
"Internet access is required to install extensions from the internet."
|
||||
)
|
||||
for line in lines:
|
||||
col.label(text=line)
|
||||
|
||||
|
||||
class BlPkgEnableNotInstalled(Operator):
|
||||
"""Turn on this extension"""
|
||||
bl_idname = "bl_pkg.extensions_enable_not_installed"
|
||||
@@ -2407,6 +2437,7 @@ classes = (
|
||||
|
||||
BlPkgShowUpgrade,
|
||||
BlPkgShowOnlinePreference,
|
||||
BlPkgShowOnlinePreferencePopup,
|
||||
|
||||
# Dummy, just shows a message.
|
||||
BlPkgEnableNotInstalled,
|
||||
|
||||
@@ -859,18 +859,28 @@ static void PREFERENCES_OT_extension_repo_upgrade(wmOperatorType *ot)
|
||||
static int preferences_extension_url_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
char *url = RNA_string_get_alloc(op->ptr, "url", nullptr, 0, nullptr);
|
||||
const bool url_is_remote = STRPREFIX(url, "http://") || STRPREFIX(url, "https://") ||
|
||||
STRPREFIX(url, "file://");
|
||||
const bool url_is_file = STRPREFIX(url, "file://");
|
||||
const bool url_is_online = STRPREFIX(url, "http://") || STRPREFIX(url, "https://");
|
||||
const bool url_is_remote = url_is_file | url_is_online;
|
||||
|
||||
/* NOTE: searching for hard-coded add-on name isn't great.
|
||||
* Needed since #WM_dropbox_add expects the operator to exist on startup. */
|
||||
const char *idname_external = url_is_remote ? "bl_pkg.pkg_install" : "bl_pkg.pkg_install_files";
|
||||
bool use_url = true;
|
||||
|
||||
if (url_is_online && (G.f & G_FLAG_INTERNET_ALLOW) == 0) {
|
||||
idname_external = "bl_pkg.extensions_show_online_prefs_popup";
|
||||
use_url = false;
|
||||
}
|
||||
|
||||
wmOperatorType *ot = WM_operatortype_find(idname_external, true);
|
||||
int retval;
|
||||
if (ot) {
|
||||
PointerRNA props_ptr;
|
||||
WM_operator_properties_create_ptr(&props_ptr, ot);
|
||||
RNA_string_set(&props_ptr, "url", url);
|
||||
if (use_url) {
|
||||
RNA_string_set(&props_ptr, "url", url);
|
||||
}
|
||||
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, event);
|
||||
WM_operator_properties_free(&props_ptr);
|
||||
retval = OPERATOR_FINISHED;
|
||||
|
||||
Reference in New Issue
Block a user