[Monodevelop-patches-list] r2674 - in trunk/MonoDevelop/Core/src/MonoDevelop.Base: . Commands Gui/ContentInterfaces Gui/Search Gui/Search/DocumentIterator Gui/Search/SearchResult Gui/Search/SearchStrategy Gui/Search/TextIterator
Lluis Sanchez <lluis@ximian.com>
lluis at mono-cvs.ximian.com
Wed Jul 20 06:33:46 EDT 2005
Author: lluis
Date: 2005-07-20 06:33:46 -0400 (Wed, 20 Jul 2005)
New Revision: 2674
Modified:
trunk/MonoDevelop/Core/src/MonoDevelop.Base/ChangeLog
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Commands/SearchCommands.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/ContentInterfaces/ITextBuffer.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DefaultFind.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DocumentIterator/AllOpenDocumentIterator.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/IFind.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceInFilesManager.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceManager.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/DefaultSearchResult.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/ISearchResult.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/BruteForceSearchStrategy.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/ISearchStrategy.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/KMPSearchStrategy.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/RegExSearchStrategy.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/WildcardSearchStrategy.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextFileIterator.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextIterator.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ITextIterator.cs
trunk/MonoDevelop/Core/src/MonoDevelop.Base/MonoDevelopCore.addin.xml
Log:
2005-07-20 Lluis Sanchez Gual <lluis at novell.com>
* Commands/SearchCommands.cs:
* Gui/Search/DocumentIterator/AllOpenDocumentIterator.cs:
* Gui/Search/SearchStrategy/KMPSearchStrategy.cs:
* Gui/Search/SearchStrategy/ISearchStrategy.cs:
* Gui/Search/SearchStrategy/WildcardSearchStrategy.cs:
* Gui/Search/SearchStrategy/RegExSearchStrategy.cs:
* Gui/Search/DefaultFind.cs:
* Gui/Search/IFind.cs:
* Gui/ContentInterfaces/ITextBuffer.cs:
* Gui/Search/SearchReplaceManager.cs: Added support for backward search.
* Gui/Search/TextIterator/ForwardTextFileIterator.cs:
* Gui/Search/SearchStrategy/BruteForceSearchStrategy.cs: Added support
for backward search and for native search method when available.
* Gui/Search/TextIterator/ITextIterator.cs:
* Gui/Search/TextIterator/ForwardTextIterator.cs:
* Gui/Search/SearchReplaceInFilesManager.cs:
* Gui/Search/SearchResult/DefaultSearchResult.cs:
* Gui/Search/SearchResult/ISearchResult.cs: Added DocumentOffset
property to ISearchResult and ITextIterator.
* MonoDevelopCore.addin.xml: Added FindPreviousSelection command.
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/ChangeLog 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/ChangeLog 2005-07-20 10:33:46 UTC (rev 2674)
@@ -1,3 +1,29 @@
+2005-07-20 Lluis Sanchez Gual <lluis at novell.com>
+
+ * Commands/SearchCommands.cs:
+ * Gui/Search/DocumentIterator/AllOpenDocumentIterator.cs:
+ * Gui/Search/SearchStrategy/KMPSearchStrategy.cs:
+ * Gui/Search/SearchStrategy/ISearchStrategy.cs:
+ * Gui/Search/SearchStrategy/WildcardSearchStrategy.cs:
+ * Gui/Search/SearchStrategy/RegExSearchStrategy.cs:
+ * Gui/Search/DefaultFind.cs:
+ * Gui/Search/IFind.cs:
+ * Gui/ContentInterfaces/ITextBuffer.cs:
+ * Gui/Search/SearchReplaceManager.cs: Added support for backward search.
+
+ * Gui/Search/TextIterator/ForwardTextFileIterator.cs:
+ * Gui/Search/SearchStrategy/BruteForceSearchStrategy.cs: Added support
+ for backward search and for native search method when available.
+
+ * Gui/Search/TextIterator/ITextIterator.cs:
+ * Gui/Search/TextIterator/ForwardTextIterator.cs:
+ * Gui/Search/SearchReplaceInFilesManager.cs:
+ * Gui/Search/SearchResult/DefaultSearchResult.cs:
+ * Gui/Search/SearchResult/ISearchResult.cs: Added DocumentOffset
+ property to ISearchResult and ITextIterator.
+
+ * MonoDevelopCore.addin.xml: Added FindPreviousSelection command.
+
2005-07-18 Lluis Sanchez Gual <lluis at novell.com>
* Services/Project/ProjectService.cs: Don't fire CurrentProjectChanged
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Commands/SearchCommands.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Commands/SearchCommands.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Commands/SearchCommands.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -20,7 +20,8 @@
FindPrevious,
Replace,
FindInFiles,
- FindSelection,
+ FindNextSelection,
+ FindPreviousSelection,
FindBox,
ReplaceInFiles
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/ContentInterfaces/ITextBuffer.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/ContentInterfaces/ITextBuffer.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/ContentInterfaces/ITextBuffer.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -36,6 +36,9 @@
object CursorPosition { get; set; }
object GetPositionFromOffset (int offset);
int GetOffsetFromPosition (object position);
+
+ object SelectionStartPosition { get; }
+ object SelectionEndPosition { get; }
void Select (object startPosition, object endPosition);
void ShowPosition (object position);
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DefaultFind.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DefaultFind.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DefaultFind.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -12,13 +12,16 @@
{
public class DefaultFind : IFind
{
- ISearchStrategy searchStrategy = null;
- IDocumentIterator documentIterator = null;
- ITextIterator textIterator = null;
- IDocumentInformation info = null;
- bool cancelled;
- int searchedFiles;
- int matches;
+ ISearchStrategy searchStrategy;
+ IDocumentIterator documentIterator;
+ ITextIterator textIterator;
+ IDocumentInformation info;
+ bool cancelled;
+ int searchedFiles;
+ int matches;
+ int lastResultPos;
+ SearchMap reverseSearchMap;
+ bool lastWasReverse;
public IDocumentInformation CurrentDocumentInformation {
get {
@@ -62,21 +65,33 @@
{
documentIterator.Reset();
textIterator = null;
+ reverseSearchMap = null;
cancelled = false;
searchedFiles = 0;
matches = 0;
+ lastResultPos = -1;
}
public void Replace (ISearchResult result, string pattern)
{
if (CurrentDocumentInformation != null && TextIterator != null) {
- TextIterator.Position = result.Offset;
+ TextIterator.Position = result.Position;
TextIterator.Replace (result.Length, pattern);
}
}
public ISearchResult FindNext(SearchOptions options)
{
+ return Find (options, false);
+ }
+
+ public ISearchResult FindPrevious (SearchOptions options)
+ {
+ return Find (options, true);
+ }
+
+ public ISearchResult Find (SearchOptions options, bool reverse)
+ {
// insanity check
Debug.Assert(searchStrategy != null);
Debug.Assert(documentIterator != null);
@@ -85,14 +100,40 @@
while (!cancelled)
{
if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
- if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed
- info = documentIterator.Current;
+ if (info.FileName != documentIterator.CurrentFileName || lastWasReverse != reverse) {
+ // create new iterator, if document changed or search direction has changed.
+ info = documentIterator.Current;
textIterator = info.GetTextIterator ();
+ reverseSearchMap = null;
+ lastResultPos = -1;
+ if (reverse)
+ textIterator.MoveToEnd ();
}
- ISearchResult result = searchStrategy.FindNext (textIterator, options);
+ ISearchResult result;
+ if (!reverse)
+ result = searchStrategy.FindNext (textIterator, options, false);
+ else {
+ if (searchStrategy.SupportsReverseSearch (textIterator, options)) {
+ result = searchStrategy.FindNext (textIterator, options, true);
+ }
+ else {
+ if (reverseSearchMap == null) {
+ reverseSearchMap = new SearchMap ();
+ reverseSearchMap.Build (searchStrategy, textIterator, options);
+ }
+ if (lastResultPos == -1)
+ lastResultPos = textIterator.Position;
+ result = reverseSearchMap.GetPreviousMatch (lastResultPos);
+ if (result != null)
+ textIterator.Position = result.Position;
+ }
+ }
+
if (result != null) {
matches++;
+ lastResultPos = result.Position;
+ lastWasReverse = reverse;
return result;
}
}
@@ -100,14 +141,22 @@
if (textIterator != null) textIterator.Close ();
// not found or first start -> move forward to the next document
- if (documentIterator.MoveForward()) {
+ bool more = !reverse ? documentIterator.MoveForward () : documentIterator.MoveBackward ();
+ if (more) {
searchedFiles++;
info = documentIterator.Current;
textIterator = info.GetTextIterator ();
+ reverseSearchMap = null;
+ lastResultPos = -1;
+ if (reverse)
+ textIterator.MoveToEnd ();
}
else
cancelled = true;
+
+ lastWasReverse = reverse;
}
+
cancelled = false;
return null;
}
@@ -117,4 +166,35 @@
cancelled = true;
}
}
+
+ class SearchMap
+ {
+ ArrayList matches = new ArrayList ();
+
+ public void Build (ISearchStrategy strategy, ITextIterator it, SearchOptions options)
+ {
+ int startPos = it.Position;
+ it.Reset ();
+
+ ISearchResult res = strategy.FindNext (it, options, false);
+ while (res != null) {
+ matches.Add (res);
+ res = strategy.FindNext (it, options, false);
+ }
+ it.Position = startPos;
+ }
+
+ public ISearchResult GetPreviousMatch (int pos)
+ {
+ if (matches.Count == 0) return null;
+
+ for (int n = matches.Count - 1; n >= 0; n--) {
+ ISearchResult m = (ISearchResult) matches [n];
+ if (m.Position < pos)
+ return m;
+ }
+
+ return null;
+ }
+ }
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DocumentIterator/AllOpenDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DocumentIterator/AllOpenDocumentIterator.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/DocumentIterator/AllOpenDocumentIterator.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -84,16 +84,16 @@
return true;
}
- if (curIndex == 0) {
+ if (curIndex == 0)
curIndex = WorkbenchSingleton.Workbench.ViewContentCollection.Count - 1;
- }
+ else
+ curIndex--;
- if (curIndex > 0) {
- --curIndex;
- WorkbenchSingleton.Workbench.ViewContentCollection[curIndex].WorkbenchWindow.SelectWindow();
- return true;
- }
- return false;
+ if (curIndex == startIndex)
+ return false;
+
+ WorkbenchSingleton.Workbench.ViewContentCollection[curIndex].WorkbenchWindow.SelectWindow();
+ return true;
}
public void Reset()
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/IFind.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/IFind.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/IFind.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -56,6 +56,8 @@
/// </returns>
ISearchResult FindNext(SearchOptions options);
+ ISearchResult FindPrevious(SearchOptions options);
+
/// <remarks>
/// Resets the find object to the original state.
/// </remarks>
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceInFilesManager.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceInFilesManager.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceInFilesManager.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -61,10 +61,10 @@
static void DisplaySearchResult(ISearchResult result)
{
if (result.Line != -1) {
- string text = result.DocumentInformation.GetLineTextAtOffset (result.Offset);
+ string text = result.DocumentInformation.GetLineTextAtOffset (result.DocumentOffset);
Runtime.TaskService.AddTask (new Task (result.FileName, text, result.Column, result.Line));
} else {
- string msg = string.Format (GettextCatalog.GetString ("Match at offset {0}"), result.Offset);
+ string msg = string.Format (GettextCatalog.GetString ("Match at offset {0}"), result.DocumentOffset);
Runtime.TaskService.AddTask (new Task(result.FileName, msg, -1, -1));
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceManager.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceManager.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchReplaceManager.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -36,8 +36,9 @@
{
public static ReplaceDialog ReplaceDialog = null;
- static IFind find = new DefaultFind();
+ static IFind find = new DefaultFind();
static SearchOptions searchOptions = new SearchOptions("SharpDevelop.SearchAndReplace.SearchAndReplaceProperties");
+ static ISearchResult lastResult = null;
public static SearchOptions SearchOptions {
get {
@@ -94,7 +95,7 @@
} else {
IBookmarkBuffer textArea = OpenView (result.FileName) as IBookmarkBuffer;
if (textArea != null) {
- object pos = textArea.GetPositionFromOffset (result.Offset);
+ object pos = textArea.GetPositionFromOffset (result.DocumentOffset);
textArea.SetBookmarked (pos, true);
}
}
@@ -125,9 +126,18 @@
}
}
- static ISearchResult lastResult = null;
- public static void FindNext()
+ public static void FindNext ()
{
+ Find (false);
+ }
+
+ public static void FindPrevious ()
+ {
+ Find (true);
+ }
+
+ public static void Find (bool reverse)
+ {
if (find == null ||
searchOptions.SearchPattern == null ||
searchOptions.SearchPattern.Length == 0) {
@@ -142,7 +152,7 @@
find.Reset ();
else {
ITextBuffer textArea = OpenView (lastResult.FileName) as ITextBuffer;
- if (textArea == null || (lastResult != null && textArea.GetOffsetFromPosition (textArea.CursorPosition) != lastResult.Offset + lastResult.Length)) {
+ if (textArea == null || (lastResult != null && textArea.GetOffsetFromPosition (textArea.CursorPosition) != lastResult.DocumentOffset + lastResult.Length)) {
find.Reset();
}
}
@@ -156,25 +166,35 @@
Runtime.MessageService.ShowMessage (GettextCatalog.GetString ("Search pattern is invalid"), DialogPointer);
return;
}
-
- ISearchResult result = find.FindNext(searchOptions);
+
+ ISearchResult result;
+ if (!reverse)
+ result = find.FindNext (searchOptions);
+ else
+ result = find.FindPrevious (searchOptions);
+ lastResult = result;
+
if (result == null) {
Runtime.MessageService.ShowMessage(GettextCatalog.GetString ("Search string not Found:") + "\n" + SearchOptions.SearchPattern, DialogPointer );
find.Reset();
} else {
ITextBuffer textArea = OpenView (result.FileName) as ITextBuffer;
if (textArea != null) {
- Console.WriteLine ("textArea.Text:" + (textArea.Text==null));
- int startPos = Math.Min (textArea.Text.Length, Math.Max(0, result.Offset));
+ int startPos = Math.Min (textArea.Text.Length, Math.Max(0, result.DocumentOffset));
int endPos = Math.Min (textArea.Text.Length, startPos + result.Length);
+ if (startPos == textArea.GetOffsetFromPosition (textArea.SelectionStartPosition) &&
+ endPos == textArea.GetOffsetFromPosition (textArea.SelectionEndPosition)) {
+ // If the result is the same of what we have selected, search again.
+ Find (reverse);
+ return;
+ }
+
textArea.ShowPosition (textArea.GetPositionFromOffset (endPos));
textArea.Select (textArea.GetPositionFromOffset (endPos), textArea.GetPositionFromOffset (startPos));
}
}
-
- lastResult = result;
}
static object OpenView (string fileName)
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/DefaultSearchResult.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/DefaultSearchResult.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/DefaultSearchResult.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -16,10 +16,12 @@
int length;
int line;
int column;
+ int position;
public DefaultSearchResult (ITextIterator iter, int length)
{
- offset = iter.Position;
+ position = iter.Position;
+ offset = iter.DocumentOffset;
line = iter.Line + 1;
column = iter.Column + 1;
this.length = length;
@@ -38,12 +40,18 @@
}
}
- public int Offset {
+ public int DocumentOffset {
get {
return offset;
}
}
+ public int Position {
+ get {
+ return position;
+ }
+ }
+
public int Length {
get {
return length;
@@ -67,7 +75,7 @@
{
return String.Format("[DefaultLocation: FileName={0}, Offset={1}, Length={2}]",
FileName,
- Offset,
+ DocumentOffset,
Length);
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/ISearchResult.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/ISearchResult.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchResult/ISearchResult.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -29,12 +29,19 @@
}
/// <value>
- /// The offset of the pattern match
+ /// The position of the pattern match in the text iterator
/// </value>
- int Offset {
+ int Position {
get;
}
+ /// <value>
+ /// The offset of the pattern match in the document
+ /// </value>
+ int DocumentOffset {
+ get;
+ }
+
int Line { get; }
int Column {get; }
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/BruteForceSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/BruteForceSearchStrategy.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/BruteForceSearchStrategy.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -92,8 +92,21 @@
searchPattern = options.IgnoreCase ? options.SearchPattern.ToUpper() : options.SearchPattern;
}
- public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
{
+ if (textIterator.SupportsSearch (options, reverseSearch)) {
+ if (textIterator.SearchNext (searchPattern, options, reverseSearch)) {
+ DefaultSearchResult sr = new DefaultSearchResult (textIterator, searchPattern.Length);
+ if (!reverseSearch)
+ textIterator.MoveAhead (searchPattern.Length);
+ return sr;
+ } else
+ return null;
+ }
+
+ if (reverseSearch)
+ throw new NotSupportedException ();
+
int offset = InternalFindNext(textIterator, options);
if (offset >= 0) {
int pos = textIterator.Position;
@@ -104,6 +117,11 @@
} else
return null;
}
+
+ public bool SupportsReverseSearch (ITextIterator textIterator, SearchOptions options)
+ {
+ return textIterator.SupportsSearch (options, true);
+ }
}
}
;
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/ISearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/ISearchStrategy.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/ISearchStrategy.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -26,6 +26,9 @@
/// The find next method should search the next occurrence of the
/// compiled pattern in the text using the textIterator and options.
/// </remarks>
- ISearchResult FindNext(ITextIterator textIterator, SearchOptions options);
+ ISearchResult FindNext (ITextIterator textIterator, SearchOptions options, bool reverseSearch);
+
+ // Returns true if this strategy can do reverse searchs with the given parameters
+ bool SupportsReverseSearch (ITextIterator textIterator, SearchOptions options);
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/KMPSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/KMPSearchStrategy.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/KMPSearchStrategy.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -64,8 +64,11 @@
}
}
- public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
{
+ if (reverseSearch)
+ throw new NotSupportedException ();
+
int pos = textIterator.Position;
int offset = InternalFindNext(textIterator, options);
@@ -73,12 +76,17 @@
if (textIterator.GetCharRelative (searchPattern.Length) == char.MinValue) {
if (pos != offset)
- return FindNext(textIterator, options);
+ return FindNext(textIterator, options, false);
else
return null;
}
return new DefaultSearchResult (textIterator, searchPattern.Length);
}
+
+ public bool SupportsReverseSearch (ITextIterator textIterator, SearchOptions options)
+ {
+ return false;
+ }
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/RegExSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/RegExSearchStrategy.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/RegExSearchStrategy.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -23,8 +23,11 @@
regex = new Regex(options.SearchPattern, regexOptions);
}
- public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
{
+ if (reverseSearch)
+ throw new NotSupportedException ();
+
if (!textIterator.MoveAhead(1)) return null;
if (regex == null) return null;
@@ -43,5 +46,10 @@
}
}
}
+
+ public bool SupportsReverseSearch (ITextIterator textIterator, SearchOptions options)
+ {
+ return false;
+ }
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/WildcardSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/WildcardSearchStrategy.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/SearchStrategy/WildcardSearchStrategy.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -151,10 +151,18 @@
CompilePattern(options.SearchPattern, options.IgnoreCase);
}
- public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
{
+ if (reverseSearch)
+ throw new NotSupportedException ();
+
int charCount = InternalFindNext(textIterator, options);
return charCount != -1 ? new DefaultSearchResult (textIterator, charCount) : null;
}
+
+ public bool SupportsReverseSearch (ITextIterator textIterator, SearchOptions options)
+ {
+ return false;
+ }
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextFileIterator.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextFileIterator.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextFileIterator.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -65,6 +65,10 @@
}
}
+ public int DocumentOffset {
+ get { return Position; }
+ }
+
public int Line {
get {
if (!lineInSync)
@@ -138,6 +142,15 @@
return reader.Peek() != -1;
}
+ public void MoveToEnd ()
+ {
+ int pos = Position;
+ while (MoveAhead (1)) {
+ pos = Position;
+ }
+ Position = pos;
+ }
+
public string ReadToEnd ()
{
return reader.ReadToEnd ();
@@ -179,5 +192,15 @@
else
reader.Close ();
}
+
+ public bool SupportsSearch (SearchOptions options, bool reverse)
+ {
+ return false;
+ }
+
+ public bool SearchNext (string text, SearchOptions options, bool reverse)
+ {
+ throw new NotSupportedException ();
+ }
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextIterator.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextIterator.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ForwardTextIterator.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -28,11 +28,21 @@
int endOffset;
IDocumentInformation docInfo;
+ public ForwardTextIterator (IDocumentInformation docInfo, Gtk.TextView document, int endOffset)
+ {
+ Debug.Assert(endOffset >= 0 && endOffset < BufferLength);
+
+ this.docInfo = docInfo;
+ this.textBuffer = document.Buffer;
+ this.endOffset = endOffset;
+ Reset();
+ }
+
public IDocumentInformation DocumentInformation {
get { return docInfo; }
}
- public char Current {
+ public virtual char Current {
get {
switch (state) {
case TextIteratorState.Resetted:
@@ -47,7 +57,12 @@
}
}
- public int Position {
+ public virtual int Position {
+ get { return BufferToIterPos (DocumentOffset); }
+ set { DocumentOffset = IterToBufferPos (value); }
+ }
+
+ public virtual int DocumentOffset {
get {
if (state == TextIteratorState.Done) return -1;
else return currentOffset;
@@ -64,33 +79,23 @@
}
}
- public int Line {
+ public virtual int Line {
get {
- int pos = Position;
+ int pos = DocumentOffset;
if (pos == -1) return -1;
return textBuffer.GetIterAtOffset (pos).Line;
}
}
- public int Column {
+ public virtual int Column {
get {
- int pos = Position;
+ int pos = DocumentOffset;
if (pos == -1) return -1;
return textBuffer.GetIterAtOffset (pos).LineOffset;
}
}
- public ForwardTextIterator (IDocumentInformation docInfo, Gtk.TextView document, int endOffset)
+ public virtual char GetCharRelative (int offset)
{
- Debug.Assert(endOffset >= 0 && endOffset < BufferLength);
-
- this.docInfo = docInfo;
- this.textBuffer = document.Buffer;
- this.endOffset = endOffset;
- Reset();
- }
-
- public char GetCharRelative(int offset)
- {
if (state != TextIteratorState.Iterating) {
throw new System.InvalidOperationException();
}
@@ -103,7 +108,7 @@
return GetCharAt(realOffset);
}
- public bool MoveAhead(int numChars)
+ public virtual bool MoveAhead(int numChars)
{
Debug.Assert(numChars > 0);
@@ -129,8 +134,18 @@
}
}
- public string ReadToEnd ()
+ public virtual void MoveToEnd ()
{
+ if (endOffset > 0)
+ currentOffset = endOffset - 1;
+ else
+ currentOffset = BufferLength - 1;
+
+ state = TextIteratorState.Iterating;
+ }
+
+ public virtual string ReadToEnd ()
+ {
if (state == TextIteratorState.Done) return "";
string doc = "";
@@ -144,7 +159,7 @@
return doc;
}
- public void Replace (int length, string pattern)
+ public virtual void Replace (int length, string pattern)
{
Gtk.TextIter start = textBuffer.GetIterAtOffset (currentOffset);
Gtk.TextIter end = textBuffer.GetIterAtOffset (currentOffset + length);
@@ -160,6 +175,16 @@
currentOffset = currentOffset - length + pattern.Length;
}
+ public virtual bool SupportsSearch (SearchOptions options, bool reverse)
+ {
+ return false;
+ }
+
+ public virtual bool SearchNext (string text, SearchOptions options, bool reverse)
+ {
+ throw new NotSupportedException ();
+ }
+
char GetCharAt (int offset)
{
if (offset < 0)
@@ -179,18 +204,38 @@
return textBuffer.GetText (begin_iter, end_iter, true);
}
+ int IterToBufferPos (int pos)
+ {
+ if (pos == -1)
+ return -1;
+ else if (pos >= (BufferLength - endOffset))
+ return pos - (BufferLength - endOffset);
+ else
+ return endOffset + pos;
+ }
+
+ int BufferToIterPos (int pos)
+ {
+ if (pos == -1)
+ return pos;
+ else if (pos >= endOffset)
+ return pos - endOffset;
+ else
+ return (BufferLength - endOffset) + pos;
+ }
+
public int BufferLength
{
get { return textBuffer.EndIter.Offset + 1; }
}
- public void Reset()
+ public virtual void Reset()
{
- state = TextIteratorState.Resetted;
+ state = TextIteratorState.Resetted;
currentOffset = endOffset;
}
- public void Close ()
+ public virtual void Close ()
{
}
@@ -198,5 +243,13 @@
{
return String.Format("[ForwardTextIterator: currentOffset={0}, endOffset={1}, state={2}]", currentOffset, endOffset, state);
}
+
+ protected Gtk.TextBuffer Buffer {
+ get { return textBuffer; }
+ }
+
+ protected int EndOffset {
+ get { return endOffset; }
+ }
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ITextIterator.cs
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ITextIterator.cs 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/Gui/Search/TextIterator/ITextIterator.cs 2005-07-20 10:33:46 UTC (rev 2674)
@@ -28,17 +28,29 @@
}
/// <value>
- /// The current position=offset of the text iterator cursor
+ /// The current position of the text iterator cursor. It always begins
+ /// at 0. It may be different from the real offset in the document.
/// </value>
int Position {
get;
set;
}
+ /// <value>
+ /// The current line in the document
+ /// </value>
int Line { get; }
+ /// <value>
+ /// The current column in the document
+ /// </value>
int Column {get; }
+ /// <value>
+ /// The current offset in the document
+ /// </value>
+ int DocumentOffset { get; }
+
/// <remarks>
/// Gets a char relative to the current position (negative values
/// will work too).
@@ -56,6 +68,11 @@
/// </remarks>
bool MoveAhead(int numChars);
+ /// <remarks>
+ /// Moves the iterator to the last valid position
+ /// </remarks>
+ void MoveToEnd ();
+
string ReadToEnd ();
/// <remarks>
@@ -68,5 +85,9 @@
void Close ();
IDocumentInformation DocumentInformation { get; }
+
+ bool SupportsSearch (SearchOptions options, bool reverse);
+
+ bool SearchNext (string text, SearchOptions options, bool reverse);
}
}
Modified: trunk/MonoDevelop/Core/src/MonoDevelop.Base/MonoDevelopCore.addin.xml
===================================================================
--- trunk/MonoDevelop/Core/src/MonoDevelop.Base/MonoDevelopCore.addin.xml 2005-07-20 03:07:57 UTC (rev 2673)
+++ trunk/MonoDevelop/Core/src/MonoDevelop.Base/MonoDevelopCore.addin.xml 2005-07-20 10:33:46 UTC (rev 2674)
@@ -453,15 +453,18 @@
icon = "Icons.16x16.FindNextIcon"
description = "Find next"
shortcut = "F3" />
- <Command id = "MonoDevelop.Commands.SearchCommands.FindSelection"
- _label = "Find Selection"
- description = "Find selection"
+ <Command id = "MonoDevelop.Commands.SearchCommands.FindNextSelection"
+ _label = "Find Next Selection"
+ description = "Find next selection"
shortcut = "Control|F3" />
<Command id = "MonoDevelop.Commands.SearchCommands.FindPrevious"
_label = "Find _Previous"
- icon = "Icons.16x16.FindPrevIcon"
description = "Find previous"
shortcut = "Shift|F3" />
+ <Command id = "MonoDevelop.Commands.SearchCommands.FindPreviousSelection"
+ _label = "Find _Previous Selection"
+ description = "Find previous selection"
+ shortcut = "Shift|Control|F3" />
<Command id = "MonoDevelop.Commands.SearchCommands.Replace"
_label = "_Replace..."
icon = "Icons.16x16.ReplaceIcon"
More information about the Monodevelop-patches-list
mailing list