private void SaveAs() { string file = this.Editor.File; if (!Mainframe.IsFilePathValid(file)) { file = Settings.User.RecentFile(); string dir; if (Mainframe.IsFilePathValid(file)) { dir = Path.GetDirectoryName(file); } else { dir = Mainframe.DefaultProjectFolder(); } file = Path.Combine(dir, this.Editor.Project.Name + Mainframe.FileExtention); } SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = Path.GetDirectoryName(Path.GetFullPath(file)); dialog.FileName = Path.GetFileName(file); dialog.Filter = Mainframe.FileFilter; dialog.DefaultExt = Mainframe.FileExtention; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { this.Save(dialog.FileName); } }
private void Import() { if (this.Editor != null && this.Editor.InEditMode) { string dir = Mainframe.DefaultProjectFolder(); string recent = Settings.User.RecentFile(); if (Mainframe.IsFilePathValid(recent)) { dir = Path.GetDirectoryName(recent); } SettingsStringCache location = new SettingsStringCache(Settings.User, "ImportFile.Folder", dir); OpenFileDialog dialog = new OpenFileDialog { Filter = Mainframe.FileFilter, DefaultExt = Mainframe.FileExtention, InitialDirectory = Mainframe.IsDirectoryPathValid(location.Value) ? location.Value : Mainframe.DefaultProjectFolder() }; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { string file = dialog.FileName; location.Value = Path.GetDirectoryName(file); this.Editor.Import(file); } } }
public static void OpenFile(string fileName) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (!Mainframe.IsFilePathValid(fileName) || !File.Exists(fileName)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "File \"{0}\" does not exist", fileName)); } App.Mainframe.Dispatcher.Invoke(() => App.Mainframe.Open(fileName)); }
internal static string AutoSaveFile(string file) { if (Mainframe.IsFilePathValid(file) && Path.HasExtension(file)) { string extension = Path.GetExtension(file); if (!string.IsNullOrEmpty(extension) && 2 < extension.Length) { return(file.Substring(0, file.Length - 2) + "~$"); } } return(null); }
private void Save() { string file = this.Editor.File; if (Mainframe.IsFilePathValid(file)) { this.Save(file); } else { this.SaveAs(); } }
private void OpenRecent(string file) { if (Mainframe.IsFilePathValid(file) && File.Exists(file)) { if (this.Editor == null || this.EnsureSaved()) { this.Edit(file); } } else if (file != null) { MessageBoxResult result = DialogMessage.Show(this, this.Title, Properties.Resources.MessageInvalidRecentFile(file), null, MessageBoxImage.Question, MessageBoxButton.YesNo ); if (result == MessageBoxResult.Yes) { Settings.User.DeleteRecentFile(file); } } }
private void ButtonFileClick(object sender, RoutedEventArgs e) { try { string file = this.FilePath; if (!Mainframe.IsFilePathValid(file)) { file = this.DefaultFileName(); } SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = Path.GetDirectoryName(file); dialog.FileName = Path.GetFileName(file); dialog.Filter = Properties.Resources.ImageFileFilter; dialog.DefaultExt = this.Encoder.Name; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { this.SetFilePath(dialog.FileName); this.SetEncoder(this.CurrentExtension()); } } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private void ButtonOkClick(object sender, RoutedEventArgs e) { try { BindingExpression filePathBindingExpression = BindingOperations.GetBindingExpression(this.fileName, TextBox.TextProperty); filePathBindingExpression.UpdateSource(); if (File.Exists(this.FilePath)) { if (MessageBoxResult.No == DialogMessage.Show(this, this.Title, Properties.Resources.MessageImageFileExists(this.FilePath), null, MessageBoxImage.Warning, MessageBoxButton.YesNo )) { return; } } if (!Mainframe.IsFilePathValid(this.FilePath)) { DialogMessage.Show(this, this.Title, Properties.Resources.ImagePathInvalid, null, MessageBoxImage.Error, MessageBoxButton.OK ); return; } RenderTargetBitmap bitmap = this.editor.ExportImage(); Tracer.Assert(bitmap != null); using (FileStream stream = new FileStream(this.FilePath, FileMode.Create)) { BitmapEncoder encoder = this.Encoder.BitmapEncoder; encoder.Frames.Clear(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); encoder.Save(stream); } this.imageExportType.Value = this.Encoder.Name; this.imageExportFolder.Value = Path.GetDirectoryName(this.FilePath); e.Handled = true; this.DialogResult = true; } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private void Open() { if (this.Editor == null || this.EnsureSaved()) { OpenFileDialog dialog = new OpenFileDialog(); string file = Settings.User.RecentFile(); if (Mainframe.IsFilePathValid(file)) { dialog.InitialDirectory = Path.GetDirectoryName(Path.GetFullPath(file)); } else { dialog.InitialDirectory = Mainframe.DefaultProjectFolder(); } dialog.Filter = Mainframe.FileFilter; dialog.DefaultExt = Mainframe.FileExtention; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { file = dialog.FileName; this.Edit(file); } } }
public static bool IsFileExists(string file) { return(Mainframe.IsFilePathValid(file) && File.Exists(file)); }