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

Commit eae3804

Browse files
committed
added npp generator and generated code
1 parent f227105 commit eae3804

File tree

9 files changed

+896
-0
lines changed

9 files changed

+896
-0
lines changed

Demo Plugin/NppManagedPluginDemo/NppManagedPluginDemo.VS2015.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
<Compile Include="..\..\Visual Studio Project Template C#\PluginInfrastructure\ClikeStringArray.cs">
5353
<Link>PluginInfrastructure\ClikeStringArray.cs</Link>
5454
</Compile>
55+
<Compile Include="..\..\Visual Studio Project Template C#\PluginInfrastructure\Preference_h.cs">
56+
<Link>PluginInfrastructure\Preference_h.cs</Link>
57+
</Compile>
58+
<Compile Include="..\..\Visual Studio Project Template C#\PluginInfrastructure\Resource_h.cs">
59+
<Link>PluginInfrastructure\Resource_h.cs</Link>
60+
</Compile>
5561
<Compile Include="..\..\Visual Studio Project Template C#\PluginInfrastructure\Win32.cs">
5662
<Link>PluginInfrastructure\Win32.cs</Link>
5763
</Compile>

ToolsForMaintainersOfTheProjectTemplate/Scintilla_iface_synchronizer/cs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# requires the notepad++ project is cloned in a folder next to this plugin pack
2+
13
import Face
24
from FileGenerator import Regenerate
35

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env python
2+
# FileGenerator.py - implemented 2013 by Neil Hodgson neilh@scintilla.org
3+
# Released to the public domain.
4+
5+
# Generate or regenerate source files based on comments in those files.
6+
# May be modified in-place or a template may be generated into a complete file.
7+
# Requires Python 2.5 or later
8+
# The files are copied to a string apart from sections between a
9+
# ++Autogenerated comment and a --Autogenerated comment which is
10+
# generated by the CopyWithInsertion function. After the whole string is
11+
# instantiated, it is compared with the target file and if different the file
12+
# is rewritten.
13+
14+
from __future__ import with_statement
15+
16+
import codecs, os, re, string, sys
17+
18+
lineEnd = "\r\n" if sys.platform == "win32" else "\n"
19+
20+
def UpdateFile(filename, updated):
21+
""" If the file contents are different to updated then copy updated into the
22+
file else leave alone so Mercurial and make don't treat it as modified. """
23+
newOrChanged = "Changed"
24+
try:
25+
with codecs.open(filename, "r", "utf-8") as infile:
26+
original = infile.read()
27+
if updated == original:
28+
# Same as before so don't write
29+
return
30+
os.unlink(filename)
31+
except IOError: # File is not there yet
32+
newOrChanged = "New"
33+
with codecs.open(filename, "w", "utf-8") as outfile:
34+
outfile.write(updated)
35+
print("%s %s" % (newOrChanged, filename))
36+
37+
# Automatically generated sections contain start and end comments,
38+
# a definition line and the results.
39+
# The results are replaced by regenerating based on the definition line.
40+
# The definition line is a comment prefix followed by "**".
41+
# If there is a digit after the ** then this indicates which list to use
42+
# and the digit and next character are not part of the definition
43+
# Backslash is used as an escape within the definition line.
44+
# The part between \( and \) is repeated for each item in the list.
45+
# \* is replaced by each list item. \t, and \n are tab and newline.
46+
# If there is no definition line than the first list is copied verbatim.
47+
# If retainDefs then the comments controlling generation are copied.
48+
def CopyWithInsertion(input, commentPrefix, retainDefs, lists):
49+
copying = 1
50+
generated = False
51+
listid = 0
52+
output = []
53+
for line in input.splitlines(0):
54+
isStartGenerated = line.lstrip().startswith(commentPrefix + "++Autogenerated")
55+
if copying and not isStartGenerated:
56+
output.append(line)
57+
if isStartGenerated:
58+
if retainDefs:
59+
output.append(line)
60+
copying = 0
61+
generated = False
62+
elif not copying and not generated:
63+
# Generating
64+
if line.startswith(commentPrefix + "**"):
65+
# Pattern to transform input data
66+
if retainDefs:
67+
output.append(line)
68+
definition = line[len(commentPrefix + "**"):]
69+
if (commentPrefix == "<!--") and (" -->" in definition):
70+
definition = definition.replace(" -->", "")
71+
listid = 0
72+
if definition[0] in string.digits:
73+
listid = int(definition[:1])
74+
definition = definition[2:]
75+
# Hide double slashes as a control character
76+
definition = definition.replace("\\\\", "\001")
77+
# Do some normal C style transforms
78+
definition = definition.replace("\\n", "\n")
79+
definition = definition.replace("\\t", "\t")
80+
# Get the doubled backslashes back as single backslashes
81+
definition = definition.replace("\001", "\\")
82+
startRepeat = definition.find("\\(")
83+
endRepeat = definition.find("\\)")
84+
intro = definition[:startRepeat]
85+
out = ""
86+
if intro.endswith("\n"):
87+
pos = 0
88+
else:
89+
pos = len(intro)
90+
out += intro
91+
middle = definition[startRepeat+2:endRepeat]
92+
for i in lists[listid]:
93+
item = middle.replace("\\*", i)
94+
if pos and (pos + len(item) >= 80):
95+
out += "\\\n"
96+
pos = 0
97+
out += item
98+
pos += len(item)
99+
if item.endswith("\n"):
100+
pos = 0
101+
outro = definition[endRepeat+2:]
102+
out += outro
103+
out = out.replace("\n", lineEnd) # correct EOLs in generated content
104+
output.append(out)
105+
else:
106+
# Simple form with no rule to transform input
107+
output.extend(lists[0])
108+
generated = True
109+
if line.lstrip().startswith(commentPrefix + "--Autogenerated") or \
110+
line.lstrip().startswith(commentPrefix + "~~Autogenerated"):
111+
copying = 1
112+
if retainDefs:
113+
output.append(line)
114+
output = [line.rstrip(" \t") for line in output] # trim trailing whitespace
115+
return lineEnd.join(output) + lineEnd
116+
117+
def GenerateFile(inpath, outpath, commentPrefix, retainDefs, *lists):
118+
"""Generate 'outpath' from 'inpath'.
119+
"""
120+
121+
try:
122+
with codecs.open(inpath, "r", "UTF-8") as infile:
123+
original = infile.read()
124+
updated = CopyWithInsertion(original, commentPrefix,
125+
retainDefs, lists)
126+
UpdateFile(outpath, updated)
127+
except IOError:
128+
print("Can not open %s" % inpath)
129+
130+
def Generate(inpath, outpath, commentPrefix, *lists):
131+
"""Generate 'outpath' from 'inpath'.
132+
"""
133+
GenerateFile(inpath, outpath, commentPrefix, inpath == outpath, *lists)
134+
135+
def Regenerate(filename, commentPrefix, *lists):
136+
"""Regenerate the given file.
137+
"""
138+
Generate(filename, filename, commentPrefix, *lists)
139+
140+
def UpdateLineInFile(path, linePrefix, lineReplace):
141+
lines = []
142+
updated = False
143+
with codecs.open(path, "r", "utf-8") as f:
144+
for l in f.readlines():
145+
l = l.rstrip()
146+
if not updated and l.startswith(linePrefix):
147+
lines.append(lineReplace)
148+
updated = True
149+
else:
150+
lines.append(l)
151+
contents = lineEnd.join(lines) + lineEnd
152+
UpdateFile(path, contents)
153+
154+
def ReplaceREInFile(path, match, replace):
155+
with codecs.open(path, "r", "utf-8") as f:
156+
contents = f.read()
157+
contents = re.sub(match, replace, contents)
158+
UpdateFile(path, contents)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# requires the notepad++ project is cloned in a folder next to this plugin pack
2+
3+
import re
4+
from FileGenerator import Regenerate
5+
6+
class Line:
7+
def __init__(self, content, comment):
8+
self.content = content
9+
self.comment = comment
10+
self.parsedContent = None
11+
12+
def isEmptyLine(self):
13+
return self.parsedContent == None and self.comment == ""
14+
15+
def isComment(self):
16+
return self.content == "" and self.comment != ""
17+
18+
def isDefinition(self):
19+
return self.parsedContent != None
20+
21+
def splitAndStripLine(line):
22+
if line[-1:] == '\n': line = line[:-1]
23+
pos = line.find("//")
24+
if pos == -1:
25+
return Line(line.strip(), "")
26+
else:
27+
return Line((line[:pos]).strip(), (line[pos:]).strip())
28+
29+
def parseLine(line):
30+
parsed = splitAndStripLine(line)
31+
match = re.match("^#define\\s+(?P<name>\\w+)\\s+\\((?P<value>[^,\")]+)\\)$", parsed.content)
32+
if match == None:
33+
match = re.match("^#define\\s+(?P<name>\\w+)\\s+(?P<value>[^,\"]+)$", parsed.content)
34+
parsed.parsedContent = match
35+
return parsed
36+
37+
def parseFile(name):
38+
file = open(name)
39+
allLines = []
40+
for line in file.readlines():
41+
allLines.append(parseLine(line))
42+
return allLines
43+
44+
def printFile(name):
45+
out = []
46+
lines = parseFile(name)
47+
48+
for i in range(0, len(lines)):
49+
if not lines[i].isDefinition():
50+
if i+1 >= len(lines) or lines[i+1].isDefinition():
51+
out.append("")
52+
elif lines[i].isDefinition():
53+
value = lines[i].parsedContent.group("value")
54+
value = value.replace("WM_USER","Constants.WM_USER")
55+
value = value.replace("NPPMSG","Constants.NPPMSG")
56+
out.append (" %s = %s," %(lines[i].parsedContent.group("name"), value))
57+
return out
58+
59+
if __name__ == "__main__":
60+
preffile = printFile("../../../notepad-plus-plus/PowerEditor/src/WinControls/Preference/preference_rc.h")
61+
Regenerate("../../Visual Studio Project Template C#/PluginInfrastructure/Preference_h.cs", "/* ", preffile)
62+
63+
resourcefile = printFile("../../../notepad-plus-plus/PowerEditor/src/resource.h")
64+
Regenerate("../../Visual Studio Project Template C#/PluginInfrastructure/resource_h.cs", "/* ", resourcefile)

Visual Studio Project Template C#/$projectname$.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<Compile Include="PluginInfrastructure\MenuCmdID_h.cs" />
6262
<Compile Include="PluginInfrastructure\Scintilla_iface.cs" />
6363
<Compile Include="PluginInfrastructure\Msgs_h.cs" />
64+
<Compile Include="PluginInfrastructure\Preference_h.cs" />
65+
<Compile Include="PluginInfrastructure\Resource_h.cs" />
6466
<Compile Include="Properties\AssemblyInfo.cs" />
6567
<Compile Include="Properties\Resources.Designer.cs">
6668
<AutoGen>True</AutoGen>

Visual Studio Project Template C#/NppPlugin.vstemplate

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<ProjectItem ReplaceParameters="false" TargetFileName="Win32.cs">Win32.cs</ProjectItem>
4747
<ProjectItem ReplaceParameters="false" TargetFileName="NppPluginNETBase.cs">NppPluginNETBase.cs</ProjectItem>
4848
<ProjectItem ReplaceParameters="false" TargetFileName="NppPluginNETHelper.cs">NppPluginNETHelper.cs</ProjectItem>
49+
<ProjectItem ReplaceParameters="false" TargetFileName="Preference_h.cs">Preference_h.cs</ProjectItem>
50+
<ProjectItem ReplaceParameters="false" TargetFileName="Resource_h.cs">Resource_h.cs</ProjectItem>
51+
<ProjectItem ReplaceParameters="false" TargetFileName="NotepadPPGateway.cs">NotepadPPGateway.cs</ProjectItem>
4952
<ProjectItem ReplaceParameters="false" TargetFileName="ScintillaGateway.cs">ScintillaGateway.cs</ProjectItem>
5053
<ProjectItem ReplaceParameters="false" TargetFileName="IScintillaGateway.cs">IScintillaGateway.cs</ProjectItem>
5154
<ProjectItem ReplaceParameters="false" TargetFileName="GatewayDomain.cs">GatewayDomain.cs</ProjectItem>

Visual Studio Project Template C#/PluginInfrastructure/Msgs_h.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Kbg.NppPluginNET.PluginInfrastructure
1212
class Constants
1313
{
1414
public const int WM_USER = 0x400;
15+
public const int NPPMSG = WM_USER + 1000;
1516
}
1617

1718
public enum LangType

0 commit comments

Comments
 (0)