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); } }
protected static IResult <Unit> setConfiguration(PlaygroundConfiguration configuration, FileName configurationFile) => from serialized in Configuration.Serialize(configuration, "kagami") from unit in configurationFile.TryTo.SetText(serialized.ToString()) select unit;