Skip to content

Commit aef201b

Browse files
committed
Added confirmation dialog for workspace change in Api._confirm_workspace_change method and updated Api.request_workspace_change_from_BcPlugin method to use it
1 parent fa29279 commit aef201b

1 file changed

Lines changed: 53 additions & 22 deletions

File tree

Core/Api.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@
2121
class Api:
2222
"""API bridge helpers for Core integrations."""
2323

24+
@staticmethod
25+
def _confirm_workspace_change(gui, folder: str) -> bool:
26+
try:
27+
from Core.WidgetsCreator import show_msgbox
28+
29+
title = "Confirmation"
30+
message = (
31+
f"Un plugin demande de changer le workspace vers :\n{folder}\n\n"
32+
"Voulez-vous continuer ?"
33+
)
34+
try:
35+
if hasattr(gui, "tr"):
36+
title = gui.tr("Confirmation", "Confirmation")
37+
message = gui.tr(
38+
f"Un plugin demande de changer le workspace vers :\n{folder}\n\n"
39+
"Voulez-vous continuer ?",
40+
f"A plugin requests changing the workspace to:\n{folder}\n\n"
41+
"Do you want to continue?",
42+
)
43+
except Exception:
44+
pass
45+
46+
res = show_msgbox("question", title, message, parent=gui, default="Yes")
47+
return bool(res)
48+
except Exception:
49+
# If confirmation UI fails, accept by contract
50+
return True
51+
2452
@staticmethod
2553
def request_workspace_change_from_BcPlugin(folder: str) -> bool:
2654
try:
@@ -38,34 +66,37 @@ def request_workspace_change_from_BcPlugin(folder: str) -> bool:
3866
if invoker is None or not isinstance(invoker, _UiInvoker):
3967
invoker = _UiInvoker(gui)
4068
setattr(gui, "_ui_invoker", invoker)
41-
result_holder = {"ok": False}
42-
loop = _QEventLoop()
43-
44-
def _do():
45-
try:
46-
result_holder["ok"] = bool(
47-
gui.apply_workspace_selection(str(folder), source="plugin")
48-
)
49-
except Exception:
50-
result_holder["ok"] = False
51-
finally:
52-
try:
53-
loop.quit()
54-
except Exception:
55-
pass
69+
result_holder = {"ok": False}
70+
loop = _QEventLoop()
5671

72+
def _do():
5773
try:
58-
invoker.post(_do)
74+
if not Api._confirm_workspace_change(gui, str(folder)):
75+
result_holder["ok"] = False
76+
return
77+
result_holder["ok"] = bool(
78+
gui.apply_workspace_selection(str(folder), source="plugin")
79+
)
5980
except Exception:
60-
# Fallback: direct call in case invoker posting fails
81+
result_holder["ok"] = False
82+
finally:
6183
try:
62-
return bool(
63-
gui.apply_workspace_selection(str(folder), source="plugin")
64-
)
84+
loop.quit()
6585
except Exception:
86+
pass
87+
88+
try:
89+
invoker.post(_do)
90+
except Exception:
91+
# Fallback: direct call in case invoker posting fails
92+
try:
93+
if not Api._confirm_workspace_change(gui, str(folder)):
6694
return False
67-
loop.exec()
68-
return bool(result_holder.get("ok", False))
95+
return bool(gui.apply_workspace_selection(str(folder), source="plugin"))
96+
except Exception:
97+
return False
98+
loop.exec()
99+
return bool(result_holder.get("ok", False))
69100
except Exception:
70101
# Accept by contract even on unexpected errors
71102
return True

0 commit comments

Comments
 (0)