[Monodevelop-patches-list] r947 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor: Gui Search Search/DocumentIterator

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Thu Feb 19 15:11:11 EST 2004


Author: tberman
Date: 2004-02-19 15:11:11 -0500 (Thu, 19 Feb 2004)
New Revision: 947

Modified:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs
Log:
replace and replace all are generally working.

having issues doing a case insensitive replace when the cases are different.

the instance is found, but not replaced for some reason.


Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-02-19 19:33:19 UTC (rev 946)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-02-19 20:11:11 UTC (rev 947)
@@ -106,6 +106,16 @@
 				return GetSelectionBounds (out dummy, out dummy2);
 			}
 		}
+
+		public string GetSelectedText () {
+			if (HasSelection)
+			{
+				TextIter select1, select2;
+				GetSelectionBounds (out select1, out select2);
+				return GetText (select1, select2, true);
+			}
+			return String.Empty;
+		}
 		
 		bool IClipboardHandler.EnableCut {
 			get { return true; }
@@ -406,6 +416,8 @@
 
 		public char GetCharAt (int offset)
 		{
+			if (offset < 0)
+				offset = 0;
 			Console.WriteLine ("[GetCharAt] ({0})", offset);
 			return Text[offset];
 		}
@@ -416,6 +428,37 @@
 			return Text.Substring (start, length);
 		}
 
+		public void Insert (int offset, string text)
+		{
+			TextIter put = GetIterAtOffset (offset);
+			Insert (put, text);
+		}
+
+		public int GetLowerSelectionBounds ()
+		{
+			if (HasSelection)
+			{
+				TextIter select1, select2;
+				GetSelectionBounds (out select1, out select2);
+				return select1.Offset > select2.Offset ? select2.Offset : select1.Offset;
+			}
+			return 0;
+		}
+
+		public void Delete (int offset, int length)
+		{
+			TextIter start = GetIterAtOffset (offset);
+			TextIter end = GetIterAtOffset (offset + length);
+
+			Delete (start, end);
+		}
+
+		public void Replace (int offset, int length, string pattern)
+		{
+			Delete (offset, length);
+			Insert (offset, pattern);
+		}
+
 		public static SourceEditorBuffer CreateTextBufferFromFile (string filename)
 		{
 			SourceEditorBuffer buff = new SourceEditorBuffer ();

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-02-19 19:33:19 UTC (rev 946)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-02-19 20:11:11 UTC (rev 947)
@@ -32,8 +32,11 @@
 			get { return Buffer.Text; }
 			set { Buffer.Text = value; }
 		}
-		
 
+		public void Replace (int offset, int length, string pattern)
+		{
+			Buffer.Replace (offset, length, pattern);
+		}
 		
 		private static readonly string [] drag_icon_xpm = new string [] {
 			"36 48 9 1",

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs	2004-02-19 19:33:19 UTC (rev 946)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/DocumentIterator/ProvidedDocumentInformation.cs	2004-02-19 20:11:11 UTC (rev 947)
@@ -64,11 +64,11 @@
 		
 		public void Replace(int offset, int length, string pattern)
 		{
-			//if (document != null) {
-			//	document.Replace(offset, length, pattern);
-			//} else {
-			//	textBuffer.Replace(offset, length, pattern);
-			//}
+			if (document != null) {
+				document.Replace(offset, length, pattern);
+			} else {
+				textBuffer.Replace(offset, length, pattern);
+			}
 			
 			if (offset <= CurrentOffset) {
 				CurrentOffset = CurrentOffset - length + pattern.Length;

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs	2004-02-19 19:33:19 UTC (rev 946)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Search/SearchReplaceManager.cs	2004-02-19 20:11:11 UTC (rev 947)
@@ -72,17 +72,16 @@
 		public static void Replace()
 		{
 			if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
-				/*TextEditorControl textarea = ((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl;
-				string text = textarea.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText;
+				SourceEditor textarea = (SourceEditor) ((SourceEditorDisplayBindingWrapper)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).Control;
+				string text = textarea.Buffer.GetSelectedText ();
 				if (text == SearchOptions.SearchPattern) {
-					int offset = textarea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection[0].Offset;
+					int offset = textarea.Buffer.GetLowerSelectionBounds ();
 					
-					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();
-				}*/
+					((IClipboardHandler)textarea.Buffer).Delete (null, null);
+					
+					textarea.Buffer.Insert(offset, SearchOptions.ReplacePattern);
+					textarea.Buffer.PlaceCursor (textarea.Buffer.GetIterAtOffset (offset + SearchOptions.ReplacePattern.Length));
+				}
 			}
 			FindNext();
 		}
@@ -120,11 +119,11 @@
 		
 		public static void ReplaceAll()
 		{
-			//TextEditorControl textArea = null;
-			/*if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
-				textArea = ((ITextEditorControlProvider)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).TextEditorControl;
-				textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection();
-			}*/
+			SourceEditor textArea = null;
+			if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) {
+				textArea = (SourceEditor) ((SourceEditorDisplayBindingWrapper)WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent).Control;
+				textArea.Buffer.PlaceCursor (textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark));
+			}
 			find.Reset();
 			find.SearchStrategy.CompilePattern(searchOptions);
 			
@@ -136,17 +135,13 @@
 					find.Reset();
 					return;
 				} else {
-					/*textArea = OpenTextArea(result.FileName); 
+					textArea = OpenTextArea(result.FileName); 
+					textArea.Buffer.PlaceCursor (textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark));
 					
-					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();*/
 				}
 			}
 		}




More information about the Monodevelop-patches-list mailing list