Skip to content

Commit

Permalink
feat: use ScintillaNET-FindReplaceDialog for find/replace
Browse files Browse the repository at this point in the history
  • Loading branch information
PocketMiner82 committed Apr 9, 2024
1 parent b9ec14c commit efac5dc
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 867 deletions.
33 changes: 29 additions & 4 deletions pseudocodeIde/PseudocodeIDEForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 19 additions & 67 deletions pseudocodeIde/PseudocodeIDEForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using pseudocodeIde.findReplace;
using pseudocode_ide;
using Newtonsoft.Json;
using System.Diagnostics;
Expand All @@ -14,6 +13,7 @@
using ScintillaNET;
using pseudocode_ide.interpreter.scanner;
using System.Drawing;
using ScintillaNET_FindReplaceDialog;

namespace pseudocodeIde
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public string code
/// </summary>
private bool isSaved = true;

private FindReplaceForm findReplaceForm;
private FindReplace findReplace;

private OutputForm outputForm;

Expand All @@ -81,10 +81,11 @@ public string code

public PseudocodeIDEForm()
{
this.findReplaceForm = new FindReplaceForm(this);
InitializeComponent();
this.outputForm = new OutputForm(this);
this.findReplace = new FindReplace(this.codeTextBox);
this.findReplace.KeyPressed += codeTextBox_KeyDown;

InitializeComponent();
this.resetUndoRedo();

// disable right click menu
Expand Down Expand Up @@ -163,12 +164,6 @@ private void singleEqualIsCompareOperatorMenuItem_Click(object sender, EventArgs
private void PseudocodeIDE_FormClosing(object sender, FormClosingEventArgs e)
{
// main form won't close if child form is not disposed
if (!this.findReplaceForm.IsDisposed)
{
this.findReplaceForm.Close();
this.Close();
return;
}
if (!this.outputForm.IsDisposed)
{
this.outputForm.Close();
Expand Down Expand Up @@ -250,6 +245,16 @@ private void codeTextBox_KeyDown(object sender, KeyEventArgs e)
e.SuppressKeyPress = false;
return;
}
else if (e.Shift && e.KeyCode == Keys.F3)
{
this.findReplace.Window.FindPrevious();
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.F3)
{
this.findReplace.Window.FindNext();
e.SuppressKeyPress = true;
}
}

private void codeTextBox_KeyPress(object sender, KeyPressEventArgs e)
Expand Down Expand Up @@ -721,70 +726,17 @@ private void redoToolStripMenuItem_Click(object sender, EventArgs e)

private void findMenuItem_Click(object sender, EventArgs e)
{
this.findReplaceForm.Show(FindReplaceTabs.FIND, codeTextBox.SelectedText);
this.findReplace.ShowFind();
}

private void replaceMenuItem_Click(object sender, EventArgs e)
{
this.findReplaceForm.Show(FindReplaceTabs.REPLACE, codeTextBox.SelectedText);
}

/// <summary>
/// Get the start of the current selection in the code text box
/// </summary>
public int getSelectionStart()
{
return codeTextBox.SelectionStart;
this.findReplace.ShowReplace();
}

/// <summary>
/// Get the end of the current selection in the code text box
/// </summary>
public int getSelectionEnd()
private void goToMenuItem_Click(object sender, EventArgs e)
{
return codeTextBox.SelectionEnd;
}

/// <summary>
/// Get the selection length in the code text box
/// </summary>
public int getSelectionLength()
{
return codeTextBox.SelectionEnd - codeTextBox.SelectionStart;
}

/// <summary>
/// Get the currently selected text.
/// </summary>
public string getSelection()
{
return codeTextBox.SelectedText;
}

/// <summary>
/// Select text in the code text box. Will be invoked on the UI thread.
/// </summary>
/// <param name="selectionLength">start of the selection</param>
/// <param name="selectionStart">length of the selection</param>
public void selectText(int selectionStart, int selectionLength)
{
Invoke(new Action(() =>
{
codeTextBox.SelectionStart = selectionStart;
codeTextBox.SelectionEnd = selectionStart + selectionLength;
}));
}

/// <summary>
/// Replace the selected text. Will be invoked on the UI thread.
/// </summary>
/// <param name="toReplace">The new text to replace</param>
public void setSelectedText(string toReplace)
{
Invoke(new Action(() =>
{
codeTextBox.ReplaceSelection(toReplace);
}));
new GoTo(codeTextBox).ShowGoToDialog();
}

// ---------------------------------------------
Expand Down
Loading

0 comments on commit efac5dc

Please sign in to comment.