Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 23ec20f

Browse files
committed
Updated ScintillaSynchronizer script
1 parent 5b65db4 commit 23ec20f

File tree

2 files changed

+71
-51
lines changed

2 files changed

+71
-51
lines changed

ToolsForMaintainersOfTheProjectTemplate/Scintilla_iface_synchronizer/cs.py

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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
22

33
import Face
44
from FileGenerator import Regenerate
5+
import os
56

67
indent = " "
8+
scintillaIfacePath = os.path.join("..","..","..","notepad-plus-plus","scintilla","include")
9+
templatePath = os.path.join("..","..","Visual Studio Project Template C#","PluginInfrastructure")
710

811
def printLexCSFile(f):
912
out = []
@@ -35,21 +38,23 @@ def isTypeUnsupported(t):
3538
def translateType(t):
3639
if t == "cells": return "Cells"
3740
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"
3944
if t == "textrange": return "TextRange"
4045
if t == "findtext": return "TextToFind"
4146
if t == "keymod": return "KeyModifier"
4247
return t
4348

4449
def translateVariableAccess(name, type):
45-
if type == "bool": return name + " ? 1 : 0"
46-
if type in ["string", "stringresult", "Cells"]: return "(IntPtr) " +name+ "Ptr"
47-
4850
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"]:
5054
res += ".Value"
51-
if type in ["TextRange", "TextToFind"]:
55+
elif type in ["TextRange", "TextToFind"]:
5256
res += ".NativePointer"
57+
else: res = "(IntPtr) " + res
5358
return res
5459

5560
def methodName(name):
@@ -85,26 +90,28 @@ def getParameterList(param1Type, param1Name, param2Type, param2Name):
8590
separator = ", " if first and second else ""
8691
return first + separator + second
8792

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
108115

109116
def printLexGatewayFile(f):
110117
out = []
@@ -172,20 +179,25 @@ def printLexGatewayFile(f):
172179
firstArg = translateVariableAccess(param1Name, param1Type)
173180
seconArg = translateVariableAccess(param2Name, param2Type)
174181

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+ ";")
189201

190202
if param1Type in ["string", "Cells", "stringresult"]:
191203
iindent = iindent[4:]
@@ -226,12 +238,11 @@ def printLexIGatewayFile(f):
226238

227239
def main():
228240
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))
235246

236247
if __name__ == "__main__":
237248
main()

makerelease.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
$version = "0.94.00"
1+
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
22

3+
$version = "0.94.00"
4+
$vsRelease = "2019"
35

46
function replaceVersionInfo($version)
57
{
@@ -28,14 +30,21 @@ $filename = "NppPlugin" + $version + ".zip"
2830
write-host "# zip the projectTemplate '$filename'" -foreground green
2931
& 'C:\Program Files\7-Zip\7z.exe' a -tzip $filename * -xr!bin -xr!obj
3032

33+
$vsTemplatepath = [Environment]::GetFolderPath("MyDocuments") + "\Visual Studio " +
34+
$vsRelease + '\Templates\ProjectTemplates\Visual C#\'
3135

32-
$vsTemplatepath = [Environment]::GetFolderPath("MyDocuments")+'\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\'
3336
write-host "# Copy projectTemplate to VS: '$vsTemplatepath'" -foreground green
34-
del "$($vsTemplatepath)\nppplugin*.zip"
37+
if (Test-Path $vsTemplatepath) {
38+
del "$($vsTemplatepath)\nppplugin*.zip"
39+
} else {
40+
ni -ItemType Directory -Force -Path $vsTemplatepath
41+
}
42+
3543
copy $filename $($vsTemplatepath)
36-
copy $filename c:\temp\
3744

3845
write-host "# remove temp files" -foreground green
3946
rm $filename
4047

4148
cd ..
49+
50+
# Read-Host -Prompt "Press Enter to continue"

0 commit comments

Comments
 (0)