public static void CopyDirectory(string directoryName, DirectoryNode node, bool includeInProject) { directoryName = FileUtility.NormalizePath(directoryName); string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(directoryName)); LoggingService.Debug("Copy " + directoryName + " to " + copiedFileName); if (!FileUtility.IsEqualFileName(directoryName, copiedFileName)) { if (includeInProject && ProjectService.OpenSolution != null) { // get ProjectItems in source directory foreach (IProject project in ProjectService.OpenSolution.Projects) { if (!FileUtility.IsBaseDirectory(project.Directory, directoryName)) continue; LoggingService.Debug("Searching for child items in " + project.Name); foreach (ProjectItem item in project.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem == null) continue; string virtualFullName = Path.Combine(project.Directory, fileItem.VirtualName); if (FileUtility.IsBaseDirectory(directoryName, virtualFullName)) { if (item.ItemType == ItemType.Folder && FileUtility.IsEqualFileName(directoryName, virtualFullName)) { continue; } LoggingService.Debug("Found file " + virtualFullName); FileProjectItem newItem = new FileProjectItem(node.Project, fileItem.ItemType); if (FileUtility.IsBaseDirectory(directoryName, fileItem.FileName)) { newItem.FileName = FileUtility.RenameBaseDirectory(fileItem.FileName, directoryName, copiedFileName); } else { newItem.FileName = fileItem.FileName; } fileItem.CopyMetadataTo(newItem); if (fileItem.IsLink) { string newVirtualFullName = FileUtility.RenameBaseDirectory(virtualFullName, directoryName, copiedFileName); fileItem.SetEvaluatedMetadata("Link", FileUtility.GetRelativePath(node.Project.Directory, newVirtualFullName)); } ProjectService.AddProjectItem(node.Project, newItem); } } } } FileService.CopyFile(directoryName, copiedFileName, true, false); DirectoryNode newNode = new DirectoryNode(copiedFileName); newNode.InsertSorted(node); if (includeInProject) { IncludeFileInProject.IncludeDirectoryNode(newNode, false); } newNode.Expanding(); } else if (includeInProject) { foreach (TreeNode childNode in node.Nodes) { if (childNode is DirectoryNode) { DirectoryNode directoryNode = (DirectoryNode)childNode; if (FileUtility.IsEqualFileName(directoryNode.Directory, copiedFileName)) { IncludeFileInProject.IncludeDirectoryNode(directoryNode, true); } } } } }
ProjectItem ConvertDirectoryToProjectItem(FileProjectItem fileItem) { string subDirectoryName = GetFirstSubDirectoryName(fileItem.Include); if (IsDirectoryInsideProject(subDirectoryName)) { return(CreateDirectoryProjectItemIfDirectoryNotAlreadyIncluded(subDirectoryName)); } return(null); }
ProjectItem CreateDirectoryProjectItem(string directoryName) { var directoryItem = new FileProjectItem(project.MSBuildProject, ItemType.Folder); directoryItem.Include = directoryName; return(new ProjectItem(project, directoryItem) { Kind = Constants.vsProjectItemKindPhysicalFolder }); }
void AddDependentFileToProject(string fileName, string dependentUpon) { var fileProjectItem = new FileProjectItem(project, ItemType.Compile) { FileName = fileName, DependentUpon = dependentUpon }; AddProjectItemToProject(fileProjectItem); }
public void CreateDirectoryNode_FileProjectItemThatEndsWithBackSlash_DirectoryNodeCreatedWithBackSlashRemoved() { CreateProject(); project.FileName = @"d:\projects\MyProject\MyProject.csproj"; FileProjectItem projectItem = CreateFileProjectItem(@"MyFolder\"); DirectoryNode node = DirectoryNodeFactory.CreateDirectoryNode(projectItem, FileNodeStatus.None); Assert.AreEqual(@"d:\projects\MyProject\MyFolder", node.Directory); }
public void GetParentFileProjectItem_ResxFileNameAndProjectHasNoFiles_ReturnsNull() { CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj"); CreateDependentFile(); string fileName = @"d:\projects\MyProject\test.resx"; FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName); Assert.IsNull(projectItem); }
protected virtual void CopyItems(IProject sourceProject, IProject targetProject, IProgressMonitor monitor) { if (sourceProject == null) { throw new ArgumentNullException("sourceProject"); } if (targetProject == null) { throw new ArgumentNullException("targetProject"); } IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider; if (targetProjectItems == null) { throw new ArgumentNullException("targetProjectItems"); } ICollection <ProjectItem> sourceItems = sourceProject.Items; double totalWork = 0; foreach (ProjectItem item in sourceItems) { totalWork += GetRequiredWork(item); } foreach (ProjectItem item in sourceItems) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null && FileUtility.IsBaseDirectory(sourceProject.Directory, fileItem.FileName)) { FileProjectItem targetItem = new FileProjectItem(targetProject, fileItem.ItemType); fileItem.CopyMetadataTo(targetItem); targetItem.Include = fileItem.Include; if (File.Exists(fileItem.FileName)) { if (!Directory.Exists(Path.GetDirectoryName(targetItem.FileName))) { Directory.CreateDirectory(Path.GetDirectoryName(targetItem.FileName)); } try { ConvertFile(fileItem, targetItem); } catch (Exception ex) { throw new ConversionException("Error converting " + fileItem.FileName, ex); } } targetProjectItems.AddProjectItem(targetItem); } else { targetProjectItems.AddProjectItem(item.CloneFor(targetProject)); } monitor.CancellationToken.ThrowIfCancellationRequested(); monitor.Progress += GetRequiredWork(item) / totalWork; } }
protected string CalcResourceFileName(string formFileName, string cultureName) { StringBuilder resourceFileName = null; IProject project = GetProject(formFileName); if (formFileName != null && formFileName != String.Empty) { resourceFileName = new StringBuilder(Path.GetDirectoryName(formFileName)); } else if (project != null) { resourceFileName = new StringBuilder(project.Directory); } else { // required for untitled files. Untitled files should NOT save their resources. resourceFileName = new StringBuilder(Path.GetTempPath()); } resourceFileName.Append(Path.DirectorySeparatorChar); string sourceFileName = null; if (project != null && formFileName != null) { // Try to find the source file name by using the project dependencies first. FileProjectItem sourceItem = project.FindFile(formFileName); if (sourceItem != null && sourceItem.DependentUpon != null && sourceItem.DependentUpon.Length > 0) { sourceFileName = Path.GetFileNameWithoutExtension(sourceItem.DependentUpon); } } if (sourceFileName == null) { // If the source file name cannot be found using the project dependencies, // assume the resource file name to be equal to the current source file name. // Remove the ".Designer" part if present. sourceFileName = Path.GetFileNameWithoutExtension(formFileName); if (sourceFileName != null && sourceFileName.ToLowerInvariant().EndsWith(".designer")) { sourceFileName = sourceFileName.Substring(0, sourceFileName.Length - 9); } } resourceFileName.Append(sourceFileName); if (!string.IsNullOrEmpty(cultureName)) { resourceFileName.Append('.'); resourceFileName.Append(cultureName); } resourceFileName.Append('.'); resourceFileName.Append(Host.RootComponent.Site.Name);//roman// resourceFileName.Append(".resources"); return(resourceFileName.ToString()); }
protected void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem, string sourceExtension, string targetExtension, SupportedLanguage sourceLanguage, IOutputAstVisitor outputVisitor) { FixExtensionOfExtraProperties(targetItem, sourceExtension, targetExtension); if (sourceExtension.Equals(Path.GetExtension(sourceItem.FileName), StringComparison.OrdinalIgnoreCase)) { string code = ParserService.GetParseableFileContent(sourceItem.FileName); IParser p = ParserFactory.CreateParser(sourceLanguage, new StringReader(code)); p.Parse(); if (p.Errors.Count > 0) { conversionLog.AppendLine(); conversionLog.AppendLine(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.Convert.IsNotConverted}", new string[, ] { { "FileName", sourceItem.FileName } })); conversionLog.AppendLine(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.Convert.ParserErrorCount}", new string[, ] { { "ErrorCount", p.Errors.Count.ToString() } })); conversionLog.AppendLine(p.Errors.ErrorOutput); base.ConvertFile(sourceItem, targetItem); return; } List <ISpecial> specials = p.Lexer.SpecialTracker.CurrentSpecials; ConvertAst(p.CompilationUnit, specials, sourceItem); using (SpecialNodesInserter.Install(specials, outputVisitor)) { outputVisitor.VisitCompilationUnit(p.CompilationUnit, null); } p.Dispose(); if (outputVisitor.Errors.Count > 0) { conversionLog.AppendLine(); conversionLog.AppendLine(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.Convert.ConverterErrorCount}", new string[, ] { { "FileName", sourceItem.FileName }, { "ErrorCount", outputVisitor.Errors.Count.ToString() } })); conversionLog.AppendLine(outputVisitor.Errors.ErrorOutput); } targetItem.Include = Path.ChangeExtension(targetItem.Include, targetExtension); File.WriteAllText(targetItem.FileName, outputVisitor.Text); } else { base.ConvertFile(sourceItem, targetItem); } }
public void GetParentFileProjectItem_DesignerInFolderName_ReturnsNull() { CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj"); AddFileToProject("abc.cs"); CreateDependentFile(); string fileName = @"d:\projects\MyProject\abc.Designer\foo.cs"; FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName); Assert.IsNull(projectItem); }
void SaveAndOpenNewClassDiagram(IProject p, string filename, XmlDocument xmlDocument) { xmlDocument.Save(filename); FileProjectItem fpi = new FileProjectItem(p, ItemType.Content); fpi.FileName = filename; ProjectService.AddProjectItem(p, fpi); ProjectBrowserPad.RefreshViewAsync(); p.Save(); FileService.OpenFile(filename); }
ProjectItem CreateDirectoryProjectItemIfDirectoryNotAlreadyIncluded(FileProjectItem fileItem) { string directory = fileItem.Include; if (!IsDirectoryIncludedAlready(directory)) { AddIncludedDirectory(directory); return(new ProjectItem(project, fileItem)); } return(null); }
void CreateProjectWithOneFile(string fileName) { project = new TestableDTEProject(); msbuildProject = project.TestableProject; fakeFileService = project.FakeFileService; fileProjectItem = new FileProjectItem(msbuildProject, ItemType.Compile) { FileName = fileName }; }
public void GetParentFileProjectItem_ResxFileNameAndProjectHasOneCSharpFileWithDifferentFileNameToResxFile_ReturnsNull() { CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj"); AddFileToProject(@"d:\projects\MyProject\program.cs"); CreateDependentFile(); string fileName = @"d:\projects\MyProject\test.resx"; FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName); Assert.IsNull(projectItem); }
void WriteProjectFileItems(ReadOnlyCollection <ProjectItem> items) { foreach (ProjectItem item in items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null) { WriteFileNameWithoutExtension(fileItem.FileName); } } }
void ProjectCreated(object sender, ProjectEventArgs e) { if (!AddInOptions.AutomaticallyAddFiles) { return; } if (!CanBeVersionControlledFile(e.Project.Directory)) { return; } string projectDir = Path.GetFullPath(e.Project.Directory); try { using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); Status status = client.SingleStatus(projectDir); if (status.TextStatus != StatusKind.Unversioned) { return; } client.Add(projectDir, Recurse.None); if (FileUtility.IsBaseDirectory(Path.Combine(projectDir, "bin"), e.Project.OutputAssemblyFullPath)) { client.AddToIgnoreList(projectDir, "bin"); } CompilableProject compilableProject = e.Project as CompilableProject; if (compilableProject != null) { if (FileUtility.IsBaseDirectory(Path.Combine(projectDir, "obj"), compilableProject.IntermediateOutputFullPath)) { client.AddToIgnoreList(projectDir, "obj"); } } foreach (ProjectItem item in e.Project.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null) { if (FileUtility.IsBaseDirectory(projectDir, fileItem.FileName)) { AddFileWithParentDirectoriesToSvn(client, fileItem.FileName); } } } AddFileWithParentDirectoriesToSvn(client, e.Project.FileName); } } catch (SvnClientException ex) { MessageService.ShowError(ex.Message); } catch (Exception ex) { MessageService.ShowException(ex, "Project add exception"); } }
void LoadFiles(IProject project) { foreach (ProjectItem item in project.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null && File.Exists(item.FileName)) { ViewModels.MainViewModel.LoadFile(item.FileName); } } }
void WriteTestsForProjectFileItems(ReadOnlyCollection <ProjectItem> items) { foreach (ProjectItem item in items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null) { WriteTestFileName(fileItem.FileName); } } }
string GetDependentUpon(string path) { var dependentFile = new DependentFile(MSBuildProject); FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(path); if (projectItem != null) { return(Path.GetFileName(projectItem.Include)); } return(null); }
public void InitFixture() { project = WixBindingTestsHelper.CreateEmptyWixProject(); project.Name = "MySetup"; FileProjectItem item = new FileProjectItem(project, ItemType.Compile); item.Include = "Setup.wxs"; ProjectService.AddProjectItem(project, item); view = new MockWixPackageFilesView(); editor = new WixPackageFilesEditor(view, this, this, this); editor.ShowFiles(project); }
ProjectItem ConvertFileToProjectItem(FileProjectItem fileItem) { if (IsInProjectRootFolder(fileItem)) { if (IsDirectory(fileItem)) { return(CreateDirectoryProjectItemIfDirectoryNotAlreadyIncluded(fileItem)); } return(new ProjectItem(project, fileItem)); } return(ConvertDirectoryToProjectItem(fileItem)); }
XElement GetModelSchema(FileProjectItem item) { XDocument edmxDocument = XDocument.Load(item.FileName); XElement conceptualModelsElement = EDMXIO.ReadSection(edmxDocument, EDMXIO.EDMXSection.CSDL); if (conceptualModelsElement == null) { throw new ArgumentException("Input file is not a valid EDMX file."); } return(conceptualModelsElement.Element(XName.Get("Schema", csdlNamespace.NamespaceName))); }
public void GetParentFileProjectItem_DesignerFileNameInLowerCaseAndCSharpParentFileExistsInProject_ReturnsParentFileProjectItem() { CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj"); FileProjectItem expectedProjectItem = AddFileToProject("test.cs"); CreateDependentFile(); string fileName = @"d:\projects\MyProject\test.designer.cs"; FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName); Assert.AreEqual(expectedProjectItem, projectItem); }
public void GetParentFileProjectItem_ResxFileNameAndVisualBasicParentFileExistsInProject_ReturnsParentFileProjectItem() { CreateCSharpProject(@"d:\projects\MyProject\MyProject.vbproj"); FileProjectItem expectedProjectItem = AddFileToProject("test.vb"); CreateDependentFile(); string fileName = @"d:\projects\MyProject\test.resx"; FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName); Assert.AreEqual(expectedProjectItem, projectItem); }
public void GetParentFileProjectItem_DesignerInFolderNameAndInFileName_ReturnsMatchingParentProjectItem() { CreateCSharpProject(@"d:\projects\MyProject\MyProject.csproj"); FileProjectItem expectedProjectItem = AddFileToProject(@"Form.Designer\abc.cs"); CreateDependentFile(); string fileName = @"d:\projects\MyProject\Form.Designer\abc.Designer.cs"; FileProjectItem projectItem = dependentFile.GetParentFileProjectItem(fileName); Assert.AreEqual(expectedProjectItem, projectItem); }
public void SetUpFixture() { PythonMSBuildEngineHelper.InitMSBuildEngine(); List <ProjectBindingDescriptor> bindings = new List <ProjectBindingDescriptor>(); using (TextReader reader = PythonBindingAddInFile.ReadAddInFile()) { AddIn addin = AddIn.Load(reader, String.Empty); bindings.Add(new ProjectBindingDescriptor(AddInHelper.GetCodon(addin, "/SharpDevelop/Workbench/ProjectBindings", "Python"))); } ProjectBindingService.SetBindings(bindings); // Set up IProjectContent so the ConvertProjectToPythonProjectCommand can // locate the startup object and determine it's filename. mockProjectContent = new ICSharpCode.Scripting.Tests.Utils.MockProjectContent(); MockClass mainClass = new MockClass(mockProjectContent, startupObject); mainClass.CompilationUnit.FileName = @"d:\projects\test\src\Main2.cs"; mockProjectContent.SetClassToReturnFromGetClass(startupObject, mainClass); convertProjectCommand = new DerivedConvertProjectToPythonProjectCommand(); convertProjectCommand.ProjectContent = mockProjectContent; convertProjectCommand.FileServiceDefaultEncoding = Encoding.Unicode; Solution solution = new Solution(new MockProjectChangeWatcher()); sourceProject = new MSBuildBasedProject( new ProjectCreateInformation() { Solution = solution, OutputProjectFileName = @"d:\projects\test\source.csproj", ProjectName = "source" }); sourceProject.Parent = solution; sourceProject.SetProperty(null, null, "StartupObject", startupObject, PropertyStorageLocations.Base, true); mainFile = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main.cs"); targetProject = (PythonProject)convertProjectCommand.CallCreateProject(@"d:\projects\test\converted", sourceProject); convertProjectCommand.CallCopyProperties(sourceProject, targetProject); targetMainFile = new FileProjectItem(targetProject, mainFile.ItemType, mainFile.Include); mainFile.CopyMetadataTo(targetMainFile); main2File = new FileProjectItem(sourceProject, ItemType.Compile, @"src\Main2.cs"); targetMain2File = new FileProjectItem(targetProject, main2File.ItemType, main2File.Include); main2File.CopyMetadataTo(targetMain2File); convertProjectCommand.AddParseableFileContent(mainFile.FileName, mainSource); convertProjectCommand.AddParseableFileContent(main2File.FileName, main2Source); convertProjectCommand.CallConvertFile(mainFile, targetMainFile); convertProjectCommand.CallConvertFile(main2File, targetMain2File); }
private static bool IsFeatureOrAppConfigFile(FileProjectItem projectFile) { string fileName = Path.GetFileName(projectFile.FileName); string extension = Path.GetExtension(fileName); if (extension == null || fileName == null) { return(false); } return(extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase) || fileName.Equals("app.config", StringComparison.InvariantCultureIgnoreCase)); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { context.RunAsync(() => { var ideSingleFileGenerator = new IdeSingleFileGenerator(); string outputFilePath = context.GetOutputFileName(item, ".feature"); ideSingleFileGenerator.GenerateFile(item.FileName, outputFilePath, () => new SharpDevelop4GeneratorServices(item.Project)); WorkbenchSingleton.SafeThreadCall( () => context.EnsureOutputFileIsInProject(item, outputFilePath)); }); }
static string[] GetFileProjectItemAsString(FileProjectItem fileItem) { if (fileItem == null) { return(new string[3]); } return(new string[] { "Include: " + fileItem.Include, "FileName: " + fileItem.FileName, "Type: " + fileItem.ItemType }); }
public void AddFile_NewFileToBeAddedInBinFolderWithBinFolderNameInUpperCase_FileIsNotAddedToProject() { CreateTestProject(@"d:\projects\MyProject\MyProject.csproj"); CreateProjectSystem(project); string fileName = @"BIN\NewFile.dll"; projectSystem.AddFile(fileName, null); FileProjectItem fileItem = ProjectHelper.GetFileFromInclude(project, fileName); Assert.IsNull(fileItem); }
FileProjectItem CreateFileProjectItemUsingPathRelativeToProject(ItemType itemType, string include) { var fileItem = new FileProjectItem(MSBuildProject, itemType) { Include = include }; if (IsLink(include)) { fileItem.SetEvaluatedMetadata("Link", Path.GetFileName(include)); } return(fileItem); }
public override void Run() { TreeNode selectedNode = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedNode; DirectoryNode node = selectedNode as DirectoryNode; if (node == null) { node = selectedNode.Parent as DirectoryNode; } if (node == null) { return; } node.Expanding(); node.Expand(); using (OpenFileDialog fdiag = new OpenFileDialog()) { fdiag.AddExtension = true; string[] fileFilters = (string[])(AddInTree.GetTreeNode("/SharpDevelop/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string)); fdiag.FilterIndex = GetFileFilterIndex(node.Project, fileFilters); fdiag.Filter = String.Join("|", fileFilters); fdiag.Multiselect = true; fdiag.CheckFileExists = true; fdiag.Title = StringParser.Parse("${res:ProjectComponent.ContextMenu.AddExistingFiles}"); if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) { List<KeyValuePair<string, string>> fileNames = new List<KeyValuePair<string, string>>(fdiag.FileNames.Length); foreach (string fileName in fdiag.FileNames) { fileNames.Add(new KeyValuePair<string, string>(fileName, "")); } bool addedDependentFiles = false; foreach (string fileName in fdiag.FileNames) { foreach (string additionalFile in FindAdditionalFiles(fileName)) { if (!fileNames.Exists(delegate(KeyValuePair<string, string> pair) { return FileUtility.IsEqualFileName(pair.Key, additionalFile); })) { addedDependentFiles = true; fileNames.Add(new KeyValuePair<string, string>(additionalFile, Path.GetFileName(fileName))); } } } string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(fileNames[0].Key)); if (!FileUtility.IsEqualFileName(fileNames[0].Key, copiedFileName)) { int res = MessageService.ShowCustomDialog(fdiag.Title, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Question}", 0, 2, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Copy}", "${res:ProjectComponent.ContextMenu.AddExistingFiles.Link}", "${res:Global.CancelButtonText}"); if (res == 1) { foreach (KeyValuePair<string, string> pair in fileNames) { string fileName = pair.Key; string relFileName = FileUtility.GetRelativePath(node.Project.Directory, fileName); FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject); FileProjectItem fileProjectItem = new FileProjectItem(node.Project, node.Project.GetDefaultItemType(fileName), relFileName); fileProjectItem.SetEvaluatedMetadata("Link", Path.Combine(node.RelativePath, Path.GetFileName(fileName))); fileProjectItem.DependentUpon = pair.Value; fileNode.ProjectItem = fileProjectItem; fileNode.AddTo(node); ProjectService.AddProjectItem(node.Project, fileProjectItem); } node.Project.Save(); if (addedDependentFiles) node.RecreateSubNodes(); return; } if (res == 2) { return; } } bool replaceAll = false; foreach (KeyValuePair<string, string> pair in fileNames) { copiedFileName = Path.Combine(node.Directory, Path.GetFileName(pair.Key)); if (!replaceAll && File.Exists(copiedFileName) && !FileUtility.IsEqualFileName(pair.Key, copiedFileName)) { ReplaceExistingFile res = ShowReplaceExistingFileDialog(fdiag.Title, Path.GetFileName(pair.Key), true); if (res == ReplaceExistingFile.YesToAll) { replaceAll = true; } else if (res == ReplaceExistingFile.No) { continue; } else if (res == ReplaceExistingFile.Cancel) { break; } } FileProjectItem item = CopyFile(pair.Key, node, true); if (item != null) { item.DependentUpon = pair.Value; } } node.Project.Save(); if (addedDependentFiles) node.RecreateSubNodes(); } } }
public static FileProjectItem IncludeFileNode(FileNode fileNode) { if (fileNode.Parent is FileNode) { if (((FileNode)fileNode.Parent).FileNodeStatus != FileNodeStatus.InProject) { IncludeFileNode((FileNode)fileNode.Parent); } } if (fileNode.Parent is DirectoryNode && !(fileNode.Parent is ProjectNode)) { if (((DirectoryNode)fileNode.Parent).FileNodeStatus != FileNodeStatus.InProject) { IncludeDirectoryNode((DirectoryNode)fileNode.Parent, false); } } ItemType type = fileNode.Project.GetDefaultItemType(fileNode.FileName); FileProjectItem newItem = new FileProjectItem(fileNode.Project, type); newItem.Include = FileUtility.GetRelativePath(fileNode.Project.Directory, fileNode.FileName); ProjectService.AddProjectItem(fileNode.Project, newItem); fileNode.ProjectItem = newItem; fileNode.FileNodeStatus = FileNodeStatus.InProject; if (fileNode.Parent is ExtTreeNode) { ((ExtTreeNode)fileNode.Parent).UpdateVisibility(); } fileNode.Project.Save(); return newItem; }
public static void IncludeDirectoryNode(DirectoryNode directoryNode, bool includeSubNodes) { if (directoryNode.Parent is DirectoryNode && !(directoryNode.Parent is ProjectNode)) { if (((DirectoryNode)directoryNode.Parent).FileNodeStatus != FileNodeStatus.InProject) { IncludeDirectoryNode((DirectoryNode)directoryNode.Parent, false); } } FileProjectItem newItem = new FileProjectItem( directoryNode.Project, ItemType.Folder, FileUtility.GetRelativePath(directoryNode.Project.Directory, directoryNode.Directory) ); ProjectService.AddProjectItem(directoryNode.Project, newItem); directoryNode.ProjectItem = newItem; directoryNode.FileNodeStatus = FileNodeStatus.InProject; if (includeSubNodes) { foreach (TreeNode childNode in directoryNode.Nodes) { if (childNode is ExtTreeNode) { ((ExtTreeNode)childNode).Expanding(); } if (childNode is FileNode) { IncludeFileNode((FileNode)childNode); } else if (childNode is DirectoryNode) { IncludeDirectoryNode((DirectoryNode)childNode, includeSubNodes); } } } directoryNode.Project.Save(); }
protected IEnumerable<FileProjectItem> AddExistingItems() { DirectoryNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedDirectoryNode; if (node == null) { return null; } node.Expanding(); node.Expand(); List<FileProjectItem> addedItems = new List<FileProjectItem>(); using (OpenFileDialog fdiag = new OpenFileDialog()) { fdiag.AddExtension = true; var fileFilters = ProjectService.GetFileFilters(); fdiag.InitialDirectory = node.Directory; fdiag.FilterIndex = GetFileFilterIndex(node.Project, fileFilters); fdiag.Filter = String.Join("|", fileFilters); fdiag.Multiselect = true; fdiag.CheckFileExists = true; fdiag.Title = StringParser.Parse("${res:ProjectComponent.ContextMenu.AddExistingFiles}"); if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window) == DialogResult.OK) { List<KeyValuePair<string, string>> fileNames = new List<KeyValuePair<string, string>>(fdiag.FileNames.Length); foreach (string fileName in fdiag.FileNames) { fileNames.Add(new KeyValuePair<string, string>(fileName, "")); } bool addedDependentFiles = false; foreach (string fileName in fdiag.FileNames) { foreach (string additionalFile in FindAdditionalFiles(fileName)) { if (!fileNames.Exists(delegate(KeyValuePair<string, string> pair) { return FileUtility.IsEqualFileName(pair.Key, additionalFile); })) { addedDependentFiles = true; fileNames.Add(new KeyValuePair<string, string>(additionalFile, Path.GetFileName(fileName))); } } } string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(fileNames[0].Key)); if (!FileUtility.IsEqualFileName(fileNames[0].Key, copiedFileName)) { int res = MessageService.ShowCustomDialog( fdiag.Title, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Question}", 0, 2, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Copy}", "${res:ProjectComponent.ContextMenu.AddExistingFiles.Link}", "${res:Global.CancelButtonText}"); if (res == 1) { // Link foreach (KeyValuePair<string, string> pair in fileNames) { string fileName = pair.Key; string relFileName = FileUtility.GetRelativePath(node.Project.Directory, fileName); FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject); FileProjectItem fileProjectItem = new FileProjectItem(node.Project, node.Project.GetDefaultItemType(fileName), relFileName); fileProjectItem.SetEvaluatedMetadata("Link", Path.Combine(node.RelativePath, Path.GetFileName(fileName))); fileProjectItem.DependentUpon = pair.Value; addedItems.Add(fileProjectItem); fileNode.ProjectItem = fileProjectItem; fileNode.InsertSorted(node); ProjectService.AddProjectItem(node.Project, fileProjectItem); } node.Project.Save(); if (addedDependentFiles) node.RecreateSubNodes(); return addedItems.AsReadOnly(); } if (res == 2) { // Cancel return addedItems.AsReadOnly(); } // only continue for res==0 (Copy) } bool replaceAll = false; foreach (KeyValuePair<string, string> pair in fileNames) { copiedFileName = Path.Combine(node.Directory, Path.GetFileName(pair.Key)); if (!replaceAll && File.Exists(copiedFileName) && !FileUtility.IsEqualFileName(pair.Key, copiedFileName)) { ReplaceExistingFile res = ShowReplaceExistingFileDialog(fdiag.Title, Path.GetFileName(pair.Key), true); if (res == ReplaceExistingFile.YesToAll) { replaceAll = true; } else if (res == ReplaceExistingFile.No) { continue; } else if (res == ReplaceExistingFile.Cancel) { break; } } FileProjectItem item = CopyFile(pair.Key, node, true); if (item != null) { addedItems.Add(item); item.DependentUpon = pair.Value; } } node.Project.Save(); if (addedDependentFiles) node.RecreateSubNodes(); } } return addedItems.AsReadOnly(); }
protected virtual void CopyItems(IProject sourceProject, IProject targetProject, IProgressMonitor monitor) { if (sourceProject == null) throw new ArgumentNullException("sourceProject"); if (targetProject == null) throw new ArgumentNullException("targetProject"); IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider; if (targetProjectItems == null) throw new ArgumentNullException("targetProjectItems"); ICollection<ProjectItem> sourceItems = sourceProject.Items; double totalWork = 0; foreach (ProjectItem item in sourceItems) { totalWork += GetRequiredWork(item); } foreach (ProjectItem item in sourceItems) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null && FileUtility.IsBaseDirectory(sourceProject.Directory, fileItem.FileName)) { FileProjectItem targetItem = new FileProjectItem(targetProject, fileItem.ItemType); fileItem.CopyMetadataTo(targetItem); targetItem.Include = fileItem.Include; if (File.Exists(fileItem.FileName)) { if (!Directory.Exists(Path.GetDirectoryName(targetItem.FileName))) { Directory.CreateDirectory(Path.GetDirectoryName(targetItem.FileName)); } try { ConvertFile(fileItem, targetItem); } catch (Exception ex) { throw new ConversionException("Error converting " + fileItem.FileName, ex); } } targetProjectItems.AddProjectItem(targetItem); } else { targetProjectItems.AddProjectItem(item.CloneFor(targetProject)); } monitor.CancellationToken.ThrowIfCancellationRequested(); monitor.Progress += GetRequiredWork(item) / totalWork; } }
protected abstract void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem);
protected virtual void CopyItems(IProject sourceProject, IProject targetProject) { if (sourceProject == null) throw new ArgumentNullException("sourceProject"); if (targetProject == null) throw new ArgumentNullException("targetProject"); IProjectItemListProvider targetProjectItems = targetProject as IProjectItemListProvider; if (targetProjectItems == null) throw new ArgumentNullException("targetProjectItems"); foreach (ProjectItem item in sourceProject.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem != null && FileUtility.IsBaseDirectory(sourceProject.Directory, fileItem.FileName)) { FileProjectItem targetItem = new FileProjectItem(targetProject, fileItem.ItemType); fileItem.CopyMetadataTo(targetItem); targetItem.Include = fileItem.Include; if (File.Exists(fileItem.FileName)) { if (!Directory.Exists(Path.GetDirectoryName(targetItem.FileName))) { Directory.CreateDirectory(Path.GetDirectoryName(targetItem.FileName)); } ConvertFile(fileItem, targetItem); } targetProjectItems.AddProjectItem(targetItem); } else { targetProjectItems.AddProjectItem(item.CloneFor(targetProject)); } } }
protected void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem, string sourceExtension, string targetExtension, SupportedLanguage sourceLanguage, IOutputAstVisitor outputVisitor) { FixExtensionOfExtraProperties(targetItem, sourceExtension, targetExtension); if (sourceExtension.Equals(Path.GetExtension(sourceItem.FileName), StringComparison.OrdinalIgnoreCase)) { string code = ParserService.GetParseableFileContent(sourceItem.FileName); IParser p = ParserFactory.CreateParser(sourceLanguage, new StringReader(code)); p.Parse(); if (p.Errors.Count > 0) { conversionLog.AppendLine(); conversionLog.AppendLine(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.Convert.IsNotConverted}", new string[,] {{"FileName", sourceItem.FileName}})); conversionLog.AppendLine(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.Convert.ParserErrorCount}", new string[,] {{"ErrorCount", p.Errors.Count.ToString()}})); conversionLog.AppendLine(p.Errors.ErrorOutput); base.ConvertFile(sourceItem, targetItem); return; } List<ISpecial> specials = p.Lexer.SpecialTracker.CurrentSpecials; ConvertAst(p.CompilationUnit, specials); using (SpecialNodesInserter.Install(specials, outputVisitor)) { outputVisitor.VisitCompilationUnit(p.CompilationUnit, null); } p.Dispose(); if (outputVisitor.Errors.Count > 0) { conversionLog.AppendLine(); conversionLog.AppendLine(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.Convert.ConverterErrorCount}", new string[,] { {"FileName", sourceItem.FileName}, {"ErrorCount", outputVisitor.Errors.Count.ToString()} })); conversionLog.AppendLine(outputVisitor.Errors.ErrorOutput); } targetItem.Include = Path.ChangeExtension(targetItem.Include, targetExtension); File.WriteAllText(targetItem.FileName, outputVisitor.Text); } else { base.ConvertFile(sourceItem, targetItem); } }
protected virtual void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem) { if (!File.Exists(targetItem.FileName)) { File.Copy(sourceItem.FileName, targetItem.FileName); } }
protected virtual void FixExtensionOfExtraProperties(FileProjectItem item, string sourceExtension, string targetExtension) { sourceExtension = sourceExtension.ToLowerInvariant(); List<KeyValuePair<string, string>> replacements = new List<KeyValuePair<string, string>>(); foreach (string metadataName in item.MetadataNames) { if ("Include".Equals(metadataName, StringComparison.OrdinalIgnoreCase)) continue; string value = item.GetMetadata(metadataName); if (value.ToLowerInvariant().EndsWith(sourceExtension)) { replacements.Add(new KeyValuePair<string, string>(metadataName, value)); } } foreach (KeyValuePair<string, string> pair in replacements) { item.SetMetadata(pair.Key, Path.ChangeExtension(pair.Value, targetExtension)); } }