[Monodevelop-patches-list] r706 - in trunk/MonoDevelop/src/AddIns/DisplayBindings: EditorBindings EditorBindings/FormattingStrategy SourceEditor/Gui

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Wed Jan 28 19:03:22 EST 2004


Author: benm
Date: 2004-01-28 19:03:22 -0500 (Wed, 28 Jan 2004)
New Revision: 706

Added:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/
   trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/AbstractFormattingStrategy.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
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:
tab/shifttab work right, beginning of formatting

Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/AbstractFormattingStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/AbstractFormattingStrategy.cs	2004-01-28 21:34:46 UTC (rev 705)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/EditorBindings/FormattingStrategy/AbstractFormattingStrategy.cs	2004-01-29 00:03:22 UTC (rev 706)
@@ -0,0 +1,31 @@
+using Gdk;
+using Gtk;
+using GtkSharp;
+using System;
+
+namespace MonoDevelop.EditorBindings.FormattingStrategy {
+	public abstract class AbstractFormattingStrategy {
+		
+		public abstract bool KeyPressed (TextView view, TextBuffer buffer, KeyPressEventArgs args);
+		
+		public string GetLineIndentation (TextIter line)
+		{
+			line.LineOffset = 0;
+			
+			// `if iter was already on line 0, but not at the start of the line, iter is
+			// snapped to the start of the line and the function returns TRUE.'
+			
+			if (! line.BackwardLine ())
+				return "";
+			
+			line.LineOffset = 0;
+			
+			TextIter end = line;
+			
+			while (! end.StartsWord () && ! end.EndsLine ())
+				end.ForwardChar ();
+			
+			return line.GetSlice (end);
+		}
+	}
+}
\ No newline at end of file

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-01-28 21:34:46 UTC (rev 705)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-01-29 00:03:22 UTC (rev 706)
@@ -15,25 +15,41 @@
 using System.Runtime.InteropServices;
 	
 namespace MonoDevelop.SourceEditor.Gui {
-	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;
 		
-		// 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 ();
-			}
+		public NoUndo (SourceEditorBuffer b) {
+			this.b = b;
+			b.BeginNotUndoableAction ();
 		}
-			
 		
+		public void Dispose ()
+		{
+			b.EndNotUndoableAction ();
+		}
+	}
+	
+	// This gives us a nice way to avoid the try/finally
+	// which is really long.
+	struct AtomicUndo : IDisposable {
+		SourceEditorBuffer b;
+		
+		public AtomicUndo (SourceEditorBuffer b) {
+			this.b = b;
+			b.BeginUserAction ();
+		}
+		
+		public void Dispose ()
+		{
+			b.EndUserAction ();
+		}
+	}
+	
+	public class SourceEditorBuffer : SourceBuffer, IClipboardHandler {
+		
 		SourceLanguagesManager slm = new SourceLanguagesManager ();
 		
 		public SourceEditorBuffer () : base (new SourceTagTable ())
@@ -325,5 +341,6 @@
 				g_slist_free (lst);
 		}
 #endregion
+
 	}
 }
\ No newline at end of file

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs	2004-01-28 21:34:46 UTC (rev 705)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs	2004-01-29 00:03:22 UTC (rev 706)
@@ -98,8 +98,7 @@
 			TextIter itr = se.Buffer.GetIterAtLine (line);
 			itr.LineOffset = column;
 			
-			se.Buffer.MoveMark (se.Buffer.InsertMark,     itr);
-			se.Buffer.MoveMark (se.Buffer.SelectionBound, itr);
+			se.Buffer.PlaceCursor (itr);
 			
 			se.View.ScrollMarkOnscreen (se.Buffer.InsertMark);
 		}
@@ -126,6 +125,7 @@
 		public override void Save (string fileName)
 		{
 			se.Buffer.Save (fileName);
+			ContentName = fileName;
 		}
 		
 		public override void Load (string fileName)

Added: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs	2004-01-28 21:34:46 UTC (rev 705)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs	2004-01-29 00:03:22 UTC (rev 706)
@@ -0,0 +1,148 @@
+using Gtk;
+using GtkSharp;
+using Gdk;
+
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+	
+namespace MonoDevelop.SourceEditor.Gui {
+	public class SourceEditorView : SourceView {
+		
+		private static GLib.GType type;
+			
+		SourceEditorBuffer buf;
+		
+		static SourceEditorView ()
+		{
+			type = RegisterGType (typeof (SourceEditorView));
+		}
+		
+		public SourceEditorView (SourceEditorBuffer buf) : base (type)
+		{
+			Buffer = this.buf = buf;
+			AutoIndent = true;
+			SmartHomeEnd = true;
+			ShowLineNumbers = true;
+			ShowLineMarkers = true;
+		}
+		
+		protected override bool OnKeyPressEvent (ref Gdk.EventKey evnt)
+		{
+			Gdk.Key key = evnt.Key;
+			uint state = evnt.state;
+			state &= 1101u;
+			const uint Normal = 0, Shift = 1, Control = 4, ShiftControl = 5, Alt = 8;
+			
+			switch (state) {
+			case Normal:
+				switch (key) {
+					case Gdk.Key.Tab:
+						if (IndentSelection ())
+							return true;
+						break;
+				}
+				break;
+			case Shift:
+				switch (key) {
+					case Gdk.Key.ISO_Left_Tab:
+						if (UnIndentSelection ())
+							return true;
+						break;
+				}
+				break;
+			}
+			
+			base.OnKeyPressEvent (ref evnt);
+			return false;
+		}
+		
+#region Indentation
+		public bool IndentSelection ()
+		{
+			TextIter begin, end;
+			if (! buf.GetSelectionBounds (out begin, out end))
+				return false;
+			
+			int y0 = begin.Line, y1 = end.Line;
+			if (y0 == y1)
+				return false;
+			
+			using (AtomicUndo a = new AtomicUndo (buf)) {
+				IndentLines (y0, y1);
+				SelectLines (y0, y1);
+			}
+			
+			return true;
+		}
+		
+		public bool UnIndentSelection ()
+		{
+			TextIter begin, end;
+			if (! buf.GetSelectionBounds (out begin, out end))
+				return false;
+			
+			int y0 = begin.Line, y1 = end.Line;
+			if (y0 == y1)
+				return false;
+			
+			using (AtomicUndo a = new AtomicUndo (buf)) {
+				UnIndentLines (y0, y1);
+				SelectLines (y0, y1);
+			}
+			
+			return true;
+		}
+		
+		void IndentLines (int y0, int y1)
+		{
+			string indent = InsertSpacesInsteadOfTabs ? "\t" : new string (' ', (int) TabsWidth);
+			
+			for (int l = y0; l <= y1; l ++)
+				Buffer.Insert (Buffer.GetIterAtLine (l), indent);
+		}
+		
+		// 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 UnIndentLines (int y0, int y1)
+		{
+			for (int l = y0; l <= y1; l ++) {
+				TextIter start = Buffer.GetIterAtLine (l);
+				TextIter end = start;
+				
+				char c = gtk_text_iter_get_char (ref end);
+				
+				if (c == '\t') {
+					end.ForwardChar ();
+					buf.Delete (start, end);
+					
+				} else if (c == ' ') {
+					int cnt = 0;
+					int max = (int) TabsWidth;
+					
+					while (cnt <= max && gtk_text_iter_get_char (ref end) == ' ' && ! end.EndsLine ()) {
+						cnt ++;
+						end.ForwardChar ();
+					}
+					
+					if (cnt == 0)
+						return;
+					
+					buf.Delete (start, end);
+				}
+			}
+		}
+		
+		void SelectLines (int y0, int y1)
+		{
+			Buffer.PlaceCursor (Buffer.GetIterAtLine (y0));
+			
+			TextIter end = Buffer.GetIterAtLine (y1);
+			end.ForwardToLineEnd ();
+			Buffer.MoveMark ("selection_bound", end);
+		}
+#endregion
+	}
+}
\ No newline at end of file

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-01-28 21:34:46 UTC (rev 705)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-01-29 00:03:22 UTC (rev 706)
@@ -1,5 +1,6 @@
 using Gtk;
 using GtkSharp;
+using Gdk;
 
 using System;
 using System.IO;
@@ -9,18 +10,15 @@
 	public class SourceEditor : ScrolledWindow {
 		
 		public readonly SourceEditorBuffer Buffer;
-		public readonly SourceView View;
+		public readonly SourceEditorView View;
 		
 		public SourceEditor ()
 		{
 			Buffer = new SourceEditorBuffer ();
 			
-			View = new SourceView (Buffer);
+			View = new SourceEditorView (Buffer);
 			
-			View.AutoIndent = true;
-			View.SmartHomeEnd = true;
-			View.ShowLineNumbers = true;
-			View.ShowLineMarkers = true;
+
 			Buffer.Highlight = true;
 			
 			View.SetMarkerPixbuf ("SourceEditorBookmark", new Gdk.Pixbuf (drag_icon_xpm));
@@ -33,6 +31,8 @@
 			set { Buffer.Text = value; }
 		}
 		
+
+		
 		private static readonly string [] drag_icon_xpm = new string [] {
 			"36 48 9 1",
 			" 	c None",




More information about the Monodevelop-patches-list mailing list