コード例 #1
0
            // this returns an array list of the propertydescriptor arrays, one for each
            // component
            //
            private static ArrayList GetCommonProperties(object[] objs, bool presort, PropertyTab tab, GridEntry parentEntry)
            {
                PropertyDescriptorCollection[] propCollections = new PropertyDescriptorCollection[objs.Length];

                Attribute[] attrs = new Attribute[parentEntry.BrowsableAttributes.Count];
                parentEntry.BrowsableAttributes.CopyTo(attrs, 0);

                for (int i = 0; i < objs.Length; i++)
                {
                    PropertyDescriptorCollection pdc = tab.GetProperties(parentEntry, objs[i], attrs);
                    if (presort)
                    {
                        pdc = pdc.Sort(PropertyComparer);
                    }
                    propCollections[i] = pdc;
                }

                ArrayList mergedList = new ArrayList();

                PropertyDescriptor[] matchArray = new PropertyDescriptor[objs.Length];

                //
                // Merge the property descriptors
                //
                int[] posArray = new int[propCollections.Length];
                for (int i = 0; i < propCollections[0].Count; i++)
                {
                    PropertyDescriptor pivotDesc = propCollections[0][i];

                    bool match = pivotDesc.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute();

                    for (int j = 1; match && j < propCollections.Length; j++)
                    {
                        if (posArray[j] >= propCollections[j].Count)
                        {
                            match = false;
                            break;
                        }

                        // check to see if we're on a match
                        //
                        PropertyDescriptor jProp = propCollections[j][posArray[j]];
                        if (pivotDesc.Equals(jProp))
                        {
                            posArray[j] += 1;

                            if (!jProp.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                            {
                                match = false;
                                break;
                            }
                            matchArray[j] = jProp;
                            continue;
                        }

                        int jPos = posArray[j];
                        jProp = propCollections[j][jPos];

                        match = false;

                        // if we aren't on a match, check all the items until we're past
                        // where the matching item would be
                        while (PropertyComparer.Compare(jProp, pivotDesc) <= 0)
                        {
                            // got a match!
                            if (pivotDesc.Equals(jProp))
                            {
                                if (!jProp.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                                {
                                    match = false;
                                    jPos++;
                                }
                                else
                                {
                                    match         = true;
                                    matchArray[j] = jProp;
                                    posArray[j]   = jPos + 1;
                                }
                                break;
                            }

                            // try again
                            jPos++;
                            if (jPos < propCollections[j].Count)
                            {
                                jProp = propCollections[j][jPos];
                            }
                            else
                            {
                                break;
                            }
                        }

                        // if we got here, there is no match, quit for this guy
                        if (!match)
                        {
                            posArray[j] = jPos;
                            break;
                        }
                    }

                    // do we have a match?
                    if (match)
                    {
                        matchArray[0] = pivotDesc;
                        mergedList.Add(matchArray.Clone());
                    }
                }

                return(mergedList);
            }
コード例 #2
0
            private static ArrayList GetCommonProperties(object[] objects, bool presort, PropertyTab tab, GridEntry parentEntry)
            {
                var propertyCollections = new PropertyDescriptorCollection[objects.Length];
                var attributes          = new Attribute[parentEntry.BrowsableAttributes.Count];

                parentEntry.BrowsableAttributes.CopyTo(attributes, 0);

                for (int i = 0; i < objects.Length; i++)
                {
                    var properties = tab.GetProperties(parentEntry, objects[i], attributes);
                    if (presort)
                    {
                        properties = properties.Sort(s_propertyComparer);
                    }

                    propertyCollections[i] = properties;
                }

                ArrayList mergedList = new();
                var       matchArray = new PropertyDescriptor[objects.Length];

                //
                // Merge the property descriptors
                //

                int[] positions = new int[propertyCollections.Length];
                for (int i = 0; i < propertyCollections[0].Count; i++)
                {
                    PropertyDescriptor pivotProperty = propertyCollections[0][i];

                    bool match = pivotProperty.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute();

                    for (int j = 1; match && j < propertyCollections.Length; j++)
                    {
                        if (positions[j] >= propertyCollections[j].Count)
                        {
                            match = false;
                            break;
                        }

                        // Check to see if we're on a match.
                        PropertyDescriptor property = propertyCollections[j][positions[j]];
                        if (pivotProperty.Equals(property))
                        {
                            positions[j] += 1;

                            if (!property.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                            {
                                match = false;
                                break;
                            }

                            matchArray[j] = property;
                            continue;
                        }

                        int position = positions[j];
                        property = propertyCollections[j][position];

                        match = false;

                        // If we aren't on a match, check all the items until we're past where the matching item would be.
                        while (s_propertyComparer.Compare(property, pivotProperty) <= 0)
                        {
                            // Got a match!
                            if (pivotProperty.Equals(property))
                            {
                                if (!property.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                                {
                                    match = false;
                                    position++;
                                }
                                else
                                {
                                    match         = true;
                                    matchArray[j] = property;
                                    positions[j]  = position + 1;
                                }

                                break;
                            }

                            // Try again.
                            position++;
                            if (position < propertyCollections[j].Count)
                            {
                                property = propertyCollections[j][position];
                            }
                            else
                            {
                                break;
                            }
                        }

                        // If we got here, there is no match, quit for this one.
                        if (!match)
                        {
                            positions[j] = position;
                            break;
                        }
                    }

                    // Do we have a match?
                    if (match)
                    {
                        matchArray[0] = pivotProperty;
                        mergedList.Add(matchArray.Clone());
                    }
                }

                return(mergedList);
            }
コード例 #3
0
ファイル: PropertyGrid.cs プロジェクト: deck05/aspeditor
        private void Populate()
        {
            bool categorised = PropertySort == System.Windows.Forms.PropertySort.Categorized;

            if (currentObject != null)
            {
                properties = selectedTab.GetProperties(currentObject);
            }
            else
            {
                properties = new PropertyDescriptorCollection(new PropertyDescriptor[0] {
                });
            }

            //kill existing table
            if (expanderBox != null)
            {
                expanderBox.Destroy();
                expanderBox = null;
            }
            Rows.Clear();

            //transcribe browsable properties
            ArrayList sorted = new ArrayList();

            foreach (PropertyDescriptor descriptor in properties)
            {
                if (descriptor.IsBrowsable)
                {
                    sorted.Add(descriptor);
                }
            }

            //expands to fill empty space
            EventBox bottomWidget = new EventBox();

            bottomWidget.ModifyBg(StateType.Normal, new Gdk.Color(0xff, 0xff, 0xff));
            bottomWidget.CanFocus          = true;
            bottomWidget.ButtonPressEvent += on_bottomWidget_ButtonPressEvent;
            expanderBox = new VBox();


            //how are we displaying it?
            if (!categorised)
            {
                sorted.Sort(new SortByName());
                table = BuildTable(sorted);
                expanderBox.PackStart(table, false, false, 0);
            }
            else
            {
                sorted.Sort(new SortByCat());

                ArrayList tabList  = new ArrayList();
                string    oldCat   = "";
                int       oldIndex = 0;
                Expander  catHead  = null;

                for (int i = 0; i < sorted.Count; i++)
                {
                    PropertyDescriptor pd = (PropertyDescriptor)sorted[i];

                    //Create category header
                    if (pd.Category != oldCat)
                    {
                        if (catHead != null)
                        {
                            Table t = BuildTable(sorted.GetRange(oldIndex, i - oldIndex));
                            catHead.Add(t);
                        }

                        catHead = new Expander("<b>" + pd.Category + "</b>");
                        ((Label)catHead.LabelWidget).UseMarkup = true;
                        catHead.Expanded = true;
                        expanderBox.PackStart(catHead, false, false, 0);

                        oldCat   = pd.Category;
                        oldIndex = i;
                    }
                }

                if (catHead != null)
                {
                    Table t = BuildTable(sorted.GetRange(oldIndex, sorted.Count - oldIndex));
                    catHead.Add(t);
                }

                //TODO: Find better way of getting all tables same size, maybe resizable
                int maxwidth = 1;
                foreach (GridRow pgr in Rows)
                {
                    int width = pgr.propertyNameLabel.SizeRequest().Width;
                    if (width > maxwidth)
                    {
                        maxwidth = width;
                    }
                }
                foreach (GridRow pgr in Rows)
                {
                    pgr.propertyNameLabel.WidthRequest = maxwidth;
                }
            }

            expanderBox.PackStart(bottomWidget, true, true, 1);
            scrolledWindow.AddWithViewport(expanderBox);
            expanderBox.ShowAll();
        }
コード例 #4
0
            private static ArrayList GetCommonProperties(object[] objs, bool presort, PropertyTab tab, GridEntry parentEntry)
            {
                PropertyDescriptorCollection[] descriptorsArray = new PropertyDescriptorCollection[objs.Length];
                Attribute[] array = new Attribute[parentEntry.BrowsableAttributes.Count];
                parentEntry.BrowsableAttributes.CopyTo(array, 0);
                for (int i = 0; i < objs.Length; i++)
                {
                    PropertyDescriptorCollection descriptors = tab.GetProperties(parentEntry, objs[i], array);
                    if (presort)
                    {
                        descriptors = descriptors.Sort(MultiSelectRootGridEntry.PropertyComparer);
                    }
                    descriptorsArray[i] = descriptors;
                }
                ArrayList list = new ArrayList();

                PropertyDescriptor[] descriptorArray = new PropertyDescriptor[objs.Length];
                int[] numArray = new int[descriptorsArray.Length];
                for (int j = 0; j < descriptorsArray[0].Count; j++)
                {
                    PropertyDescriptor descriptor = descriptorsArray[0][j];
                    bool flag = descriptor.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute();
                    for (int k = 1; flag && (k < descriptorsArray.Length); k++)
                    {
                        if (numArray[k] >= descriptorsArray[k].Count)
                        {
                            flag = false;
                            break;
                        }
                        PropertyDescriptor descriptor2 = descriptorsArray[k][numArray[k]];
                        if (descriptor.Equals(descriptor2))
                        {
                            numArray[k]++;
                            if (!descriptor2.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                            {
                                flag = false;
                                break;
                            }
                            descriptorArray[k] = descriptor2;
                            continue;
                        }
                        int num4 = numArray[k];
                        descriptor2 = descriptorsArray[k][num4];
                        flag        = false;
                        while (MultiSelectRootGridEntry.PropertyComparer.Compare(descriptor2, descriptor) <= 0)
                        {
                            if (descriptor.Equals(descriptor2))
                            {
                                if (!descriptor2.Attributes[typeof(MergablePropertyAttribute)].IsDefaultAttribute())
                                {
                                    flag = false;
                                    num4++;
                                }
                                else
                                {
                                    flag = true;
                                    descriptorArray[k] = descriptor2;
                                    numArray[k]        = num4 + 1;
                                }
                                break;
                            }
                            num4++;
                            if (num4 >= descriptorsArray[k].Count)
                            {
                                break;
                            }
                            descriptor2 = descriptorsArray[k][num4];
                        }
                        if (!flag)
                        {
                            numArray[k] = num4;
                            break;
                        }
                    }
                    if (flag)
                    {
                        descriptorArray[0] = descriptor;
                        list.Add(descriptorArray.Clone());
                    }
                }
                return(list);
            }