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