Skip to content

Commit 5179bbe

Browse files
author
Sébastien Geiser
committed
Merge branch 'dev'
2 parents a4b36e2 + 1632644 commit 5179bbe

File tree

73 files changed

+13192
-2259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+13192
-2259
lines changed

CSharpRegexTools4Npp/BNpp.cs

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
namespace CSharpRegexTools4Npp
66
{
7-
public class BNpp
7+
public static class BNpp
88
{
9-
public static NotepadPPGateway NotepadPP { get; private set; } = new NotepadPPGateway();
9+
public static NotepadPPGateway NotepadPP { get; } = new NotepadPPGateway();
10+
11+
public static ScintillaGateway Scintilla => new ScintillaGateway(PluginBase.GetCurrentScintilla());
1012

1113
/// <summary>
1214
/// Récupère les caractères de fin de lignes courant
@@ -17,18 +19,16 @@ public static string CurrentEOL
1719
get
1820
{
1921
string eol = "\n";
20-
int value = Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETEOLMODE, 0, 0).ToInt32();
22+
int value = Scintilla.GetEOLMode();
2123

22-
switch (value)
24+
switch ((SciMsg)value)
2325
{
24-
case 0:
26+
case SciMsg.SC_EOL_CRLF:
2527
eol = "\r\n";
2628
break;
27-
case 1:
29+
case SciMsg.SC_EOL_CR:
2830
eol = "\r";
2931
break;
30-
default:
31-
break;
3232
}
3333

3434
return eol;
@@ -51,7 +51,7 @@ public static string Text
5151
set
5252
{
5353
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
54-
string text = BEncoding.GetScintillaTextFromUtf8Text(value, out int length);
54+
string text = BEncoding.GetScintillaTextFromUtf8Text(value, out _);
5555
scintilla.SetText(text);
5656
}
5757
}
@@ -85,7 +85,7 @@ public static int SelectionEnd
8585
int curPos = (int)Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GETSELECTIONEND, 0, 0);
8686
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
8787
string beginingText = scintilla.GetText(curPos);
88-
string text = BEncoding.GetScintillaTextFromUtf8Text(beginingText, out int length);
88+
BEncoding.GetScintillaTextFromUtf8Text(beginingText, out int length);
8989
return length;
9090
}
9191

@@ -104,7 +104,7 @@ public static int SelectionEnd
104104
}
105105

106106
string afterText = allText.Substring(0, endToUse);
107-
string afterTextInDefaultEncoding = BEncoding.GetScintillaTextFromUtf8Text(afterText, out int defaultEnd);
107+
BEncoding.GetScintillaTextFromUtf8Text(afterText, out int defaultEnd);
108108

109109
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETSELECTIONEND, defaultEnd, 0);
110110
}
@@ -136,17 +136,15 @@ public static string SelectedText
136136
{
137137
get
138138
{
139-
IScintillaGateway scintillaGateway = new ScintillaGateway(PluginBase.GetCurrentScintilla());
140-
int start = scintillaGateway.GetSelectionStart().Value;
141-
int end = scintillaGateway.GetSelectionEnd().Value;
142-
143-
return end - start == 0 ? "" : Text.Substring(start, end - start);
139+
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
140+
return BEncoding.GetUtf8TextFromScintillaText(scintilla.GetSelText());
144141
}
145142

146143
set
147144
{
145+
IScintillaGateway scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
148146
string defaultNewText = BEncoding.GetScintillaTextFromUtf8Text(value);
149-
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_REPLACESEL, 0, defaultNewText);
147+
scintilla.ReplaceSel(defaultNewText);
150148
}
151149
}
152150

@@ -186,9 +184,9 @@ public static void SelectTextAndShow(int start, int end)
186184
}
187185

188186
string beforeText = allText.Substring(0, startToUse);
189-
string beforeTextInDefaultEncoding = BEncoding.GetScintillaTextFromUtf8Text(beforeText, out int defaultStart);
187+
BEncoding.GetScintillaTextFromUtf8Text(beforeText, out int defaultStart);
190188
string endText = allText.Substring(0, endToUse);
191-
string endTextInDefaultEncoding = BEncoding.GetScintillaTextFromUtf8Text(endText, out int defaultEnd);
189+
BEncoding.GetScintillaTextFromUtf8Text(endText, out int defaultEnd);
192190

193191
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GOTOPOS, defaultStart, 0);
194192
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETSELECTIONEND, defaultEnd, 0);
@@ -230,14 +228,13 @@ public static void AddSelection(int start, int end)
230228
}
231229

232230
string beforeText = allText.Substring(0, startToUse);
233-
string beforeTextInDefaultEncoding = BEncoding.GetScintillaTextFromUtf8Text(beforeText, out int defaultStart);
231+
BEncoding.GetScintillaTextFromUtf8Text(beforeText, out int defaultStart);
234232
string endText = allText.Substring(0, endToUse);
235-
string endTextInDefaultEncoding = BEncoding.GetScintillaTextFromUtf8Text(endText, out int defaultEnd);
233+
BEncoding.GetScintillaTextFromUtf8Text(endText, out int defaultEnd);
236234

237235
Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_ADDSELECTION, defaultStart, defaultEnd);
238236
}
239237

240-
241238
/// <summary>
242239
/// Récupère le texte de la ligne spécifiée
243240
/// </summary>
@@ -263,84 +260,63 @@ public static string GetLineText(int lineNb)
263260
/// </summary>
264261
internal static class BEncoding
265262
{
266-
private static Encoding utf8 = Encoding.UTF8;
263+
private static readonly Encoding utf8 = Encoding.UTF8;
267264

268265
/// <summary>
269266
/// Convertit le texte spécifier de l'encodage du document Notepad++ courant à l'encodage C# (UTF8)
270267
/// </summary>
271268
public static string GetUtf8TextFromScintillaText(string scText)
272269
{
273-
string result = "";
274-
int iEncoding = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETCODEPAGE, 0, 0);
275-
276-
switch (iEncoding)
270+
switch ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETCODEPAGE, 0, 0))
277271
{
278272
case 65001: // UTF8
279-
result = utf8.GetString(Encoding.Default.GetBytes(scText));
280-
break;
273+
return utf8.GetString(Encoding.Default.GetBytes(scText));
281274
default:
282275
Encoding ANSI = Encoding.GetEncoding(1252);
283276

284277
byte[] ansiBytes = ANSI.GetBytes(scText);
285278
byte[] utf8Bytes = Encoding.Convert(ANSI, Encoding.UTF8, ansiBytes);
286279

287-
result = Encoding.UTF8.GetString(utf8Bytes);
288-
break;
280+
return Encoding.UTF8.GetString(utf8Bytes);
289281
}
290-
291-
return result;
292282
}
293283

294284
/// <summary>
295285
/// Convertit le texte spécifier de l'encodage C# (UTF8) à l'encodage document Notepad++ courant
296286
/// </summary>
297287
public static string GetScintillaTextFromUtf8Text(string utf8Text)
298288
{
299-
string result = "";
300-
int iEncoding = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETCODEPAGE, 0, 0);
301-
302-
switch (iEncoding)
289+
switch ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETCODEPAGE, 0, 0))
303290
{
304291
case 65001: // UTF8
305-
result = Encoding.Default.GetString(utf8.GetBytes(utf8Text));
306-
break;
292+
return Encoding.Default.GetString(utf8.GetBytes(utf8Text));
307293
default:
308294
Encoding ANSI = Encoding.GetEncoding(1252);
309295

310296
byte[] utf8Bytes = utf8.GetBytes(utf8Text);
311297
byte[] ansiBytes = Encoding.Convert(Encoding.UTF8, ANSI, utf8Bytes);
312298

313-
result = ANSI.GetString(ansiBytes);
314-
break;
299+
return ANSI.GetString(ansiBytes);
315300
}
316-
317-
return result;
318301
}
319302

320303
/// <summary>
321304
/// Convertit le texte spécifier de l'encodage C# (UTF8) à l'encodage document Notepad++ courant
322305
/// </summary>
323306
public static string GetScintillaTextFromUtf8Text(string utf8Text, out int length)
324307
{
325-
string result = "";
326-
int iEncoding = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETCODEPAGE, 0, 0);
327-
328308
byte[] utf8Bytes = utf8.GetBytes(utf8Text);
329309
length = utf8Bytes.Length;
330310

331-
switch (iEncoding)
311+
switch ((int)Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_GETCODEPAGE, 0, 0))
332312
{
333313
case 65001: // UTF8
334-
result = Encoding.Default.GetString(utf8.GetBytes(utf8Text));
335-
break;
314+
return Encoding.Default.GetString(utf8.GetBytes(utf8Text));
336315
default:
337316
Encoding ANSI = Encoding.GetEncoding(1252);
338317
byte[] ansiBytes = Encoding.Convert(Encoding.UTF8, ANSI, utf8Bytes);
339-
result = ANSI.GetString(ansiBytes);
340-
break;
318+
return ANSI.GetString(ansiBytes);
341319
}
342-
343-
return result;
344320
}
345321
}
346322
}

CSharpRegexTools4Npp/CSharpRegexTools4Npp.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props')" />
3+
<Import Project="..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
@@ -65,8 +65,8 @@
6565
<StartProgram Condition="'$(Platform)'=='x86'">$(MSBuildProgramFiles32)\Notepad++\notepad++.exe</StartProgram>
6666
</PropertyGroup>
6767
<ItemGroup>
68-
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
69-
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
68+
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
69+
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
7070
</Reference>
7171
<Reference Include="Microsoft.CSharp" />
7272
<Reference Include="PresentationCore" />
@@ -145,10 +145,10 @@
145145
<PropertyGroup>
146146
<ErrorText>Ce projet fait référence à des packages NuGet qui sont manquants sur cet ordinateur. Utilisez l'option de restauration des packages NuGet pour les télécharger. Pour plus d'informations, consultez http://go.microsoft.com/fwlink/?LinkID=322105. Le fichier manquant est : {0}.</ErrorText>
147147
</PropertyGroup>
148-
<Error Condition="!Exists('..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.3.3\build\Costura.Fody.props'))" />
149-
<Error Condition="!Exists('..\packages\Fody.4.2.1\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.4.2.1\build\Fody.targets'))" />
148+
<Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
149+
<Error Condition="!Exists('..\packages\Fody.6.1.1\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.1.1\build\Fody.targets'))" />
150150
</Target>
151-
<Import Project="..\packages\Fody.4.2.1\build\Fody.targets" Condition="Exists('..\packages\Fody.4.2.1\build\Fody.targets')" />
151+
<Import Project="..\packages\Fody.6.1.1\build\Fody.targets" Condition="Exists('..\packages\Fody.6.1.1\build\Fody.targets')" />
152152
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
153153
Other similar extension points exist, see Microsoft.Common.targets.
154154
<Target Name="BeforeBuild">

CSharpRegexTools4Npp/Main.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
namespace CSharpRegexTools4Npp
1212
{
13-
1413
public class Main
1514
{
1615
internal const string PluginName = "C# Regex Tools 4 Npp";
17-
static int idMyDlg = 0;
18-
static Bitmap tbBmp = Resources.icon;
16+
private static int idMyDlg = 0;
17+
private static readonly Bitmap tbBmp = Resources.icon;
1918
//static RegExToolDialog dialog = null;
2019

2120
//Import the FindWindow API to find our window
@@ -30,10 +29,10 @@ public class Main
3029
private static extern IntPtr SetWindowLong(IntPtr hWnd, int windowLongFlags, IntPtr dwNewLong);
3130

3231
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
33-
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
32+
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
3433

3534
[DllImport("user32.dll", CharSet = CharSet.Auto)]
36-
static extern long SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
35+
private static extern long SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
3736

3837
public const int GWL_EXSTYLE = -20;
3938
public const int WS_EX_LAYERED = 0x80000;
@@ -103,7 +102,7 @@ public static void ShowTheDialog()
103102
{
104103
GetText = () => BNpp.Text,
105104

106-
SetText = (string text) =>
105+
SetText = text =>
107106
{
108107
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
109108
{
@@ -113,7 +112,7 @@ public static void ShowTheDialog()
113112
BNpp.Text = text;
114113
},
115114

116-
SetTextInNew = (string text) =>
115+
SetTextInNew = text =>
117116
{
118117
BNpp.NotepadPP.FileNew();
119118

@@ -122,27 +121,29 @@ public static void ShowTheDialog()
122121

123122
GetSelectedText = () => BNpp.SelectedText,
124123

125-
SetPosition = (int index, int length) => BNpp.SelectTextAndShow(index, index + length),
124+
SetPosition = (index, length) => BNpp.SelectTextAndShow(index, index + length),
126125

127-
SetSelection = (int index, int length) => BNpp.AddSelection(index, index + length),
126+
SetSelection = (index, length) => BNpp.AddSelection(index, index + length),
128127

129128
GetSelectionStartIndex = () => BNpp.SelectionStart,
130129

131130
GetSelectionLength = () => BNpp.SelectionLength,
132131

133132
SaveCurrentDocument = () => BNpp.NotepadPP.SaveCurrentFile(),
134133

135-
TryOpen = (string fileName, bool onlyIfAlreadyOpen) =>
134+
TryOpen = (fileName, onlyIfAlreadyOpen) =>
136135
{
137136
try
138137
{
139138
bool result = false;
140139

141-
if (BNpp.NotepadPP.CurrentFileName.ToLower().Equals(fileName.ToLower()))
140+
if (BNpp.NotepadPP.CurrentFileName.Equals(fileName, StringComparison.OrdinalIgnoreCase))
141+
{
142142
result = true;
143-
else if (BNpp.NotepadPP.GetAllOpenedDocuments.Any((string s) => s.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
143+
}
144+
else if (BNpp.NotepadPP.GetAllOpenedDocuments.Any(s => s.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
144145
{
145-
BNpp.NotepadPP.ShowOpenedDocument(fileName);
146+
BNpp.NotepadPP.ShowTab(fileName);
146147
result = true;
147148
}
148149
else if (!onlyIfAlreadyOpen)

CSharpRegexTools4Npp/PluginInfrastructure/GatewayDomain.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public Colour(int rgb)
3030
/// <param name="blue">a number 0-255</param>
3131
public Colour(int red, int green, int blue)
3232
{
33-
if(red > 255 || red < 0)
33+
if (red > 255 || red < 0)
3434
throw new ArgumentOutOfRangeException("red", "must be 0-255");
35-
if(green > 255 || green < 0)
35+
if (green > 255 || green < 0)
3636
throw new ArgumentOutOfRangeException("green", "must be 0-255");
37-
if(blue > 255 || blue < 0)
37+
if (blue > 255 || blue < 0)
3838
throw new ArgumentOutOfRangeException("blue", "must be 0-255");
3939
Red = red;
4040
Green = green;
@@ -150,7 +150,7 @@ public static Position Max(Position a, Position b)
150150
return b;
151151
}
152152

153-
public override string ToString()
153+
public override string ToString()
154154
{
155155
return "Position: " + pos;
156156
}
@@ -202,7 +202,7 @@ public class KeyModifier
202202
/// </summary>
203203
public KeyModifier(SciMsg SCK_KeyCode, SciMsg SCMOD_modifier)
204204
{
205-
value = (int) SCK_KeyCode | ((int) SCMOD_modifier << 16);
205+
value = (int)SCK_KeyCode | ((int)SCMOD_modifier << 16);
206206
}
207207

208208
public int Value
@@ -218,7 +218,6 @@ public CharacterRange(int cpmin, int cpmax)
218218
{
219219
cpMin = cpmin; cpMax = cpmax;
220220
}
221-
222221
public int cpMin;
223222
public int cpMax;
224223
}
@@ -246,7 +245,6 @@ public TextRange(CharacterRange chrRange, int stringCapacity)
246245
_sciTextRange.chrg = chrRange;
247246
_sciTextRange.lpstrText = Marshal.AllocHGlobal(stringCapacity);
248247
}
249-
250248
public TextRange(int cpmin, int cpmax, int stringCapacity)
251249
{
252250
_sciTextRange.chrg.cpMin = cpmin;

0 commit comments

Comments
 (0)