internal static void PrepareList(Object list) { if (!(list is ListView)) { MessageBox.Show("Программа выполнила невыполнимое, допустила недопустимое!"); return; } ((ListView)list).Items.Clear(); int fileCount = -1; IntPtr currentScintilla = PluginBase.GetCurrentScintilla(); fileCount = Main.GetFileCount(currentScintilla); ClikeStringArray _names = new ClikeStringArray(fileCount, Win32.MAX_PATH); Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETOPENFILENAMES, _names.NativePointer, fileCount); ListViewItem lvi = null; for (int i = 0; i < fileCount; i++) { lvi = new ListViewItem(); lvi.Checked = true; lvi.Text = _names.ManagedStringsUnicode[i]; ((ListView)list).Items.Add(lvi); } ((ListView)list).Refresh(); }
public static string[] GetOpenFiles() { int nbFile = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, 0); using (ClikeStringArray cStrArray = new ClikeStringArray(nbFile, Win32.MAX_PATH)) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETOPENFILENAMES, cStrArray.NativePointer, nbFile) != IntPtr.Zero) { return(cStrArray.ManagedStringsUnicode.ToArray()); } else { return(null); } } }
public string[] GetOpenFilesRaw() { var count = send(NppMsg.NPPM_GETNBOPENFILES, Unused, Unused); using (var cStrArray = new ClikeStringArray(count.ToInt32(), Win32.MAX_PATH)) { if (send(NppMsg.NPPM_GETOPENFILENAMES, cStrArray.NativePointer, count) != IntPtr.Zero) { return(cStrArray.ManagedStringsUnicode.ToArray()); } else { return(new string[0]); } } }
public static string[] GetOpenFiles() { int count = execute(NppMsg.NPPM_GETNBOPENFILES, 0, 0); using (var cStrArray = new ClikeStringArray(count, Win32.MAX_PATH)) { if (execute(NppMsg.NPPM_GETOPENFILENAMES, (int)cStrArray.NativePointer, count) != 0) { return(cStrArray.ManagedStringsUnicode.ToArray()); } else { return(new string[0]); } } }
/// <summary> /// Get list of open files /// </summary> /// <returns></returns> public static List <string> GetOpenedFiles() { List <string> openedFiles = new List <string>(); int nbFile = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, 0); using (ClikeStringArray cStrArray = new ClikeStringArray(nbFile, Win32.MAX_PATH)) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETOPENFILENAMES, cStrArray.NativePointer, nbFile) != IntPtr.Zero) { foreach (string s in cStrArray.ManagedStringsUnicode) { openedFiles.Add(s); } } } return(openedFiles); }
static void getFileNamesDemo() { int nbFile = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, 0, 0); MessageBox.Show(nbFile.ToString(), "Number of opened files:"); using (ClikeStringArray cStrArray = new ClikeStringArray(nbFile, Win32.MAX_PATH)) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETOPENFILENAMES, cStrArray.NativePointer, nbFile) != IntPtr.Zero) { foreach (string file in cStrArray.ManagedStringsUnicode) { MessageBox.Show(file); } } } }
static public List <string> GetOpenFileExtensions() { List <string> extensions = new List <string>(); int filecount = GetNumberOfOpenFiles(); ClikeStringArray cStringArray = new ClikeStringArray(filecount, Win32.MAX_PATH); if (filecount > 0) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETOPENFILENAMES, cStringArray.NativePointer, filecount) != IntPtr.Zero) { foreach (var file in cStringArray.ManagedStringsUnicode) { extensions.Add(Path.GetExtension(file.ToString())); } } } return(extensions); }
static void getSessionFileNamesDemo() { int nbFile = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBSESSIONFILES, 0, sessionFilePath); if (nbFile < 1) { MessageBox.Show("Please modify \"sessionFilePath\" in \"Demo.cs\" in order to point to a valid session file", "Error"); return; } MessageBox.Show(nbFile.ToString(), "Number of session files:"); using (ClikeStringArray cStrArray = new ClikeStringArray(nbFile, Win32.MAX_PATH)) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETSESSIONFILES, cStrArray.NativePointer, sessionFilePath) != IntPtr.Zero) { foreach (string file in cStrArray.ManagedStringsUnicode) { MessageBox.Show(file); } } } }
private void btnTransform_Click(object sender, EventArgs e) { string xmlFileName = ""; string xmlData = ""; string xslData = ""; string working = "Working..."; // Check each file to the right of the XML file. bool foundXML = false; bool foundXSLT = false; bool foundXForm = false; bool onXSLT = false; try { Cursor = Cursors.WaitCursor; // Get the current doctype LangType docType = LangType.L_TEXT; Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTLANGTYPE, 0, ref docType); bool isDocTypeXML = docType == LangType.L_XML; // Return if doctype is not XML if (!isDocTypeXML) { lblWarning.Text = "Please select an XML file to transform."; Utils.TimerWarning(lblWarning); return; } // Get XML text xmlFileName = notepad.GetCurrentFilePath(); xmlData = editor.GetAllText(); // Identify the current document as XSLT. if (xmlData.IndexOf("</xsl:stylesheet>") > 0) { onXSLT = true; } // ************************************************** // Find the XSLT document // ************************************************** // Count of opened files int fileCnt = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, 0, 0); // If viewing XSLT, select the XML file before it. if (onXSLT) { using (ClikeStringArray cStrArray = new ClikeStringArray(fileCnt, Win32.MAX_PATH)) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, cStrArray.NativePointer, fileCnt) != IntPtr.Zero) { string prevFile = ""; foreach (string file in cStrArray.ManagedStringsUnicode) { if (file == xmlFileName) { Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SWITCHTOFILE, 0, prevFile); xmlFileName = notepad.GetCurrentFilePath(); xmlData = editor.GetAllText(); break; } prevFile = file; } } } } using (ClikeStringArray cStrArray = new ClikeStringArray(fileCnt, Win32.MAX_PATH)) { if (Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, cStrArray.NativePointer, fileCnt) != IntPtr.Zero) { foreach (string file in cStrArray.ManagedStringsUnicode) { if (foundXML) { // Check for an XML document Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SWITCHTOFILE, 0, file); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTLANGTYPE, 0, ref docType); isDocTypeXML = docType == LangType.L_XML; if (isDocTypeXML && !foundXSLT) { foundXSLT = true; xslData = editor.GetAllText(); } if (foundXSLT) { if (file.ToLower().IndexOf(".xform") > 0) { Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SWITCHTOFILE, 0, file); foundXForm = true; break; } } } if (file == xmlFileName) { foundXML = true; } } } if (foundXML && foundXSLT) { if (!foundXForm) { notepad.FileNew(); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SAVECURRENTFILEAS, 0, Path.GetTempFileName() + ".xform"); foundXForm = true; } editor.SetText(working); working = ""; Application.DoEvents(); var data = SaxonXForm.TransformXml(xmlData, xslData); editor.SetXML(data + Environment.NewLine); } else { MessageBox.Show("The XML and XSLT documents could not be identified.", "ERP Helper", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; MessageBox.Show(message, "ERP Helper", MessageBoxButtons.OK, MessageBoxIcon.Error); if (foundXForm) { if (working.Length == 0) { try { editor.SetText(working + Environment.NewLine); } catch { // ignore exception } } } } finally { Cursor = Cursors.Default; } }