private bool InternalShowOpenFileDialog(OpenFileOptions options) { var dlg = new Microsoft.Win32.OpenFileDialog { Filter = GetFilterString(options), FilterIndex = options.FilterIndex, Multiselect = options.Multiselect }; if (options.Title != null) { dlg.Title = options.Title; } if (options.InitialDirectory != null && System.IO.Directory.Exists(options.InitialDirectory)) { dlg.InitialDirectory = options.InitialDirectory; } dlg.RestoreDirectory = options.RestoreDirectory; if (true == dlg.ShowDialog(TopmostModalWindow)) { options.FileName = dlg.FileName; options.FileNames = dlg.FileNames; return(true); } else { return(false); } }
public override bool ShowOpenFileDialog(OpenFileOptions options) { var dlg = new OpenFileDialog(); dlg.Filter = GetFilterString(options); dlg.FilterIndex = options.FilterIndex; dlg.Multiselect = options.Multiselect; if (options.Title != null) { dlg.Title = options.Title; } if (options.InitialDirectory != null) { dlg.InitialDirectory = options.InitialDirectory; } dlg.RestoreDirectory = options.RestoreDirectory; DialogResult r = dlg.ShowDialog(MainWindow); if (r == DialogResult.OK) { options.FileName = dlg.FileName; options.FileNames = dlg.FileNames; } return(r == DialogResult.OK); }
public override void Execute(object parameter) { Altaxo.Scripting.IScriptText script = null; // or load it from somewhere if (script == null) { script = new Altaxo.Scripting.ProgramInstanceScript(); } var options = new Altaxo.Gui.OpenFileOptions { Title = "Open a script or press Cancel to create a new script" }; options.AddFilter("*.cs", "C# files (*.cs)"); options.AddFilter("*.*", "All files (*.*)"); options.FilterIndex = 0; if (Current.Gui.ShowOpenFileDialog(options)) { string err = OpenScriptText(options.FileName, out var scripttext); if (null != err) { Current.Gui.ErrorMessageBox(err); } else { script.ScriptText = scripttext; } } object[] args = new object[] { script, new Altaxo.Gui.Scripting.ScriptExecutionHandler(EhScriptExecution) }; if (Current.Gui.ShowDialog(args, "New instance script")) { string errors = null; do { errors = null; // store the script somewhere m_Table.TableScript = (TableScript)args[0]; var saveOptions = new Altaxo.Gui.SaveFileOptions { Title = "Save your script" }; saveOptions.AddFilter("*.cs", "C# files (*.cs)"); saveOptions.AddFilter("*.*", "All files (*.*)"); saveOptions.FilterIndex = 0; if (Current.Gui.ShowSaveFileDialog(saveOptions)) { errors = SaveScriptText(saveOptions.FileName, script.ScriptText); if (null != errors) { Current.Gui.ErrorMessageBox(errors); } } } while (null != errors); } }
private string GetFilterString(OpenFileOptions options) { var stb = new StringBuilder(); foreach (var entry in options.FilterList) { stb.Append(entry.Value); stb.Append('|'); stb.Append(entry.Key); stb.Append('|'); } if (stb.Length > 0) { stb.Length -= 1; // account for the trailing | char } return(stb.ToString()); }
public override bool ShowOpenFileDialog(OpenFileOptions options) { return(Current.Dispatcher.InvokeIfRequired(InternalShowOpenFileDialog, options)); }