Exemple #1
0
        /// <summary>
        /// This is the only method that does more than just calling the delegate functions
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider,
                                         object value)
        {
            if (delegateEditor == null)
            {
                return(value);
            }
            object retval;

            //tricky: Avoid passing VALUE_UNDEFINED to the delegateEditor (can lead to exception)
            // => map to null, if null is returned, we know that we canceled the editor
            // if OTOH, NULL_VALUE_SELECTED is set, we know that the button has been clicked.
            //this is really evil, but since we cannot override delegateEditor's EditValue
            //in a generic way, we use this work  around
            //todo: find a better solution!
            //todo: control this via editor attribute
            if (value == OptionItem.VALUE_UNDEFINED)
            {
                retval = delegateEditor.EditValue(context, provider, null);
                if (retval == null)
                {
                    //editing has been canceled
                    retval = OptionItem.VALUE_UNDEFINED;
                }
            }
            else
            {
                retval = delegateEditor.EditValue(context, provider, value);
            }
            return(retval);
        }
Exemple #2
0
        public void DefaultValues()
        {
            Assert.AreSame(graphics, editor.EditValue(null, graphics), "EditValue(2)");
            Assert.AreSame(graphics, editor.EditValue(null, null, graphics), "EditValue(3)");

            Assert.AreEqual(UITypeEditorEditStyle.None, editor.GetEditStyle(), "GetEditStyle()");
            Assert.AreEqual(UITypeEditorEditStyle.None, editor.GetEditStyle(null), "GetEditStyle(null)");

            Assert.IsFalse(editor.GetPaintValueSupported(), "GetPaintValueSupported()");
            Assert.IsFalse(editor.GetPaintValueSupported(null), "GetPaintValueSupported(null)");
            Assert.IsFalse(editor.IsDropDownResizable, "IsDropDownResizable");
        }
 protected override void OnDoubleClick(EventArgs e)
 {
     if (uieditor != null)
     {
         Value = uieditor.EditValue(this, Value);
     }
     else
     {
         editor.Visible = true;
         editor.Focus();
     }
     Invalidate();
     base.OnDoubleClick(e);
 }
Exemple #4
0
        //===========================================================================
        #region ** private members

        private void DoDropDown()
        {
            // fire event as usual
            base.OnDropDown(EventArgs.Empty);

            // if this is a popup, hide editing area
            if (_editor.GetEditStyle() == UITypeEditorEditStyle.Modal)
            {
                Bounds = Rectangle.Empty;
            }

            // show editor and get the new value
            _dropped = true;
            _value   = _editor.EditValue((IServiceProvider)this, _value);

            // force the drop down to close
            DrawMode = DrawMode.Normal;
            DrawMode = DrawMode.OwnerDrawFixed;
            if (!IsDisposed)
            {
                DroppedDown = false;
            }
            Capture = false;

            // fire OnLeave so grid knows we're done
            base.OnLeave(EventArgs.Empty);
        }
        /// <include file='doc\ImageCollectionEditor.uex' path='docs/doc[@for="ImageCollectionEditor.CreateInstance"]/*' />
        /// <devdoc>
        ///    <para>Creates an instance of the specified type in the collection.</para>
        /// </devdoc>
        protected override object CreateInstance(Type type)
        {
            UITypeEditor editor = (UITypeEditor)TypeDescriptor.GetEditor(typeof(Image), typeof(UITypeEditor));
            Image        image  = (Image)editor.EditValue(this.Context, null);

            return(image);
        }
        /// <summary>
        /// Invokes the editor for the items of the designed ImageListView.
        /// </summary>
        public void EditItems()
        {
            // IComponentChangeService is used to pass change notifications to the designer
            IComponentChangeService ccs = (IComponentChangeService)GetService(typeof(IComponentChangeService));

            // Get the collection editor
            itemProperty = GetPropertyByName("Items");
            UITypeEditor editor = (UITypeEditor)itemProperty.GetEditor(typeof(UITypeEditor));
            object       value  = imageListView.Items;

            // Notify the designers of the change
            if (ccs != null)
            {
                ccs.OnComponentChanging(imageListView, itemProperty);
            }

            // Edit the value
            value = editor.EditValue(this, this, value);
            imageListView.Items = (ImageListView.ImageListViewItemCollection)value;

            // Notify the designers of the change
            if (ccs != null)
            {
                ccs.OnComponentChanged(imageListView, itemProperty, null, null);
            }

            designerService.Refresh(Component);
        }
        public static object EditValue(ComponentDesigner designer, object objectToChange, string propName)
        {
            // Get PropertyDescriptor
            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(objectToChange)[propName];
            // Create a Context
            EditorServiceContext context = new EditorServiceContext(designer, descriptor);
            // Get Editor
            UITypeEditor editor = descriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
            // Get value to edit
            object value = descriptor.GetValue(objectToChange);
            // Edit value
            object newValue = editor.EditValue(context, context, value);

            if (newValue != value)
            {
                try
                {
                    descriptor.SetValue(objectToChange, newValue);
                }
                catch (CheckoutException)
                {
                }
            }
            return(newValue);
        }
Exemple #8
0
            protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
            {
                Point cellLocation = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location;

                cellLocation.Offset(e.Location);
                if (buttonBounds.Contains(cellLocation))
                {
                    UITypeEditor editor = OwningDesignerColumn.GetBoundPropertyEditor();
                    if (editor != null && editor.GetEditStyle() == UITypeEditorEditStyle.Modal)
                    {
                        ITypeDescriptorContext context = new TypeDescriptorContext(DataGridView.Site, OwningDesignerColumn.GetBoundProperty(), this);
                        object value = GetValue(e.RowIndex);
                        value = editor.EditValue(context, DataGridView.Site, value);
                        SetValue(e.RowIndex, value);
                    }

                    // Notify the grid the cell was modified
                    DataGridView.NotifyCurrentCellDirty(true);
                    DataGridView.NotifyCurrentCellDirty(false);
                }
                else
                {
                    base.OnMouseClick(e);
                }
            }
Exemple #9
0
 /// <summary>
 /// 编辑数据
 /// </summary>
 /// <param name="context">参数</param>
 /// <param name="provider">参数</param>
 /// <param name="value">旧数据</param>
 /// <returns>编辑后的新数据</returns>
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (editor != null)
     {
         XColorValue xc       = value as XColorValue;
         Color       oldColor = xc == null ? Color.Empty : xc.Value;
         Color       newColor = (Color)editor.EditValue(context, provider, oldColor);
         if (oldColor.Equals(newColor) == false)
         {
             return(new XColorValue(newColor));
         }
         else
         {
             return(value);
         }
     }
     else
     {
         using (ColorDialog dlg = new ColorDialog())
         {
             XColorValue xc = value as XColorValue;
             if (xc != null)
             {
                 dlg.Color = xc.Value;
                 if (dlg.ShowDialog() == DialogResult.OK)
                 {
                     return(new XColorValue(dlg.Color));
                 }
             }
         }
     }
     return(value);
 }
Exemple #10
0
            /// <summary>
            /// </summary>
            /// <param name="owner">form owner for the UI Dialog</param>
            /// <param name="component">the class instance to edit</param>
            /// <param name="propertyName">property name to edit (must have the Editor attribute)</param>
            /// <remarks></remarks>
            public static void ShowEditor(IWin32Window owner, object component, string propertyName)
            {
                PropertyDescriptor property = TypeDescriptor.GetProperties(RuntimeHelpers.GetObjectValue(component))[propertyName];

                if (property == null)
                {
                    throw new ArgumentException(nameof(propertyName));
                }
                UITypeEditor editor = (UITypeEditor)property.GetEditor(typeof(UITypeEditor));

                if (editor == null)
                {
                    throw new NotImplementedException("Unsupported UIEditor Type");
                }
                if (!(editor.GetType().IsSubclassOf(typeof(EnhancedCollectionEditor)) | editor.GetType().IsSubclassOf(typeof(CollectionEditor))))
                {
                    throw new NotImplementedException("Unsupported UIEditor Type");
                }
                RunTimeUIEdTools.RunTimeTypeEdit runTimeTypeEdit = new RunTimeUIEdTools.RunTimeTypeEdit(owner, RuntimeHelpers.GetObjectValue(component), property);
                object objectValue1 = RuntimeHelpers.GetObjectValue(property.GetValue(RuntimeHelpers.GetObjectValue(component)));
                object objectValue2 = RuntimeHelpers.GetObjectValue(editor.EditValue((ITypeDescriptorContext)runTimeTypeEdit, (IServiceProvider)runTimeTypeEdit, RuntimeHelpers.GetObjectValue(objectValue1)));

                if (property.IsReadOnly)
                {
                    return;
                }
                property.SetValue(RuntimeHelpers.GetObjectValue(component), RuntimeHelpers.GetObjectValue(objectValue2));
            }
Exemple #11
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            UITypeEditor editor = (UITypeEditor)context.PropertyDescriptor.GetEditor(typeof(UITypeEditor));
            EditorRuntimeServiceProvider serviceProvider = new EditorRuntimeServiceProvider(context);

            return(editor.EditValue(serviceProvider, serviceProvider, value));
        }
        /// <summary>
        /// Execute the Editor for the property with the given name
        /// </summary>
        /// <param name="propertyName">The name for the property to be edited</param>
        public void ExecuteUiEditor(string propertyName)
        {
            GridItem item = getGridItem(propertyName);

            if (item == null)
            {
                // error: Failed to find the property
                Console.WriteLine("Failed to find the property in the PropertyGrid:" + propertyName);
                throw new Exception("Failed to find the property in the PropertyGrid:" + propertyName);
            }
            else
            {
                // set the property as the selected grid item
                propertyGrid.SelectedGridItem = item;

                // get the selected item and object of the property grid
                GridItem selectedItem   = propertyGrid.SelectedGridItem;
                object   selectedObject = SelectedObject;

                // get the property in the selected item
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(SelectedObject);
                PropertyDescriptor           property   = properties[propertyName];

                // call the editor of the selected item
                UITypeEditor editor   = (UITypeEditor)selectedItem.PropertyDescriptor.GetEditor(typeof(UITypeEditor));
                object       newValue = editor.EditValue((ITypeDescriptorContext)selectedItem, (IServiceProvider)selectedItem, selectedItem.Value);

                // set the proprty to the new value returned by the editor
                property.SetValue(selectedObject, newValue);
            }
        }
        private bool EditRoleGroupsChangeCallback(object context)
        {
            PropertyDescriptor propDesc = (PropertyDescriptor)context;
            IDesignerHost      service  = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            UITypeEditor       editor   = (UITypeEditor)propDesc.GetEditor(typeof(UITypeEditor));

            return(editor.EditValue(new System.Web.UI.Design.WebControls.TypeDescriptorContext(service, propDesc, base.Component), new WindowsFormsEditorServiceHelper(this), propDesc.GetValue(base.Component)) != null);
        }
Exemple #14
0
        public void InvokeTemplateDialog()
        {
            PropertyDescriptor   prop    = TypeDescriptor.GetProperties(this.Component)["Workbook"];
            UITypeEditor         editor  = prop.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
            EditorServiceContext context = new EditorServiceContext(designer, prop);

            editor.EditValue(context, prop.GetValue(this.Component));
        }
            public override object EditValue(ITypeDescriptorContext context,
                                             IServiceProvider provider,
                                             object value)
            {
                ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance);

                return(uiTypeEditor.EditValue(wrappedContext, provider, value));
            }
        // Method that is target of a DesignerActionMethodItem.
        // It calls the string collection editor.
        public void EditNames()
        {
            PropertyDescriptor     itemsPropertyDescriptor = GetPropertyByName("Items");
            TypeDescriptionContext context = new TypeDescriptionContext(linkedControl, itemsPropertyDescriptor);
            UITypeEditor           editor  = (UITypeEditor)itemsPropertyDescriptor.GetEditor(typeof(UITypeEditor));

            itemsPropertyDescriptor.SetValue(linkedControl, editor.EditValue(context, context, linkedControl.Items));
        }
            protected override void OnDoubleClick(EventArgs e)
            {
                base.OnDoubleClick(e);

                UITypeEditor imageEditor = (UITypeEditor)TypeDescriptor.GetEditor(typeof(Image), typeof(UITypeEditor));

                _serviceContext.SetInstance(this, TypeDescriptor.GetProperties(this)["Image"]);
                this.Image = imageEditor.EditValue(_serviceContext, _serviceContext, this.Image) as Image;
            }
Exemple #18
0
        private void EditVideoMap(VideoMap map)
        {
            PropertyDescriptor     pd              = TypeDescriptor.GetProperties(map)["Lines"];
            UITypeEditor           editor          = (UITypeEditor)pd.GetEditor(typeof(UITypeEditor));
            RuntimeServiceProvider serviceProvider = new RuntimeServiceProvider();

            editor.EditValue(serviceProvider, serviceProvider, map.Lines);
            LoadListBox();
        }
Exemple #19
0
        private void OpenDropDownEditor()
        {
            if (m_isEditing)
            {
                return;
            }
            try
            {
                m_isEditing = true;
                object oldValue, value;
                var    oldContext = m_context;

                // Alan Beckus: save references to all the required objects to perform the transaction.
                // Because EditValue(...) enters modal loop using Application.DonEvent()
                // consequently selectedObjects, transaction and event m_context itself can change
                // before returning from EditValue(...).
                // note: previous attempt to solve this issue was to cache selected objects inside
                //       m_context but it failed to solve the issue because the cache was cleared
                //       by PropertyView before it can be used.
                List <object> selection          = new List <object>(m_context.SelectedObjects);
                var           transactionContext = m_context.TransactionContext;
                var           descriptor         = m_context.Descriptor;
                oldValue = m_context.GetValue();

                UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(m_descriptor, this);

                // Bring up the editor which can cause Bind() to be called, so make sure that we use the
                //  correct context and selection after this EditValue call.
                value = editor.EditValue(this, this, oldValue);


                transactionContext.DoTransaction(delegate
                {
                    foreach (object selectedObject in selection)
                    {
                        PropertyUtils.SetProperty(selectedObject, descriptor, value);
                    }
                }, string.Format("Edit: {0}".Localize(), descriptor.DisplayName));


                // notify that we just changed a value
                NotifyPropertyEdit(oldValue, value);

                // Refresh text box, paint rect
                if (oldContext == m_context)
                {
                    SetTextBoxFromProperty();
                    EnableTextBox();
                }

                Invalidate();
            }
            finally
            {
                m_isEditing = false;
            }
        }
        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            if (context != null)
            {
                return(_parentEditor.EditValue(CreateContext(context), provider, value));
            }

            return(base.EditValue(context, provider, value));
        }
Exemple #21
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            UITypeEditor editor = lookUpEditor(context);

            if (editor != null)
            {
                return(editor.EditValue(context, provider, value));
            }

            return(base.EditValue(context, provider, value));
        }
Exemple #22
0
        internal static T EditValue <T>(this UITypeEditor editor, T value) where T : class
        {
            var    runtimeServiceProvider = new RuntimeUIServiceProvider();
            object obj = editor.EditValue(runtimeServiceProvider, runtimeServiceProvider, value);

            if (typeof(T) == typeof(string))
            {
                return(obj?.ToString() as T);
            }
            return((T)obj);
        }
Exemple #23
0
        /// <summary>
        /// Invokes the editor for the columns of the designed ImageListView.
        /// </summary>
        public void EditColumns()
        {
            // TODO: Column editing cannot be undone in the designer.
            property = TypeDescriptor.GetProperties(imageListView)["Columns"];
            UITypeEditor editor = (UITypeEditor)property.GetEditor(typeof(UITypeEditor));
            object       value  = imageListView.Columns;// property.GetValue(imageListView);

            value = editor.EditValue(this, this, value);
            SetProperty("Columns", value);
            designerService.Refresh(Component);
        }
Exemple #24
0
        private void OnEditSharedEditors(object sender, EventArgs e)
        {
            PropertyDescriptor propdef = TypeDescriptor.GetProperties(Control)["RowTemplateList"];

            if (propdef == null)
            {
                return;
            }

            UITypeEditor           editor          = (UITypeEditor)propdef.GetEditor(typeof(UITypeEditor));
            RuntimeServiceProvider serviceProvider =
                new RuntimeServiceProvider(this.Control, this.Component, propdef);

            editor.EditValue(serviceProvider, serviceProvider, propdef.GetValue(this.Control));
        }
Exemple #25
0
 public static void EditValue(IWin32Window owner, object component, string propertyName)
 {
     PropertyDescriptor prop = TypeDescriptor.GetProperties(component)[propertyName];
     if (prop == null) throw new ArgumentException("propertyName");
     UITypeEditor editor = (UITypeEditor)prop.GetEditor(typeof(UITypeEditor));
     MyHelper ctx = new MyHelper(owner, component, prop);
     if (editor != null && editor.GetEditStyle(ctx) == UITypeEditorEditStyle.Modal)
     {
         object value = prop.GetValue(component);
         value = editor.EditValue(ctx, ctx, value);
         if (!prop.IsReadOnly)
         {
             prop.SetValue(component, value);
         }
     }
 }
Exemple #26
0
        private void OpenDropDownEditor()
        {
            try
            {
                m_isEditing = true;

                PropertyEditorControlContext oldContext = m_context;
                object oldValue, value;
                try
                {
                    // Certain property editing controls like the FlagsUITypeEditor's private CheckedListBox will
                    //  not lose focus until the user clicks away, and the user's click may change the
                    //  PropertyEditorControlContext's selection, so let's temporarily freeze the selection.
                    oldContext.CacheSelection();

                    oldValue = m_context.GetValue();
                    UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(m_descriptor, this);

                    // Bring up the editor which can cause Bind() to be called, so make sure that we use the
                    //  correct context and selection after this EditValue call.
                    value = editor.EditValue(this, this, oldValue);

                    oldContext.SetValue(value);
                }
                finally
                {
                    oldContext.ClearCachedSelection();
                }

                // notify that we just changed a value
                NotifyPropertyEdit(oldValue, value);

                // Refresh text box, paint rect
                if (oldContext == m_context)
                {
                    SetTextBoxFromProperty();
                    EnableTextBox();
                }

                Invalidate();
            }
            finally
            {
                m_isEditing = false;
            }
        }
Exemple #27
0
        public static object EditValue(ComponentDesigner designer, object objectToChange, string propName)
        {
            PropertyDescriptor   prop    = TypeDescriptor.GetProperties(objectToChange)[propName];
            EditorServiceContext context = new EditorServiceContext(designer, prop);
            UITypeEditor         editor  = prop.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
            object obj2 = prop.GetValue(objectToChange);
            object obj3 = editor.EditValue(context, context, obj2);

            if (obj3 != obj2)
            {
                try {
                    prop.SetValue(objectToChange, obj3);
                }
                catch (CheckoutException) {
                }
            }
            return(obj3);
        }
Exemple #28
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            UITypeEditor  editor    = this.GetActualEditor(context);
            TypeConverter converter = this.actualConverter;

            if (editor == null || converter == null)
            {
                return(value);
            }

            if (currProperty == null)
            {
                return(value);
            }


            object convertedValue;

            if (value == null || value.GetType() != currProperty.PropertyType)
            {
                if (currProperty.PropertyType.IsValueType)
                {
                    convertedValue = Activator.CreateInstance(currProperty.PropertyType);
                }
                else
                {
                    convertedValue = null;
                }
            }
            else
            {
                convertedValue = converter.ConvertFrom(value);
            }

            object res = value;

            if (editor != null)
            {
                res = editor.EditValue(provider, convertedValue);
                res = converter.ConvertTo(res, typeof(string));
            }

            return(res);
        }
        public Image OpenImageCollection()
        {
            object obj2 = this._propertyDescriptor.GetValue(this._component);

            if (this._propertyDescriptor != null)
            {
                Image        image  = null;
                UITypeEditor editor = this._propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (editor != null)
                {
                    image = (Image)editor.EditValue(this, this, obj2);
                }
                if (image != null)
                {
                    return(image);
                }
            }
            return((Image)obj2);
        }
Exemple #30
0
        /// <summary>
        /// Show the dialog
        /// </summary>
        public override void ShowDialog()
        {
            try
            {
                OnDialogOpen(EventArgs.Empty);
                if (uiTypeEditor != null)
                {
                    UITypeEditorEditStyle l_Style = uiTypeEditor.GetEditStyle();
                    if (l_Style == UITypeEditorEditStyle.DropDown ||
                        l_Style == UITypeEditorEditStyle.Modal)
                    {
                        object l_EditObject;
                        try
                        {
                            l_EditObject = Value;
                        }
                        catch
                        {
                            if (Validator != null)
                            {
                                l_EditObject = Validator.DefaultValue;
                            }
                            else
                            {
                                l_EditObject = null;
                            }
                        }

                        object tmp = uiTypeEditor.EditValue(this, l_EditObject);
                        Value = tmp;
                    }
                }

                OnDialogClosed(EventArgs.Empty);
            }
            catch (Exception ex)
            {
                LoggerManager.Log(LogLevels.Error, "Unexpected exception: " + ex.ToString());
                MessageBox.Show(ex.Message, Application.ProductName + " build " + Application.ProductVersion,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }