3 name:
"VCS Configuration",
4 description:
"Configure Blame/Diff/Log/Commit commands",
5 wbModules: {
"ResourceManager",
"ScriptEditor" },
7 awesomeFontCode: 0xF1DE)]
8class SCR_VCSSettingsPlugin : WorkbenchPlugin
15 protected string m_sBlameCommandLine;
18 protected string m_sDiffCommandLine;
21 protected string m_sLogCommandLine;
24 protected string m_sCommitCommandLine;
30 [
Attribute(defvalue:
"1",
desc:
"Commit root directory, otherwise only commit the currently-opened file",
category:
"Settings")]
31 protected bool m_bCommitRootDirectory;
38 protected bool m_bPrintCommandOnUse;
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\"";
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\"";
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",
65 protected void ButtonTortoiseSVN()
67 m_sBlameCommandLine = TORTOISESVN_BLAME;
68 m_sDiffCommandLine = TORTOISESVN_DIFF;
69 m_sLogCommandLine = TORTOISESVN_LOG;
70 m_sCommitCommandLine = TORTOISESVN_COMMIT;
75 protected void ButtonGitExtensions()
77 m_sBlameCommandLine = GITEXT_BLAME;
78 m_sDiffCommandLine = GITEXT_DIFF;
79 m_sLogCommandLine = GITEXT_LOG;
80 m_sCommitCommandLine = GITEXT_COMMIT;
85 protected void ButtonClose();
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; }
96class SCR_VCSRootPlugin : WorkbenchPlugin
98 protected typename m_WorkbenchModuleTypename;
101 protected override void Run()
103 array<string> absoluteFilePaths = {};
104 array<int> lineNumbers = {};
106 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
107 if (!vcsSettingsPlugin)
110 bool commitRootDirectory = vcsSettingsPlugin.GetCommitRootDirectory();
111 bool printCommand = vcsSettingsPlugin.GetPrintCommandOnUse();
113 if (!GetFilesToProcess(absoluteFilePaths, lineNumbers))
117 if (commitRootDirectory && thisStr.StartsWith(
"" + SCR_VCSCommitPlugin))
119 string command = GetCommandLine();
121 if (!Workbench.GetAbsolutePath(
"", directory,
true))
124 command.Replace(
"$dir", directory);
128 Workbench.RunCmd(command);
132 Print(
"Cannot obtain current file(s) - " + thisStr,
LogLevel.WARNING);
138 int absoluteFilePathsCount = absoluteFilePaths.Count();
139 if (absoluteFilePathsCount < 1)
142 if (lineNumbers.Count() < absoluteFilePathsCount)
143 lineNumbers.Resize(absoluteFilePathsCount);
145 string originalCommand = GetCommandLine();
150 if (commitRootDirectory)
151 commitRootDirectory = Workbench.GetAbsolutePath(
"", directory,
true);
153 foreach (
int i,
string absoluteFilePath : absoluteFilePaths)
155 string command = originalCommand;
157 if (!commitRootDirectory)
158 directory = FilePath.StripFileName(absoluteFilePath);
160 command.Replace(
"$path", absoluteFilePath);
161 command.Replace(
"$dir", directory);
162 command.Replace(
"$line", lineNumbers[i].
ToString());
167 Workbench.RunCmd(command);
172 protected SCR_VCSSettingsPlugin GetVCSSettings(
typename workbenchModuleTypename)
174 WBModuleDef workbenchModule = Workbench.GetModule(workbenchModuleTypename);
175 if (!workbenchModule)
178 return SCR_VCSSettingsPlugin.Cast(workbenchModule.GetPlugin(SCR_VCSSettingsPlugin));
182 protected string GetBlameCommandLine()
184 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
185 if (!vcsSettingsPlugin)
188 return vcsSettingsPlugin.GetBlameCommandLine();
192 protected string GetDiffCommandLine()
194 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
195 if (!vcsSettingsPlugin)
198 return vcsSettingsPlugin.GetDiffCommandLine();
202 protected string GetLogCommandLine()
204 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
205 if (!vcsSettingsPlugin)
208 return vcsSettingsPlugin.GetLogCommandLine();
212 protected string GetCommitCommandLine()
214 SCR_VCSSettingsPlugin vcsSettingsPlugin = GetVCSSettings(m_WorkbenchModuleTypename);
215 if (!vcsSettingsPlugin)
218 return vcsSettingsPlugin.GetCommitCommandLine();
223 protected bool GetFilesToProcess(notnull out array<string> absoluteFilePaths, notnull out array<int> lineNumbers);
227 protected string GetCommandLine();
230class SCR_VCSScriptEditorRootPlugin : SCR_VCSRootPlugin
233 protected override bool GetFilesToProcess(notnull out array<string> absoluteFilePaths, notnull out array<int> lineNumbers)
235 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
240 string absoluteFilePath;
241 if (!scriptEditor.GetCurrentFile(file) || !Workbench.GetAbsolutePath(file, absoluteFilePath))
247 absoluteFilePaths.Insert(absoluteFilePath);
248 lineNumbers.Insert(scriptEditor.GetCurrentLine() + 1);
255 void SCR_VCSScriptEditorRootPlugin()
257 m_WorkbenchModuleTypename = ScriptEditor;
261class SCR_VCSResourceManagerRootPlugin : SCR_VCSRootPlugin
264 protected override bool GetFilesToProcess(notnull out array<string> absoluteFilePaths, notnull out array<int> lineNumbers)
266 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
267 if (!resourceManager)
270 array<ResourceName> selection = {};
271 resourceManager.GetResourceBrowserSelection(selection.Insert,
true);
273 if (selection.IsEmpty())
275 BaseContainer currentContainer = resourceManager.GetContainer(0);
276 if (!currentContainer)
279 BaseContainer ancestor = currentContainer.GetAncestor();
283 selection.Insert(ancestor.GetResourceName());
288 string absoluteFilePath;
289 if (!Workbench.GetAbsolutePath(
resourceName.GetPath(), absoluteFilePath))
292 absoluteFilePaths.Insert(absoluteFilePath);
300 void SCR_VCSResourceManagerRootPlugin()
302 m_WorkbenchModuleTypename = ResourceManager;
307class SCR_VCSLogScriptEditorPlugin : SCR_VCSScriptEditorRootPlugin
310 protected override string GetCommandLine()
312 return GetLogCommandLine();
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
320 protected override string GetCommandLine()
322 return GetLogCommandLine();
327class SCR_VCSDiffResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
330 protected override string GetCommandLine()
332 return GetDiffCommandLine();
337class SCR_VCSBlameResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
340 protected override string GetCommandLine()
342 return GetBlameCommandLine();
347class SCR_VCSCommitResourceManagerPlugin : SCR_VCSResourceManagerRootPlugin
350 protected override string GetCommandLine()
352 return GetCommitCommandLine();
357class SCR_VCSDiffPlugin : SCR_VCSScriptEditorRootPlugin
360 protected override string GetCommandLine()
362 return GetDiffCommandLine();
367class SCR_VCSBlamePlugin : SCR_VCSScriptEditorRootPlugin
370 protected override string GetCommandLine()
372 return GetBlameCommandLine();
377class SCR_VCSCommitPlugin : SCR_VCSScriptEditorRootPlugin
380 protected override string GetCommandLine()
382 return GetCommitCommandLine();
ResourceName resourceName
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
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.
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.