|
1 |
| -# requires the notepad++ project is cloned in a folder next to this plugin pack |
| 1 | +# requires the notepad++ project to be cloned in a folder next to this plugin pack |
2 | 2 |
|
3 | 3 | import Face
|
4 | 4 | from FileGenerator import Regenerate
|
| 5 | +import os |
5 | 6 |
|
6 | 7 | indent = " "
|
| 8 | +scintillaIfacePath = os.path.join("..","..","..","notepad-plus-plus","scintilla","include") |
| 9 | +templatePath = os.path.join("..","..","Visual Studio Project Template C#","PluginInfrastructure") |
7 | 10 |
|
8 | 11 | def printLexCSFile(f):
|
9 | 12 | out = []
|
@@ -35,21 +38,23 @@ def isTypeUnsupported(t):
|
35 | 38 | def translateType(t):
|
36 | 39 | if t == "cells": return "Cells"
|
37 | 40 | if t == "colour": return "Colour"
|
38 |
| - if t == "position": return "Position" |
| 41 | + if t == "line": return "int" |
| 42 | + if t == "pointer": return "IntPtr" |
| 43 | + if t == "position": return "int" |
39 | 44 | if t == "textrange": return "TextRange"
|
40 | 45 | if t == "findtext": return "TextToFind"
|
41 | 46 | if t == "keymod": return "KeyModifier"
|
42 | 47 | return t
|
43 | 48 |
|
44 | 49 | def translateVariableAccess(name, type):
|
45 |
| - if type == "bool": return name + " ? 1 : 0" |
46 |
| - if type in ["string", "stringresult", "Cells"]: return "(IntPtr) " +name+ "Ptr" |
47 |
| - |
48 | 50 | res = name if name else "Unused"
|
49 |
| - if type in ["Colour", "Position", "KeyModifier"]: |
| 51 | + if type == "bool": return "new IntPtr(" +res+ " ? 1 : 0)" |
| 52 | + elif type in ["string", "stringresult", "Cells"]: return "(IntPtr) " +res+ "Ptr" |
| 53 | + elif type in ["Colour", "KeyModifier"]: |
50 | 54 | res += ".Value"
|
51 |
| - if type in ["TextRange", "TextToFind"]: |
| 55 | + elif type in ["TextRange", "TextToFind"]: |
52 | 56 | res += ".NativePointer"
|
| 57 | + else: res = "(IntPtr) " + res |
53 | 58 | return res
|
54 | 59 |
|
55 | 60 | def methodName(name):
|
@@ -85,26 +90,28 @@ def getParameterList(param1Type, param1Name, param2Type, param2Name):
|
85 | 90 | separator = ", " if first and second else ""
|
86 | 91 | return first + separator + second
|
87 | 92 |
|
88 |
| -#def printEnumDefinitions(f): |
89 |
| -# out = [] |
90 |
| -# for name in f.order: |
91 |
| -# v = f.features[name] |
92 |
| -# |
93 |
| -# iindent = indent + " " |
94 |
| -# |
95 |
| -# if v["FeatureType"] in ["enu"]: |
96 |
| -# appendComment(indent, out, v) |
97 |
| -# prefix = v["Value"] |
98 |
| -# out.append(indent + "public enum " + name) |
99 |
| -# out.append(indent + "{") |
100 |
| -# for ename in f.order: |
101 |
| -# ve = f.features[ename] |
102 |
| -# if ve["FeatureType"] in ["val"]: |
103 |
| -# if ename.startswith(prefix): |
104 |
| -# out.append(iindent + ename[len(prefix):] + " = " + ve["Value"] + "," ) |
105 |
| -# |
106 |
| -# out.append(indent + "}") |
107 |
| -# return out |
| 93 | +def printEnumDefinitions(f): |
| 94 | + out = [] |
| 95 | + for name in f.order: |
| 96 | + v = f.features[name] |
| 97 | + |
| 98 | + iindent = indent + " " |
| 99 | + |
| 100 | + if v["FeatureType"] in ["enu"] and name not in ["Keys"]: # for all except excluded enums [conflicting] |
| 101 | + appendComment(indent, out, v) |
| 102 | + prefix = v["Value"] |
| 103 | + out.append(indent + "public enum " + name) |
| 104 | + out.append(indent + "{") |
| 105 | + for ename in f.order: |
| 106 | + ve = f.features[ename] |
| 107 | + if ve["FeatureType"] in ["val"] and ename.startswith(prefix): |
| 108 | + valname = ename[len(prefix):] |
| 109 | + if valname[0].isdigit(): valname = "_" + valname # for enums labels such as char encoding |
| 110 | + if ve["Value"] == "0xFFFFFFFF": ve["Value"] = "-1" # reset back since these are signed enums |
| 111 | + out.append(iindent + valname + " = " + ve["Value"] + "," ) |
| 112 | + out[-1] = out[-1].rstrip(",") |
| 113 | + out.append(indent + "}") |
| 114 | + return out |
108 | 115 |
|
109 | 116 | def printLexGatewayFile(f):
|
110 | 117 | out = []
|
@@ -172,20 +179,25 @@ def printLexGatewayFile(f):
|
172 | 179 | firstArg = translateVariableAccess(param1Name, param1Type)
|
173 | 180 | seconArg = translateVariableAccess(param2Name, param2Type)
|
174 | 181 |
|
175 |
| - out.append(iindent + "IntPtr res = Win32.SendMessage(scintilla, " +featureConstant+ ", " +firstArg+ ", " +seconArg+ ");") |
176 |
| - |
177 |
| - |
178 |
| - if returnType != "void": |
179 |
| - if returnType == "bool": |
180 |
| - out.append(iindent + "return 1 == (int) res;") |
181 |
| - elif returnType == "Colour": |
182 |
| - out.append(iindent + "return new Colour((int) res);") |
183 |
| - elif returnType == "Position": |
184 |
| - out.append(iindent + "return new Position((int) res);") |
185 |
| - elif returnType == "string": |
186 |
| - out.append(iindent + "return Encoding.UTF8.GetString("+bufferVariableName+").TrimEnd('\\0');") |
187 |
| - else: |
188 |
| - out.append(iindent + "return (" +returnType+ ") res;") |
| 182 | + res = "Win32.SendMessage(scintilla, " +featureConstant+ ", " +firstArg+ ", " +seconArg+ ")" |
| 183 | + |
| 184 | + if returnType == "void": |
| 185 | + out.append(iindent + res + ";") |
| 186 | + elif returnType == "IntPtr": |
| 187 | + out.append(iindent + "return "+ res + ";") |
| 188 | + elif returnType == "bool": |
| 189 | + out.append(iindent + "return 1 == (int)" +res+ ";") |
| 190 | + elif returnType == "Colour": |
| 191 | + out.append(iindent + "return new Colour((int) " +res+ ");") |
| 192 | + # elif returnType == "Line": |
| 193 | + # out.append(iindent + "return new Line((int) " +res+ ");") |
| 194 | + # elif returnType == "Position": |
| 195 | + # out.append(iindent + "return new Position((int) " +res+ ");") |
| 196 | + elif returnType == "string": |
| 197 | + out.append(iindent + res + ";") |
| 198 | + out.append(iindent + "return Encoding.UTF8.GetString("+bufferVariableName+").TrimEnd('\\0');") |
| 199 | + else: |
| 200 | + out.append(iindent + "return (" +returnType+ ")" +res+ ";") |
189 | 201 |
|
190 | 202 | if param1Type in ["string", "Cells", "stringresult"]:
|
191 | 203 | iindent = iindent[4:]
|
@@ -226,12 +238,11 @@ def printLexIGatewayFile(f):
|
226 | 238 |
|
227 | 239 | def main():
|
228 | 240 | f = Face.Face()
|
229 |
| - f.ReadFromFile("../../../notepad-plus-plus/scintilla/include/Scintilla.iface") |
230 |
| - Regenerate("../../Visual Studio Project Template C#/PluginInfrastructure/Scintilla_iface.cs", "/* ", printLexCSFile(f)) |
231 |
| - Regenerate("../../Visual Studio Project Template C#/PluginInfrastructure/ScintillaGateWay.cs", "/* ", printLexGatewayFile(f)) |
232 |
| - Regenerate("../../Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateWay.cs", "/* ", printLexIGatewayFile(f)) |
233 |
| -# Regenerate("../../Visual Studio Project Template C#/PluginInfrastructure/gatewaydomain.cs", "/* ", printEnumDefinitions(f)) |
234 |
| - |
| 241 | + f.ReadFromFile(os.path.join(scintillaIfacePath,"Scintilla.iface")) |
| 242 | + Regenerate(os.path.join(templatePath,"Scintilla_iface.cs"), "/* ", printLexCSFile(f)) |
| 243 | + Regenerate(os.path.join(templatePath,"ScintillaGateway.cs"), "/* ", printLexGatewayFile(f)) |
| 244 | + Regenerate(os.path.join(templatePath,"IScintillaGateway.cs"), "/* ", printLexIGatewayFile(f)) |
| 245 | + Regenerate(os.path.join(templatePath,"GatewayDomain.cs"), "/* ", printEnumDefinitions(f)) |
235 | 246 |
|
236 | 247 | if __name__ == "__main__":
|
237 | 248 | main()
|
0 commit comments