/// <summary> /// Finds the correct match based on the current position /// </summary> private void FindCorrect(String text, Boolean refreshHighlights) { if (string.IsNullOrEmpty(text)) { return; } ScintillaControl sci = Globals.SciControl; this.findTextBox.BackColor = this.backColor; List <SearchMatch> matches = this.GetResults(sci, text); if (matches != null && matches.Count != 0) { SearchMatch match = FRDialogGenerics.GetNextDocumentMatch(sci, matches, true, true); if (match != null) { FRDialogGenerics.SelectMatch(sci, match); } if (refreshHighlights) { this.RefreshHighlights(sci, matches); } String message = TextHelper.GetString("Info.ShowingResult"); Int32 index = FRDialogGenerics.GetMatchIndex(match, matches); String formatted = String.Format(message, index, matches.Count); this.infoLabel.Text = formatted; } else { this.findTextBox.BackColor = Globals.MainForm.GetThemeColor("QuickFind.ErrorBack", Color.Salmon); sci.SetSel(sci.SelectionStart, sci.SelectionStart); String message = TextHelper.GetString("Info.NoMatchesFound"); this.infoLabel.Text = message; } }
/// <summary> /// Finds the previous match based on the current position /// </summary> private void FindPrev(String text, Boolean refreshHighlights) { if (text == "") { return; } ScintillaControl sci = Globals.SciControl; this.findTextBox.BackColor = SystemColors.Window; List <SearchMatch> matches = this.GetResults(sci, text); if (matches != null && matches.Count != 0) { SearchMatch match = FRDialogGenerics.GetNextDocumentMatch(sci, matches, false, false); if (match != null) { FRDialogGenerics.SelectMatch(sci, match); } if (refreshHighlights) { this.RefreshHighlights(sci, matches); } String message = TextHelper.GetString("Info.ShowingResult"); Int32 index = FRDialogGenerics.GetMatchIndex(match, matches); String formatted = String.Format(message, index, matches.Count); this.infoLabel.Text = formatted; } else { this.findTextBox.BackColor = Color.Salmon; sci.SetSel(sci.SelectionStart, sci.SelectionStart); String message = TextHelper.GetString("Info.NoMatchesFound"); this.infoLabel.Text = message; } }
public SearchMatch GetMatch(int start) { if (string.IsNullOrEmpty(_input)) { return(null); } if (_list == null || GetItemCountValue() <= 0) { return(null); } //(re)build regex if (_regex == null) { UpdateRegEx(); } //find first match in [start,END] int index = -1; Match match = null; for (index = start; index < GetItemCountValue(); index++) { match = _regex.Match(GetItemSearchPropertyValue(index)); if (match.Success) { break; } } //find math in [BEGIN,start[ if (match == null || !match.Success) { for (index = 0; index < start; index++) { match = _regex.Match(GetItemSearchPropertyValue(index)); if (match.Success) { break; } } } //process result SearchMatch searchmatch = null; if (match != null && match.Success) { searchmatch = new SearchMatch(); searchmatch._text = match.Groups[0].Value; searchmatch._index = index; searchmatch._start = match.Groups[0].Index; searchmatch._length = match.Groups[0].Length; } return(searchmatch); }
/// <summary> /// Selects a search match /// </summary> public static void SelectMatch(ScintillaControl sci, SearchMatch match) { Int32 start = sci.MBSafePosition(match.Index); // wchar to byte position Int32 end = start + sci.MBSafeTextLength(match.Value); // wchar to byte text length Int32 line = sci.LineFromPosition(start); sci.EnsureVisible(line); sci.SetSel(start, end); }
public bool GetMatches(int start, List <int> lstMatches, ref SearchMatch firstMatch) { if (string.IsNullOrEmpty(_input)) { return(false); } if (_list == null || GetItemCountValue() <= 0) { return(false); } //(re)build regex if (_regex == null) { UpdateRegEx(); } //find all matches in if (lstMatches == null) { lstMatches = new List <int>(); } else { lstMatches.Clear(); } firstMatch = null; //first match after start SearchMatch veryFirstMatch = null; //first match in list Match match = null; for (int index = 0; index < GetItemCountValue(); index++) { match = _regex.Match(GetItemSearchPropertyValue(index)); if (match.Success) { lstMatches.Add(index); if (veryFirstMatch == null) { veryFirstMatch = new SearchMatch(match.Groups[0], index); } if (firstMatch == null && index >= start) { firstMatch = new SearchMatch(match.Groups[0], index); } } } if (firstMatch == null && veryFirstMatch != null) { firstMatch = veryFirstMatch; } return((lstMatches != null) && (lstMatches.Count > 0)); }
/// <summary> /// Gets an index of the search match /// </summary> public static Int32 GetMatchIndex(SearchMatch match, List <SearchMatch> matches) { for (Int32 i = 0; i < matches.Count; i++) { if (match == matches[i]) { return(i + 1); } } return(-1); }
public static SearchMatch ThreadIdToMatch( string url ) { var match = new SearchMatch { Url = url }; return(match); }
/// <summary> /// Checks if a given search match actually points to the given target source /// </summary /// <returns>True if the SearchMatch does point to the target source.</returns> static public bool DoesMatchPointToTarget(ScintillaNet.ScintillaControl Sci, SearchMatch match, ASResult target, DocumentHelper associatedDocumentHelper) { if (Sci == null || target == null) { return(false); } bool matchMember = target.InFile != null && target.Member != null; bool matchType = target.Member == null && target.IsStatic && target.Type != null; if (!matchMember && !matchType) { return(false); } ASResult result = null; // get type at match position if (match.Index < Sci.Text.Length) // TODO: find out rare cases of incorrect index reported { result = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value)); if (associatedDocumentHelper != null) { // because the declaration lookup opens a document, we should register it with the document helper to be closed later associatedDocumentHelper.RegisterLoadedDocument(PluginBase.MainForm.CurrentDocument); } } // check if the result matches the target if (result == null || (result.InFile == null && result.Type == null)) { return(false); } if (matchMember) { if (result.Member == null) { return(false); } return(result.InFile.BasePath == target.InFile.BasePath && result.InFile.FileName == target.InFile.FileName && result.Member.LineFrom == target.Member.LineFrom && result.Member.Name == target.Member.Name); } else // type { if (result.Type == null) { return(false); } if (result.Type.QualifiedName == target.Type.QualifiedName) { return(true); } return(false); } }
/// <summary> /// Checks if the given match actually is the declaration. /// </summary> public static bool IsMatchTheTarget(ScintillaControl Sci, SearchMatch match, ASResult target) { if (Sci == null || target == null || target.InFile == null || target.Member == null) { return(false); } String originalFile = Sci.FileName; // get type at match position ASResult declaration = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value)); return((declaration.InFile != null && originalFile == declaration.InFile.FileName) && (Sci.CurrentPos == (Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value)))); }
/// <summary> /// Gets the replacement text and escapes it if needed /// </summary> private String GetReplaceText(SearchMatch match) { String replace = this.replaceComboBox.Text; if (this.escapedCheckBox.Checked) { replace = FRSearch.Unescape(replace); } if (this.useRegexCheckBox.Checked) { replace = FRSearch.ExpandGroups(replace, match); } return(replace); }
/// <summary> /// Marks the lookup as dirty /// </summary> private void LookupChanged(Object sender, System.EventArgs e) { if (this.Visible) { this.lookupIsDirty = true; this.currentMatch = null; } if (sender == this.matchCaseCheckBox && !Globals.Settings.DisableFindOptionSync) { Globals.MainForm.SetMatchCase(this, this.matchCaseCheckBox.Checked); } if (sender == this.wholeWordCheckBox && !Globals.Settings.DisableFindOptionSync) { Globals.MainForm.SetWholeWord(this, this.wholeWordCheckBox.Checked); } }
public SearchResultItem(string absoluteFilePath, string relativeFilePath, SearchMatch match) { if (string.IsNullOrWhiteSpace(absoluteFilePath)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(absoluteFilePath)); } if (string.IsNullOrWhiteSpace(relativeFilePath)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(relativeFilePath)); } this.AbsoluteFilePath = absoluteFilePath; this.RelativeFilePath = relativeFilePath; this.Match = match ?? throw new ArgumentNullException(nameof(match)); }
public static SearchMatch GetNextDocumentMatch(ScintillaControl sci, List<SearchMatch> matches, int position) { SearchMatch nearestMatch = matches[0]; Int32 currentPosition = sci.MBSafeCharPosition(position); for (Int32 i = 0; i < matches.Count; i++) { if (currentPosition > matches[matches.Count - 1].Index) { return matches[0]; } if (matches[i].Index >= currentPosition) { return matches[i]; } } return nearestMatch; }
private SearchMatch ComposeSerachMatch(IDictionary <string, string> searchContent) { var result = new SearchMatch { Symbol = searchContent[SearchSymbolJsonToken.Symbol], Name = searchContent[SearchSymbolJsonToken.Name], Type = searchContent[SearchSymbolJsonToken.Type], Region = searchContent[SearchSymbolJsonToken.Region], MarketOpenTime = searchContent[SearchSymbolJsonToken.MarketOpenTime].ParseTimeSpan(), MarketCloseTime = searchContent[SearchSymbolJsonToken.MarketCloseTime].ParseTimeSpan(), Timezone = searchContent[SearchSymbolJsonToken.Timezone], Currency = searchContent[SearchSymbolJsonToken.Currency], MatchScore = searchContent[SearchSymbolJsonToken.MatchScore].ParseDecimal(), }; return(result); }
/// <summary> /// Gets the next valid match but fixes position with selected text's length /// </summary> public static SearchMatch GetNextDocumentMatch(ScintillaControl sci, List <SearchMatch> matches, Boolean forward, Boolean fixedPosition) { SearchMatch nearestMatch = matches[0]; Int32 currentPosition = sci.MBSafeCharPosition(sci.CurrentPos); if (fixedPosition) { currentPosition -= sci.MBSafeTextLength(sci.SelText); } for (Int32 i = 0; i < matches.Count; i++) { if (forward) { if (currentPosition > matches[matches.Count - 1].Index) { return(matches[0]); } if (matches[i].Index >= currentPosition) { return(matches[i]); } } else { if (sci.SelText.Length > 0 && currentPosition <= matches[0].Index + matches[0].Value.Length) { return(matches[matches.Count - 1]); } if (currentPosition < matches[0].Index + matches[0].Value.Length) { return(matches[matches.Count - 1]); } if (sci.SelText.Length == 0 && currentPosition == matches[i].Index + matches[i].Value.Length) { return(matches[i]); } if (matches[i].Index > nearestMatch.Index && matches[i].Index + matches[i].Value.Length < currentPosition) { nearestMatch = matches[i]; } } } return(nearestMatch); }
/// <summary> /// Finds the next result based on direction /// </summary> public void FindNext(Boolean forward, Boolean update, Boolean simple) { this.currentMatch = null; if (update) { this.UpdateFindText(); } if (Globals.SciControl == null) { return; } ScintillaControl sci = Globals.SciControl; List <SearchMatch> matches = this.GetResults(sci, simple); if (matches != null && matches.Count != 0) { FRDialogGenerics.UpdateComboBoxItems(this.findComboBox); SearchMatch match = FRDialogGenerics.GetNextDocumentMatch(sci, matches, forward, false); if (match != null) { this.currentMatch = match; FRDialogGenerics.SelectMatch(sci, match); this.lookupIsDirty = false; } if (this.Visible) { Int32 index = FRDialogGenerics.GetMatchIndex(match, matches); String message = TextHelper.GetString("Info.ShowingResult"); String formatted = String.Format(message, index, matches.Count); this.ShowMessage(formatted, 0); } } else { if (this.Visible) { String message = TextHelper.GetString("Info.NoMatchesFound"); this.ShowMessage(message, 0); } } this.SelectText(); }
/// <summary> /// Checks if a given search match actually points to the given target source /// </summary /// <returns>True if the SearchMatch does point to the target source.</returns> static public bool DoesMatchPointToTarget(ScintillaNet.ScintillaControl Sci, SearchMatch match, ASResult target, DocumentHelper associatedDocumentHelper) { if (Sci == null || target == null || target.inFile == null || target.Member == null) { return(false); } // get type at match position ASResult result = DeclarationLookupResult(Sci, Sci.MBSafePosition(match.Index) + Sci.MBSafeTextLength(match.Value)); if (associatedDocumentHelper != null) { // because the declaration lookup opens a document, we should register it with the document helper to be closed later associatedDocumentHelper.RegisterLoadedDocument(PluginBase.MainForm.CurrentDocument); } // check if the result matches the target // TODO: this method of checking their equality seems pretty crude -- is there a better way? if (result == null || result.inFile == null || result.Member == null) { return(false); } Boolean doesMatch = result.inFile.BasePath == target.inFile.BasePath && result.inFile.FileName == target.inFile.FileName && result.Member.LineFrom == target.Member.LineFrom && result.Member.Name == target.Member.Name; return(doesMatch); }
public static void Execute() { if ( Globals.SciControl == null ) return; ScintillaControl sci = Globals.SciControl; MainForm mainForm = (MainForm) Globals.MainForm; ITabbedDocument document = mainForm.CurrentDocument; String documentDirectory = Path.GetDirectoryName(document.FileName); ASContext context = (ASContext) ASContext.Context; string currentPackage = context.CurrentModel.Package; List<ClassModel> classes = context.CurrentModel.Classes; MemberList imports = context.CurrentModel.Imports; sci.BeginUndoAction(); String pattern = "}"; FRSearch search = new FRSearch(pattern); search.Filter = SearchFilter.None; List<SearchMatch> matches = search.Matches(sci.Text); if (matches == null || matches.Count == 0) return; if (classes.Count < 2) return; SearchMatch match = GetNextDocumentMatch(sci, matches, sci.PositionFromLine(classes[0].LineTo + 1)); Int32 packageEnd = sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value); // wchar to byte text length String strImport = ""; if (imports.Count > 0) { for (int i=imports.Count-1; i>0; --i ) { MemberModel import = imports[i]; if(packageEnd < sci.PositionFromLine(import.LineFrom)) { sci.SelectionStart = sci.PositionFromLine(import.LineFrom); sci.SelectionEnd = sci.PositionFromLine(import.LineTo + 1); strImport = sci.SelText + strImport; sci.Clear(); } } } context.UpdateCurrentFile(true); Int32 prevClassEnd = packageEnd; foreach (ClassModel currentClass in classes) { // 最初のクラスは無視 if (currentClass == classes[0]) continue; sci.SelectionStart = prevClassEnd; sci.SelectionEnd = sci.PositionFromLine(currentClass.LineTo + 1); String content = "package " + currentPackage + "\n{\n" + Regex.Replace( strImport, @"^", "\t", RegexOptions.Multiline) + Regex.Replace( sci.SelText, @"^", "\t", RegexOptions.Multiline) + "\n}\n"; prevClassEnd = sci.PositionFromLine(currentClass.LineTo + 1); Encoding encoding = sci.Encoding; String file = documentDirectory + "\\" + currentClass.Name + ".as"; FileHelper.WriteFile(file, content, encoding); } sci.SelectionStart = packageEnd; sci.Clear(); sci.EndUndoAction(); }
public bool GetMatches(int start, List<int> lstMatches, ref SearchMatch firstMatch) { if (string.IsNullOrEmpty(_input)) return false; if (_list == null || GetItemCountValue() <= 0) return false; //(re)build regex if (_regex == null) UpdateRegEx(); //find all matches in if (lstMatches == null) lstMatches = new List<int>(); else lstMatches.Clear(); firstMatch = null; //first match after start SearchMatch veryFirstMatch = null; //first match in list Match match = null; for (int index = 0; index < GetItemCountValue(); index++) { match = _regex.Match(GetItemSearchPropertyValue(index)); if (match.Success) { lstMatches.Add(index); if (veryFirstMatch == null) veryFirstMatch = new SearchMatch(match.Groups[0], index); if (firstMatch == null && index >= start) firstMatch = new SearchMatch(match.Groups[0], index); } } if (firstMatch == null && veryFirstMatch != null) firstMatch = veryFirstMatch; return (lstMatches != null) && (lstMatches.Count > 0); }
private void SearchInDirectory(DirectoryInfo directoryInfo, string searchText, bool subfoldersSearch, CancellationToken token, int level = 0) { var files = directoryInfo.GetFiles("*.siq"); var folders = directoryInfo.GetDirectories(); var total = files.Length + (subfoldersSearch ? folders.Length : 0); var done = 0; SearchMatch found = null; foreach (var file in files) { lock (_searchSync) { if (token.IsCancellationRequested) { return; } } found = null; try { using (var stream = File.OpenRead(file.FullName)) { using (var doc = SIDocument.Load(stream)) { var package = doc.Package; if ((found = package.SearchFragment(searchText)) == null) { foreach (var round in package.Rounds) { if ((found = round.SearchFragment(searchText)) != null) { break; } foreach (var theme in round.Themes) { if ((found = theme.SearchFragment(searchText)) != null) { break; } foreach (var quest in theme.Questions) { if ((found = quest.SearchFragment(searchText)) != null) { break; } } if (found != null) { break; } } if (found != null) { break; } } } else { } } } if (found != null) { var fileNameLocal = file.FullName; var foundLocal = found; Task.Factory.StartNew(() => { lock (_searchSync) { if (token.IsCancellationRequested) { return; } SearchResults.Add(new SearchResult { FileName = fileNameLocal, Fragment = foundLocal }); } }, CancellationToken.None, TaskCreationOptions.None, UI.Scheduler); } } catch { } finally { done++; if (level == 0) { lock (_searchSync) { if (!token.IsCancellationRequested) { SearchProgress = 100 * done / total; } } } } } if (subfoldersSearch) { foreach (var dir in folders) { SearchInDirectory(dir, searchText, subfoldersSearch, token, level + 1); done++; if (level == 0) { lock (_searchSync) { if (token.IsCancellationRequested) { return; } SearchProgress = 100 * done / total; } } } } }
public static bool IsInsideCommentOrString(SearchMatch match, ScintillaControl sci, bool includeComments, bool includeStrings) { int style = sci.BaseStyleAt(match.Index); return(includeComments && IsCommentStyle(style) || includeStrings && IsStringStyle(style)); }
public SearchMatch GetMatch(int start) { if (string.IsNullOrEmpty(_input)) return null; if (_list == null || GetItemCountValue() <= 0) return null; //(re)build regex if (_regex == null) UpdateRegEx(); //find first match in [start,END] int index = -1; Match match = null; for (index = start; index < GetItemCountValue(); index++) { match = _regex.Match(GetItemSearchPropertyValue(index)); if (match.Success) break; } //find math in [BEGIN,start[ if (match == null || !match.Success) { for (index = 0; index < start; index++) { match = _regex.Match(GetItemSearchPropertyValue(index)); if (match.Success) break; } } //process result SearchMatch searchmatch = null; if (match != null && match.Success) { searchmatch = new SearchMatch(); searchmatch._text = match.Groups[0].Value; searchmatch._index = index; searchmatch._start = match.Groups[0].Index; searchmatch._length = match.Groups[0].Length; } return searchmatch; }
public bool Execute(JHSNetworkMessage netMsg) { if (DbManager == null) { DbManager = AccountManager.Instance; } if (matchQueue == null) { matchQueue = PlayerQueueManager.Instance; } SearchMatch packet = netMsg.ReadMessage <SearchMatch>(); if (packet != null) { uint connectionId = netMsg.conn.connectionId; AccountOBJ user = DbManager.GetOnlineByConnectionId(connectionId); if (user != null) { switch (packet.op) { case SearchMatchOperations.Search: if (user.InQueue) { netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch() { op = SearchMatchOperations.NO_ERROR_SEARCHING }); return(true); } CharacterOBJ player = user.GetPlayer(packet.value); if (player != null) { lock (user) { user.SelectedCharacer = player.PlayerId; user.InQueue = true; user.ResetNotification(); matchQueue.AddPlayer(new MatchPlayer() { League = user.League, userId = user.Id, ConnectionId = connectionId, PlayerId = player.PlayerId }); netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch() { op = SearchMatchOperations.SEARCHING_INIT, value = (uint)matchQueue.AvregeWaitTime() }); } } else { netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch() { op = SearchMatchOperations.ERR_CHARATER_NOT_THERE }); } break; case SearchMatchOperations.Cancel: lock (user) { user.SelectedCharacer = 0; user.InQueue = false; netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch() { op = SearchMatchOperations.Cancel }); } break; case SearchMatchOperations.CHECK_START: matchQueue.CheckStart(); break; } } else { netMsg.conn.Send(NetworkConstants.START_SEARCH_MATCH, new SearchMatch() { op = SearchMatchOperations.ERR_ACCOUNT_NOT_FOUND }); } } return(true); }