コード例 #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider?.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    if (dropdownControl == null) //load on demand and reuse it.
                    {
                        //We want to use the same font as the properties control...
                        // edSvc container has a Font and property we need but it is of type System.Windows.Forms.PropertyGridInternal.PropertyGridView and not accessable without reflection. Arrgh!
                        var fontPI = edSvc.GetType().GetProperty("Font", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        var font   = fontPI == null ? SystemFonts.MessageBoxFont : (Font)fontPI.GetValue(edSvc);

                        dropdownControl = new EnumPanel(font);
                    }

                    dropdownControl.EnumValue = (Enum)Convert.ChangeType(value, context.PropertyDescriptor.PropertyType);
                    edSvc.DropDownControl(dropdownControl);

                    return(dropdownControl.EnumValue);
                }
            }
            return(null);
        }
コード例 #2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            iw            = context.Instance as IWithCollection;
            _propertyName = context.PropertyDescriptor.Name;
            object v = base.EditValue(context, provider, value);

            if (iw != null)
            {
                iw.OnCollectionChanged(context.PropertyDescriptor.Name);
            }
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    Type         t    = edSvc.GetType();
                    PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                    if (pif0 != null)
                    {
                        object       g  = pif0.GetValue(edSvc, null);
                        PropertyGrid pg = g as PropertyGrid;
                        if (pg != null)
                        {
                            pg.Refresh();
                        }
                    }
                }
            }
            return(v);
        }
コード例 #3
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             MethodDataTransfer mdt = context.Instance as MethodDataTransfer;
             if (mdt == null)
             {
                 IAction act = context.Instance as IAction;
                 if (act != null)
                 {
                     mdt = act.ActionMethod as MethodDataTransfer;
                 }
             }
             if (mdt != null)
             {
                 FrmObjectExplorer dlg = DesignUtil.GetPropertySelector(null, mdt.Action.ScopeMethod, null);
                 dlg.SetMultipleSelection(true);
                 dlg.ObjectSubType = EnumObjectSelectSubType.Property;
                 if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                 {
                     if (dlg.SelectedProperties != null)
                     {
                         foreach (IProperty p in dlg.SelectedProperties)
                         {
                             mdt.AddProperty(p);
                         }
                         PropertyGrid pg   = null;
                         Type         t    = edSvc.GetType();
                         PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                         if (pif0 != null)
                         {
                             object g = pif0.GetValue(edSvc, null);
                             pg = g as PropertyGrid;
                         }
                         if (pg != null && pg.SelectedGridItem != null)
                         {
                             pg.SelectedGridItem.Expanded = true;
                         }
                         mdt.OnChanged();
                         return(true);
                     }
                 }
             }
         }
     }
     return(string.Empty);
 }
コード例 #4
0
        private void RefreshPropertyGrid()
        {
            if (_editorService == null)
            {
                return;
            }
            object pg = _editorService.GetType().InvokeMember("OwnerGrid", BindingFlags.GetProperty,
                                                              null, _editorService, null);

            if (pg is PropertyGrid)
            {
                (pg as PropertyGrid).Refresh();
            }
        }
コード例 #5
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (service != null)
         {
             DrawingItem item = context.Instance as DrawingItem;
             if (item == null)
             {
                 IDrawDesignControl dc = context.Instance as IDrawDesignControl;
                 if (dc != null)
                 {
                     item = dc.Item;
                 }
             }
             if (item != null && item.Page != null)
             {
                 ListBox list = new ListBox();
                 foreach (DrawingLayer l in item.Page.DrawingLayers)
                 {
                     list.Items.Add(l);
                 }
                 list.Tag    = service;
                 list.Click += new EventHandler(list_Click);
                 service.DropDownControl(list);
                 if (list.SelectedIndex >= 0)
                 {
                     DrawingLayer ly = list.Items[list.SelectedIndex] as DrawingLayer;
                     item.Page.MoveItemToLayer(item, ly);
                     value = ly.LayerId.ToString();
                     Type         t    = service.GetType();
                     PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                     if (pif0 != null)
                     {
                         PropertyGrid pg = pif0.GetValue(service, null) as PropertyGrid;
                         if (pg != null)
                         {
                             pg.Refresh();
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             ITypedNamedValuesHolder vep = context.Instance as ITypedNamedValuesHolder;
             if (vep != null)
             {
                 DlgNewTypedNamedValue dlg = new DlgNewTypedNamedValue();
                 dlg.LoadData(vep.GetValueNames(), "New value", null);
                 if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                 {
                     if (vep.CreateTypedNamedValue(dlg.DataName, dlg.DataType))
                     {
                         PropertyGrid pg   = null;
                         Type         t    = edSvc.GetType();
                         PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                         if (pif0 != null)
                         {
                             object g = pif0.GetValue(edSvc, null);
                             pg = g as PropertyGrid;
                             if (pg != null)
                             {
                                 pg.Refresh();
                             }
                         }
                         PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance, true);
                         PropertyDescriptor           p  = ps["Dummy"];
                         if (p != null)
                         {
                             p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                         }
                         IPropertyListchangeable plc = context.Instance as IPropertyListchangeable;
                         if (plc != null)
                         {
                             plc.OnPropertyListChanged();
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }
コード例 #7
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             LimnorWebApp wapp = context.Instance as LimnorWebApp;
             if (wapp == null)
             {
                 ClassPointer cp = context.Instance as ClassPointer;
                 if (cp != null)
                 {
                     wapp = cp.ObjectInstance as LimnorWebApp;
                 }
             }
             if (wapp != null)
             {
                 Form         frmOwner = null;
                 Type         t        = edSvc.GetType();
                 PropertyInfo pif0     = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object       g  = pif0.GetValue(edSvc, null);
                     PropertyGrid pg = g as PropertyGrid;
                     if (pg != null)
                     {
                         frmOwner = pg.FindForm();
                     }
                 }
                 DialogProjectOutput dlg = new DialogProjectOutput();
                 dlg.LoadData(wapp.Project, wapp.TestWebSiteName(frmOwner));
                 if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                 {
                     if (dlg.WebSite != null)
                     {
                         value            = dlg.WebSite.WebName;
                         wapp.WebSiteName = dlg.WebSite.WebName;
                     }
                 }
             }
         }
     }
     return(value);
 }
コード例 #8
0
 public static Form GetForm(IServiceProvider provider)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             Type         t    = edSvc.GetType();
             PropertyInfo pif0 = t.GetProperty("OwnerGrid");
             if (pif0 != null)
             {
                 Control g = pif0.GetValue(edSvc, null) as Control;
                 if (g != null)
                 {
                     return(g.FindForm());
                 }
             }
         }
     }
     return(null);
 }
コード例 #9
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            object                 v     = base.EditValue(context, provider, value);
            DrawingLayer           layer = value as DrawingLayer;
            DrawingLayerCollection ls    = context.Instance as DrawingLayerCollection;

            if (layer != null && ls != null)
            {
                foreach (DrawingItem item in layer)
                {
                    item.LayerId = layer.LayerId;
                }
                IDrawingOwnerPointer iw = ls.Page.DesignerPointer;
                if (iw != null)
                {
                    iw.OnDrawingCollectionChanged(layer);
                }
            }
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    Type         t    = edSvc.GetType();
                    PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                    if (pif0 != null)
                    {
                        object       g  = pif0.GetValue(edSvc, null);
                        PropertyGrid pg = g as PropertyGrid;
                        if (pg != null)
                        {
                            pg.Refresh();
                        }
                    }
                }
            }
            return(v);
        }
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         ParameterValue pv = context.Instance as ParameterValue;
         if (pv == null)
         {
             MapItem item = context.Instance as MapItem;
             if (item != null)
             {
                 pv = item.Item.Value as ParameterValue;
             }
         }
         if (pv == null)
         {
             pv = value as ParameterValue;
         }
         if (pv != null)
         {
             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             if (edSvc != null)
             {
                 IMathExpression mew = value as IMathExpression;
                 if (mew == null)
                 {
                     mew = pv.MathExpression;
                     if (mew == null)
                     {
                         MathNodeRoot r = new MathNodeRoot();
                         r.Name = pv.Name;
                         mew    = r;
                     }
                 }
                 System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 IMathEditor dlg = mew.CreateEditor(rc);
                 //
                 MathPropertyGrid pg   = null;
                 Type             t    = edSvc.GetType();
                 PropertyInfo     pif0 = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object g = pif0.GetValue(edSvc, null);
                     pg = g as MathPropertyGrid;
                 }
                 IMethod imScope = pv.ScopeMethod;
                 if (imScope == null)
                 {
                     imScope = mew.ScopeMethod;
                     if (imScope == null)
                     {
                         if (pg != null)
                         {
                             imScope = pg.ScopeMethod;
                         }
                     }
                 }
                 //
                 dlg.ActionContext = pv.ActionContext;
                 dlg.SetScopeMethod(imScope);
                 dlg.VariableMapTargetType      = typeof(ParameterValue);
                 dlg.MathExpression             = (IMathExpression)mew.Clone();
                 dlg.MathExpression.ScopeMethod = imScope;
                 dlg.MathExpression.EnableUndo  = true;
                 if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                 {
                     mew = dlg.MathExpression;
                     if (value != pv)
                     {
                         value = mew;
                         pv.SetValue(value);
                     }
                     else
                     {
                         pv.SetValue(mew);
                     }
                     if (pg != null)
                     {
                         pg.OnValueChanged(mew, EventArgs.Empty);
                     }
                 }
             }
         }
     }
     return(value);
 }
コード例 #11
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             IMethod m = value as IMethod;
             IActionMethodPointer im     = null;
             MethodPointer        method = value as MethodPointer;
             if (m == null)
             {
                 IMethodPointerHolder mh = context.Instance as IMethodPointerHolder;
                 if (mh != null)
                 {
                     im = mh.GetMethodPointer();
                     if (im != null)
                     {
                         m = im.MethodPointed;
                     }
                 }
             }
             MethodClass  scopeMethod = null;
             Type         t           = edSvc.GetType();
             PropertyInfo pif0        = t.GetProperty("OwnerGrid");
             if (pif0 != null)
             {
                 object           g  = pif0.GetValue(edSvc, null);
                 MathPropertyGrid pg = g as MathPropertyGrid;
                 if (pg != null)
                 {
                     scopeMethod = pg.ScopeMethod as MethodClass;
                 }
             }
             if (scopeMethod == null)
             {
                 IAction ia = context.Instance as IAction;
                 if (ia != null)
                 {
                     scopeMethod = ia.ScopeMethod as MethodClass;
                 }
             }
             FrmObjectExplorer dlg = DesignUtil.CreateSelectMethodDialog(scopeMethod, m);
             if (edSvc.ShowDialog(dlg) == DialogResult.OK)
             {
                 IAction act = null;
                 if (method != null)
                 {
                     act = method.Action;
                 }
                 if (act == null)
                 {
                     if (im != null)
                     {
                         act = im.Action;
                     }
                 }
                 IPropertyEx p = dlg.SelectedObject as IPropertyEx;
                 if (p != null)
                 {
                     value = p.CreateSetterMethodPointer(act);
                 }
                 else
                 {
                     MethodPointer mp = dlg.SelectedObject as MethodPointer;
                     if (mp != null)
                     {
                         mp.Action = act;
                         value     = mp;
                     }
                     else
                     {
                         CustomMethodPointer cmp = dlg.SelectedObject as CustomMethodPointer;
                         if (cmp != null)
                         {
                             cmp.Action = act;
                             value      = cmp;
                         }
                     }
                 }
             }
         }
     }
     return(value);
 }
コード例 #12
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && provider != null && context.Instance != null)
     {
         MathematicExpression me = context.Instance as MathematicExpression;
         if (me != null)
         {
             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             if (edSvc != null)
             {
                 Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 MathExpEditor.ExcludeProjectItem = true;
                 IMathEditor dlg = me.CreateEditor(rc);
                 MathExpEditor.ExcludeProjectItem = false;
                 MathNodeRoot r = new MathNodeRoot();
                 r.SetWriter(me.GetWriter());
                 r.SetReader(me.GetReader());
                 try
                 {
                     XmlDocument doc = new XmlDocument();
                     doc.LoadXml(me.Formula.Xml);
                     if (doc.DocumentElement != null)
                     {
                         r.Load(doc.DocumentElement);
                     }
                 }
                 catch
                 {
                 }
                 dlg.MathExpression            = r;
                 dlg.MathExpression.EnableUndo = true;
                 try
                 {
                     if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                     {
                         r = (MathNodeRoot)dlg.MathExpression;
                         r.FindAllInputVariables();
                         XmlDocument doc      = new XmlDocument();
                         XmlNode     rootNode = doc.CreateElement(MathematicExpression.XML_Root);
                         doc.AppendChild(rootNode);
                         r.SetWriter(me.GetWriter());
                         r.SetReader(me.GetReader());
                         r.Save(rootNode);
                         value = new FormulaProperty(doc.OuterXml);
                         PropertyGrid pg   = null;
                         Type         t    = edSvc.GetType();
                         PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                         if (pif0 != null)
                         {
                             object g = pif0.GetValue(edSvc, null);
                             pg = g as PropertyGrid;
                             if (pg != null)
                             {
                                 me.SetPropertyGrid(pg);
                             }
                         }
                     }
                 }
                 catch (Exception err2)
                 {
                     MessageBox.Show(MathException.FormExceptionText(null, err2), "Math Expression Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
     }
     return(value);
 }
コード例 #13
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (service != null)
         {
             IObjectPointer mm = value as IObjectPointer;
             if (mm == null)
             {
                 PropertyPointer pp = new PropertyPointer();
                 IDataScope      dv = context.Instance as IDataScope;
                 if (dv != null)
                 {
                     pp.Scope = dv.ScopeDataType;
                     pp.Owner = dv.ScopeOwner;
                 }
                 mm = pp;
             }
             if (mm != null)
             {
                 IMethod      imScope = null;
                 Type         t       = service.GetType();
                 PropertyInfo pif0    = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object           pv = pif0.GetValue(service, null);
                     MathPropertyGrid pg = pv as MathPropertyGrid;
                     if (pg != null)
                     {
                         imScope = pg.ScopeMethod;
                     }
                 }
                 if (imScope == null)
                 {
                     IScopeMethodHolder mh = context.Instance as IScopeMethodHolder;
                     if (mh != null)
                     {
                         imScope = mh.GetScopeMethod();
                     }
                 }
                 DataTypePointer scope = null;
                 IOwnerScope     ios   = context.Instance as IOwnerScope;
                 if (ios != null)
                 {
                     scope = ios.OwnerScope;
                 }
                 if (scope == null)
                 {
                     ParameterValue pv = context.Instance as ParameterValue;
                     if (pv != null && pv.DataType != null && pv.DataType.BaseClassType != null)
                     {
                         if (typeof(Delegate).IsAssignableFrom(pv.DataType.BaseClassType))
                         {
                             scope = pv.DataType;
                         }
                     }
                 }
                 FrmObjectExplorer dlg = DesignUtil.GetPropertySelector(mm, imScope, scope);
                 if (dlg != null)
                 {
                     OnDialogCreated(dlg);
                     if (service.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                     {
                         bool   isValid = true;
                         string msg     = string.Empty;
                         if (MethodEditContext.IsWebPage)
                         {
                             IObjectPointer iop = dlg.SelectedObject as IObjectPointer;
                             if (iop != null)
                             {
                                 if (MethodEditContext.UseClientPropertyOnly)
                                 {
                                     if (iop.RunAt == EnumWebRunAt.Server)
                                     {
                                         isValid = false;
                                         msg     = "Server value is not allowed";
                                     }
                                 }
                                 else if (MethodEditContext.UseServerPropertyOnly)
                                 {
                                     if (iop.RunAt == EnumWebRunAt.Client)
                                     {
                                         isValid = false;
                                         msg     = "Client value is not allowed";
                                     }
                                 }
                             }
                         }
                         if (!isValid)
                         {
                             MessageBox.Show(msg, "Select value", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                         else
                         {
                             value = dlg.SelectedObject;
                             if (context.PropertyDescriptor.IsReadOnly)
                             {
                                 //manually set it
                                 PropertyInfo pif = context.Instance.GetType().GetProperty(context.PropertyDescriptor.Name);
                                 pif.SetValue(context.Instance, value, new object[] { });
                             }
                         }
                     }
                     dlg.ResetSelectLValue();
                 }
             }
         }
     }
     return(value);
 }
コード例 #14
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    ITypedNamedValuesHolder vep = context.Instance as ITypedNamedValuesHolder;
                    if (vep != null)
                    {
                        CommandList list = new CommandList(edSvc);
                        edSvc.DropDownControl(list);
                        if (list.MadeSelection)
                        {
                            bool edited = false;
                            switch (list.Selection)
                            {
                            case 0:
                                DlgNewTypedNamedValue dlg = new DlgNewTypedNamedValue();
                                TypedNamedValue       tn  = vep.GetTypedNamedValueByName(context.PropertyDescriptor.Name);
                                dlg.LoadData(vep.GetValueNames(), "Modify value name and type", tn);
                                if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                                {
                                    edited = vep.RenameTypedNamedValue(context.PropertyDescriptor.Name, dlg.DataName, dlg.DataType);
                                }
                                break;

                            case 1:
                                DlgText dlgt = new DlgText();
                                dlgt.LoadData(value as string, string.Format(CultureInfo.InvariantCulture, "Modify {0}", context.PropertyDescriptor.Name));
                                if (edSvc.ShowDialog(dlgt) == DialogResult.OK)
                                {
                                    value = dlgt.GetText();
                                }
                                break;

                            case 2:
                                edited = vep.DeleteTypedNamedValue(context.PropertyDescriptor.Name);
                                break;
                            }
                            if (edited)
                            {
                                PropertyGrid pg   = null;
                                Type         t    = edSvc.GetType();
                                PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                                if (pif0 != null)
                                {
                                    object g = pif0.GetValue(edSvc, null);
                                    pg = g as PropertyGrid;
                                    if (pg != null)
                                    {
                                        pg.Refresh();
                                    }
                                }
                                PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance, true);
                                PropertyDescriptor           p  = ps["Dummy"];
                                if (p != null)
                                {
                                    p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                                }
                                IPropertyListchangeable plc = context.Instance as IPropertyListchangeable;
                                if (plc != null)
                                {
                                    plc.OnPropertyListChanged();
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }