Ejemplo n.º 1
0
        internal IEnumerable <IProjectItem> ExecuteInternal(IProject project, IProjectItemTemplate itemTemplate, string userSpecifiedFileName)
        {
            List <IProjectItem> itemsToOpen        = (List <IProjectItem>)null;
            TemplateItemHelper  templateItemHelper = new TemplateItemHelper(project, (IList <string>)null, (IServiceProvider)this.designerContext.Services);
            CreationOptions     creationOptions    = CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath;

            if (!this.allowOverwrite)
            {
                creationOptions |= CreationOptions.DoNotAllowOverwrites;
            }
            IEnumerable <IProjectItem> enumerable = templateItemHelper.AddProjectItemsForTemplateItem(itemTemplate, userSpecifiedFileName, this.designerContext.ProjectManager.TargetFolderForProject(project), creationOptions, out itemsToOpen);

            if (enumerable != null)
            {
                foreach (IProjectItem projectItem in enumerable)
                {
                    if (projectItem.DocumentType is AssemblyReferenceDocumentType)
                    {
                        project.AddAssemblyReference(projectItem.DocumentReference.Path, false);
                    }
                }
            }
            if (itemsToOpen != null)
            {
                foreach (IProjectItem projectItem in itemsToOpen)
                {
                    projectItem.OpenView(true);
                }
            }
            return(enumerable);
        }
Ejemplo n.º 2
0
 private void InitializeDialogInternal()
 {
     this.DataContext          = (object)this;
     this.Title                = StringTable.CreateProjectItemDialogTitle;
     this.SizeToContent        = SizeToContent.WidthAndHeight;
     this.projectItemTemplates = new ObservableCollection <IProjectItemTemplate>();
     this.projectItemTypesView = CollectionViewSource.GetDefaultView((object)this.projectItemTemplates);
     this.templateItemHelper   = new TemplateItemHelper(this.project, this.typeFilter, (IServiceProvider)this.designerContext.Services);
     foreach (IProjectItemTemplate projectItemTemplate in this.templateItemHelper.TemplateItems)
     {
         if (!projectItemTemplate.Hidden)
         {
             this.projectItemTemplates.Add(projectItemTemplate);
         }
     }
     this.projectItemTypesView.SortDescriptions.Clear();
     this.projectItemTypesView.SortDescriptions.Add(new SortDescription("SortOrder", ListSortDirection.Ascending));
     this.projectItemTypesView.SortDescriptions.Add(new SortDescription("ItemName", ListSortDirection.Ascending));
     this.projectItemTypesView.CurrentChanged += new EventHandler(this.ProjectItemTypesView_CurrentChanged);
     if (this.projectItemTemplates.Count <= 0)
     {
         return;
     }
     this.projectItemTypesView.MoveCurrentToFirst();
     this.projectItemTypesView.Refresh();
 }
Ejemplo n.º 3
0
            public override void Execute()
            {
                IProject validXamlProject = this.ValidXamlProject;

                if (validXamlProject == null || string.IsNullOrEmpty(this.FileName))
                {
                    return;
                }
                List <IProjectItem>  itemsToOpen        = new List <IProjectItem>();
                TemplateItemHelper   templateItemHelper = new TemplateItemHelper(validXamlProject, (IList <string>)null, (IServiceProvider)this.services);
                IProjectItemTemplate templateItem       = templateItemHelper.FindTemplateItem(this.TemplateName);
                string targetFolder = this.ProjectManager.TargetFolderForProject(validXamlProject);

                if (templateItem == null)
                {
                    return;
                }
                if (targetFolder == null)
                {
                    return;
                }
                try
                {
                    templateItemHelper.AddProjectItemsForTemplateItem(templateItem, Path.GetFileName(this.FileName), targetFolder, CreationOptions.DoNotSelectCreatedItems, out itemsToOpen);
                }
                catch (ArgumentException ex)
                {
                }
            }
Ejemplo n.º 4
0
        private string EnsureOutOfBrowserSettingsFile(ref bool shouldSaveProjectFile)
        {
            string str;
            string outOfBrowserSettingsFileLocation = this.GetOutOfBrowserSettingsFileLocation();

            if (string.IsNullOrEmpty(outOfBrowserSettingsFileLocation))
            {
                if (!base.AttemptToMakeProjectWritable())
                {
                    return(null);
                }
                PathHelper.ClearFileOrDirectoryReadOnlyAttribute(base.DocumentReference.Path);
                string str1 = (this.PropertiesPath != null ? Path.Combine(this.PropertiesPath, SilverlightProject.OutOfBrowserSettingsFile) : SilverlightProject.OutOfBrowserSettingsFile);
                base.ProjectStore.SetProperty("OutOfBrowserSettingsFile", str1);
                shouldSaveProjectFile            = true;
                outOfBrowserSettingsFileLocation = PathHelper.ResolveRelativePath(base.ProjectRoot.Path, str1);
            }
            if (!PathHelper.FileOrDirectoryExists(outOfBrowserSettingsFileLocation))
            {
                TemplateItemHelper   templateItemHelper  = new TemplateItemHelper(this, null, base.Services);
                IProjectItemTemplate projectItemTemplate = templateItemHelper.FindTemplateItem("OutOfBrowserSettings");
                if (projectItemTemplate != null)
                {
                    try
                    {
                        List <IProjectItem> projectItems = new List <IProjectItem>();
                        string str2 = PathHelper.EnsurePathEndsInDirectorySeparator(PathHelper.GetDirectoryNameOrRoot(outOfBrowserSettingsFileLocation));
                        string fileNameWithoutExtension          = Path.GetFileNameWithoutExtension(outOfBrowserSettingsFileLocation);
                        IEnumerable <IProjectItem> projectItems1 = templateItemHelper.AddProjectItemsForTemplateItem(projectItemTemplate, fileNameWithoutExtension, str2, CreationOptions.DoNotSelectCreatedItems, out projectItems);
                        if (projectItems1 == null || !projectItems1.CountIs <IProjectItem>(1))
                        {
                            str = null;
                        }
                        else
                        {
                            return(outOfBrowserSettingsFileLocation);
                        }
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        if (!(exception is NotSupportedException) && !ErrorHandling.ShouldHandleExceptions(exception))
                        {
                            throw;
                        }
                        ErrorArgs errorArg = new ErrorArgs()
                        {
                            Exception = exception
                        };
                        base.Services.MessageDisplayService().ShowError(errorArg);
                        str = null;
                    }
                    return(str);
                }
            }
            return(outOfBrowserSettingsFileLocation);
        }
Ejemplo n.º 5
0
        internal MakeUserControlDialog(DesignerContext designerContext, string dialogTitle, TemplateItemHelper templateItemHelper, string recommendedName)
        {
            this.InitializeComponent();
            this.userControlItem = templateItemHelper.FindTemplateItem("UserControl");
            this.designerContext = designerContext;
            this.Title           = dialogTitle;
            this.DataContext     = (object)this;
            string str1 = designerContext.ProjectManager.TargetFolderForProject(designerContext.ActiveProject);

            if (!string.IsNullOrEmpty(recommendedName))
            {
                string            str2 = recommendedName + ".xaml";
                DocumentReference documentReference = DocumentReference.Create(Path.Combine(str1, str2));
                this.name = designerContext.ActiveProject.FindItem(documentReference) == null ? recommendedName : Path.GetFileNameWithoutExtension(ProjectPathHelper.GetAvailableFilePath(str2, str1, designerContext.ActiveProject));
            }
            else if (this.userControlItem != null)
            {
                this.name = Path.GetFileNameWithoutExtension(ProjectPathHelper.GetAvailableFilePath(this.userControlItem.DefaultName, str1, designerContext.ActiveProject));
            }
            this.controlNameMessageBubble = new MessageBubbleHelper((UIElement)this.Control_Name, (IMessageBubbleValidator) new ProjectItemNameValidator(designerContext.ActiveProject));
        }
        public bool TryCreateDesignTimeResourceReference()
        {
            bool?nullable = this.doNotAskAgain;

            if ((!nullable.GetValueOrDefault() ? 0 : (nullable.HasValue ? true : false)) != 0)
            {
                this.solutionSettingsManager.SetProjectProperty((INamedProject)this.rootProject, EditDesignTimeResourceModel.DoNotAskForDesignTimeResourcesAgain, (object)true);
            }
            else
            {
                this.solutionSettingsManager.ClearProjectProperty((INamedProject)this.rootProject, EditDesignTimeResourceModel.DoNotAskForDesignTimeResourcesAgain);
            }
            if (this.Selected != null)
            {
                try
                {
                    List <IProjectItem> itemsToOpen = new List <IProjectItem>();
                    if (this.designTimeResources == null)
                    {
                        TemplateItemHelper   templateItemHelper = new TemplateItemHelper(this.rootProject, (IList <string>)null, (IServiceProvider)this.context.Services);
                        IProjectItemTemplate templateItem       = templateItemHelper.FindTemplateItem("Resource Dictionary");
                        string availableFilePath = ProjectPathHelper.GetAvailableFilePath(EditDesignTimeResourceModel.TargetName, this.targetPath, this.rootProject, true);
                        this.designTimeResources = Enumerable.SingleOrDefault <IProjectItem>(templateItemHelper.AddProjectItemsForTemplateItem(templateItem, Path.GetFileName(availableFilePath), this.targetPath, CreationOptions.DoNotSelectCreatedItems | CreationOptions.DesignTimeResource, out itemsToOpen));
                    }
                    if (this.designTimeResources == null)
                    {
                        return(false);
                    }
                    DocumentResourceContainer resourceContainer = new DocumentResourceContainer(this.context.ResourceManager, this.designTimeResources);
                    try
                    {
                        if (resourceContainer.ProjectItem.Document == null)
                        {
                            return(false);
                        }
                        IProject project = this.Selected.Container.ProjectItem.Project;
                        if (project != this.rootProject && !Enumerable.Contains <IProject>(this.rootProject.ReferencedProjects, project))
                        {
                            IProjectItem projectItem = this.rootProject.AddProjectReference(project);
                            if (projectItem == null)
                            {
                                return(false);
                            }
                            projectItem.ContainsDesignTimeResources = true;
                        }
                        uint resourceChangeStamp = this.context.ResourceManager.ResourceChangeStamp;
                        this.context.ResourceManager.LinkToResource((ResourceContainer)resourceContainer, this.Selected.Container.DocumentReference);
                        this.context.ViewUpdateManager.RefreshViewUpdatesForDesignTimeResources(true);
                        return(this.context.ResourceManager.ResourceChangeStamp > resourceChangeStamp);
                    }
                    finally
                    {
                        resourceContainer.Close();
                    }
                }
                catch (Exception ex)
                {
                    if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex))
                    {
                        this.context.Services.GetService <IMessageDisplayService>().ShowError(new ErrorArgs()
                        {
                            Exception = ex
                        });
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(false);
        }
        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);
                    }
                }
            }
        }