Ejemplo n.º 1
0
        public ConsoleDocument(Form form, DocumentConfiguration documentConfiguration, ConsoleConfiguration consoleConfiguration)
        {
            editTextBox    = documentConfiguration.TextBox;
            consoleTextBox = consoleConfiguration.TextBox;
            console        = consoleConfiguration.Console(form);
            document       = documentConfiguration.Document(form);

            writer = console.Writer();
            reader = console.Reader();

            document.StandardMenus();
        }
Ejemplo n.º 2
0
        void Playground_Load(object sender, EventArgs e)
        {
            results  = new AutoHash <int, string>(k => "");
            settings = getSettings();

            errorConsole = new TextBoxConsole(this, textErrors, settings.ErrorFont, settings.ErrorFontSize, Cathode);
            errorWriter  = errorConsole.Writer();
            try
            {
                try
                {
                    tabStops = array(32, 64, 96, 128);
                    textEditor.SelectionTabs = tabStops;
                }
                catch (Exception exception)
                {
                    displayException(exception);
                }

                outputConsole = new TextBoxConsole(this, textConsole, settings.ConsoleFont, settings.ConsoleFontSize, Quick);
                consoleWriter = outputConsole.Writer();
                textReader    = outputConsole.Reader();

                document = new Document(this, textEditor, ".orange", "Orange", settings.EditorFont, settings.EditorFontSize);
                document.StandardMenus();
                menus = document.Menus;
                menus.Menu(MENU_FILE, "Set Current Folder", (s, evt) => setCurrentFolder());

                menus.Menu(MENU_EDIT, "Duplicate", (s, evt) => duplicate(), "^D");
                menus.Menu(MENU_EDIT, "Indent", (s, evt) => indent(), "^I");
                menus.Menu(MENU_EDIT, "Unindent", (s, evt) => unindent(), "^%I");

                menus.Menu($"&{MENU_BUILD}");
                menus.Menu(MENU_BUILD, "Run", (s, evt) => run(), "F5");
                menus.Menu(MENU_BUILD, "Manual", (s, evt) =>
                {
                    manual = !manual;
                    ((ToolStripMenuItem)s).Checked = manual;
                }, "^F5");

                menus.Menu($"&{MENU_TEXT}");
                menus.Menu(MENU_TEXT, "Clipboard -> Text", (s, evt) =>
                {
                    var text = ClipboardText();
                    if (text.IsSome)
                    {
                        var windowsText = GetWindowsText(text.Value);
                        if (textText.SelectionLength == 0)
                        {
                            textText.Text = windowsText;
                        }
                        else
                        {
                            textText.SelectedText = windowsText;
                        }
                        tabs.SelectedTab = tabText;
                    }
                }, "^|V");
                menus.Menu(MENU_TEXT, "Clipboard -> Append to Text", (s, evt) =>
                {
                    var text = ClipboardText();
                    if (text.IsSome)
                    {
                        var windowsText = GetWindowsText(text.Value);
                        textText.AppendText(windowsText);
                        tabs.SelectedTab = tabText;
                    }
                });
                menus.Menu(MENU_TEXT, "Clipboard -> Text & Run", (s, evt) =>
                {
                    var text = ClipboardText();
                    if (text.IsSome)
                    {
                        textText.Text = GetWindowsText(text.Value);
                    }
                    DoEvents();
                    run();
                    var selectedText = textConsole.SelectionLength == 0 ? textConsole.Text : textConsole.SelectedText;
                    selectedText     = GetWindowsText(selectedText);
                    SetText(selectedText);
                }, "F6");
                menus.Menu(MENU_TEXT, "Text -> Clipboard", (s, evt) =>
                {
                    var text = textConsole.SelectionLength == 0 ? textConsole.Text : textConsole.SelectedText;
                    text     = GetWindowsText(text);
                    SetText(text);
                }, "^|C");
                menus.Menu(MENU_TEXT, "Save text to file", (s, evt) =>
                {
                    var text = textConsole.SelectionLength == 0 ? textConsole.Text : textConsole.SelectedText;
                    text     = GetWindowsText(text);
                    if (dialogSave.ShowDialog() == DialogResult.OK)
                    {
                        FileName file = dialogSave.FileName;
                        try
                        {
                            file.Text = text;
                        }
                        catch (Exception exception)
                        {
                            displayException(exception);
                        }
                    }
                });

                menus.Menu($"&{MENU_INSERT}");
                menus.Menu(MENU_INSERT, "println", (s, evt) => insertText("println ", 0, 0), "^P");
                menus.Menu(MENU_INSERT, "println interpolated", (s, evt) => insertText("println $\"\"", -1, 0), "^%P");
                menus.Menu(MENU_INSERT, "print", (s, evt) => insertText("print ", 0, 0));
                menus.Menu(MENU_INSERT, "manifln", (s, evt) => insertText("manifln ", 0, 0), "^M");
                menus.Menu(MENU_INSERT, "manif", (s, evt) => insertText("manif", 0, 0));
                menus.Menu(MENU_INSERT, "put", (s, evt) => insertText("put ", 0, 0));
                menus.Menu(MENU_INSERT, "peek", (s, evt) => surround("peek(", ")"), "^K");
                menus.MenuSeparator(MENU_INSERT);
                menus.Menu(MENU_INSERT, "if template", (s, evt) => insertTemplate("if true", "true"), "^|I");
                menus.Menu(MENU_INSERT, "while template", (s, evt) => insertTemplate("while true", "true"), "^|W");
                menus.Menu(MENU_INSERT, "for template", (s, evt) => insertTemplate("for i in ^0", "^0"), "^|F");
                menus.Menu(MENU_INSERT, "func template", (s, evt) => insertTemplate("func proc()", "proc"), "^|P");
                menus.Menu(MENU_INSERT, "func template", (s, evt) => insertTemplate("func proc()", "proc"), "^|P");

                menus.CreateMainMenu(this);

                menus.StandardContextEdit(document);

                textEditor.ReassignHandle();

                locked    = false;
                manual    = false;
                stopwatch = new Stopwatch();
                fileCache = new InteractiveFileCache();

                textEditor.Paint += (s, evt) => paintResults(evt);

                setManual(settings.Manual);
                if (settings.DefaultFolder != null)
                {
                    FolderName.Current = settings.DefaultFolder;
                }
                textText.Text = settings.Text.FromBase64(Encoding.UTF8) ?? "";
                if (PassedFileName.IsSome)
                {
                    document.Open(PassedFileName.Value);
                }
                else if (settings.LastFile != null && ((FileName)settings.LastFile).Exists())
                {
                    document.Open(settings.LastFile);
                }
            }
            catch (Exception exception)
            {
                displayException(exception);
            }
        }
Ejemplo n.º 3
0
        protected void Playground_Load(object sender, EventArgs e)
        {
            try
            {
                var result =
                    from file in existingConfigurationFile()
                    from config in getConfiguration(file)
                    select config;
                if (result.If(out playgroundConfiguration))
                {
                }
                else
                {
                    playgroundConfiguration = new PlaygroundConfiguration
                    {
                        DefaultFolder = FolderName.Current,
                        FontName      = PLAYGROUND_FONT_NAME,
                        FontSize      = PLAYGROUND_FONT_SIZE,
                        PackageFolder = "C" + PLAYGROUND_PACKAGE_FOLDER
                    };
                }
            }
            catch (Exception exception)
            {
                labelStatus.Text = exception.Message;
            }

            packageFolder = playgroundConfiguration.PackageFolder;

            outputConsole = new TextBoxConsole(this, textConsole, playgroundConfiguration.FontName, playgroundConfiguration.FontSize,
                                               TextBoxConsole.ConsoleColorType.Quick);
            textWriter = outputConsole.Writer();
            textReader = outputConsole.Reader();
            context    = new PlaygroundContext(textWriter, textReader);
            colorizer  = new Colorizer(textEditor);

            try
            {
                _exceptionData = none <ExceptionData>();
                document       = new Document(this, textEditor, ".kagami", "Kagami", playgroundConfiguration.FontName, playgroundConfiguration.FontSize);
                var menus = document.Menus;
                menus.Menu("&File");
                menus.Menu("File", "&New", (_, _) =>
                {
                    textEditor.ClearModificationGlyphs();
                    document.New();
                });
                menus.Menu("File", "&Open", (_, _) =>
                {
                    textEditor.ClearModificationGlyphs();
                    document.Open();
                }, "^O");
                menus.Menu("File", "&Save", (_, _) =>
                {
                    textEditor.SetToSavedGlyphs();
                    document.Save();
                }, "^S");
                menus.Menu("File", "Save As", (_, _) =>
                {
                    textEditor.SetToSavedGlyphs();
                    document.SaveAs();
                });
                menus.Menu("File", "Exit", (_, _) => Close(), "%F4");

                document.StandardEditMenu();

                menus.Menu("Edit", "Duplicate", (_, _) => duplicate(), "^D");
                menus.Menu("Edit", "Indent", (_, _) => indent(), "^I");
                menus.Menu("Edit", "Unindent", (_, _) => unindent(), "^%I");
                menus.Menu("&Build");
                menus.Menu("Build", "Run", (_, _) => run(), "F5");
                menus.Menu("Build", "Manual", (s, _) =>
                {
                    manual = !manual;
                    ((ToolStripMenuItem)s).Checked = manual;
                }, "^F5");
                menus.Menu("Build", "Dump operations", (s, _) =>
                {
                    dumpOperations = !dumpOperations;
                    ((ToolStripMenuItem)s).Checked = dumpOperations;
                });
                menus.Menu("Build", "Trace", (s, _) =>
                {
                    tracing = !tracing;
                    ((ToolStripMenuItem)s).Checked = tracing;
                }, "^T");
                menus.Menu("&Insert");
                menus.Menu("Insert", "open sys", (_, _) => insertText("open sys\n\n", 0, 0), "^%S");
                menus.Menu("Insert", "open math", (_, _) => insertText("open math\n\n", 0, 0), "^%M");
                menus.Menu("Insert", "println()", (_, _) => insertText("println()", -1, 0), "^P");
                menus.Menu("Insert", "println() interpolated", (_, _) => insertText("println($\"\")", -2, 0), "^%P");
                menus.Menu("Insert", "print()", (_, _) => insertText("print()", -1, 0));
                menus.Menu("Insert", "put()", (_, _) => insertText("put()", -1, 0));
                menus.Menu("Insert", "peek()", (_, _) => surround("peek(", ")"), "^K");
                menus.Menu("Insert", "Triple quotes", (_, _) => insertText("\"\"\"\n\"\"\"", -3), "^Q");
                menus.Menu("Insert", "List", (_, _) => insertText("⌈⌉", -1), "^L");
                menus.Menu("Insert", "Set", (_, _) => insertText("⎩⎭", -1), "^E");

                menus.Menu("&Debug");
                menus.Menu("Debug", "Step Into", (_, _) => stepInto(), "F11");
                menus.Menu("Debug", "Step Over", (_, _) => stepOver(), "F10");

                menus.CreateMainMenu(this);
                menus.StandardContextEdit(document);

                textEditor.SetTabs(32, 64, 96, 128);
                textEditor.SetLeftMargin(70);
                textEditor.ReassignHandle();
                textEditor.Paint         += (_, evt) => paint(evt);
                textEditor.AnnotationFont = new Font(textEditor.Font, FontStyle.Bold);

                locked          = false;
                manual          = false;
                dumpOperations  = false;
                tracing         = false;
                stopwatch       = new Stopwatch();
                _exceptionIndex = none <int>();
                cancelled       = false;
                if (playgroundConfiguration.LastFile != null)
                {
                    document.Open(playgroundConfiguration.LastFile);
                }
            }
            catch (Exception exception)
            {
                textWriter.WriteLine(exception.Message);
            }
        }
Ejemplo n.º 4
0
        protected void Playground_Load(object sender, EventArgs e)
        {
            results  = new AutoHash <int, string>(_ => "");
            settings = getSettings();

            errorConsole = new TextBoxConsole(this, textErrors, settings.ErrorFont, settings.ErrorFontSize, TextBoxConsole.ConsoleColorType.Cathode);
            errorWriter  = errorConsole.Writer();
            try
            {
                try
                {
                    tabStops = array(32, 64, 96, 128);
                    textEditor.SelectionTabs = tabStops;
                }
                catch (Exception exception)
                {
                    displayException(exception);
                }

                outputConsole = new TextBoxConsole(this, textConsole, settings.ConsoleFont, settings.ConsoleFontSize,
                                                   TextBoxConsole.ConsoleColorType.Quick);
                consoleWriter = outputConsole.Writer();
                textReader    = outputConsole.Reader();

                document = new Document(this, textEditor, ".orange", "Orange", settings.EditorFont, settings.EditorFontSize);
                document.StandardMenus();
                menus = document.Menus;
                menus.Menu(MENU_FILE, "Set Current Folder", (_, _) => setCurrentFolder());

                menus.Menu(MENU_EDIT, "Duplicate", (_, _) => duplicate(), "^D");
                menus.Menu(MENU_EDIT, "Indent", (_, _) => indent(), "^I");
                menus.Menu(MENU_EDIT, "Unindent", (_, _) => unindent(), "^%I");

                menus.Menu($"&{MENU_BUILD}");
                menus.Menu(MENU_BUILD, "Run", (_, _) => run(), "F5");
                menus.Menu(MENU_BUILD, "Manual", (s, _) =>
                {
                    manual = !manual;
                    ((ToolStripMenuItem)s).Checked = manual;
                }, "^F5");

                menus.Menu($"&{MENU_TEXT}");
                menus.Menu(MENU_TEXT, "Clipboard -> Text", (_, _) =>
                {
                    if (ClipboardText().If(out var clipboardText))
                    {
                        var windowsText = GetWindowsText(clipboardText);
                        if (textText.SelectionLength == 0)
                        {
                            textText.Text = windowsText;
                        }
                        else
                        {
                            textText.SelectedText = windowsText;
                        }

                        tabs.SelectedTab = tabText;
                    }
                }, "^|V");
                menus.Menu(MENU_TEXT, "Clipboard -> Append to Text", (_, _) =>
                {
                    if (ClipboardText().If(out var clipboardText))
                    {
                        var windowsText = GetWindowsText(clipboardText);
                        textText.AppendText(windowsText);
                        tabs.SelectedTab = tabText;
                    }
                });
Ejemplo n.º 5
0
 public TextBoxInterface(Form form, ExRichTextBox textBox)
 {
     console = new TextBoxConsole(form, textBox);
     writer  = console.Writer();
     reader  = console.Reader();
 }