Ejemplo n.º 1
0
        void PreviewFile(string path, int linenum)
        {
            var text = File.ReadAllText(path);
            var fp   = Previewer();

            SciUtil.SetAllText(fp.scintilla, text);
            fp.Text = path;

            var pos = fp.scintilla.Lines[linenum - 1].Position;

            fp.scintilla.GotoPosition(pos);
            SciUtil.RevealLine(fp.scintilla, linenum - 1);

            int found = SciUtil.SearchAndMove(fp.scintilla, Ui.searchTextBox.Text);

            // simple find didn't find it - so let's highlight the whole line
            if (found == -1)
            {
                fp.scintilla.SelectionStart = pos;
                fp.scintilla.SelectionEnd   = fp.scintilla.Lines[linenum].Position;
            }

            fp.Show();
            FormsUtil.BringFormToFront(fp, Ui.form);
        }
Ejemplo n.º 2
0
        public MainFormBehind(MainFormUi ui)
        {
            void SetupScintilla()
            {
                var scintilla = SciUtil.CreateScintilla();

                scintilla.UpdateUI += (o, e) =>
                {
                    if (e.Change == UpdateChange.Selection)
                    {
                        UpdateStatusBar();
                    }
                };
                //sci.ReadOnly = true;
                ui.resultBox = scintilla;
                ui.form.Controls.Add(ui.resultBox);
                ui.resultBox.Dock = DockStyle.Fill;
                ui.searchTextBox.Select();
                ui.tableLayout.Controls.Add(ui.resultBox, 0, 1);
            }

            this.Ui = ui;
            SetupScintilla();
            ui.searchTextBox.KeyDown += (o, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    SearchStartEvent(ui, e);
                }
            };
            ui.dirSelector.KeyDown += (o, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    SearchStartEvent(ui, e);
                }
            };

            ui.resultBox.KeyDown += (o, e) =>
            {
                HandleKeyDownOnResults(e, ui.resultBox.CurrentLine);
            };
            ui.resultBox.KeyPress += (o, e) =>
            {
                // prevent PLING sound
                e.Handled = true;
            };
            SciUtil.SetAllText(ui.resultBox, Logic.Tutorial);

            ui.dirSelector.DataSource   = Logic.DirHistory;
            ui.searchTextBox.DataSource = Logic.SearchHistory;
            ui.rgArgsComboBox.Items.AddRange(new[]
            {
                Logic.RgExtraArgs,
                "--files",
                "-m 5 --smart-case",
                "-M 1000",
                "-g *.cs -g *.csproj",
                "--no-ignore",
                "--context 2"
            });
            ui.rgArgsComboBox.TextChanged += (o, e) =>
            {
                Logic.RgExtraArgs = ui.rgArgsComboBox.Text;
                UpdateStatusBar();
            };

            ui.dirSelector.Text = Logic.WorkDir;
            ui.btnAbort.Click  += (o, e) =>
            {
                ui.btnAbort.Visible = false;
                Logic.KillSearch();
            };
            LiveSearchEvents(ui);

            if (Logic.InitialSearchString != null)
            {
                ui.searchTextBox.Text     = Logic.InitialSearchString;
                Logic.InitialSearchString = null;
                Logic.StartSearch(ui);
            }
            UpdateStatusBar();
        }