public Range Find(Range r, Regex findExpression, bool searchUp) { // Single line and Multi Line in RegExp doesn't really effect // whether or not a match will include newline charaters. This // means we can't do a line by line search. We have to search // the entire range becuase it could potentially match the // entire range. Match m = findExpression.Match(r.Text); if (!m.Success) return null; if (searchUp) { // Since we can't search backwards with RegExp we // have to search the entire string and return the // last match. Not the most efficient way of doing // things but it works. Range range = null; while (m.Success) { range = new Range(r.Start + m.Index, r.Start + m.Index + m.Length, Scintilla); m = m.NextMatch(); } return range; } return new Range(r.Start + m.Index, r.Start + m.Index + m.Length, Scintilla); }
private void StyleToken(EtcScriptLib.Token Token, int Style, int FoldLevel) { var range = new ScintillaNET.Range(Token.Location.Index, Token.Location.EndIndex, scintilla1); range.SetStyle(Style); //range.StartingLine.FoldLevel = FoldLevel; ////range.StartingLine.Indentation = FoldLevel; //if (FoldLevel > this.FoldLevel) // range.StartingLine.IsFoldPoint = true; //else // range.StartingLine.IsFoldPoint = false; //this.FoldLevel = FoldLevel; }
protected override void OnActivated(EventArgs e) { if (Scintilla.Selection.Length > 0) { chkSearchSelectionF.Enabled = true; chkSearchSelectionR.Enabled = true; } else { chkSearchSelectionF.Enabled = false; chkSearchSelectionR.Enabled = false; chkSearchSelectionF.Checked = false; chkSearchSelectionR.Checked = false; } // if they leave the dialog and come back any "Search Selection" // range they might have had is invalidated _searchRange = null; lblStatus.Text = string.Empty; MoveFormAwayFromSelection(); base.OnActivated(e); }
private void btnReplaceAll_Click(object sender, EventArgs e) { if (cboFindR.Text == string.Empty) return; lblStatus.Text = string.Empty; List<Range> foundRanges = null; if (rdoRegexR.Checked) { Regex rr = null; try { rr = new Regex(cboFindR.Text, GetRegexOptions()); } catch (ArgumentException ex) { lblStatus.Text = "Error in Regular Expression: " + ex.Message; return; } if (chkSearchSelectionR.Checked) { if (_searchRange == null) { _searchRange = Scintilla.Selection.Range; } foundRanges = Scintilla.FindReplace.ReplaceAll(_searchRange, rr, cboReplace.Text); } else { _searchRange = null; foundRanges = Scintilla.FindReplace.ReplaceAll(rr, cboReplace.Text); } } else { if (chkSearchSelectionR.Checked) { if (_searchRange == null) _searchRange = Scintilla.Selection.Range; foundRanges = Scintilla.FindReplace.ReplaceAll(_searchRange, cboFindR.Text, cboReplace.Text, GetSearchFlags()); } else { _searchRange = null; foundRanges = Scintilla.FindReplace.ReplaceAll(cboFindR.Text, cboReplace.Text, GetSearchFlags()); } } lblStatus.Text = "Total Replaced: " + foundRanges.Count.ToString(); }
public static void StyleNeeded(Scintilla scintilla, Range range) { // Create an instance of our lexer and bada-bing the line! IniLexer lexer = new IniLexer(scintilla, range.Start, range.StartingLine.Length); lexer.Style(); }
public Range Search(Range searchRange, Range startingAfterRange) { int start = startingAfterRange.End; if (start > _scintilla.NativeInterface.GetTextLength()) return null; int foundStart = _scintilla.NativeInterface.IndicatorEnd(_index, start); int foundEnd = _scintilla.NativeInterface.IndicatorEnd(_index, foundStart); if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd) return null; return new Range(foundStart, foundEnd, _scintilla); }
private string ReplaceAllEvaluator(Match m) { // So this method is called for every match // We make a replacement in the range based upon // the match range. string replacement = m.Result(_lastReplaceAllReplaceString); int start = _lastReplaceAllRangeToSearch.Start + m.Index + _lastReplaceAllOffset; int end = start + m.Length; Range r = new Range(start, end, Scintilla); _lastReplaceAllMatches.Add(r); r.Text = replacement; // But because we've modified the document, the RegEx // match ranges are going to be different from the // document ranges. We need to compensate _lastReplaceAllOffset += replacement.Length - m.Value.Length; return replacement; }
public bool IntersectsWith(Range otherRange) { return otherRange.PositionInRange(_start) | otherRange.PositionInRange(_end) | PositionInRange(otherRange.Start) | PositionInRange(otherRange.End); }
public Range Find(Range rangeToSearch, string searchString, SearchFlags searchflags) { return Find(rangeToSearch.Start, rangeToSearch.End, searchString, searchflags); }
/// <summary> /// Initializes a new instance of the StyleNeededEventArgs class. /// </summary> /// <param name="range">the document range that needs styling</param> public StyleNeededEventArgs(Range range) { _range = range; }
public Range Find(Range r, Regex findExpression, bool searchUp) { // Single line and Multi Line in RegExp doesn't really effect // whether or not a match will include newline characters. This // means we can't do a line by line search. We have to search // the entire range because it could potentially match the // entire range. string text = r.Text; Match m = findExpression.Match(text); if (!m.Success) return null; if (searchUp) { // Since we can't search backwards with RegExp we // have to search the entire string and return the // last match. Not the most efficient way of doing // things but it works. Range range = null; while (m.Success) { int start = r.Start + Scintilla.Encoding.GetByteCount(text.Substring(0, m.Index)); int end = Scintilla.Encoding.GetByteCount(text.Substring(m.Index, m.Length)); range = new Range(start, start + end, Scintilla); m = m.NextMatch(); } return range; } else { int start = r.Start + Scintilla.Encoding.GetByteCount(text.Substring(0, m.Index)); int end = Scintilla.Encoding.GetByteCount(text.Substring(m.Index, m.Length)); return new Range(start, start + end, Scintilla); } }
public Range Search(Range searchRange) { int foundStart = NativeScintilla.IndicatorEnd(_number, searchRange.Start); int foundEnd = NativeScintilla.IndicatorEnd(_number, foundStart); if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd) return null; return new Range(foundStart, foundEnd, Scintilla); }
public Range Search(Range searchRange, Range startingAfterRange) { int start = startingAfterRange.End; if (start > NativeScintilla.GetTextLength()) return null; int foundStart = NativeScintilla.IndicatorEnd(_number, start); int foundEnd = NativeScintilla.IndicatorEnd(_number, foundStart); if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd) return null; return new Range(foundStart, foundEnd, Scintilla); }
public List<Range> ReplaceAll(Range rangeToSearch, Regex findExpression, string replaceString) { Scintilla.UndoRedo.BeginUndoAction(); // I tried using an anonymous delegate for this but it didn't work too well. // It's too bad because it was a lot cleaner than using member variables as // psuedo globals. _lastReplaceAllMatches = new List<Range>(); _lastReplaceAllReplaceString = replaceString; _lastReplaceAllRangeToSearch = rangeToSearch; _lastReplaceAllOffset = 0; findExpression.Replace(rangeToSearch.Text, new MatchEvaluator(ReplaceAllEvaluator)); Scintilla.UndoRedo.EndUndoAction(); // No use having these values hanging around wasting memory :) List<Range> ret = _lastReplaceAllMatches; _lastReplaceAllMatches = null; _lastReplaceAllReplaceString = null; _lastReplaceAllRangeToSearch = null; return ret; }
public Range Find(Range rangeToSearch, string searchString, SearchFlags searchflags, bool searchUp) { if (searchUp) return Find(rangeToSearch.End, rangeToSearch.Start, searchString, searchflags); else return Find(rangeToSearch.Start, rangeToSearch.End, searchString, searchflags); }
public List<Range> ReplaceAll(Range rangeToSearch, string searchString, string replaceString, SearchFlags flags) { return ReplaceAll(rangeToSearch.Start, rangeToSearch.End, searchString, replaceString, _flags); }
public List<Range> FindAll(Range rangeToSearch, Regex findExpression) { List<Range> res = new List<Range>(); while (true) { Range r = Find(rangeToSearch, findExpression); if (r == null) { break; } else { res.Add(r); rangeToSearch = new Range(r.End, rangeToSearch.End, Scintilla); } } return res; }
public Range Find(Range r, Regex findExpression) { return Find(r, findExpression, false); }
public List<Range> FindAll(Range rangeToSearch, string searchString, SearchFlags flags) { return FindAll(rangeToSearch.Start, rangeToSearch.End, searchString, _flags); }
public Range Search(Range searchRange) { int foundStart = _scintilla.NativeInterface.IndicatorEnd(_index, searchRange.Start); int foundEnd = _scintilla.NativeInterface.IndicatorEnd(_index, foundStart); if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd) return null; return new Range(foundStart, foundEnd, _scintilla); }
public Range FindNext(Regex findExpression, bool wrap, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.Start, searchRange.End, findExpression, false); Range r = Find(caret, searchRange.End, findExpression); if (r != null) return r; else if (wrap) return Find(searchRange.Start, caret, findExpression); else return null; }
public List<Range> SearchAll(Range searchRange) { Range foundRange = _scintilla.GetRange(-1, -1); List<Range> ret = new List<Range>(); do { foundRange = Search(searchRange, foundRange); if (foundRange != null) ret.Add(foundRange); } while (foundRange != null); return ret; }
public Range FindNext(string searchString, bool wrap, SearchFlags flags, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.Start, searchRange.End, searchString, flags); Range r = Find(caret, searchRange.End, searchString, flags); if (r != null) return r; else if (wrap) return Find(searchRange.Start, caret, searchString, flags); else return null; }
protected internal ManagedRange(Range range) : this(range.Start, range.End, range.Scintilla) { }
public Range FindPrevious(Regex findExpression, bool wrap, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.Start, searchRange.End, findExpression, true); int anchor = Scintilla.Caret.Anchor; if (!searchRange.PositionInRange(anchor)) anchor = caret; Range r = Find(searchRange.Start, anchor, findExpression, true); if (r != null) return r; else if (wrap) return Find(anchor, searchRange.End, findExpression, true); else return null; }
private Range FindNextR(bool searchUp, ref Regex rr) { Range foundRange; if (rdoRegexR.Checked) { if (rr == null) rr = new Regex(cboFindR.Text, GetRegexOptions()); if (chkSearchSelectionR.Checked) { if (_searchRange == null) _searchRange = Scintilla.Selection.Range; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(rr, chkWrapR.Checked, _searchRange); else foundRange = Scintilla.FindReplace.FindNext(rr, chkWrapR.Checked, _searchRange); } else { _searchRange = null; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(rr, chkWrapR.Checked); else foundRange = Scintilla.FindReplace.FindNext(rr, chkWrapR.Checked); } } else { if (chkSearchSelectionF.Checked) { if (_searchRange == null) _searchRange = Scintilla.Selection.Range; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(cboFindR.Text, chkWrapR.Checked, GetSearchFlags(), _searchRange); else foundRange = Scintilla.FindReplace.FindNext(cboFindR.Text, chkWrapR.Checked, GetSearchFlags(), _searchRange); } else { _searchRange = null; if (searchUp) foundRange = Scintilla.FindReplace.FindPrevious(cboFindR.Text, chkWrapF.Checked, GetSearchFlags()); else foundRange = Scintilla.FindReplace.FindNext(cboFindR.Text, chkWrapF.Checked, GetSearchFlags()); } } return foundRange; }
public Range FindPrevious(string searchString, bool wrap, SearchFlags flags, Range searchRange) { int caret = Scintilla.Caret.Position; if (!searchRange.PositionInRange(caret)) return Find(searchRange.End, searchRange.Start, searchString, flags); int anchor = Scintilla.Caret.Anchor; if (!searchRange.PositionInRange(anchor)) anchor = caret; Range r = Find(anchor, searchRange.Start, searchString, flags); if (r != null) return r; else if (wrap) return Find(searchRange.End, anchor, searchString, flags); else return null; }
private void btnFindAll_Click(object sender, EventArgs e) { if (cboFindF.Text == string.Empty) return; AddFindMru(); lblStatus.Text = string.Empty; List<Range> foundRanges = null; if (rdoRegexF.Checked) { Regex rr = null; try { rr = new Regex(cboFindF.Text, GetRegexOptions()); } catch (ArgumentException ex) { lblStatus.Text = "Error in Regular Expression: " + ex.Message; return; } if (chkSearchSelectionF.Checked) { if (_searchRange == null) { _searchRange = Scintilla.Selection.Range; } foundRanges = Scintilla.FindReplace.FindAll(_searchRange, rr); } else { _searchRange = null; foundRanges = Scintilla.FindReplace.FindAll(rr); } } else { if (chkSearchSelectionF.Checked) { if (_searchRange == null) _searchRange = Scintilla.Selection.Range; foundRanges = Scintilla.FindReplace.FindAll(_searchRange, cboFindF.Text, GetSearchFlags()); } else { _searchRange = null; foundRanges = Scintilla.FindReplace.FindAll(cboFindF.Text, GetSearchFlags()); } } lblStatus.Text = "Total found: " + foundRanges.Count.ToString(); btnClear_Click(null, null); if (chkMarkLine.Checked) Scintilla.FindReplace.MarkAll(foundRanges); if (chkHighlightMatches.Checked) Scintilla.FindReplace.HighlightAll(foundRanges); }
public Main() { InitializeComponent(); try { Settings = Newtonsoft.Json.JsonConvert.DeserializeObject<Settings>( System.IO.File.ReadAllText("default-settings.txt")); } catch (Exception e) { MessageBox.Show(e.Message); Settings = new EtcScriptEmu.Settings(); } //scintilla1.Styles[0].ForeColor = Color.Black; //scintilla1.Styles[1].ForeColor = Color.Red; //scintilla1.Styles[2].ForeColor = Color.Green; //scintilla1.Styles[3].ForeColor = Color.Blue; //scintilla1.Styles[4].ForeColor = Color.Orange; StyleMap = new Dictionary<EtcScriptLib.SyntaxLex.TokenStyle, int>(); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Basic, 0); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Clause, 4); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.ComplexStringPart, 2); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Error, 1); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Keyword, 3); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Number, 2); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.Operator, 4); StyleMap.Add(EtcScriptLib.SyntaxLex.TokenStyle.String, 2); ScriptEnvironment = new EtcScriptLib.Environment(); SyntaxLex = new EtcScriptLib.SyntaxLex(ScriptEnvironment.Context, (token, style, fold) => { if (StyleMap.ContainsKey(style)) StyleToken(token, StyleMap[style], fold); else StyleToken(token, 0, fold); }, (token) => { var range = new ScintillaNET.Range(token.Location.Index, token.Location.EndIndex, scintilla1); range.StartingLine.IsFoldPoint = true; }); runButton.Enabled = false; var defaultHost = Settings.Hosts.Where(hs => hs.DisplayName == Settings.DefaultHost).FirstOrDefault(); if (defaultHost != null) PrepareHost(System.IO.Path.GetFullPath(defaultHost.Path)); if (Settings.OpenFiles.Count == 0) OpenNewFile(); else foreach (var filename in Settings.OpenFiles) Open(filename); foreach (var host in Settings.Hosts) { var lCopy = host; var button = defaultHosts.DropDownItems.Add(host.DisplayName); button.Click += (sender, args) => { PrepareHost(System.IO.Path.GetFullPath(lCopy.Path)); }; } }