diff --git a/Demo Plugin/NppManagedPluginDemo/Demo.cs b/Demo Plugin/NppManagedPluginDemo/Demo.cs index 96bae70..a435ec1 100644 --- a/Demo Plugin/NppManagedPluginDemo/Demo.cs +++ b/Demo Plugin/NppManagedPluginDemo/Demo.cs @@ -1,5 +1,6 @@ // NPP plugin platform for .Net v0.91.57 by Kasper B. Graversen etc. using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Drawing; @@ -36,10 +37,33 @@ static internal void SetToolBarIcon() public static void OnNotification(ScNotification notification) { + uint code = notification.Header.Code; + // This method is invoked whenever something is happening in notepad++ + // use eg. as + // if (code == (uint)NppMsg.NPPN_xxx) + // { ... } + // or + // + // if (code == (uint)SciMsg.SCNxxx) + // { ... } + // when closing a file + if (code == (uint)NppMsg.NPPN_FILEBEFORECLOSE) + { + Kbg.Demo.Namespace.Main.AddToFilesClosed(notification.Header.IdFrom); + return; + } + if (notification.Header.Code == (uint)SciMsg.SCN_CHARADDED) { Kbg.Demo.Namespace.Main.doInsertHtmlCloseTag((char)notification.Character); + return; } + + //if (code > int.MaxValue) // windows messages + //{ + // int wm = -(int)code; + // } + //} } internal static string PluginName { get { return Kbg.Demo.Namespace.Main.PluginName; }} @@ -59,6 +83,7 @@ class Main static string sessionFilePath = @"C:\text.session"; static frmGoToLine frmGoToLine = null; static internal int idFrmGotToLine = -1; + static internal List filesClosedThisSession = new List(); // toolbar icons static Bitmap tbBmp = Properties.Resources.star; @@ -136,6 +161,8 @@ static internal void CommandMenuInit() PluginBase.SetCommand(16, "---", null); PluginBase.SetCommand(17, "Print Scroll and Row Information", PrintScrollInformation); + PluginBase.SetCommand(18, "Use NanInf class for -inf, inf, nan!!", PrintNanInf); + PluginBase.SetCommand(19, "Show files closed this session", FilesClosedThisSession); } /// @@ -222,6 +249,7 @@ static void callbackHelloFX() static void WhatIsNpp() { + // from https://notepad-plus-plus.org/ string text2display = "Notepad++ is a free (as in \"free speech\" and also as in \"free beer\") " + "source code editor and Notepad replacement that supports several languages.\n" + "Running in the MS Windows environment, its use is governed by GPL License.\n\n" + @@ -233,34 +261,53 @@ static void WhatIsNpp() new Thread(new ParameterizedThreadStart(callbackWhatIsNpp)).Start(text2display); } + /// + /// Open up a new file and slowly printing out the "What is NPP" text above.

+ /// Stops printing text if the new file is closed. + ///
+ /// static void callbackWhatIsNpp(object data) { string text2display = (string)data; notepad.FileNew(); + string new_file_name = getCurrentPath(NppMsg.FULL_CURRENT_PATH); Random srand = new Random(DateTime.Now.Millisecond); int rangeMin = 0; - int rangeMax = 250; + int rangeMax = 125; for (int i = 0; i < text2display.Length; i++) { Thread.Sleep(srand.Next(rangeMin, rangeMax) + 30); + // stop adding new text if the user closes or switches out of the new file. + // otherwise you get this obnoxious addition of text to existing files. + string selected_file_name = getCurrentPath(NppMsg.FULL_CURRENT_PATH); + if (selected_file_name != new_file_name) break; editor.AppendTextAndMoveCursor(text2display[i].ToString()); } } static void insertCurrentFullPath() { - insertCurrentPath(NppMsg.FULL_CURRENT_PATH); + editor.ReplaceSel(getCurrentPath(NppMsg.FULL_CURRENT_PATH)); } static void insertCurrentFileName() { - insertCurrentPath(NppMsg.FILE_NAME); + editor.ReplaceSel(getCurrentPath(NppMsg.FILE_NAME)); } static void insertCurrentDirectory() { - insertCurrentPath(NppMsg.CURRENT_DIRECTORY); + editor.ReplaceSel(getCurrentPath(NppMsg.CURRENT_DIRECTORY)); } - static void insertCurrentPath(NppMsg which) + + /// + /// Returns a property of the currently open file, depending on argument:

+ /// * If NppMsg.NPPM_GETFULLCURRENTPATH -> return absolute path to current file

+ /// * If NppMsg.NPPM_GETFILENAME -> return file name of current file

+ /// * If NppMsg.NPPM_GETCURRENTDIRECTORY -> return directory of current file

+ ///
+ /// + /// + static string getCurrentPath(NppMsg which) { NppMsg msg = NppMsg.NPPM_GETFULLCURRENTPATH; if (which == NppMsg.FILE_NAME) @@ -269,9 +316,9 @@ static void insertCurrentPath(NppMsg which) msg = NppMsg.NPPM_GETCURRENTDIRECTORY; StringBuilder path = new StringBuilder(Win32.MAX_PATH); - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) msg, 0, path); + Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)msg, 0, path); - editor.ReplaceSel(path.ToString()); + return path.ToString(); } static void insertShortDateTime() @@ -293,7 +340,7 @@ static void checkInsertHtmlCloseTag() PluginBase.CheckMenuItemToggle(9, ref doCloseTag); // 9 = menu item index } - static Regex regex = new Regex(@"[\._\-:\w]", RegexOptions.Compiled); + static Regex XmlTagNameRegex = new Regex(@"[\._\-:\w]", RegexOptions.Compiled); static internal void doInsertHtmlCloseTag(char newChar) { @@ -335,7 +382,7 @@ static internal void doInsertHtmlCloseTag(char newChar) var insertString = new StringBuilder("frmGoToLine.cs + Resources.resx diff --git a/Demo Plugin/NppManagedPluginDemo/PluginInfrastructure/NanInf.cs b/Demo Plugin/NppManagedPluginDemo/PluginInfrastructure/NanInf.cs new file mode 100644 index 0000000..79f812e --- /dev/null +++ b/Demo Plugin/NppManagedPluginDemo/PluginInfrastructure/NanInf.cs @@ -0,0 +1,30 @@ +using System; + +namespace Kbg.NppPluginNET.PluginInfrastructure +{ + /// + /// holds NaN, Infinity, and -Infinity as things generated at runtime

+ /// because the compiler freaks out if it sees any of

+ /// double.NegativeInfinity, double.PositiveInfinity, or double.NaN

+ /// or any statically analyzed function of two constants that makes one of those constants

+ /// like 1d/0d, 0d/0d, or -1d/0d. + ///
+ public class NanInf + { + /// + /// a/b

+ /// may be necessary to generate infinity or nan at runtime + /// to avoid the compiler pre-computing things

+ /// since if the compiler sees literal 1d/0d in the code + /// it just pre-computes it at compile time + ///
+ /// + /// + /// + public static double Divide(double a, double b) { return a / b; } + + public static readonly double inf = Divide(1d, 0d); + public static readonly double neginf = Divide(-1d, 0d); + public static readonly double nan = Divide(0d, 0d); + } +} diff --git a/README.md b/README.md index 1ccf325..2379c49 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ This is a fork of UFO's plugin package updated for VS2015, 2017 and 2019 * https://github.com/wakatime/notepadpp-wakatime * https://github.com/alex-ilin/WebEdit * https://github.com/Fruchtzwerg94/PlantUmlViewer + * https://github.com/molsonkiko/JsonToolsNppPlugin If your plugin is not on the list, please make a PR with a link to it.. :-) diff --git a/Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateway.cs b/Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateway.cs index 981e1b7..c19ac58 100644 --- a/Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateway.cs +++ b/Visual Studio Project Template C#/PluginInfrastructure/IScintillaGateway.cs @@ -2516,7 +2516,10 @@ public interface IScintillaGateway /// Set up the key words used by the lexer. (Scintilla feature 4005) unsafe void SetKeyWords(int keyWordSet, string keyWords); - /// Set the lexing language of the document based on string name. (Scintilla feature 4006) + /// Set the lexing language of the document based on string name. (Scintilla feature 4006)

+ /// WARNING! This does not appear to do anything.

+ /// Use INotepadPPGateway.SetCurrentLanguage instead. + ///
unsafe void SetLexerLanguage(string language); /// Load a lexer library (dll / so). (Scintilla feature 4007) diff --git a/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs b/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs index 747712a..d2d101f 100644 --- a/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs +++ b/Visual Studio Project Template C#/PluginInfrastructure/NotepadPPGateway.cs @@ -16,7 +16,7 @@ public interface INotepadPPGateway string GetNppPath(); string GetPluginConfigPath(); string GetCurrentFilePath(); - unsafe string GetFilePath(int bufferId); + unsafe string GetFilePath(IntPtr bufferId); // use IntPtr to work with 32-bit and 64-bit Notepad++ void SetCurrentLanguage(LangType language); bool OpenFile(string path); } @@ -108,7 +108,7 @@ public bool OpenFile(string path) /// /// Gets the path of the current document. /// - public unsafe string GetFilePath(int bufferId) + public unsafe string GetFilePath(IntPtr bufferId) { var path = new StringBuilder(2000); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETFULLPATHFROMBUFFERID, bufferId, path);