public void Reset() { store.Clear(); foreach (var asm in assemblies) { int matchRank = 0; string name, version; if (stringMatcher != null) { string txt = asm.File.FileName + " " + asm.Version; if (!stringMatcher.CalcMatchRank(txt, out matchRank)) { continue; } int[] match = stringMatcher.GetMatch(txt); name = GetMatchMarkup(treeView, asm.File.FileName, match, 0); version = GetMatchMarkup(treeView, asm.Version, match, asm.File.FileName.Length + 1); } else { name = GLib.Markup.EscapeText(asm.File.FileName); version = GLib.Markup.EscapeText(asm.Version); } store.AppendValues(name, version, asm, asm.Selected, asm.File.ToString(), MonoDevelop.Ide.Gui.Stock.OpenFolder, matchRank); } }
bool MatchName(string name, out int matchRank) { MatchResult savedMatch; if (!savedMatches.TryGetValue(name, out savedMatch)) { bool doesMatch = matcher.CalcMatchRank(name, out matchRank); savedMatches[name] = savedMatch = new MatchResult(doesMatch, matchRank); } matchRank = savedMatch.Rank; return(savedMatch.Match); }
internal SearchResult CheckType(ITypeDefinition type) { int rank; if (MatchName(type.Name, out rank)) { return new TypeSearchResult(pattern, type.Name, rank, type, false) { Ambience = ambience } } ; if (!FullSearch) { return(null); } if (MatchName(type.FullName, out rank)) { return new TypeSearchResult(pattern, type.FullName, rank, type, true) { Ambience = ambience } } ; return(null); } Dictionary <string, MatchResult> savedMatches = new Dictionary <string, MatchResult> (); bool MatchName(string name, out int matchRank) { if (name == null) { matchRank = -1; return(false); } MatchResult savedMatch; if (!savedMatches.TryGetValue(name, out savedMatch)) { bool doesMatch = matcher.CalcMatchRank(name, out matchRank); savedMatches[name] = savedMatch = new MatchResult(doesMatch, matchRank); } matchRank = savedMatch.Rank; return(savedMatch.Match); } } }
static bool MatchName(Dictionary <string, MatchResult> savedMatches, StringMatcher matcher, string name, out int matchRank) { if (name == null) { matchRank = -1; return(false); } MatchResult savedMatch; if (!savedMatches.TryGetValue(name, out savedMatch)) { bool doesMatch = matcher.CalcMatchRank(name, out matchRank); savedMatches [name] = savedMatch = new MatchResult(doesMatch, matchRank); } matchRank = savedMatch.Rank; return(savedMatch.Match); }
bool MatchName(string name, out int matchRank) { if (name == null) { matchRank = -1; return(false); } bool doesMatch; if (firstChars != null) { int idx = name.IndexOfAny(firstChars); doesMatch = idx >= 0; if (doesMatch) { matchRank = int.MaxValue - (name.Length - 1) * 10 - idx; if (name[idx] != firstChar) { matchRank /= 2; } return(true); } else { matchRank = -1; } return(false); } MatchResult savedMatch; if (!savedMatches.TryGetValue(name, out savedMatch)) { doesMatch = matcher.CalcMatchRank(name, out matchRank); savedMatches [name] = savedMatch = new MatchResult(doesMatch, matchRank); } matchRank = savedMatch.Rank; return(savedMatch.Match); }
public void Reset() { store.Clear(); bool isPcl = configureProject.IsPortableLibrary; foreach (SystemAssembly systemAssembly in targetContext.GetAssemblies(targetVersion)) { if (systemAssembly.Package.IsFrameworkPackage && (isPcl || systemAssembly.Name == "mscorlib")) { continue; } bool selected = IsSelected(ReferenceType.Package, systemAssembly.FullName, systemAssembly.Package.Name); int matchRank = 0; string name, version; if (stringMatcher != null) { string txt = systemAssembly.Name + " " + systemAssembly.Version; if (!stringMatcher.CalcMatchRank(txt, out matchRank)) { continue; } int[] match = stringMatcher.GetMatch(txt); name = GetMatchMarkup(treeView, systemAssembly.Name, match, 0); version = GetMatchMarkup(treeView, systemAssembly.Version, match, systemAssembly.Name.Length + 1); } else { name = GLib.Markup.EscapeText(systemAssembly.Name); version = GLib.Markup.EscapeText(systemAssembly.Version); } string pkg = systemAssembly.Package.GetDisplayName(); if (systemAssembly.Package.IsInternalPackage) { pkg += " " + GettextCatalog.GetString("(Provided by {0})", BrandingService.ApplicationName); } store.AppendValues(name, version, systemAssembly, selected, systemAssembly.FullName, pkg, MonoDevelop.Ide.Gui.Stock.Package, matchRank, ReferenceType.Package); } if (showAll) { Solution openSolution = configureProject.ParentSolution; if (openSolution == null) { return; } Dictionary <DotNetProject, bool> references = new Dictionary <DotNetProject, bool> (); foreach (Project projectEntry in openSolution.GetAllItems <Project>()) { if (projectEntry == configureProject) { continue; } bool selected = IsSelected(ReferenceType.Project, projectEntry.Name, ""); int matchRank = 0; string name; if (stringMatcher != null) { if (!stringMatcher.CalcMatchRank(projectEntry.Name, out matchRank)) { continue; } int[] match = stringMatcher.GetMatch(projectEntry.Name); name = GetMatchMarkup(treeView, projectEntry.Name, match, 0); } else { name = GLib.Markup.EscapeText(projectEntry.Name); } DotNetProject netProject = projectEntry as DotNetProject; if (netProject != null) { if (ProjectReferencePanel.ProjectReferencesProject(references, null, netProject, configureProject.Name)) { continue; } string reason; if (!configureProject.CanReferenceProject(netProject, out reason)) { continue; } } store.AppendValues(name, "", null, selected, projectEntry.FileName.ToString(), "", projectEntry.StockIcon, matchRank, ReferenceType.Project); } foreach (FilePath file in selectDialog.GetRecentFileReferences()) { bool selected = IsSelected(ReferenceType.Assembly, file, ""); int matchRank = 0; string fname = file.FileName; string name; string version = string.Empty; try { string sname = SystemAssemblyService.GetAssemblyName(file); var aname = SystemAssemblyService.ParseAssemblyName(sname); version = aname.Version.ToString(); } catch { continue; } if (stringMatcher != null) { if (!stringMatcher.CalcMatchRank(fname, out matchRank)) { continue; } int[] match = stringMatcher.GetMatch(fname); name = GetMatchMarkup(treeView, fname, match, 0); } else { name = GLib.Markup.EscapeText(fname); } store.AppendValues(name, version, null, selected, (string)file, GLib.Markup.EscapeText(file), MonoDevelop.Ide.Gui.Stock.OpenFolder, matchRank, ReferenceType.Assembly); } } }
protected int FindMatchedEntry(string partialWord, out bool hasMismatches) { // default - word with highest match rating in the list. hasMismatches = true; int idx = -1; StringMatcher matcher = null; if (!string.IsNullOrEmpty(partialWord)) { matcher = CompletionMatcher.CreateCompletionMatcher(partialWord); string bestWord = null; int bestRank = int.MinValue; int bestIndex = 0; int bestIndexPriority = int.MinValue; for (int i = 0; i < list.filteredItems.Count; i++) { int index = list.filteredItems [i]; var data = DataProvider.GetCompletionData(index); if (bestIndexPriority > data.PriorityGroup) { continue; } string text = data.DisplayText; int rank; if (!matcher.CalcMatchRank(text, out rank)) { continue; } if (rank > bestRank || data.PriorityGroup > bestIndexPriority) { bestWord = text; bestRank = rank; bestIndex = i; bestIndexPriority = data.PriorityGroup; } } if (bestWord != null) { idx = bestIndex; hasMismatches = false; // exact match found. if (string.Compare(bestWord, partialWord ?? "", true) == 0) { return(idx); } } } CompletionData currentData; int bestMruIndex; if (idx >= 0) { currentData = completionDataList [list.filteredItems [idx]]; bestMruIndex = cache.GetIndex(currentData); } else { bestMruIndex = int.MaxValue; currentData = null; } for (int i = 0; i < list.filteredItems.Count; i++) { var mruData = completionDataList [list.filteredItems [i]]; int curMruIndex = cache.GetIndex(mruData); if (curMruIndex == 1) { continue; } if (curMruIndex < bestMruIndex) { int r1 = 0, r2 = 0; if (currentData == null || matcher != null && matcher.CalcMatchRank(mruData.DisplayText, out r1) && matcher.CalcMatchRank(currentData.DisplayText, out r2)) { if (r1 >= r2 || PartialWord.Length <= 1) { bestMruIndex = curMruIndex; idx = i; currentData = mruData; } } } } return(idx); }
public virtual CompletionSelectionStatus FindMatchedEntry(ICompletionDataList completionDataList, MruCache cache, string partialWord, List <int> filteredItems) { // default - word with highest match rating in the list. int idx = -1; if (DefaultCompletionString != null && DefaultCompletionString.StartsWith(partialWord, StringComparison.OrdinalIgnoreCase)) { partialWord = DefaultCompletionString; } StringMatcher matcher = null; if (!string.IsNullOrEmpty(partialWord)) { matcher = CompletionMatcher.CreateCompletionMatcher(partialWord); string bestWord = null; int bestRank = int.MinValue; int bestIndex = 0; int bestIndexPriority = int.MinValue; for (int i = 0; i < filteredItems.Count; i++) { int index = filteredItems [i]; var data = completionDataList [index]; if (bestIndexPriority > data.PriorityGroup) { continue; } string text = data.DisplayText; int rank; if (!matcher.CalcMatchRank(text, out rank)) { continue; } if (rank > bestRank || data.PriorityGroup > bestIndexPriority) { bestWord = text; bestRank = rank; bestIndex = i; bestIndexPriority = data.PriorityGroup; } } if (bestWord != null) { idx = bestIndex; // exact match found. if (string.Compare(bestWord, partialWord ?? "", true) == 0) { return(new CompletionSelectionStatus(idx)); } } } CompletionData currentData; int bestMruIndex; if (idx >= 0) { currentData = completionDataList [filteredItems [idx]]; bestMruIndex = cache.GetIndex(currentData); } else { bestMruIndex = int.MaxValue; currentData = null; } for (int i = 0; i < filteredItems.Count; i++) { var mruData = completionDataList [filteredItems [i]]; int curMruIndex = cache.GetIndex(mruData); if (curMruIndex == 1) { continue; } if (curMruIndex < bestMruIndex) { int r1 = 0, r2 = 0; if (currentData == null || matcher != null && matcher.CalcMatchRank(mruData.DisplayText, out r1) && matcher.CalcMatchRank(currentData.DisplayText, out r2)) { if (r1 >= r2 || partialWord.Length == 0 || partialWord.Length == 1 && mruData.DisplayText [0] == partialWord [0]) { bestMruIndex = curMruIndex; idx = i; currentData = mruData; } } } } return(new CompletionSelectionStatus(idx)); }
void PopulateListView() { store.Clear(); Solution openSolution = configureProject.ParentSolution; if (openSolution == null) { return; } Dictionary <DotNetProject, bool> references = new Dictionary <DotNetProject, bool> (); foreach (Project projectEntry in openSolution.GetAllItems <Project>()) { if (projectEntry == configureProject) { continue; } if (projectEntry is UnknownProject) { continue; } string txt; int matchRank = 0; if (stringMatcher != null) { if (!stringMatcher.CalcMatchRank(projectEntry.Name, out matchRank)) { continue; } int[] match = stringMatcher.GetMatch(projectEntry.Name); txt = PackageReferencePanel.GetMatchMarkup(treeView, projectEntry.Name, match, 0); } else { txt = GLib.Markup.EscapeText(projectEntry.Name); } bool selected = selection.Contains(projectEntry.Name); bool allowSelecting = true; DotNetProject netProject = projectEntry as DotNetProject; if (netProject != null) { string reason; if (ProjectReferencesProject(references, null, netProject, configureProject.Name)) { txt += " " + GLib.Markup.EscapeText(GettextCatalog.GetString("(Cyclic dependencies not allowed)")); allowSelecting = false; } else if (!configureProject.CanReferenceProject(netProject, out reason)) { txt += " " + GLib.Markup.EscapeText("(" + reason + ")"); allowSelecting = false; } } var icon = ImageService.GetIcon(projectEntry.StockIcon, IconSize.Menu); if (!allowSelecting) { // Don't show unselectable projects if there is a filter if (stringMatcher != null) { continue; } icon = icon.WithAlpha(0.5); } Gtk.TreeIter it = store.AppendValues(txt, projectEntry.BaseDirectory.ToString(), projectEntry, selected, icon, allowSelecting); if (!allowSelecting) { store.SetValue(it, ColColor, "dimgrey"); } } }
internal SearchResult CheckMember(IMember member) { int rank; bool useDeclaringTypeName = member is IMethod && (((IMethod)member).IsConstructor || ((IMethod)member).IsDestructor); string memberName = useDeclaringTypeName ? member.DeclaringType.Name : member.Name; if (MatchName(memberName, out rank)) { return new MemberSearchResult(pattern, memberName, rank, member, false) { Ambience = ambience } } ; if (!FullSearch) { return(null); } memberName = useDeclaringTypeName ? member.DeclaringType.FullName : member.FullName; if (MatchName(memberName, out rank)) { return new MemberSearchResult(pattern, memberName, rank, member, true) { Ambience = ambience } } ; return(null); } Dictionary <string, MatchResult> savedMatches = new Dictionary <string, MatchResult> (); bool MatchName(string name, out int matchRank) { MatchResult savedMatch; if (!savedMatches.TryGetValue(name, out savedMatch)) { bool doesMatch = matcher.CalcMatchRank(name, out matchRank); savedMatches[name] = savedMatch = new MatchResult(doesMatch, matchRank); } matchRank = savedMatch.Rank; return(savedMatch.Match); } } IEnumerable <ProjectFile> files; IEnumerable <IMember> members { get { getMembersTimer.BeginTiming(); try { lock (members) { foreach (var type in types) { foreach (var m in type.Members) { yield return(m); } } } } finally { getMembersTimer.EndTiming(); } } } WorkerResult lastResult; void SearchWorker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; var arg = (KeyValuePair <string, WorkerResult>)e.Argument; WorkerResult lastResult = arg.Value; WorkerResult newResult = new WorkerResult(this); newResult.pattern = arg.Key; newResult.IncludeFiles = (NavigateToType & NavigateToType.Files) == NavigateToType.Files; newResult.IncludeTypes = (NavigateToType & NavigateToType.Types) == NavigateToType.Types; newResult.IncludeMembers = (NavigateToType & NavigateToType.Members) == NavigateToType.Members; var firstType = types.FirstOrDefault(); newResult.ambience = firstType != null?AmbienceService.GetAmbienceForFile(firstType.Region.FileName) : AmbienceService.DefaultAmbience; string toMatch = arg.Key; int i = toMatch.IndexOf(':'); if (i != -1) { toMatch = toMatch.Substring(0, i); newResult.isGotoFilePattern = true; } newResult.matcher = StringMatcher.GetMatcher(toMatch, false); newResult.FullSearch = useFullSearch; foreach (SearchResult result in AllResults(worker, lastResult, newResult)) { if (worker.CancellationPending) { break; } newResult.results.AddResult(result); } if (worker.CancellationPending) { e.Cancel = true; return; } newResult.results.Sort(new DataItemComparer()); e.Result = newResult; } IEnumerable <SearchResult> AllResults(BackgroundWorker worker, WorkerResult lastResult, WorkerResult newResult) { // Search files if (newResult.IncludeFiles) { newResult.filteredFiles = new List <ProjectFile> (); bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith(lastResult.pattern) && lastResult.filteredFiles != null; IEnumerable <ProjectFile> allFiles = startsWithLastFilter ? lastResult.filteredFiles : files; foreach (ProjectFile file in allFiles) { if (worker.CancellationPending) { yield break; } SearchResult curResult = newResult.CheckFile(file); if (curResult != null) { newResult.filteredFiles.Add(file); yield return(curResult); } } } if (newResult.isGotoFilePattern) { yield break; } // Search Types if (newResult.IncludeTypes) { newResult.filteredTypes = new List <ITypeDefinition> (); lock (types) { bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith(lastResult.pattern) && lastResult.filteredTypes != null; var allTypes = startsWithLastFilter ? lastResult.filteredTypes : types; foreach (var type in allTypes) { if (worker.CancellationPending) { yield break; } SearchResult curResult = newResult.CheckType(type); if (curResult != null) { newResult.filteredTypes.Add(type); yield return(curResult); } } } } // Search members if (newResult.IncludeMembers) { newResult.filteredMembers = new List <IMember> (); lock (members) { bool startsWithLastFilter = lastResult.pattern != null && newResult.pattern.StartsWith(lastResult.pattern) && lastResult.filteredMembers != null; var allMembers = startsWithLastFilter ? lastResult.filteredMembers : members; foreach (var member in allMembers) { if (worker.CancellationPending) { yield break; } SearchResult curResult = newResult.CheckMember(member); if (curResult != null) { newResult.filteredMembers.Add(member); yield return(curResult); } } } } } void WaitForCollectFiles() { if (collectFiles != null) { collectFiles.Join(); collectFiles = null; } }