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

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Fri Jan 30 23:05:37 EST 2004


Author: tberman
Date: 2004-01-30 23:05:37 -0500 (Fri, 30 Jan 2004)
New Revision: 727

Added:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IndexerInsightDataProvider.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/MethodInsightDataProvider.cs
Modified:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IInsightDataProvider.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/InsightWindow.cs
Log:
bits and pieces of some working Insight Window, it needs cleanups, and functionality fixups, but its better than nothing.


Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs	2004-01-30 23:19:42 UTC (rev 726)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/CodeCompletion/CompletionWindow.cs	2004-01-31 04:05:37 UTC (rev 727)
@@ -71,7 +71,7 @@
 		{
 			Gdk.Key key = ex.Event.Key;
 			char val = (char) key;
-			Console.WriteLine("Got Press event ({0}). Key {1}", ex, key);
+			
 			switch (key) {
 				case Gdk.Key.Shift_L:
 				case Gdk.Key.Shift_R:
@@ -81,24 +81,11 @@
 					return;
 					
 				case Gdk.Key.Escape:
-					Console.WriteLine("Got Escape");
 					LostFocusListView(null, null);
 					ex.RetVal = true;
 					return;
 					
-				case Gdk.Key.BackSpace:
-					Console.WriteLine("Got BackSpace on key press");
-					//new ICSharpCode.TextEditor.Actions.Backspace().Execute(control.ActiveTextAreaControl.TextArea);
-					if (insertLength > 0) {
-						--insertLength;
-					} else {
-						// no need to delete here (insertLength <= 0)
-						LostFocusListView(null, null);
-					}
-					break;
-					
 				default:
-					Console.WriteLine("Got key: {0}", key);
 					if (val != '_' && !Char.IsLetterOrDigit(val)) {
 						if (listView.Selection.CountSelectedRows() > 0) {
 							ActivateItem(null, null);
@@ -106,7 +93,7 @@
 							LostFocusListView(null, null);
 						}
 						
-						control.Buffer.InsertAtCursor (val.ToString ());
+						//control.Buffer.InsertAtCursor (val.ToString ());
 						ex.RetVal = true;
 						return;
 					} else {

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs	2004-01-30 23:19:42 UTC (rev 726)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/Gui/SourceEditorView.cs	2004-01-31 04:05:37 UTC (rev 727)
@@ -7,6 +7,7 @@
 using System.Runtime.InteropServices;
 
 using MonoDevelop.SourceEditor.CodeCompletion;
+using MonoDevelop.SourceEditor.InsightWindow;
 	
 namespace MonoDevelop.SourceEditor.Gui {
 	public class SourceEditorView : SourceView {
@@ -63,12 +64,31 @@
 				//FIXME: ' ' needs to do extra parsing
 				case ' ':
 				case '.':
-					Console.WriteLine ("About to show completion Window");
 					completionWindow = new CompletionWindow (this, ParentEditor.DisplayBinding.ContentName, new CodeCompletionDataProvider ());
 					completionWindow.ShowCompletionWindow ((char)key);
 					break;
+				case '(':
+					try {
+						InsightWindow insightWindow = new InsightWindow(this, ParentEditor.DisplayBinding.ContentName);
+						
+						insightWindow.AddInsightDataProvider(new MethodInsightDataProvider());
+						insightWindow.ShowInsightWindow();
+					} catch (Exception e) {
+						Console.WriteLine("EXCEPTION: " + e);
+					}
+					break;
+				case '[':
+					try {
+						InsightWindow insightWindow = new InsightWindow(this, ParentEditor.DisplayBinding.ContentName);
+						
+						insightWindow.AddInsightDataProvider(new IndexerInsightDataProvider());
+						insightWindow.ShowInsightWindow();
+					} catch (Exception e) {
+						Console.WriteLine("EXCEPTION: " + e);
+					}
+					break;
 			}
-			
+		
 			return base.OnKeyPressEvent (ref evnt);
 		}
 		

Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow (from rev 721, trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/InsightWindow)

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IInsightDataProvider.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/InsightWindow/IInsightDataProvider.cs	2004-01-29 23:52:56 UTC (rev 721)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IInsightDataProvider.cs	2004-01-31 04:05:37 UTC (rev 727)
@@ -10,13 +10,13 @@
 using System.Reflection;
 using System.Collections;
 
-using ICSharpCode.TextEditor.Document;
+using MonoDevelop.SourceEditor.Gui;
 
-namespace ICSharpCode.TextEditor.Gui.InsightWindow
+namespace MonoDevelop.SourceEditor.InsightWindow
 {
 	public interface IInsightDataProvider
 	{
-		void SetupDataProvider(string fileName, TextArea textArea);
+		void SetupDataProvider(string fileName, SourceEditorView textArea);
 		
 		bool CaretOffsetChanged();
 		bool CharTyped();

Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IndexerInsightDataProvider.cs (from rev 721, trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/InsightWindow/IndexerInsightDataProvider.cs)
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/InsightWindow/IndexerInsightDataProvider.cs	2004-01-29 23:52:56 UTC (rev 721)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/IndexerInsightDataProvider.cs	2004-01-31 04:05:37 UTC (rev 727)
@@ -0,0 +1,129 @@
+// <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 System.Reflection;
+using System.Collections;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Templates;
+using ICSharpCode.SharpDevelop.Services;
+using SharpDevelop.Internal.Parser;
+
+using MonoDevelop.SourceEditor.Gui;
+using MonoDevelop.SourceEditor.CodeCompletion;
+
+namespace MonoDevelop.SourceEditor.InsightWindow
+{
+	public class IndexerInsightDataProvider : IInsightDataProvider
+	{
+		ClassBrowserIconsService classBrowserIconService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService));
+		AmbienceService          ambienceService = (AmbienceService)ServiceManager.Services.GetService(typeof(AmbienceService));
+		
+		string              fileName = null;
+		SourceEditorView    textArea;
+		IndexerCollection   methods  = new IndexerCollection();
+		
+		public int InsightDataCount {
+			get {
+				return methods.Count;
+			}
+		}
+		
+		public string GetInsightData(int number)
+		{
+			IIndexer method = methods[number];
+			IAmbience conv = ambienceService.CurrentAmbience;
+			conv.ConversionFlags = ConversionFlags.StandardConversionFlags;
+			return conv.Convert(method) + 
+			       "\n" + 
+			       CodeCompletionData.GetDocumentation(method.Documentation); // new (by G.B.)
+		}
+		
+		int initialOffset;
+		public void SetupDataProvider(string fileName, SourceEditorView textArea)
+		{
+			this.fileName = fileName;
+			this.textArea = textArea;
+			Gtk.TextIter initialIter = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
+			initialOffset = initialIter.Offset;
+			
+			string word         = TextUtilities.GetExpressionBeforeOffset(textArea, initialOffset);
+			string methodObject = word;
+			
+			// the parser works with 1 based coordinates
+			int caretLineNumber      = initialIter.Line + 1;
+			int caretColumn          = initialIter.LineOffset + 1;
+			IParserService parserService = (IParserService)ServiceManager.Services.GetService(typeof(IParserService));
+			ResolveResult results = parserService.Resolve(methodObject,
+			                                              caretLineNumber,
+			                                              caretColumn,
+			                                              fileName,
+			                                              textArea.Buffer.Text);
+			if (results != null && results.Type != null) {
+				foreach (IClass c in results.Type.ClassInheritanceTree) {
+					foreach (IIndexer indexer in c.Indexer) {
+						methods.Add(indexer);
+					}
+				}
+				foreach (object o in results.ResolveContents) {
+					if (o is IClass) {
+						foreach (IClass c in ((IClass)o).ClassInheritanceTree) {
+							foreach (IIndexer indexer in c.Indexer) {
+								methods.Add(indexer);
+							}
+						}
+					}
+				}
+			}
+		}
+		
+		public bool CaretOffsetChanged()
+		{
+			Gtk.TextIter caret = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
+			bool closeDataProvider = caret.Offset <= initialOffset;
+			string text = textArea.Buffer.Text;
+			
+			if (!closeDataProvider) {
+				bool insideChar   = false;
+				bool insideString = false;
+				for (int offset = initialOffset; offset < Math.Min(caret.Offset, text.Length); ++offset) {
+					char ch = text [offset];
+					switch (ch) {
+						case '\'':
+							insideChar = !insideChar;
+							break;
+						case '"':
+							insideString = !insideString;
+							break;
+						case ']':
+						case '}':
+						case '{':
+						case ';':
+							if (!(insideChar || insideString)) {
+								return true;
+							}
+							break;
+					}
+				}
+			}
+			
+			return closeDataProvider;
+		}
+		
+		public bool CharTyped()
+		{
+			int offset = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark).Offset - 1;
+			if (offset >= 0) {
+				return textArea.Buffer.Text [offset] == ']';
+			}
+			return false;
+		}
+	}
+}

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/InsightWindow.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/ICSharpCode.TextEditor/src/Gui/InsightWindow/InsightWindow.cs	2004-01-29 23:52:56 UTC (rev 721)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/InsightWindow.cs	2004-01-31 04:05:37 UTC (rev 727)
@@ -9,27 +9,28 @@
 using System.Reflection;
 using System.Collections;
 
-using ICSharpCode.TextEditor.Document;
-using ICSharpCode.TextEditor.Util;
-using ICSharpCode.TextEditor;
+using ICSharpCode.Core.Services;
 using Gtk;
 using GtkSharp;
 
-namespace ICSharpCode.TextEditor.Gui.InsightWindow
+using MonoDevelop.SourceEditor.Gui;
+using MonoDevelop.SourceEditor.CodeCompletion;
+
+namespace MonoDevelop.SourceEditor.InsightWindow
 {
 	public class InsightWindow : Window
 	{
 		static GLib.GType type;
-		TextEditorControl control;
+		SourceEditorView  control;
 		Stack             insightDataProviderStack = new Stack();
+
+		Gtk.Label desc;
+		Gtk.Label current;
+		Gtk.Label max;
+		string description;
+
+		StringParserService StringParserService = (StringParserService)ServiceManager.Services.GetService (typeof (StringParserService)); 
 		
-		EventHandler         focusEventHandler;
-#if GTK
-		// FIXME: GTKize?
-#else
-		KeyPressEventHandler keyPressEventHandler;
-#endif
-		
 		class InsightDataProviderStackElement 
 		{
 			public int                  currentData;
@@ -44,7 +45,7 @@
 		
 		public void AddInsightDataProvider(IInsightDataProvider provider)
 		{
-			provider.SetupDataProvider(fileName, control.ActiveTextAreaControl.TextArea);
+			provider.SetupDataProvider(fileName, control);
 			if (provider.InsightDataCount > 0) {
 				insightDataProviderStack.Push(new InsightDataProviderStackElement(provider));
 			}
@@ -56,6 +57,10 @@
 			}
 			set {
 				((InsightDataProviderStackElement)insightDataProviderStack.Peek()).currentData = value;
+				desc.Text = DataProvider.GetInsightData (CurrentData);
+				current.Text = CurrentData.ToString ();
+				max.Text = DataProvider.InsightDataCount.ToString ();
+				ReshowWithInitialSize ();
 			}
 		}
 		
@@ -72,7 +77,7 @@
 		{
 			insightDataProviderStack.Pop();
 			if (insightDataProviderStack.Count == 0) {
-				Hide();
+				Destroy ();
 			} else {
 				this.QueueDraw ();
 			}
@@ -84,13 +89,15 @@
 				if (insightDataProviderStack.Count > 0) {
 //					control.TextAreaPainter.IHaveTheFocusLock = true;
 					BeforeShow ();
-					//this.ShowAll ();
+					this.ShowAll ();
 //					dialogKeyProcessor = new TextEditorControl.DialogKeyProcessor(ProcessTextAreaKey);
 //					control.ProcessDialogKeyProcessor += dialogKeyProcessor;
-					control.GrabFocus ();
+					//control.GrabFocus ();
 
 //					control.TextAreaPainter.IHaveTheFocus     = true;
 //					control.TextAreaPainter.IHaveTheFocusLock = false;
+					desc.Text = description = DataProvider.GetInsightData(CurrentData);
+					
 				}
 			} else {
 
@@ -105,39 +112,38 @@
 			type = RegisterGType (typeof (InsightWindow));
 		}
 		
-		public InsightWindow(TextEditorControl control, string fileName) : base (type)
+		public InsightWindow(SourceEditorView control, string fileName) : base (type)
 		{
 			this.control             = control;
 			this.fileName = fileName;
-			System.Drawing.Point caretPos  = control.ActiveTextAreaControl.TextArea.Caret.Position;
+			/*System.Drawing.Point caretPos  = control.ActiveTextAreaControl.TextArea.Caret.Position;
 			System.Drawing.Point visualPos = new System.Drawing.Point(control.ActiveTextAreaControl.TextArea.TextView.GetDrawingXPos(caretPos.Y, caretPos.X) + control.ActiveTextAreaControl.TextArea.TextView.DrawingPosition.X,
-			          (int)((1 + caretPos.Y) * control.ActiveTextAreaControl.TextArea.TextView.FontHeight) - control.ActiveTextAreaControl.TextArea.VirtualTop.Y - 1 + control.ActiveTextAreaControl.TextArea.TextView.DrawingPosition.Y);
+			          (int)((1 + caretPos.Y) * control.ActiveTextAreaControl.TextArea.TextView.FontHeight) - control.ActiveTextAreaControl.TextArea.VirtualTop.Y - 1 + control.ActiveTextAreaControl.TextArea.TextView.DrawingPosition.Y);*/
 			
-			focusEventHandler = new EventHandler(TextEditorLostFocus);
 			
-			control.ActiveTextAreaControl.Caret.PositionChanged += new EventHandler(CaretOffsetChanged);
+			//control.ActiveTextAreaControl.Caret.PositionChanged += new EventHandler(CaretOffsetChanged);
 //			control.TextAreaPainter.IHaveTheFocusChanged += focusEventHandler;
 			
-//			control.TextAreaPainter.KeyPress += keyPressEventHandler;
-			
-#if GTK
+			AddEvents ((int) (Gdk.EventMask.KeyPressMask));
 			this.SkipPagerHint = true;
 			this.SkipTaskbarHint = true;
 			this.Decorated = false;
 			this.BorderWidth = 2;
 			this.TypeHint = Gdk.WindowTypeHint.Dialog;
-#else
-	 		Location = control.ActiveTextAreaControl.PointToScreen(visualPos);
-			
-			StartPosition   = FormStartPosition.Manual;
-			FormBorderStyle = FormBorderStyle.None;
-			TopMost         = true;
-			ShowInTaskbar   = false;
-			Size            = new Size(0, 0);
-			
-			SetStyle(ControlStyles.UserPaint, true);
-			SetStyle(ControlStyles.DoubleBuffer, true);
-#endif
+
+			desc = new Gtk.Label ("");
+			current = new Gtk.Label ("");
+			max = new Gtk.Label ("");
+			HBox mainBox = new HBox (false, 2);
+			mainBox.PackStart (new Gtk.Image (Gtk.Stock.GotoTop, Gtk.IconSize.Menu), false, false, 2);
+			mainBox.PackStart (current, false, false, 2);
+			mainBox.PackStart (new Gtk.Label (" of "), false, false, 2);
+			mainBox.PackStart (max, false, false, 2);
+			mainBox.PackStart (new Gtk.Image (Gtk.Stock.GotoBottom, Gtk.IconSize.Menu), false, false, 2);
+			mainBox.PackStart (desc);
+			Gtk.Frame framer = new Gtk.Frame ();
+			framer.Add (mainBox);
+			this.Add (framer);
 		}
 		
 		// Methods that are inserted into the TextArea :
@@ -145,7 +151,7 @@
 		{
 			switch (keyData) {
 				case Gdk.Key.Escape:
-					Hide();
+					Destroy ();
 					return true;
 				case Gdk.Key.Down:
 					if (DataProvider != null && DataProvider.InsightDataCount > 0) {
@@ -163,16 +169,19 @@
 			return false;
 		}
 		
-#if GTK
-		// FIXME: GTKize
-#else
-		void KeyPressEvent(object sender, KeyPressEventArgs e)
+		protected override bool OnKeyPressEvent (ref Gdk.EventKey e)
 		{
-			if (DataProvider != null && DataProvider.CharTyped()) {
-				CloseCurrentDataProvider();
+			//if (DataProvider != null && DataProvider.CharTyped()) {
+			//	CloseCurrentDataProvider();
+			//}
+			char val = (char)e.Key;
+			if (ProcessTextAreaKey (e.Key) == false) {
+				control.Buffer.InsertAtCursor (val.ToString ());
+				return true;
+			} else {
+				return base.OnKeyPressEvent (ref e);
 			}
 		}
-#endif
 		
 		void CaretOffsetChanged(object sender, EventArgs e)
 		{
@@ -203,50 +212,45 @@
 			}*/
 		}
 		
-#if !GTK
-		protected override void OnClosed(EventArgs e)
+/*		protected override void OnClosed(EventArgs e)
 		{
 			base.OnClosed(e);
 			
 			// take out the inserted methods
-			control.ActiveTextAreaControl.Caret.PositionChanged -= new EventHandler(CaretOffsetChanged);
+			//control.MoveCursor -= new GtkSharp.MoveCursorHandler(CaretOffsetChanged);
 //			control.ProcessDialogKeyProcessor            -= dialogKeyProcessor;
+
 //			control.TextAreaPainter.IHaveTheFocusChanged -= focusEventHandler;
 //			control.TextAreaPainter.KeyPress             -= keyPressEventHandler;
-		}
-#endif
+		}*/
 		
 		protected void TextEditorLostFocus(object sender, EventArgs e)
 		{
-			if (!control.ActiveTextAreaControl.TextArea.IsFocus) {
+			if (!control.HasFocus) {
 				Hide();
 			}
 		}
 
-#if GTK
 		protected void BeforeShow ()
 		{
-			string methodCountMessage = null, description;
+			string methodCountMessage = null;
 			if (DataProvider == null || DataProvider.InsightDataCount < 1) {
 				description = "Unknown Method";
 			} else {
-				/*if (DataProvider.InsightDataCount > 1) {
+				if (DataProvider.InsightDataCount > 1) {
 					StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
 					stringParserService.Properties["CurrentMethodNumber"]  = (CurrentData + 1).ToString();
 					stringParserService.Properties["NumberOfTotalMethods"] = DataProvider.InsightDataCount.ToString();
 					methodCountMessage = stringParserService.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.InsightWindow.NumberOfText}");
-				}*/
+				}
 				
-				description = DataProvider.GetInsightData(CurrentData);
+				//I know this call looks stupid, but really it isnt.
+				CurrentData = CurrentData;
+				QueueDraw ();
 			}
-			
-			Console.WriteLine ("Current Data: {0}", CurrentData);
-			Console.WriteLine ("Description: {0}", description);
-			//TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics,
-			//	Font, methodCountMessage, description);
 		}
-#else
-		protected override void OnPaint(PaintEventArgs pe)
+		
+		/*protected override void OnPaint(PaintEventArgs pe)
 		{
 			string methodCountMessage = null, description;
 			if (DataProvider == null || DataProvider.InsightDataCount < 1) {
@@ -264,12 +268,6 @@
 			
 			TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics,
 				Font, methodCountMessage, description);
-		}
-		
-		protected override void OnPaintBackground(PaintEventArgs pe)
-		{
-			pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle);
-		}
-#endif
+		}*/
 	}
 }

Copied: trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/MethodInsightDataProvider.cs (from rev 721, trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/InsightWindow/MethodInsightDataProvider.cs)
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Gui/Editor/InsightWindow/MethodInsightDataProvider.cs	2004-01-29 23:52:56 UTC (rev 721)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/SourceEditor/InsightWindow/MethodInsightDataProvider.cs	2004-01-31 04:05:37 UTC (rev 727)
@@ -0,0 +1,214 @@
+// <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 System.Reflection;
+using System.Collections;
+
+using ICSharpCode.Core.Services;
+using ICSharpCode.Core.Properties;
+using ICSharpCode.SharpDevelop.Internal.Templates;
+using ICSharpCode.SharpDevelop.Services;
+using SharpDevelop.Internal.Parser;
+
+using MonoDevelop.SourceEditor.Gui;
+using MonoDevelop.SourceEditor.CodeCompletion;
+
+namespace MonoDevelop.SourceEditor.InsightWindow 
+{
+	public class MethodInsightDataProvider : IInsightDataProvider
+	{
+		ClassBrowserIconsService classBrowserIconService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService));
+		AmbienceService          ambienceService = (AmbienceService)ServiceManager.Services.GetService(typeof(AmbienceService));
+		
+		string              fileName = null;
+		SourceEditorView    textArea  = null;
+		MethodCollection    methods  = new MethodCollection();
+		
+		int caretLineNumber;
+		int caretColumn;
+		
+		public int InsightDataCount {
+			get {
+				return methods.Count;
+			}
+		}
+		
+		public string GetInsightData(int number)
+		{
+			IMethod method = methods[number];
+			IAmbience conv = ambienceService.CurrentAmbience;
+			conv.ConversionFlags = ConversionFlags.StandardConversionFlags;
+			return conv.Convert(method);
+			//       "\n" + 
+			//       CodeCompletionData.GetDocumentation(method.Documentation); // new (by G.B.)
+		}
+		
+		int initialOffset;
+		public void SetupDataProvider(string fileName, SourceEditorView textArea)
+		{
+			this.fileName = fileName;
+			this.textArea = textArea;
+			Gtk.TextIter initialIter = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
+			initialOffset = initialIter.Offset;
+			string text = textArea.Buffer.Text;
+			
+			string word         = TextUtilities.GetExpressionBeforeOffset(textArea, initialOffset);
+			string methodObject = word;
+			string methodName   =  null;
+			int idx = methodObject.LastIndexOf('.');
+			if (idx >= 0) {
+				methodName   = methodObject.Substring(idx + 1);
+				methodObject = methodObject.Substring(0, idx);
+			} else {
+				methodObject = "this";
+				methodName   = word;
+			}
+			
+			if (methodName.Length == 0 || methodObject.Length == 0) {
+				return;
+			}
+			
+			// the parser works with 1 based coordinates
+			caretLineNumber      = initialIter.Line + 1;
+			caretColumn          = initialIter.LineOffset + 1;
+			
+			string[] words = word.Split(' ');
+			bool contructorInsight = false;
+			if (words.Length > 1) {
+				contructorInsight = words[words.Length - 2] == "new";
+				if (contructorInsight) {
+					methodObject = words[words.Length - 1];
+				}
+			}
+			IParserService parserService = (IParserService)ServiceManager.Services.GetService(typeof(IParserService));
+			ResolveResult results = parserService.Resolve(methodObject, caretLineNumber, caretColumn, fileName, text);
+			
+			if (results != null && results.Type != null) {
+				if (contructorInsight) {
+					AddConstructors(results.Type);
+				} else {
+					foreach (IClass c in results.Type.ClassInheritanceTree) {
+						AddMethods(c, methodName, false);
+					}
+				}
+			}
+		}
+		
+		bool IsAlreadyIncluded(IMethod newMethod) 
+		{
+			foreach (IMethod method in methods) {
+				if (method.Name == newMethod.Name) {
+					if (newMethod.Parameters.Count != method.Parameters.Count) {
+						return false;
+					}
+					
+					for (int i = 0; i < newMethod.Parameters.Count; ++i) {
+						if (newMethod.Parameters[i].ReturnType != method.Parameters[i].ReturnType) {
+							return false;
+						}
+					}
+					
+					// take out old method, when it isn't documented.
+					if (method.Documentation == null || method.Documentation.Length == 0) {
+						methods.Remove(method);
+						return false;
+					}
+					return true;
+				}
+			}
+			return false;
+		}
+		
+		void AddConstructors(IClass c)
+		{
+			foreach (IMethod method in c.Methods) {
+				if (method.IsConstructor && !method.IsStatic) {
+					methods.Add(method);
+				}
+			}
+		}
+		
+		void AddMethods(IClass c, string methodName, bool discardPrivate)
+		{
+			foreach (IMethod method in c.Methods) {
+				if (!(method.IsPrivate && discardPrivate) && 
+				    method.Name == methodName &&
+				    !IsAlreadyIncluded(method)) {
+					methods.Add(method);
+				}
+			}
+		}
+		
+		public bool CaretOffsetChanged()
+		{
+			Gtk.TextIter insertIter = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark);
+			bool closeDataProvider = insertIter.Offset <= initialOffset;
+			int brackets = 0;
+			int curlyBrackets = 0;
+			string text = textArea.Buffer.Text;
+			if (!closeDataProvider) {
+				bool insideChar   = false;
+				bool insideString = false;
+				for (int offset = initialOffset; offset < Math.Min(insertIter.Offset, text.Length); ++offset) {
+					char ch = text[offset];
+					switch (ch) {
+						case '\'':
+							insideChar = !insideChar;
+							break;
+						case '(':
+							if (!(insideChar || insideString)) {
+								++brackets;
+							}
+							break;
+						case ')':
+							if (!(insideChar || insideString)) {
+								--brackets;
+							}
+							if (brackets <= 0) {
+								return true;
+							}
+							break;
+						case '"':
+							insideString = !insideString;
+							break;
+						case '}':
+							if (!(insideChar || insideString)) {
+								--curlyBrackets;
+							}
+							if (curlyBrackets < 0) {
+								return true;
+							}
+							break;
+						case '{':
+							if (!(insideChar || insideString)) {
+								++curlyBrackets;
+							}
+							break;
+						case ';':
+							if (!(insideChar || insideString)) {
+								return true;
+							}
+							break;
+					}
+				}
+			}
+			
+			return closeDataProvider;
+		}
+		
+		public bool CharTyped()
+		{
+			int offset = textArea.Buffer.GetIterAtMark (textArea.Buffer.InsertMark).Offset - 1;
+			if (offset >= 0) {
+				return textArea.Buffer.Text [offset] == ')';
+			}
+			return false;
+		}
+	}
+}




More information about the Monodevelop-patches-list mailing list