Beispiel #1
0
        void OnContextChanged()
        {
            this.targetFramework = WorkflowDesigner.GetTargetFramework(this.Context);

            AttachedPropertiesService attachedPropertyService = this.Context.Services.GetService <AttachedPropertiesService>();

            Fx.Assert(attachedPropertyService != null, "AttachedPropertiesService shouldn't be null in EditingContext.");
            attachedPropertyService.AddProperty(CreateAttachedPropertyForNamespace <string>(ErrorMessagePropertyName));
            attachedPropertyService.AddProperty(CreateAttachedPropertyForNamespace <bool>(IsInvalidPropertyName));
            //clear any defaults because it's meant to be set by host and not serialized to XAML
            VisualBasicSettings.Default.ImportReferences.Clear();

            ModelService modelService = this.Context.Services.GetService <ModelService>();

            Fx.Assert(modelService != null, "ModelService shouldn't be null in EditingContext.");
            Fx.Assert(modelService.Root != null, "model must have a root");
            this.importsModelItem = modelService.Root.Properties[NamespaceListPropertyDescriptor.ImportCollectionPropertyName].Collection;
            Fx.Assert(this.importsModelItem != null, "root must have imports");
            this.importsModelItem.CollectionChanged += this.OnImportsModelItemCollectionChanged;

            this.importedNamespacesItem = this.Context.Items.GetValue <ImportedNamespaceContextItem>();
            this.importedNamespacesItem.EnsureInitialized(this.Context);

            if (this.availableNamespaces == null)
            {
                //change to available namespace should not be a model change so we access the dictionary directly
                this.availableNamespaces = this.importsModelItem.Properties[NamespaceListPropertyDescriptor.AvailableNamespacesPropertyName].ComputedValue as Dictionary <string, List <string> >;
                Fx.Assert(this.availableNamespaces != null, "Available namespace dictionary is not in right format");
            }
            RefreshNamespaces();
        }
Beispiel #2
0
        public override void Initialize(EditingContext context)
        {
            this.context = context;
            AttachedPropertiesService propertiesService = this.context.Services.GetService <AttachedPropertiesService>();

            helpService = this.context.Services.GetService <IIntegratedHelpService>();

            oldSelection = this.context.Items.GetValue <Selection>();
            isPrimarySelectionProperty = new AttachedProperty <bool>()
            {
                Getter    = (modelItem) => (this.context.Items.GetValue <Selection>().PrimarySelection == modelItem),
                Name      = "IsPrimarySelection",
                OwnerType = typeof(Object)
            };

            isSelectionProperty = new AttachedProperty <bool>()
            {
                Getter    = (modelItem) => (((IList)this.context.Items.GetValue <Selection>().SelectedObjects).Contains(modelItem)),
                Name      = "IsSelection",
                OwnerType = typeof(Object)
            };


            propertiesService.AddProperty(isPrimarySelectionProperty);
            propertiesService.AddProperty(isSelectionProperty);



            if (this.context.Services.GetService <ViewService>() == null)
            {
                view = new System.Activities.Presentation.View.DesignerView(this.context);
                WorkflowViewService      viewService      = new WorkflowViewService(context);
                WorkflowViewStateService viewStateService = new WorkflowViewStateService(context);
                this.context.Services.Publish <ViewService>(viewService);
                this.context.Services.Publish <VirtualizedContainerService>(new VirtualizedContainerService(this.context));
                this.context.Services.Publish <ViewStateService>(viewStateService);
                this.context.Services.Publish <DesignerView>(view);

                WorkflowAnnotationAdornerService annotationService = new WorkflowAnnotationAdornerService();
                annotationService.Initialize(this.context, view.scrollViewer);
                this.context.Services.Publish <AnnotationAdornerService>(annotationService);

                this.context.Services.Subscribe <ModelService>(delegate(ModelService modelService)
                {
                    this.modelService = modelService;
                    if (modelService.Root != null)
                    {
                        view.MakeRootDesigner(modelService.Root);
                    }
                    view.RestoreDesignerStates();
                    this.context.Items.Subscribe <Selection>(new SubscribeContextCallback <Selection>(OnItemSelected));
                });
            }

            if (helpService != null)
            {
                helpService.AddContextAttribute(string.Empty, KeywordForWorkflowDesignerHomePage, HelpKeywordType.F1Keyword);
            }
        }
        private static void ExposeArgumentTypeForUpdate(ModelItem modelItem, AttachedPropertiesService service, int argIndex, int argsLength)
        {
            service.AddProperty(new AttachedProperty <Type>
            {
                Name = argsLength > 1
                    ? TypeArgumentPropertyName + (argIndex + 1)
                    : TypeArgumentPropertyName,

                OwnerType   = modelItem.ItemType,
                Getter      = (mItem) => GetTypeArgument(mItem, argIndex),
                Setter      = (mItem, argType) => UpdateTypeArgument(mItem, argType, argIndex),
                IsBrowsable = true
            });
        }
        internal void Initialize(EditingContext editingContext, ScrollViewer scrollViewer)
        {
            this.scrollViewer = scrollViewer;
            this.enabled      = editingContext.Services.GetService <DesignerConfigurationService>().AnnotationEnabled;

            if (!this.enabled)
            {
                return;
            }

            AttachedPropertiesService attachedPropertiesService = editingContext.Services.GetService <AttachedPropertiesService>();
            AttachedProperty <string> attachedProperty          = new AttachedProperty <string>
            {
                IsBrowsable          = false,
                IsVisibleToModelItem = true,
                Name      = Annotation.AnnotationTextPropertyName,
                OwnerType = typeof(object),
                Getter    = (modelItem) =>
                {
                    string annotation = null;
                    AttachablePropertyServices.TryGetProperty <string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out annotation);
                    return(annotation);
                },
                Setter = (modelItem, value) =>
                {
                    string oldValue = null;
                    AttachablePropertyServices.TryGetProperty <string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out oldValue);
                    if (oldValue == value)
                    {
                        return;
                    }

                    ModelTreeManager treeManager = modelItem.GetEditingContext().Services.GetService <ModelTreeManager>();

                    AttachablePropertyChange change = new AttachablePropertyChange()
                    {
                        Owner = modelItem,
                        AttachablePropertyIdentifier = Annotation.AnnotationTextProperty,
                        OldValue     = oldValue,
                        NewValue     = value,
                        PropertyName = Annotation.AnnotationTextPropertyName
                    };

                    treeManager.AddToCurrentEditingScope(change);
                }
            };

            attachedPropertiesService.AddProperty(attachedProperty);
        }
        public static void Attach(ModelItem modelItem, Int32 maximumUpdatableTypes)
        {
            Type[] genericArguments = modelItem.ItemType.GetGenericArguments();

            if (genericArguments.Any() == false)
            {
                return;
            }

            Int32                     argumentCount          = genericArguments.Length;
            Int32                     updatableArgumentCount = Math.Min(argumentCount, maximumUpdatableTypes);
            EditingContext            context = modelItem.GetEditingContext();
            AttachedPropertiesService attachedPropertiesService = context.Services.GetService <AttachedPropertiesService>();

            for (Int32 index = 0; index < updatableArgumentCount; index++)
            {
                AttachUpdatableArgumentType(modelItem, attachedPropertiesService, index, updatableArgumentCount);
            }
        }
        private void RegisterDisplayNameProperty()
        {
            AttachedPropertiesService attachedPropertiesService =
                this.Context.Services.GetService <AttachedPropertiesService>();

            if (attachedPropertiesService == null)
            {
                return;
            }

            IEnumerable <AttachedProperty> properties = attachedPropertiesService.GetAttachedProperties(typeof(ActivityBuilder <>));

            if (properties != null && properties.Contains(displayNameProperty))
            {
                return;
            }

            attachedPropertiesService.AddProperty(displayNameProperty);
        }
Beispiel #7
0
        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);
        }
            public DisplayNameUpdater(EditingContext context)
            {
                activityBuilderDisplayNameProperty = new AttachedProperty <string>
                {
                    Name      = "DisplayName",
                    OwnerType = typeof(ActivityBuilder),
                    Getter    = (modelItem) => ViewUtilities.GetActivityBuilderDisplayName(modelItem)
                };
                activityTemplateFactoryBuilderDisplayNameProperty = new AttachedProperty <string>
                {
                    Name      = "DisplayName",
                    OwnerType = typeof(ActivityTemplateFactoryBuilder),
                    Getter    = (modelItem) => ViewUtilities.GetActivityBuilderDisplayName(modelItem)
                };
                AttachedPropertiesService attachedPropertiesService = context.Services.GetService <AttachedPropertiesService>();

                attachedPropertiesService.AddProperty(activityBuilderDisplayNameProperty);
                attachedPropertiesService.AddProperty(activityTemplateFactoryBuilderDisplayNameProperty);
                context.Services.GetService <ModelService>().ModelChanged += new EventHandler <ModelChangedEventArgs>(ModelChanged);
            }
        private static void AttachUpdatableArgumentType(
            ModelItem modelItem, AttachedPropertiesService attachedPropertiesService, Int32 argumentIndex, Int32 argumentCount)
        {
            String propertyName = "ArgumentType";

            if (argumentCount > 1)
            {
                propertyName += argumentIndex + 1;
            }

            AttachedProperty <Type> attachedProperty = new AttachedProperty <Type>
            {
                Name        = propertyName,
                OwnerType   = modelItem.ItemType,
                IsBrowsable = true
            };

            attachedProperty.Getter = (ModelItem arg) => GetTypeArgument(arg, argumentIndex);
            attachedProperty.Setter = (ModelItem arg, Type newType) => UpdateTypeArgument(arg, argumentIndex, newType);

            attachedPropertiesService.AddProperty(attachedProperty);
        }
        public sealed override void Initialize(EditingContext context, Type modelType)
        {
            this.modelType = modelType;

            context.Services.Subscribe <ViewStateService>(delegate(ViewStateService viewStateService)
            {
                this.viewStateService              = viewStateService;
                viewStateService.ViewStateChanged += this.OnViewStateChanged;
                if (this.attachedPropertiesService != null)
                {
                    RegisterAttachedProperties();
                }
            });
            context.Services.Subscribe <AttachedPropertiesService>(delegate(AttachedPropertiesService attachedPropertiesService)
            {
                this.attachedPropertiesService = attachedPropertiesService;
                if (this.viewStateService != null)
                {
                    RegisterAttachedProperties();
                }
            });
        }
Beispiel #12
0
        void AttachDisplayName()
        {
            AttachedPropertiesService attachedPropertiesService = this.Context.Services.GetService <AttachedPropertiesService>();

            Fx.Assert(attachedPropertiesService != null, "AttachedPropertiesService is not available.");
            Type modelItemType = this.ModelItem.ItemType;

            foreach (AttachedProperty property in attachedPropertiesService.GetAttachedProperties(modelItemType))
            {
                if (property.Name == "DisplayName" && property.OwnerType == modelItemType)
                {
                    return;
                }
            }
            AttachedProperty <string> displayNameProperty = new AttachedProperty <string>
            {
                Name      = "DisplayName",
                OwnerType = modelItemType,
                Getter    = (modelItem) => { return("Case"); }
            };

            attachedPropertiesService.AddProperty(displayNameProperty);
        }
        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());

            if (!LocalAppContextSwitches.UseLegacyAccessibilityFeatures)
            {
                // Keeps track of a dictionary of session objects on current Workflow Designer.
                // The initial purpose is to pass the focused VisualBasicEditor from NetFx to VS.
                this.context.Services.Publish <Dictionary <string, object> >(new Dictionary <string, object>());
            }

            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();
                    }
                }
            };
        }