[Monodevelop-patches-list] r703 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor: . Gui

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Wed Jan 28 12:38:39 EST 2004


Author: benm
Date: 2004-01-28 12:38:39 -0500 (Wed, 28 Jan 2004)
New Revision: 703

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
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile
Log:
implement bookmarks -- TODO: get good icon, wait for MK to allow me to write c#; yes the code is ugly, very ugly

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-01-28 06:31:55 UTC (rev 702)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorBuffer.cs	2004-01-28 17:38:39 UTC (rev 703)
@@ -1,5 +1,6 @@
 using Gtk;
 using GtkSharp;
+using GLib;
 
 using ICSharpCode.SharpDevelop.Gui;
 using ICSharpCode.SharpDevelop.Internal.Project;
@@ -146,5 +147,183 @@
 		
 		Gtk.Clipboard clipboard = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
 #endregion
+
+#region Bookmark Operations
+		
+		//
+		// Ok, the GtkSourceView people made this extremely dificult because they took over
+		// the TextMark type for their SourceMarker, So i have to marshall for them. It is annoying
+		// I filed a bug.
+		//
+		// Again, this is retarded
+		//
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_buffer_get_markers_in_region (IntPtr raw, ref Gtk.TextIter begin, ref Gtk.TextIter end);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_buffer_create_marker(IntPtr raw, string name, string type, ref Gtk.TextIter where);
+
+		[DllImport("gtksourceview-1.0")]
+		static extern void gtk_source_buffer_delete_marker(IntPtr raw, IntPtr marker);
+		
+		[DllImport("gtksharpglue")]
+		static extern IntPtr gtksharp_slist_get_data (IntPtr l);
+
+		[DllImport("gtksharpglue")]
+		static extern IntPtr gtksharp_slist_get_next (IntPtr l);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_marker_get_marker_type(IntPtr raw);
+		
+		[DllImport("libglib-2.0-0.dll")]
+		static extern void g_slist_free (IntPtr l);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern void gtk_source_buffer_get_iter_at_marker (IntPtr raw, ref Gtk.TextIter iter, IntPtr marker);
+		
+		public void ToggleBookmark ()
+		{
+			TextIter insert = GetIterAtMark (InsertMark);
+			TextIter begin_line = insert, end_line = insert;
+			begin_line.LineOffset = 0;
+			
+			while (! end_line.EndsLine ())
+				end_line.ForwardChar ();
+			
+			
+			IntPtr lst = gtk_source_buffer_get_markers_in_region (Handle, ref begin_line, ref end_line);
+
+			bool found_marker = false;
+			
+			//
+			// Ok, again, this is absurd. The problem is that the buffer owns the
+			// reference to the marker. So, if we use the nice Gtk# stuff, we get
+			// a problem when we dispose it later. Thus we must basically write this
+			// in C. It sucks. It really sucks.
+			//
+			
+			IntPtr current = lst;
+			while (current != IntPtr.Zero) {
+				
+				IntPtr data = gtksharp_slist_get_data (current);
+				IntPtr nm = gtk_source_marker_get_marker_type (data);
+				string name = GLibSharp.Marshaller.PtrToStringGFree (nm);
+				if (name == "SourceEditorBookmark") {
+					gtk_source_buffer_delete_marker (Handle, data);
+					found_marker = true;
+				}
+				
+				current = gtksharp_slist_get_next (current);
+			}
+			
+			if (lst != IntPtr.Zero)
+				g_slist_free (lst);
+			
+			if (found_marker)
+				return;
+			
+			gtk_source_buffer_create_marker (Handle, null, "SourceEditorBookmark", ref begin_line);
+		}
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_buffer_get_prev_marker(IntPtr raw, ref Gtk.TextIter iter);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_buffer_get_last_marker(IntPtr raw);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_marker_prev (IntPtr raw);
+		
+		public void PrevBookmark ()
+		{
+			TextIter loc = GetIterAtMark (InsertMark);
+			int ln = loc.Line;
+			
+			IntPtr prevMarker = gtk_source_buffer_get_prev_marker (Handle, ref loc);
+			IntPtr firstMarker = prevMarker;
+			bool first = true;
+			while (true) {
+				// Thats a wrap!
+				if (prevMarker == IntPtr.Zero)
+					prevMarker = gtk_source_buffer_get_last_marker (Handle);
+				
+				IntPtr nm = gtk_source_marker_get_marker_type (prevMarker);
+				string name = GLibSharp.Marshaller.PtrToStringGFree (nm);
+				if (name == "SourceEditorBookmark") {
+					gtk_source_buffer_get_iter_at_marker (Handle, ref loc, prevMarker);
+					
+					if (! first || loc.Line != ln)
+						break;
+				}
+				
+				prevMarker = gtk_source_marker_prev (prevMarker);
+				
+				first = false;
+			}
+			
+			PlaceCursor (loc);
+		}
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_buffer_get_first_marker (IntPtr raw);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_buffer_get_next_marker(IntPtr raw, ref Gtk.TextIter iter);
+		
+		[DllImport("gtksourceview-1.0")]
+		static extern IntPtr gtk_source_marker_next(IntPtr raw);
+		
+		public void NextBookmark ()
+		{
+			TextIter loc = GetIterAtMark (InsertMark);
+			int ln = loc.Line;
+			
+			IntPtr nextMarker = gtk_source_buffer_get_next_marker (Handle, ref loc);
+			IntPtr firstMarker = nextMarker;
+			bool first = true;
+			while (true) {
+				// Thats a wrap!
+				if (nextMarker == IntPtr.Zero)
+					nextMarker = gtk_source_buffer_get_first_marker (Handle);
+				
+				IntPtr nm = gtk_source_marker_get_marker_type (nextMarker);
+				string name = GLibSharp.Marshaller.PtrToStringGFree (nm);
+				if (name == "SourceEditorBookmark") {
+					gtk_source_buffer_get_iter_at_marker (Handle, ref loc, nextMarker);
+					
+					if (! first || loc.Line != ln)
+						break;
+				}
+				
+				nextMarker = gtk_source_marker_next (nextMarker);
+				
+				first = false;
+			}
+			
+			PlaceCursor (loc);
+		}
+		
+		public void ClearBookmarks ()
+		{
+			TextIter begin = StartIter;
+			TextIter end = EndIter;
+			IntPtr lst = gtk_source_buffer_get_markers_in_region (Handle, ref begin, ref end);
+			
+			IntPtr current = lst;
+			while (current != IntPtr.Zero) {
+				
+				IntPtr data = gtksharp_slist_get_data (current);
+				IntPtr nm = gtk_source_marker_get_marker_type (data);
+				string name = GLibSharp.Marshaller.PtrToStringGFree (nm);
+				if (name == "SourceEditorBookmark")
+					gtk_source_buffer_delete_marker (Handle, data);
+				
+				current = gtksharp_slist_get_next (current);
+			}
+			
+			if (lst != IntPtr.Zero)
+				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 06:31:55 UTC (rev 702)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorDisplayBinding.cs	2004-01-28 17:38:39 UTC (rev 703)
@@ -64,7 +64,7 @@
 	}
 	
 	public class SourceEditorDisplayBindingWrapper : AbstractViewContent,
-		IEditable, IPositionable
+		IEditable, IPositionable, IBookmarkOperations
 	{
 		internal SourceEditor se;
 		
@@ -231,5 +231,27 @@
 		}
 #endregion
 
+#region IBookmarkOperations
+		void IBookmarkOperations.ToggleBookmark ()
+		{
+			se.Buffer.ToggleBookmark ();
+		}
+		
+		void IBookmarkOperations.PrevBookmark ()
+		{
+			se.Buffer.PrevBookmark ();
+		}
+		
+		void IBookmarkOperations.NextBookmark ()
+		{
+			se.Buffer.NextBookmark ();
+		}
+		
+		void IBookmarkOperations.ClearBookmarks ()
+		{
+			se.Buffer.ClearBookmarks ();
+		}
+#endregion
+
 	}
 }

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-01-28 06:31:55 UTC (rev 702)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorWidget.cs	2004-01-28 17:38:39 UTC (rev 703)
@@ -23,6 +23,8 @@
 			View.ShowLineMarkers = true;
 			Buffer.Highlight = true;
 			
+			View.SetMarkerPixbuf ("SourceEditorBookmark", new Gdk.Pixbuf (drag_icon_xpm));
+			
 			Add (View);
 		}
 		
@@ -30,5 +32,66 @@
 			get { return Buffer.Text; }
 			set { Buffer.Text = value; }
 		}
+		
+		private static readonly string [] drag_icon_xpm = new string [] {
+			"36 48 9 1",
+			" 	c None",
+			".	c #020204",
+			"+	c #8F8F90",
+			"@	c #D3D3D2",
+			"#	c #AEAEAC",
+			"$	c #ECECEC",
+			"%	c #A2A2A4",
+			"&	c #FEFEFC",
+			"*	c #BEBEBC",
+			"               .....................",
+			"              ..&&&&&&&&&&&&&&&&&&&.",
+			"             ...&&&&&&&&&&&&&&&&&&&.",
+			"            ..&.&&&&&&&&&&&&&&&&&&&.",
+			"           ..&&.&&&&&&&&&&&&&&&&&&&.",
+			"          ..&&&.&&&&&&&&&&&&&&&&&&&.",
+			"         ..&&&&.&&&&&&&&&&&&&&&&&&&.",
+			"        ..&&&&&.&&&@&&&&&&&&&&&&&&&.",
+			"       ..&&&&&&.*$%$+$&&&&&&&&&&&&&.",
+			"      ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.",
+			"     ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.",
+			"    ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.",
+			"   ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.",
+			"  ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
+			" ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
+			"................&$@&&&@&&&&&&&&&&&&.",
+			".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&&.",
+			".&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&&&.",
+			".&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&&&.",
+			".&&&&&&@#@@$&*@&@#@#$**#$&&&&&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&@%&%$&&&&&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
+			".&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&&&.",
+			".&&&&&&&&&+&$+&$&@&$@&&$@&&&&&&&&&&.",
+			".&&&&&&&&&+&&#@%#+@#@*$%&+$&&&&&&&&.",
+			".&&&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&.",
+			".&&&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&.",
+			".&&&&&&&&@#@@$&*@&@#@#$#*#$&&&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&&&.",
+			".&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&.",
+			".&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&&&&&.",
+			".&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&.",
+			".&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&&&&&.",
+			".&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&&&&&.",
+			".&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
+			".&&&&&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&.",
+			".&&&&&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&.",
+			".&&&&&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&.",
+			".&&&&&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&.",
+			".&&&&&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&.",
+			".&&&&&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
+			".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
+			"...................................."
+		};
 	}
 }
\ No newline at end of file

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile	2004-01-28 06:31:55 UTC (rev 702)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Makefile	2004-01-28 17:38:39 UTC (rev 703)
@@ -3,7 +3,7 @@
 all : $(DLL)
 
 $(DLL) : $(shell find . -name \*.cs)
-	mcs $(shell find . -name \*.cs) /out:$@ /t:library /r:gtk-sharp /r:gdk-sharp /r:gtksourceview-sharp \
+	mcs $(shell find . -name \*.cs) /out:$@ /t:library /r:gtk-sharp /r:gdk-sharp /r:gtksourceview-sharp /r:glib-sharp \
 		/r:../../../../build/bin/MonoDevelop.Core.dll \
 		/r:../../../../build/bin/MonoDevelop.TextEditor.dll \
 		/r:../../../../build/bin/MonoDevelop.Base.dll \




More information about the Monodevelop-patches-list mailing list