Пример #1
0
        void Initialize(DTE dte, IUnboundAssetReference reference, object currentValue, Type valueType)
        {
            if (dte == null)
            {
                throw new ArgumentNullException("dte");
            }
            if (reference == null && valueType == null)
            {
                throw new ArgumentNullException("reference, valueType",
                                                Properties.Resources.SolutionPicker_NullRefAndType);
            }
            this.dte               = dte;
            this.reference         = reference;
            this.valueType         = valueType;
            this.originalSelection = currentValue;

            try
            {
                if (reference != null && !reference.IsEnabledFor(currentValue))
                {
                    this.originalSelection = null;
                }
            }
            catch (Exception e)
            {
                throw new RecipeExecutionException(reference.AssetName,
                                                   Properties.Resources.Reference_FailEnabledFor, e);
            }
            InitializeComponent();
            this.SuspendLayout();
            LoadElements();
            this.ResumeLayout(false);
        }
Пример #2
0
        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;
                //It's better to continue executing the action and not stop because of the caption in the label
                //throw new RecipeExecutionException(reference.AssetName,
                //	string.Format(CultureInfo.CurrentCulture,
                //	Properties.Resources.Reference_InvalidAttributes, "AppliesTo"), e);
            }
            this.messageText.Text = String.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                this.messageText.Text,
                appliesTo);
        }
Пример #3
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 RecipeExecutionException(reference.AssetName,
                                                           Properties.Resources.Reference_FailEnabledFor, ex);
                    }
                    if (enabled)
                    {
                        return(control.SelectedTarget);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(control.SelectedTarget);
                }
            }
        }
Пример #4
0
        private void GetAssetLists(IAssetReference[] allReferences, out List <IUnboundAssetReference> unboundAssetReferenceList, out List <IAssetReference> otherAssetReferenceList)
        {
            unboundAssetReferenceList = new List <IUnboundAssetReference>();
            otherAssetReferenceList   = new List <IAssetReference>();

            foreach (IAssetReference reference in allReferences)
            {
                IUnboundAssetReference unboundAssetReference = reference as IUnboundAssetReference;
                if (unboundAssetReference != null)
                {
                    unboundAssetReferenceList.Add(unboundAssetReference);
                }
                else
                {
                    otherAssetReferenceList.Add(reference);
                }
            }
        }
Пример #5
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);
        }
Пример #6
0
 public bool SelectTarget(IWin32Window ownerWindow, IUnboundAssetReference forReference)
 {
     return(true);
 }
Пример #7
0
 /// <summary>
 /// Initializes the control receiving the DTE, reference and current value
 /// to customize the behavior of the control.
 /// </summary>
 /// <param name="dte">Reference to the Visual Studio environment.</param>
 /// <param name="reference">The unbound reference used to determine whether the current node is valid.</param>
 /// <param name="currentValue">The current value to preselect. Can be <see langword="null"/>.</param>
 /// <param name="valueType">The type of the element to pick.</param>
 /// <exception cref="ArgumentNullException">Either <paramref name="dte"/> or <paramref name="reference"/> are <see langword="null"/>.</exception>
 /// <remarks>
 /// If <paramref name="currentValue"/> is not valid for the given <paramref name="reference"/>, the value
 /// is ignored and not pre-selected.
 /// If a <paramref name="reference"/> is not provided, then the <paramref name="valueType"/> is used to
 /// determine a valid target. Note at least one of them has to have a non <see langword="null"/> value.
 /// </remarks>
 public SolutionPickerControl(DTE dte, IUnboundAssetReference reference, object currentValue, Type valueType)
 {
     Initialize(dte, reference, currentValue, valueType);
 }