public void CreateImageBrushResource(ResourceContainer container, IProjectItem item) { SceneViewModel viewModel = container.ViewModel; string resourceReference = item.GetResourceReference(viewModel.Document.DocumentReference); ImageBrushNode imageBrushNode = (ImageBrushNode)viewModel.CreateSceneNode(PlatformTypes.ImageBrush); imageBrushNode.Source = resourceReference; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitPaste, false)) { IType type = viewModel.ProjectContext.ResolveType(PlatformTypes.ImageBrush); new CreateResourceModel(viewModel, viewModel.DesignerContext.ResourceManager, type.RuntimeType, (Type)null, (string)null, container.Node as SceneElement, (SceneNode)null, CreateResourceModel.ContextFlags.None) { KeyString = Path.GetFileNameWithoutExtension(resourceReference) }.CreateResource(imageBrushNode.DocumentNode, (IPropertyId)null, -1); editTransaction.Commit(); } }
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); }
private bool CanDrop(DragEventArgs e, out ResourceEntryItem resourceEntry) { resourceEntry = (ResourceEntryItem)null; ResourceContainer dropTargetContainer = this.DragDropTargetContainer; if (dropTargetContainer != null && !dropTargetContainer.DocumentHasErrors && dropTargetContainer.DocumentNode != null) { IDataObject data = e.Data; if (data != null && data.GetDataPresent("ResourceEntryItem", true)) { resourceEntry = (ResourceEntryItem)data.GetData("ResourceEntryItem", true); if (resourceEntry != null && resourceEntry.DocumentNode != null && PlatformTypes.PlatformsCompatible(dropTargetContainer.ProjectContext.PlatformMetadata, resourceEntry.DocumentNode.PlatformMetadata)) { return(true); } } } return(false); }
private void AddExternalDictionaries(ResourceManager resourceManager, ResourceContainer resourceContainer) { List <ResourceDictionaryItem> list = new List <ResourceDictionaryItem>(); resourceManager.FindAllReachableDictionaries(resourceContainer, (ICollection <ResourceDictionaryItem>)list); foreach (ResourceDictionaryItem resourceDictionaryItem in list) { DocumentResourceContainer resourceContainer1 = resourceManager.FindResourceContainer(resourceDictionaryItem.DesignTimeSource) as DocumentResourceContainer; if (resourceContainer1 != null && !this.externalResourceDictionaries.Contains((ResourceContainer)resourceContainer1) && PlatformTypes.PlatformsCompatible(this.viewModel.ProjectContext.PlatformMetadata, resourceContainer1.ProjectContext.PlatformMetadata)) { this.externalResourceDictionaries.Add((ResourceContainer)resourceContainer1); } } if (this.selectedExternalResourceDictionaryFile != null || this.externalResourceDictionaries.Count <= 0) { return; } this.selectedExternalResourceDictionaryFile = this.externalResourceDictionaries[0]; }
public static ResourceItem GetTypedItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel model) { ITypeId type = (ITypeId)model.ValueNode.Type; if (PlatformTypes.Brush.IsAssignableFrom(type)) { return((ResourceItem) new BrushResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.DrawingImage.IsAssignableFrom(type)) { return((ResourceItem) new DrawingImageResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.Transform.IsAssignableFrom(type) || PlatformTypes.Transform3D.IsAssignableFrom(type)) { return((ResourceItem) new TransformResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.Style.IsAssignableFrom(type)) { return((ResourceItem) new StyleResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.ControlTemplate.IsAssignableFrom(type)) { return((ResourceItem) new ControlTemplateResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.DataTemplate.IsAssignableFrom(type)) { return((ResourceItem) new DataTemplateResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.ItemsPanelTemplate.IsAssignableFrom(type)) { return((ResourceItem) new ItemsPanelTemplateResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.Timeline.IsAssignableFrom(type)) { return((ResourceItem) new TimelineResourceItem(resourceManager, resourceContainer, model)); } if (PlatformTypes.XmlDataProvider.IsAssignableFrom(type)) { return((ResourceItem) new DataSourceResourceItem(resourceManager, resourceContainer, model)); } return((ResourceItem) new ResourceEntryItem(resourceManager, resourceContainer, model)); }
protected override ObservableCollectionWorkaround <LocalResourceModel> RecalculateLocalResources(ObservableCollectionWorkaround <LocalResourceModel> currentResources) { List <ResourceContainer> activeContainers = new List <ResourceContainer>(); ResourceContainer container = this.resource.Container; if (container is NodeResourceContainer) { foreach (ResourceContainer resourceContainer in this.designerContext.ResourceManager.ActiveResourceContainers) { if (resourceContainer.DocumentNode.DocumentRoot == container.DocumentNode.DocumentRoot && resourceContainer.DocumentNode.IsAncestorOf(container.DocumentNode)) { activeContainers.Add(resourceContainer); } } } else { activeContainers.Add(container); } return(this.ProvideLocalResources(activeContainers)); }
internal void UpdateResourceList(ResourceManager resourceManager) { ResourceContainer resourceContainer1 = this.selectedExternalResourceDictionaryFile; ResourceContainer resourceContainer2 = this.selectedResourceDictionary != null ? this.selectedResourceDictionary.Instance : resourceManager.ActiveRootContainer; this.externalResourceDictionaries.Clear(); this.thisDocumentResourceDictionaries.Clear(); this.selectedExternalResourceDictionaryFile = (ResourceContainer)null; this.selectedResourceDictionary = (Named <ResourceContainer>)null; ResourceContainer resourceContainer3 = resourceManager.TopLevelResourceContainer; if (resourceManager.ActiveSceneViewModel == this.viewModel && resourceManager.ActiveRootContainer is NodeResourceContainer) { foreach (ResourceContainer resourceContainer4 in resourceManager.ActiveResourceContainers) { if (resourceContainer4.IsInScope) { if (resourceContainer4 == resourceContainer3) { resourceContainer3 = (ResourceContainer)null; } NodeResourceContainer nodeResourceContainer; this.thisDocumentResourceDictionaries.Add((nodeResourceContainer = resourceContainer4 as NodeResourceContainer) == null ? new Named <ResourceContainer>(resourceContainer4.Name, resourceContainer4, resourceContainer4.DocumentReference.Path) : this.CreateNamedResourceContainer(nodeResourceContainer)); this.AddExternalDictionaries(resourceManager, resourceContainer4); } } } IProject currentProject = ProjectHelper.GetProject(this.viewModel.DesignerContext.ProjectManager, this.viewModel.Document.DocumentContext); foreach (DocumentResourceContainer resourceContainer4 in Enumerable.Where <DocumentResourceContainer>((IEnumerable <DocumentResourceContainer>)resourceManager.DocumentResourceContainers, (Func <DocumentResourceContainer, bool>)(documentContainer => { if (!documentContainer.ProjectItem.ContainsDesignTimeResources) { return(false); } if (documentContainer.ProjectItem.Project != currentProject) { return(ProjectHelper.DoesProjectReferencesContainTarget(currentProject, documentContainer.ProjectContext)); } return(true); }))) { this.AddExternalDictionaries(resourceManager, (ResourceContainer)resourceContainer4); } if (resourceContainer3 != null) { if (resourceContainer3 is DocumentResourceContainer && resourceContainer3.Document != this.applicationDocument) { this.externalResourceDictionaries.Add(resourceContainer3); } this.AddExternalDictionaries(resourceManager, resourceContainer3); } if (this.explicitResourcesHost != null) { this.thisDocumentResourceDictionaries.Add(this.explicitResourcesHost); } foreach (Named <ResourceContainer> named in (Collection <Named <ResourceContainer> >) this.thisDocumentResourceDictionaries) { if (named.Instance == resourceContainer2) { this.SelectedResourceDictionary = named; break; } } if (this.externalResourceDictionaries.Contains(resourceContainer1)) { this.SelectedExternalResourceDictionaryFile = resourceContainer1; } this.OnPropertyChanged("CanDefineInOtherDocument"); }
protected ResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer) { this.resourceManager = resourceManager; this.resourceContainer = resourceContainer; }
protected TypedResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer, resource) { }
public LinkToResourcesCommand(ResourceManager resourceManager, ResourceContainer targetContainer, IProjectItem dictionaryItem) { this.resourceManager = resourceManager; this.targetContainer = targetContainer; this.dictionaryItem = dictionaryItem; }
public LinkToDesignTimeResourceCommand(DesignerContext context, ResourceContainer targetContainer) { this.context = context; this.targetContainer = targetContainer; this.resolver = new DesignTimeResourceResolver(this.context); }
private void PasteResource() { int index = -1; ResourceContainer container = (ResourceContainer)null; if (this.resourceManager.SelectedResourceContainers.Count == 1) { container = this.resourceManager.SelectedResourceContainers[0]; index = container.ResourceItems.Count; } else if (this.resourceManager.SelectedResourceItems.Count == 1) { ResourceItem resourceItem = this.resourceManager.SelectedResourceItems[0]; container = resourceItem.Container; index = container.ResourceItems.IndexOf(resourceItem) + 1; } SafeDataObject dataObject = SafeDataObject.FromClipboard(); if (index < 0) { return; } SceneViewModel viewModel = container.ViewModel; PastePackage pastePackage = PastePackage.FromData(viewModel, dataObject); if (pastePackage != null) { if (pastePackage.Elements.Count > 0) { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteResourcesFailedElementsFoundDialogMessage); } else { IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>(); foreach (SceneNode sceneNode in pastePackage.Resources) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitPaste)) { Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, container.Node, index, true); editTransaction.Commit(); } } } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { DesignerContext designerContext = viewModel.DesignerContext; IDocumentType[] supportedDocumentTypes = new IDocumentType[1] { designerContext.DocumentTypeManager.DocumentTypes[DocumentTypeNamesHelper.Image] }; string[] supportedFiles = new FileDropUtility(designerContext.ProjectManager, (FrameworkElement)null, supportedDocumentTypes).GetSupportedFiles(ClipboardService.GetDataObject()); if (supportedFiles.Length > 0) { foreach (IProjectItem projectItem in designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo() { SourcePath = file })))) { this.CreateImageBrushResource(container, projectItem); } } else { designerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else { if (!dataObject.GetDataPresent(DataFormats.Bitmap)) { return; } IProject project = EnumerableExtensions.SingleOrNull <IProject>(this.projectManager.ItemSelectionSet.SelectedProjects); if (project == null) { return; } IProjectItem projectItem = CutBuffer.AddImageDataFromClipboard(this.projectManager, project); this.CreateImageBrushResource(container, projectItem); } }
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); } } } }
public DataSourceResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resourceModel) : base(resourceManager, resourceContainer, resourceModel) { }
private ContextMenu BuildResourceContextMenu(ReadOnlyCollection <ResourceEntryBase> selection) { ContextMenu contextMenu = new ContextMenu(); if (selection.Count == 1) { ResourceEntryBase resourceEntryBase = selection[0]; ResourceEntryItem resourceEntryItem = resourceEntryBase as ResourceEntryItem; if (resourceEntryItem != null) { TypedResourceItem typedResourceItem = resourceEntryItem as TypedResourceItem; if (typedResourceItem != null) { contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemEdit, "ResourceEntryItem_Edit", typedResourceItem.EditCommand)); } } ResourceDictionaryItem resourceDictionaryItem = resourceEntryBase as ResourceDictionaryItem; if (resourceDictionaryItem != null) { contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemEdit, "ResourceDictionaryItem_Edit", resourceDictionaryItem.EditCommand)); } ResourceContainer targetContainer = resourceEntryBase as ResourceContainer; if (resourceEntryBase == this.activeDocumentWrapper) { targetContainer = this.resourceManager.ActiveRootContainer; } if (targetContainer != null && targetContainer.DocumentContext != null && resourceEntryBase.DocumentNode != null && (targetContainer is DocumentResourceContainer || targetContainer is NodeResourceContainer)) { IProject project = ProjectHelper.GetProject(this.DesignerContext.ProjectManager, targetContainer.DocumentContext); if (project != null) { if (project.FindItem(targetContainer.DocumentReference).ContainsDesignTimeResources) { MenuItem menuItem = this.CreateItem(StringTable.DesignTimeResourcesAddDictionary, "ResourceContainer_LinkToDesignTimeResources", (ICommand) new ResourcePane.LinkToDesignTimeResourceCommand(this.DesignerContext, targetContainer)); contextMenu.Items.Add((object)menuItem); } else { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext != null) { MenuItem menuItem1 = this.CreateItem(StringTable.UndoUnitLinkToResourceDictionary, "ResourceContainer_LinkToResources", (ICommand)null); foreach (DocumentResourceContainer resourceContainer in (Collection <DocumentResourceContainer>) this.resourceManager.DocumentResourceContainers) { if (resourceContainer.DocumentReference != targetContainer.DocumentReference && resourceContainer.Document != null && (resourceContainer.Document.DocumentRoot != null && resourceContainer.Document.DocumentRoot.RootNode != null) && (resourceContainer.ProjectContext != null && !resourceContainer.ProjectItem.ContainsDesignTimeResources && PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)resourceContainer.Document.DocumentRoot.RootNode.Type)) && (resourceContainer.ProjectContext == projectContext || ProjectHelper.DoesProjectReferencesContainTarget(project, resourceContainer.ProjectContext))) { ResourcePane.LinkToResourcesCommand resourcesCommand = new ResourcePane.LinkToResourcesCommand(this.resourceManager, targetContainer, resourceContainer.ProjectItem); MenuItem menuItem2 = this.CreateItem(resourceContainer.Name, resourceContainer.Name, (ICommand)resourcesCommand); menuItem2.IsCheckable = true; menuItem2.SetBinding(MenuItem.IsCheckedProperty, (BindingBase) new Binding("IsChecked") { Source = (object)resourcesCommand, Mode = BindingMode.OneTime }); menuItem1.Items.Add((object)menuItem2); } } if (menuItem1.Items.Count == 0) { MenuItem menuItem2 = this.CreateItem(StringTable.ResourcePaneNoDictionaries, (string)null, (ICommand)null); menuItem2.IsEnabled = false; menuItem1.Items.Add((object)menuItem2); } contextMenu.Items.Add((object)menuItem1); } } } } if (contextMenu.Items.Count > 0) { contextMenu.Items.Add((object)new Separator()); } } contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemCut, "ResourcePane_Cut", this.CutCommand)); contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemCopy, "ResourcePane_Copy", this.CopyCommand)); contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemPaste, "ResourcePane_Paste", this.PasteCommand)); contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemDelete, "ResourcePane_Delete", this.DeleteCommand)); contextMenu.Items.Add((object)new Separator()); contextMenu.Items.Add((object)this.CreateItem(StringTable.ViewXamlCommandName, "ResourcePane_ViewXaml", this.ViewXamlCommand)); return(contextMenu); }
public ResourceDictionaryItem(ResourceManager resourceManager, ResourceContainer resourceContainer, DocumentCompositeNode dictionary) : base(resourceManager, resourceContainer) { this.dictionary = dictionary; this.marker = dictionary.Marker; }
public ControlTemplateResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer, resource) { }
public TimelineResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer, resource) { }
public TransformResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer, resource) { }
public DrawingImageResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer, resource) { }
public BrushResourceItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer, resource) { }
protected ResourceEntryItem(ResourceManager resourceManager, ResourceContainer resourceContainer, ResourceModel resource) : base(resourceManager, resourceContainer) { this.resource = resource; }