forked from SuzanneSoy/SearchBar
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetItemGroups.py
84 lines (63 loc) · 2.48 KB
/
GetItemGroups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import FreeCAD as App
import FreeCADGui as Gui
globalGroups = []
itemGroups = None
serializedItemGroups = None
# Define the translation
translate = App.Qt.translate
def onResultSelected(index, groupId):
global globalGroups
nfo = globalGroups[groupId]
handlerName = nfo["action"]["handler"]
import SearchResults
if handlerName in SearchResults.actionHandlers:
SearchResults.actionHandlers[handlerName](nfo)
else:
from PySide import QtGui
QtGui.QMessageBox.warning(
None,
translate("SearchBar", "Could not execute this action"),
translate(
"SearchBar",
"Could not execute this action, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.",
),
)
def getToolTip(groupId, setParent):
global globalGroups
nfo = globalGroups[int(groupId)]
handlerName = nfo["action"]["handler"]
import SearchResults
if handlerName in SearchResults.toolTipHandlers:
return SearchResults.toolTipHandlers[handlerName](nfo, setParent)
else:
return translate(
"SearchBar",
"Could not load tooltip for this tool, it could be from a Mod that has been uninstalled. Try refreshing the list of tools.",
)
def getItemGroups():
global itemGroups, serializedItemGroups, globalGroups
# Import the tooltip+action handlers and search result providers that are bundled with this Mod.
# Other providers should import SearchResults and register their handlers and providers
import BuiltInSearchResults
# Load the list of tools, preferably from the cache, if it has not already been loaded:
if itemGroups is None:
if serializedItemGroups is None:
import RefreshTools
itemGroups = RefreshTools.refreshToolbars(doLoadAllWorkbenches=False)
else:
import Serialize_SearchBar
itemGroups = Serialize_SearchBar.deserialize(serializedItemGroups)
# Aggregate the tools (cached) and document objects (not cached), and assign an index to each
import SearchResults
igs = itemGroups
for providerName, provider in SearchResults.resultProvidersUncached.items():
igs = igs + provider()
globalGroups = []
def addId(group):
globalGroups.append(group)
group["id"] = len(globalGroups) - 1
for subitem in group["subitems"]:
addId(subitem)
for ig in igs:
addId(ig)
return igs