Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VCSPlugins.c
Go to the documentation of this file.
1#ifdef WORKBENCH
3 name: "VCS Configuration",
4 description: "Configure Blame/Diff/Log/Commit commands",
5 wbModules: { "ResourceManager", "ScriptEditor" },
6 category: SCR_PluginCategory.SCRIPTEDITOR_VCS,
7 awesomeFontCode: 0xF1DE)]
8class SCR_VCSSettingsPlugin : WorkbenchPlugin
9{
10 /*
11 Category: Commands
12 */
13
14 [Attribute(defvalue: TORTOISESVN_BLAME, desc: "Find out whodunit", category: "Commands")]
15 protected string m_sBlameCommandLine;
16
17 [Attribute(defvalue: TORTOISESVN_DIFF, desc: "Find out local changes", category: "Commands")]
18 protected string m_sDiffCommandLine;
19
20 [Attribute(defvalue: TORTOISESVN_LOG, desc: "Find out the file history", category: "Commands")]
21 protected string m_sLogCommandLine;
22
23 [Attribute(defvalue: TORTOISESVN_COMMIT, desc: "Commit the current directory", category: "Commands")]
24 protected string m_sCommitCommandLine;
25
26 /*
27 Category: Settings
28 */
29
30 [Attribute(defvalue: "1", desc: "Commit root directory, otherwise only commit the currently-opened file", category: "Settings")]
31 protected bool m_bCommitRootDirectory;
32
33 /*
34 Category: Debug
35 */
36
37 [Attribute(defvalue: "0", desc: "Prints the command in log console", category: "Debug")]
38 protected bool m_bPrintCommandOnUse;
39
40 protected static const string TORTOISESVN_BLAME = "TortoiseProc /command:blame /path:\"$path\" /startrev:1 /endrev:-1 /ignoreeol /ignoreallspaces /line:$line";
41 protected static const string TORTOISESVN_DIFF = "TortoiseProc /command:diff /path:\"$path\"";
42 protected static const string TORTOISESVN_LOG = "TortoiseProc /command:log /path:\"$path\"";
43 protected static const string TORTOISESVN_COMMIT = "TortoiseProc /command:commit /path:\"$dir\"";
44
45 protected static const string GITEXT_BLAME = "gitex blame \"$path\"";
46 protected static const string GITEXT_DIFF = "gitex difftool \"$path\"";
47 protected static const string GITEXT_LOG = "gitex filehistory \"$path\"";
48 protected static const string GITEXT_COMMIT = "gitex commit \"$dir\"";
49
50 //------------------------------------------------------------------------------------------------
51 protected override void Configure()
52 {
53 Workbench.ScriptDialog(
54 "Configure Blame/Diff/Log/Commit commands",
55 "Settings are per Workbench module (e.g Resource Manager can have different settings than Script Editor).\n\n"
56 + "Available parameters:\n"
57 + "- $path: the absolute file path (unquoted)\n"
58 + "- $dir: the absolute file/commit directory (unquoted)\n"
59 + "- $line: the current line number",
60 this);
61 }
62
63 //------------------------------------------------------------------------------------------------
64 [ButtonAttribute("Set TortoiseSVN values")]
65 protected void ButtonTortoiseSVN()
66 {
67 m_sBlameCommandLine = TORTOISESVN_BLAME;
68 m_sDiffCommandLine = TORTOISESVN_DIFF;
69 m_sLogCommandLine = TORTOISESVN_LOG;
70 m_sCommitCommandLine = TORTOISESVN_COMMIT;
71 }
72
73 //------------------------------------------------------------------------------------------------
74 [ButtonAttribute("Set Git Extensions values")]
75 protected void ButtonGitExtensions()
76 {
77 m_sBlameCommandLine = GITEXT_BLAME;
78 m_sDiffCommandLine = GITEXT_DIFF;
79 m_sLogCommandLine = GITEXT_LOG;
80 m_sCommitCommandLine = GITEXT_COMMIT;
81 }
82
83 //------------------------------------------------------------------------------------------------
84 [ButtonAttribute("Close", true)]
85 protected void ButtonClose();
86
87 //------------------------------------------------------------------------------------------------
88 string GetBlameCommandLine() { return m_sBlameCommandLine; }
89 string GetDiffCommandLine() { return m_sDiffCommandLine; }
90 string GetLogCommandLine() { return m_sLogCommandLine; }
91 string GetCommitCommandLine() { return m_sCommitCommandLine; }
92 bool GetCommitRootDirectory() { return m_bCommitRootDirectory; }
93 bool GetPrintCommandOnUse() { return m_bPrintCommandOnUse; }
94}
95
96class SCR_VCSRootPlugin : WorkbenchPlugin
97{
98 protected typename m_WorkbenchModuleTypename;
99
100 //------------------------------------------------------------------------------------------------
101 protected override void Run()
102 {
103 array<string> absoluteFilePaths = {};
104 array<int> lineNumbers = {};
105
106 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
107 if (!vcsSettingsPlugin)
108 return; // no settings?!
109
110 bool commitRootDirectory = vcsSettingsPlugin.GetCommitRootDirectory();
111 bool printCommand = vcsSettingsPlugin.GetPrintCommandOnUse();
112
113 if (!GetFilesToProcess(absoluteFilePaths, lineNumbers))
114 {
115 // if no files open, commit root directory
116 string thisStr = ToString();
117 if (commitRootDirectory && thisStr.StartsWith("" + SCR_VCSCommitPlugin)) // ugly!
118 {
119 string command = GetCommandLine();
120 string directory;
121 if (!Workbench.GetAbsolutePath("", directory, true))
122 return;
123
124 command.Replace("$dir", directory);
125 if (printCommand)
126 Print("" + command, LogLevel.NORMAL);
127
128 Workbench.RunCmd(command);
129 }
130 else // quit
131 {
132 Print("Cannot obtain current file(s) - " + thisStr, LogLevel.WARNING);
133 }
134
135 return;
136 }
137
138 int absoluteFilePathsCount = absoluteFilePaths.Count();
139 if (absoluteFilePathsCount < 1)
140 return;
141
142 if (lineNumbers.Count() < absoluteFilePathsCount)
143 lineNumbers.Resize(absoluteFilePathsCount); // fill with zeroes
144
145 string originalCommand = GetCommandLine();
146 if (printCommand)
147 Print("" + originalCommand, LogLevel.NORMAL);
148
149 string directory;
150 if (commitRootDirectory)
151 commitRootDirectory = Workbench.GetAbsolutePath("", directory, true); // cannot really fail?
152
153 foreach (int i, string absoluteFilePath : absoluteFilePaths)
154 {
155 string command = originalCommand;
156
157 if (!commitRootDirectory)
158 directory = FilePath.StripFileName(absoluteFilePath);
159
160 command.Replace("$path", absoluteFilePath);
161 command.Replace("$dir", directory);
162 command.Replace("$line", lineNumbers[i].ToString());
163
164 if (printCommand)
165 Print("" + command, LogLevel.NORMAL);
166
167 Workbench.RunCmd(command);
168 }
169 }
170
171 //------------------------------------------------------------------------------------------------
172 protected SCR_VCSSettingsPlugin GetVCSSettings(typename workbenchModuleTypename)
173 {
174 WBModuleDef workbenchModule = Workbench.GetModule(workbenchModuleTypename);
175 if (!workbenchModule)
176 return null;
177
178 return SCR_VCSSettingsPlugin.Cast(workbenchModule.GetPlugin(SCR_VCSSettingsPlugin));
179 }
180
181 //------------------------------------------------------------------------------------------------
182 protected string GetBlameCommandLine()
183 {
184 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
185 if (!vcsSettingsPlugin)
186 return string.Empty;
187
188 return vcsSettingsPlugin.GetBlameCommandLine();
189 }
190
191 //------------------------------------------------------------------------------------------------
192 protected string GetDiffCommandLine()
193 {
194 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
195 if (!vcsSettingsPlugin)
196 return string.Empty;
197
198 return vcsSettingsPlugin.GetDiffCommandLine();
199 }
200
201 //------------------------------------------------------------------------------------------------
202 protected string GetLogCommandLine()
203 {
204 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
205 if (!vcsSettingsPlugin)
206 return string.Empty;
207
208 return vcsSettingsPlugin.GetLogCommandLine();
209 }
210
211 //------------------------------------------------------------------------------------------------
212 protected string GetCommitCommandLine()
213 {
214 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
215 if (!vcsSettingsPlugin)
216 return string.Empty;
217
218 return vcsSettingsPlugin.GetCommitCommandLine();
219 }
220
221 //------------------------------------------------------------------------------------------------
222 // to be overridden by each module root plugin
223 protected bool GetFilesToProcess(notnull out array<string> absoluteFilePaths, notnull out array<int> lineNumbers);
224
225 //------------------------------------------------------------------------------------------------
226 // to be overridden with Get*CommandLine by each plugin
227 protected string GetCommandLine();
228}
229
230class SCR_VCSScriptEditorRootPlugin : SCR_VCSRootPlugin
231{
232 //------------------------------------------------------------------------------------------------
233 protected override bool GetFilesToProcess(notnull out array<string> absoluteFilePaths, notnull out array<int> lineNumbers)
234 {
235 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
236 if (!scriptEditor)
237 return false;
238
239 string file;
240 string absoluteFilePath;
241 if (!scriptEditor.GetCurrentFile(file) || !Workbench.GetAbsolutePath(file, absoluteFilePath))
242 {
243 Print("File cannot be opened " + file, LogLevel.WARNING);
244 return false;
245 }
246
247 absoluteFilePaths.Insert(absoluteFilePath);
248 lineNumbers.Insert(scriptEditor.GetCurrentLine() + 1); // 0-based
249
250 return true;
251 }
252
253 //------------------------------------------------------------------------------------------------
254 // constructor
255 void SCR_VCSScriptEditorRootPlugin()
256 {
257 m_WorkbenchModuleTypename = ScriptEditor;
258 }
259}
260
261class SCR_VCSResourceManagerRootPlugin : SCR_VCSRootPlugin
262{
263 //------------------------------------------------------------------------------------------------
264 protected override bool GetFilesToProcess(notnull out array<string> absoluteFilePaths, notnull out array<int> lineNumbers)
265 {
266 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
267 if (!resourceManager)
268 return false;
269
270 array<ResourceName> selection = {};
271 resourceManager.GetResourceBrowserSelection(selection.Insert, true);
272
273 if (selection.IsEmpty())
274 {
275 BaseContainer currentContainer = resourceManager.GetContainer(0);
276 if (!currentContainer)
277 return false; // image, script or something
278
279 BaseContainer ancestor = currentContainer.GetAncestor();
280 if (!ancestor)
281 return false;
282
283 selection.Insert(ancestor.GetResourceName());
284 }
285
286 foreach (ResourceName resourceName : selection)
287 {
288 string absoluteFilePath;
289 if (!Workbench.GetAbsolutePath(resourceName.GetPath(), absoluteFilePath))
290 continue;
291
292 absoluteFilePaths.Insert(absoluteFilePath);
293 }
294
295 return true;
296 }
297
298 //------------------------------------------------------------------------------------------------
299 // constructor
300 void SCR_VCSResourceManagerRootPlugin()
301 {
302 m_WorkbenchModuleTypename = ResourceManager;
303 }
304}
305
306[WorkbenchPluginAttribute("VCS Log", "Show current file's changelog", "Alt+Shift+L", "", { "ScriptEditor" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF1DE)]
307class SCR_VCSLogScriptEditorPlugin : SCR_VCSScriptEditorRootPlugin
308{
309 //------------------------------------------------------------------------------------------------
310 protected override string GetCommandLine()
311 {
312 return GetLogCommandLine();
313 }
314}
315
316[WorkbenchPluginAttribute("File(s) VCS Changelog", "Show Resource Browser-selected file(s) changelog or (whenever possible) the currently opened file if no files are selected", "Alt+Shift+L", "", { "ResourceManager" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF1DE)]
317class SCR_VCSLogResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
318{
319 //------------------------------------------------------------------------------------------------
320 protected override string GetCommandLine()
321 {
322 return GetLogCommandLine();
323 }
324}
325
326[WorkbenchPluginAttribute("VCS Diff", "Show current file's local changes", "Alt+Shift+I", "", { "ResourceManager" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF002)]
327class SCR_VCSDiffResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
328{
329 //------------------------------------------------------------------------------------------------
330 protected override string GetCommandLine()
331 {
332 return GetDiffCommandLine();
333 }
334}
335
336[WorkbenchPluginAttribute("VCS Blame", "Show current file's line authors", "Alt+Shift+B", "", { "ResourceManager" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF4FC)]
337class SCR_VCSBlameResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
338{
339 //------------------------------------------------------------------------------------------------
340 protected override string GetCommandLine()
341 {
342 return GetBlameCommandLine();
343 }
344}
345
346[WorkbenchPluginAttribute("VCS Commit", "Commit current file directory's files", "Alt+Shift+C", "", { "ResourceManager" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF4FC)]
347class SCR_VCSCommitResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
348{
349 //------------------------------------------------------------------------------------------------
350 protected override string GetCommandLine()
351 {
352 return GetCommitCommandLine();
353 }
354}
355
356[WorkbenchPluginAttribute("VCS Diff", "Show current file's local changes", "Alt+Shift+I", "", { "ScriptEditor" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF002)]
357class SCR_VCSDiffPlugin : SCR_VCSScriptEditorRootPlugin
358{
359 //------------------------------------------------------------------------------------------------
360 protected override string GetCommandLine()
361 {
362 return GetDiffCommandLine();
363 }
364}
365
366[WorkbenchPluginAttribute("VCS Blame", "Show current file's line authors", "Alt+Shift+B", "", { "ScriptEditor" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF4FC)]
367class SCR_VCSBlamePlugin : SCR_VCSScriptEditorRootPlugin
368{
369 //------------------------------------------------------------------------------------------------
370 protected override string GetCommandLine()
371 {
372 return GetBlameCommandLine();
373 }
374}
375
376[WorkbenchPluginAttribute("VCS Commit", "Commit current file directory's files", "Alt+Shift+C", "", { "ScriptEditor" }, SCR_PluginCategory.SCRIPTEDITOR_VCS, 0xF4FC)]
377class SCR_VCSCommitPlugin : SCR_VCSScriptEditorRootPlugin
378{
379 //------------------------------------------------------------------------------------------------
380 protected override string GetCommandLine()
381 {
382 return GetCommitCommandLine();
383 }
384}
385#endif // WORKBENCH
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
ResourceName resourceName
Definition SCR_AIGroup.c:66
override void Run()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void Configure()
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.