Ejemplo n.º 1
0
        private bool PropertyHitTest(int index, string text, bool system, bool display)
        {
            SystemProperty sp = tiArray[index].Item as SystemProperty;

            if ((system && sp.FullName.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) ||
                (display && sp.DisplayName != null && sp.DisplayName.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0))
            {
                searchIndex = index;
                SelectTreeProperty(tiArray[index]);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        // Top level entry point for the algorithm that builds the property name tree from an unordered sequence
        // of property names
        private TreeItem AddTreeItem(Dictionary <string, TreeItem> dict, List <TreeItem> roots, SystemProperty sp)
        {
            Debug.Assert(sp.FullName.Contains('.')); // Because the algorithm assumes that this is the case
            TreeItem ti = AddTreeItemInner(dict, roots, sp.FullName, sp.DisplayName);

            ti.Item = sp;

            return(ti);
        }
Ejemplo n.º 3
0
        public void PopulateSystemProperties()
        {
            List <SystemProperty>    systemProperties        = new List <SystemProperty>();
            IPropertyDescriptionList propertyDescriptionList = null;
            IPropertyDescription     propertyDescription     = null;
            Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList);

            try
            {
                int hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions(PropertySystemNativeMethods.PropDescEnumFilter.PDEF_ALL, ref guid, out propertyDescriptionList);
                if (hr >= 0)
                {
                    uint count;
                    propertyDescriptionList.GetCount(out count);
                    guid = new Guid(ShellIIDGuid.IPropertyDescription);

                    for (uint i = 0; i < count; i++)
                    {
                        propertyDescriptionList.GetAt(i, ref guid, out propertyDescription);

                        string propName;
                        propertyDescription.GetCanonicalName(out propName);
                        IntPtr displayNamePtr;
                        string displayName = null;
                        propertyDescription.GetDisplayName(out displayNamePtr);
                        if (displayNamePtr != IntPtr.Zero)
                        {
                            displayName = Marshal.PtrToStringAuto(displayNamePtr);
                        }
                        SystemProperty sp = new SystemProperty {
                            FullName = propName, DisplayName = displayName
                        };

                        systemProperties.Add(sp);

                        // If we ever need it:
                        // ShellPropertyDescription desc = new ShellPropertyDescription(propertyDescription);

                        if (propertyDescription != null)
                        {
                            Marshal.ReleaseComObject(propertyDescription);
                            propertyDescription = null;
                        }
                    }

                    Dictionary <string, TreeItem> dict = new Dictionary <string, TreeItem>();
                    List <TreeItem> roots = new List <TreeItem>();

                    // Build tree based on property names
                    foreach (SystemProperty sp in systemProperties)
                    {
                        AddTreeItem(dict, roots, sp);
                    }

                    // Wire trees to tree controls, tweaking the structure as we go
                    TreeItem propGroup = null;
                    foreach (TreeItem root in roots)
                    {
                        if (root.Name == "System")
                        {
                            AllProperties.Insert(0, root);

                            // Move property groups from root to their own list
                            propGroup = root.Children.Where(x => x.Name == "PropGroup").FirstOrDefault();
                            if (propGroup != null)
                            {
                                foreach (TreeItem ti in propGroup.Children)
                                {
                                    GroupProperties.Add(ti.Name);
                                }
                                root.RemoveChild(propGroup);
                            }

                            // Make remaining children of System that are parents into roots
                            List <TreeItem> movers = new List <TreeItem>(root.Children.Where(x => x.Children.Count() > 0));
                            foreach (TreeItem ti in movers)
                            {
                                root.RemoveChild(ti);
                                AllProperties.Add(ti);
                            }
                        }
                        else
                        {
                            AllProperties.Add(root);
                        }
                    }
                }
            }
            finally
            {
                if (propertyDescriptionList != null)
                {
                    Marshal.ReleaseComObject(propertyDescriptionList);
                }
                if (propertyDescription != null)
                {
                    Marshal.ReleaseComObject(propertyDescription);
                }
            }
        }