コード例 #1
0
ファイル: Editor.cs プロジェクト: dirkbretthauer/gui.cs
        private View FindTab()
        {
            var d = new View()
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            d.DrawContent += (e) => {
                foreach (var v in d.Subviews)
                {
                    v.SetNeedsDisplay();
                }
            };

            var lblWidth = "Replace:".Length;

            var label = new Label(0, 1, "Find:")
            {
                Width         = lblWidth,
                TextAlignment = TextAlignment.Right,
                LayoutStyle   = LayoutStyle.Computed
            };

            d.Add(label);

            SetFindText();
            var txtToFind = new TextField(_textToFind)
            {
                X     = Pos.Right(label) + 1,
                Y     = Pos.Top(label),
                Width = 20
            };

            txtToFind.Enter += (_) => txtToFind.Text = _textToFind;
            d.Add(txtToFind);

            var btnFindNext = new Button("Find _Next")
            {
                X             = Pos.Right(txtToFind) + 1,
                Y             = Pos.Top(label),
                Width         = 20,
                Enabled       = !txtToFind.Text.IsEmpty,
                TextAlignment = TextAlignment.Centered,
                IsDefault     = true
            };

            btnFindNext.Clicked += () => FindNext();
            d.Add(btnFindNext);

            var btnFindPrevious = new Button("Find _Previous")
            {
                X             = Pos.Right(txtToFind) + 1,
                Y             = Pos.Top(btnFindNext) + 1,
                Width         = 20,
                Enabled       = !txtToFind.Text.IsEmpty,
                TextAlignment = TextAlignment.Centered
            };

            btnFindPrevious.Clicked += () => FindPrevious();
            d.Add(btnFindPrevious);

            txtToFind.TextChanged += (e) => {
                _textToFind = txtToFind.Text.ToString();
                _textView.FindTextChanged();
                btnFindNext.Enabled     = !txtToFind.Text.IsEmpty;
                btnFindPrevious.Enabled = !txtToFind.Text.IsEmpty;
            };

            var btnCancel = new Button("Cancel")
            {
                X             = Pos.Right(txtToFind) + 1,
                Y             = Pos.Top(btnFindPrevious) + 2,
                Width         = 20,
                TextAlignment = TextAlignment.Centered
            };

            btnCancel.Clicked += () => {
                DisposeWinDialog();
            };
            d.Add(btnCancel);

            var ckbMatchCase = new CheckBox("Match c_ase")
            {
                X       = 0,
                Y       = Pos.Top(txtToFind) + 2,
                Checked = _matchCase
            };

            ckbMatchCase.Toggled += (e) => _matchCase = ckbMatchCase.Checked;
            d.Add(ckbMatchCase);

            var ckbMatchWholeWord = new CheckBox("Match _whole word")
            {
                X       = 0,
                Y       = Pos.Top(ckbMatchCase) + 1,
                Checked = _matchWholeWord
            };

            ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = ckbMatchWholeWord.Checked;
            d.Add(ckbMatchWholeWord);

            d.Width  = label.Width + txtToFind.Width + btnFindNext.Width + 2;
            d.Height = btnFindNext.Height + btnFindPrevious.Height + btnCancel.Height + 4;

            return(d);
        }