private void Load_Click(object sender, RoutedEventArgs e) { OpenFileDialog open = new OpenFileDialog(); try { if (open.ShowDialog() == true) { //Reads a Project_File file Project_File project = GetProject(open.FileName); Update_Writer(0, project); //Stores the location of the opened file SetLocation(open.FileName); Directory directory = GetDirectory(); string json = JsonConvert.SerializeObject(project); directory.projectPaths.Add(open.FileName); json = JsonConvert.SerializeObject(directory); File.WriteAllText(loadDirectory, json); Update_Projects(); } } catch { //Error expected then the file is empty. } }
private void Update_Selection(Project_File project) { this.Snippet_Select.Items.Clear(); foreach (snippet document in project.snippets) { if (this.Snippet_Select.Items.Contains(document.Name) == false) { this.Snippet_Select.Items.Add(document.Name); } } }
private void Save_Click(object sender, RoutedEventArgs e) { /* * Takes the values from the xaml and * saves them into a a project file. */ SaveFileDialog saveFile = new SaveFileDialog(); saveFile.FileName = this.Project_Text.Text; saveFile.DefaultExt = ".json"; if (saveFile.ShowDialog() == true) { Project_File project = new Project_File(); bool isDocumentFound = false; string projectFile = File.ReadAllText(saveFile.FileName); project = JsonConvert.DeserializeObject <Project_File>(projectFile); #region Matching Snippet search int i = 0; foreach (snippet Snippet in project.snippets) { if (Snippet.Name == this.Name_Text.Text) { //Matching document IS found isDocumentFound = true; project.snippets[i].Name = this.Name_Text.Text; project.snippets[i].Text = this.Writer_Main_Text.Text; project.snippets[i].Project = this.Project_Text.Text; project.snippets[i].CharacterCount = Convert.ToInt32(this.Character_Count_Text.Text); project.snippets[i].WordCount = Convert.ToInt32(this.WordCount_Text.Text); //project.Snippets[i].CreationDate = this.Name_Text.Text; project.snippets[i].LastEdit = DateTime.Now.ToString("dd.Mm.yy"); } i++; } if (isDocumentFound == false) { //Matching document is NOT found project.snippets.Add(GetSnippet()); } #endregion string editedproject = JsonConvert.SerializeObject(project); File.WriteAllText(saveFile.FileName, editedproject); Update_Selection(project); //Saves the adress of the saved file SetLocation(saveFile.FileName); } }
private void Update_Projects() { Directory directory = GetDirectory(); foreach (string path in directory.projectPaths) { if (this.Project_Select.Items.Contains(path) == false) { Project_File project = GetProject(path); this.Project_Select.Items.Add(project.ProjectName); } } }
private void Delete_Click(object sender, RoutedEventArgs e) { //Deletes a document file from the project Directory directory = GetDirectory(); Project_File project = GetProject(directory.lastAdress); int index = this.Snippet_Select.SelectedIndex; project.snippets.RemoveAt(index); string editedproject = JsonConvert.SerializeObject(project); File.WriteAllText(directory.lastAdress, editedproject); this.Snippet_Select.Items.RemoveAt(index); }
private void Update_Writer(int index, Project_File project) { /* * Writes the information of an indexed document of a project * into the writer interface. */ snippet Snippet = project.snippets[index]; this.Name_Text.Text = project.snippets[index].Name; this.Writer_Main_Text.Text = project.snippets[index].Text; this.Project_Text.Text = project.snippets[index].Project; //this.Character_Count_Text.Text) = project.Snippets[index].CharacterCount this.WordCount_Text.Text = Convert.ToString(project.snippets[index].WordCount); Update_Selection(project); }
private void CreateProject_Click(object sender, RoutedEventArgs e) { Directory directory = GetDirectory(); Project_File project = new Project_File(); SaveFileDialog saveFile = new SaveFileDialog(); saveFile.DefaultExt = ".json"; if (saveFile.ShowDialog() == true) { project.ProjectName = saveFile.FileName; string json = JsonConvert.SerializeObject(project); File.WriteAllText(saveFile.FileName, json); directory.projectPaths.Add(saveFile.FileName); json = JsonConvert.SerializeObject(directory); File.WriteAllText(loadDirectory, json); } }
private void Project_Select_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { Directory directory = GetDirectory(); string projectPath = directory.projectPaths[this.Project_Select.SelectedIndex]; //Reads a Project_File file Project_File project = GetProject(projectPath); Update_Writer(0, project); //Stores the location of the opened file SetLocation(projectPath); } catch { //Error expected then the file is empty. } }
private void Snippet_Select_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Loads the relevant document file when the chapter select changes try { //Updates the writer text to reflect the chosen selection Directory directory = GetDirectory(); Project_File project = GetProject(directory.lastAdress); int index = this.Snippet_Select.SelectedIndex; Update_Writer(index, project); //Saves the selected item for its future automatic loading directory.writerIndex = this.Snippet_Select.SelectedIndex; File.WriteAllText(loadDirectory, JsonConvert.SerializeObject(directory)); } catch { /* * NO CONSEQUENCES FOR FAILURE * * Initial application will not find a project file. */ } }
private Project_File GetProject(string path) { Project_File project = JsonConvert.DeserializeObject <Project_File>(File.ReadAllText(path)); return(project); }