2[
WorkbenchPluginAttribute(name:
"Debug Line Shortcut", description:
"Insert a debug line, as formatted in its options", shortcut:
"Ctrl+Shift+D", wbModules: {
"ScriptEditor" }, awesomeFontCode: 0xF1CD)]
3class SCR_DebugLinePlugin : WorkbenchPlugin
5 [
Attribute(defvalue:
"[%1.%2] debug line (%4 L%5)",
desc:
"Text to be printed in the debug line"
6 +
"\n- %1 = class name (as string, hardcoded)"
7 +
"\n- %2 = method name (as string, hardcoded)"
8 +
"\n- %3 = file name (as preprocess command)"
9 +
"\n- %4 = file's full path (as preprocessor command)"
10 +
"\n- %5 = debug line number (as preprocessor command)", uiwidget:
UIWidgets.EditBoxMultiline,
category:
"Format")]
14 enums: GetLogLevelEnumOptions(),
19 [
Attribute(defvalue:
"0",
desc:
"Make debug line use PrintFormat to output custom variables",
category:
"Format")]
20 protected bool m_bIncludeParams;
25 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
28 if (!scriptEditor.GetCurrentFile(fileFormat))
30 Print(
"Cannot insert debug line, no file is opened!",
LogLevel.WARNING);
35 scriptEditor.GetLineText(lineText);
38 if (lineText.EndsWith(
"{"))
42 for (
int i; i <= tabIndex; ++i)
47 int nextLine = scriptEditor.GetCurrentLine() + 1;
48 string debugLine = tabPrefix + GetDebugLine(scriptEditor);
49 scriptEditor.InsertLine(debugLine, nextLine);
56 protected string GetDebugLine(notnull ScriptEditor scriptEditor)
59 debugLine.TrimInPlace();
63 return "PrintFormat(\"%1\", this);";
65 return "Print(\"test\");";
68 string className, methodName;
70 if (debugLine.Contains(
"%1"))
73 SCR_CopyClassAndMethodPlugin.GetCursorClassAndMethodNames(scriptEditor, className, methodName);
75 debugLine.Replace(
"%1", className);
78 if (debugLine.Contains(
"%2"))
81 SCR_CopyClassAndMethodPlugin.GetCursorClassAndMethodNames(scriptEditor, className, methodName);
83 debugLine.Replace(
"%2", methodName);
86 if (debugLine.Contains(
"%3"))
87 debugLine.Replace(
"%3",
"\" + FilePath.StripPath(__FILE__) + \"");
89 if (debugLine.Contains(
"%4"))
90 debugLine.Replace(
"%4",
"\" + __FILE__ + \"");
92 if (debugLine.Contains(
"%5"))
93 debugLine.Replace(
"%5",
"\" + __LINE__ + \"");
97 debugLine =
"PrintFormat(\"" + debugLine +
"\", this";
98 if (m_eLogLevel > -1 && m_eLogLevel !=
int.
MAX)
99 debugLine +=
", level: LogLevel." +
typename.EnumToString(
LogLevel, m_eLogLevel);
103 debugLine =
"Print(\"" + debugLine +
"\"";
104 if (m_eLogLevel > -1 && m_eLogLevel !=
int.
MAX)
105 debugLine +=
", LogLevel." +
typename.EnumToString(
LogLevel, m_eLogLevel);
115 protected static ParamEnumArray GetLogLevelEnumOptions()
118 ParamEnumArray result = {
new ParamEnum(
"No LogLevel (temporary Print)",
"-1") };
124 for (
int i, count = e.GetVariableCount(); i < count; ++i)
126 if (e.GetVariableType(i) ==
int && e.GetVariableValue(null, i, val))
128 displayName = e.GetVariableName(i);
129 firstLetter = displayName[0];
130 firstLetter.ToUpper();
131 displayName.ToLower();
132 displayName = firstLetter + displayName.Substring(1, displayName.Length() - 1);
133 result.Insert(
new ParamEnum(displayName, val.ToString()));
143 Workbench.ScriptDialog(
"Configure the 'Insert Debug Line' plugin",
"",
this);
148 protected bool ButtonClose()
void ParamEnum(string key, string value, string desc="")
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