Esempio n. 1
0
        public override void init()
        {
            BackColor   = Color.FromArgb(0x2e, 0x2e, 0x2e);
            allControls = new List <Control>();
            Text        = "Text Editor";
            setScreenSizePercentage(.75);
            editor = new Editor(backColor: BackColor)
            {
                Dock = DockStyle.Fill
            };
            int             colorBase = 0x88;
            HorizontalPanel topPanel  = new HorizontalPanel()
            {
                Dock      = DockStyle.Top,
                Height    = topHeight,
                BackColor = Color.FromArgb(colorBase, colorBase, colorBase)
            };

            topPanel.addControl(new TopButton(click: delegate {
                save(SysSettings.getSetting(openFileSetting, null));
            }, text: "Save"));
            topPanel.addControl(new TopButton(click: delegate { open(); }, text: "Open"));
            topPanel.addControl(new TopButton(click: delegate {
                SysSettings.deleteSetting(openFileSetting);
                editor.Text = string.Empty;
            }, text: "Close File"));
            this.addControl(topPanel);
            Panel editorContainer = new Panel()
            {
                Padding = new Padding(5),
                Dock    = DockStyle.Bottom
            };

            editor.scrollEvent += delegate {
            };
            Action <Control> addToList = null;

            addToList = (Control c) => {
                if (c == null)
                {
                    return;
                }
                allControls.Add(c);
                foreach (Control subC in c.Controls)
                {
                    addToList(subC);
                }
            };
            editorContainer.addControl(editor);
            this.addControl(editorContainer);
            addToList(this);
            async(() => {
                string openFile = SysSettings.getSetting(openFileSetting, null);
                if (openFile != null)
                {
                    editor.runOnUiThread(() => { open(openFile); });
                }
            });

            KeyEventHandler keyHandler = (object o, KeyEventArgs args) => {
                if (args.Control)
                {
                    switch (args.KeyCode)
                    {
                    case Keys.O:
                        open();
                        break;

                    case Keys.S:
                        save(SysSettings.getSetting(openFileSetting, null));
                        break;

                    case Keys.A:
                        editor.SelectAll();
                        break;
                    }
                }
            };

            KeyDown += keyHandler;
            foreach (Control c in allControls)
            {
                c.KeyDown += keyHandler;
            }
            resizeHandler = delegate {
                editorContainer.Height = ClientSize.Height - (topHeight + 10);
            };
        }