示例#1
0
        public async Task InitializeAsync()
        {
            var text = new TitleTextPair(await Env.Cipher.DecryptFileAsync(File)).Text;

            TabPage.Text = Helper.StripTags(Title);
            TabPage.Tag  = this;
            var splitContainer = new SplitContainer
            {
                Dock             = DockStyle.Fill,
                Parent           = TabPage,
                SplitterWidth    = 1,
                SplitterDistance = Env.Config.SplitterDistance,
                TabStop          = false
            };

            _panel = new RichTextBoxPlus
            {
                Dock        = DockStyle.Fill,
                Parent      = splitContainer.Panel1,
                BorderStyle = BorderStyle.None,
                ReadOnly    = true,
                WordWrap    = false,
                TabStop     = false
            };

            _rtb = new RichTextBoxPlus
            {
                Dock        = DockStyle.Fill,
                Parent      = splitContainer.Panel2,
                AcceptsTab  = true,
                BorderStyle = BorderStyle.None,
                ReadOnly    = Env.FlagManager.HasFlag("ReadOnly") || Program.ReadOnly,
                Text        = text
            };

            UpdatePanel(true);
            if (_textEditorForm.TryGetPosition(Name, out var rtbPosition))
            {
                _rtb.LoadPosition(rtbPosition);
            }

            _changed = false;

            _rtb.TextChanged += (s, e) =>
            {
                _changed           = true;
                _shouldUpdatePanel = true;
            };

            _rtb.KeyDown += async(s, e) =>
            {
                if (e.Handled)
                {
                    return;
                }
                switch (e.KeyData)
                {
                case Keys.F6:
                    e.Handled = true;
                    OpenMode(MoveSelectedLines);
                    break;

                case Keys.F6 | Keys.Shift:
                    e.Handled = true;
                    OpenMode(MoveCaretToSection);
                    break;

                case Keys.Control | Keys.PageUp:
                    e.Handled = true;
                    MoveCaretToTopOfSection();
                    break;

                case Keys.Control | Keys.PageDown:
                    e.Handled = true;
                    MoveCaretToEndOfSection();
                    break;

                case Keys.Control | Keys.W:
                    e.Handled = true;
                    await SaveAsync();

                    Close();
                    break;

                case Keys.F2:
                    e.Handled = true;
                    await Rename();

                    break;

                case Keys.F5:
                    e.Handled = true;
                    Compile();
                    break;
                }
            };

            _panel.MouseClick += (s, e) =>
            {
                _rtb.Focus();
                MoveCaretToSection(_panel.GetCurrentLine());
            };

            Env.FlagManager.FlagsChanged += FlagsChanged;
        }