예제 #1
0
        private void IsValidTarget(TreeNode treeNode)
        {
            bool isValid = false;

            try
            {
                isValid = reference.IsEnabledFor(treeNode.Tag);
            }
            catch (Exception)
            {
                // If the reference thrown any kind of exception we'll assume that the node is not valid.
            }

            if (!isValid)
            {
                treeNode.ForeColor = SystemColors.GrayText;
            }
            else
            {
                treeNode.ForeColor = SystemColors.WindowText;
                if (treeNode.Parent != null)
                {
                    treeNode.Parent.Expand();
                }
            }
        }
예제 #2
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);
        }
예제 #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 solutionTree_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (e.Node.Tag == null)
     {
         // May be a node that holds other elements.
         this.validSelection = false;
         if (SelectionChanged != null)
         {
             SelectionChanged(this, new SelectionChangedEventArgs(this.validSelection, e.Node.Tag));
         }
         return;
     }
     try
     {
         if (reference == null)
         {
             // UNDONE: the generic code at the end of the if statements
             // doesn't work for COM objects. Find an alternative generic way of
             // determining type compatibility in the future.
             if (this.valueType == typeof(EnvDTE.Solution))
             {
                 this.validSelection = e.Node.Tag is EnvDTE.Solution;
             }
             else if (this.valueType == typeof(EnvDTE.Project))
             {
                 this.validSelection = e.Node.Tag is EnvDTE.Project;
             }
             else if (this.valueType == typeof(EnvDTE.ProjectItem))
             {
                 this.validSelection = e.Node.Tag is EnvDTE.ProjectItem;
             }
             else if (this.valueType == typeof(EnvDTE80.SolutionFolder))
             {
                 this.validSelection = e.Node.Tag is EnvDTE80.SolutionFolder;
             }
             else if (this.valueType == typeof(VSLangProj.Reference))
             {
                 this.validSelection = e.Node.Tag is VSLangProj.Reference;
             }
             else
             {
                 this.validSelection = (this.valueType == e.Node.Tag.GetType() ||
                                        this.valueType.IsAssignableFrom(e.Node.Tag.GetType()));
             }
         }
         else
         {
             try
             {
                 this.validSelection = reference.IsEnabledFor(e.Node.Tag);
             }
             catch (Exception ex)
             {
                 throw new RecipeExecutionException(reference.AssetName,
                                                    Properties.Resources.Reference_FailEnabledFor, ex);
             }
         }
     }
     catch (Exception ex)
     {
         this.validSelection = false;
         ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex);
     }
     finally
     {
         try
         {
             if (this.validSelection && GetService(typeof(IWindowsFormsEditorService)) != null)
             {
                 ((IWindowsFormsEditorService)GetService(typeof(IWindowsFormsEditorService))).CloseDropDown();
             }
             if (SelectionChanged != null)
             {
                 SelectionChanged(this, new SelectionChangedEventArgs(this.validSelection, e.Node.Tag));
             }
         }
         catch (Exception ex)
         {
             ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex);
         }
     }
 }