File size: 12,791 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
-- ========== GENERATED BY XTemplate Editor (Alt-F3) DO NOT EDIT MANUALLY! ==========

PlaceObj('XTemplate', {
	__is_kind_of = "GedApp",
	group = "GedApps",
	id = "PresetEditTemplate",
	save_in = "Common",
	PlaceObj('XTemplateWindow', {
		'__class', "GedApp",
		'Translate', true,
		'Title', "<PresetClass> Editor<opt(u(EditorShortcut),' (',')')>",
	}, {
		PlaceObj('XTemplateWindow', {
			'__context', function (parent, context) return "root" end,
			'__class', "GedTreePanel",
			'Id', "idPresets",
			'Title', "Items",
			'TitleFormatFunc', "GedFormatPresets",
			'SearchHistory', 20,
			'SearchValuesAvailable', true,
			'PersistentSearch', true,
			'ActionsClass', "Preset",
			'Delete', "GedOpPresetDelete",
			'Cut', "GedOpPresetCut",
			'Copy', "GedOpPresetCopy",
			'Paste', "GedOpPresetPaste",
			'Duplicate', "GedOpPresetDuplicate",
			'ActionContext', "PresetsPanelAction",
			'SearchActionContexts', {
				"PresetsPanelAction",
				"PresetsChildAction",
			},
			'FormatFunc', "GedPresetTree",
			'Format', "<if(mod)>[<u('ModItem')>] </if><if(IsReadOnly)><color 150 150 150></if><EditorView><if(IsReadOnly)></color></if>",
			'FilterName', "PresetFilter",
			'SelectionBind', "SelectedPreset,SelectedObject",
			'MultipleSelection', true,
			'ItemClass', function (gedapp) return gedapp.PresetClass end,
			'RootActionContext', "PresetsPanelAction",
			'ChildActionContext', "PresetsChildAction",
		}, {
			PlaceObj('XTemplateWindow', {
				'comment', "bookmarks",
				'__context', function (parent, context) return "bookmarks" end,
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
				'__class', "GedTreePanel",
				'Id', "idBookmarks",
				'Dock', "bottom",
				'MaxHeight', 350,
				'Collapsible', true,
				'StartsExpanded', true,
				'ExpandedMessage', "(press F2 to cycle)",
				'EmptyMessage', "(press Ctrl-F2 to bookmark)",
				'Title', "Bookmarks",
				'EnableSearch', false,
				'FormatFunc', "GedBookmarksTree",
				'Format', "<EditorView>",
				'SelectionBind', "SelectedPreset,SelectedObject,SelectedBookmark",
				'EmptyText', "Add a bookmark here by pressing Ctrl-F2.",
				'ChildActionContext', "BookmarksChildAction",
				'ShowToolbarButtons', false,
			}, {
				PlaceObj('XTemplateFunc', {
					'name', "Open(self, ...)",
					'func', function (self, ...)
						self.expanded = true
						GedTreePanel.Open(self, ...)
						self.connection:Send("rfnBindBookmarks", self.context, self.app.PresetClass)
					end,
				}),
				PlaceObj('XTemplateAction', {
					'ActionId', "RemoveBookmark",
					'ActionTranslate', false,
					'ActionName', "Remove Bookmark",
					'OnAction', function (self, host, source, ...)
						host:Send("GedToggleBookmark", "SelectedBookmark", host.PresetClass)
					end,
					'ActionContexts', {
						"BookmarksChildAction",
					},
				}),
				PlaceObj('XTemplateAction', {
					'ActionId', "NextBookmark",
					'ActionTranslate', false,
					'ActionName', "Next Bookmark",
					'ActionShortcut', "F2",
					'OnAction', function (self, host, source, ...)
						local tree = host.idPresets.idBookmarks.idContainer
						local selection = tree:GetSelection()
						if not selection then
							tree:SetSelection{ 1 }
						else
							tree:OnShortcut("Down")
							local new_selection = tree:GetSelection() -- get first value returned
							if ValueToLuaCode(selection) == ValueToLuaCode(new_selection) then
								tree:SetSelection{ 1 }
							end
						end
					end,
				}),
				}),
			PlaceObj('XTemplateWindow', {
				'comment', "preset filter panel",
				'__context', function (parent, context) return "PresetFilter" end,
				'__class', "GedPropPanel",
				'Dock', "bottom",
				'Visible', false,
				'FoldWhenHidden', true,
				'Collapsible', true,
				'Title', "<FilterName>",
				'EnableSearch', false,
				'DisplayWarnings', false,
				'EnableUndo', false,
				'EnableCollapseDefault', false,
				'EnableShowInternalNames', false,
				'EnableCollapseCategories', false,
				'HideFirstCategory', true,
			}),
			PlaceObj('XTemplateTemplate', {
				'__template', "GedStatusBar",
			}),
			}),
		PlaceObj('XTemplateAction', {
			'ActionId', "File",
			'ActionName', T(923464262345, --[[XTemplate PresetEditTemplate ActionName]] "File"),
			'ActionMenubar', "main",
			'OnActionEffect', "popup",
		}, {
			PlaceObj('XTemplateAction', {
				'ActionId', "idNews",
				'ActionName', T(689845029747, --[[XTemplate PresetEditTemplate ActionName]] "New"),
				'ActionIcon', "CommonAssets/UI/Ged/new.tga",
				'ActionToolbar', "main",
				'OnActionEffect', "popup",
			}, {
				PlaceObj('XTemplateForEach', {
					'array', function (parent, context) return context.Classes end,
					'run_after', function (child, context, item, i, n, last)
						child.ActionId = "New" .. item
						child.ActionName = "New " .. item
						child.ActionTranslate = false
						child.OnAction = function(self, host)
							host:Op("GedOpNewPreset", "root", host.idPresets:GetSelection(), item)
						end
					end,
				}, {
					PlaceObj('XTemplateAction', {
						'ActionIcon', "CommonAssets/UI/Ged/new.tga",
						'ActionContexts', {
							"PresetsPanelAction",
						},
					}),
					}),
				}),
			PlaceObj('XTemplateCode', {
				'comment', '-- If single "new" action, move to top level',
				'run', function (self, parent, context)
					local newAction = parent:ActionById("idNews")
					local subitemActions = table.ifilter(parent:GetActions(), function(k, action) return action.ActionMenubar == "idNews" end)
					if #subitemActions == 1 then
						subitemActions[1]:SetActionMenubar(newAction.ActionMenubar)
						subitemActions[1]:SetActionToolbar("main")
						parent:RemoveAction(newAction)
					end
				end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "SavePreset",
				'ActionName', T(710972932371, --[[XTemplate PresetEditTemplate ActionName]] "Save"),
				'ActionIcon', "CommonAssets/UI/Ged/save.tga",
				'ActionToolbar', "main",
				'ActionToolbarSplit', true,
				'ActionShortcut', "Ctrl-S",
				'OnAction', function (self, host, source, ...)
					host:OnSaving()
					if config.ModdingToolsInUserMode then
						host:Send("GedPresetSaveMods", "SelectedPreset", host.PresetClass)
					else
						host:Send("GedPresetSave", "SelectedPreset", host.PresetClass)
					end
				end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "SavePresetForce",
				'ActionName', T(430241313051, --[[XTemplate PresetEditTemplate ActionName]] "Force Save All"),
				'ActionIcon', "CommonAssets/UI/Ged/save.tga",
				'ActionShortcut', "Ctrl-Shift-S",
				'OnAction', function (self, host, source, ...)
					host:OnSaving()
					if config.ModdingToolsInUserMode then
						host:Send("GedPresetSaveMods", "SelectedPreset", host.PresetClass)
					else
						host:Send("GedPresetSave", "SelectedPreset", host.PresetClass, "force_save_all")
					end
				end,
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "SVNShowLog",
				'ActionTranslate', false,
				'ActionName', "SVN Show Log",
				'OnAction', function (self, host, source, ...)
					host:Op("GedOpSVNShowLog", "SelectedPreset")
				end,
				'ActionContexts', {
					"PresetsChildAction",
				},
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "SVNShowDiff",
				'ActionTranslate', false,
				'ActionName', "SVN Diff",
				'OnAction', function (self, host, source, ...)
					host:Op("GedOpSVNShowDiff", "SelectedPreset")
				end,
				'ActionContexts', {
					"PresetsChildAction",
				},
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "SVNShowBlame",
				'ActionTranslate', false,
				'ActionName', "SVN Blame",
				'OnAction', function (self, host, source, ...)
					host:Op("GedOpSVNShowBlame", "SelectedPreset")
				end,
				'ActionContexts', {
					"PresetsChildAction",
				},
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "LocatePreset",
				'ActionTranslate', false,
				'ActionName', "Find preset references",
				'OnAction', function (self, host, source, ...)
					host:Op("GedOpLocatePreset", "SelectedPreset")
				end,
				'ActionContexts', {
					"PresetsChildAction",
				},
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "GoToNext",
				'ActionTranslate', false,
				'ActionName', "Next reference",
				'ActionShortcut', "Ctrl-G",
				'OnAction', function (self, host, source, ...)
					host:Op("GedOpGoToNext", "SelectedPreset")
				end,
				'ActionContexts', {
					"PresetsChildAction",
				},
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "AddRemoveBookmark",
				'ActionTranslate', false,
				'ActionName', "Add / Remove Bookmark",
				'ActionIcon', "CommonAssets/UI/Ged/bookmark_icon",
				'ActionToolbar', "main",
				'ActionShortcut', "Ctrl-F2",
				'OnAction', function (self, host, source, ...)
					host:Send("GedToggleBookmark", "SelectedPreset", host.PresetClass)
				end,
				'ActionContexts', {
					"PresetsChildAction",
				},
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			PlaceObj('XTemplateAction', {
				'ActionId', "ToggleDisplayWarnings",
				'ActionTranslate', false,
				'ActionName', "Toggle Display Warnings",
				'ActionIcon', "CommonAssets/UI/Ged/exclamation.tga",
				'ActionToolbar', "main",
				'ActionToolbarSplit', true,
				'ActionShortcut', "Ctrl-W",
				'ActionToggle', true,
				'ActionToggled', function (self, host)
					return host.actions_toggled["ToggleDisplayWarnings"]
				end,
				'OnAction', function (self, host, source, ...)
					host:SetActionToggled("ToggleDisplayWarnings", not host.actions_toggled["ToggleDisplayWarnings"])
					
					for _, panel in ipairs(host.all_panels) do
						if IsKindOf(panel, "GedPropPanel") or IsValid(panel) then
							local display_warnings = not host.actions_toggled["ToggleDisplayWarnings"]
							panel:SetDisplayWarnings(display_warnings)
							
							if not display_warnings then
								panel:UnbindView("warning")
								-- Hide existing warnings
								panel.idWarningText:SetVisible(false)
							else
								panel:BindView("warning", "GedGetWarning")
							end
						end
					end	
				end,
				'__condition', function (parent, context) return not config.ModdingToolsInUserMode end,
			}),
			}),
		PlaceObj('XTemplateCode', {
			'comment', "-- Custom Editor Actions",
			'run', function (self, parent, context)
				local has_toggle_actions = false
				
				for func_name, data in sorted_pairs(context.EditorCustomActions or empty_table) do
					if type(func_name) ~= "string" then func_name = data.FuncName end
					if type(func_name) ~= "string" or func_name == "" then func_name = false end
					
					local action = XAction:new({
						ActionId = data.Name,
						ActionName = data.Name or "Unnamed",
						ActionTranslate = false,
						ActionToggle = data.IsToggledFuncName,
						ActionShortcut = data.Shortcut or "",
						ActionMenubar = data.Menubar,
						ActionToolbar = data.Toolbar or "",
						ActionToolbarSplit = data.Split,
						ActionIcon = data.Icon or "CommonAssets/UI/Ged/cog.tga",
						ActionSortKey = data.SortKey or "10000",
						RolloverText = data.Rollover,
					}, parent)
					if func_name then
						action.OnAction = function(self, host)
							if data.IsToggledFuncName then
								parent.actions_toggled[data.Name] = not parent.actions_toggled[data.Name]
							end
							host:Send("GedCustomEditorAction", "SelectedPreset", func_name)
						end
					else
						action.OnActionEffect = "popup"
					end
					if data.IsToggledFuncName then
						has_toggle_actions = true
						action.ActionToggled = function(self, host)
							return host.actions_toggled[data.Name]
						end
					end
				end
				
				if has_toggle_actions then
					CreateRealTimeThread(function()
						for _, data in sorted_pairs(context.EditorCustomActions or empty_table) do
							if data.IsToggledFuncName then
								parent.actions_toggled[data.Name] = parent:Call("GedGetToggledActionState", data.IsToggledFuncName)
							end
						end
						parent:ActionsUpdated()
					end)
				end
			end,
		}),
		PlaceObj('XTemplateCode', {
			'comment', "-- Setup preset filter, alt format",
			'run', function (self, parent, context)
				parent.idPresets.FilterClass = parent.FilterClass
				parent.idPresets.AltFormat = parent.AltFormat
			end,
		}),
		}),
})