internal ReferencesFoundDialog(ReferencesFoundModel model) { this.model = model; FrameworkElement element = FileTable.GetElement("Resources\\ResourcePane\\ReferencesFoundDialog.xaml"); element.DataContext = (object)model; this.DialogContent = (UIElement)element; this.Title = StringTable.ReferencesFoundDialogTitle; this.SizeToContent = SizeToContent.WidthAndHeight; Button button1 = (Button)LogicalTreeHelper.FindLogicalNode((DependencyObject)this, ReferencesFoundDialog.AcceptButtonName); if (button1 != null) { button1.IsDefault = false; } Button button2 = (Button)LogicalTreeHelper.FindLogicalNode((DependencyObject)this, ReferencesFoundDialog.CancelButtonName); if (button2 != null) { button2.IsDefault = true; } TextBlock textBlock = (TextBlock)LogicalTreeHelper.FindLogicalNode((DependencyObject)this, ReferencesFoundDialog.ResourceNameTextBlock); if (textBlock == null) { return; } textBlock.Text = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ReferencesFoundDialogText, new object[1] { this.model.ResourceEntryNode.Key }); }
public FixupResourceReferenceAsyncProcess(ReferencesFoundModel model, IList <string> documentPaths) : base((IAsyncMechanism) new CurrentDispatcherAsyncMechanism(DispatcherPriority.Background)) { this.model = model; this.documentPaths = documentPaths; this.documentPathIndex = -1; }
protected override void Work() { IViewCollection views = this.model.ResourceEntryNode.ViewModel.DesignerContext.ViewService.Views; if (this.currentViewIndex < 0 || this.currentViewIndex >= views.Count) { return; } SceneView sceneView = views[this.currentViewIndex] as SceneView; if (sceneView == null) { return; } SceneViewModel viewModel = sceneView.ViewModel; if (viewModel == this.model.ResourceEntryNode.ViewModel || !viewModel.Document.IsEditable) { return; } List <SceneNode> list = new List <SceneNode>(); viewModel.FindInternalResourceReferences((DocumentCompositeNode)this.model.ResourceEntryNode.DocumentNode, (ICollection <SceneNode>)list); foreach (SceneNode node in list) { this.model.ReferenceNames.Add(ReferencesFoundModel.SceneNodeElementName(node)); this.model.AddReferencesFile(sceneView.ViewModel.Document); } }
private bool?ShowReferencesFoundDialog(ReferencesFoundModel model) { bool?nullable1 = new bool?(true); bool?nullable2 = new ReferencesFoundDialog(model).ShowDialog(); if (nullable2.GetValueOrDefault(false) && model.SelectedUpdateMethod != ReferencesFoundModel.UpdateMethod.DontFix) { nullable2 = new AsyncProcessDialog(model.FixReferencesAsync(), this.DesignerContext.ExpressionInformationService).ShowDialog(); } return(nullable2); }
public override void InteractiveDelete() { ReferencesFoundModel referencingResources = this.InteractiveGetReferencingResources(ReferencesFoundModel.UseScenario.DeleteResource); if (referencingResources == null || referencingResources.ReferenceNames.Count > 0 && !this.ShowReferencesFoundDialog(referencingResources).GetValueOrDefault(false)) { return; } PerformanceUtility.StartPerformanceSequence(PerformanceEvent.DeleteResourceItem); SceneViewModel viewModel = this.Container.ViewModel; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitDeleteResource)) { this.Container.ResourceDictionaryNode.Remove((DictionaryEntryNode)viewModel.GetSceneNode((DocumentNode)this.resource.ResourceNode)); editTransaction.Commit(); } PerformanceUtility.EndPerformanceSequence(PerformanceEvent.DeleteResourceItem); }
public ReferencesFoundModel(SceneNode resourceEntryNode, ICollection <SceneNode> references, ReferencesFoundModel.UseScenario useScenario) { this.resourceEntryNode = resourceEntryNode; foreach (SceneNode node in (IEnumerable <SceneNode>)references) { this.referenceNames.Add(ReferencesFoundModel.SceneNodeElementName(node)); } if (references.Count > 0) { this.AddReferencesFile(resourceEntryNode.ViewModel.Document); } this.useScenario = useScenario; if (this.IsDeleting) { this.updateMethod = ReferencesFoundModel.UpdateMethod.ConvertToLocal; } else { this.updateMethod = ReferencesFoundModel.UpdateMethod.UpdateReferences; } }
internal ReferencesFoundModel InteractiveGetReferencingResources(ReferencesFoundModel.UseScenario useScenario) { SceneViewModel viewModel = this.Container.ViewModel; List <SceneNode> list = new List <SceneNode>(); viewModel.FindInternalResourceReferences(this.resource.ResourceNode, (ICollection <SceneNode>)list); ITypeId type = (ITypeId)viewModel.RootNode.Type; bool flag = PlatformTypes.ResourceDictionary.IsAssignableFrom(type) || PlatformTypes.Application.IsAssignableFrom(type); ReferencesFoundModel model = new ReferencesFoundModel(viewModel.GetSceneNode((DocumentNode)this.resource.ResourceNode), (ICollection <SceneNode>)list, useScenario); if (list.Count > 0 || flag) { if (!new AsyncProcessDialog((AsyncProcess) new SerialAsyncProcess((IAsyncMechanism) new CurrentDispatcherAsyncMechanism(DispatcherPriority.Background), new AsyncProcess[2] { (AsyncProcess) new ExternalOpenSceneResourceReferenceAnalyzer(model), (AsyncProcess) new ExternalClosedSceneResourceReferenceAnalyzer(model) }), this.DesignerContext.ExpressionInformationService).ShowDialog().GetValueOrDefault(false)) { model = (ReferencesFoundModel)null; } } return(model); }
public ExternalOpenSceneResourceReferenceAnalyzer(ReferencesFoundModel model) : base((IAsyncMechanism) new CurrentDispatcherAsyncMechanism(DispatcherPriority.Background)) { this.model = model; }
public ExternalClosedSceneResourceReferenceAnalyzer(ReferencesFoundModel model) : base((IAsyncMechanism) new CurrentDispatcherAsyncMechanism(DispatcherPriority.Background)) { this.model = model; this.projectDocuments = (IList <IProjectDocument>) new List <IProjectDocument>((IEnumerable <IProjectDocument>)model.ResourceEntryNode.ProjectContext.Documents); }
private bool MoveItem(ResourceEntryItem resourceEntry, ResourceContainer destinationContainer, int destinationIndex, bool skipReferencedResourceCopy, ReferencesFoundModel referencesFoundModel, bool doReferenceFixup) { bool flag = this.CopyItem(resourceEntry, destinationContainer, destinationIndex, skipReferencedResourceCopy); if (flag) { if (doReferenceFixup && !new AsyncProcessDialog(referencesFoundModel.FixReferencesAsync(), resourceEntry.Container.ViewModel.DesignerContext.ExpressionInformationService).ShowDialog().GetValueOrDefault(false)) { return(false); } DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)resourceEntry.Container.ViewModel.GetSceneNode((DocumentNode)resourceEntry.Resource.ResourceNode); using (SceneEditTransaction editTransaction = resourceEntry.Container.ViewModel.CreateEditTransaction(StringTable.UndoUnitDeleteResource)) { resourceEntry.Container.ResourceDictionaryNode.Remove(dictionaryEntryNode); editTransaction.Commit(); } } return(flag); }
protected void DoDrop(DragEventArgs eventArgs, int destinationIndex) { IDataObject data = eventArgs.Data; if (this.ResourceManager.IsFiltering) { return; } ResourceEntryItem resourceEntry = (ResourceEntryItem)null; if (!this.CanDrop(eventArgs, out resourceEntry) || resourceEntry == this) { return; } ResourceContainer dropTargetContainer = this.DragDropTargetContainer; if (resourceEntry.Container == dropTargetContainer) { if ((eventArgs.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey) { using (SceneEditTransaction editTransaction = resourceEntry.Container.ViewModel.CreateEditTransaction(StringTable.UndoUnitCopyResource)) { DocumentCompositeNode entryNode = resourceEntry.Resource.ResourceNode.Clone(dropTargetContainer.ViewModel.Document.DocumentContext) as DocumentCompositeNode; DocumentNode keyNode = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.GenerateUniqueResourceKey(resourceEntry.Key.ToString(), dropTargetContainer.Node); ResourceNodeHelper.SetResourceEntryKey(entryNode, keyNode); Microsoft.Expression.DesignSurface.Utility.ResourceHelper.AddResource((DictionaryEntryNode)dropTargetContainer.ViewModel.GetSceneNode((DocumentNode)entryNode), dropTargetContainer.ResourceDictionaryNode, destinationIndex); editTransaction.Commit(); } } else { resourceEntry.Container.MoveItem(resourceEntry, destinationIndex); } } else { ObservableCollection <string> observableCollection = new ObservableCollection <string>(); observableCollection.Add(dropTargetContainer.DocumentContext.DocumentUrl); bool skipReferencedResourceCopy = this.IsContainerReachable((IEnumerable <string>)observableCollection, resourceEntry.Container); if ((eventArgs.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey) { this.CopyItem(resourceEntry, dropTargetContainer, destinationIndex, skipReferencedResourceCopy); } else { ReferencesFoundModel referencingResources = resourceEntry.InteractiveGetReferencingResources(ReferencesFoundModel.UseScenario.DeleteResource); if (referencingResources == null) { return; } bool doReferenceFixup = false; if (referencingResources.ReferenceNames.Count > 0 && !this.IsContainerReachable((IEnumerable <string>)referencingResources.ScenesWithReferences, dropTargetContainer)) { if (!new ReferencesFoundDialog(referencingResources).ShowDialog().GetValueOrDefault(false)) { return; } doReferenceFixup = referencingResources.SelectedUpdateMethod != ReferencesFoundModel.UpdateMethod.DontFix; } if (dropTargetContainer.ViewModel == resourceEntry.Container.ViewModel) { using (SceneEditTransaction editTransaction = dropTargetContainer.ViewModel.CreateEditTransaction(StringTable.UndoUnitMoveResource)) { if (this.MoveItem(resourceEntry, dropTargetContainer, destinationIndex, skipReferencedResourceCopy, referencingResources, doReferenceFixup)) { editTransaction.Commit(); } else { editTransaction.Cancel(); } } } else { this.MoveItem(resourceEntry, dropTargetContainer, destinationIndex, skipReferencedResourceCopy, referencingResources, doReferenceFixup); } } } }
private void InteractiveRenameResource() { if (this.DocumentNode == null || this.DocumentNode.DocumentRoot == null || this.DocumentNode.DocumentRoot.DocumentContext == null) { return; } string key = this.currentName; this.currentName = (string)null; if (key == null || key.Equals(this.resource.Name)) { this.OnKeyChanged(); } else { SceneViewModel viewModel = this.Container.ViewModel; if (new ResourceSite(viewModel.Document.DocumentContext, this.Container.ResourcesCollection).FindResource((IDocumentRootResolver)null, key, (ICollection <DocumentCompositeNode>)null, (ICollection <IDocumentRoot>)null) != null) { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.CreateResourceKeyStringIssueDirectConflict); this.OnKeyChanged(); } else { List <SceneNode> list = new List <SceneNode>(); ReferencesFoundModel model = (ReferencesFoundModel)null; viewModel.FindInternalResourceReferences(this.resource.ResourceNode, (ICollection <SceneNode>)list); ITypeId type = (ITypeId)viewModel.RootNode.Type; bool flag = PlatformTypes.ResourceDictionary.IsAssignableFrom(type) || PlatformTypes.Application.IsAssignableFrom(type); DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)viewModel.GetSceneNode((DocumentNode)this.resource.ResourceNode); if (list.Count > 0 || flag) { model = new ReferencesFoundModel((SceneNode)dictionaryEntryNode, (ICollection <SceneNode>)list, ReferencesFoundModel.UseScenario.RenameResource); bool valueOrDefault = new AsyncProcessDialog((AsyncProcess) new SerialAsyncProcess((IAsyncMechanism) new CurrentDispatcherAsyncMechanism(DispatcherPriority.Background), new AsyncProcess[2] { (AsyncProcess) new ExternalOpenSceneResourceReferenceAnalyzer(model), (AsyncProcess) new ExternalClosedSceneResourceReferenceAnalyzer(model) }), this.DesignerContext.ExpressionInformationService).ShowDialog().GetValueOrDefault(false); if (valueOrDefault && model.ReferenceNames.Count > 0) { valueOrDefault = new ReferencesFoundDialog(model).ShowDialog().GetValueOrDefault(false); } if (!valueOrDefault) { this.OnKeyChanged(); return; } } using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitRenameResource)) { if (model != null && model.SelectedUpdateMethod != ReferencesFoundModel.UpdateMethod.DontFix && model.ReferenceNames.Count > 0) { model.NewKey = (object)key; new AsyncProcessDialog(model.FixReferencesAsync(), this.DesignerContext.ExpressionInformationService).ShowDialog(); } dictionaryEntryNode.Key = (object)key; editTransaction.Commit(); } this.OnKeyChanged(); } } }