public ProjectFileRow(ProjectFile file, ProjectMenu parentProjectMenu) { InitializeComponent(); File = file; ParentProjectMenu = parentProjectMenu; tbl_Filename.Text = file.FileTitle; }
public AddFileDialog(ProjectFile file) : this() { // If we have a file, we're in edit mode CurrentFile = file; // Update the UI titles string newTitle = "View / Edit File"; Title = newTitle; tbl_Title.Text = newTitle; tb_FileTitle.Text = file.FileTitle; // Process based on file type if (file.IsFile) { SelectFileAsType(); ApplyNewFileToWindow(file.Filename); } else { SelectUrlAsType(); ApplyNewUrlToWindow(file.Filename); } // Program to open if (file.ProgramToOpen != null) { ApplyNewProgramToOpenToWindow(file.ProgramToOpen); SetOpenWithDefaultStatus(false); } else { SetOpenWithDefaultStatus(true); } // Update the buttons g_AddButtons.Visibility = System.Windows.Visibility.Collapsed; g_EditButtons.Visibility = System.Windows.Visibility.Visible; }
/// <summary> /// Returns a list of the files associated with this project. /// </summary> /// <param name="project">The project whose files to return.</param> /// <returns>The list of project files.</returns> public static List<ProjectFile> GetFilesForProjectFromFile(Project project) { List<ProjectFile> projectFiles = new List<ProjectFile>(); // Get the non-empty and non-comment lines from the log file List<string> projectFileRows = GetNonEmptyAndNonCommentLinesFromFile(GetFileNameForProject(project, FileType.FILES)); // Parse the remaining lines foreach (var line in projectFileRows) { // Ensure that the line has the correct format string[] lineItems = line.Split('|'); int numberOfItems = 4; if (lineItems.Length != numberOfItems) { ErrorLogger.AddLog(string.Format("Could not parse line '{0}'. Skipping entry.", line), ErrorSeverity.HIGH); continue; } // Ensure that the first part is a valid title string fileTitle = lineItems[0]; if (fileTitle == "") { ErrorLogger.AddLog(string.Format("Could not parse file title. Value was '{0}'. Skipping entry.", fileTitle), ErrorSeverity.HIGH); continue; } // Ensure that the second part is a "true" or "false" // Note: We do this before checking the filename because that check depends on this value. string isFileString = lineItems[2]; if (isFileString != "true" && isFileString != "false") { ErrorLogger.AddLog(string.Format("Could not parse file type. Value was '{0}'. Skipping entry.", isFileString), ErrorSeverity.HIGH); continue; } bool isFile = isFileString == "true" ? true : false; // Ensure that the first part is a valid filepath string fileName = lineItems[1]; if (isFile) { try { fileName = Path.GetFullPath(fileName); } catch (ArgumentException e) { ErrorLogger.AddLog(string.Format("Could not parse filename '{0}':\n{1}\nSkipping entry.", fileName, e.Message), ErrorSeverity.HIGH); continue; } } else { Uri uriResult; bool result = Uri.TryCreate(fileName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (!result) { ErrorLogger.AddLog(string.Format("Could not parse url '{0}':\n{1}\nSkipping entry.", fileName), ErrorSeverity.HIGH); continue; } } // Ensure that the third part is a valid program or is blank string programToOpen = lineItems[3]; if (programToOpen != "") { try { programToOpen = Path.GetFullPath(programToOpen); } catch (ArgumentException e) { ErrorLogger.AddLog(string.Format("Could not parse filename '{0}':\n{1}\nSkipping entry.", programToOpen, e.Message), ErrorSeverity.HIGH); continue; } } // If we got here, we have valid project file, so create an instance ProjectFile projectFile = null; if (programToOpen == "") { projectFile = new ProjectFile(fileTitle, fileName, isFile, project); } else { projectFile = new ProjectFile(fileTitle, fileName, isFile, programToOpen, project); } projectFiles.Add(projectFile); } return projectFiles; }
private void b_AddFile_Click(object sender, RoutedEventArgs e) { AddFileDialog window = new AddFileDialog(); if (window.ShowDialog() == true) { // Create the file ProjectFile newFile; string filename = window.IsFile ? window.Filename : window.Url; if (window.OpenWithDefaultProgram) { newFile = new ProjectFile(window.FileTitle, filename, window.IsFile, CurrentProject); } else { newFile = new ProjectFile(window.FileTitle, filename, window.IsFile, window.ProgramToOpen, CurrentProject); } // Add the file AddFileToProject(newFile); RefreshFilesOnUI(); } }
/// <summary> /// Adds the given file to the project (if it is not already there). /// </summary> /// <param name="file">The file to add.</param> private void AddFileToProject(ProjectFile file) { // Add and sort the files if necessary if (!CurrentProject.Files.Contains(file)) { CurrentProject.Files.Add(file); CurrentProject.SortFiles(); } // Update the backing file ProjectFileInterface.WriteProjectFilesToFile(CurrentProject); }
/// <summary> /// Removes the given file from the project if possible. /// </summary> /// <param name="file">The file to remove.</param> public void RemoveFileEntry(ProjectFile file) { if (Files.Contains(file)) { Files.Remove(file); } }