Skip to content

Commit

Permalink
tidy code; fix typos; improve code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
molsonkiko committed Jan 17, 2024
1 parent 048a020 commit 66cf116
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

1. toggle highlighting of `close HTML/XML tag` toolbar icon based on whether the setting is true.
2. add more UI tests for [ScintillaGateway.cs](/NppCSharpPluginPack/PluginInfrastructure/ScintillaGateway.cs) and [NotepadPPGateway.cs](/NppCSharpPluginPack/PluginInfrastructure/NotepadPPGateway.cs) methods to make sure they work.
3. In [ToolsForMaintainersOfTheProjectTemplate](/ToolsForMaintainersOfTheProjectTemplate/), I need to add auto-generation of calls to `GetNullStrippedStringFromMessageThatReturnsLength(SciMsg msg, IntPtr wParam=default)` instead of the old fixed-size 10000-byte buffers

### To Be Changed

Expand Down
3 changes: 1 addition & 2 deletions NppCSharpPluginPack/Forms/DarkModeTestForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Windows.Forms;
using System.Windows.Forms;
using Kbg.NppPluginNET;
using NppDemo.Utils;

Expand Down
4 changes: 2 additions & 2 deletions NppCSharpPluginPack/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.0.1.3")]
[assembly: AssemblyFileVersion("0.0.1.3")]
[assembly: AssemblyVersion("0.0.1.4")]
[assembly: AssemblyFileVersion("0.0.1.4")]
4 changes: 2 additions & 2 deletions NppCSharpPluginPack/Tests/Benchmarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace NppDemo.Tests
{
/// <summary>
/// contains benchmarking tests for RemesPath, JsonParser, and JsonSchemaValidator
/// put performance benchmarks for your code in this file (assuming you want to run them with TestRunner.cs)
/// </summary>
public class Benchmarker
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public class Benchmarker
queryTimesStr[ii] = Math.Round(queryTimes[ii] / 1e4, 3).ToString();
}
Npp.AddLine($"Query times (ms): {String.Join(", ", queryTimesStr)}");
string resultPreview = "Previow of result";
string resultPreview = "Preview of result";
Npp.AddLine($"Preview of result: {resultPreview}");
}
return false;
Expand Down
1 change: 0 additions & 1 deletion NppCSharpPluginPack/Tests/UserInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using NppDemo.Forms;
using NppDemo.Utils;
using Kbg.NppPluginNET;

Expand Down
4 changes: 1 addition & 3 deletions NppCSharpPluginPack/Utils/FormStyle.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Drawing;
using System.Reflection;
using System.Drawing;
using System.Windows.Forms;

namespace NppDemo.Utils
Expand Down
2 changes: 1 addition & 1 deletion NppCSharpPluginPack/Utils/NanInf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class NanInf
/// a/b<br></br>
/// may be necessary to generate infinity or nan at runtime
/// to avoid the compiler pre-computing things<br></br>
/// since if the compiler sees literal 1d/0d in the code
/// since if the compiler sees literal division by 0d in the code
/// it just pre-computes it at compile time
/// </summary>
/// <param name="a"></param>
Expand Down
4 changes: 1 addition & 3 deletions NppCSharpPluginPack/Utils/Npp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,8 @@ public static void CharToSb(StringBuilder sb, char c)

/// <summary>
/// the string representation of a JSON string
/// with or without the enclosing quotes a JSON string normally has
/// if not quoted, this will not have the enclosing quotes a JSON string normally has
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string StrToString(string s, bool quoted)
{
int slen = s.Length;
Expand Down
4 changes: 2 additions & 2 deletions NppCSharpPluginPack/Utils/SelectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public static int StartEndCompareByStart((int start, int end) se1, (int start, i
/// Given selections (selstart1,selend1), (selstart2,selend2), ..., (selstartN,selendN)<br></br>
/// returns a sep-separated list of "start,end" pairs.<br></br>
/// EXAMPLE:<br></br>
/// * StartEndListToJsonString([(1, 2), (5, 7)], "], [") returns "1,2], [5,7"<br></br>
/// * StartEndListToJsonString([(1, 2), (9, 20), (30,45)], " ") returns "1,2 9,20 30,45"
/// * StartEndListToString([(1, 2), (5, 7)], "], [") returns "1,2], [5,7"<br></br>
/// * StartEndListToString([(1, 2), (9, 20), (30,45)], " ") returns "1,2 9,20 30,45"
/// </summary>
public static string StartEndListToString(IEnumerable<(int start, int end)> selections, string sep=" ")
{
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

[![License](http://img.shields.io/badge/License-Apache_2-red.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)

This is a template for Notepad++ plugins written. The vast majority of the code (certainly all the parts that were really hard to implment) come from [kbilsted's now-archived `NotepadPlusPlusPluginPack.Net`](https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net), with some significant changes, including:
This is a template for Notepad++ plugins written in C#. The vast majority of the code (certainly all the parts that were really hard to implement) come from [kbilsted's now-archived `NotepadPlusPlusPluginPack.Net`](https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net), with some significant changes, including:

1. `NotepadPlusPlusPluginPack.Net` has an architecture that is (in my opinion) needlessly complicated, because it separates the `PluginInfrastructure` folder containing all the necessary code for connecting with Notepad++ in a completely different directory tree from the rest of the code.
2. This plugin template includes an example of a [non-docking (pop-up) dialog](/docs/README.md#about-form) opened from the plugin menu, a [docking form](/docs/README.md#selections-remembering-form), and a [non-docking non-pop-up form](/docs/README.md#dark-mode-test-form).
3. This plugin template includes a [settings form](/docs/README.md#settings-form) that makes it easy for the maintainer to add, remove or edit settings.
4. This template has a template for [automated tests](/docs/README.md#running-tests) that can be run inside Notepad++, including a template for user interface tests that automatically test forms.
1. A simpler architecture in which the [PluginInfrastructure folder](/NppCSharpPluginPack/PluginInfrastructure/) is side-by-side with the rest of the plugin's code, rather than in a separate directory tree.
2. An example of a [non-docking (pop-up) dialog](/docs/README.md#about-form) opened from the plugin menu, a [docking form](/docs/README.md#selections-remembering-form), and a [non-docking non-pop-up form](/docs/README.md#dark-mode-test-form).
3. A [settings form](/docs/README.md#settings-form) that makes it easy for the maintainer to add, remove or edit settings.
4. A template for [automated tests](/docs/README.md#running-tests) that can be run inside Notepad++, including a template for user interface tests that automatically test forms.

If you have any issues, see if [updating to the latest release](https://github.com/molsonkiko/NppCSharpPluginPack/releases) helps, and then feel free to raise an [issue](https://github.com/molsonkiko/NppCSharpPluginPack/issues) on GitHub. Please be sure to include diagnostic information about your system, Notepad++ version, and plugin version (go to `?->Debug Info...` from the Notepad++ main menu).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,16 @@ def printLexGatewayFile(f):
iindent = iindent + " "

if param2Type == "stringresult":
bufferVariableName = param2Name + "Buffer"
bufferSize = "length" if (param1Type == "int" and param1Name == "length") else "10000"
out.append(iindent + "byte[] " + bufferVariableName +" = new byte["+bufferSize+"];")
out.append(iindent + "fixed (byte* "+param2Name+"Ptr = " +bufferVariableName + ")" )
out.append(iindent + "{")
iindent = iindent + " "
# TODO: this is where I need to auto-generate calls to
# GetNullStrippedStringFromMessageThatReturnsLength(SciMsg msg, IntPtr wParam=default)
# THIS IS STILL NOT FINISHED
returnvalue = 'return GetNullStrippedStringFromMessageThatReturnsLength(' + featureConstant
# if param 1 is unused, don't pass a second arg
if param1Type != 'Unused':
returnvalue += ', (IntPtr)' + param1Name
returnvalue += ')'
out.append(returnvalue)


firstArg = translateVariableAccess(param1Name, param1Type)
seconArg = translateVariableAccess(param2Name, param2Type)
Expand All @@ -196,14 +200,14 @@ def printLexGatewayFile(f):
# out.append(iindent + "return new Position((int) " +res+ ");")
elif returnType == "string":
out.append(iindent + res + ";")
out.append(iindent + "return Encoding.UTF8.GetString("+bufferVariableName+").TrimEnd('\\0');")
out.append(iindent + "return Utf8BytesToNullStrippedString("+bufferVariableName+");")
else:
out.append(iindent + "return (" +returnType+ ")" +res+ ";")

if param1Type in ["string", "Cells", "stringresult"]:
iindent = iindent[4:]
out.append(iindent + "}")
if param2Type in ["string", "Cells", "stringresult"]:
if param2Type in ["string", "Cells"]:
iindent = iindent[4:]
out.append(iindent + "}")

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ One thing to note is that this form responds to keys in intuitive and useful way

This is all because I registered the controls in the form with the `KeyUp`, `KeyDown`, and `KeyPress` handlers in [NppCSharpPlugin/Forms/NppFormHelper.cs](/NppCSharpPluginPack/Forms/NppFormHelper.cs).

You will notice that the DarkModeTestForm discussed below does not have these nice responses to keys, because I did not register those handlers for its controls.
You will notice that the DarkModeTestForm discussed below *does not have these nice responses to keys*, because I did not register those handlers for its controls.

## Dark mode test form ##

Expand Down
10 changes: 5 additions & 5 deletions most recent errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Test results for CSharpPluginPack v0.0.1.3 on Notepad++ 8.5.8 64bit
Test results for CSharpPluginPack v0.0.1.4 on Notepad++ 8.5.8 64bit
NOTE: Ctrl-F (regular expressions *on*) for "Failed [1-9]\d*" to find all failed tests
No tests failed
=========================
Expand All @@ -21,13 +21,13 @@ Testing Performance of something
Performance tests for My benchmarks (test1)
=========================

To run query "foo" on file of size 7913 into took 0 +/- 0 ms over 32 trials
Query times (ms): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Preview of result: Previow of result
To run query "foo" on file of size 7913 into took 0 +/- 0.002 ms over 32 trials
Query times (ms): 0.01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Preview of result: Preview of result
=========================
Performance tests for My benchmarks (test2)
=========================

To run query "bar" on file of size 7913 into took 0 +/- 0 ms over 32 trials
Query times (ms): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Preview of result: Previow of result
Preview of result: Preview of result

0 comments on commit 66cf116

Please sign in to comment.