/// <summary> /// Sends the message. /// </summary> /// <param name="editor">The editor.</param> /// <param name="Msg">The MSG.</param> /// <param name="wParam">The w parameter.</param> /// <param name="lParam">The l parameter.</param> /// <param name="expectedSize">The expected size.</param> public static void SendMessage(this NotepadPPGateway editor, NppMsg Msg, int wParam, out string lParam, int expectedSize = 2000) { var path = new StringBuilder(expectedSize); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETFULLCURRENTPATH, path.Capacity, path); lParam = path.ToString(); }
public void StartParse(CsvSettings settings) { StartSomething(() => Parse(settings, new DiagnosticTimer(), PluginBase.CurrentScintillaGateway.GetAllText(), NotepadPPGateway.GetCurrentBufferId())); }
/// <summary> /// Load the ini-file and initialize the menu items. The toolbar will be /// initialized later and will use the commands used in the menu added here /// to get the command identifiers for the toolbar buttons. /// </summary> internal static void CommandMenuInit() { int i = 0; var npp = new NotepadPPGateway(); iniDirectory = Path.Combine(npp.GetPluginConfigPath(), PluginName); _ = Directory.CreateDirectory(iniDirectory); iniFilePath = Path.Combine(iniDirectory, IniFileName); LoadConfig(); // TODO: move the menu initialization to the LoadConfig method. var ini = new IniFile(iniFilePath); var actions = new Actions(ini); foreach (string key in actions.iniKeys) { var methodInfo = typeof(Actions).GetMethod("ExecuteCommand" + i); if (methodInfo == null) { break; } PluginBase.SetCommand( i++, key, (NppFuncItemDelegate)Delegate.CreateDelegate( typeof(NppFuncItemDelegate), actions, methodInfo.Name)); } PluginBase.SetCommand( i++, "Replace Tag", ReplaceTag, new ShortcutKey(false, true, false, Keys.Enter)); PluginBase.SetCommand(0, "", null); PluginBase.SetCommand(i++, "Edit Config", EditConfig); PluginBase.SetCommand(i++, "Load Config", LoadConfig); PluginBase.SetCommand(i++, "About...", About); }
private void Analyze(bool silent) { var watch = new DiagnosticTimer(); var bufferId = NotepadPPGateway.GetCurrentBufferId(); var textLength = PluginBase.CurrentScintillaGateway.GetTextLength(); var text = PluginBase.CurrentScintillaGateway.GetTextRange(0, Math.Min(100000, textLength)); watch.Checkpoint("GetText"); var csvSettings = CsvAnalyzer.Analyze(text); if (csvSettings.Separator == '\0' && csvSettings.FieldWidths == null) { if (silent) { return; } var askUserDialog = new ParseSettings(csvSettings); this.UiThread(() => askUserDialog.ShowDialog()); if (askUserDialog.DialogResult != DialogResult.OK) { return; } csvSettings = askUserDialog.Settings; } watch.Checkpoint("Analyze"); using (var sr = ScintillaStreams.StreamAllText()) { this.Parse(csvSettings, watch, sr, bufferId); } }
static public void OpenFile(this NotepadPPGateway editor, string file, bool grabFocus) { editor.Open(file); if (grabFocus) { Npp.GetCurrentDocument().GrabFocus(); } }
// [DllImport("user32")] // public static extern IntPtr SendMessage(IntPtr hWnd, NppMsg Msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lParam); // [DllImport("user32")] // public static extern IntPtr SendMessage(IntPtr hWnd, NppMsg Msg, int wParam, int lParam); // static int execute(NppMsg msg, int wParam, int lParam = 0) // { // return (int)NppExtensions.SendMessage(Npp.Editor.Handle, msg, wParam, lParam); // } // static public string GetTabFile(int index) // { // var path = new StringBuilder(Win32.MAX_PATH); // SendMessage(Npp.Editor.Handle, NppMsg.NPPM_GETFULLPATHFROMBUFFERID, index, path); // return path.ToString(); // } // public static string[] get_open_files1(this NotepadPPGateway editor) // { // int count = execute(NppMsg.NPPM_GETNBOPENFILES, 0, 0); // var files = new List<string>(); // for (int i = 0; i < count; i++) // { // int id = execute(NppMsg.NPPM_GETBUFFERIDFROMPOS, i, 0); // var file = GetTabFile(id); // if (file != null) // files.Add(file); // } // return files.ToArray(); // } static public void DisplayInNewDocument(this NotepadPPGateway editor, string text) { editor.FileNew(); var document = Npp.GetCurrentDocument(); document.GrabFocus(); document.AddText(text); }
/// <summary> /// Open the corresponding file on label click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LblfileName_1_MouseDown(object sender, MouseButtonEventArgs e) { try { System.Windows.Controls.Label srcLabel = e.Source as System.Windows.Controls.Label; //to know which label call this handler string fileName = srcLabel.Content.ToString(); string fileSearchPath = CommitWindow.pushDirectory; string[] folders = Directory.GetDirectories(fileSearchPath); foreach (string folder in folders) { string folderName = folder.Split('\\')[folder.Split('\\').Length - 1]; if (folderName == fileName) { string[] files = Directory.GetFiles(folder); foreach (string file in files) { string replacedString = file.Split('\\')[file.Split('\\').Length - 1]; //Need to add commit info with filename to get the searched file int rowNumberOfSrcLabel = Convert.ToInt32(((srcLabel.Name).Split('_'))[1]); Label modifiedTime = FindName("lblfileDate_" + (rowNumberOfSrcLabel)) as Label; Label modifedBy = FindName("lblModifiedBy_" + (rowNumberOfSrcLabel)) as Label; string searchFileName = modifiedTime.Content.ToString() + "_" + modifedBy.Content.ToString() + "_" + fileName; searchFileName = searchFileName.Replace(":", "_"); //string flname = replacedString.Split('_')[replacedString.Split('_').Length-1]; if (replacedString == searchFileName) { NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); //Save as file with temp prefix for temporary opening string tempFileName = "temp_" + fileName; string tempFileSavePath = CommitWindow.pushDirectory + "\\" + tempFileName; notepadPPGateway.openFile(file); notepadPPGateway.SaveCurrentFile(tempFileSavePath); notepadPPGateway.openFile(file); notepadPPGateway.CloseCurrentFile(); this.Close(); break; } } } } } catch { //Write error log here } }
public void StartParse(CsvSettings settings) { this.StartSomething(() => { using (var sr = ScintillaStreams.StreamAllText()) { this.Parse(settings, new DiagnosticTimer(), sr, NotepadPPGateway.GetCurrentBufferId()); } }); }
internal static void printDebugLine() { IntPtr hCurrScintilla = PluginBase.GetCurrentScintilla(); ScintillaGateway sci = new ScintillaGateway(hCurrScintilla); var lineNumber = sci.GetCurrentLineNumber() + 1; NotepadPPGateway npp = new NotepadPPGateway(); var fileName = Path.GetFileNameWithoutExtension(npp.GetCurrentFilePath()); var stream = new FileStream(@"plugins/Config/GoToDefinition/debug_table.txt", FileMode.Open, FileAccess.Read); using (var streamReader = new StreamReader(stream, Encoding.UTF8)) { var text = streamReader.ReadToEnd(); text = text + $"'{fileName}', {lineNumber}, )"; sci.AddText(text.Length, text); } }
private void OnClickExecButton(object sender, EventArgs e) { this.StartSomething(() => { var watch = new DiagnosticTimer(); var bufferId = NotepadPPGateway.GetCurrentBufferId(); this.Execute(bufferId, watch); var diagnosticMessage = watch.LastCheckpoint("Save query in history"); Trace.TraceInformation(diagnosticMessage); if (Main.Settings.DebugMode) { this.Message(diagnosticMessage); } }); }
internal static void CommandMenuInit() { _settings = new Settings(); Gateway = new NotepadPPGateway(); PluginBase.SetCommand(0, "Parse", ParseParams); PluginBase.SetCommand(1, "Format", FormatSql); PluginBase.SetCommand(2, "Format And Parse", FormatSqlAndParseParams); PluginBase.SetCommand(3, "Format, Parse, Execute", FormatSqlParseExecuteParams); PluginBase.SetCommand(4, "Execute", ShowExecuteWindow, new ShortcutKey(true, false, false, Keys.F5)); _idExecuteWindow = 4; PluginBase.SetCommand(5, "Config", ShowConfigWindow); _idConfigWindow = 5; }
/// <summary> /// Add the toolbar icons for the menu items that have the configured /// bitmap files in the iniDirectory folder. /// </summary> internal static void AddToolbarIcons() { var npp = new NotepadPPGateway(); var ini = new IniFile(iniFilePath); foreach (string key in ini.GetKeys("Toolbar")) { try { npp.AddToolbarIcon( Convert.ToInt32(key) - 1, new Bitmap( Path.Combine( iniDirectory, ini.Get("Toolbar", key).Replace("\0", "")))); } catch { // Ignore any errors like missing or corrupt bitmap files, or // incorrect command index values. } } }
private static void pmlCommit() { NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); //Save the file to original location string path = notepadPPGateway.GetCurrentFilePath(); //check the file is committed file or not. if (path.Contains("temp")) { MessageBox.Show("This file can not be committed. Revert to this version before committing."); return; } //Open Commit form to enter commit message CommitWindow commitFrm = new CommitWindow(); commitFrm.Show(); }
internal static void goToDefinition() { IntPtr hCurrScintilla = PluginBase.GetCurrentScintilla(); NotepadPPGateway npp = new NotepadPPGateway(); ScintillaGateway sci = new ScintillaGateway(hCurrScintilla); var selectedText = sci.GetSelText(); if (string.IsNullOrEmpty(selectedText)) { return; } Dictionary <string, string> filePaths = new Dictionary <string, string>(); var stream = new FileStream(@"plugins/Config/GoToDefinition/sql_repos.txt", FileMode.Open, FileAccess.Read); using (var streamReader = new StreamReader(stream, Encoding.UTF8)) { var text = streamReader.ReadToEnd(); var allFilePaths = text.Split(';'); foreach (var filePath in allFilePaths) { var kvp = filePath.Split('='); if (kvp.Length > 1) { filePaths.Add(kvp[0], kvp[1]); } } } StringBuilder sb = new StringBuilder(); var matchingFileNames = new List <string>(); foreach (var kvp in filePaths) { var matchingFiles = Directory.GetFiles(kvp.Value, $"{selectedText}*", SearchOption.TopDirectoryOnly); matchingFileNames.AddRange(matchingFiles); } FilesDialog fd = new FilesDialog(matchingFileNames.ToArray()); fd.Show(); }
internal static void myMenuFunction() { try { /* Not sure why this works when running as a local admin user but something * fails when running as a user without local admin. Will investigate later, * for now just accept that previous values may not be retrieved. */ StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath); iniFilePath = sbIniFilePath.ToString(); if (!Directory.Exists(iniFilePath)) { Directory.CreateDirectory(iniFilePath); } iniFilePath = Path.Combine(iniFilePath, PluginName + ".ini"); StringBuilder savedPathname = new StringBuilder("", 255); int i = Win32.GetPrivateProfileString("Dependencies", "7ZipExeDirectory", "", savedPathname, 255, iniFilePath); config7ZipPath = savedPathname.ToString(); } catch (Exception) { } PathTo7Zip = Find7zPath(); INotepadPPGateway notepad = new NotepadPPGateway(); string currentFile = notepad.GetCurrentFilePath(); if (string.IsNullOrEmpty(currentFile) || !File.Exists(currentFile)) { MessageBox.Show("Please save the file list first"); return; } if (frmMyDlg == null) { frmMyDlg = new frmMyDlg(); } frmMyDlg.SourceFilePath = currentFile; if (frmMyDlg.ShowDialog() == DialogResult.OK) { CreateArchive(currentFile, frmMyDlg.ArchiveFilename, frmMyDlg.StartDirectory); } }
static public bool IsCurrentDocScriptFile(this NotepadPPGateway editor) { return(editor.GetCurrentFilePath().IsScriptFile()); }
/// <summary> /// Sends the menu command. /// </summary> /// <param name="editor">The editor.</param> /// <param name="command">The command.</param> /// <returns></returns> public static IntPtr SendMenuCommand(this NotepadPPGateway editor, NppMenuCmd command) => Win32.SendMessage(editor.Handle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_NEW);
/// <summary> /// Sends the message. /// </summary> /// <param name="editor">The editor.</param> /// <param name="Msg">The MSG.</param> /// <param name="wParam">The w parameter.</param> /// <param name="lParam">The l parameter.</param> /// <returns></returns> public static int SendMessage(this NotepadPPGateway editor, NppMsg Msg, int wParam, int lParam) => (int)Win32.SendMessage(editor.Handle, Msg, wParam, lParam);
private static void revertToOldVersion() { try { string codeDirectory = CommitWindow.codeDirectory; NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); List <string> linesList = new List <string>();//all the lines except commit lines //Save the file to original location string path = notepadPPGateway.GetCurrentFilePath(); string savePath = path.Split('\\')[path.Split('\\').Length - 1];//file name savePath = savePath.Replace("temp_", ""); if (!(CommitWindow.currentFileDirectory == "") && Path.GetFileName(CommitWindow.currentFileDirectory) == savePath) { //Delete the commit messages from the file //read the file and for original path to save string[] lines = File.ReadAllLines(path); foreach (string line in lines) { if (!(line.Contains("--Commit"))) { linesList.Add(line); } } //Getting save directory savePath = CommitWindow.currentFileDirectory; } else { //read the file and for original path to save string[] lines = File.ReadAllLines(path); foreach (string line in lines) { if (line.Contains("--Commit Original Directory: ")) { savePath = line.Replace("--Commit Original Directory: ", ""); break; } } foreach (string line in lines) { if (!(line.Contains("--Commit"))) { linesList.Add(line); } } } if (!File.Exists(savePath)) { MessageBox.Show("This file could not be reverted"); } else if (path == savePath) { MessageBox.Show("This is the current version"); } else { //Save the file without commit message if (File.Exists(savePath)) { File.Delete(savePath); } File.WriteAllLines(savePath, linesList); notepadPPGateway.openFile(savePath); MessageBox.Show("Reverted successfully!"); } }catch (Exception err) { MessageBox.Show(err.ToString()); } }
public VersionShowWindow() { InitializeComponent(); try { NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); //Save the file to original location string path = notepadPPGateway.GetCurrentFilePath(); CommitWindow.currentFileDirectory = path; //Save the file to another directory string currentFileName = System.IO.Path.GetFileName(path); allVersionInfo = versionInfo(currentFileName); //All available version info is stored here //Now need to add them to UI int count = 1; foreach (PmlVersion version in allVersionInfo) { if (count < 11) { //Finding and assigning filename System.Windows.Controls.Label lblFileName = this.FindName("lblfileName_" + count) as System.Windows.Controls.Label; lblFileName.Content = version.fileName; lblFileName.Visibility = Visibility.Visible; //Finding and assigning modifiedDate System.Windows.Controls.Label lblModifiedDate = this.FindName("lblfileDate_" + count) as System.Windows.Controls.Label; lblModifiedDate.Content = version.modifiedDate; lblModifiedDate.Visibility = Visibility.Visible; //Finding and assigning modifiedBy System.Windows.Controls.Label lblModifiedBy = this.FindName("lblModifiedBy_" + count) as System.Windows.Controls.Label; lblModifiedBy.Content = version.modifiedBy; lblModifiedBy.Visibility = Visibility.Visible; //Finding and assigning commitMessage System.Windows.Controls.RichTextBox lblCommitMessage = this.FindName("lblCommitMessage_" + count) as System.Windows.Controls.RichTextBox; lblCommitMessage.AppendText(version.commitMessage); lblCommitMessage.Visibility = Visibility.Visible; } count++; } //Finding and assigning count System.Windows.Controls.Label lblCountNumber = this.FindName("countNumber") as System.Windows.Controls.Label; lblCountNumber.Content = (count - 1).ToString("00"); lblCountNumber.Visibility = Visibility.Visible; //Search all labels and set horizontal allignement center for version info labels only try { UIElementCollection uiFileInfoLabels = fileInfoLabels.Children; foreach (System.Windows.Controls.Label lbl in uiFileInfoLabels) { lbl.HorizontalContentAlignment = HorizontalAlignment.Center; } } catch { } }catch (Exception err) { MessageBox.Show(err.ToString()); } }
private void btnCommit_Click(object sender, EventArgs e) { //Check its pml file or not NotepadPPGateway notepadPPGatewayTemp = new NotepadPPGateway(); string pathTemp = notepadPPGatewayTemp.GetCurrentFilePath(); string currentFileNameTemp = Path.GetFileName(pathTemp); bool isPml = Utility.isPml(currentFileNameTemp); //True if this is a PML file //Take the commit message string[] commitMessage = richTxtCommit.Lines; int i = 0; //Getting commit message foreach (string s in commitMessage) { commitMessage[i] = Utility.commentSpecifier + "Commit Message:$ " + commitMessage[i]; i++; } if (!(commitMessage.Length == 0)) { NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); //Save the file to original location string path = notepadPPGateway.GetCurrentFilePath(); //check the file is committed file or not. if (path.Contains("temp")) { MessageBox.Show("This file can not be committed. Revert to this version before committing."); return; } currentFileDirectory = path;//for later use notepadPPGateway.SaveCurrentFile(); //Save the file to another directory string currentFileName = Path.GetFileName(path); string userName = Environment.UserName; DateTime now = System.DateTime.Now; string pushedFileName = now.ToString() + "_" + userName + "_" + currentFileName; pushedFileName = pushedFileName.Replace(":", "_"); pushedFileName = pushedFileName.Replace(@"\", "_"); //Create directory for the original file if (Directory.Exists(pushDirectory) && !(pushDirectory == "") && Directory.Exists(rootDirectory) && !(rootDirectory == "") && Directory.Exists(codeDirectory) && !(codeDirectory == "") && Directory.Exists(finalDirectoryForEncryption) && !(finalDirectoryForEncryption == "")) { Directory.CreateDirectory(pushDirectory + "\\" + currentFileName); string pushedFileDirectory = pushDirectory + "\\" + currentFileName + "\\" + pushedFileName; notepadPPGateway.SaveCurrentFile(pushedFileDirectory); //Open the file from remote directory and write commit message on top of it as comment and save AddCommitMessageToFileTop(commitMessage, pushedFileDirectory); MessageBox.Show("Successfully Committed"); //Closing the save as file and opening the original file notepadPPGateway.CloseCurrentFile(); notepadPPGateway.openFile(path); //Only pml files can be commited as final if ((chkFinal.Checked == true || chkEmergency.Checked == true) && isPml == false) { MessageBox.Show("Only PML file can be committed as Final"); return; } if (chkFinal.Checked == true) { //Check file path contains code directory of PML files if (path.Contains(codeDirectory)) { string strucDirectory = (path.Replace(codeDirectory, "")).Replace(currentFileName, ""); string newDirectory = finalDirectoryForEncryption + strucDirectory; Directory.CreateDirectory(newDirectory); if (File.Exists(newDirectory + currentFileName)) { File.Delete(newDirectory + currentFileName); File.Copy(path, newDirectory + currentFileName); } else { File.Copy(path, newDirectory + currentFileName); } } else { MessageBox.Show("File should be opened from code directory to make as final"); } } else if (chkEmergency.Checked == true) { //Check file path contains code directory of PML files if (path.Contains(codeDirectory)) { //To copy on final directory for encryption //Same name on same if else conflicts so 'New' added string strucDirectoryNew = (path.Replace(codeDirectory, "")).Replace(currentFileName, ""); string newDirectoryNew = finalDirectoryForEncryption + strucDirectoryNew; if (!Directory.Exists(newDirectoryNew)) { Directory.CreateDirectory(newDirectoryNew); } if (File.Exists(newDirectoryNew + currentFileName)) { File.Delete(newDirectoryNew + currentFileName); File.Copy(path, newDirectoryNew + currentFileName); } else { File.Copy(path, newDirectoryNew + currentFileName); } //To copy on emergency directory to get immediately newDirectoryNew = emergencyDirectory + strucDirectoryNew; if (!Directory.Exists(newDirectoryNew)) { Directory.CreateDirectory(newDirectoryNew); } if (File.Exists(newDirectoryNew + currentFileName)) { File.Delete(newDirectoryNew + currentFileName); File.Copy(path, newDirectoryNew + currentFileName); } else { File.Copy(path, newDirectoryNew + currentFileName); } //Utility.pmlindexAppend(emergencyDirectory + "\\" + "pml.index", newDirectoryNew + currentFileName); } else { MessageBox.Show("File should be opened from code directory to make as final"); } } } else { MessageBox.Show("Invalid Directory"); } //Close the commit form and dispose this.Close(); this.Dispose(); } else { MessageBox.Show("Write a Commit Message before commiting code describing changes"); } }