Beispiel #1
0
        protected void setHTMLAttr <T>(string attrName, T newValue)
        {
            List <HTMLAttribute> attrs = GetMoreHTMLAttributesValue();
            HTMLAttribute        attr  = attrs.Find(a => string.Compare(a.AttributeName, attrName /*, true*/) == 0);

            if (attr != null)
            {
                attr.AttributeValue = newValue.ToString();
            }
            else
            {
                attrs.Add(new HTMLAttribute(attrName, newValue.ToString()));
            }
        }
        protected override CollectionForm CreateCollectionForm()
        {
            var form = base.CreateCollectionForm();

            Button orgOKBtn = form.AcceptButton as Button;

            if (orgOKBtn == null)
            {
                return(form);
            }

            // hide the original OK button
            orgOKBtn.AutoSize = false;
            orgOKBtn.Width    = 0;
            orgOKBtn.Height   = 0;
            orgOKBtn.Visible  = false;

            // create a new OK button
            Button newOKBtn = new Button()
            {
                Text = "OK"
            };

            orgOKBtn.Parent.Controls.Add(newOKBtn);
            form.AcceptButton = newOKBtn;

            newOKBtn.Click += new EventHandler((obj, arg) => {
                // validate value
                List <HTMLAttribute> newAttrList = form.EditValue as List <HTMLAttribute>;
                string errMsg = HTMLAttribute.ValidateAttributes(newAttrList);
                if (errMsg != null)
                {
                    //// show message in ErrorList window
                    //var errProvider = new Microsoft.VisualStudio.Shell.ErrorListProvider(provider);
                    //errProvider.ProviderName = "test";
                    //errProvider.ProviderGuid = new Guid();
                    //errProvider.Tasks.Add(new Microsoft.VisualStudio.Shell.Task(ex));

                    MessageBox.Show(form, errMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // perform original onclick handling
                // must make original ok button visible, otherwise PerformClick() doesn't work
                orgOKBtn.Visible = true;
                orgOKBtn.PerformClick();
            });
            return(form);
        }
Beispiel #3
0
        protected T getHTMLAttr <T>(string attrName, T defaultValue = default(T))
        {
            List <HTMLAttribute> attrs = GetMoreHTMLAttributesValue();
            HTMLAttribute        attr  = attrs.Find(a => string.Compare(a.AttributeName, attrName /*, true*/) == 0);

            if (attr != null)
            {
                System.ComponentModel.TypeConverter converter
                    = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T));
                if (converter != null)
                {
                    return((T)(converter.ConvertFromString(attr.AttributeValue)));
                }
            }

            return(defaultValue);
        }
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            List <HTMLAttribute> oldList = HTMLAttribute.CloneHTMLAttributeList((List <HTMLAttribute>)value);
            List <HTMLAttribute> newList = base.EditValue(context, provider, value) as List <HTMLAttribute>;

            // remove empty attributes
            if (newList != null)
            {
                newList.RemoveAll(attr => string.IsNullOrEmpty(attr.AttributeName));
            }

            if (HTMLAttribute.AreAttributeListsEqual(oldList, newList))
            {
                // value are not changed
                return(newList);
            }
            else
            {
                // value changed. turn on document dirty flag
                return(new List <HTMLAttribute>(newList));
            }
        }