Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 public bool EhScriptExecution(Altaxo.Scripting.IScriptText script, IProgressReporter reporter)
 {
     return(((Altaxo.Scripting.ProgramInstanceScript)script).Execute(reporter));
 }