예제 #1
0
        private bool CopyItem(ResourceEntryItem primaryResource, ResourceContainer destinationContainer, int destinationIndex, bool skipReferencedResourceCopy)
        {
            ResourceConflictResolution conflictResolution = ResourceConflictResolution.UseExisting;
            DocumentNode               node1              = primaryResource.Resource.ResourceNode.Clone(destinationContainer.ViewModel.Document.DocumentContext);
            DictionaryEntryNode        primaryResource1   = (DictionaryEntryNode)destinationContainer.ViewModel.GetSceneNode(node1);
            ResourceEvaluation         resourceEvaluation = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EvaluateResource(primaryResource1, destinationContainer.Node);
            List <DictionaryEntryNode> list1              = new List <DictionaryEntryNode>();

            if (!skipReferencedResourceCopy)
            {
                List <DocumentNode> foundResources = new List <DocumentNode>();
                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindAllReferencedResources(primaryResource.DocumentNode, foundResources, (Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PostOrderOperation)null);
                foreach (DocumentNode documentNode in foundResources)
                {
                    DocumentNode node2 = documentNode.Parent.Clone(destinationContainer.ViewModel.Document.DocumentContext);
                    list1.Add((DictionaryEntryNode)destinationContainer.ViewModel.GetSceneNode(node2));
                }
            }
            IList <ResourceEvaluation> list2 = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EvaluateResources((IList <DictionaryEntryNode>)list1, destinationContainer.Node);

            if (!Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CheckEvaluationResults(list2, (ResourceEvaluationResult)7))
            {
                if (!Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CheckEvaluationResult(resourceEvaluation, ResourceEvaluationResult.ConflictingResourceExists, ResourceEvaluationResult.IdenticalResourceExists))
                {
                    goto label_10;
                }
            }
            conflictResolution = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PromptForResourceConflictResolution(ResourceConflictResolution.UseExisting | ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld);
            if (conflictResolution == ResourceConflictResolution.Undetermined)
            {
                return(false);
            }
label_10:
            using (SceneEditTransaction editTransaction = destinationContainer.ViewModel.CreateEditTransaction(StringTable.UndoUnitCopyResource))
            {
                int num = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.AddResources(list2, (IList <SceneNode>)null, conflictResolution, destinationContainer.Node, destinationIndex);
                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.AddPrimaryResource(resourceEvaluation, (IList <SceneNode>)null, conflictResolution, destinationContainer.Node, destinationIndex + num);
                ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(destinationContainer.ViewModel.DocumentRootResolver);
                SceneNode           keyNode             = primaryResource1.KeyNode;
                if (keyNode != null)
                {
                    DocumentNode documentNode = expressionEvaluator.EvaluateResource(destinationContainer.Node.DocumentNodePath, keyNode.DocumentNode);
                    foreach (DictionaryEntryNode dictionaryEntryNode in destinationContainer.ResourceDictionaryNode)
                    {
                        if (dictionaryEntryNode.Value.DocumentNode == documentNode)
                        {
                            this.ResourceManager.SelectedItems.SetSelection((ResourceEntryBase)this.ResourceManager.GetResourceItem(destinationContainer, dictionaryEntryNode.DocumentNode as DocumentCompositeNode));
                            editTransaction.Commit();
                            return(true);
                        }
                    }
                }
                else
                {
                    editTransaction.Commit();
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
 internal void MoveItem(ResourceEntryItem resourceEntry, int destinationIndex)
 {
     using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(StringTable.UndoUnitMoveResource))
     {
         DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)resourceEntry.Resource.ResourceNode.SceneNode;
         int num = this.ResourceDictionaryNode.IndexOf(dictionaryEntryNode);
         if (num == -1)
         {
             return;
         }
         if (destinationIndex > num)
         {
             --destinationIndex;
         }
         if (!this.ResourceDictionaryNode.Remove(dictionaryEntryNode))
         {
             return;
         }
         if (destinationIndex >= 0 && destinationIndex < this.ResourceDictionaryNode.Count)
         {
             this.ResourceDictionaryNode.Insert(destinationIndex, dictionaryEntryNode);
         }
         else
         {
             this.ResourceDictionaryNode.Add(dictionaryEntryNode);
         }
         editTransaction.Commit();
     }
 }
예제 #3
0
        public virtual void OnDragOver(DragEventArgs e)
        {
            e.Handled = true;
            e.Effects = DragDropEffects.None;
            if (this.ResourceManager.IsFiltering)
            {
                return;
            }
            this.InDragOver = true;
            ResourceEntryItem resourceEntry = (ResourceEntryItem)null;

            if (!this.CanDrop(e, out resourceEntry))
            {
                return;
            }
            ResourceContainer dropTargetContainer = this.DragDropTargetContainer;

            if (dropTargetContainer.DocumentHasErrors || dropTargetContainer.DocumentNode == null)
            {
                return;
            }
            if (resourceEntry.Container != dropTargetContainer && (e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey)
            {
                e.Effects = DragDropEffects.Copy;
            }
            else
            {
                e.Effects = DragDropEffects.Move;
            }
        }
예제 #4
0
 public ResourceValueModel(ResourceEntryItem resourceItem, DesignerContext designerContext)
 {
     this.resourceItem  = resourceItem;
     this.helper        = new PropertyEditingHelper(this.resourceItem.Container.Document, (UIElement)null);
     this.objectSet     = new ResourceValueObjectSet(resourceItem, designerContext, (IPropertyInspector)this);
     this.valueProperty = this.objectSet.CreateSceneNodeProperty(new PropertyReference((ReferenceStep)resourceItem.Container.ProjectContext.ResolveProperty(DictionaryEntryNode.ValueProperty)), TypeUtilities.GetAttributes(resourceItem.Resource.TargetType));
     this.valueProperty.PropertyValue.PropertyValueException += new EventHandler <PropertyValueExceptionEventArgs>(this.OnPropertyValueException);
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ResourceEntryItem resourceEntryItem = value as ResourceEntryItem;

            if (resourceEntryItem != null && this.ResourcePane != null)
            {
                return((object)this.ResourcePane.GetResourceValueModel(resourceEntryItem));
            }
            return((object)null);
        }
예제 #6
0
        internal ResourceValueModel GetResourceValueModel(ResourceEntryItem item)
        {
            ResourceValueModel resourceValueModel = (ResourceValueModel)null;

            if (!this.valueModels.TryGetValue((ResourceItem)item, out resourceValueModel) && item.Container.DocumentNode != null)
            {
                resourceValueModel = new ResourceValueModel(item, this.designerContext);
                this.valueModels[(ResourceItem)item] = resourceValueModel;
            }
            return(resourceValueModel);
        }
 private void ContentProvider_KeyChanged(object sender, EventArgs <DocumentNode> e)
 {
     foreach (ResourceItem resourceItem in (Collection <ResourceItem>) this.ResourceItems)
     {
         if (resourceItem.DocumentNode == e.Value)
         {
             ResourceEntryItem resourceEntryItem = resourceItem as ResourceEntryItem;
             if (resourceEntryItem != null)
             {
                 resourceEntryItem.OnKeyChanged();
                 break;
             }
         }
     }
 }
예제 #8
0
            public int Compare(ResourceItem a, ResourceItem b)
            {
                ResourceEntryItem resourceEntryItem1 = a as ResourceEntryItem;
                ResourceEntryItem resourceEntryItem2 = b as ResourceEntryItem;

                if (resourceEntryItem1 != null && resourceEntryItem2 != null)
                {
                    int num = string.Compare(resourceEntryItem1.Key, resourceEntryItem2.Key, StringComparison.Ordinal);
                    if (num != 0)
                    {
                        return(num);
                    }
                }
                return(this.comparer.Compare((ResourceEntryBase)a, (ResourceEntryBase)b));
            }
예제 #9
0
 private bool CopyResourceCore()
 {
     if (this.resourceManager.SelectedResourceContainers.Count == 0 && this.resourceManager.SelectedResourceItems.Count == 1)
     {
         ResourceEntryItem resourceEntryItem = this.resourceManager.SelectedResourceItems[0] as ResourceEntryItem;
         if (resourceEntryItem != null)
         {
             SceneViewModel viewModel    = resourceEntryItem.Container.ViewModel;
             PastePackage   pastePackage = new PastePackage(viewModel);
             pastePackage.AddResource(viewModel.GetSceneNode((DocumentNode)resourceEntryItem.Resource.ResourceNode) as DictionaryEntryNode);
             pastePackage.SendToClipboard();
             return(true);
         }
     }
     return(false);
 }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        public EditResourceModel(DesignerContext designerContext, DictionaryEntryNode resourceEntryNode, IPropertyInspector transactionContext)
        {
            this.designerContext   = designerContext;
            this.resourceEntryNode = resourceEntryNode;
            object       key = resourceEntryNode.Key;
            DocumentNode expression;

            if ((expression = key as DocumentNode) != null)
            {
                this.keyString = XamlExpressionSerializer.GetStringFromExpression(expression, resourceEntryNode.DocumentNode);
            }
            else if ((this.keyString = key as string) == null)
            {
                this.keyString = key.ToString();
            }
            this.keyStringIsValid = true;
            ResourceEntryItem resource = (ResourceEntryItem)this.designerContext.ResourceManager.GetResourceItem((DocumentCompositeNode)resourceEntryNode.DocumentNode);

            this.resourceObjectSet = new ResourceValueObjectSet(resource, designerContext, transactionContext);
            this.standInProperty   = this.resourceObjectSet.CreateProperty(new PropertyReference((ReferenceStep)this.resourceObjectSet.ProjectContext.ResolveProperty(DictionaryEntryNode.ValueProperty)), TypeUtilities.GetAttributes(resource.EffectiveType));
            this.standInProperty.PropertyValue.PropertyValueException += new EventHandler <PropertyValueExceptionEventArgs>(this.OnPropertyValueException);
            this.standInProperty.PropertyValue.PropertyChanged        += new PropertyChangedEventHandler(this.OnValuePropertyChanged);
        }
예제 #13
0
 public ResourceValueObjectSet(ResourceEntryItem resource, DesignerContext designerContext, IPropertyInspector transactionContext)
     : base(designerContext, transactionContext)
 {
     this.resource        = resource;
     this.designerContext = designerContext;
 }
예제 #14
0
        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);
        }
예제 #15
0
        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);
                    }
                }
            }
        }