|
1 | 1 | using CSharpRegexTools4Npp.PluginInfrastructure;
|
2 | 2 | using System;
|
3 |
| -using System.Collections.Generic; |
4 |
| -using System.IO; |
5 | 3 | using System.Text;
|
6 | 4 |
|
7 |
| - |
8 | 5 | namespace CSharpRegexTools4Npp
|
9 | 6 | {
|
10 | 7 | public class BNpp
|
11 | 8 | {
|
12 |
| - |
13 |
| - /// <summary> |
14 |
| - /// Constante défini au niveau des APIs Windows qui défini le nombre max de caractères |
15 |
| - /// que peut prendre un chemin d'accès complet d'un fichier |
16 |
| - /// </summary> |
17 |
| - public const int PATH_MAX = 260; |
18 |
| - |
19 |
| - |
20 |
| - /// <summary> |
21 |
| - /// Récupère le chemin d'accès au fichier courant ouvert dans Notepad++ |
22 |
| - /// </summary> |
23 |
| - public static string CurrentPath |
24 |
| - { |
25 |
| - get |
26 |
| - { |
27 |
| - var path = new StringBuilder(2000); |
28 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETFULLCURRENTPATH, 0, path); |
29 |
| - return path.ToString(); |
30 |
| - } |
31 |
| - } |
32 |
| - |
33 |
| - /// <summary> |
34 |
| - /// Récupère le chemin d'accès au dossier ou se trouve l'exécutable de l'instance courante de Notepad++ |
35 |
| - /// </summary> |
36 |
| - public static string NppBinDirectoryPath |
37 |
| - { |
38 |
| - get |
39 |
| - { |
40 |
| - var path = new StringBuilder(2000); |
41 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNPPDIRECTORY, 0, path); |
42 |
| - return path.ToString(); |
43 |
| - } |
44 |
| - } |
45 |
| - |
46 |
| - /// <summary> |
47 |
| - /// Récupère le nombre de fichiers ouverts dans Notepad++ |
48 |
| - /// </summary> |
49 |
| - public static int NbrOfOpenedFiles |
50 |
| - { |
51 |
| - get |
52 |
| - { |
53 |
| - // le - 1 enlève le "new 1" en trop, toujours présent dans la liste des fichier ouverts |
54 |
| - return Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_GETNBOPENFILES, 0, (int)NppMsg.ALL_OPEN_FILES) |
55 |
| - .ToInt32() - 1; |
56 |
| - } |
57 |
| - } |
58 |
| - |
59 |
| - /// <summary> |
60 |
| - /// Récupère la liste de tous les chemins d'accès aux fichiers ouverts dans Notepad++ |
61 |
| - /// </summary> |
62 |
| - public static List<string> AllOpenedDocuments |
63 |
| - { |
64 |
| - get |
65 |
| - { |
66 |
| - List<string> result = new List<string>(); |
67 |
| - int nbr = NbrOfOpenedFiles; |
68 |
| - |
69 |
| - using (var cStringArray = new ClikeStringArray(nbr, PATH_MAX)) |
70 |
| - { |
71 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETOPENFILENAMES, cStringArray.NativePointer, nbr); |
72 |
| - |
73 |
| - result = cStringArray.ManagedStringsUnicode; |
74 |
| - } |
75 |
| - |
76 |
| - return result; |
77 |
| - } |
78 |
| - } |
79 |
| - |
80 |
| - /// <summary> |
81 |
| - /// Affiche le tab du document déjà ouvert spécifié dans Notepad++ |
82 |
| - /// </summary> |
83 |
| - /// <param name="tabPath">Le chemin d'accès du fichier ouvert dans Notepad++ que l'on veut afficher</param> |
84 |
| - /// <see>AllOpenedFilesPaths</see> |
85 |
| - public static void ShowOpenedDocument(string tabPath) |
86 |
| - { |
87 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_SWITCHTOFILE, 0, tabPath); |
88 |
| - } |
89 |
| - |
90 |
| - /// <summary> |
91 |
| - /// Crée un nouveau document dans Notepad++ dans un nouveau tab. |
92 |
| - /// </summary> |
93 |
| - public static void CreateNewDocument() |
94 |
| - { |
95 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_NEW); |
96 |
| - } |
97 |
| - |
98 |
| - /// <summary> |
99 |
| - /// Essai d'ouvrir le fichier spécifié dans Notepad++ |
100 |
| - /// </summary> |
101 |
| - /// <param name="fileName">Le chemin d'accès du fichier à ouvrir dans Notepad++</param> |
102 |
| - /// <returns><c>True</c> Si le fichier à pu s'ouvrir correctement <c>False</c> si le fichier spécifié ne peut pas être ouvert</returns> |
103 |
| - public static bool OpenFile(string fileName) |
104 |
| - { |
105 |
| - bool result = false; |
106 |
| - |
107 |
| - if (File.Exists(fileName)) |
108 |
| - { |
109 |
| - #if X64 |
110 |
| - result = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_DOOPEN, 0, fileName).ToInt64() == 1; |
111 |
| - #else |
112 |
| - result = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DOOPEN, 0, fileName).ToInt32() == 1; |
113 |
| - #endif |
114 |
| - } |
115 |
| - |
116 |
| - return result; |
117 |
| - } |
118 |
| - |
119 |
| - /// <summary> |
120 |
| - /// Sauvegarde le document courant |
121 |
| - /// </summary> |
122 |
| - public static void SaveCurrentDocument() |
123 |
| - { |
124 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SAVECURRENTFILE, 0, 0); |
125 |
| - } |
126 |
| - |
127 |
| - /// <summary> |
128 |
| - /// Sauvegarde tous les documents actuellement ouverts dans Notepad++ |
129 |
| - /// </summary> |
130 |
| - public static void SaveAllOpenedDocuments() |
131 |
| - { |
132 |
| - Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SAVEALLFILES, 0, 0); |
133 |
| - } |
| 9 | + public static NotepadPPGateway NotepadPP { get; private set; } = new NotepadPPGateway(); |
134 | 10 |
|
135 | 11 | /// <summary>
|
136 | 12 | /// Récupère les caractères de fin de lignes courant
|
|
0 commit comments