public bool SaveAs() { bool finalResult = false; var saveMsg = new SaveFileMessage( new WorkflowFileInfo(this), this, null, result => { if (result.PerformSave) { SaveWorkflow(result.FileName); finalResult = true; } else { finalResult = false; } }); MessengerInstance.Send(saveMsg); return(finalResult); }
private static async Task ShowSaveFileDialogAsync(SaveFileMessage message) { string filename = null; try { var dialog = new SaveFileDialog() { Title = message.Title, Filters = GetSaveFilters(message.FileType == FileType.ExportedImage), DefaultExtension = GetSaveDefaultExtension(message.FileType == FileType.ExportedImage), Directory = null != message.ExistingFile ? Path.GetDirectoryName(message.ExistingFile) : null, InitialFileName = null != message.ExistingFile ? Path.GetFileName(message.ExistingFile) : null, }; filename = await dialog.ShowAsync(MainWindow); } catch (Exception ex) { ExceptionUtils.HandleException(ex); } finally { message.Process(filename); } }
public bool Save(bool forceIfdirty) { if (IsSaved && !forceIfdirty) { return(true); } var file = FilePath; if (IsDirty) { var saveResult = SaveFileResult.DoNothing; var saveMsg = new SaveFileMessage( new WorkflowFileInfo(this), this, null, result => { saveResult = result; }); MessengerInstance.Send(saveMsg); if (!saveResult.PerformSave) { return(false); } file = saveResult.FileName; } SaveWorkflow(file); return(true); }
/* ----------------------------------------------------------------- */ /// /// SetDestination /// /// <summary> /// Sets the message result to the Destination and Format /// properties. /// </summary> /// /// <param name="src">Source facade.</param> /// <param name="e">Result message.</param> /// /* ----------------------------------------------------------------- */ public static void SetDestination(this Facade src, SaveFileMessage e) { Debug.Assert(e.FilterIndex > 0); Debug.Assert(e.FilterIndex <= ViewResources.Formats.Count); src.Settings.Value.Destination = e.Value; src.Settings.Value.Format = ViewResources.Formats[e.FilterIndex - 1].Value; }
/* ----------------------------------------------------------------- */ /// /// Send /// /// <summary> /// Sends the specified message, and invokes the specified action /// when not canceled by the user. /// </summary> /// /// <param name="message">Message to send.</param> /// <param name="next"> /// Action to be invoked when not canceled by the user. /// </param> /// /* ----------------------------------------------------------------- */ protected async Task Send(SaveFileMessage message, Action <string> next) { Send(message); if (message.Cancel) { return; } await Track(() => next(message.Value)); }
[TestCase(Format.Unknown, "*.zip")] /* Contains all formats */ public void GetDialogFilters(Format format, string piece) { var upper = piece.ToUpperInvariant(); var dest = new SaveFileMessage("dummy") { Filters = Resource.GetDialogFilters(format) }.GetFilterText(); Assert.That(dest.Contains("*.*")); Assert.That(dest.Contains(piece), piece); Assert.That(dest.Contains(upper), upper); }
public void Create_SaveFileMessage() { var src = new SaveFileMessage(); Assert.That(src.Text, Is.Empty); Assert.That(src.Value, Is.Empty); Assert.That(src.InitialDirectory, Is.Empty); Assert.That(src.Filter, Is.EqualTo("All Files (*.*)|*.*")); Assert.That(src.FilterIndex, Is.EqualTo(0)); Assert.That(src.CheckPathExists, Is.False); Assert.That(src.OverwritePrompt, Is.True); Assert.That(src.Cancel, Is.False); }
/* ----------------------------------------------------------------- */ /// /// CreateForDestination /// /// <summary> /// Creates a message to show an OpenFileDialog dialog for /// selecting the destination path. /// </summary> /// /// <param name="src">User settings.</param> /// /// <returns>SaveFileMessage object.</returns> /// /* ----------------------------------------------------------------- */ public static SaveFileMessage CreateForDestination(this SettingFolder src) { var path = src.Value.Destination; var dest = new SaveFileMessage { Text = Properties.Resources.TitleSelectDestination, Value = GetFileName(path, src.IO), OverwritePrompt = false, Filter = ViewResources.DestinationFilters.GetFilter(), FilterIndex = ViewResources.DestinationFilters.GetFilterIndex(path, src.IO), }; if (src.Value.ExplicitDirectory) { dest.InitialDirectory = GetDirectoryName(path, src.IO); } return(dest); }
private static void OnSaveFileMessage(SaveFileMessage saveFileMessage) { var saveDlg = new SaveFileDialog { Title = "Save - FlowStudio", FileName = saveFileMessage.WorkflowFileInfo.FilePath, CheckFileExists = false, AddExtension = true, Filter = "Activity|*.xaml|Workflow Service|*.xamlx", FilterIndex = saveFileMessage.WorkflowFileInfo.WorkflowType == WorkflowType.Activity ? 1 : 2 }; var r = saveDlg.ShowDialog(); saveFileMessage.Execute(r.GetValueOrDefault() ? new SaveFileResult(saveDlg.FileName) : SaveFileResult.DoNothing); }
public void SaveDialog(SaveFileMessage msg) { var dlg = new SaveFileDialog(); dlg.Filter = "Text Files (*.txt)|*.txt"; dlg.DefaultExt = "txt"; dlg.AddExtension = true; if (dlg.ShowDialog() == DialogResult.OK) { if (msg.OpenStream) { using (var stream = dlg.OpenFile()) { msg.OpenStreamAction(stream); } } else { msg.PassFileNameAction(dlg.FileName); } } }
public async void SaveDialog(SaveFileMessage msg) { var dlg = new SaveFileDialog(); dlg.DefaultExtension = "*.txt"; //dlg.Filter = "Text Files (*.txt)|*.txt"; var result = await dlg.ShowAsync(null); if (!string.IsNullOrWhiteSpace(result)) { if (msg.OpenStream) { using (var stream = new FileStream(result, FileMode.OpenOrCreate)) { msg.OpenStreamAction(stream); } } else { msg.PassFileNameAction(result); } } }
private static async Task ShowSaveFileDialogAsync(SaveFileMessage message) { string filename = null; try { var dialog = new SaveFileDialog() { Title = message.Title, Filters = GetFilters(message.FileType), DefaultExtension = GetDefaultExtension(message.FileType), }; filename = await dialog.ShowAsync(MainWindow); } catch (Exception ex) { ExceptionUtils.HandleException(ex); } finally { message.Process(filename); } }
/* ----------------------------------------------------------------- */ /// /// ExportCommand /// /// <summary> /// Export コマンドを実行します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ExportCommand(SaveFileMessage e, string dest, bool result) { e.FileName = dest; e.Result = result; e.Callback(e); }
private void DoGenerate() { var saveFileMessage = new SaveFileMessage(); saveFileMessage.DialogTitle = "Save the generated code"; CodeDomProvider codeProvider = null; if (CSharpCode) { saveFileMessage.DefaultExtension = "cs"; saveFileMessage.Filters = "CSharp source file (*.cs)| *.cs"; codeProvider = new CSharpCodeProvider(); } else { saveFileMessage.DefaultExtension = "vb"; saveFileMessage.Filters = "VB.Net source file (*.vb)| *.vb"; codeProvider = new VBCodeProvider(); } _addin.Manager.Messenger.Send(saveFileMessage); if (string.IsNullOrWhiteSpace(saveFileMessage.FilePath)) { return; } var fileStream = new FileStream(saveFileMessage.FilePath, FileMode.Create, FileAccess.Write); using (fileStream) using (var writer = new StreamWriter(fileStream)) { _codeGenerationEngine.GenerateCode(_modelDefinition, codeProvider, writer); writer.Flush(); fileStream.Flush(); fileStream.Close(); } UserSimpleTextMessage msg = new UserSimpleTextMessage(); msg.Title = "Code generation"; msg.Message = "Successfull"; _addin.Manager.Messenger.Send(msg); }
public bool SaveAs() { bool finalResult = false; var saveMsg = new SaveFileMessage( new WorkflowFileInfo(this), this, null, result => { if (result.PerformSave) { SaveWorkflow(result.FileName); finalResult = true; } else { finalResult = false; } }); MessengerInstance.Send(saveMsg); return finalResult; }
public bool Save(bool forceIfdirty) { if (IsSaved && !forceIfdirty) { return true; } var file = FilePath; if (IsDirty) { var saveResult = SaveFileResult.DoNothing; var saveMsg = new SaveFileMessage( new WorkflowFileInfo(this), this, null, result => { saveResult = result; }); MessengerInstance.Send(saveMsg); if (!saveResult.PerformSave) { return false; } file = saveResult.FileName; } SaveWorkflow(file); return true; }
/* ----------------------------------------------------------------- */ /// /// ExportCommand /// /// <summary> /// Export コマンドを実行します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ExportCommand(SaveFileMessage e, string dest, bool ok) { e.Value = dest; e.Cancel = !ok; }