protected void OpenInitialScene() { IProject startupProject = this.StartupProject as IProject; if (startupProject == null || startupProject is IWebsiteProject || startupProject is WebApplicationProject) { return; } if (startupProject.StartupItem != null) { if (this.Services.ViewService().Views.OfType <IDocumentView>().FirstOrDefault <IDocumentView>((IDocumentView documentView) => documentView.Document.DocumentReference == startupProject.StartupItem.DocumentReference) != null) { return; } } IProjectItem startupItem = startupProject.StartupItem; if (startupItem == null || !startupItem.DocumentType.CanView) { foreach (IProjectItem item in startupProject.Items) { if (item.DocumentType != ((ProjectManager)this.Services.ProjectManager()).KnownDocumentTypes.SceneDocumentType || !item.DocumentType.CanView) { continue; } startupItem = item; break; } } if (startupItem != null) { startupItem.OpenView(true); } }
private void ActivateResult(IProjectItem projectItem, FindInFilesResult result) { if (projectItem == null) { return; } if (this.FindInFile(projectItem, new FindInFilesDialog.ProcessResult(this.UpdateResult), result)) { result.Line = -1; result.Column = -1; this.FindInFile(projectItem, new FindInFilesDialog.ProcessResult(this.UpdateToLastResult), result); } if (result.Line == -1 || result.Column == -1) { return; } IDocumentView documentView = projectItem.OpenView(true); if (documentView == null) { return; } ISetCaretPosition setCaretPosition = documentView as ISetCaretPosition; if (setCaretPosition == null) { return; } setCaretPosition.SetCaretPosition(result.Line, result.Column); }
internal static bool OpenFile(this IServiceProvider source, string url) { bool flag; ISolution currentSolution = source.GetService <IProjectManager>().CurrentSolution; if (currentSolution == null) { return(false); } using (IEnumerator <IProject> enumerator = currentSolution.Projects.GetEnumerator()) { while (enumerator.MoveNext()) { IProjectItem projectItem = enumerator.Current.Items.FindMatchByUrl <IProjectItem>(url); if (projectItem == null) { continue; } flag = projectItem.OpenView(true) != null; return(flag); } return(false); } return(flag); }
public override void Execute() { if (!this.IsEnabled) { return; } foreach (IDocumentItem documentItem in Enumerable.ToList <IDocumentItem>(ProjectCommandExtensions.Selection((IProjectCommand)this))) { IProjectItem projectItem = documentItem as IProjectItem; if (projectItem != null) { projectItem.OpenView(true); } } }
public static bool UpdateDesignValues(IProjectItem designDataFile, IProperty property, ISampleTypeConfiguration valueGenerator) { designDataFile.OpenView(false); SceneDocument sceneDocument = designDataFile.Document as SceneDocument; if (sceneDocument == null || sceneDocument.DocumentRoot == null || sceneDocument.DocumentRoot.RootNode == null) { return(false); } using (SceneEditTransaction editTransaction = sceneDocument.CreateEditTransaction(StringTable.UpdateDesignValuesUndo)) { DesignDataGenerator.UpdateDesignValues(sceneDocument.DocumentRoot.RootNode, property, valueGenerator); editTransaction.Commit(); } return(true); }
private void OnViewXamlCommand() { List <DocumentNode> itemsDocumentNodes = this.GetSelectedItemsDocumentNodes(); if (itemsDocumentNodes == null || itemsDocumentNodes.Count <= 0) { return; } IProjectItem projectItem = (IProjectItem)null; foreach (IProject project in this.projectManager.CurrentSolution.Projects) { projectItem = project.FindItem(DocumentReferenceLocator.GetDocumentReference(itemsDocumentNodes[0].Context)); if (projectItem != null) { break; } } SceneView sceneView = projectItem.OpenView(true) as SceneView; if (sceneView == null) { return; } DocumentNode rootNode = itemsDocumentNodes[0].DocumentRoot.RootNode; if (itemsDocumentNodes.Count == 1 && itemsDocumentNodes[0] == rootNode) { sceneView.EnsureXamlEditorVisible(); } else { if (itemsDocumentNodes.Contains(rootNode)) { itemsDocumentNodes.Remove(rootNode); } GoToXamlCommand.GoToXaml(sceneView.ViewModel.XamlDocument, itemsDocumentNodes); } }
public IEnumerable <INamedProject> CreateProjects(string name, string path, IEnumerable <TemplateArgument> templateArguments, IServiceProvider serviceProvider) { Uri uri; IEnumerable <INamedProject> namedProjects; ICodeDocumentType codeDocumentType = base.GetCodeDocumentType(serviceProvider); if (templateArguments != null) { templateArguments = templateArguments.Concat <TemplateArgument>(TemplateManager.GetDefaultArguments(serviceProvider.ExpressionInformationService())); } else { templateArguments = TemplateManager.GetDefaultArguments(serviceProvider.ExpressionInformationService()); } TemplateArgument templateArgument = new TemplateArgument("projectname", name); if (!base.Template.TemplateData.CreateNewFolderSpecified || base.Template.TemplateData.CreateNewFolder) { path = Microsoft.Expression.Framework.Documents.PathHelper.ResolveCombinedPath(path, name); Directory.CreateDirectory(path); } List <INamedProject> namedProjects1 = new List <INamedProject>(); Uri uri1 = null; try { uri1 = new Uri(Microsoft.Expression.Framework.Documents.PathHelper.EnsurePathEndsInDirectorySeparator(path)); } catch (UriFormatException uriFormatException) { namedProjects = namedProjects1; return(namedProjects); } List <Uri> uris = new List <Uri>(); List <ProjectTemplate.FileToOpen> fileToOpens = new List <ProjectTemplate.FileToOpen>(); List <ProjectTemplate.SourceDestination> sourceDestinations = new List <ProjectTemplate.SourceDestination>(); string str = CodeGenerator.MakeSafeIdentifier(codeDocumentType, name, false); string str1 = CodeGenerator.MakeSafeIdentifier(codeDocumentType, name, true); TemplateArgument templateArgument1 = new TemplateArgument("safeprojectname", str); TemplateArgument templateArgument2 = new TemplateArgument("safeprojectname", str1); TemplateArgument templateArgument3 = new TemplateArgument("assemblyname", name); TemplateArgument templateArgument4 = new TemplateArgument("safeassemblyname", name.Replace(' ', '\u005F')); using (ProjectPathHelper.TemporaryDirectory temporaryDirectory = new ProjectPathHelper.TemporaryDirectory(true)) { foreach (VSTemplateTemplateContentProject templateProject in this.TemplateProjects) { if (!string.IsNullOrEmpty(templateProject.File)) { string targetFileName = templateProject.TargetFileName; if (string.IsNullOrEmpty(targetFileName)) { targetFileName = string.Concat(name, Path.GetExtension(templateProject.File)); } TemplateArgument[] templateArgumentArray = new TemplateArgument[] { templateArgument, templateArgument1, templateArgument3, templateArgument4 }; IEnumerable <TemplateArgument> templateArguments1 = templateArguments.Concat <TemplateArgument>(templateArgumentArray); uri = base.ResolveFileUri(targetFileName, uri1); string str2 = TemplateParser.ReplaceTemplateArguments(uri.LocalPath, templateArguments1); uri = new Uri(str2); if (!string.IsNullOrEmpty(templateProject.File) && !base.IsDirectory(templateProject.File)) { Uri uri2 = new Uri(temporaryDirectory.GenerateTemporaryFileName()); base.CreateFile(templateProject.File, base.TemplateLocation, uri2, templateProject.ReplaceParameters, templateArguments1); ProjectTemplate.SourceDestination sourceDestination = new ProjectTemplate.SourceDestination() { Source = uri2, Destination = uri }; sourceDestinations.Add(sourceDestination); } } else { uri = uri1; } foreach (Microsoft.Expression.Project.Templates.ProjectItem projectItem in templateProject.Items.OfType <Microsoft.Expression.Project.Templates.ProjectItem>()) { string value = projectItem.TargetFileName; if (string.IsNullOrEmpty(value)) { value = projectItem.Value; } int num = projectItem.Value.IndexOf('.'); string str3 = (num != -1 ? projectItem.Value.Remove(num) : projectItem.Value); bool flag = Path.GetExtension(projectItem.Value).Equals(codeDocumentType.DefaultFileExtension, StringComparison.OrdinalIgnoreCase); string str4 = CodeGenerator.MakeSafeIdentifier(codeDocumentType, str3, flag); TemplateArgument[] templateArgumentArray1 = new TemplateArgument[] { templateArgument, templateArgument3, templateArgument4, null, null, null }; templateArgumentArray1[3] = (flag ? templateArgument2 : templateArgument1); templateArgumentArray1[4] = new TemplateArgument("safeitemname", str4); templateArgumentArray1[5] = new TemplateArgument("safeitemrootname", str4); TemplateArgument[] templateArgumentArray2 = templateArgumentArray1; string str5 = TemplateParser.ReplaceTemplateArguments(value, templateArguments.Concat <TemplateArgument>(templateArgumentArray2)); Uri uri3 = base.ResolveFileUri(str5, uri1); Uri uri4 = new Uri(temporaryDirectory.GenerateTemporaryFileName()); if (!base.CreateFile(projectItem.Value, base.TemplateLocation, uri4, projectItem.ReplaceParameters, templateArguments.Concat <TemplateArgument>(templateArgumentArray2))) { continue; } if (projectItem.OpenInEditorSpecified && projectItem.OpenInEditor) { ProjectTemplate.FileToOpen fileToOpen = new ProjectTemplate.FileToOpen() { ProjectFile = uri, ProjectItem = uri3 }; fileToOpens.Add(fileToOpen); } ProjectTemplate.SourceDestination sourceDestination1 = new ProjectTemplate.SourceDestination() { Source = uri4, Destination = uri3 }; sourceDestinations.Add(sourceDestination1); } uris.Add(uri); } foreach (ProjectTemplate.SourceDestination sourceDestination2 in sourceDestinations) { string localPath = sourceDestination2.Destination.LocalPath; if (!Microsoft.Expression.Framework.Documents.PathHelper.FileOrDirectoryExists(localPath)) { continue; } IMessageDisplayService messageDisplayService = serviceProvider.MessageDisplayService(); CultureInfo currentUICulture = CultureInfo.CurrentUICulture; string cannotCreateTemplateDirectoryOrFileExistsMessage = StringTable.CannotCreateTemplateDirectoryOrFileExistsMessage; object[] objArray = new object[] { localPath }; messageDisplayService.ShowError(string.Format(currentUICulture, cannotCreateTemplateDirectoryOrFileExistsMessage, objArray)); namedProjects = namedProjects1; return(namedProjects); } foreach (ProjectTemplate.SourceDestination sourceDestination3 in sourceDestinations) { base.CreateFile(sourceDestination3.Source.LocalPath, new Uri(Path.GetDirectoryName(sourceDestination3.Source.LocalPath)), sourceDestination3.Destination, false, Enumerable.Empty <TemplateArgument>()); } foreach (Uri uri5 in uris) { DocumentReference documentReference = DocumentReference.Create(uri5.LocalPath); IProjectStore projectStore = null; INamedProject namedProject = null; try { projectStore = ProjectStoreHelper.CreateProjectStore(documentReference, serviceProvider, ProjectStoreHelper.DefaultProjectCreationChain); namedProject = serviceProvider.ProjectManager().AddProject(projectStore); } finally { if (namedProject == null && projectStore != null) { projectStore.Dispose(); } } if (namedProject == null) { continue; } namedProjects1.Add(namedProject); } foreach (ProjectTemplate.FileToOpen fileToOpen1 in fileToOpens) { ISolution currentSolution = serviceProvider.ProjectManager().CurrentSolution; if (currentSolution == null) { continue; } IProject project = currentSolution.Projects.FindMatchByUrl <IProject>(fileToOpen1.ProjectFile.LocalPath); if (project == null) { continue; } IProjectItem projectItem1 = project.Items.FindMatchByUrl <IProjectItem>(fileToOpen1.ProjectItem.LocalPath); if (projectItem1 == null) { continue; } projectItem1.OpenView(true); } return(namedProjects1); } return(namedProjects); }
private void Project_ItemChanged(object sender, ProjectItemEventArgs e) { IProjectItem projectItem = e.ProjectItem; if (projectItem.IsOpen) { MessageBoxResult messageBoxResult = MessageBoxResult.No; string projectItemChangedDialogFileDirtyMessage = null; if (projectItem.IsDirty) { if ((e.Options & ProjectItemEventOptions.SilentIfDirty) != ProjectItemEventOptions.SilentIfDirty) { projectItemChangedDialogFileDirtyMessage = StringTable.ProjectItemChangedDialogFileDirtyMessage; } else { messageBoxResult = MessageBoxResult.Yes; } } else if ((e.Options & ProjectItemEventOptions.SilentIfOpen) != ProjectItemEventOptions.SilentIfOpen) { projectItemChangedDialogFileDirtyMessage = StringTable.ProjectItemChangedDialogFileCleanMessage; } else { messageBoxResult = MessageBoxResult.Yes; } if (!SolutionBase.IsReloadPromptEnabled()) { messageBoxResult = MessageBoxResult.Yes; projectItemChangedDialogFileDirtyMessage = null; } if (!string.IsNullOrEmpty(projectItemChangedDialogFileDirtyMessage)) { MessageBoxArgs messageBoxArg = new MessageBoxArgs(); CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] path = new object[] { projectItem.DocumentReference.Path, base.Services.ExpressionInformationService().ShortApplicationName }; messageBoxArg.Message = string.Format(currentCulture, projectItemChangedDialogFileDirtyMessage, path); messageBoxArg.Button = MessageBoxButton.YesNo; messageBoxArg.Image = MessageBoxImage.Exclamation; MessageBoxArgs messageBoxArg1 = messageBoxArg; messageBoxResult = base.Services.MessageDisplayService().ShowMessage(messageBoxArg1); } if (messageBoxResult == MessageBoxResult.Yes) { bool isReadOnly = projectItem.Document.IsReadOnly; bool document = projectItem.Document == base.Services.DocumentService().ActiveDocument; bool flag = false; foreach (IView view in base.Services.ViewService().Views) { IDocumentView documentView = view as IDocumentView; if (documentView == null || documentView.Document != projectItem.Document) { continue; } flag = true; break; } projectItem.CloseDocument(); projectItem.OpenDocument(isReadOnly); if (projectItem.IsOpen && flag) { projectItem.OpenView(document); } } } }
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); } } } }