[Monodevelop-patches-list] r686 - trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Tue Jan 27 17:17:25 EST 2004


Author: benm
Date: 2004-01-27 17:17:25 -0500 (Tue, 27 Jan 2004)
New Revision: 686

Modified:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs
Log:
handle undos right, update status bar

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-01-27 22:10:02 UTC (rev 685)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-01-27 22:17:25 UTC (rev 686)
@@ -14,9 +14,25 @@
 using System.Runtime.InteropServices;
 	
 namespace MonoDevelop.SourceEditor.Gui {
-	public class SourceEditorBuffer : SourceBuffer,
-		IClipboardHandler {
+	public class SourceEditorBuffer : SourceBuffer, IClipboardHandler {
 		
+		// This gives us a nice way to avoid the try/finally
+		// which is really long.
+		struct NoUndo : IDisposable {
+			SourceEditorBuffer b;
+			
+			public NoUndo (SourceEditorBuffer b) {
+				this.b = b;
+				b.BeginNotUndoableAction ();
+			}
+			
+			public void Dispose ()
+			{
+				b.EndNotUndoableAction ();
+			}
+		}
+			
+		
 		SourceLanguagesManager slm = new SourceLanguagesManager ();
 		
 		public SourceEditorBuffer () : base (new SourceTagTable ())
@@ -25,26 +41,33 @@
 		
 		public void LoadFile (string file, string mime)
 		{
-			LoadText (File.OpenText (file).ReadToEnd (), mime);
+			LoadText (File.OpenText (file).ReadToEnd (), mime);		
 			Modified = false;
 		}
 		
 		public void LoadFile (string file)
 		{
-			Text = File.OpenText (file).ReadToEnd ();
+			using (NoUndo n = new NoUndo (this))
+				Text = File.OpenText (file).ReadToEnd ();
+			
 			Modified = false;
 		}
 		
 		public void LoadText (string text, string mime)
 		{
-			Text = text;
 			Language = slm.GetLanguageFromMimeType (mime);
+			
+			using (NoUndo n = new NoUndo (this))
+				Text = text;
+			
 			Modified = false;
 		}
 		
 		public void LoadText (string text)
 		{
-			Text = text;
+			using (NoUndo n = new NoUndo (this))
+				Text = text;
+			
 			Modified = false;
 		}
 		

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs	2004-01-27 22:10:02 UTC (rev 685)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs	2004-01-27 22:17:25 UTC (rev 686)
@@ -8,8 +8,10 @@
 using ICSharpCode.Core.Services;
 using ICSharpCode.SharpDevelop.Services;
 using ICSharpCode.Core.AddIns.Codons;
+using System.Runtime.InteropServices;
 
 using Gtk;
+using GtkSharp;
 
 namespace MonoDevelop.SourceEditor.Gui {
 	public class SourceEditorDisplayBinding : IDisplayBinding {
@@ -82,6 +84,8 @@
 		{
 			se = new SourceEditor ();
 			se.Buffer.ModifiedChanged += new EventHandler (OnModifiedChanged);
+			se.Buffer.MarkSet += new MarkSetHandler (OnMarkSet);
+			se.Buffer.Changed += new EventHandler (OnChanged);
 		}
 		
 		public override void RedrawContent()
@@ -146,6 +150,63 @@
 			se.Buffer.Redo ();
 		}
 #endregion
+#region Status Bar Handling
+		IStatusBarService statusBarService = (IStatusBarService) ServiceManager.Services.GetService (typeof (IStatusBarService));
+		
+		void OnMarkSet (object o, MarkSetArgs args)
+		{
+			// 99% of the time, this is the insertion point
+			UpdateLineCol ();
+		}
+		
+		void OnChanged (object o, EventArgs e)
+		{
+			// gedit also hooks this event, but do we need it?
+			UpdateLineCol ();
+		}
+		
+		// WORKAROUND until we get this method returning char in gtk#
+		[DllImport("libgtk-win32-2.0-0.dll")]
+		static extern char gtk_text_iter_get_char (ref Gtk.TextIter raw);
+		
+		void UpdateLineCol ()
+		{
+			int col = 1; // first char == 1
+			int chr = 1;
+			bool found_non_ws = false;
+			int tab_size = (int) se.View.TabsWidth;
+			
+			TextIter iter = se.Buffer.GetIterAtMark (se.Buffer.InsertMark);
+			TextIter start = iter;
+			
+			iter.LineOffset = 0;
+			
+			while (! iter.Equal (start)) {
+				char c = gtk_text_iter_get_char (ref iter);
+				
+				if (c == '\t')
+					col += (tab_size - (col % tab_size));
+				else
+					col ++;
+				
+				if (c != '\t' && c != ' ')
+					found_non_ws = true;
+				
+				if (found_non_ws ) {
+					if (c == '\t')
+						chr += (tab_size - (col % tab_size));
+					else
+						chr ++;
+				}
+				
+				iter.ForwardChar ();
+			}
+			
+			// NOTE: this is absurd, *I* should tell the status bar which numbers
+			// to print.
+			statusBarService.SetCaretPosition (col - 1, iter.Line, chr - 1);
+		}
+#endregion
 
 	}
 }

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-01-27 22:10:02 UTC (rev 685)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-01-27 22:17:25 UTC (rev 686)
@@ -9,21 +9,21 @@
 	public class SourceEditor : ScrolledWindow {
 		
 		public readonly SourceEditorBuffer Buffer;
-		SourceView sv;
+		public readonly SourceView View;
 		
 		public SourceEditor ()
 		{
 			Buffer = new SourceEditorBuffer ();
 			
-			sv = new SourceView (Buffer);
+			View = new SourceView (Buffer);
 			
-			sv.AutoIndent = true;
-			sv.SmartHomeEnd = true;
-			sv.ShowLineNumbers = true;
-			sv.ShowLineMarkers = true;
+			View.AutoIndent = true;
+			View.SmartHomeEnd = true;
+			View.ShowLineNumbers = true;
+			View.ShowLineMarkers = true;
 			Buffer.Highlight = true;
 			
-			Add (sv);
+			Add (View);
 		}
 		
 		public string Text {




More information about the Monodevelop-patches-list mailing list