public void Move(CodeFile file) { var window = new OpenFolderWindow(System.IO.Path.GetDirectoryName(file.Path)); bool?result = window.ShowDialog(); if (result.HasValue && result.Value) { // Сохраняем исходный file.Save(); try { // Перемещение file.Move(System.IO.Path.Combine(window.Path, file.Name)); CodeProjectManager.Instance.SaveCurrent(); } catch (FileMoveException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_MoveFile_short"), FullDesc = LocalString.Get("Error_MoveFile_full"), Exception = ex }; err.ShowDialog(); } } }
private void SaveXML() { try { using (var w = new XmlTextWriter(Path, Encoding.UTF8)) { w.Formatting = Formatting.Indented; w.WriteStartElement("Project"); //w.WriteAttributeString("Name", Name); w.WriteAttributeString("NextDefaultFileNumber", NextDefaultFileNumber.ToString()); w.WriteStartElement("Files"); foreach (CodeFile file in Files) { try { file.Save(); // Файл будет записан в проект, только если сохранение успешно прошло w.WriteStartElement("File"); w.WriteAttributeString("Path", file.Path); w.WriteEndElement(); // File } catch (SaveCodeFileException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_SaveFileInProject_short") + " '" + System.IO.Path.GetFileName(ex.FileName) + "'.", FullDesc = LocalString.Get("Error_SaveFileInProject_full"), Exception = ex }; err.ShowDialog(); } } w.WriteEndElement(); // Files w.WriteStartElement("WorkDirs"); foreach (string dir in WorkDirs) { w.WriteStartElement("WorkDir"); w.WriteAttributeString("Path", dir); w.WriteEndElement(); } w.WriteEndElement(); // WorkDirs w.WriteEndElement(); // Project } } catch (IOException ex) { throw new SaveProjectException(Path, ex); } catch (UnauthorizedAccessException ex) { throw new SaveProjectException(Path, ex); } }
public void SaveCurrent() { try { if (Current != null) { Current.Save(); } } catch (SaveProjectException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_SaveProject_short"), FullDesc = LocalString.Get("Error_SaveProject_full"), Exception = ex }; err.ShowDialog(); } }
public void Load(string path) { try { // Закрыть предыдущий if (Current != null) { CloseCurrent(); } // Открыть новый Current = CodeProject.Load(path); // Поставить фокус на проджект эксплорер //_mainWindowView.ActivateProjectExplorer(); Logger.LogWithBinding("Status_ProjectOpened"); } catch (ParsingProjectException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_OpenProject_short"), FullDesc = LocalString.Get("Error_OpenProject_full"), Exception = ex }; err.ShowDialog(); } catch (FileNotFoundException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_OpenProject_short"), FullDesc = LocalString.Get("Error_OpenProject_full"), Exception = ex }; err.ShowDialog(); } }
public void CloseCurrent() { try { if (Current != null) { Current.Close(); Current = null; Logger.LogWithBinding("Status_ProjectClosed"); } } catch (SaveProjectException ex) { ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_CloseProject_short"), FullDesc = LocalString.Get("Error_CloseProject_full"), Exception = ex }; err.ShowDialog(); } }
private void LoadXML() { try { using (var xml_reader = new XmlTextReader(Path)) using (var reader = new XmlValidatingReader(xml_reader)) { int fileErrorsCounter = 0; XmlSchema schema = XmlSchema.Read(new StringReader(Resources.ResourceManager.GetString("ProjectSchema")), null); reader.Schemas.Add(schema); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Project") { //project.Name = reader.GetAttribute("Name"); //project.DefaultCodeFileExtension = reader.GetAttribute("DefaultCodeFileExtension"); NextDefaultFileNumber = Convert.ToInt32(reader.GetAttribute("NextDefaultFileNumber")); } // Files else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Files") { } else if (reader.NodeType == XmlNodeType.Element && reader.Name == "File") { try { CodeFile file = new CodeFile(reader.GetAttribute("Path"), false); AddFile(file, false); } catch (LoadCodeFileException ex) { fileErrorsCounter++; ErrorWindow err = new ErrorWindow { ShortDesc = LocalString.Get("Error_LoadFileInProject_short") + " '" + System.IO.Path.GetFileName(ex.FileName) + "'.", FullDesc = LocalString.Get("Error_LoadFileInProject_full"), Exception = ex }; err.ShowDialog(); } } // WorkDirs else if (reader.NodeType == XmlNodeType.Element && reader.Name == "WorkDirs") { } if (reader.NodeType == XmlNodeType.Element && reader.Name == "WorkDir") { WorkDirs.Add(reader.GetAttribute("Path")); } } if (fileErrorsCounter > 0) { } } } catch (IOException ex) { throw new ParsingProjectException(Path, ex); } catch (XmlException ex) { throw new ParsingProjectException(Path, ex); } catch (XmlSchemaException ex) { throw new ParsingProjectException(Path, ex); } catch (UnauthorizedAccessException ex) { throw new ParsingProjectException(Path, ex); } }