Ejemplo n.º 1
0
        private void RefreshAssemblies(SceneView view)
        {
            if (view == null || view.IsClosing)
            {
                return;
            }
            ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(view.ProjectContext);

            if (projectXamlContext == null)
            {
                return;
            }
            projectXamlContext.RefreshAssemblies();
        }
        private bool AddReferences(IProjectContext projectContext, ReplaceStyleTemplateCommand.ExtraReferences references, string resourceKey)
        {
            ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(projectContext);

            if (projectXamlContext == null)
            {
                return(false);
            }
            if (references.Assemblies.Count > 0)
            {
                ISolution currentSolution = this.DesignerContext.ProjectManager.CurrentSolution;
                if (currentSolution != null)
                {
                    List <IProject>        list1 = new List <IProject>();
                    List <IProjectContext> list2 = new List <IProjectContext>();
                    foreach (IProject project in currentSolution.Projects)
                    {
                        ProjectXamlContext projectContext1 = ProjectXamlContext.GetProjectContext(project);
                        if (projectContext1 != null && projectContext1.ProjectAssembly != null && references.Assemblies.Contains(projectContext1.ProjectAssembly))
                        {
                            list1.Add(project);
                            list2.Add((IProjectContext)projectContext1);
                        }
                    }
                    for (int index = 0; index < list1.Count; ++index)
                    {
                        IProject        source          = list1[index];
                        IProjectContext projectContext1 = list2[index];
                        if (projectXamlContext != projectContext1 && ProjectHelper.DoesProjectReferenceHierarchyContainTarget(source, (IProjectContext)projectXamlContext))
                        {
                            this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.DocumentRefersToUnresolvedTypesHeader, new object[1]
                            {
                                (object)resourceKey
                            }));
                            return(false);
                        }
                    }
                }
                foreach (IAssembly assembly in (IEnumerable <IAssembly>)references.Assemblies)
                {
                    projectXamlContext.EnsureAssemblyReferenceMatches(this.SceneViewModel.ProjectContext, assembly);
                }
            }
            foreach (string assemblyPath in (IEnumerable <string>)references.PlatformAssemblies)
            {
                projectXamlContext.EnsureAssemblyReferenced(assemblyPath);
            }
            this.SceneViewModel.DesignerContext.ViewUpdateManager.RebuildPostponedViews();
            return(true);
        }
Ejemplo n.º 3
0
        private bool EnsureTreeControlTypeAssembly()
        {
            if (this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                return(true);
            }
            ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(this.ProjectContext);

            if (projectXamlContext == null)
            {
                return(false);
            }
            projectXamlContext.EnsureAssemblyReferenced(DataBindingDragDropDefaultHandler.SilverlightTreeControlAssemblyName);
            this.DragModel.TargetNode.DesignerContext.ViewUpdateManager.RebuildPostponedViews();
            return(!this.ProjectContext.PlatformMetadata.IsNullType((ITypeId)this.ProjectContext.ResolveType(DataBindingDragDropDefaultHandler.TreeControlType)));
        }
Ejemplo n.º 4
0
        public static IType GetSourceType(IType type, ITypeResolver typeResolver)
        {
            if (typeResolver.PlatformMetadata.IsNullType((ITypeId)type))
            {
                return(type);
            }
            DesignTypeResult designTypeResult = DesignTypeGenerator.LookupGetDesignTypeResult(type.RuntimeType);

            if (designTypeResult != null && !designTypeResult.IsFailed && designTypeResult.SourceType != type.RuntimeType)
            {
                ITypeResolver typeResolver1 = (ITypeResolver)ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext) ?? typeResolver;
                IType         type1         = typeResolver1.GetType(designTypeResult.SourceType);
                if (!typeResolver1.PlatformMetadata.IsNullType((ITypeId)type1))
                {
                    return(type1);
                }
            }
            return(type);
        }
        private static StringComparison GetMethodNameComparison(ITypeResolver typeResolver)
        {
            StringComparison   stringComparison   = StringComparison.Ordinal;
            ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext);

            if (projectXamlContext == null)
            {
                return(stringComparison);
            }
            IProject project = (IProject)projectXamlContext.GetService(typeof(IProject));

            if (project == null || project.CodeDocumentType == null)
            {
                return(stringComparison);
            }
            ICodeGeneratorHost codeGeneratorHost = project.CodeDocumentType as ICodeGeneratorHost;

            if (codeGeneratorHost == null || (codeGeneratorHost.CodeDomProvider.LanguageOptions & LanguageOptions.CaseInsensitive) != LanguageOptions.CaseInsensitive)
            {
                return(stringComparison);
            }
            stringComparison = StringComparison.OrdinalIgnoreCase;
            return(stringComparison);
        }
Ejemplo n.º 6
0
        public static void GoToXaml(SceneView sceneView, SceneXamlDocument document, List <DocumentNode> targetNodes, bool selectElementNameOnly, bool setFocusToXamlEditor)
        {
            ITextRange         selectionSpan      = TextRange.Null;
            bool               flag               = false;
            ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(document.ProjectContext);

            if (projectXamlContext == null)
            {
                return;
            }
            DocumentNode rootNode = document.RootNode;

            if (rootNode != null && targetNodes != null)
            {
                foreach (DocumentNode documentNode in targetNodes)
                {
                    DocumentNode node = GoToXamlCommand.GetCorrespondingDocumentNode(documentNode, rootNode);
                    if (node != null)
                    {
                        ITextRange nodeSpan;
                        for (nodeSpan = DocumentNodeHelper.GetNodeSpan(node); TextRange.IsNull(nodeSpan) && node != null && node != rootNode; nodeSpan = DocumentNodeHelper.GetNodeSpan(node))
                        {
                            node = (DocumentNode)node.Parent;
                        }
                        if (!TextRange.IsNull(nodeSpan))
                        {
                            if (!flag)
                            {
                                flag          = true;
                                selectionSpan = nodeSpan;
                            }
                            else
                            {
                                selectionSpan = TextRange.Union(selectionSpan, nodeSpan);
                            }
                        }
                    }
                }
            }
            if (sceneView == null)
            {
                sceneView = projectXamlContext.OpenView((IDocumentRoot)document, true);
            }
            using (sceneView.DisableSelectionSynchronization())
            {
                sceneView.EnsureXamlEditorVisible();
                if (!flag || sceneView.CodeEditor == null)
                {
                    return;
                }
                ITextEditor textEditor = sceneView.CodeEditor;
                textEditor.ClearSelection();
                if (selectElementNameOnly)
                {
                    selectionSpan = GoToXamlCommand.GetElementNameSelectionSpan((IReadableSelectableTextBuffer)document.TextBuffer, selectionSpan);
                }
                textEditor.Select(selectionSpan.Offset, selectionSpan.Length);
                textEditor.CaretPosition = selectionSpan.Offset + selectionSpan.Length;
                Action action = (Action)(() =>
                {
                    textEditor.EnsureSpanVisible(selectionSpan.Offset, selectionSpan.Length);
                    textEditor.EnsureCaretVisible();
                    textEditor.MoveLineToCenterOfView(textEditor.GetLineNumberFromPosition(selectionSpan.Offset));
                    if (!setFocusToXamlEditor)
                    {
                        return;
                    }
                    textEditor.Focus();
                });
                if (SceneViewUpdateScheduleTask.Synchronous)
                {
                    action();
                }
                else
                {
                    UIThreadDispatcher.Instance.BeginInvoke(DispatcherPriority.Render, action);
                }
            }
        }
        public override void Execute()
        {
            string               fileName           = "test";
            IProject             activeProject      = this.DesignerContext.ActiveProject;
            TemplateItemHelper   templateItemHelper = new TemplateItemHelper(activeProject, (IList <string>)null, (IServiceProvider)this.DesignerContext.Services);
            IProjectItemTemplate templateItem       = templateItemHelper.FindTemplateItem("UserControl");

            if (templateItem == null)
            {
                this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlTemplateNotFound);
            }
            else
            {
                SceneViewModel      activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel;
                List <SceneElement> elements             = new List <SceneElement>();
                elements.AddRange((IEnumerable <SceneElement>)activeSceneViewModel.ElementSelectionSet.Selection);
                elements.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(activeSceneViewModel.RootNode));
                if (this.ShowUI)
                {
                    string recommendedName = this.GetRecommendedName((IEnumerable <SceneElement>)elements);
                    MakeUserControlDialog userControlDialog = new MakeUserControlDialog(this.DesignerContext, this.DialogTitle, templateItemHelper, recommendedName);
                    bool?nullable = userControlDialog.ShowDialog();
                    if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                    {
                        return;
                    }
                    fileName = userControlDialog.ControlName;
                }
                List <IProjectItem>        itemsToOpen  = (List <IProjectItem>)null;
                IProjectItem               projectItem1 = (IProjectItem)null;
                IEnumerable <IProjectItem> source       = (IEnumerable <IProjectItem>)null;
                try
                {
                    source = templateItemHelper.AddProjectItemsForTemplateItem(templateItem, fileName, this.DesignerContext.ProjectManager.TargetFolderForProject(activeProject), CreationOptions.DoNotAllowOverwrites | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath, out itemsToOpen);
                }
                catch (Exception ex)
                {
                    if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex))
                    {
                        this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ProjectNewFileErrorDialogMessage, new object[2]
                        {
                            (object)fileName,
                            (object)ex.Message
                        }));
                    }
                    else
                    {
                        throw;
                    }
                }
                if (source == null || EnumerableExtensions.CountIsLessThan <IProjectItem>(source, 1))
                {
                    return;
                }
                if (itemsToOpen != null && itemsToOpen.Count > 0)
                {
                    projectItem1 = Enumerable.FirstOrDefault <IProjectItem>((IEnumerable <IProjectItem>)itemsToOpen);
                    projectItem1.OpenDocument(false, true);
                }
                if (projectItem1 != null && projectItem1.IsOpen && projectItem1.DocumentType.CanView)
                {
                    Rect empty = Rect.Empty;
                    for (int index = 0; index < elements.Count; ++index)
                    {
                        BaseFrameworkElement child = elements[index] as BaseFrameworkElement;
                        if (child != null)
                        {
                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                            empty.Union(childRect);
                        }
                    }
                    Rect         rect              = RoundingHelper.RoundRect(empty);
                    SceneElement parentElement     = elements[0].ParentElement;
                    bool         useLayoutRounding = LayoutRoundingHelper.GetUseLayoutRounding(parentElement);
                    DataObject   dataObject        = (DataObject)null;
                    using (activeSceneViewModel.ForceBaseValue())
                    {
                        PastePackage pastePackage = new PastePackage(activeSceneViewModel);
                        pastePackage.CopyStoryboardsReferencingElements = true;
                        pastePackage.AddElements(elements);
                        dataObject = pastePackage.GetPasteDataObject();
                    }
                    SceneView sceneView = projectItem1.OpenView(true) as SceneView;
                    if (sceneView != null)
                    {
                        SceneViewModel     viewModel           = sceneView.ViewModel;
                        ProjectXamlContext projectXamlContext  = ProjectXamlContext.FromProjectContext(viewModel.ViewRoot.ProjectContext);
                        ClassAttributes    rootClassAttributes = viewModel.DocumentRoot.RootClassAttributes;
                        ITypeId            typeId = (ITypeId)null;
                        if (projectXamlContext != null && rootClassAttributes != null)
                        {
                            projectXamlContext.RefreshUnbuiltTypeDescriptions();
                            if (rootClassAttributes != null)
                            {
                                typeId = (ITypeId)projectXamlContext.GetType(projectXamlContext.ProjectAssembly.Name, rootClassAttributes.QualifiedClassName);
                            }
                        }
                        if (typeId != null && this.CheckForCircularReference((IEnumerable <SceneElement>)elements, typeId))
                        {
                            this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlCircularReferenceFound);
                            this.CleanupAfterCancel(projectItem1);
                            return;
                        }
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                        {
                            if (!rect.IsEmpty)
                            {
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignWidthProperty, (object)rect.Width);
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignHeightProperty, (object)rect.Height);
                                if (this.AddToApplicationFlow)
                                {
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.WidthProperty, (object)rect.Width);
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.HeightProperty, (object)rect.Height);
                                }
                            }
                            IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty(viewModel.RootNode);
                            if (property != null)
                            {
                                viewModel.RootNode.SetValue((IPropertyId)property, (object)(bool)(useLayoutRounding ? true : false));
                            }
                            ILayoutDesigner         designerForParent = viewModel.GetLayoutDesignerForParent(viewModel.ActiveSceneInsertionPoint.SceneElement, true);
                            bool                    canceledPasteOperation;
                            ICollection <SceneNode> nodes = PasteCommand.PasteData(viewModel, new SafeDataObject((IDataObject)dataObject), viewModel.ActiveSceneInsertionPoint, out canceledPasteOperation);
                            if (canceledPasteOperation)
                            {
                                editTransaction.Cancel();
                                this.CleanupAfterCancel(projectItem1);
                                return;
                            }
                            editTransaction.Update();
                            if (nodes.Count > 0)
                            {
                                viewModel.DefaultView.UpdateLayout();
                                viewModel.SelectNodes(nodes);
                                if (designerForParent != null)
                                {
                                    foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes)
                                    {
                                        BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                        if (child != null && child.IsViewObjectValid)
                                        {
                                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                                            childRect.Location = (Point)(childRect.Location - rect.Location);
                                            designerForParent.SetChildRect(child, childRect);
                                        }
                                    }
                                }
                            }
                            editTransaction.Commit();
                        }
                        if (this.AddToApplicationFlow && this.DesignerContext.PrototypingService != null)
                        {
                            this.DesignerContext.PrototypingService.PromoteToCompositionScreen(projectItem1);
                        }
                        if (typeId != null)
                        {
                            using (activeSceneViewModel.ForceBaseValue())
                            {
                                using (activeSceneViewModel.DisableDrawIntoState())
                                {
                                    using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                                    {
                                        using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove())
                                        {
                                            SceneElement primarySelection = activeSceneViewModel.ElementSelectionSet.PrimarySelection;
                                            IProperty    propertyForChild = parentElement.GetPropertyForChild((SceneNode)primarySelection);
                                            PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(parentElement, propertyForChild);
                                            SceneNode sceneNode = (SceneNode)null;
                                            if (sceneInsertionPoint.CanInsert(typeId))
                                            {
                                                foreach (SceneElement element in elements)
                                                {
                                                    if (element != primarySelection)
                                                    {
                                                        activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                                                        element.Remove();
                                                    }
                                                }
                                                ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)propertyForChild);
                                                int index = collectionForProperty.IndexOf((SceneNode)primarySelection);
                                                activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
                                                primarySelection.Remove();
                                                sceneNode = activeSceneViewModel.CreateSceneNode(typeId);
                                                collectionForProperty.Insert(index, sceneNode);
                                                this.DesignerContext.ViewService.ActiveView = (IView)activeSceneViewModel.DefaultView;
                                                editTransaction.Update();
                                                activeSceneViewModel.DefaultView.UpdateLayout();
                                                BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                                if (child != null && child.IsViewObjectValid)
                                                {
                                                    activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true).SetChildRect(child, rect);
                                                }
                                            }
                                            if (this.AddToApplicationFlow)
                                            {
                                                if (sceneNode != null)
                                                {
                                                    sceneNode.SetValue(DesignTimeProperties.IsPrototypingCompositionProperty, (object)true);
                                                }
                                            }
                                        }
                                        editTransaction.Commit();
                                    }
                                }
                            }
                            this.DesignerContext.ViewService.ActiveView = (IView)viewModel.DefaultView;
                        }
                    }
                }
                if (itemsToOpen == null || itemsToOpen.Count <= 1)
                {
                    return;
                }
                foreach (IProjectItem projectItem2 in itemsToOpen)
                {
                    if (projectItem1 != projectItem2)
                    {
                        projectItem2.OpenView(true);
                    }
                }
            }
        }