예제 #1
0
        public static void downloadO2Scripts(Action <string> statusMessage)
        {
            statusMessage("Downloading zip with latest rules");
            var url     = "https://github.com/o2platform/O2.Platform.Scripts/zipball/master";
            var zipFile = url.download();

            statusMessage("Unziping files into temp folder");
            var targetFolder = @"_Downloaded_O2Scripts".tempDir(false).fullPath();

            if (targetFolder.size() > 120)
            {
                "[downloadO2Scripts] targetFolder path was more than 120 chars: {0}".error(targetFolder);
                targetFolder = System.IO.Path.GetTempPath().pathCombine(targetFolder.fileName());
                "[downloadO2Scripts] set targetFolder to: {0}".info(targetFolder);
            }
            zipFile.unzip_File(targetFolder);

            statusMessage("Copying files into scripts folder");
            var baseDir       = targetFolder.folders().first();
            var scriptsFolder = PublicDI.config.LocalScriptsFolder;
            var filesCopied   = 0;

            foreach (var file in baseDir.files(true))
            {
                var targetFile = file.replace(baseDir, scriptsFolder);
                targetFile.parentFolder().createDir();
                file.file_Copy(targetFile);
                filesCopied++;
            }
            "copied: {0}".info(filesCopied);
            CompileEngine.clearLocalScriptFileMappings();
            statusMessage("Done");
        }
        public static ComboBox executeScriptOnSelection(this ComboBox comboBox, Items mappings)
        {
            comboBox.onSelection <string>(
                (key) => {
                if (mappings.hasKey(key))
                {
                    comboBox.parent().focus();           // do this in order to prevent a nasty user experience that happens if the user uses the up and down arrows to navigate the comboBox
                    "executing script mapped to '{0}: {1}".info(key, mappings[key]);
                    var itemToExecute = mappings[key];
                    if (itemToExecute.isUri())
                    {
                        Processes.startProcess(itemToExecute);
                    }
                    //itemToExecute.startProcess();
                    else
                    {
                        if (itemToExecute.fileExists().isFalse() && itemToExecute.local().fileExists().isFalse())
                        {
                            CompileEngine.clearLocalScriptFileMappings();
                        }
                        "itemToExecute: {0}".debug(itemToExecute);
                        //"itemToExecuteextension: {0}".debug(itemToExecute.extension(".o2"));
                        if (itemToExecute.extension(".h2") || itemToExecute.extension(".o2"))
                        {
                            if (Control.ModifierKeys == Keys.Shift)
                            {
                                "Shift Key pressed, so launching in new process: {0}".info(itemToExecute);
                                itemToExecute.executeH2_or_O2_in_new_Process();
                                return;
                            }
                        }

/*												else
 *                                                                                              {
 *                                                                                                      "Shift Key was pressed, so running script in current process".debug(itemToExecute);
 *                                                                                                      O2Thread.mtaThread(()=>itemToExecute.executeFirstMethod());
 *                                                                                              }
 *                                                                                      else*/

                        O2Thread.mtaThread(() => itemToExecute.executeFirstMethod());
                    }
                }
            });
            return(comboBox);
        }
예제 #3
0
 private void clearLocalFileMappingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CompileEngine.clearLocalScriptFileMappings();
 }
        public void configureGui()
        {
            result_Panel.visible(false);
            executeButton.enabled(false);

            commandsToExecute.textEditor().showInvalidLines(false);

            swapGeneratedCodeViewMode();                // make it not visible by default

            executeButton.onClick(execute);
            commandsToExecute.onTextChanged(onTextChanged);

            commandsToExecute.editor().vScroolBar_Enabled(false);
            commandsToExecute.editor().hScroolBar_Enabled(false);
            commandsToExecute.set_ColorsForCSharp();

            commandsToExecute.allowCompile(false);
            sourceCodeViewer.allowCompile(false);

            sourceCodeViewer.astDetails(false);
            commandsToExecute.astDetails(false);

            //remove original ContextMenu and add new one
            sourceCodeViewer.textEditorControl().remove_ContextMenu();
            var contextMenu = commandsToExecute.textEditorControl().add_ContextMenu();

            commandsToExecute.textArea().KeyUp           += (sender, e) => handlePressedKeys(e);
            commandsToExecute.textArea().KeyEventHandler += handleKeyEventHandler;

            contextMenu.add_MenuItem("current source code")
            .add_MenuItem("compile", (menuitem) => compile())
            .add_MenuItem("copy to clipboard", (menuitem) => currentCode().toClipboard())
            .add_MenuItem("save", (menuitem) => saveScript())
            .add_MenuItem("save As", (menuitem) => saveAsScript())
            .add_MenuItem("what is the current loaded filename", (menuitem) => "The path of the currently loaded file is: {0}".info(currentSourceCodeFilePath()))
            .add_MenuItem("force compilation", (menuitem) => forceCompilation())
            .add_MenuItem("replace with generated source code", (menuitem) => replaceMainCodeWithGeneratedSource())
            .add_MenuItem("show/hide generated source code", (menuitem) => swapGeneratedCodeViewMode())
            .add_MenuItem("-------------------------------")
            .add_MenuItem("clear AssembliesCheckedIfExists list", (menuitem) => O2GitHub.clear_AssembliesCheckedIfExists())
            .add_MenuItem("clear CachedCompiledAssemblies list", (menuitem) => CompileEngine.clearCompilationCache())
            .add_MenuItem("clear LocalScriptFileMappings list", (menuitem) => CompileEngine.clearLocalScriptFileMappings())
            .add_MenuItem("clear CompilationPathMappings list", (menuitem) => CompileEngine.clearCompilationPathMappings());

            contextMenu.add_MenuItem("selected text")
            .add_MenuItem("cut", () => commandsToExecute.editor().clipboard_Cut())
            .add_MenuItem("copy", () => commandsToExecute.editor().clipboard_Copy())
            .add_MenuItem("paste", () => commandsToExecute.editor().clipboard_Paste())
            .add_MenuItem("(if a local file) open selected text in code Editor", () => openSelectedTextInCodeEditor());
            contextMenu.add_MenuItem("execution options")
            .add_MenuItem("execute", (menuitem) => execute())
            .add_MenuItem("enable /disable Execute on compile", (menuitem) => ExecuteOnCompile = !ExecuteOnCompile)
            .add_MenuItem("enable /disable Execute on enter", (menuitem) => ExecuteOnEnter     = !ExecuteOnEnter)
            .add_MenuItem("disable / enabled Auto compile on code change", (menuitem) => AutoCompileOnCodeChange = !AutoCompileOnCodeChange);
            contextMenu.add_MenuItem("auto saved scripts")
            .add_MenuItem("show auto saved scripts", (menuitem) => showAutoSavedScripts())
            .add_MenuItem("enable / disable Auto Save on compile success", (menuitem) => AutoSaveOnCompileSuccess = !AutoSaveOnCompileSuccess);
            contextMenu.add_MenuItem("code complete")
            .add_MenuItem("enable Code Complete", (menuitem) => commandsToExecute.enableCodeComplete())
            .add_MenuItem("enable /disabled 'Only Show Code Complete Results From O2 Namespace'", (menuitem) => enableDisableFullCodeComplete());
            contextMenu.add_MenuItem("code snippets (helper)")
            .add_MenuItem("when compiling: Dont use Cached Assembly if available", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("when compiling: remove all auto references to O2 scripts and dlls (same as next two options)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            //.add_MenuItem("when compiling: don't include extra cs file (with extension methods)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("when compiling, only add referenced assemblies", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("when compiling, set InvocationParameters to dynamic", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("generate debug symbols (and create temp assembly)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("add using statement", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("add additional source code (when compile)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("add external reference (dll or exe or GAC assembly)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("run in STA thread (when invoke)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("run in MTA thread (when invoke)", (menuitem) => insertCodeSnipptet(menuitem.Text))
            .add_MenuItem("clear 'AssembliesCheckedIfExists' cache", (menuitem) => insertCodeSnipptet(menuitem.Text));
            contextMenu.add_MenuItem("This Script Editor")
            .add_MenuItem("REPL script this Script", scriptTheCurrentScript)
            .add_MenuItem("REPL script this Script's codeComplete object", scriptTheCurrentScript_CodeComplete);
            contextMenu.add_MenuItem("O2 Scripts")
            //.add_MenuItem("Download/Update O2 Scripts (via http)", O2Scripts.downloadO2Scripts)
            .add_MenuItem("O2 Script: find WinForms Control and REPL it ", () => "Util - Find WinForms Control and REPL it.h2".local().executeH2Script())
            .add_MenuItem("O2 Script: new C# Script Editor", () => open.scriptEditor())
            .add_MenuItem("O2 Script: Find Script to execute", () => "Util - O2 Available scripts.h2".local().executeH2Script())
            .add_MenuItem("O2 Script: open Main O2 GUI", () => "Main O2 Gui.h2".local().executeH2Script())
            .add_MenuItem("O2 Script: open ConsoleOut", () => "Util - ConsoleOut.h2".local().executeH2Script());

            contextMenu.add_MenuItem("package current Script as StandAlone Exe", () => packageCurrentScriptAsStandAloneExe());
            contextMenu.add_MenuItem("show O2 Object Model", () => open.o2ObjectModel());
            contextMenu.add_MenuItem("report a bug to O2 developers", () => ReportBug.showGui(commandsToExecute));
            contextMenu.add_MenuItem("show Log Viewer", (menuitem) => showLogViewer());
        }