mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-27 06:02:11 +00:00
@ working on find & replace in script editor
This commit is contained in:
parent
8593fd62dd
commit
c4b71597b4
6 changed files with 111 additions and 19 deletions
|
@ -96,6 +96,7 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
editor.OnExplicitSaveTab += panel.ExplicitSaveCurrentTab;
|
editor.OnExplicitSaveTab += panel.ExplicitSaveCurrentTab;
|
||||||
editor.OnOpenScriptBrowser += panel.OpenBrowseScript;
|
editor.OnOpenScriptBrowser += panel.OpenBrowseScript;
|
||||||
editor.OnOpenFindAndReplace += panel.OpenFindAndReplace;
|
editor.OnOpenFindAndReplace += panel.OpenFindAndReplace;
|
||||||
|
editor.OnFindNext += panel.FindNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disposer
|
// Disposer
|
||||||
|
@ -105,6 +106,7 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
editor.OnExplicitSaveTab -= panel.ExplicitSaveCurrentTab;
|
editor.OnExplicitSaveTab -= panel.ExplicitSaveCurrentTab;
|
||||||
editor.OnOpenScriptBrowser -= panel.OpenBrowseScript;
|
editor.OnOpenScriptBrowser -= panel.OpenBrowseScript;
|
||||||
editor.OnOpenFindAndReplace -= panel.OpenFindAndReplace;
|
editor.OnOpenFindAndReplace -= panel.OpenFindAndReplace;
|
||||||
|
editor.OnFindNext -= panel.FindNext;
|
||||||
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
@ -221,6 +223,7 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
string text = Encoding.GetEncoding(config.CodePage).GetString(data);
|
string text = Encoding.GetEncoding(config.CodePage).GetString(data);
|
||||||
StringComparison mode = options.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
|
StringComparison mode = options.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
|
||||||
int startpos = Math.Max(editor.SelectionStart, editor.SelectionEnd);
|
int startpos = Math.Max(editor.SelectionStart, editor.SelectionEnd);
|
||||||
|
bool wrapped = false;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
@ -230,7 +233,13 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
// Check to see if it is the whole word
|
// Check to see if it is the whole word
|
||||||
if(options.WholeWord)
|
if(options.WholeWord)
|
||||||
{
|
{
|
||||||
|
// Veryfy that we have found a whole word
|
||||||
|
string foundword = editor.GetWordAt(result + 1);
|
||||||
|
if(foundword.Length != options.FindText.Length)
|
||||||
|
{
|
||||||
|
startpos = result + 1;
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still ok?
|
// Still ok?
|
||||||
|
@ -246,9 +255,10 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If we haven't tried from the start, try from the start now
|
// If we haven't tried from the start, try from the start now
|
||||||
if(startpos > 0)
|
if((startpos > 0) && !wrapped)
|
||||||
{
|
{
|
||||||
startpos = 0;
|
startpos = 0;
|
||||||
|
wrapped = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,10 +60,12 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
public delegate void ExplicitSaveTabDelegate();
|
public delegate void ExplicitSaveTabDelegate();
|
||||||
public delegate void OpenScriptBrowserDelegate();
|
public delegate void OpenScriptBrowserDelegate();
|
||||||
public delegate void OpenFindReplaceDelegate();
|
public delegate void OpenFindReplaceDelegate();
|
||||||
|
public delegate void FindNextDelegate();
|
||||||
|
|
||||||
public event ExplicitSaveTabDelegate OnExplicitSaveTab;
|
public event ExplicitSaveTabDelegate OnExplicitSaveTab;
|
||||||
public event OpenScriptBrowserDelegate OnOpenScriptBrowser;
|
public event OpenScriptBrowserDelegate OnOpenScriptBrowser;
|
||||||
public event OpenFindReplaceDelegate OnOpenFindAndReplace;
|
public event OpenFindReplaceDelegate OnOpenFindAndReplace;
|
||||||
|
public event FindNextDelegate OnFindNext;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -351,15 +353,22 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
// This returns the current word (where the caret is at)
|
// This returns the current word (where the caret is at)
|
||||||
public string GetCurrentWord()
|
public string GetCurrentWord()
|
||||||
{
|
{
|
||||||
int wordstart = scriptedit.WordStartPosition(scriptedit.CurrentPos, true);
|
return GetWordAt(scriptedit.CurrentPos);
|
||||||
int wordend = scriptedit.WordEndPosition(scriptedit.CurrentPos, true);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This returns the word at the given position
|
||||||
|
public string GetWordAt(int position)
|
||||||
|
{
|
||||||
|
int wordstart = scriptedit.WordStartPosition(position, true);
|
||||||
|
int wordend = scriptedit.WordEndPosition(position, true);
|
||||||
|
|
||||||
// Decode the text
|
// Decode the text
|
||||||
byte[] scripttextdata = scriptedit.GetText(scriptedit.TextSize);
|
byte[] scripttextdata = scriptedit.GetText(scriptedit.TextSize);
|
||||||
Encoding encoder = Encoding.GetEncoding(scriptedit.CodePage);
|
Encoding encoder = Encoding.GetEncoding(scriptedit.CodePage);
|
||||||
string scripttext = encoder.GetString(scripttextdata);
|
string scripttext = encoder.GetString(scripttextdata);
|
||||||
|
|
||||||
if(wordstart > wordend)
|
if(wordstart < wordend)
|
||||||
return scripttext.Substring(wordstart, wordend - wordstart);
|
return scripttext.Substring(wordstart, wordend - wordstart);
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
|
@ -625,6 +634,13 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
if((e.KeyCode == Keys.N) && ((e.Modifiers & Keys.Control) == Keys.Control)) e.Handled = true;
|
if((e.KeyCode == Keys.N) && ((e.Modifiers & Keys.Control) == Keys.Control)) e.Handled = true;
|
||||||
if((e.KeyCode == Keys.M) && ((e.Modifiers & Keys.Control) == Keys.Control)) e.Handled = true;
|
if((e.KeyCode == Keys.M) && ((e.Modifiers & Keys.Control) == Keys.Control)) e.Handled = true;
|
||||||
|
|
||||||
|
// F3 for Find Next
|
||||||
|
if((e.KeyCode == Keys.F3) && (e.Modifiers == Keys.None))
|
||||||
|
{
|
||||||
|
if(OnFindNext != null) OnFindNext();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
// CTRL+F for find & replace
|
// CTRL+F for find & replace
|
||||||
if((e.KeyCode == Keys.F) && ((e.Modifiers & Keys.Control) == Keys.Control))
|
if((e.KeyCode == Keys.F) && ((e.Modifiers & Keys.Control) == Keys.Control))
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,8 +49,9 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
private List<ScriptConfiguration> scriptconfigs;
|
private List<ScriptConfiguration> scriptconfigs;
|
||||||
private List<CompilerError> compilererrors;
|
private List<CompilerError> compilererrors;
|
||||||
|
|
||||||
// Windows
|
// Find/Replace
|
||||||
private ScriptFindReplaceForm findreplaceform;
|
private ScriptFindReplaceForm findreplaceform;
|
||||||
|
private FindReplaceOptions findoptions;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -169,7 +170,41 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
|
|
||||||
#region ================== Methods
|
#region ================== Methods
|
||||||
|
|
||||||
// This opens the Find & Replace sub window
|
// Find Next
|
||||||
|
public void FindNext(FindReplaceOptions options)
|
||||||
|
{
|
||||||
|
// Save the options
|
||||||
|
findoptions = options;
|
||||||
|
FindNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find Next with saved options
|
||||||
|
public void FindNext()
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrEmpty(findoptions.FindText))
|
||||||
|
{
|
||||||
|
if(!ActiveTab.FindNext(findoptions))
|
||||||
|
{
|
||||||
|
General.MainWindow.DisplayStatus(StatusType.Warning, "Can't find any occurence of \"" + findoptions.FindText + "\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
General.MessageBeep(MessageBeepType.Default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This closed the Find & Replace subwindow
|
||||||
|
public void CloseFindReplace(bool closing)
|
||||||
|
{
|
||||||
|
if(findreplaceform != null)
|
||||||
|
{
|
||||||
|
if(!closing) findreplaceform.Close();
|
||||||
|
findreplaceform = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This opens the Find & Replace subwindow
|
||||||
public void OpenFindAndReplace()
|
public void OpenFindAndReplace()
|
||||||
{
|
{
|
||||||
if(findreplaceform == null)
|
if(findreplaceform == null)
|
||||||
|
|
2
Source/Windows/ScriptFindReplaceForm.Designer.cs
generated
2
Source/Windows/ScriptFindReplaceForm.Designer.cs
generated
|
@ -131,6 +131,7 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
this.closebutton.TabIndex = 9;
|
this.closebutton.TabIndex = 9;
|
||||||
this.closebutton.Text = "Close";
|
this.closebutton.Text = "Close";
|
||||||
this.closebutton.UseVisualStyleBackColor = true;
|
this.closebutton.UseVisualStyleBackColor = true;
|
||||||
|
this.closebutton.Click += new System.EventHandler(this.closebutton_Click);
|
||||||
//
|
//
|
||||||
// replacebutton
|
// replacebutton
|
||||||
//
|
//
|
||||||
|
@ -163,6 +164,7 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||||
this.Name = "ScriptFindReplaceForm";
|
this.Name = "ScriptFindReplaceForm";
|
||||||
this.Text = "Find and Replace";
|
this.Text = "Find and Replace";
|
||||||
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ScriptFindReplaceForm_FormClosing);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
{
|
{
|
||||||
#region ================== Variables
|
#region ================== Variables
|
||||||
|
|
||||||
|
private bool appclose;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Properties
|
#region ================== Properties
|
||||||
|
@ -51,24 +53,51 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Events
|
#region ================== Methods
|
||||||
|
|
||||||
// Find Next
|
// This makes the Find & Replace options
|
||||||
private void findnextbutton_Click(object sender, EventArgs e)
|
private FindReplaceOptions MakeOptions()
|
||||||
{
|
{
|
||||||
FindReplaceOptions options = new FindReplaceOptions();
|
FindReplaceOptions options = new FindReplaceOptions();
|
||||||
options.FindText = findtext.Text;
|
options.FindText = findtext.Text;
|
||||||
options.CaseSensitive = casesensitive.Checked;
|
options.CaseSensitive = casesensitive.Checked;
|
||||||
options.WholeWord = wordonly.Checked;
|
options.WholeWord = wordonly.Checked;
|
||||||
options.ReplaceWith = replacetext.Text;
|
options.ReplaceWith = replacetext.Text;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
if(!General.Map.ScriptEditor.Editor.ActiveTab.FindNext(options))
|
// Close the window
|
||||||
|
new public void Close()
|
||||||
|
{
|
||||||
|
appclose = true;
|
||||||
|
base.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Events
|
||||||
|
|
||||||
|
// Form is closing
|
||||||
|
private void ScriptFindReplaceForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
if(!appclose)
|
||||||
{
|
{
|
||||||
// No such thing
|
General.Map.ScriptEditor.Editor.CloseFindReplace(true);
|
||||||
General.MainWindow.DisplayStatus(StatusType.Warning, "Can't find any occurence of \"" + findtext.Text + "\".");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find Next
|
||||||
|
private void findnextbutton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
General.Map.ScriptEditor.Editor.FindNext(MakeOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close
|
||||||
|
private void closebutton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
General.Map.ScriptEditor.Editor.CloseFindReplace(false);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue