public ModelItemDictionaryImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); Fx.Assert(itemType != null, "item type cannot be null"); Fx.Assert(instance != null, "instance cannot be null"); this.itemType = itemType; this.instance = new DictionaryWrapper(instance); this.modelTreeManager = modelTreeManager; this.parents = new List <ModelItem>(1); this.sources = new List <ModelProperty>(1); this.helper = new ModelTreeItemHelper(); if (parent != null) { this.manuallySetParent = parent; } this.modelPropertyStore = new Dictionary <string, ModelItem>(); this.subTreeNodesThatNeedBackLinkPatching = new List <ModelItem>(); this.modelItems = new NullableKeyDictionary <ModelItem, ModelItem>(); UpdateInstance(); if (ItemsCollectionObject != null) { ItemsCollectionModelItemCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(itemsCollection_CollectionChanged); this.ItemsCollectionObject.ModelDictionary = this; } }
internal static string GetRootEditorSetting(ModelTreeManager modelTreeManager, FrameworkName targetFramework) { Debug.Assert(modelTreeManager != null, "modelTreeManager is null."); Debug.Assert(targetFramework != null, "targetFramework is null."); string globalEditorSetting = null; if (Is45OrHigher(targetFramework)) { if (modelTreeManager != null) { ModelItem rootItem = modelTreeManager.Root; if (rootItem != null) { object root = rootItem.GetCurrentValue(); globalEditorSetting = ExpressionActivityEditor.GetExpressionActivityEditor(root); if (string.IsNullOrEmpty(globalEditorSetting)) { globalEditorSetting = VBExpressionLanguageName; } } } } else { // When the target framework is less than 4.5, the root setting is ignored and always return VB globalEditorSetting = VBExpressionLanguageName; } return globalEditorSetting; }
internal static string GetRootEditorSetting(ModelTreeManager modelTreeManager, FrameworkName targetFramework) { Debug.Assert(modelTreeManager != null, "modelTreeManager is null."); Debug.Assert(targetFramework != null, "targetFramework is null."); string globalEditorSetting = null; if (Is45OrHigher(targetFramework)) { if (modelTreeManager != null) { ModelItem rootItem = modelTreeManager.Root; if (rootItem != null) { object root = rootItem.GetCurrentValue(); globalEditorSetting = ExpressionActivityEditor.GetExpressionActivityEditor(root); if (string.IsNullOrEmpty(globalEditorSetting)) { globalEditorSetting = VBExpressionLanguageName; } } } } else { // When the target framework is less than 4.5, the root setting is ignored and always return VB globalEditorSetting = VBExpressionLanguageName; } return(globalEditorSetting); }
public MainWindow() { InitializeComponent(); EditingContext = new System.Activities.Presentation.EditingContext(); _mtm = new ModelTreeManager(EditingContext); EditingContext.Services.Publish(_mtm); // we can add undo/redo _undo = new UndoEngine(EditingContext); EditingContext.Services.Publish(_undo); _undo.UndoRedoBufferChanged += _undo_UndoRedoBufferChanged; // add whatever services EditingContext.Services.Publish(new MessageBoxService()); var root = new ObjectRoot(); root.Text = "This is the root"; root.Leaves.Add(new ObjectLeaf { Text = "this is leaf one" }); _mtm.Load(root); ModelItemRoot = _mtm.Root; // the hard way var mi = ModelItemRoot.Properties["Leaves"].Collection.Add(new ObjectLeaf { Text = "this is leaf two" }); mi.PropertyChanged += mi_PropertyChanged; }
public static ModelItem CreateModelItem(object parent, object objectToMakeModelItem) { EditingContext ec = new EditingContext(); ModelTreeManager mtm = new ModelTreeManager(ec); return(mtm.CreateModelItem(CreateModelItem(parent), objectToMakeModelItem)); }
void OnModelTreeManagerAvailable(ModelTreeManager modelTreeManager) { if (modelTreeManager != null) { this.modelTreeManager = modelTreeManager; } }
private static ModelItem FindActivityModelItem(ModelTreeManager modelTreeManager, Activity errorTarget) { // Search the lowest Activity ModelItem lowestModelItem = null; List <Activity> parentChain = GetParentChain(errorTarget); Fx.Assert(parentChain != null, "Cannot find parent chain for " + errorTarget.DisplayName); foreach (Activity parent in parentChain) { lowestModelItem = modelTreeManager.GetModelItem(parent); if (lowestModelItem != null) { break; } } ModelItem foundItem = null; // Find in nearest parent first. if (lowestModelItem != null) { // The foundItem could be null because lowestModelItem is not errorTarget's parent any more. // This happens if background validation hasn't finished updating errorTarget's parent. foundItem = ModelTreeManager.FindFirst(lowestModelItem, (modelItem) => (modelItem.GetCurrentValue() == errorTarget)); } // Not found, search from root. if (foundItem == null) { foundItem = FindActivityModelItemFromRoot(modelTreeManager, errorTarget); } return(foundItem); }
// This supports loading objects instead of xaml into the designer public void Load(object instance) { if (isLoaded) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowDesignerLoadShouldBeCalledOnlyOnce)); } isLoaded = true; if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } DesignerConfigurationService configurationService = this.context.Services.GetService <DesignerConfigurationService>(); configurationService.ApplyDefaultPreference(); // Because we want AutoConnect/AutoSplit to be on even in Dev10 if PU1 is installed. // But we cannot know whether PU1 is installed or not, we decide to enable these 2 features for all Dev10. if (configurationService.WorkflowDesignerHostId == WorkflowDesignerHostId.Dev10) { configurationService.AutoConnectEnabled = true; configurationService.AutoSplitEnabled = true; } configurationService.IsWorkflowLoaded = true; configurationService.Validate(); if (this.PreviewLoad != null) { this.PreviewLoad(this, new PreviewLoadEventArgs(instance, this.context)); } if (configurationService.TargetFrameworkName.IsLessThan45()) { TargetFrameworkPropertyFilter.FilterOut45Properties(); } modelTreeManager = new ModelTreeManager(this.context); modelTreeManager.Load(instance); this.context.Services.Publish(typeof(ModelTreeManager), modelTreeManager); viewManager = GetViewManager(this.modelTreeManager.Root); this.context.Services.Publish <ModelSearchService>(this.ModelSearchService); view.Children.Add((UIElement)viewManager.View); modelTreeManager.EditingScopeCompleted += new EventHandler <EditingScopeEventArgs>(OnEditingScopeCompleted); this.view.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { this.perfEventProvider.WorkflowDesignerApplicationIdleAfterLoad(); })); //Subscribe to the ViewStateChanged event of ViewStateService to show document dirty. It would be published in the call to GetViewManager(). WorkflowViewStateService wfViewStateService = this.Context.Services.GetService(typeof(ViewStateService)) as WorkflowViewStateService; if (wfViewStateService != null) { wfViewStateService.UndoableViewStateChanged += new ViewStateChangedEventHandler(OnViewStateChanged); } this.isModelChanged = false; }
public ModelItemDictionaryImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); Fx.Assert(itemType != null, "item type cannot be null"); Fx.Assert(instance != null, "instance cannot be null"); this.itemType = itemType; this.instance = new DictionaryWrapper(instance); this.modelTreeManager = modelTreeManager; this.parents = new List<ModelItem>(1); this.sources = new List<ModelProperty>(1); this.helper = new ModelTreeItemHelper(); if (parent != null) { this.manuallySetParent = parent; } this.modelPropertyStore = new Dictionary<string, ModelItem>(); this.subTreeNodesThatNeedBackLinkPatching = new List<ModelItem>(); this.modelItems = new NullableKeyDictionary<ModelItem, ModelItem>(); UpdateInstance(); if (ItemsCollectionObject != null) { ItemsCollectionModelItemCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(itemsCollection_CollectionChanged); this.ItemsCollectionObject.ModelDictionary = this; } }
private void ImportArgumentsBtn_Click(object sender, RoutedEventArgs e) { var workflowFilePathArg = ModelItem.Properties["WorkflowFilePath"].ComputedValue as InArgument <string>; var workflowFilePath = ""; if (workflowFilePathArg != null) { //TODO WJF 此处该转换不确定是否正确,准确用法需要Get(Context)这种用法 workflowFilePath = GetInArgumentStringValue(workflowFilePathArg); //转成绝对路径 //如果workflowFilePath不是绝对路径,则转成绝对路径 if (!System.IO.Path.IsPathRooted(workflowFilePath)) { workflowFilePath = System.IO.Path.Combine(SharedObject.Instance.ProjectPath, workflowFilePath); } } Dictionary <string, Argument> argDict = new Dictionary <string, Argument>(); if (!string.IsNullOrEmpty(workflowFilePath)) { var activity = ActivityXamlServices.Load(workflowFilePath) as DynamicActivity; foreach (var prop in activity.Properties) { if (!argDict.ContainsKey(prop.Name)) { if (prop.Value == null) { argDict.Add(prop.Name, (Argument)Activator.CreateInstance(prop.Type)); } else { argDict.Add(prop.Name, (Argument)prop.Value); } } } } var options = new DynamicArgumentDesignerOptions() { Title = "导入工作流参数" }; ModelTreeManager mtm = new ModelTreeManager(new EditingContext()); mtm.Load(argDict); if (DynamicArgumentDialog.ShowDialog(this.ModelItem, mtm.Root, Context, this.ModelItem.View, options)) { var saveArgDict = this.ModelItem.Properties["Arguments"].Dictionary; saveArgDict.Clear(); foreach (var item in argDict) { saveArgDict.Add(item.Key, item.Value); } } }
public ImmediateEditingScope(ModelTreeManager modelTreeManager, UndoEngine.Bookmark undoEngineBookmark) : base(modelTreeManager, null) { Fx.Assert(modelTreeManager != null, "modelTreeManager should never be null!"); Fx.Assert(undoEngineBookmark != null, "undoEngineBookmark should never be null!"); this.modelTreeManager = modelTreeManager; this.undoEngineBookmark = undoEngineBookmark; }
public ModelServiceImpl(ModelTreeManager modelTreeManager) { if (modelTreeManager == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelTreeManager")); } this.modelTreeManager = modelTreeManager; }
private void GenerateExpression() { //TODO: Enhance the type infering logic if (ExpressionType == null) { // Get the variables in scope List <ModelItem> declaredVariables = CSharpExpressionHelper.GetVariablesInScope(OwnerActivity); if (declaredVariables.Count > 0) { InferredType = ((LocationReference)declaredVariables[0].GetCurrentValue()).Type; } } Type resultType = ExpressionType != null ? ExpressionType : InferredType; ////This could happen when: ////1) No ExpressionType is specified and ////2) The expression is invalid so that the inferred type equals to null if (resultType == null) { resultType = typeof(object); } // If the text is null we don't need to bother generating the expression (this would be the case the // first time you enter an ETB. We still need to generate the expression when it is EMPTY however - otherwise // the case where you had an expression (valid or invalid), then deleted the whole thing will not be evaluated. if (Text != null) { using (ModelEditingScope scope = OwnerActivity.BeginEdit("Property Change")) if (OwnerActivity != null) { EditingState = EditingState.Validating; // we set the expression to null // a) when the expressionText is empty AND it's a reference expression or // b) when the expressionText is empty AND the DefaultValue property is null if (Text.Length == 0 && (UseLocationExpression || DefaultValue == null)) { Expression = null; } else { if (Text.Length == 0) { Text = DefaultValue; } ModelTreeManager modelTreeManager = Context.Services.GetService <ModelTreeManager>(); ActivityWithResult newExpression = CSharpExpressionHelper.CreateExpressionFromString(Text, UseLocationExpression, resultType); ModelItem expressionItem = modelTreeManager.CreateModelItem(null, newExpression); Expression = expressionItem; } scope.Complete(); } } }
public static ModelItem CreateModelItem(object objectToMakeModelItem) { EditingContext ec = new EditingContext(); ModelTreeManager mtm = new ModelTreeManager(ec); mtm.Load(objectToMakeModelItem); return(mtm.Root); }
public BookmarkUndoUnit(EditingContext context, ModelTreeManager modelTreeManager) : base(context) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); this.modelTreeManager = modelTreeManager; this.DoList = new List <UndoUnit>(); this.RedoList = new List <UndoUnit>(); }
public static ModelItem CreateModelItem(object objectToMakeModelItem) { EditingContext ec = new EditingContext(); ModelTreeManager mtm = new ModelTreeManager(ec); mtm.Load(objectToMakeModelItem); return mtm.Root; }
internal static EditingScope TryCreateImmediateEditingScope(ModelTreeManager manager, string editingScopeDescription) { if (manager.CanCreateImmediateEditingScope()) { return(manager.CreateEditingScope(editingScopeDescription, true)); } return(null); }
internal EditingScope(ModelTreeManager modelTreeManager, EditingScope outerScope) { this.modelTreeManager = modelTreeManager; this.changes = new List <Change>(); this.outerScope = outerScope; this.HasModelChanges = false; this.itemsAdded = new HashSet <ModelItem>(); this.itemsRemoved = new HashSet <ModelItem>(); }
void GetAvailableNamespaces() { Fx.Assert(this.availableNamespaces != null, "available namespace table should have been set before calling this method"); AssemblyContextControlItem assemblyItem = this.Context.Items.GetValue <AssemblyContextControlItem>(); if (assemblyItem != null) { IMultiTargetingSupportService multiTargetingService = this.Context.Services.GetService <IMultiTargetingSupportService>(); ////When ReferencedAssemblyNames is null, it's in rehost scenario. And we need to preload assemblies in ////TextExpression.ReferencesForImplementation/References if there is any. So that these assemblies will be returned ////by AssemblyContextControlItem.GetEnvironmentAssemblies and user can see namespaces defined in these assemlbies ////in the dropdown list of Import Designer. if ((assemblyItem.ReferencedAssemblyNames == null) && (this.targetFramework.Is45OrHigher())) { ModelTreeManager modelTreeManager = this.Context.Services.GetService <ModelTreeManager>(); object root = modelTreeManager.Root.GetCurrentValue(); IList <AssemblyReference> references; NamespaceHelper.GetTextExpressionNamespaces(root, out references); foreach (AssemblyReference reference in references) { reference.LoadAssembly(); } } IEnumerable <Assembly> allAssemblies = assemblyItem.GetEnvironmentAssemblies(multiTargetingService); if (assemblyItem.LocalAssemblyName != null) { allAssemblies = allAssemblies.Union <Assembly>(new Collection <Assembly> { AssemblyContextControlItem.GetAssembly(assemblyItem.LocalAssemblyName, multiTargetingService) }); } foreach (Assembly assembly in allAssemblies) { try { if (assembly != null) { Fx.Assert(!assembly.IsDynamic, "there should not be any dynamic assemblies in reference list"); this.UpdateAvailableNamespaces(assembly, assemblyItem); } } catch (ReflectionTypeLoadException) { } catch (FileNotFoundException) { } } if (assemblyItem.LocalAssemblyName == null) { AppDomain.CurrentDomain.AssemblyLoad += this.proxy.OnAssemblyLoad; } } }
public static ModelItemCollection CreateModelItemCollection(ICollection objectToMakeModelItem) { EditingContext ec = new EditingContext(); ModelTreeManager mtm = new ModelTreeManager(ec); mtm.Load(objectToMakeModelItem); return(mtm.Root as ModelItemCollection); }
internal static EditingScope TryCreateImmediateEditingScope(ModelTreeManager manager, string editingScopeDescription) { if (manager.CanCreateImmediateEditingScope()) { return manager.CreateEditingScope(editingScopeDescription, true); } return null; }
internal EditingScope(ModelTreeManager modelTreeManager, EditingScope outerScope) { this.modelTreeManager = modelTreeManager; this.changes = new List<Change>(); this.outerScope = outerScope; this.HasModelChanges = false; this.itemsAdded = new HashSet<ModelItem>(); this.itemsRemoved = new HashSet<ModelItem>(); }
public BookmarkUndoUnit(EditingContext context, ModelTreeManager modelTreeManager) : base(context) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); this.modelTreeManager = modelTreeManager; this.DoList = new List<UndoUnit>(); this.RedoList = new List<UndoUnit>(); }
public ErrorsMarkedEventArgs(ICollection <ValidationError> errors, ValidationReason reason, ModelTreeManager modelTreeManager, EditingContext context) { this.errors = errors; this.reason = reason; this.modelTreeManager = modelTreeManager; this.context = context; }
public ErrorsMarkedEventArgs(ICollection<ValidationError> errors, ValidationReason reason, ModelTreeManager modelTreeManager, EditingContext context) { this.errors = errors; this.reason = reason; this.modelTreeManager = modelTreeManager; this.context = context; }
private void SetDesigner(string filePath = null) { _wfDesigner = CustomWfDesigner.NewInstance(filePath); modelTreeManager = _wfDesigner.Context.Services.GetService <ModelTreeManager>(); if (modelTreeManager != null) { modelTreeManager.EditingScopeCompleted -= ModelTreeManager_EditingScopeCompleted; } modelTreeManager.EditingScopeCompleted += ModelTreeManager_EditingScopeCompleted; WfDesignerBorder.Child = _wfDesigner.View; WfPropertyBorder.Child = _wfDesigner.PropertyInspectorView; }
public EditingScopeUndoUnit(EditingContext context, ModelTreeManager modelTreeManager, EditingScope editingScope) : base(context) { Fx.Assert(context != null, "context cannot be null"); Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); Fx.Assert(editingScope != null, "editingScope cannot be null"); this.context = context; this.modelTreeManager = modelTreeManager; this.editingScope = editingScope; this.Description = this.editingScope.Description; SaveGlobalState(); }
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 StartSymbol CreateStartSymbol(EditingContext context) { StartSymbol start = new StartSymbol(); FakeRoot fakeRoot = new FakeRoot { StartNode = new StartNode() }; ModelTreeManager manager = context.Services.GetService <ModelTreeManager>(); start.ModelItem = new FakeModelItemImpl(manager, typeof(FakeRoot), fakeRoot, null).Properties["StartNode"].Value; start.Name = "StartSymbol"; start.Focusable = true; start.Context = context; start.DataContext = start; return(start); }
/// <summary> /// Updates the PropertyGrid's properties /// </summary> public void RefreshPropertyList() { var context = new EditingContext(); var mtm = new ModelTreeManager(context); mtm.Load(this.SelectedObject); var selection = Selection.Select(context, mtm.Root); OnSelectionChangedMethod.Invoke(Designer.PropertyInspectorView, new object[] { selection }); // var olditem = this.SelectedObject; // this.SelectedObject = null; // this.SelectedObject = olditem; //RefreshMethod.Invoke(Designer.PropertyInspectorView, new object[] { false }); }
public bool TryReplaceArgument(ModelTreeManager modelTreeManager, ValidationService validationService) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null."); Fx.Assert(validationService != null, "validationService cannot be null."); ModelItem expressionModelItem = modelTreeManager.GetModelItem(this.ExpressionToReplace); if (expressionModelItem != null) { ModelItem argumentModelItem = expressionModelItem.Parent; ModelItem parentObject = argumentModelItem.Parent; if (argumentModelItem.Source != null) { ModelProperty argumentProperty = parentObject.Properties[argumentModelItem.Source.Name]; Type argumentPropertyType = argumentProperty.PropertyType; if (argumentPropertyType == typeof(InArgument) || argumentPropertyType == typeof(OutArgument) || argumentPropertyType == typeof(InOutArgument)) { ModelItem oldArgumentModel = argumentProperty.Value; ModelItem newArgumentModel = argumentProperty.SetValue(this.NewArgument); // Make sure argument.Expression is wrapped in ModelItem as well ModelItem newExpressionModel = newArgumentModel.Properties["Expression"].Value; return(true); } } } else { Activity parentActivity = ValidationService.GetParent(this.ExpressionToReplace); if (this.ArgumentAccessor.Setter != null) { try { validationService.DeactivateValidation(); this.ArgumentAccessor.Setter(parentActivity, this.NewArgument); return(true); } finally { validationService.ActivateValidation(); } } } return(false); }
internal static ModelEditingScope ModelItemBeginEdit(ModelTreeManager modelTreeManager, string description, bool shouldApplyChangesImmediately) { if (shouldApplyChangesImmediately && modelTreeManager.Context.Services.GetService<UndoEngine>().IsBookmarkInPlace) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidNestedModelItemBeginEditExceptionMessage)); } EditingScope editingScope = modelTreeManager.CreateEditingScope(description, shouldApplyChangesImmediately); if (shouldApplyChangesImmediately && editingScope == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidNestedModelItemBeginEditExceptionMessage)); } return editingScope; }
internal static ModelEditingScope ModelItemBeginEdit(ModelTreeManager modelTreeManager, string description, bool shouldApplyChangesImmediately) { if (shouldApplyChangesImmediately && modelTreeManager.Context.Services.GetService <UndoEngine>().IsBookmarkInPlace) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidNestedModelItemBeginEditExceptionMessage)); } EditingScope editingScope = modelTreeManager.CreateEditingScope(description, shouldApplyChangesImmediately); if (shouldApplyChangesImmediately && editingScope == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidNestedModelItemBeginEditExceptionMessage)); } return(editingScope); }
private static void SelectedObjectsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { WpfPropertyGrid pg = source as WpfPropertyGrid; pg.CoerceValue(SelectedObjectsProperty); object[] collection = e.NewValue as object[]; if (collection.Length == 0) { pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null }); pg.SelectionTypeLabel.Text = string.Empty; } else { bool same = true; Type first = null; var context = new EditingContext(); var mtm = new ModelTreeManager(context); Selection selection = null; // Accumulates the selection and determines the type to be shown in the top of the PG for (int i = 0; i < collection.Length; i++) { mtm.Load(collection[i]); if (i == 0) { selection = Selection.Select(context, mtm.Root); first = collection[0].GetType(); } else { selection = Selection.Union(context, mtm.Root); if (!collection[i].GetType().Equals(first)) { same = false; } } } pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection }); pg.SelectionTypeLabel.Text = same ? first.Name + " <multiple>" : "Object <multiple>"; } pg.ChangeHelpText(string.Empty, string.Empty); }
public override IEnumerable <ModelItem> Find(ModelItem startingItem, Type type) { if (startingItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("startingItem")); } if (type == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("type")); } Fx.Assert(!type.IsValueType, "hmm why would some one search for modelitems for value types?"); return(ModelTreeManager.Find(startingItem, delegate(ModelItem modelItem) { return type.IsAssignableFrom(modelItem.ItemType); }, false)); }
public ModelItemImpl(ModelTreeManager modelTreeManager, Type itemType, object instance, ModelItem parent) { this.itemType = itemType; this.instance = instance; this.modelTreeManager = modelTreeManager; this.parents = new ObservableCollection <ModelItem>(); this.internalParents = new ReadOnlyObservableCollection <ModelItem>(parents); this.sources = new ObservableCollection <ModelProperty>(); this.helper = new ModelTreeItemHelper(); this.internalSources = new ReadOnlyObservableCollection <ModelProperty>(sources); if (parent != null) { this.manuallySetParent = parent; } this.modelPropertyStore = new Dictionary <string, ModelItem>(); this.subTreeNodesThatNeedBackLinkPatching = new List <ModelItem>(); }
public ModelItemImpl(ModelTreeManager modelTreeManager, Type itemType, object instance, ModelItem parent) { this.itemType = itemType; this.instance = instance; this.modelTreeManager = modelTreeManager; this.parents = new ObservableCollection<ModelItem>(); this.internalParents = new ReadOnlyObservableCollection<ModelItem>(parents); this.sources = new ObservableCollection<ModelProperty>(); this.helper = new ModelTreeItemHelper(); this.internalSources = new ReadOnlyObservableCollection<ModelProperty>(sources); if (parent != null) { this.manuallySetParent = parent; } this.modelPropertyStore = new Dictionary<string, ModelItem>(); this.subTreeNodesThatNeedBackLinkPatching = new List<ModelItem>(); }
public override void StoreViewStateWithUndo(ModelItem modelItem, string key, object value) { object oldValue = RetrieveViewState(modelItem, key); ViewStateChange vsChange = new ViewStateChange(this) { Item = modelItem, Key = key, OldValue = oldValue, NewValue = value, }; ModelTreeManager modelTreeManager = this.context.Services.GetService <ModelTreeManager>(); if (modelTreeManager != null) { modelTreeManager.AddToCurrentEditingScope(vsChange); } }
private void AddDefaultArguments() { ModelTreeManager mtm = _workflowDesigner.Context.Services.GetService <ModelTreeManager>(); ModelItem ab = mtm.Root; ModelItemCollection argsAndProperties = ab.Properties["Properties"].Collection; argsAndProperties.Add(new DynamicActivityProperty { Name = "ArgFileSystemItemId", Type = typeof(InArgument <int>), }); argsAndProperties.Add(new DynamicActivityProperty { Name = "ArgSessionId", Type = typeof(InArgument <string>), }); }
// CreateImmediateEditingScope - creates a new ImmediateEditingScope which gatters all edits in its // undo unit list. all changes in ImmediateEditingScope appear as a one change and can be // undoned or redoned as a one set. internal ImmediateEditingScope CreateImmediateEditingScope(string bookmarkName, ModelTreeManager modelTreeManager) { Fx.Assert(modelTreeManager != null, "modelTreeManager should not be null."); //only one bookmark is supported Fx.Assert(this.bookmark == null, "Nested bookmarks are not supported."); //create bookmark undo unit, and give it a description BookmarkUndoUnit unit = new BookmarkUndoUnit(this.context, modelTreeManager) { Description = bookmarkName ?? string.Empty, }; //create bookmark, and pass bookmark undo unit to it. this.bookmark = new Bookmark(this, unit); //switch implementation of AddUndoUnit, Undo, Redo to be delegated through bookmark this.undoEngineImpl = bookmark; return new ImmediateEditingScope(modelTreeManager, this.bookmark); }
public ModelItemCollectionImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); Fx.Assert(itemType != null, "item type cannot be null"); Fx.Assert(instance != null, "instance cannot be null"); this.itemType = itemType; this.instance = instance; this.modelTreeManager = modelTreeManager; this.parents = new List<ModelItem>(1); this.sources = new List<ModelProperty>(1); this.helper = new ModelTreeItemHelper(); if (parent != null) { this.manuallySetParent = parent; } this.modelPropertyStore = new Dictionary<string, ModelItem>(); this.subTreeNodesThatNeedBackLinkPatching = new List<ModelItem>(); this.modelItems = new List<ModelItem>(); UpdateInstance(instance); }
// Find model item and properly create it if necessary. internal static ModelItem FindModelItem(ModelTreeManager modelTreeManager, object sourceDetail) { if (sourceDetail == null) { return null; } Fx.Assert(modelTreeManager != null, "modelTreeManager != null"); Activity element = sourceDetail as Activity; object errorTarget = sourceDetail; // if source detail is not an Activity, we just expand the model tree to search it. if (element == null) { return ModelTreeManager.FindFirst(modelTreeManager.Root, (modelItem) => (modelItem.GetCurrentValue() == errorTarget)); } else { return FindActivityModelItem(modelTreeManager, element); } }
private static ModelItem FindActivityModelItem(ModelTreeManager modelTreeManager, Activity errorTarget) { // Search the lowest Activity ModelItem lowestModelItem = null; List<Activity> parentChain = GetParentChain(errorTarget); Fx.Assert(parentChain != null, "Cannot find parent chain for " + errorTarget.DisplayName); foreach (Activity parent in parentChain) { lowestModelItem = modelTreeManager.GetModelItem(parent); if (lowestModelItem != null) { break; } } ModelItem foundItem = null; // Find in nearest parent first. if (lowestModelItem != null) { // The foundItem could be null because lowestModelItem is not errorTarget's parent any more. // This happens if background validation hasn't finished updating errorTarget's parent. foundItem = ModelTreeManager.FindFirst(lowestModelItem, (modelItem) => (modelItem.GetCurrentValue() == errorTarget)); } // Not found, search from root. if (foundItem == null) { foundItem = FindActivityModelItemFromRoot(modelTreeManager, errorTarget); } return foundItem; }
private static ModelItem FindActivityModelItemFromRoot(ModelTreeManager modelTreeManager, Activity errorTarget) { ModelItem root = modelTreeManager.Root; Fx.Assert(root != null && errorTarget != null, "root != null && errorTarget != null"); ModelProperty property = root.Properties["Properties"]; ModelItem propertiesModelItem = property == null ? null : property.Value; ModelItem foundItem = null; if (propertiesModelItem != null) { // So,search "Properties" first to delay expanding "Implementation" and other properties. foundItem = ModelTreeManager.FindFirst(propertiesModelItem, (modelItem) => (modelItem.GetCurrentValue() == errorTarget)); } // If activity is not in Properties, expand others except Properties. foundItem = foundItem ?? ModelTreeManager.FindFirst( root, (modelItem) => (modelItem.GetCurrentValue() == errorTarget), (modelItem) => { return modelItem != propertiesModelItem; }); return foundItem; }
// Returns a wrapped converter for the given item. internal static TypeConverter GetConverter(ModelTreeManager modelTreeManager, ModelItem item) { return new ModelTypeConverter(modelTreeManager, XamlUtilities.GetConverter(item.ItemType)); }
void OnModelTreeManagerServiceAvailable(ModelTreeManager modelTreeManager) { this.modelTreeManager = modelTreeManager; this.modelTreeManager.EditingScopeCompleted += OnEditingScopeCompleted; }
internal ModelTypeConverter(ModelTreeManager modelTreeManager, TypeConverter converter) { this.modelTreeManager = modelTreeManager; this.converter = converter; }
public FakeModelItemImpl(ModelTreeManager modelTreeManager, Type itemType, object instance, FakeModelItemImpl parent) : base(modelTreeManager, itemType, instance, parent) { }
public bool TryReplaceArgument(ModelTreeManager modelTreeManager, ValidationService validationService) { Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null."); Fx.Assert(validationService != null, "validationService cannot be null."); ModelItem expressionModelItem = modelTreeManager.GetModelItem(this.ExpressionToReplace); if (expressionModelItem != null) { ModelItem argumentModelItem = expressionModelItem.Parent; ModelItem parentObject = argumentModelItem.Parent; if (argumentModelItem.Source != null) { ModelProperty argumentProperty = parentObject.Properties[argumentModelItem.Source.Name]; Type argumentPropertyType = argumentProperty.PropertyType; if (argumentPropertyType == typeof(InArgument) || argumentPropertyType == typeof(OutArgument) || argumentPropertyType == typeof(InOutArgument)) { ModelItem oldArgumentModel = argumentProperty.Value; ModelItem newArgumentModel = argumentProperty.SetValue(this.NewArgument); // Make sure argument.Expression is wrapped in ModelItem as well ModelItem newExpressionModel = newArgumentModel.Properties["Expression"].Value; return true; } } } else { Activity parentActivity = ValidationService.GetParent(this.ExpressionToReplace); if (this.ArgumentAccessor.Setter != null) { try { validationService.DeactivateValidation(); this.ArgumentAccessor.Setter(parentActivity, this.NewArgument); return true; } finally { validationService.ActivateValidation(); } } } return false; }
private static void SelectedObjectsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { WpfPropertyGrid pg = source as WpfPropertyGrid; pg.CoerceValue(SelectedObjectsProperty); object[] collection = e.NewValue as object[]; if (collection.Length == 0) { pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null }); pg.SelectionTypeLabel.Text = string.Empty; } else { bool same = true; Type first = null; var context = new EditingContext(); var mtm = new ModelTreeManager(context); Selection selection = null; // Accumulates the selection and determines the type to be shown in the top of the PG for (int i = 0; i < collection.Length; i++) { mtm.Load(collection[i]); if (i == 0) { selection = Selection.Select(context, mtm.Root); first = collection[0].GetType(); } else { selection = Selection.Union(context, mtm.Root); if (!collection[i].GetType().Equals(first)) same = false; } } pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection }); pg.SelectionTypeLabel.Text = same ? first.Name + " <multiple>" : "Object <multiple>"; } pg.ChangeHelpText(string.Empty, string.Empty); }
private static void SelectedObjectPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { WpfPropertyGrid pg = source as WpfPropertyGrid; pg.CoerceValue(SelectedObjectsProperty); if (e.NewValue == null) { pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { null }); pg.SelectionTypeLabel.Text = string.Empty; } else { var context = new EditingContext(); var mtm = new ModelTreeManager(context); mtm.Load(e.NewValue); Selection selection = Selection.Select(context, mtm.Root); pg.OnSelectionChangedMethod.Invoke(pg.Designer.PropertyInspectorView, new object[] { selection }); pg.SelectionTypeLabel.Text = e.NewValue.GetType().Name; } pg.ChangeHelpText(string.Empty, string.Empty); }
// This supports loading objects instead of xaml into the designer public void Load(object instance) { if (isLoaded) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowDesignerLoadShouldBeCalledOnlyOnce)); } isLoaded = true; if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } DesignerConfigurationService configurationService = this.context.Services.GetService<DesignerConfigurationService>(); configurationService.ApplyDefaultPreference(); // Because we want AutoConnect/AutoSplit to be on even in Dev10 if PU1 is installed. // But we cannot know whether PU1 is installed or not, we decide to enable these 2 features for all Dev10. if (configurationService.WorkflowDesignerHostId == WorkflowDesignerHostId.Dev10) { configurationService.AutoConnectEnabled = true; configurationService.AutoSplitEnabled = true; } configurationService.IsWorkflowLoaded = true; configurationService.Validate(); if (this.PreviewLoad != null) { this.PreviewLoad(this, new PreviewLoadEventArgs(instance, this.context)); } if (configurationService.TargetFrameworkName.IsLessThan45()) { TargetFrameworkPropertyFilter.FilterOut45Properties(); } modelTreeManager = new ModelTreeManager(this.context); modelTreeManager.Load(instance); this.context.Services.Publish(typeof(ModelTreeManager), modelTreeManager); viewManager = GetViewManager(this.modelTreeManager.Root); this.context.Services.Publish<ModelSearchService>(this.ModelSearchService); view.Children.Add((UIElement)viewManager.View); modelTreeManager.EditingScopeCompleted += new EventHandler<EditingScopeEventArgs>(OnEditingScopeCompleted); this.view.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { this.perfEventProvider.WorkflowDesignerApplicationIdleAfterLoad(); })); //Subscribe to the ViewStateChanged event of ViewStateService to show document dirty. It would be published in the call to GetViewManager(). WorkflowViewStateService wfViewStateService = this.Context.Services.GetService(typeof(ViewStateService)) as WorkflowViewStateService; if (wfViewStateService != null) { wfViewStateService.UndoableViewStateChanged += new ViewStateChangedEventHandler(OnViewStateChanged); } this.isModelChanged = false; }
internal ModelTypeDescriptorContextWrapper(ITypeDescriptorContext context, ModelTreeManager modelTreeManager) { this.context = context; this.modelTreeManager = modelTreeManager; }
internal static string GetRootEditorSetting(ModelTreeManager modelTreeManager, FrameworkName targetFramework) { return ExpressionSettingHelper.GetRootEditorSetting(modelTreeManager, targetFramework); }
private void OnModelTreeManagerAvailable(ModelTreeManager modelTreeManager) { modelTreeManager.EditingScopeCompleted += new EventHandler<EditingScopeEventArgs>(OnEditingScopeCompleted); }