Skip to content

Commit d799003

Browse files
author
Sébastien Geiser
committed
Refactoring
1 parent e677ee9 commit d799003

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

CSharpRegexTools4Npp/BNpp.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ public static bool OpenFile(string fileName)
105105

106106
if (File.Exists(fileName))
107107
{
108-
result = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_DOOPEN, 0, fileName).ToInt32() == 1;
108+
#if X64
109+
result = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_DOOPEN, 0, fileName).ToInt64() == 1;
110+
#else
111+
result = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DOOPEN, 0, fileName).ToInt32() == 1;
112+
#endif
109113
}
110114

111115
return result;

CSharpRegexTools4Npp/CSharpRegexTools4Npp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</PropertyGroup>
3939
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
4040
<DebugSymbols>true</DebugSymbols>
41-
<DefineConstants>DEBUG;TRACE</DefineConstants>
41+
<DefineConstants>TRACE;DEBUG;X64</DefineConstants>
4242
<DebugType>full</DebugType>
4343
<ErrorReport>prompt</ErrorReport>
4444
<Optimize>false</Optimize>
@@ -48,7 +48,7 @@
4848
<Prefer32Bit>false</Prefer32Bit>
4949
</PropertyGroup>
5050
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
51-
<DefineConstants>TRACE</DefineConstants>
51+
<DefineConstants>TRACE;X64</DefineConstants>
5252
<Optimize>true</Optimize>
5353
<OutputPath>bin\Release-x64</OutputPath>
5454
<DebugType>pdbonly</DebugType>

CSharpRegexTools4Npp/Main.cs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,9 @@ public static void ShowTheDialog()
9898
{
9999
var dialog = new RegExToolDialog
100100
{
101-
GetText = delegate ()
102-
{
103-
return BNpp.Text;
104-
},
101+
GetText = () => BNpp.Text,
105102

106-
SetText = delegate (string text)
103+
SetText = (string text) =>
107104
{
108105
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
109106
{
@@ -113,44 +110,35 @@ public static void ShowTheDialog()
113110
BNpp.Text = text;
114111
},
115112

116-
SetTextInNew = delegate (string text)
113+
SetTextInNew = (string text) =>
117114
{
118115
BNpp.CreateNewDocument();
119116

120117
BNpp.Text = text;
121118
},
122119

123-
GetSelectedText = delegate ()
124-
{
125-
return BNpp.SelectedText;
126-
},
120+
GetSelectedText = () => BNpp.SelectedText,
127121

128-
SetPosition = delegate (int index, int length)
129-
{
130-
BNpp.SelectTextAndShow(index, index + length);
131-
},
122+
SetPosition = (int index, int length) => BNpp.SelectTextAndShow(index, index + length),
132123

133-
SetSelection = delegate (int index, int length)
134-
{
135-
BNpp.AddSelection(index, index + length);
136-
},
124+
SetSelection = (int index, int length) => BNpp.AddSelection(index, index + length),
137125

138126
GetSelectionStartIndex = () => BNpp.SelectionStart,
139127

140128
GetSelectionLength = () => BNpp.SelectionLength,
141129

142130
SaveCurrentDocument = () => BNpp.SaveCurrentDocument(),
143131

144-
TryOpen = delegate (string fileName, bool onlyIfAlreadyOpen)
132+
TryOpen = (string fileName, bool onlyIfAlreadyOpen) =>
145133
{
146134
try
147135
{
148136
bool result = false;
149137

150-
//MessageBox.Show(BNpp.CurrentPath + "\r\n" + fileName);
151-
if (BNpp.CurrentPath.ToLower().Equals(fileName.ToLower()))
138+
//MessageBox.Show(BNpp.CurrentPath + "\r\n" + fileName);
139+
if (BNpp.CurrentPath.ToLower().Equals(fileName.ToLower()))
152140
result = true;
153-
else if (BNpp.AllOpenedDocuments.Any(delegate (string s) { return s.Equals(fileName, StringComparison.OrdinalIgnoreCase); }))
141+
else if (BNpp.AllOpenedDocuments.Any((string s) => s.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
154142
{
155143
BNpp.ShowOpenedDocument(fileName);
156144
result = true;
@@ -179,10 +167,7 @@ public static void ShowTheDialog()
179167

180168
},
181169

182-
GetCurrentFileName = delegate ()
183-
{
184-
return BNpp.CurrentPath;
185-
}
170+
GetCurrentFileName = () => BNpp.CurrentPath
186171
};
187172

188173
dialog.Show();

CSharpRegexTools4Npp/PluginInfrastructure/GatewayDomain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public override bool Equals(object obj)
147147

148148
public override int GetHashCode()
149149
{
150-
return pos;
150+
return (int)pos;
151151
}
152152
}
153153

CSharpRegexTools4Npp/PluginInfrastructure/Scintilla_iface.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,36 @@ public struct ScNotificationHeader
3838
public struct ScNotification
3939
{
4040
public ScNotificationHeader Header;
41-
private readonly int position; /* SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED, SCN_MARGINCLICK, SCN_NEEDSHOWN, SCN_DWELLSTART, SCN_DWELLEND, SCN_CALLTIPCLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION */
42-
public int character; /* SCN_CHARADDED, SCN_KEY, SCN_AUTOCCOMPLETE, SCN_AUTOCSELECTION, SCN_USERLISTSELECTION */
43-
public int Mmodifiers; /* SCN_KEY, SCN_DOUBLECLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE */
44-
public int ModificationType; /* SCN_MODIFIED - modification types are name "SC_MOD_*" */
41+
private readonly uint position; /* SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED, SCN_MARGINCLICK, SCN_NEEDSHOWN, SCN_DWELLSTART, SCN_DWELLEND, SCN_CALLTIPCLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION */
42+
public uint character; /* SCN_CHARADDED, SCN_KEY, SCN_AUTOCCOMPLETE, SCN_AUTOCSELECTION, SCN_USERLISTSELECTION */
43+
public uint Mmodifiers; /* SCN_KEY, SCN_DOUBLECLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE */
44+
public uint ModificationType; /* SCN_MODIFIED - modification types are name "SC_MOD_*" */
4545
public IntPtr TextPointer; /* SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION, SCN_URIDROPPED */
46-
public int Length; /* SCN_MODIFIED */
47-
public int LinesAdded; /* SCN_MODIFIED */
48-
public int Message; /* SCN_MACRORECORD */
46+
public uint Length; /* SCN_MODIFIED */
47+
public uint LinesAdded; /* SCN_MODIFIED */
48+
public uint Message; /* SCN_MACRORECORD */
4949
public IntPtr wParam; /* SCN_MACRORECORD */
5050
public IntPtr lParam; /* SCN_MACRORECORD */
5151

5252
/// <summary>
5353
/// 0-based index
5454
/// </summary>
55-
public int LineNumber; /* SCN_MODIFIED */
56-
public int FoldLevelNow; /* SCN_MODIFIED */
57-
public int FoldLevelPrev; /* SCN_MODIFIED */
58-
public int Margin; /* SCN_MARGINCLICK */
59-
public int ListType; /* SCN_USERLISTSELECTION */
60-
public int X; /* SCN_DWELLSTART, SCN_DWELLEND */
61-
public int Y; /* SCN_DWELLSTART, SCN_DWELLEND */
62-
public int Token; /* SCN_MODIFIED with SC_MOD_CONTAINER */
63-
public int AnnotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */
64-
public int Updated; /* SCN_UPDATEUI */
65-
public int ListCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION */
55+
public uint LineNumber; /* SCN_MODIFIED */
56+
public uint FoldLevelNow; /* SCN_MODIFIED */
57+
public uint FoldLevelPrev; /* SCN_MODIFIED */
58+
public uint Margin; /* SCN_MARGINCLICK */
59+
public uint ListType; /* SCN_USERLISTSELECTION */
60+
public uint X; /* SCN_DWELLSTART, SCN_DWELLEND */
61+
public uint Y; /* SCN_DWELLSTART, SCN_DWELLEND */
62+
public uint Token; /* SCN_MODIFIED with SC_MOD_CONTAINER */
63+
public uint AnnotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */
64+
public uint Updated; /* SCN_UPDATEUI */
65+
public uint ListCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION */
6666

6767
/// <summary>
6868
/// SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED, SCN_MARGINCLICK, SCN_NEEDSHOWN, SCN_DWELLSTART, SCN_DWELLEND, SCN_CALLTIPCLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
6969
/// </summary>
70-
public Position Position { get { return new Position(position); } }
70+
public Position Position { get { return new Position((int)position); } }
7171

7272
/// <summary>
7373
/// Character of the notification - eg keydown

CSharpRegexTools4Npp/PluginInfrastructure/Win32.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public enum ScrollInfoBar
8484
/// If gateways are missing or incomplete, please help extend them and send your code to the project
8585
/// at https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net
8686
/// </summary>
87-
[DllImport("user32")]
87+
[DllImport("user32", CharSet = CharSet.Auto)]
8888
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
8989

9090
/// <summary>
@@ -93,7 +93,7 @@ public enum ScrollInfoBar
9393
/// If gateways are missing or incomplete, please help extend them and send your code to the project
9494
/// at https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net
9595
/// </summary>
96-
[DllImport("user32")]
96+
[DllImport("user32", CharSet = CharSet.Auto)]
9797
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lParam);
9898

9999
/// <summary>
@@ -102,7 +102,7 @@ public enum ScrollInfoBar
102102
/// If gateways are missing or incomplete, please help extend them and send your code to the project
103103
/// at https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net
104104
/// </summary>
105-
[DllImport("user32")]
105+
[DllImport("user32", CharSet = CharSet.Auto)]
106106
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
107107

108108
/// <summary>
@@ -111,7 +111,7 @@ public enum ScrollInfoBar
111111
/// If gateways are missing or incomplete, please help extend them and send your code to the project
112112
/// at https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net
113113
/// </summary>
114-
[DllImport("user32")]
114+
[DllImport("user32", CharSet = CharSet.Auto)]
115115
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, out IntPtr lParam);
116116

117117
/// <summary>

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
596596
{
597597
text = File.ReadAllText(fileName);
598598
int matchesCount = regex.Matches(text).Count;
599-
nbrOfElementToReplace += matchesCount;
600599

601600
if (matchesCount > 0)
602601
{
@@ -652,11 +651,17 @@ private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
652651
{
653652
text = GetText();
654653
int matchesCount = regex.Matches(text).Count;
655-
654+
nbrOfElementToReplace += matchesCount;
656655
if (matchesCount > 0)
657656
{
658657
SetText(regex.Replace(text, replaceText));
659658

659+
try
660+
{
661+
SaveCurrentDocument?.Invoke();
662+
}
663+
catch { }
664+
660665
files++;
661666
}
662667
}
@@ -910,7 +915,7 @@ private void MatchResultsTreeView_SelectedItemChanged(object sender, RoutedPrope
910915
{
911916
try
912917
{
913-
RegexResult regexResult = MatchResultsTreeView.SelectedValue as RegexResult;
918+
RegexResult regexResult = e.NewValue as RegexResult;
914919

915920
if(regexResult != null && regexResult.FileName.Length > 0)
916921
{

0 commit comments

Comments
 (0)