コード例 #1
0
        /// <summary>
        /// Allows to change the value of the Editor
        /// </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 (referenceType != null && reference == null)
            {
                ITypeResolutionService resolver = (ITypeResolutionService)ServiceHelper.GetService(provider,
                                                                                                   typeof(ITypeResolutionService), this);
                Type type = resolver.GetType(referenceType, true);
                ReflectionHelper.EnsureAssignableTo(type, typeof(IUnboundAssetReference));
                reference = (IUnboundAssetReference)Activator.CreateInstance(type, String.Empty);
            }

            DTE vs = (DTE)ServiceHelper.GetService(provider, typeof(DTE), this);

            using (SolutionPickerControl control = new SolutionPickerControl(
                       vs, reference, value, context.PropertyDescriptor.PropertyType))
            {
                // Set site so the control can find the IWindowsFormsEditorService
                control.Site = new Site(provider, control, control.GetType().FullName);
                //control.SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged);
                first        = true;
                initialValue = value;

                formsService = (IWindowsFormsEditorService)ServiceHelper.GetService(
                    provider, typeof(IWindowsFormsEditorService), this);
                formsService.DropDownControl(control);
                formsService = null;
                if (reference != null)
                {
                    bool enabled;
                    try
                    {
                        enabled = reference.IsEnabledFor(control.SelectedTarget);
                    }
                    catch (Exception ex)
                    {
                        throw new RecipeFrameworkException(
                                  Properties.Resources.Reference_FailEnabledFor, ex);
                    }
                    if (enabled)
                    {
                        return(control.SelectedTarget);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(control.SelectedTarget);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes an instance of the form.
        /// </summary>
        public SolutionPickerForm(DTE dte, IUnboundAssetReference reference)
        {
            InitializeComponent();
            this.picker                   = new SolutionPickerControl(dte, reference, DteHelper.GetTarget(dte), null);
            this.picker.Dock              = System.Windows.Forms.DockStyle.Fill;
            this.picker.SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged);
            this.pnlContainer.Controls.Add(this.picker);
            string appliesTo;

            try
            {
                appliesTo = reference.AppliesTo;
            }
            catch (Exception)
            {
                appliesTo = Properties.Resources.Reference_AppliesToThrew;
            }
            this.messageText.Text = String.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                this.messageText.Text,
                appliesTo);
        }