예제 #1
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
        {
            // get model properties
            List <PropertyDescriptor> properties = new List <PropertyDescriptor>();


            foreach (PropertyDescriptor modelPropertyDescriptor in ModelUtilities.WrapProperties(this))
            {
                properties.Add(modelPropertyDescriptor);
            }

            // try to see if there are pseudo builtin properties for this type.
            AttachedPropertiesService AttachedPropertiesService = this.modelTreeManager.Context.Services.GetService <AttachedPropertiesService>();

            if (AttachedPropertiesService != null)
            {
                var nonBrowsableAttachedProperties = from attachedProperty in AttachedPropertiesService.GetAttachedProperties(this.itemType)
                                                     where (!attachedProperty.IsBrowsable && !attachedProperty.IsVisibleToModelItem)
                                                     select attachedProperty;

                foreach (AttachedProperty AttachedProperty in nonBrowsableAttachedProperties)
                {
                    properties.Add(new AttachedPropertyDescriptor(AttachedProperty, this));
                }
            }
            return(new PropertyDescriptorCollection(properties.ToArray(), true));
        }
        PropertyDescriptorCollection GetPropertyDescriptors()
        {
            PropertyDescriptorCollection propertyDescriptors = PropertyDescriptorCollection.Empty;

            try
            {
                object instance = parent.GetCurrentValue();
                if (instance != null)
                {
                    if (!(instance is ICustomTypeDescriptor))
                    {
                        Type instanceType = instance.GetType();
                        if (instanceType.IsValueType)
                        {
                            propertyDescriptors = TypeDescriptor.GetProvider(instanceType).GetTypeDescriptor(instanceType).GetProperties();
                        }
                        else
                        {
                            propertyDescriptors = TypeDescriptor.GetProvider(instance).GetTypeDescriptor(instance).GetProperties();
                        }
                    }
                    else
                    {
                        propertyDescriptors = TypeDescriptor.GetProperties(instance);
                    }
                }

                // Add browsable attached properties
                AttachedPropertiesService AttachedPropertiesService = this.parent.GetEditingContext().Services.GetService <AttachedPropertiesService>();
                if (AttachedPropertiesService != null)
                {
                    var browsableAttachedProperties = from attachedProperty in AttachedPropertiesService.GetAttachedProperties(this.parent.ItemType)
                                                      where (attachedProperty.IsBrowsable || attachedProperty.IsVisibleToModelItem)
                                                      select new AttachedPropertyDescriptor(attachedProperty, this.parent);

                    List <PropertyDescriptor> mergedProperties = new List <PropertyDescriptor>();
                    foreach (PropertyDescriptor propertyDescriptor in propertyDescriptors)
                    {
                        mergedProperties.Add(propertyDescriptor);
                    }
                    propertyDescriptors = new PropertyDescriptorCollection(mergedProperties.Concat(browsableAttachedProperties).ToArray(), true);
                }
            }
            catch (FileNotFoundException e)
            {
                EditingContext context = parent.GetEditingContext();
                if (context.Items.GetValue <ErrorItem>() == null)
                {
                    context.Items.SetValue(new ErrorItem {
                        Message = e.Message, Details = e.ToString()
                    });
                }
            }

            return(propertyDescriptors);
        }
        public WorkflowDesigner()
        {
            // create our perf trace provider first
            this.perfEventProvider = new DesignerPerfEventProvider();            
            this.idManager = new ViewStateIdManager();
            this.context = new EditingContext();
            this.ModelSearchService = new ModelSearchServiceImpl(this);
            this.context.Items.SetValue(new ReadOnlyState { IsReadOnly = false });
            this.view = new Grid();
            this.view.Focusable = false;
            
            //add the resource dictionary to application resource so every component could reference it
            if (Application.Current == null)
            {
                //create an application if it doesn't exist, make sure it will not shutdown after windows being shut down
                Application app = new Application();
                app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            }
            Fx.Assert(Application.Current != null, "Application and resources must be there");
            Application.Current.Resources.MergedDictionaries.Add(WorkflowDesignerColors.FontAndColorResources);
            Application.Current.Resources.MergedDictionaries.Add(WorkflowDesignerIcons.IconResourceDictionary);
            AttachedPropertiesService propertiesService = new AttachedPropertiesService();
            this.context.Services.Publish(typeof(AttachedPropertiesService), propertiesService);

            undoEngine = new UndoEngine(context);
            this.context.Services.Publish(typeof(UndoEngine), undoEngine);
            undoEngine.UndoCompleted += new EventHandler<UndoUnitEventArgs>(OnUndoCompleted);

            this.context.Services.Publish<ValidationService>(this.ValidationService);
            this.context.Services.Publish<ObjectReferenceService>(this.ObjectReferenceService);
            this.context.Services.Publish<DesignerPerfEventProvider>(this.perfEventProvider);
            this.context.Services.Publish<FeatureManager>(new FeatureManager(this.context));
            this.context.Services.Publish<DesignerConfigurationService>(new DesignerConfigurationService());

            this.context.Services.Subscribe<ICommandService>((s) =>
            {
                const string addinTypeName = "Microsoft.VisualStudio.Activities.AddIn.WorkflowDesignerAddIn";
                if (s != null && s.GetType().FullName.Equals(addinTypeName))
                {
                    DesignerConfigurationService service = this.context.Services.GetService<DesignerConfigurationService>();
                    if (service != null)
                    {
                        service.WorkflowDesignerHostId = WorkflowDesignerHostId.Dev10;
                    }
                }
            });

            this.context.Services.Subscribe<IVSSqmService>((service) =>
            {
                const string serviceTypeName = "Microsoft.VisualStudio.Activities.AddIn.VSSqmService";
                if (service != null && service.GetType().FullName.Equals(serviceTypeName))
                {
                    DesignerConfigurationService configurationService = this.context.Services.GetService<DesignerConfigurationService>();
                    if (configurationService != null)
                    {
                        configurationService.WorkflowDesignerHostId = WorkflowDesignerHostId.Dev11;
                    }
                }
            });

            this.Context.Items.Subscribe<ErrorItem>(delegate(ErrorItem errorItem)
            {
                ErrorView errorView = new ErrorView();
                errorView.Message = errorItem.Message;
                errorView.Details = errorItem.Details;
                errorView.Context = this.Context;

                // Clear views
                this.view.Children.Clear();
                this.view.Children.Add(errorView);
                if (this.outlineView != null)
                {
                    this.outlineView.Children.Clear();
                }
            }
                );

            this.context.Items.Subscribe<ReadOnlyState>(new SubscribeContextCallback<ReadOnlyState>(OnReadonlyStateChanged));

            this.context.Services.Subscribe<IXamlLoadErrorService>(s => this.xamlLoadErrorService = s);

            this.PreviewLoad += NamespaceSettingsHandler.PreviewLoadRoot;
            this.view.Loaded += (s, e) =>
            {
                //when view is loaded, check if user did provide his own WindowHelperService - if not, provide a default one
                if (!this.context.Services.Contains<WindowHelperService>())
                {
                    IntPtr hWND = IntPtr.Zero;
                    Window ownerWindow = Window.GetWindow(this.view);
                    if (null != ownerWindow)
                    {
                        WindowInteropHelper helper = new WindowInteropHelper(ownerWindow);
                        hWND = helper.Handle;
                    }
                    this.Context.Services.Publish<WindowHelperService>(new WindowHelperService(hWND));
                }
                WindowHelperService whs = this.context.Services.GetService<WindowHelperService>();
                whs.View = this.view;

                //check if workflow command extension item is available - if not, provide default one
                if (!this.context.Items.Contains<WorkflowCommandExtensionItem>())
                {
                    WorkflowCommandExtensionItem item = new WorkflowCommandExtensionItem(new DefaultCommandExtensionCallback());
                    this.context.Items.SetValue(item);
                }

                ComponentDispatcher.EnterThreadModal += new EventHandler(ComponentDispatcher_EnterThreadModal);
                ComponentDispatcher.LeaveThreadModal += new EventHandler(ComponentDispatcher_LeaveThreadModal);
            };

            this.view.Unloaded += (s, e) =>
            {
                ComponentDispatcher.EnterThreadModal -= new EventHandler(ComponentDispatcher_EnterThreadModal);
                ComponentDispatcher.LeaveThreadModal -= new EventHandler(ComponentDispatcher_LeaveThreadModal);
            };

            this.view.IsKeyboardFocusWithinChanged += (s, e) =>
            {
                // The ModelTreeManager is null when there is an active ErrorItem.
                // We have nothing to write to text in this case.
                if (this.modelTreeManager != null && (bool)e.NewValue == false)
                {
                    if ((FocusManager.GetFocusedElement(this.view) as TextBox) != null)
                    {
                        FocusManager.SetFocusedElement(this.view, null);
                        this.NotifyModelChanged();
                    }
                }
            };
        }
        void OnAttachedPropertiesServiceAvailable(AttachedPropertiesService attachedPropertiesService)
        {
            this.isBreakpointEnabledProperty = new AttachedProperty<bool>()
                {
                    Getter = (modelItem) => IsBreakpointOfType(modelItem, BreakpointTypes.Enabled),
                    Name = "IsBreakpointEnabled",
                    OwnerType = typeof(object)
                };

            this.isBreakpointBoundedProperty = new AttachedProperty<bool>()
                {
                    Getter = (modelItem) => IsBreakpointOfType(modelItem, BreakpointTypes.Bounded),
                    Name = "IsBreakpointBounded",
                    OwnerType = typeof(object)
                };

            this.isBreakpointConditionalProperty = new AttachedProperty<bool>()
                {
                    Getter = (modelItem) => IsBreakpointOfType(modelItem, BreakpointTypes.Conditional),
                    Name = "IsBreakpointConditional",
                    OwnerType = typeof(object)
                };

            this.isCurrentLocationProperty = new AttachedProperty<bool>()
                {
                    Getter = (modelItem) => IsCurrentLocation(modelItem),
                    Name = "IsCurrentLocation",
                    OwnerType = typeof(object)
                };

            this.isCurrentContextProperty = new AttachedProperty<bool>()
                {
                    Getter = (modelItem) => IsCurrentContext(modelItem),
                    Name = "IsCurrentContext",
                    OwnerType = typeof(object)
                };

            attachedPropertiesService.AddProperty(isBreakpointEnabledProperty);
            attachedPropertiesService.AddProperty(isBreakpointBoundedProperty);
            attachedPropertiesService.AddProperty(isBreakpointConditionalProperty);
            attachedPropertiesService.AddProperty(isCurrentLocationProperty);
            attachedPropertiesService.AddProperty(isCurrentContextProperty);
        }
        void OnAttachedPropertiesServiceAvailable(AttachedPropertiesService attachedPropertiesService)
        {
            this.validationStateProperty = new AttachedProperty<ValidationState>()
            {
                Getter = (modelItem) => GetValidationState(modelItem),
                Name = "ValidationState",
                OwnerType = typeof(object)
            };

            attachedPropertiesService.AddProperty(this.validationStateProperty);

            this.validationMessageProperty = new AttachedProperty<string>()
            {
                Getter = (modelItem) => GetValidationMessage(modelItem),
                Name = "ValidationMessage",
                OwnerType = typeof(object)
            };

            attachedPropertiesService.AddProperty(this.validationMessageProperty);
        }