Esempio n. 1
0
            public int Compare(KeyValuePair <int, string> xpair, KeyValuePair <int, string> ypair)
            {
                string x = xpair.Value;
                string y = ypair.Value;

                int[] xMatches = matcher.GetMatch(x) ?? new int[0];
                int[] yMatches = matcher.GetMatch(y) ?? new int[0];
                if (xMatches.Length < yMatches.Length)
                {
                    return(1);
                }
                if (xMatches.Length > yMatches.Length)
                {
                    return(-1);
                }

                int xExact = 0;
                int yExact = 0;

                for (int i = 0; i < filterWord.Length; i++)
                {
                    if (i < xMatches.Length && filterWord[i] == x[xMatches[i]])
                    {
                        xExact++;
                    }
                    if (i < yMatches.Length && filterWord[i] == y[yMatches[i]])
                    {
                        yExact++;
                    }
                }

                if (xExact < yExact)
                {
                    return(1);
                }
                if (xExact > yExact)
                {
                    return(-1);
                }

                // favor words where the match starts sooner
                if (xMatches.Length > 0 && yMatches.Length > 0 && xMatches[0] != yMatches[0])
                {
                    return(xMatches[0].CompareTo(yMatches[0]));
                }

                int xIndex = xpair.Key;
                int yIndex = ypair.Key;

                if (x.Length == y.Length)
                {
                    return(xIndex.CompareTo(yIndex));
                }

                return(x.Length.CompareTo(y.Length));
            }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public void ShouldNotMatch()
        {
            StringMatcher matcher;
            Match         match;

            matcher = new StringMatcher();
            matcher.Add("bcd");
            Assert.AreEqual(false, matcher.Match("abc"));
            match = matcher.GetMatch("abc");
            Assert.AreEqual(null, match);
        }
Esempio n. 4
0
        public void ShouldMatch()
        {
            StringMatcher matcher;
            Match         match;

            matcher = new StringMatcher();
            matcher.Add("abc");
            Assert.AreEqual(true, matcher.Match("abc"));
            match = matcher.GetMatch("abc");
            Assert.AreEqual(true, match.Success);
            Assert.AreEqual("abc", match.Value);
        }
Esempio n. 5
0
        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);
                }
            }
        }
        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");
                }
            }
        }