private void SaveFile(XmlModel xmlModel) { if (string.IsNullOrEmpty(xmlModel.FilePath)) { string fileName = _dialogService.SaveFileDialog(); if (!string.IsNullOrEmpty(fileName)) { xmlModel.FileName = Path.GetFileName(fileName); xmlModel.FilePath = fileName; } else { return; } } try { File.WriteAllText(xmlModel.FilePath, xmlModel.Xml.Text); xmlModel.HasChanges = false; } catch (Exception exc) { _dialogService.InfoBox( Resources.ErrorCaption, exc.Message); } }
private void OpenFile() { string fileName = _dialogService.OpenFileDialog(); if (!string.IsNullOrEmpty(fileName)) { string xml; try { xml = File.ReadAllText(fileName); } catch (Exception exc) { _dialogService.InfoBox( Resources.ErrorCaption, exc.Message); return; } XmlModel xmlModel = new XmlModel( Path.GetFileName(fileName), fileName, xml); AddXml(xmlModel); } }
private void CloseFile(XmlModel xmlModel, bool remove = true) { if (xmlModel.HasChanges) { bool shouldSave = _dialogService.PromptMessageBox( Resources.CloseCaption, string.Format(Resources.CloseText, xmlModel.FileName)); if (shouldSave) { SaveFile(xmlModel); } } if (remove) { XmlModels.Remove(xmlModel); } }
private void NewFile() { XmlModel xmlModel = new XmlModel(Resources.NewTab + " " + _fileIndex++); AddXml(xmlModel); }
private void AddXml(XmlModel xmlModel) { XmlModels.Add(xmlModel); SelectedXml = xmlModel; }