[Monodevelop-patches-list] r942 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor: . Gui Gui/Dialogs Search Search/DocumentIterator Search/SearchResult Search/SearchStrategy Search/TextIterator
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Wed Feb 18 22:42:54 EST 2004
Author: tberman
Date: 2004-02-18 22:42:53 -0500 (Wed, 18 Feb 2004)
New Revision: 942
Added:
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/Dialogs/ReplaceDialog.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/Dialogs/ReplaceInFilesDialog.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DefaultFind.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/AllOpenDocumentIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/CurrentDocumentIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/DirectoryDocumentIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/IDocumentIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ReverseDocumentIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/WholeProjectDocumentIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/IFind.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/ITextBufferStrategy.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchOptions.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceInFilesManager.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceUtilities.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/DefaultSearchResult.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/ISearchResult.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/ISearchStrategy.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/KMPSearchStrategy.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/RegExSearchStrategy.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/WildcardSearchStrategy.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIteratorBuilder.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIterator.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIteratorBuilder.cs
Modified:
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am
Log:
adding search stuff, doesnt work yet, but it does compile
Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/Dialogs/ReplaceDialog.cs (from rev 941, trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/ReplaceDialog.cs)
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/ReplaceDialog.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/Dialogs/ReplaceDialog.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,446 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Drawing;
+using System.ComponentModel;
+using System.Collections.Specialized;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.TextEditor.Document;
+using ICSharpCode.Core.Properties;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.SharpDevelop.Services;
+using ICSharpCode.TextEditor;
+//using MonoDevelop.EditorBindings.Search;
+
+using Gtk;
+using Glade;
+
+namespace ICSharpCode.SharpDevelop.Gui.Dialogs
+{
+ public class ReplaceDialog
+ {
+ private const int HISTORY_LIMIT = 20;
+ private const char HISTORY_SEPARATOR_CHAR = (char) 10;
+ // regular members
+ public bool replaceMode;
+ StringCollection findHistory = new StringCollection();
+ StringCollection replaceHistory = new StringCollection();
+
+ // services
+ ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
+ static PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+ static FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+ StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService (typeof (StringParserService));
+
+ // gtk widgets
+ [Glade.Widget] Gtk.Combo searchPatternComboBox;
+ [Glade.Widget] Gtk.Combo replacePatternComboBox;
+ [Glade.Widget] Gtk.Button findHelpButton;
+ [Glade.Widget] Gtk.Button findButton;
+ [Glade.Widget] Gtk.Button markAllButton;
+ [Glade.Widget] Gtk.Button closeButton;
+ [Glade.Widget] Gtk.Button replaceButton;
+ [Glade.Widget] Gtk.Button replaceAllButton;
+ [Glade.Widget] Gtk.Button replaceHelpButton;
+ [Glade.Widget] Gtk.CheckButton ignoreCaseCheckBox;
+ [Glade.Widget] Gtk.CheckButton searchWholeWordOnlyCheckBox;
+ [Glade.Widget] Gtk.CheckButton useSpecialSearchStrategyCheckBox;
+ [Glade.Widget] Gtk.OptionMenu specialSearchStrategyComboBox;
+ [Glade.Widget] Gtk.OptionMenu searchLocationComboBox;
+ [Glade.Widget] Gtk.Label label1;
+ [Glade.Widget] Gtk.Label label2;
+ [Glade.Widget] Gtk.Label searchLocationLabel;
+ [Glade.Widget] Gtk.Dialog FindDialogWidget;
+ [Glade.Widget] Gtk.Dialog ReplaceDialogWidget;
+ Gtk.Dialog ReplaceDialogPointer;
+
+ void InitDialog ()
+ {
+ label1.Text = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.FindWhat}");
+ searchLocationLabel.Text = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.SearchIn}");
+ //findButton.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.FindNextButton}");
+ //closeButton.Label = stringParserService.Parse ("${res:Global.CloseButtonText}");
+ findButton.UseUnderline = true;
+ closeButton.UseUnderline = true;
+ ignoreCaseCheckBox.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.CaseSensitive}");
+ searchWholeWordOnlyCheckBox.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.WholeWord}");
+ useSpecialSearchStrategyCheckBox.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.UseMethodLabel}");
+
+
+ //set up the size groups
+ SizeGroup labels = new SizeGroup(SizeGroupMode.Horizontal);
+ SizeGroup combos = new SizeGroup(SizeGroupMode.Horizontal);
+ SizeGroup options = new SizeGroup(SizeGroupMode.Horizontal);
+ SizeGroup helpButtons = new SizeGroup(SizeGroupMode.Horizontal);
+ SizeGroup checkButtons = new SizeGroup(SizeGroupMode.Horizontal);
+ labels.AddWidget(label1);
+ combos.AddWidget(searchPatternComboBox);
+ helpButtons.AddWidget(findHelpButton);
+ checkButtons.AddWidget(ignoreCaseCheckBox);
+ checkButtons.AddWidget(searchWholeWordOnlyCheckBox);
+ checkButtons.AddWidget(useSpecialSearchStrategyCheckBox);
+ checkButtons.AddWidget(searchLocationLabel);
+ options.AddWidget(specialSearchStrategyComboBox);
+ options.AddWidget(searchLocationComboBox);
+
+ // set button sensitivity
+ findHelpButton.Sensitive = false;
+
+ // set replace dialog properties
+ if(replaceMode)
+ {
+ ReplaceDialogPointer = this.ReplaceDialogWidget;
+ // set the label properties
+ label2.Text = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.ReplaceWith}");
+ //replaceButton.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.ReplaceButton}");
+ replaceAllButton.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.ReplaceAllButton}");
+ replaceButton.UseUnderline = true;
+ replaceAllButton.UseUnderline = true;
+
+ // set te size groups to include the replace dialog
+ labels.AddWidget(label2);
+ combos.AddWidget(replacePatternComboBox);
+ helpButtons.AddWidget(replaceHelpButton);
+
+ replaceHelpButton.Sensitive = false;
+ }
+ else
+ {
+ ReplaceDialogPointer = this.FindDialogWidget;
+ markAllButton.UseUnderline = true;
+ markAllButton.Label = stringParserService.Parse ("${res:Dialog.NewProject.SearchReplace.MarkAllButton}");
+ }
+ }
+
+ public ReplaceDialog(bool replaceMode)
+ {
+ // some members needed to initialise this dialog based on replace mode
+ this.replaceMode = replaceMode;
+ string dialogName = (replaceMode) ? "ReplaceDialogWidget" : "FindDialogWidget";
+
+ // we must do it from *here* otherwise, we get this assembly, not the caller
+ Glade.XML glade = new XML (null, "texteditoraddin.glade", dialogName, null);
+ glade.Autoconnect (this);
+ InitDialog ();
+ /*if (replaceMode) {
+ //this.SetupFromXml(Path.Combine(propertyService.DataDirectory, @"resources\dialogs\ReplaceDialog.xfrm"));
+ //ControlDictionary["replaceHelpButton"].Enabled = false;
+ InitDialogForReplace ();
+ } else {
+ InitDialogForFind ();
+ //this.SetupFromXml(Path.Combine(propertyService.DataDirectory, @"resources\dialogs\FindDialog.xfrm"));
+ }*/
+
+ //AcceptButton = (Button)ControlDictionary["findButton"];
+ //CancelButton = (Button)ControlDictionary["closeButton"];
+
+ LoadHistoryValues();
+
+ ignoreCaseCheckBox.Active = !SearchReplaceManager.SearchOptions.IgnoreCase;
+ searchWholeWordOnlyCheckBox.Active = SearchReplaceManager.SearchOptions.SearchWholeWordOnly;
+
+ useSpecialSearchStrategyCheckBox.Active = SearchReplaceManager.SearchOptions.SearchStrategyType != SearchStrategyType.Normal;
+ useSpecialSearchStrategyCheckBox.Toggled += new EventHandler(SpecialSearchStrategyCheckBoxChangedEvent);
+
+ Gtk.MenuItem tmpItem = new Gtk.MenuItem ("Wildcards");
+ Gtk.Menu stratMenu = new Gtk.Menu ();
+ stratMenu.Append (tmpItem);
+ tmpItem = new Gtk.MenuItem (resourceService.GetString("Dialog.NewProject.SearchReplace.SearchStrategy.RegexSearch"));
+ stratMenu.Append (tmpItem);
+ specialSearchStrategyComboBox.Menu = stratMenu;
+
+ uint index = 0;
+ switch (SearchReplaceManager.SearchOptions.SearchStrategyType) {
+ case SearchStrategyType.Normal:
+ case SearchStrategyType.Wildcard:
+ break;
+ case SearchStrategyType.RegEx:
+ index = 1;
+ break;
+ }
+ specialSearchStrategyComboBox.SetHistory (index);
+
+ Gtk.Menu locMenu = new Gtk.Menu ();
+ tmpItem = new Gtk.MenuItem (resourceService.GetString("Global.Location.currentfile"));
+ locMenu.Append (tmpItem);
+ tmpItem = new Gtk.MenuItem (resourceService.GetString("Global.Location.allopenfiles"));
+ locMenu.Append (tmpItem);
+ tmpItem = new Gtk.MenuItem (resourceService.GetString("Global.Location.wholeproject"));
+ locMenu.Append (tmpItem);
+
+ searchLocationComboBox.Menu = locMenu;
+
+ index = 0;
+ switch (SearchReplaceManager.SearchOptions.DocumentIteratorType) {
+ case DocumentIteratorType.AllOpenFiles:
+ index = 1;
+ break;
+ case DocumentIteratorType.WholeCombine:
+ SearchReplaceManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
+ break;
+ }
+ searchLocationComboBox.SetHistory (index);
+
+ searchPatternComboBox.Entry.Text = SearchReplaceManager.SearchOptions.SearchPattern;
+
+ // insert event handlers
+ findButton.Clicked += new EventHandler(FindNextEvent);
+ closeButton.Clicked += new EventHandler(CloseDialogEvent);
+ ReplaceDialogPointer.Close += new EventHandler(CloseDialogEvent);
+ ReplaceDialogPointer.DeleteEvent += new DeleteEventHandler (OnDeleted);
+
+ if (replaceMode) {
+ ReplaceDialogPointer.Title = resourceService.GetString("Dialog.NewProject.SearchReplace.ReplaceDialogName");
+ replaceButton.Clicked += new EventHandler(ReplaceEvent);
+ replaceAllButton.Clicked += new EventHandler(ReplaceAllEvent);
+ replacePatternComboBox.Entry.Text = SearchReplaceManager.SearchOptions.ReplacePattern;
+ } else {
+ ReplaceDialogPointer.Title = resourceService.GetString("Dialog.NewProject.SearchReplace.FindDialogName");
+ markAllButton.Clicked += new EventHandler(MarkAllEvent);
+ }
+
+ //ControlDictionary["replacePatternComboBox"].Visible = false;
+ //ControlDictionary["replaceAllButton"].Visible = false;
+ //ControlDictionary["replacePatternLabel"].Visible = false;
+ //ControlDictionary["replacePatternButton"].Visible = false;
+ //ControlDictionary["replaceButton"].Text = resourceService.GetString("Dialog.NewProject.SearchReplace.ToggleReplaceModeButton");
+ //ClientSize = new Size(ClientSize.Width, ClientSize.Height - 32);
+
+ SpecialSearchStrategyCheckBoxChangedEvent(null, null);
+ SearchReplaceManager.ReplaceDialog = this;
+ }
+
+ protected void OnClosed()
+ {
+ SaveHistoryValues();
+
+ }
+
+ void OnDeleted (object o, DeleteEventArgs args)
+ {
+ // perform the standard closing windows event
+ OnClosed();
+ SearchReplaceManager.ReplaceDialog = null;
+ }
+
+ public void SetSearchPattern(string pattern)
+ {
+ searchPatternComboBox.Entry.Text = pattern;
+ }
+
+ void SetupSearchReplaceManager()
+ {
+ SearchReplaceManager.SearchOptions.SearchPattern = searchPatternComboBox.Entry.Text;
+ if (replaceMode) {
+ SearchReplaceManager.SearchOptions.ReplacePattern = replacePatternComboBox.Entry.Text;
+ }
+
+ SearchReplaceManager.SearchOptions.IgnoreCase = !ignoreCaseCheckBox.Active;
+ SearchReplaceManager.SearchOptions.SearchWholeWordOnly = searchWholeWordOnlyCheckBox.Active;
+
+ if (useSpecialSearchStrategyCheckBox.Active) {
+ switch (specialSearchStrategyComboBox.History) {
+ case 0:
+ SearchReplaceManager.SearchOptions.SearchStrategyType = SearchStrategyType.Wildcard;
+ break;
+ case 1:
+ SearchReplaceManager.SearchOptions.SearchStrategyType = SearchStrategyType.RegEx;
+ break;
+ }
+ } else {
+ SearchReplaceManager.SearchOptions.SearchStrategyType = SearchStrategyType.Normal;
+ }
+
+ switch (searchLocationComboBox.History) {
+ case 0:
+ SearchReplaceManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
+ break;
+ case 1:
+ SearchReplaceManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.AllOpenFiles;
+ break;
+ case 2:
+ SearchReplaceManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.WholeCombine;
+ break;
+ }
+ }
+
+ void FindNextEvent(object sender, EventArgs e)
+ {
+ if (searchPatternComboBox.Entry.Text.Length == 0) {
+ return;
+ }
+
+ try {
+ //Cursor = Cursors.WaitCursor;
+ SetupSearchReplaceManager();
+ SearchReplaceManager.FindNext();
+ //this.Focus();
+ }
+ finally {
+ //Cursor = Cursors.Default;
+ }
+
+ AddSearchHistoryItem(findHistory, searchPatternComboBox.Entry.Text);
+ }
+
+ void ReplaceEvent(object sender, EventArgs e)
+ {
+ if (searchPatternComboBox.Entry.Text.Length == 0) {
+ return;
+ }
+
+ try {
+ //Cursor = Cursors.WaitCursor;
+
+ SetupSearchReplaceManager();
+ SearchReplaceManager.Replace();
+ }
+ finally {
+ //Cursor = Cursors.Default;
+ }
+
+ AddSearchHistoryItem(replaceHistory, replacePatternComboBox.Entry.Text);
+ }
+
+ void ReplaceAllEvent(object sender, EventArgs e)
+ {
+ if (searchPatternComboBox.Entry.Text.Length == 0) {
+ return;
+ }
+
+ try {
+ //Cursor = Cursors.WaitCursor;
+
+ SetupSearchReplaceManager();
+ SearchReplaceManager.ReplaceAll();
+ } finally {
+ //Cursor = Cursors.Default;
+ }
+
+ AddSearchHistoryItem(replaceHistory, replacePatternComboBox.Entry.Text);
+ }
+
+ void MarkAllEvent(object sender, EventArgs e)
+ {
+ if (searchPatternComboBox.Entry.Text.Length == 0) {
+ return;
+ }
+
+ try {
+ //Cursor = Cursors.WaitCursor;
+
+ SetupSearchReplaceManager();
+ SearchReplaceManager.MarkAll();
+ } finally {
+ //Cursor = Cursors.Default;
+ }
+
+ AddSearchHistoryItem(findHistory, searchPatternComboBox.Entry.Text);
+ }
+
+ void CloseDialogEvent(object sender, EventArgs e)
+ {
+ ReplaceDialogPointer.Hide();
+ OnClosed ();
+ }
+
+ void SpecialSearchStrategyCheckBoxChangedEvent(object sender, EventArgs e)
+ {
+ if (useSpecialSearchStrategyCheckBox != null) {
+ specialSearchStrategyComboBox.Sensitive = useSpecialSearchStrategyCheckBox.Active;
+ }
+ }
+
+ // generic method to add a string to a history item
+ private void AddSearchHistoryItem(StringCollection history, string toAdd)
+ {
+ // add the item to the find history
+ if (history.Contains(toAdd)) {
+ // remove it so it gets added at the top
+ history.Remove(toAdd);
+ }
+ // make sure there is only 20
+ if (history.Count == HISTORY_LIMIT) {
+ history.RemoveAt(HISTORY_LIMIT - 1);
+ }
+ history.Insert(0, toAdd);
+
+ // update the drop down for the combobox
+ string[] stringArray = new string[history.Count];
+ history.CopyTo(stringArray, 0);
+ if (history == findHistory) {
+ searchPatternComboBox.PopdownStrings = stringArray;
+ } else if( history == replaceHistory) {
+ replacePatternComboBox.PopdownStrings = stringArray;
+ }
+ }
+
+ // loads the history arrays from the property service
+ // NOTE: this dialog uses a newline character to separate search history strings in the properties file
+ private void LoadHistoryValues()
+ {
+ object stringArray;
+ // set the history in properties
+ stringArray = propertyService.GetProperty("MonoDevelop.FindReplaceDialogs.FindHistory");
+
+ if(stringArray != null) {
+ findHistory.AddRange(stringArray.ToString().Split(HISTORY_SEPARATOR_CHAR));
+ searchPatternComboBox.PopdownStrings = stringArray.ToString().Split(HISTORY_SEPARATOR_CHAR);
+ }
+
+ // now do the replace history
+ if(replaceMode) {
+ stringArray = propertyService.GetProperty("MonoDevelop.FindReplaceDialogs.ReplaceHistory");
+ if(stringArray != null) {
+ replaceHistory.AddRange(stringArray.ToString().Split(HISTORY_SEPARATOR_CHAR));
+ replacePatternComboBox.PopdownStrings = stringArray.ToString().Split(HISTORY_SEPARATOR_CHAR);
+ }
+ }
+ }
+
+ // saves the history arrays to the property service
+ // NOTE: this dialog uses a newline character to separate search history strings in the properties file
+ private void SaveHistoryValues()
+ {
+ string[] stringArray;
+ // set the history in properties
+ stringArray = new string[findHistory.Count];
+ findHistory.CopyTo(stringArray, 0);
+ propertyService.SetProperty("MonoDevelop.FindReplaceDialogs.FindHistory", string.Join(HISTORY_SEPARATOR_CHAR.ToString(), stringArray));
+
+ // now do the replace history
+ if(replaceMode) {
+ stringArray = new string[replaceHistory.Count];
+ replaceHistory.CopyTo(stringArray, 0);
+ propertyService.SetProperty("MonoDevelop.FindReplaceDialogs.ReplaceHistory", string.Join(HISTORY_SEPARATOR_CHAR.ToString(), stringArray));
+ }
+ }
+
+ #region code to pretend to be a dialog (cause we can't inherit Dialog and use glade)
+ public void Present()
+ {
+ ReplaceDialogPointer.Present();
+ }
+
+ public void Destroy()
+ {
+ // save the search and replace history to properties
+ OnClosed ();
+ ReplaceDialogPointer.Destroy();
+ }
+
+ public void ShowAll()
+ {
+ ReplaceDialogPointer.ShowAll();
+ }
+ #endregion
+ }
+}
Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/Dialogs/ReplaceInFilesDialog.cs (from rev 941, trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/ReplaceInFilesDialog.cs)
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Dialogs/ReplaceInFilesDialog.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/Dialogs/ReplaceInFilesDialog.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,207 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Drawing;
+using System.ComponentModel;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.TextEditor.Document;
+using ICSharpCode.Core.Properties;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.SharpDevelop.Services;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.SharpDevelop.Gui.Dialogs
+{
+ public class ReplaceInFilesDialog //: BaseSharpDevelopForm
+ {/*
+ ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
+ IMessageService messageService = (IMessageService)ServiceManager.Services.GetService(typeof(IMessageService));
+ static PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+ bool replaceMode;
+
+ public ReplaceInFilesDialog(bool replaceMode)
+ {
+ this.replaceMode = replaceMode;
+ FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+ if (replaceMode) {
+ this.SetupFromXml(propertyService.DataDirectory + @"\resources\dialogs\ReplaceInFilesDialog.xfrm");
+ ControlDictionary["replacePatternComboBox"].Text = SearchReplaceInFilesManager.SearchOptions.ReplacePattern;
+ ControlDictionary["replaceHelpButton"].Enabled = false;
+ } else {
+ this.SetupFromXml(propertyService.DataDirectory + @"\resources\dialogs\FindInFilesDialog.xfrm");
+ }
+
+ ControlDictionary["findHelpButton"].Enabled = false;
+ ControlDictionary["searchPatternComboBox"].Text = SearchReplaceInFilesManager.SearchOptions.SearchPattern;
+
+ AcceptButton = (Button)ControlDictionary["findButton"];
+ CancelButton = (Button)ControlDictionary["closeButton"];
+
+ ((ComboBox)ControlDictionary["specialSearchStrategyComboBox"]).Items.Add(resourceService.GetString("Dialog.NewProject.SearchReplace.SearchStrategy.WildcardSearch"));
+ ((ComboBox)ControlDictionary["specialSearchStrategyComboBox"]).Items.Add(resourceService.GetString("Dialog.NewProject.SearchReplace.SearchStrategy.RegexSearch"));
+ int index = 0;
+ switch (SearchReplaceManager.SearchOptions.SearchStrategyType) {
+ case SearchStrategyType.Normal:
+ case SearchStrategyType.Wildcard:
+ break;
+ case SearchStrategyType.RegEx:
+ index = 1;
+ break;
+ }
+ ((ComboBox)ControlDictionary["specialSearchStrategyComboBox"]).SelectedIndex = index;
+
+ ((ComboBox)ControlDictionary["searchLocationComboBox"]).Items.Add(resourceService.GetString("Global.Location.directories"));
+ ((ComboBox)ControlDictionary["searchLocationComboBox"]).Items.Add(resourceService.GetString("Global.Location.allopenfiles"));
+ ((ComboBox)ControlDictionary["searchLocationComboBox"]).Items.Add(resourceService.GetString("Global.Location.wholeproject"));
+
+ index = 0;
+ switch (SearchReplaceInFilesManager.SearchOptions.DocumentIteratorType) {
+ case DocumentIteratorType.AllOpenFiles:
+ index = 1;
+ break;
+ case DocumentIteratorType.WholeCombine:
+ index = 2;
+ break;
+ }
+
+ ((ComboBox)ControlDictionary["searchLocationComboBox"]).SelectedIndex = index;
+ ((ComboBox)ControlDictionary["searchLocationComboBox"]).SelectedIndexChanged += new EventHandler(SearchLocationCheckBoxChangedEvent);
+
+ ((CheckBox)ControlDictionary["useSpecialSearchStrategyCheckBox"]).CheckedChanged += new EventHandler(SpecialSearchStrategyCheckBoxChangedEvent);
+
+ ControlDictionary["directoryTextBox"].Text = SearchReplaceInFilesManager.SearchOptions.SearchDirectory;
+ ControlDictionary["fileMaskTextBox"].Text = SearchReplaceInFilesManager.SearchOptions.FileMask;
+ ((CheckBox)ControlDictionary["includeSubdirectoriesCheckBox"]).Checked = SearchReplaceInFilesManager.SearchOptions.SearchSubdirectories;
+
+ ControlDictionary["browseButton"].Click += new EventHandler(BrowseDirectoryEvent);
+
+ ControlDictionary["findButton"].Click += new EventHandler(FindEvent);
+
+ if (replaceMode) {
+ ControlDictionary["replaceAllButton"].Click += new EventHandler(ReplaceEvent);
+ }
+
+
+ SearchLocationCheckBoxChangedEvent(null, null);
+ SpecialSearchStrategyCheckBoxChangedEvent(null, null);
+ }
+
+ void FindEvent(object sender, EventArgs e)
+ {
+ if (SetupSearchReplaceInFilesManager()) {
+ SearchReplaceInFilesManager.FindAll();
+ }
+ }
+
+ void ReplaceEvent(object sender, EventArgs e)
+ {
+ if (SetupSearchReplaceInFilesManager()) {
+ SearchReplaceInFilesManager.ReplaceAll();
+ }
+ }
+
+ void BrowseDirectoryEvent(object sender, EventArgs e)
+ {
+ FolderDialog fd = new FolderDialog();
+ if (fd.DisplayDialog(resourceService.GetString("NewProject.SearchReplace.FindInFilesBrowseLabel")) == DialogResult.OK) {
+ ControlDictionary["directoryTextBox"].Text = fd.Path;
+ }
+ }
+
+ void SearchLocationCheckBoxChangedEvent(object sender, EventArgs e)
+ {
+ bool enableDirectorySearch = ((ComboBox)ControlDictionary["searchLocationComboBox"]).SelectedIndex == 0;
+ ControlDictionary["fileMaskTextBox"].Enabled = enableDirectorySearch;
+ ControlDictionary["directoryTextBox"].Enabled = enableDirectorySearch;
+ ControlDictionary["browseButton"].Enabled = enableDirectorySearch;
+ ControlDictionary["includeSubdirectoriesCheckBox"].Enabled = enableDirectorySearch;
+ }
+
+ void SpecialSearchStrategyCheckBoxChangedEvent(object sender, EventArgs e)
+ {
+ CheckBox cb = (CheckBox)ControlDictionary["useSpecialSearchStrategyCheckBox"];
+ if (cb != null) {
+ ControlDictionary["specialSearchStrategyComboBox"].Enabled = cb.Checked;
+ }
+ }
+
+ bool SetupSearchReplaceInFilesManager()
+ {
+ FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+
+ string directoryName = ControlDictionary["directoryTextBox"].Text;
+ string fileMask = ControlDictionary["fileMaskTextBox"].Text;
+ if (fileMask == null || fileMask.Length == 0) {
+ fileMask = "*";
+ }
+
+ if (SearchReplaceInFilesManager.SearchOptions.DocumentIteratorType == DocumentIteratorType.Directory) {
+
+ if (!fileUtilityService.IsValidFileName(directoryName)) {
+ messageService.ShowErrorFormatted("${res:NewProject.SearchReplace.FindInFilesInvalidDirectoryMessage}", directoryName);
+ return false;
+ }
+
+ if (!Directory.Exists(directoryName)) {
+ messageService.ShowErrorFormatted("${res:NewProject.SearchReplace.FindInFilesDirectoryNotExistingMessage}", directoryName);
+ return false;
+ }
+
+ if (!fileUtilityService.IsValidFileName(fileMask) || fileMask.IndexOf('\\') >= 0) {
+ messageService.ShowErrorFormatted("${res:NewProject.SearchReplace.FindInFilesInvalidFilemaskMessage}", fileMask);
+ return false;
+ }
+ }
+ if (fileMask == null || fileMask.Length == 0) {
+ SearchReplaceInFilesManager.SearchOptions.FileMask = "*";
+ } else {
+ SearchReplaceInFilesManager.SearchOptions.FileMask = fileMask;
+ }
+ SearchReplaceInFilesManager.SearchOptions.SearchDirectory = directoryName;
+ SearchReplaceInFilesManager.SearchOptions.SearchSubdirectories = ((CheckBox)ControlDictionary["includeSubdirectoriesCheckBox"]).Checked;
+
+ SearchReplaceInFilesManager.SearchOptions.SearchPattern = ControlDictionary["searchPatternComboBox"].Text;
+ if (replaceMode) {
+ SearchReplaceInFilesManager.SearchOptions.ReplacePattern = ControlDictionary["replacePatternComboBox"].Text;
+ }
+
+ SearchReplaceInFilesManager.SearchOptions.IgnoreCase = !((CheckBox)ControlDictionary["ignoreCaseCheckBox"]).Checked;
+ SearchReplaceInFilesManager.SearchOptions.SearchWholeWordOnly = ((CheckBox)ControlDictionary["searchWholeWordOnlyCheckBox"]).Checked;
+
+ if (((CheckBox)ControlDictionary["useSpecialSearchStrategyCheckBox"]).Checked) {
+ switch (((ComboBox)ControlDictionary["specialSearchStrategyComboBox"]).SelectedIndex) {
+ case 0:
+ SearchReplaceInFilesManager.SearchOptions.SearchStrategyType = SearchStrategyType.Wildcard;
+ break;
+ case 1:
+ SearchReplaceInFilesManager.SearchOptions.SearchStrategyType = SearchStrategyType.RegEx;
+ break;
+ }
+ } else {
+ SearchReplaceInFilesManager.SearchOptions.SearchStrategyType = SearchStrategyType.Normal;
+ }
+
+ switch (((ComboBox)ControlDictionary["searchLocationComboBox"]).SelectedIndex) {
+ case 0:
+ SearchReplaceInFilesManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.Directory;
+ break;
+ case 1:
+ SearchReplaceInFilesManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.AllOpenFiles;
+ break;
+ case 2:
+ SearchReplaceInFilesManager.SearchOptions.DocumentIteratorType = DocumentIteratorType.WholeCombine;
+ break;
+ }
+ return true;
+ }
+ */
+ }
+}
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -125,7 +125,6 @@
}
break;
case '[':
- break;
try {
InsightWindow insightWindow = new InsightWindow(this, ParentEditor.DisplayBinding.ContentName);
Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile.am 2004-02-19 03:42:53 UTC (rev 942)
@@ -20,6 +20,8 @@
./Gui/OptionPanels/GeneralTextEditorPanel.cs \
./Gui/EditTemplateGroupDialog.cs \
./Gui/Dialogs/GotoLineNumberDialog.cs \
+./Gui/Dialogs/ReplaceDialog.cs \
+./Gui/Dialogs/ReplaceInFilesDialog.cs \
./InsightWindow/IndexerInsightDataProvider.cs \
./InsightWindow/MethodInsightDataProvider.cs \
./InsightWindow/InsightWindow.cs \
@@ -39,7 +41,32 @@
./FormattingStrategy/IndentStyle.cs \
./FormattingStrategy/IFormattingStrategy.cs \
./FormattingStrategy/IFormattableDocument.cs \
-./Codons/EditActionCodon.cs
+./Codons/EditActionCodon.cs \
+./Search/DocumentIterator/ProvidedDocumentInformation.cs \
+./Search/DocumentIterator/DirectoryDocumentIterator.cs \
+./Search/DocumentIterator/AllOpenDocumentIterator.cs \
+./Search/DocumentIterator/IDocumentIterator.cs \
+./Search/DocumentIterator/ReverseDocumentIterator.cs \
+./Search/DocumentIterator/WholeProjectDocumentIterator.cs \
+./Search/DocumentIterator/CurrentDocumentIterator.cs \
+./Search/SearchStrategy/KMPSearchStrategy.cs \
+./Search/SearchStrategy/ISearchStrategy.cs \
+./Search/SearchStrategy/BruteForceSearchStrategy.cs \
+./Search/SearchStrategy/RegExSearchStrategy.cs \
+./Search/SearchStrategy/WildcardSearchStrategy.cs \
+./Search/SearchReplaceManager.cs \
+./Search/DefaultFind.cs \
+./Search/SearchResult/DefaultSearchResult.cs \
+./Search/SearchResult/ISearchResult.cs \
+./Search/SearchOptions.cs \
+./Search/SearchReplaceInFilesManager.cs \
+./Search/SearchReplaceUtilities.cs \
+./Search/IFind.cs \
+./Search/TextIterator/ITextIterator.cs \
+./Search/TextIterator/ITextIteratorBuilder.cs \
+./Search/TextIterator/ForwardTextIteratorBuilder.cs \
+./Search/TextIterator/ForwardTextIterator.cs \
+./Search/ITextBufferStrategy.cs
all : $(DLL)
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DefaultFind.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DefaultFind.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DefaultFind.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,124 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+using ICSharpCode.SharpDevelop.Gui;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class DefaultFind : IFind
+ {
+ ISearchStrategy searchStrategy = null;
+ IDocumentIterator documentIterator = null;
+ ITextIterator textIterator = null;
+ ITextIteratorBuilder textIteratorBuilder = null;
+ ProvidedDocumentInformation info = null;
+
+ public ProvidedDocumentInformation CurrentDocumentInformation {
+ get {
+ return info;
+ }
+ }
+
+ public ITextIteratorBuilder TextIteratorBuilder {
+ get {
+ return textIteratorBuilder;
+ }
+ set {
+ textIteratorBuilder = value;
+ }
+ }
+
+ public ITextIterator TextIterator {
+ get {
+ return textIterator;
+ }
+ }
+
+ public ISearchStrategy SearchStrategy {
+ get {
+ return searchStrategy;
+ }
+ set {
+ searchStrategy = value;
+ }
+ }
+
+ public IDocumentIterator DocumentIterator {
+ get {
+ return documentIterator;
+ }
+ set {
+ documentIterator = value;
+ }
+ }
+
+ ISearchResult CreateNamedSearchResult(ISearchResult pos)
+ {
+ if (info == null || pos == null) {
+ return null;
+ }
+ pos.ProvidedDocumentInformation = info;
+ return pos;
+ }
+
+ public void Reset()
+ {
+ documentIterator.Reset();
+ textIterator = null;
+ }
+
+ public void Replace(int offset, int length, string pattern)
+ {
+ if (CurrentDocumentInformation != null && TextIterator != null) {
+ CurrentDocumentInformation.Replace(offset, length, pattern);
+ CurrentDocumentInformation.SaveBuffer();
+ TextIterator.InformReplace(offset, length, pattern.Length);
+ }
+ }
+
+ public ISearchResult FindNext(SearchOptions options)
+ {
+ // insanity check
+ Debug.Assert(searchStrategy != null);
+ Debug.Assert(documentIterator != null);
+ Debug.Assert(textIteratorBuilder != null);
+ Debug.Assert(options != null);
+
+ if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
+ if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed
+ info = documentIterator.Current;
+ textIterator = textIteratorBuilder.BuildTextIterator(info);
+ } else { // old document -> initialize iterator position to caret pos
+ textIterator.Position = info.CurrentOffset;
+ }
+
+ ISearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, options));
+ if (result != null) {
+ info.CurrentOffset = textIterator.Position;
+ return result;
+ }
+ }
+
+ // not found or first start -> move forward to the next document
+ if (documentIterator.MoveForward()) {
+ info = documentIterator.Current;
+ // document is valid for searching -> set iterator & fileName
+ if (info != null && info.TextBuffer != null && info.EndOffset >= 0 && info.EndOffset < info.TextBuffer.Length) {
+ textIterator = textIteratorBuilder.BuildTextIterator(info);
+ } else {
+ textIterator = null;
+ }
+
+ return FindNext(options);
+ }
+ return null;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/AllOpenDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/AllOpenDocumentIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/AllOpenDocumentIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,111 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class AllOpenDocumentIterator : IDocumentIterator
+ {
+ int startIndex = -1;
+ bool resetted = true;
+
+ public AllOpenDocumentIterator()
+ {
+ Reset();
+ }
+
+ public string CurrentFileName {
+ get {
+ if (!SearchReplaceUtilities.IsTextAreaSelected) {
+ return null;
+ }
+
+ if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.ContentName == null) {
+ return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.UntitledName;
+ }
+
+ return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.ContentName;
+ }
+ }
+
+ public ProvidedDocumentInformation Current {
+ get {
+ if (!SearchReplaceUtilities.IsTextAreaSelected) {
+ return null;
+ }
+ //IDocument document = (((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl).Document;
+ //return new ProvidedDocumentInformation(document,
+ // CurrentFileName);
+ return null;
+ }
+ }
+
+ int GetCurIndex()
+ {
+ for (int i = 0; i < WorkbenchSingleton.Workbench.ViewContentCollection.Count; ++i) {
+ if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent == WorkbenchSingleton.Workbench.ViewContentCollection[i]) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public bool MoveForward()
+ {
+ int curIndex = GetCurIndex();
+ if (curIndex < 0) {
+ return false;
+ }
+
+ if (resetted) {
+ resetted = false;
+ return true;
+ }
+
+ int nextIndex = (curIndex + 1) % WorkbenchSingleton.Workbench.ViewContentCollection.Count;
+ if (nextIndex == startIndex) {
+ return false;
+ }
+ WorkbenchSingleton.Workbench.ViewContentCollection[nextIndex].WorkbenchWindow.SelectWindow();
+ return true;
+ }
+
+ public bool MoveBackward()
+ {
+ int curIndex = GetCurIndex();
+ if (curIndex < 0) {
+ return false;
+ }
+ if (resetted) {
+ resetted = false;
+ return true;
+ }
+
+ if (curIndex == 0) {
+ curIndex = WorkbenchSingleton.Workbench.ViewContentCollection.Count - 1;
+ }
+
+ if (curIndex > 0) {
+ --curIndex;
+ WorkbenchSingleton.Workbench.ViewContentCollection[curIndex].WorkbenchWindow.SelectWindow();
+ return true;
+ }
+ return false;
+ }
+
+ public void Reset()
+ {
+ startIndex = GetCurIndex();
+ resetted = true;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/CurrentDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/CurrentDocumentIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/CurrentDocumentIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,73 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class CurrentDocumentIterator : IDocumentIterator
+ {
+ bool didRead = false;
+ //IDocument curDocument = null;
+
+ public CurrentDocumentIterator()
+ {
+ Reset();
+ }
+
+ public string CurrentFileName {
+ get {
+ if (!SearchReplaceUtilities.IsTextAreaSelected) {
+ return null;
+ }
+ if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.ContentName == null) {
+ return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.UntitledName;
+ }
+ return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent.ContentName;
+ }
+ }
+
+ public ProvidedDocumentInformation Current {
+ get {
+ if (!SearchReplaceUtilities.IsTextAreaSelected) {
+ return null;
+ }
+ //curDocument = (((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl).Document;
+ //return new ProvidedDocumentInformation(curDocument,
+ // CurrentFileName);
+ return null;
+ }
+ }
+
+ public bool MoveForward()
+ {
+ if (!SearchReplaceUtilities.IsTextAreaSelected) {
+ return false;
+ }
+ if (didRead) {
+ return false;
+ }
+ didRead = true;
+
+ return true;
+ }
+
+ public bool MoveBackward()
+ {
+ return MoveForward();
+ }
+
+ public void Reset()
+ {
+ didRead = false;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/DirectoryDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/DirectoryDocumentIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/DirectoryDocumentIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,109 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.IO;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.SharpDevelop.Internal.Project;
+using ICSharpCode.Core.Services;
+using ICSharpCode.SharpDevelop.Services;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class DirectoryDocumentIterator : IDocumentIterator
+ {
+ string searchDirectory;
+ string fileMask;
+ bool searchSubdirectories;
+
+ StringCollection files = null;
+ int curIndex = -1;
+
+ public DirectoryDocumentIterator(string searchDirectory, string fileMask, bool searchSubdirectories)
+ {
+ this.searchDirectory = searchDirectory;
+ this.fileMask = fileMask;
+ this.searchSubdirectories = searchSubdirectories;
+
+ Reset();
+ }
+
+ public string CurrentFileName {
+ get {
+ if (curIndex < 0 || curIndex >= files.Count) {
+ return null;
+ }
+
+ return files[curIndex].ToString();;
+ }
+ }
+
+ public ProvidedDocumentInformation Current {
+ get {
+ /*if (curIndex < 0 || curIndex >= files.Count) {
+ return null;
+ }
+ if (!File.Exists(files[curIndex].ToString())) {
+ ++curIndex;
+ return Current;
+ }
+ IDocument document;
+ string fileName = files[curIndex].ToString();
+ foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
+ // WINDOWS DEPENDENCY : ToUpper
+ if (content.ContentName != null &&
+ content.ContentName.ToUpper() == fileName.ToUpper()) {
+ document = ((ITextEditorControlProvider)content).TextEditorControl.Document;
+ return new ProvidedDocumentInformation(document,
+ fileName);
+ }
+ }
+ ITextBufferStrategy strategy = null;
+ try {
+ strategy = StringTextBufferStrategy.CreateTextBufferFromFile(fileName);
+ } catch (Exception) {
+ TaskService taskService = (TaskService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(TaskService));
+ taskService.Tasks.Add(new Task(String.Empty, "can't access " + fileName, -1, -1));
+ return null;
+ }
+ return new ProvidedDocumentInformation(strategy,
+ fileName,
+ 0);
+ */
+ return null;
+ }
+ }
+
+ public bool MoveForward()
+ {
+ if (curIndex == -1) {
+ FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+ files = fileUtilityService.SearchDirectory(this.searchDirectory, this.fileMask, this.searchSubdirectories);
+ }
+ return ++curIndex < files.Count;
+ }
+
+ public bool MoveBackward()
+ {
+ if (curIndex == -1) {
+ curIndex = files.Count - 1;
+ return true;
+ }
+ return --curIndex >= -1;
+ }
+
+
+ public void Reset()
+ {
+ curIndex = -1;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/IDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/IDocumentIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/IDocumentIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,54 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Represents a bi-directional iterator which could move froward/backward
+ /// in a document queue. Note that after move forward is called
+ /// move backward needn't to function correctly either move forward or move
+ /// backward is called but they're not mixed. After a reset the move operation
+ /// can be switched.
+ /// </summary>
+ public interface IDocumentIterator
+ {
+ /// <value>
+ /// Returns the current ProvidedDocumentInformation. This method
+ /// usually creates a new ProvidedDocumentInformation object which can
+ /// be time consuming
+ /// </value>
+ ProvidedDocumentInformation Current {
+ get;
+ }
+
+ /// <value>
+ /// Returns the file name of the current provided document information. This
+ /// property usually is not time consuming
+ /// </value>
+ string CurrentFileName {
+ get;
+ }
+
+ /// <remarks>
+ /// Moves the iterator one document forward.
+ /// </remarks>
+ bool MoveForward();
+
+ /// <remarks>
+ /// Moves the iterator one document backward.
+ /// </remarks>
+ bool MoveBackward();
+
+ /// <remarks>
+ /// Resets the iterator to the start position.
+ /// </remarks>
+ void Reset();
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,110 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Collections;
+
+using ICSharpCode.SharpDevelop.Gui;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class ProvidedDocumentInformation
+ {
+ //IDocument document;
+ ITextBufferStrategy textBuffer;
+ string fileName;
+ int currentOffset;
+
+ public ITextBufferStrategy TextBuffer {
+ get {
+ return textBuffer;
+ }
+ set {
+ textBuffer = value;
+ }
+ }
+
+ public string FileName {
+ get {
+ return fileName;
+ }
+ }
+
+ public int CurrentOffset {
+ get {
+// if (document != null) {
+// return document.Caret.Offset;
+// }
+ return currentOffset;
+ }
+ set {
+// if (document != null) {
+// document.Caret.Offset = value;
+// } else {
+ currentOffset = value;
+// }
+ }
+ }
+
+ public int EndOffset {
+ get {
+ //if (document != null) {
+ // return SearchReplaceUtilities.CalcCurrentOffset(document);
+ //}
+ return currentOffset;
+ }
+ }
+
+ public void Replace(int offset, int length, string pattern)
+ {
+ //if (document != null) {
+ // document.Replace(offset, length, pattern);
+ //} else {
+ // textBuffer.Replace(offset, length, pattern);
+ //}
+
+ if (offset <= CurrentOffset) {
+ CurrentOffset = CurrentOffset - length + pattern.Length;
+ }
+ }
+
+ public void SaveBuffer()
+ {
+ //if (document != null) {
+
+ //} else {
+ StreamWriter streamWriter = File.CreateText(this.fileName);
+ streamWriter.Write(textBuffer.GetText(0, textBuffer.Length));
+ streamWriter.Close();
+ //}
+ }
+
+ /*public IDocument CreateDocument()
+ {
+ if (document != null) {
+ return document;
+ }
+ return new DocumentFactory().CreateFromFile(fileName);
+ }*/
+
+ /*public ProvidedDocumentInformation(IDocument document, string fileName)
+ {
+ this.document = document;
+ this.textBuffer = document.TextBufferStrategy;
+ this.fileName = fileName;
+// this.currentOffset = document.Caret.Offset;
+ }*/
+
+ public ProvidedDocumentInformation(ITextBufferStrategy textBuffer, string fileName, int currentOffset)
+ {
+ this.textBuffer = textBuffer;
+ this.fileName = fileName;
+ this.currentOffset = currentOffset;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ReverseDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ReverseDocumentIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ReverseDocumentIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,53 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Represents a bi-directional iterator which could move froward/backward
+ /// in a document queue.
+ /// </summary>
+ public class ReverseDocumentIterator : IDocumentIterator
+ {
+ IDocumentIterator documentIterator;
+
+ public string CurrentFileName {
+ get {
+ return documentIterator.CurrentFileName;
+ }
+ }
+
+ public ProvidedDocumentInformation Current {
+ get {
+ return documentIterator.Current;
+ }
+ }
+
+ public ReverseDocumentIterator(IDocumentIterator documentIterator)
+ {
+ this.documentIterator = documentIterator;
+ }
+
+ public bool MoveForward()
+ {
+ return documentIterator.MoveBackward();
+ }
+
+ public bool MoveBackward()
+ {
+ return documentIterator.MoveBackward();
+ }
+
+ public void Reset()
+ {
+ documentIterator.Reset();
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/WholeProjectDocumentIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/WholeProjectDocumentIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/WholeProjectDocumentIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,121 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.IO;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.SharpDevelop.Internal.Project;
+using ICSharpCode.Core.Services;
+using ICSharpCode.SharpDevelop.Services;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class WholeProjectDocumentIterator : IDocumentIterator
+ {
+ ArrayList files = new ArrayList();
+ int curIndex = -1;
+
+ public WholeProjectDocumentIterator()
+ {
+ Reset();
+ }
+
+ public string CurrentFileName {
+ get {
+ if (curIndex < 0 || curIndex >= files.Count) {
+ return null;
+ }
+
+ return files[curIndex].ToString();;
+ }
+ }
+
+ public ProvidedDocumentInformation Current {
+ get {
+ if (curIndex < 0 || curIndex >= files.Count) {
+ return null;
+ }
+ if (!File.Exists(files[curIndex].ToString())) {
+ ++curIndex;
+ return Current;
+ }
+ //IDocument document;
+ string fileName = files[curIndex].ToString();
+ /*foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
+ // WINDOWS DEPENDENCY : ToUpper
+ if (content.ContentName != null &&
+ content.ContentName.ToUpper() == fileName.ToUpper()) {
+ document = (((ITextEditorControlProvider)content).TextEditorControl).Document;
+ return new ProvidedDocumentInformation(document,
+ fileName);
+ }
+ }*/
+ ITextBufferStrategy strategy = null;
+ try {
+ //strategy = StringTextBufferStrategy.CreateTextBufferFromFile(fileName);
+ } catch (Exception) {
+ TaskService taskService = (TaskService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(TaskService));
+ taskService.Tasks.Add(new Task(String.Empty, "can't access " + fileName, -1, -1));
+ return null;
+ }
+ return new ProvidedDocumentInformation(strategy,
+ fileName,
+ 0);
+ }
+ }
+
+ public bool MoveForward()
+ {
+ return ++curIndex < files.Count;
+ }
+
+ public bool MoveBackward()
+ {
+ if (curIndex == -1) {
+ curIndex = files.Count - 1;
+ return true;
+ }
+ return --curIndex >= -1;
+ }
+
+
+ void AddFiles(IProject project)
+ {
+ foreach (ProjectFile file in project.ProjectFiles) {
+ if (file.BuildAction == BuildAction.Compile &&
+ file.Subtype == Subtype.Code) {
+ files.Add(file.Name);
+ }
+ }
+ }
+
+ void AddFiles(Combine combine)
+ {
+ foreach (CombineEntry entry in combine.Entries) {
+ if (entry is ProjectCombineEntry) {
+ AddFiles(((ProjectCombineEntry)entry).Project);
+ } else {
+ AddFiles(((CombineCombineEntry)entry).Combine);
+ }
+ }
+ }
+
+ public void Reset()
+ {
+ files.Clear();
+ IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
+ if (projectService.CurrentOpenCombine != null) {
+ AddFiles(projectService.CurrentOpenCombine);
+ }
+
+ curIndex = -1;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/IFind.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/IFind.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/IFind.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,75 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+using ICSharpCode.SharpDevelop.Gui;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// The basic interface for search operations in a document.
+ /// </summary>
+ public interface IFind
+ {
+ /// <value>
+ /// An object that implements a search algorithm.
+ /// </value>
+ ISearchStrategy SearchStrategy {
+ get;
+ set;
+ }
+
+ /// <value>
+ /// Gets the current document information
+ /// </value>
+ ProvidedDocumentInformation CurrentDocumentInformation {
+ get;
+ }
+
+ /// <value>
+ /// An object that provides a document loading approach.
+ /// </value>
+ IDocumentIterator DocumentIterator {
+ get;
+ set;
+ }
+
+ /// <value>
+ /// The text iterator builder which builds ITextIterator objects
+ /// for the find.
+ /// </value>
+ ITextIteratorBuilder TextIteratorBuilder {
+ get;
+ set;
+ }
+
+ /// <remarks>
+ /// Does a replace in the current document information. This
+ /// is the only method which should be used for doing replacements
+ /// in a searched document.
+ /// </remarks>
+ void Replace(int offset, int length, string pattern);
+
+ /// <remarks>
+ /// Finds next pattern.
+ /// <remarks>
+ /// <returns>
+ /// null if the pattern wasn't found. If it returns null the current document
+ /// information will be null too otherwise it will point to the document in which
+ /// the search pattern was found.
+ /// </returns>
+ ISearchResult FindNext(SearchOptions options);
+
+ /// <remarks>
+ /// Resets the find object to the original state.
+ /// </remarks>
+ void Reset();
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/ITextBufferStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/ITextBufferStrategy.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/ITextBufferStrategy.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,85 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Interface to describe a sequence of characters that can be edited.
+ /// </summary>
+ public interface ITextBufferStrategy
+ {
+ /// <value>
+ /// The current length of the sequence of characters that can be edited.
+ /// </value>
+ int Length {
+ get;
+ }
+
+ /// <summary>
+ /// Inserts a string of characters into the sequence.
+ /// </summary>
+ /// <param name="offset">
+ /// offset where to insert the string.
+ /// </param>
+ /// <param name="text">
+ /// text to be inserted.
+ /// </param>
+ void Insert(int offset, string text);
+
+ /// <summary>
+ /// Removes some portion of the sequence.
+ /// </summary>
+ /// <param name="offset">
+ /// offset of the remove.
+ /// </param>
+ /// <param name="length">
+ /// number of characters to remove.
+ /// </param>
+ void Remove(int offset, int length);
+
+ /// <summary>
+ /// Replace some portion of the sequence.
+ /// </summary>
+ /// <param name="offset">
+ /// offset.
+ /// </param>
+ /// <param name="length">
+ /// number of characters to replace.
+ /// </param>
+ /// <param name="text">
+ /// text to be replaced with.
+ /// </param>
+ void Replace(int offset, int length, string text);
+
+ /// <summary>
+ /// Fetches a string of characters contained in the sequence.
+ /// </summary>
+ /// <param name="offset">
+ /// Offset into the sequence to fetch
+ /// </param>
+ /// <param name="length">
+ /// number of characters to copy.
+ /// </param>
+ string GetText(int offset, int length);
+
+ /// <summary>
+ /// Returns a specific char of the sequence.
+ /// </summary>
+ /// <param name="offset">
+ /// Offset of the char to get.
+ /// </param>
+ char GetCharAt(int offset);
+
+ /// <summary>
+ /// This method sets the stored content.
+ /// </summary>
+ /// <param name="text">
+ /// The string that represents the character sequence.
+ /// </param>
+ void SetContent(string text);
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchOptions.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchOptions.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchOptions.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,141 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Drawing;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class SearchOptions
+ {
+ static PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+ IProperties properties;
+
+ public bool IgnoreCase {
+ get {
+ return properties.GetProperty("IgnoreCase", false);
+ }
+ set {
+ properties.SetProperty("IgnoreCase", value);
+ }
+ }
+
+ public bool SearchWholeWordOnly {
+ get {
+ return properties.GetProperty("SearchWholeWordOnly", false);
+ }
+
+ set {
+ properties.SetProperty("SearchWholeWordOnly", value);
+ }
+ }
+
+ public string SearchPattern {
+ get {
+ return properties.GetProperty("SearchPattern", String.Empty);
+ }
+ set {
+ properties.SetProperty("SearchPattern", value);
+ }
+ }
+
+ public string ReplacePattern {
+ get {
+ return properties.GetProperty("ReplacePattern", String.Empty);
+ }
+ set {
+ properties.SetProperty("ReplacePattern", value);
+ }
+ }
+
+ public DocumentIteratorType DocumentIteratorType {
+ get {
+ return (DocumentIteratorType)propertyService.GetProperty("DocumentIteratorType", DocumentIteratorType.CurrentDocument);
+ }
+ set {
+ if (DocumentIteratorType != value) {
+ propertyService.SetProperty("DocumentIteratorType", value);
+ OnDocumentIteratorTypeChanged(EventArgs.Empty);
+ }
+ }
+ }
+
+ public SearchStrategyType SearchStrategyType {
+ get {
+ return (SearchStrategyType)propertyService.GetProperty("SearchStrategyType", SearchStrategyType.Normal);
+ }
+ set {
+ if (SearchStrategyType != value) {
+ propertyService.SetProperty("SearchStrategyType", value);
+ OnSearchStrategyTypeChanged(EventArgs.Empty);
+ }
+ }
+ }
+
+ public string FileMask {
+ get {
+ return propertyService.GetProperty("FileMask", String.Empty);
+ }
+ set {
+ propertyService.SetProperty("FileMask", value);
+ }
+ }
+
+ public string SearchDirectory {
+ get {
+ return propertyService.GetProperty("SearchDirectory", String.Empty);
+ }
+ set {
+ propertyService.SetProperty("SearchDirectory", value);
+ }
+ }
+
+ public bool SearchSubdirectories {
+ get {
+ return propertyService.GetProperty("SearchSubdirectories", true);
+ }
+ set {
+ propertyService.SetProperty("SearchSubdirectories", value);
+ }
+ }
+
+ /// <remarks>
+ /// For unit testing purposes
+ /// </remarks>
+ public SearchOptions(IProperties properties)
+ {
+ this.properties = properties;
+ }
+
+ public SearchOptions(string propertyName)
+ {
+ properties = (IProperties)propertyService.GetProperty(propertyName, new DefaultProperties());
+ }
+
+ protected void OnDocumentIteratorTypeChanged(EventArgs e)
+ {
+ if (DocumentIteratorTypeChanged != null) {
+ DocumentIteratorTypeChanged(this, e);
+ }
+ }
+
+ protected void OnSearchStrategyTypeChanged(EventArgs e)
+ {
+ if (SearchStrategyTypeChanged != null) {
+ SearchStrategyTypeChanged(this, e);
+ }
+ }
+
+ public event EventHandler DocumentIteratorTypeChanged;
+ public event EventHandler SearchStrategyTypeChanged;
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceInFilesManager.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceInFilesManager.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceInFilesManager.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,143 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+using ICSharpCode.SharpDevelop.Gui;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.SharpDevelop.Services;
+using ICSharpCode.SharpDevelop.Gui.Dialogs;
+using ICSharpCode.SharpDevelop.Gui.Pads;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class SearchReplaceInFilesManager
+ {
+ static IFind find = new DefaultFind();
+ static SearchOptions searchOptions = new SearchOptions("SharpDevelop.SearchAndReplace.SearchAndReplaceInFilesProperties");
+
+ static PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+
+ static string currentFileName = String.Empty;
+ //static IDocument currentDocument = null;
+
+ public static SearchOptions SearchOptions {
+ get {
+ return searchOptions;
+ }
+ }
+
+ static SearchReplaceInFilesManager()
+ {
+ find.TextIteratorBuilder = new ForwardTextIteratorBuilder();
+ searchOptions.SearchStrategyTypeChanged += new EventHandler(InitializeSearchStrategy);
+ searchOptions.DocumentIteratorTypeChanged += new EventHandler(InitializeDocumentIterator);
+ InitializeDocumentIterator(null, null);
+ InitializeSearchStrategy(null, null);
+ }
+
+ static void InitializeSearchStrategy(object sender, EventArgs e)
+ {
+ find.SearchStrategy = SearchReplaceUtilities.CreateSearchStrategy(SearchOptions.SearchStrategyType);
+ }
+
+ static void InitializeDocumentIterator(object sender, EventArgs e)
+ {
+ find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType);
+ }
+
+ /// <remarks>
+ /// This method displays the search result in the task view
+ /// </remarks>
+ static void DisplaySearchResult(ISearchResult result)
+ {
+ TaskService taskService = (TaskService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(TaskService));
+
+ // check if the current document is up to date
+ if (currentFileName != result.FileName) {
+ // if not, create new document
+ currentFileName = result.FileName;
+ //currentDocument = result.CreateDocument();
+ }
+
+ // get line out of the document and display it in the task list
+ //int lineNumber = currentDocument.GetLineNumberForOffset(Math.Min(currentDocument.TextLength, result.Offset));
+ //LineSegment line = currentDocument.GetLineSegment(lineNumber);
+ //taskService.Tasks.Add(new Task(result.FileName, currentDocument.GetText(line.Offset, line.Length), result.Offset - line.Offset, lineNumber));
+ }
+
+ static bool InitializeSearchInFiles()
+ {
+ Debug.Assert(searchOptions != null);
+
+ TaskService taskService = (TaskService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(TaskService));
+ taskService.Tasks.Clear();
+
+ InitializeDocumentIterator(null, null);
+ InitializeSearchStrategy(null, null);
+ find.Reset();
+ find.SearchStrategy.CompilePattern(searchOptions);
+
+ currentFileName = String.Empty;
+ //currentDocument = null;
+
+ return true;
+ }
+
+ static void FinishSearchInFiles()
+ {
+ TaskService taskService = (TaskService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(TaskService));
+ taskService.NotifyTaskChange();
+
+ OpenTaskView taskView = WorkbenchSingleton.Workbench.GetPad(typeof(OpenTaskView)) as OpenTaskView;
+ if (taskView != null) taskView.BringToFront();
+ }
+
+ public static void ReplaceAll()
+ {
+ if (!InitializeSearchInFiles()) {
+ return;
+ }
+
+ while (true) {
+ ISearchResult result = find.FindNext(searchOptions);
+ if (result == null) {
+ break;
+ }
+
+ find.Replace(result.Offset,
+ result.Length,
+ result.TransformReplacePattern(SearchOptions.ReplacePattern));
+
+ DisplaySearchResult(result);
+ }
+
+ FinishSearchInFiles();
+ }
+
+ public static void FindAll()
+ {
+ if (!InitializeSearchInFiles()) {
+ return;
+ }
+
+ while (true) {
+ ISearchResult result = find.FindNext(searchOptions);
+ if (result == null) {
+ break;
+ }
+
+ DisplaySearchResult(result);
+ }
+
+ FinishSearchInFiles();
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,200 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+using ICSharpCode.SharpDevelop.Gui;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.SharpDevelop.Services;
+using ICSharpCode.SharpDevelop.Gui.Dialogs;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public enum DocumentIteratorType {
+ None,
+ CurrentDocument,
+ AllOpenFiles,
+ WholeCombine,
+ Directory // only used for search in files
+ }
+
+ public enum SearchStrategyType {
+ None,
+ Normal,
+ RegEx,
+ Wildcard
+ }
+
+ public class SearchReplaceManager
+ {
+ public static ReplaceDialog ReplaceDialog = null;
+
+ static IFind find = new DefaultFind();
+ static SearchOptions searchOptions = new SearchOptions("SharpDevelop.SearchAndReplace.SearchAndReplaceProperties");
+
+
+ public static SearchOptions SearchOptions {
+ get {
+ return searchOptions;
+ }
+ }
+
+ static SearchReplaceManager()
+ {
+ find.TextIteratorBuilder = new ForwardTextIteratorBuilder();
+ searchOptions.SearchStrategyTypeChanged += new EventHandler(InitializeSearchStrategy);
+ searchOptions.DocumentIteratorTypeChanged += new EventHandler(InitializeDocumentIterator);
+ InitializeDocumentIterator(null, null);
+ InitializeSearchStrategy(null, null);
+ }
+
+ static void InitializeSearchStrategy(object sender, EventArgs e)
+ {
+ find.SearchStrategy = SearchReplaceUtilities.CreateSearchStrategy(SearchOptions.SearchStrategyType);
+ }
+
+ static void InitializeDocumentIterator(object sender, EventArgs e)
+ {
+ find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType);
+ }
+
+ // TODO: Transform Replace Pattern
+ public static void Replace()
+ {
+ if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
+ /*TextEditorControl textarea = ((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl;
+ string text = textarea.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText;
+ if (text == SearchOptions.SearchPattern) {
+ int offset = textarea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection[0].Offset;
+
+ textarea.BeginUpdate();
+ textarea.ActiveTextAreaControl.TextArea.SelectionManager.RemoveSelectedText();
+ textarea.Document.Insert(offset, SearchOptions.ReplacePattern);
+ textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(offset + SearchOptions.ReplacePattern.Length);
+ textarea.EndUpdate();
+ }*/
+ }
+ FindNext();
+ }
+
+ public static void MarkAll()
+ {
+ //TextEditorControl textArea = null;
+ /*if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
+ textArea = ((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl;
+ textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection();
+ }*/
+ find.Reset();
+ find.SearchStrategy.CompilePattern(searchOptions);
+ while (true) {
+ ISearchResult result = SearchReplaceManager.find.FindNext(searchOptions);
+
+ if (result == null) {
+ //MessageBox.Show((Form)WorkbenchSingleton.Workbench, "Mark all done", "Finished");
+ find.Reset();
+ return;
+ } else {
+ /*textArea = OpenTextArea(result.FileName);
+
+ textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(result.Offset);
+ int lineNr = textArea.Document.GetLineNumberForOffset(result.Offset);
+
+ if (!textArea.Document.BookmarkManager.IsMarked(lineNr)) {
+ textArea.Document.BookmarkManager.ToggleMarkAt(lineNr);
+ }*/
+ }
+ }
+ }
+
+ public static void ReplaceAll()
+ {
+ //TextEditorControl textArea = null;
+ /*if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
+ textArea = ((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl;
+ textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection();
+ }*/
+ find.Reset();
+ find.SearchStrategy.CompilePattern(searchOptions);
+
+ while (true) {
+ ISearchResult result = SearchReplaceManager.find.FindNext(SearchReplaceManager.searchOptions);
+
+ if (result == null) {
+ //MessageBox.Show((Form)WorkbenchSingleton.Workbench, "Replace all done", "Finished");
+ find.Reset();
+ return;
+ } else {
+ /*textArea = OpenTextArea(result.FileName);
+
+ textArea.BeginUpdate();
+ textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection.Clear();
+
+ string transformedPattern = result.TransformReplacePattern(SearchOptions.ReplacePattern);
+ find.Replace(result.Offset,
+ result.Length,
+ transformedPattern);
+ textArea.EndUpdate();
+ textArea.Refresh();*/
+ }
+ }
+ }
+
+ static ISearchResult lastResult = null;
+ public static void FindNext()
+ {
+ if (find == null ||
+ searchOptions.SearchPattern == null ||
+ searchOptions.SearchPattern.Length == 0) {
+ return;
+ }
+
+ find.SearchStrategy.CompilePattern(searchOptions);
+ ISearchResult result = find.FindNext(searchOptions);
+
+ if (result == null) {
+ ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
+ /*MessageBox.Show((Form)WorkbenchSingleton.Workbench,
+ resourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"),
+ "Not Found",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Information);*/
+ find.Reset();
+ } else {
+ /*TextEditorControl textArea = OpenTextArea(result.FileName);
+
+ if (lastResult != null && lastResult.FileName == result.FileName &&
+ textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length) {
+ find.Reset();
+ }
+ int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
+ int endPos = Math.Min(textArea.Document.TextLength, startPos + result.Length);
+
+ textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(endPos);
+ textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection();
+ textArea.ActiveTextAreaControl.TextArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, textArea.Document.OffsetToPosition(startPos),
+ textArea.Document.OffsetToPosition(endPos)));
+ textArea.Refresh();*/
+ }
+
+ lastResult = result;
+ }
+
+ /*static TextEditorControl OpenTextArea(string fileName)
+ {
+ if (fileName != null) {
+ IFileService fileService = (IFileService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
+ fileService.OpenFile(fileName);
+ }
+
+ return ((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl;
+ }*/
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceUtilities.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceUtilities.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceUtilities.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,81 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+using ICSharpCode.SharpDevelop.Gui;
+using ICSharpCode.TextEditor;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public sealed class SearchReplaceUtilities
+ {
+ public static bool IsTextAreaSelected {
+ get {
+ /*
+ return WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null &&
+ WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent is ITextEditorControlProvider;
+ */
+ return false;
+ }
+ }
+
+
+ public static bool IsWholeWordAt(ITextBufferStrategy document, int offset, int length)
+ {
+ return (offset - 1 < 0 || Char.IsWhiteSpace(document.GetCharAt(offset - 1))) &&
+ (offset + length + 1 >= document.Length || Char.IsWhiteSpace(document.GetCharAt(offset + length)));
+ }
+
+ /*public static int CalcCurrentOffset(IDocument document)
+ {
+// TODO:
+// int endOffset = document.Caret.Offset % document.TextLength;
+// return endOffset;
+ return 0;
+ }*/
+
+ public static ISearchStrategy CreateSearchStrategy(SearchStrategyType type)
+ {
+ switch (type) {
+ case SearchStrategyType.None:
+ return null;
+ case SearchStrategyType.Normal:
+ return new BruteForceSearchStrategy(); // new KMPSearchStrategy();
+ case SearchStrategyType.RegEx:
+ return new RegExSearchStrategy();
+ case SearchStrategyType.Wildcard:
+ return new WildcardSearchStrategy();
+ default:
+ throw new System.NotImplementedException("CreateSearchStrategy for type " + type);
+ }
+ }
+
+
+ public static IDocumentIterator CreateDocumentIterator(DocumentIteratorType type)
+ {
+ switch (type) {
+ case DocumentIteratorType.None:
+ return null;
+ case DocumentIteratorType.CurrentDocument:
+ return new CurrentDocumentIterator();
+ case DocumentIteratorType.Directory:
+ return new DirectoryDocumentIterator(SearchReplaceInFilesManager.SearchOptions.SearchDirectory,
+ SearchReplaceInFilesManager.SearchOptions.FileMask,
+ SearchReplaceInFilesManager.SearchOptions.SearchSubdirectories);
+ case DocumentIteratorType.AllOpenFiles:
+ return new AllOpenDocumentIterator();
+ case DocumentIteratorType.WholeCombine:
+ return new WholeProjectDocumentIterator();
+ default:
+ throw new System.NotImplementedException("CreateDocumentIterator for type " + type);
+ }
+ }
+ }
+
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/DefaultSearchResult.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/DefaultSearchResult.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/DefaultSearchResult.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,71 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Drawing;
+
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class DefaultSearchResult : ISearchResult
+ {
+ ProvidedDocumentInformation providedDocumentInformation;
+ int offset;
+ int length;
+
+ public string FileName {
+ get {
+ return providedDocumentInformation.FileName;
+ }
+ }
+
+ public ProvidedDocumentInformation ProvidedDocumentInformation {
+ set {
+ providedDocumentInformation = value;
+ }
+ }
+
+ public int Offset {
+ get {
+ return offset;
+ }
+ }
+
+ public int Length {
+ get {
+ return length;
+ }
+ }
+
+ public virtual string TransformReplacePattern(string pattern)
+ {
+ return pattern;
+ }
+
+ /*public IDocument CreateDocument()
+ {
+ return providedDocumentInformation.CreateDocument();
+ }*/
+
+ public DefaultSearchResult(int offset, int length)
+ {
+ this.offset = offset;
+ this.length = length;
+ }
+
+ public override string ToString()
+ {
+ return String.Format("[DefaultLocation: FileName={0}, Offset={1}, Length={2}]",
+ FileName,
+ Offset,
+ Length);
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/ISearchResult.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/ISearchResult.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchResult/ISearchResult.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,66 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.IO;
+using System.Drawing;
+
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// This interface describes the result a search strategy must
+ /// return with a call to find next.
+ /// </summary>
+ public interface ISearchResult
+ {
+ /// <value>
+ /// Returns the file name of the search result. This
+ /// value is null till the ProvidedDocumentInformation
+ /// property is set.
+ /// </value>
+ string FileName {
+ get;
+ }
+
+ /// <value>
+ /// This property is set by the find object and need not to be
+ /// set by the search strategies. All search results that are returned
+ /// by the find object do have a ProvidedDocumentInformation.
+ /// </value>
+ ProvidedDocumentInformation ProvidedDocumentInformation {
+ set;
+ }
+
+ /// <value>
+ /// The offset of the pattern match
+ /// </value>
+ int Offset {
+ get;
+ }
+
+ /// <value>
+ /// The length of the pattern match.
+ /// </value>
+ int Length {
+ get;
+ }
+
+ /// <remarks>
+ /// This method creates a document for the file FileName. This method works
+ /// only after the ProvidedDocumentInformation is set.
+ /// </remarks>
+
+ /// <remarks>
+ /// Replace operations must transform the replace pattern with this
+ /// method.
+ /// </remarks>
+ string TransformReplacePattern(string pattern);
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,72 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Only for fallback purposes.
+ /// </summary>
+ public class BruteForceSearchStrategy : ISearchStrategy
+ {
+ string searchPattern;
+
+ bool MatchCaseSensitive(ITextBufferStrategy document, int offset, string pattern)
+ {
+ for (int i = 0; i < pattern.Length; ++i) {
+ if (offset + i >= document.Length || document.GetCharAt(offset + i) != pattern[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ bool MatchCaseInsensitive(ITextBufferStrategy document, int offset, string pattern)
+ {
+ for (int i = 0; i < pattern.Length; ++i) {
+ if (offset + i >= document.Length || Char.ToUpper(document.GetCharAt(offset + i)) != pattern[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ bool IsWholeWordAt(ITextBufferStrategy document, int offset, int length)
+ {
+ return (offset - 1 < 0 || Char.IsWhiteSpace(document.GetCharAt(offset - 1))) &&
+ (offset + length + 1 >= document.Length || Char.IsWhiteSpace(document.GetCharAt(offset + length)));
+ }
+
+ int InternalFindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ while (textIterator.MoveAhead(1)) {
+ if (options.IgnoreCase ? MatchCaseInsensitive(textIterator.TextBuffer, textIterator.Position, searchPattern) :
+ MatchCaseSensitive(textIterator.TextBuffer, textIterator.Position, searchPattern)) {
+ if (!options.SearchWholeWordOnly || IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length)) {
+ return textIterator.Position;
+ }
+ }
+ }
+ return -1;
+ }
+
+ public void CompilePattern(SearchOptions options)
+ {
+ searchPattern = options.IgnoreCase ? options.SearchPattern.ToUpper() : options.SearchPattern;
+ }
+
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ int offset = InternalFindNext(textIterator, options);
+ return offset >= 0 ? new DefaultSearchResult(offset, searchPattern.Length) : null;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/ISearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/ISearchStrategy.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/ISearchStrategy.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,35 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Drawing;
+
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// This interface is the basic interface which all
+ /// search algorithms must implement.
+ /// </summary>
+ public interface ISearchStrategy
+ {
+ /// <remarks>
+ /// Only with a call to this method the search strategy must
+ /// update their pattern information. This method will be called
+ /// before the FindNext function.
+ /// </remarks>
+ void CompilePattern(SearchOptions options);
+
+ /// <remarks>
+ /// 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);
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/KMPSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/KMPSearchStrategy.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/KMPSearchStrategy.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,78 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Andrea Paatz" email="andrea at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Implements the Knuth, Morris, Pratt searching algorithm.
+ /// </summary>
+ public class KMPSearchStrategy : ISearchStrategy
+ {
+ string searchPattern;
+ int[] overlap;
+
+ public void CompilePattern(SearchOptions options)
+ {
+ if (searchPattern != (options.IgnoreCase ? options.SearchPattern.ToUpper() : options.SearchPattern)) {
+ searchPattern = options.IgnoreCase ? options.SearchPattern.ToUpper() : options.SearchPattern;
+ overlap = new int[searchPattern.Length + 1];
+ Preprocessing();
+ }
+ }
+
+ void Preprocessing()
+ {
+ overlap[0] = -1;
+ for (int i = 0, j = -1; i < searchPattern.Length;) {
+ while (j >= 0 && searchPattern[i] != searchPattern[j]) {
+ j = overlap[j];
+ }
+ ++i;
+ ++j;
+ overlap[i] = j;
+ }
+ }
+
+ int InternalFindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ int j = 0;
+ if (!textIterator.MoveAhead(1)) {
+ return -1;
+ }
+ while (true) { // until pattern found or Iterator finished
+ while (j >= 0 && searchPattern[j] != (options.IgnoreCase ? Char.ToUpper(textIterator.GetCharRelative(j)) : textIterator.GetCharRelative(j))) {
+ if (!textIterator.MoveAhead(j - overlap[j])) {
+ return -1;
+ }
+ j = overlap[j];
+ }
+ if (++j >= searchPattern.Length) {
+ if ((!options.SearchWholeWordOnly || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length))) {
+ return textIterator.Position;
+ }
+ if (!textIterator.MoveAhead(j - overlap[j])) {
+ return -1;
+ }
+ j = overlap[j];
+ }
+ }
+ }
+
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ int offset = InternalFindNext(textIterator, options);
+
+ if (offset + searchPattern.Length >= textIterator.TextBuffer.Length) {
+ return FindNext(textIterator, options);
+ }
+
+ return offset >= 0 ? new DefaultSearchResult(offset, searchPattern.Length) : null;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/RegExSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/RegExSearchStrategy.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/RegExSearchStrategy.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,50 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Text.RegularExpressions;
+
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class RegExSearchStrategy : ISearchStrategy
+ {
+ Regex regex = null;
+
+ public void CompilePattern(SearchOptions options)
+ {
+ RegexOptions regexOptions = RegexOptions.Compiled;
+ if (options.IgnoreCase) {
+ regexOptions |= RegexOptions.IgnoreCase;
+ }
+ regex = new Regex(options.SearchPattern, regexOptions);
+ }
+
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length);
+
+ while (textIterator.MoveAhead(1)) {
+ Match m = regex.Match(document, textIterator.Position);
+ if (m == null || m.Index <= 0 || m.Length <= 0) {
+
+ } else {
+ int delta = m.Index - textIterator.Position;
+ if (delta <= 0 || textIterator.MoveAhead(delta)) {
+ return new DefaultSearchResult(m.Index, m.Length);
+ } else {
+ return null;
+ }
+ }
+ }
+
+ return null;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/WildcardSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/WildcardSearchStrategy.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchStrategy/WildcardSearchStrategy.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,157 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Undo;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Implements a wildcard search strategy.
+ ///
+ /// Wildcard search has following pattern code :
+ /// * = Zero or more of any character
+ /// ? = Any single character
+ /// # = Any single digit
+ /// [...] = Any one character in the set
+ /// [!...] = Any one character not in the set
+ /// </summary>
+ public class WildcardSearchStrategy : ISearchStrategy
+ {
+ enum CommandType {
+ Match,
+ AnyZeroOrMore,
+ AnySingle,
+ AnyDigit,
+ AnyInList,
+ NoneInList
+ }
+
+ class Command {
+ public CommandType CommandType = CommandType.Match;
+ public char SingleChar = '\0';
+ public string CharList = String.Empty;
+ }
+
+ ArrayList patternProgram = null;
+ int curMatchEndOffset = -1;
+
+ void CompilePattern(string pattern, bool ignoreCase)
+ {
+ patternProgram = new ArrayList();
+ for (int i = 0; i < pattern.Length; ++i) {
+ Command newCommand = new Command();
+ switch (pattern[i]) {
+ case '#':
+ newCommand.CommandType = CommandType.AnyDigit;
+ break;
+ case '*':
+ newCommand.CommandType = CommandType.AnyZeroOrMore;
+ break;
+ case '?':
+ newCommand.CommandType = CommandType.AnySingle;
+ break;
+ case '[':
+ int index = pattern.IndexOf(']', i);
+ if (index > 0) {
+ newCommand.CommandType = CommandType.AnyInList;
+ string list = pattern.Substring(i + 1, index - i - 1);
+ if (list[0] == '!') {
+ newCommand.CommandType = CommandType.NoneInList;
+ list = list.Substring(1);
+ }
+ newCommand.CharList = ignoreCase ? list.ToUpper() : list;
+ i = index;
+ } else {
+ goto default;
+ }
+ break;
+ default:
+ newCommand.CommandType = CommandType.Match;
+ newCommand.SingleChar = ignoreCase ? Char.ToUpper(pattern[i]) : pattern[i];
+ break;
+ }
+ patternProgram.Add(newCommand);
+ }
+ }
+
+ bool Match(ITextBufferStrategy document,
+ int offset,
+ bool ignoreCase,
+ int programStart)
+ {
+ int curOffset = offset;
+ curMatchEndOffset = -1;
+
+ for (int pc = programStart; pc < patternProgram.Count; ++pc) {
+ if (curOffset >= document.Length) {
+ return false;
+ }
+
+ char ch = ignoreCase ? Char.ToUpper(document.GetCharAt(curOffset)) : document.GetCharAt(curOffset);
+ Command cmd = (Command)patternProgram[pc];
+
+ switch (cmd.CommandType) {
+ case CommandType.Match:
+ if (ch != cmd.SingleChar) {
+ return false;
+ }
+ break;
+ case CommandType.AnyZeroOrMore:
+ return Match(document, curOffset, ignoreCase, pc + 1) ||
+ Match(document, curOffset + 1, ignoreCase, pc);
+ case CommandType.AnySingle:
+ break;
+ case CommandType.AnyDigit:
+ if (!Char.IsDigit(ch)) {
+ return false;
+ }
+ break;
+ case CommandType.AnyInList:
+ if (cmd.CharList.IndexOf(ch) < 0) {
+ return false;
+ }
+ break;
+ case CommandType.NoneInList:
+ if (cmd.CharList.IndexOf(ch) >= 0) {
+ return false;
+ }
+ break;
+ }
+ ++curOffset;
+ }
+ curMatchEndOffset = curOffset;
+ return true;
+ }
+
+ int InternalFindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ while (textIterator.MoveAhead(1)) {
+ if (Match(textIterator.TextBuffer, textIterator.Position, options.IgnoreCase, 0)) {
+ if (!options.SearchWholeWordOnly || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, curMatchEndOffset - textIterator.Position)) {
+ return textIterator.Position;
+ }
+ }
+ }
+ return -1;
+ }
+
+ public void CompilePattern(SearchOptions options)
+ {
+ CompilePattern(options.SearchPattern, options.IgnoreCase);
+ }
+
+ public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
+ {
+ int offset = InternalFindNext(textIterator, options);
+ return offset >= 0 ? new DefaultSearchResult(offset, curMatchEndOffset - offset) : null;
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,133 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Diagnostics;
+using System.Collections;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class ForwardTextIterator : ITextIterator
+ {
+ enum TextIteratorState {
+ Resetted,
+ Iterating,
+ Done,
+ }
+
+ TextIteratorState state;
+
+ ITextBufferStrategy textBuffer;
+ int currentOffset;
+ int endOffset;
+ int oldOffset = -1;
+
+ public ITextBufferStrategy TextBuffer {
+ get {
+ return textBuffer;
+ }
+ }
+
+ public char Current {
+ get {
+ switch (state) {
+ case TextIteratorState.Resetted:
+ throw new System.InvalidOperationException("Call moveAhead first");
+ case TextIteratorState.Iterating:
+ return textBuffer.GetCharAt(currentOffset);
+ case TextIteratorState.Done:
+ throw new System.InvalidOperationException("TextIterator is at the end");
+ default:
+ throw new System.InvalidOperationException("unknown text iterator state");
+ }
+ }
+ }
+
+ public int Position {
+ get {
+ return currentOffset;
+ }
+ set {
+ currentOffset = value;
+ }
+ }
+
+
+ public ForwardTextIterator(ITextBufferStrategy textBuffer, int endOffset)
+ {
+ Debug.Assert(textBuffer != null);
+ Debug.Assert(endOffset >= 0 && endOffset < textBuffer.Length);
+
+ this.textBuffer = textBuffer;
+ this.endOffset = endOffset;
+ Reset();
+ }
+
+ public char GetCharRelative(int offset)
+ {
+ if (state != TextIteratorState.Iterating) {
+ throw new System.InvalidOperationException();
+ }
+
+ int realOffset = (currentOffset + (1 + Math.Abs(offset) / textBuffer.Length) * textBuffer.Length + offset) % textBuffer.Length;
+ return textBuffer.GetCharAt(realOffset);
+ }
+
+ public bool MoveAhead(int numChars)
+ {
+ Debug.Assert(numChars > 0);
+
+ switch (state) {
+ case TextIteratorState.Resetted:
+ currentOffset = endOffset;
+ state = TextIteratorState.Iterating;
+ return true;
+ case TextIteratorState.Done:
+ return false;
+ case TextIteratorState.Iterating:
+ currentOffset = (currentOffset + numChars) % textBuffer.Length;
+ bool finish = oldOffset != -1 && (oldOffset > currentOffset || oldOffset < endOffset) && currentOffset >= endOffset;
+
+ oldOffset = currentOffset;
+ if (finish) {
+ state = TextIteratorState.Done;
+ return false;
+ }
+ return true;
+ default:
+ throw new Exception("Unknown text iterator state");
+ }
+ }
+
+ public void InformReplace(int offset, int length, int newLength)
+ {
+ if (offset <= endOffset) {
+ endOffset = endOffset - length + newLength;
+ }
+
+ if (offset <= currentOffset) {
+ currentOffset = currentOffset - length + newLength;
+ }
+
+ if (offset <= oldOffset) {
+ oldOffset = oldOffset - length + newLength;
+ }
+ }
+
+ public void Reset()
+ {
+ state = TextIteratorState.Resetted;
+ currentOffset = endOffset;
+ oldOffset = -1;
+ }
+
+ public override string ToString()
+ {
+ return String.Format("[ForwardTextIterator: currentOffset={0}, endOffset={1}, state={2}]", currentOffset, endOffset, state);
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIteratorBuilder.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIteratorBuilder.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ForwardTextIteratorBuilder.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,22 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Diagnostics;
+using System.Collections;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ public class ForwardTextIteratorBuilder : ITextIteratorBuilder
+ {
+ public ITextIterator BuildTextIterator(ProvidedDocumentInformation info)
+ {
+ Debug.Assert(info != null);
+ return new ForwardTextIterator(info.TextBuffer, info.EndOffset);
+ }
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIterator.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIterator.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,72 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// This iterator iterates on a text buffer strategy.
+ /// </summary>
+ public interface ITextIterator
+ {
+ /// <value>
+ /// The text buffer strategy
+ /// </value>
+ ITextBufferStrategy TextBuffer {
+ get;
+ }
+
+ /// <value>
+ /// Gets the current char this is the same as
+ /// GetCharRelative(0)
+ /// </value>
+ /// <exception cref="System.InvalidOperationException">
+ /// If this method is called before the first MoveAhead or after
+ /// MoveAhead or after MoveAhead returns false.
+ /// </exception>
+ char Current {
+ get;
+ }
+
+ /// <value>
+ /// The current position=offset of the text iterator cursor
+ /// </value>
+ int Position {
+ get;
+ set;
+ }
+
+ /// <remarks>
+ /// Gets a char relative to the current position (negative values
+ /// will work too).
+ /// </remarks>
+ /// <exception cref="System.InvalidOperationException">
+ /// If this method is called before the first MoveAhead or after
+ /// MoveAhead or after MoveAhead returns false.
+ /// </exception>
+ char GetCharRelative(int offset);
+
+ /// <remarks>
+ /// Moves the iterator position numChars
+ /// </remarks>
+ bool MoveAhead(int numChars);
+
+ /// <remarks>
+ /// Rests the iterator
+ /// </remarks>
+ void Reset();
+
+ /// <remarks>
+ /// The find object calls the InformReplace method to inform the text iterator
+ /// about the replace operation on the TextBuffer. The text iterator must update
+ /// all internal offsets to the new offsets (if neccessary)
+ /// </remarks>
+ void InformReplace(int offset, int length, int newLength);
+ }
+}
Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIteratorBuilder.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIteratorBuilder.cs 2004-02-19 02:32:39 UTC (rev 941)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/TextIterator/ITextIteratorBuilder.cs 2004-02-19 03:42:53 UTC (rev 942)
@@ -0,0 +1,20 @@
+// <file>
+// <copyright see="prj:///doc/copyright.txt"/>
+// <license see="prj:///doc/license.txt"/>
+// <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+// <version value="$version"/>
+// </file>
+
+using System;
+using System.Collections;
+
+namespace ICSharpCode.TextEditor.Document
+{
+ /// <summary>
+ /// Builds a text iterator object.
+ /// </summary>
+ public interface ITextIteratorBuilder
+ {
+ ITextIterator BuildTextIterator(ProvidedDocumentInformation info);
+ }
+}
More information about the Monodevelop-patches-list
mailing list