/// <summary>
 /// Provides a UI for the <see cref="CodeModelEditor"/>
 /// </summary>
 public CodeModelEditorForm(
     System.ComponentModel.ITypeDescriptorContext context,
     CodeModelEditor.BrowseRoot root,
     CodeModelEditor.BrowseKind kind,
     ICodeModelEditorFilter filter,
     CodeElement customRoot,
     bool onlyUserCode)
     : this()
 {
     this.context      = context;
     this.customRoot   = customRoot;
     this.root         = root;
     this.kind         = kind;
     this.filter       = filter;
     this.filterState  = new Hashtable();
     this.onlyUserCode = onlyUserCode;
 }
Beispiel #2
0
        /// <summary>
        /// See <see cref="UITypeEditor.EditValue(System.ComponentModel.ITypeDescriptorContext,IServiceProvider,object)"/>.
        /// </summary>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            // We need the editor service.
            if (provider.GetService(typeof(IWindowsFormsEditorService)) == null ||
                provider.GetService(typeof(DTE)) == null)
            {
                return(base.EditValue(context, provider, value));
            }

            ICodeModelEditorFilter filter = null;

            using (CreateFilter(provider, this.filterTypeName, this.attributes, out filter))
            {
                CodeElement customRoot = null;
                if (!string.IsNullOrEmpty(customRootEntryName))
                {
                    IDictionaryService dictService =
                        (IDictionaryService)provider.GetService(typeof(IDictionaryService));
                    try
                    {
                        customRoot = (CodeElement)dictService.GetValue(customRootEntryName);
                    }
                    catch
                    {
                        // Error getting the root object
                        return(null);
                    }
                }
                using (CodeModelEditorForm form = new CodeModelEditorForm(context, root, kind, filter, customRoot, onlyUserCode))
                {
                    IWindowsFormsEditorService svc = (IWindowsFormsEditorService)
                                                     provider.GetService(typeof(IWindowsFormsEditorService));
                    form.Site = new Site(provider, form, form.GetType().FullName);
                    if (svc.ShowDialog(form) == DialogResult.OK)
                    {
                        return(form.SelectedObject);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Validates <paramref name="value"/>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            CodeElement codeElement = null;

            if (value is string)
            {
                codeElement = (CodeElement)ConvertTo(context, CultureInfo.CurrentCulture, value, typeof(CodeElement));
            }
            else if (value is CodeElement)
            {
                codeElement = (CodeElement)value;
            }
            if (codeElement == null)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(this.filterTypeName))
            {
                return(true);
            }
            else
            {
                ICodeModelEditorFilter filter = null;
                using (CodeModelEditor.CreateFilter((IServiceProvider)context,
                                                    this.filterTypeName, this.attributes, out filter))
                {
                    if (filter != null)
                    {
                        try
                        {
                            return(!filter.Filter(codeElement));
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
        }
Beispiel #4
0
 internal static Microsoft.Practices.ComponentModel.ServiceContainer CreateFilter(IServiceProvider provider, string filterTypeName, StringDictionary attributes, out ICodeModelEditorFilter filter)
 {
     Microsoft.Practices.ComponentModel.ServiceContainer editorServiceProvider = new Microsoft.Practices.ComponentModel.ServiceContainer(true);
     editorServiceProvider.Site = new Site(provider, editorServiceProvider, editorServiceProvider.GetType().FullName);
     editorServiceProvider.AddService(typeof(IDictionaryService), new DictionaryWrapper(attributes));
     if (string.IsNullOrEmpty(filterTypeName))
     {
         filter = null;
     }
     else
     {
         ITypeResolutionService typeResService =
             (ITypeResolutionService)provider.GetService(typeof(ITypeResolutionService));
         Type filterType = typeResService.GetType(filterTypeName);
         if (filterType == null)
         {
             filter = null;
         }
         else
         {
             filter = (ICodeModelEditorFilter)Activator.CreateInstance(filterType);
             if (filter is IComponent)
             {
                 editorServiceProvider.Add((IComponent)filter);
             }
         }
     }
     return(editorServiceProvider);
 }