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); }
private void LiveSearchEvents(MainFormUi ui) { var ctrl = ui.searchControl; var rb = ui.resultBox; ctrl.searchTextBox.TextChanged += (o, e) => SciUtil.SearchAndMove(rb, ctrl.searchTextBox.Text); ctrl.btnNext.Click += (o, e) => SciUtil.SearchAndMove(rb, ctrl.searchTextBox.Text); ctrl.btnPrev.Click += (o, e) => SciUtil.SearchAndMove(rb, ctrl.searchTextBox.Text, reverse: true); ctrl.searchTextBox.KeyDown += (o, e) => { if (e.KeyCode == Keys.Enter) { if (e.Shift) { SciUtil.SearchAndMove(rb, ctrl.searchTextBox.Text, reverse: true); } else { SciUtil.SearchAndMove(rb, ctrl.searchTextBox.Text); } e.SuppressKeyPress = true; e.Handled = true; } }; }
public FullPreviewForm() { InitializeComponent(); scintilla = SciUtil.CreateScintilla(); Controls.Add(scintilla); scintilla.Dock = DockStyle.Fill; FormClosing += (o, e) => { if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; Hide(); } }; }
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(); }