private FindAndReplace() { _editor = Editor.GetActive(); _window = new FindAndReplaceForm { FindHistory = Settings.FindHistory.ToArray(), ReplaceHistory = Settings.ReplaceHistory.ToArray(), MatchCase = Settings.MatchCase, MatchWholeWord = Settings.MatchWholeWord, UseRegularExpression = Settings.UseRegularExpression, SearchFromBegining = Settings.SearchFromBegining, SearchBackwards = Settings.SearchBackwards, SearchIn = Settings.SearchIn }; if (!Settings.WindowSize.IsEmpty) { _window.ClientSize = Settings.WindowSize; } if (!Settings.WindowLocation.IsEmpty) { _window.StartPosition = FormStartPosition.Manual; _window.Location = Settings.WindowLocation; } _window.DoAction += OnDoAction; _owner = new WindowWrapper(PluginBase.nppData._nppHandle); }
private FindAndReplace() { _editor = Editor.GetActive(); if (FindHistory == null) FindHistory = new List<string>(); if (ReplaceHistory == null) ReplaceHistory = new List<string>(); _window = new FindAndReplaceForm { FindHistory = FindHistory.ToArray(), ReplaceHistory = ReplaceHistory.ToArray(), MatchCase = MatchCase, MatchWholeWord = MatchWholeWord, UseRegularExpression = UseRegularExpression, SearchFromBegining = SearchFromBegining, SearchBackwards = SearchBackwards, SearchIn = SearchInOptions.CurrentDocument }; _window.DoAction += OnDoAction; _owner = new WindowWrapper(PluginBase.nppData._nppHandle); }
private IndentationSettings() { _editor = Editor.GetActive(); }
private IndentationSettings() { _editor = Editor.GetActive(); _dialog = new IndentationSettingsForm(); _owner = new WindowWrapper(PluginBase.nppData._nppHandle); }
private int FindInOtherDocument(string findText, int view, int fileIndex) { // Activate next document Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, view, fileIndex); _editor = Editor.GetActive(); // This statement avoids a loop if there's no match in the first document, it calls FindInOtherDocument but if SearchFromBegining is true it starts back at first document again. Settings.SearchFromBegining = false; // Reset cursor position to top of documnet _editor.SetSelection(0, 0); return FindNext(findText); }
private int ReplaceAll(string findText, string replaceText, int currentDocument, int currentView) { if (Settings.SearchIn == SearchInOptions.SelectedText && (!_searchScope.HasValue || _searchScope.Value.cpMin == _searchScope.Value.cpMax)) throw new InvalidOperationException("Search scope has not been defined."); var replacements = 0; SetSearchFlags(); var startPosition = Settings.SearchIn == SearchInOptions.SelectedText ? _searchScope.Value.cpMin : 0; var endPosition = Settings.SearchIn == SearchInOptions.SelectedText ? _searchScope.Value.cpMax :_editor.GetDocumentLength(); var posFound = _editor.FindInTarget(findText, startPosition, endPosition); if (findText == "^" && Settings.UseRegularExpression) { // Special case for replace all start of line so it hits the first line posFound = startPosition; _editor.SetTargetRange(startPosition, endPosition); } if (posFound != -1 && posFound <= endPosition) { _editor.BeginUndoAction(); while (posFound != -1) { var matchEnd = _editor.GetTargetRange().cpMax; var targetLength = matchEnd - posFound; var movePastEOL = 0; if (targetLength <= 0) { var nextChar = _editor.GetCharAt(matchEnd); if (nextChar == '\r' || nextChar == '\n') movePastEOL = 1; } var replacedLength = _editor.ReplaceText(replaceText, Settings.UseRegularExpression); // Modify for change caused by replacement endPosition += replacedLength - targetLength; // For the special cases of start of line and end of line // something better could be done but there are too many special cases var lastMatch = posFound + replacedLength + movePastEOL; if (targetLength == 0) lastMatch = _editor.PositionAfter(lastMatch); if (lastMatch >= endPosition) // Run off the end of the document/selection with an empty match posFound = -1; else posFound = _editor.FindInTarget(findText, lastMatch, endPosition); replacements++; } _editor.EndUndoAction(); } if (Settings.SearchIn == SearchInOptions.OpenDocuments) { // Is there another document? var fileCount = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, currentView + 1); // If there's another document in the view, switch to it if (currentDocument < fileCount - 1) { Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, currentView, ++currentDocument); _editor = Editor.GetActive(); replacements += ReplaceAll(findText, replaceText, currentDocument, currentView); } else if (currentView == (int)NppMsg.MAIN_VIEW && IsViewVisible((int)NppMsg.SUB_VIEW)) { currentView = (int)NppMsg.SUB_VIEW; currentDocument = 0; Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, currentView, currentDocument); _editor = Editor.GetActive(); replacements += ReplaceAll(findText, replaceText, currentDocument, currentView); } } return replacements; }
private int ReplaceAll(string findText, string replaceText) { if (Settings.SearchIn == SearchInOptions.OpenDocuments) { var currentDocument = 0; var currentView = IsViewVisible((int)NppMsg.MAIN_VIEW) ? (int)NppMsg.MAIN_VIEW : (int)NppMsg.SUB_VIEW; Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, currentView, currentDocument); _editor = Editor.GetActive(); return ReplaceAll(findText, replaceText, currentDocument, currentView); } return ReplaceAll(findText, replaceText, -1, -1); }
private int FindNext(string findText) { if (Settings.SearchIn == SearchInOptions.SelectedText && (!_searchScope.HasValue || _searchScope.Value.cpMin == _searchScope.Value.cpMax)) throw new InvalidOperationException("Search scope has not been defined."); if (Settings.SearchIn == SearchInOptions.OpenDocuments && Settings.SearchFromBegining) { // Assumes that both views ALWAYS have one document open (index 0). Notepad++ always shows a 'New 1' document if everthing else is closed. if (!Settings.SearchBackwards) { Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, IsViewVisible((int)NppMsg.MAIN_VIEW) ? (int)NppMsg.MAIN_VIEW : (int)NppMsg.SUB_VIEW, 0); _editor = Editor.GetActive(); } else { if (IsViewVisible((int)NppMsg.SUB_VIEW)) { var secondViewFileCount = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, (int)NppMsg.SECOND_VIEW); Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, (int)NppMsg.SUB_VIEW, secondViewFileCount > 0 ? secondViewFileCount - 1 : 0); } else { var primaryViewFileCount = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, (int)NppMsg.PRIMARY_VIEW); Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ACTIVATEDOC, (int)NppMsg.MAIN_VIEW, primaryViewFileCount > 0 ? primaryViewFileCount - 1 : 0); } _editor = Editor.GetActive(); } } var selection = _editor.GetSelectionRange(); var documentLength = _editor.GetDocumentLength(); var startPosition = Settings.SearchBackwards ? Settings.SearchFromBegining ? Settings.SearchIn == SearchInOptions.SelectedText ? _searchScope.Value.cpMax : documentLength : selection.cpMin : Settings.SearchFromBegining ? Settings.SearchIn == SearchInOptions.SelectedText ? _searchScope.Value.cpMin : 0 : selection.cpMax; var endPosition = Settings.SearchBackwards ? Settings.SearchIn == SearchInOptions.SelectedText ? _searchScope.Value.cpMin : 0 : Settings.SearchIn == SearchInOptions.SelectedText ? _searchScope.Value.cpMax : documentLength; SetSearchFlags(); var posFind = _editor.FindInTarget(findText, startPosition, endPosition); if (posFind != -1) { // Highlight if found _lastMatch = _editor.GetTargetRange(); _editor.EnsureRangeVisible(_lastMatch.Value.cpMin, _lastMatch.Value.cpMax); _editor.SetSelection(_lastMatch.Value.cpMin, _lastMatch.Value.cpMax); } else if (Settings.SearchIn == SearchInOptions.OpenDocuments) { // Check next document int currentView; Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTSCINTILLA, 0, out currentView); var currentFileIndex = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTDOCINDEX, 0, currentView); if (!Settings.SearchBackwards) { // Searching forwards var fileCount = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, currentView + 1); // If there's another document in the view, switch to it if (currentFileIndex < fileCount - 1) posFind = FindInOtherDocument(findText, currentView, currentFileIndex + 1); else if (currentView == (int)NppMsg.MAIN_VIEW && IsViewVisible((int)NppMsg.SUB_VIEW)) posFind = FindInOtherDocument(findText, (int)NppMsg.SUB_VIEW, 0); } else { // Searching backwards if (currentFileIndex > 0) posFind = FindInOtherDocument(findText, currentView, currentFileIndex - 1); else if (currentView == (int)NppMsg.SUB_VIEW && IsViewVisible((int)NppMsg.MAIN_VIEW)) { var primaryViewFileCount = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETNBOPENFILES, 0, (int)NppMsg.PRIMARY_VIEW); posFind = FindInOtherDocument(findText, (int)NppMsg.MAIN_VIEW, primaryViewFileCount > 0 ? primaryViewFileCount - 1 : 0); } } } return posFind; }
private GuidGenerator() { _editor = Editor.GetActive(); _dialog = new GuidGeneratorForm(); _owner = new WindowWrapper(PluginBase.nppData._nppHandle); }