Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CopyClassAndMethodPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Copy Class and Method Name", description: "Copy class and method name based on the current line.\nWhen it is inside of a method, the format is 'MyClass.MyMethod()', otherwise the result is just 'MyClass'", shortcut: "Ctrl+Shift+C", wbModules: { "ScriptEditor" }, awesomeFontCode: 0xF0C5)]
3class SCR_CopyClassAndMethodPlugin : WorkbenchPlugin
4{
5 //------------------------------------------------------------------------------------------------
6 override void Run()
7 {
8 ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
9
10 string className, methodName;
11 if (!GetCursorClassAndMethodNames(scriptEditor, className, methodName))
12 {
13 Print("Nothing copied to clipboard, the current line is not inside of a class.", LogLevel.DEBUG);
14 return;
15 }
16
17 string result;
18 if (methodName) // !IsEmpty
19 result = string.Format("%1.%2()", className, methodName);
20 else
21 result = className;
22
23 System.ExportToClipboard(result);
24 Print(string.Format("Copied to clipboard: \"%1\"", result), LogLevel.DEBUG);
25 }
26
27 //------------------------------------------------------------------------------------------------
33 static bool GetCursorClassAndMethodNames(notnull ScriptEditor scriptEditor, out string className, out string methodName)
34 {
35 string line;
36 array<string> lines = {};
37 for (int lineId, lineCount = scriptEditor.GetCurrentLine() + 1; lineId < lineCount; ++lineId)
38 {
39 scriptEditor.GetLineText(line, lineId);
40 lines.Insert(line);
41 }
42
43 return GetLineClassAndMethodNames(lines, scriptEditor.GetCurrentLine(), className, methodName);
44 }
45
46 //------------------------------------------------------------------------------------------------
53 static bool GetLineClassAndMethodNames(notnull array<string> lines, int cursorLineId, out string className, out string methodName)
54 {
55 const string bracketOpen = "{";
56 const string bracketClose = "}";
57 const string commentOpen = "/" + "*";
58 const string commentClose = "*" + "/";
59
60 //--- Get scope hierarchy
61 array<int> scopes = {};
62 bool isComment;
63 int linesCount = cursorLineId;
64
65 foreach (int lineId, string line : lines)
66 {
67 if (lineId > linesCount)
68 break;
69
70 line.Replace(SCR_StringHelper.SPACE, string.Empty);
71 line.Replace(SCR_StringHelper.TAB, string.Empty);
72
73 if (!isComment)
74 {
75 if (line.StartsWith("["))
76 continue;
77
78 if (line.StartsWith("/" + "/"))
79 continue;
80
81 if (line.StartsWith(bracketOpen))
82 {
83 scopes.Insert(lineId - 1);
84 }
85 else if (line.StartsWith(bracketClose))
86 {
87 if (!scopes.IsEmpty())
88 scopes.Resize(scopes.Count() - 1);
89 }
90 else if (line.StartsWith(commentOpen))
91 {
92 isComment = true;
93 }
94 }
95 else
96 {
97 if (line.Contains(SCR_StringHelper.DOUBLE_SLASH)) // QnD inline comment removal
98 {
99 array<string> tokens = {};
100 line.Split(SCR_StringHelper.DOUBLE_SLASH, tokens, true);
101 line = tokens[0];
102 }
103
104 if (line.StartsWith(commentClose) || line.EndsWith(commentClose))
105 isComment = false;
106 }
107 }
108
109 if (scopes.IsEmpty())
110 scopes.Insert(cursorLineId);
111
112 string line = lines[scopes[0]];
113 if (SCR_StringHelper.StartsWithAny(line, { "[", "#", "/" + "/" }))
114 return false;
115
116 array<string> lineArray = {};
117 line.Split(SCR_StringHelper.SPACE, lineArray, false);
118 lineArray.RemoveItemOrdered("modded");
119 lineArray.RemoveItemOrdered("sealed");
120 if (lineArray.Count() < 2)
121 return false;
122
123 className = lineArray[1];
124 className.Replace(":", string.Empty);
125 className.TrimInPlace();
126
127 if (scopes.Count() == 1)
128 scopes.Insert(cursorLineId);
129
130 if (!lines.IsIndexValid(scopes[1]))
131 {
132 methodName = string.Empty;
133 return true;
134 }
135
136 if (lines[scopes[1]].Trim().StartsWith(bracketOpen))
137 scopes[1] = scopes[1] - 1;
138
139 // methodName = lines[scopes[1]];
140 lines[scopes[1]].Split("(", lineArray, false); // )
141 if (lineArray.Count() >= 2)
142 {
143 methodName = lineArray[0];
144 methodName.Split(SCR_StringHelper.SPACE, lineArray, false);
145 if (lineArray.Count() > 1)
146 methodName = lineArray[lineArray.Count() - 1];
147 else
148 methodName = string.Empty;
149 }
150
151 return true;
152 }
153}
154#endif // WORKBENCH
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
override void Run()
static bool StartsWithAny(string input, notnull array< string > lineStarts)
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