[MonoDevelop] [PATCH] Fix improper member node command handling

Balaji Rao balajirrao at gmail.com
Mon Jul 2 15:22:06 EDT 2007


On Sun, Jul 01, 2007 at 05:05:51PM +0200, Lluis Sanchez wrote:
> El dj 28 de 06 del 2007 a les 19:33 +0530, en/na Balaji Rao va escriure:
> > On Thu, Jun 28, 2007 at 12:29:29AM +0200, Lluis Sanchez wrote:
> > > Hi!
Hi
> > > 
> > > I think that MemberNodeCommandHandler should use
> > > IdeApp.ProjectOperations.JumpToDeclaration () to open the file. I don't
> > > know if JumpToDeclaration() will work for the case that your patch fixes
> > > though. You can try it, and if it doesn't maybe you can apply the patch
> > > there.
> > > 
> > Fixed it. Is it ok now ?
> 
> Not yet:
>       * Insted of "typeof(IField).IsInstanceOfType(mem)" please use "mem
>         is IField".
>       * To be consistent with the surrounding code, the "file=
>         c.Region.FileName" call should be "file = GetClassFileName (c)".
>       * The method CanJumpToDeclaration should be in sync with
>         JumpToDeclaration.
>       * The patch is missing the corresponding ChangeLog entries.
Along with the above changes, I have also improved the
CanJumpToDeclaration() and JumpToDeclaration in which I felt that the
code was redundant.

I think it should be OK now. Is it?

Thank you
Balaji rao
> 
> Thanks,
> Lluis.
> 
> > > Lluis.
> > Regards,
> > Balaji Rao
> > > 
> > > El dt 26 de 06 del 2007 a les 16:07 +0530, en/na Balaji Rao va
> > > escriure: 
> > > > Hello guys, 
> > > > 
> > > > This patch fixes improper node command handling incase of partial
> > > > classes.
> > > > _______________________________________________
> > > > Monodevelop-list mailing list
> > > > Monodevelop-list at lists.ximian.com
> > > > http://lists.ximian.com/mailman/listinfo/monodevelop-list
> > > 
> > _______________________________________________
> > Monodevelop-list mailing list
> > Monodevelop-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/monodevelop-list
> 
-------------- next part --------------
Index: Core/src/MonoDevelop.Ide/ChangeLog
===================================================================
--- Core/src/MonoDevelop.Ide/ChangeLog	(revision 81194)
+++ Core/src/MonoDevelop.Ide/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2007-07-02  Balaji Rao <balajirrao at gmail.com>
+	* Monodevelop.Ide.Gui/ProjectOperations.cs:
+	Fixed and improved JumpToDeclaration method to support partial classes
+	* MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs:
+	Uses ProjectOperation.JumpToDeclaration() inplace of
+	ProjectOperation.OpenDocument directly.
+
 2007-07-02  Ben Motmans <ben.motmans at gmail.com>
 
 	* MonoDevelop.Ide.Gui/ProjectOperations.cs:
Index: Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs
===================================================================
--- Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs	(revision 81194)
+++ Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs	(working copy)
@@ -38,22 +38,9 @@
 	public class MemberNodeCommandHandler: NodeCommandHandler
 	{
 		public override void ActivateItem ()
-		{
-			string file = GetFileName ();
-			IMember member = CurrentNode.DataItem as IMember;
-			int line = member.Region.BeginLine;
-			IdeApp.Workbench.OpenDocument (file, Math.Max (1, line), 1, true);
+		{			
+			ILanguageItem member = CurrentNode.DataItem as ILanguageItem;
+			IdeApp.ProjectOperations.JumpToDeclaration(member);
 		}
-		
-		string GetFileName ()
-		{
-			IMember member = (IMember) CurrentNode.GetParentDataItem (typeof(IMember), true);
-			if (member != null && member.Region.FileName != null) return member.Region.FileName;
-			
-			ClassData cls = (ClassData) CurrentNode.GetParentDataItem (typeof(ClassData), true);
-			if (cls != null && cls.Class.Region.FileName != null) return cls.Class.Region.FileName;
-			
-			return null;
-		}
 	}
 }
Index: Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ProjectOperations.cs
===================================================================
--- Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ProjectOperations.cs	(revision 81194)
+++ Core/src/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ProjectOperations.cs	(working copy)
@@ -206,49 +206,53 @@
 			}
 		}
 		
-		public void JumpToDeclaration (ILanguageItem item)
-		{
+		string GetDeclaredFile(ILanguageItem item) {			
 			if (item is IMember) {
-				IMember mem = (IMember) item;
-				string file = null;
+				IMember mem = (IMember) item;				
 				if (mem.Region == null)
-					return;
+					return null;
 				else if (mem.Region.FileName != null)
-					file = mem.Region.FileName;
-				else if (mem.DeclaringType != null)
-					file = GetClassFileName (mem.DeclaringType);
-				if (file != null)
-					IdeApp.Workbench.OpenDocument (file, mem.Region.BeginLine, mem.Region.BeginColumn, true);
+					return mem.Region.FileName;
+				else if (mem.DeclaringType != null) {
+					foreach (IClass c in mem.DeclaringType.Parts) {
+						if ((mem is IField && c.Fields.Contains((IField)mem)) ||
+						    (mem is IEvent && c.Events.Contains((IEvent)mem)) || 
+						    (mem is IProperty  && c.Properties.Contains((IProperty)mem)) ||
+						    (mem is IMethod && c.Methods.Contains((IMethod)mem))) {
+							return GetClassFileName(c);							
+						}                                   
+					}
+				}
 			} else if (item is IClass) {
 				IClass cls = (IClass) item;
-				string file = GetClassFileName (cls);
-				if (cls.Region != null && file != null)
-					IdeApp.Workbench.OpenDocument (file, cls.Region.BeginLine, cls.Region.BeginColumn, true);
+				return GetClassFileName (cls);
 			} else if (item is LocalVariable) {
 				LocalVariable cls = (LocalVariable) item;
-				if (cls.Region != null)
-					IdeApp.Workbench.OpenDocument (cls.Region.FileName, cls.Region.BeginLine, cls.Region.BeginColumn, true);
+				return cls.Region.FileName;
 			}
+			return null;
 		}
 		
 		public bool CanJumpToDeclaration (ILanguageItem item)
 		{
+			return (GetDeclaredFile(item) != null);
+		}
+		
+		public void JumpToDeclaration (ILanguageItem item)
+		{
+			String file;
+			if ((file = GetDeclaredFile(item)) == null)
+				return;
 			if (item is IMember) {
 				IMember mem = (IMember) item;
-				if (mem.Region == null)
-					return false;
-				else if (mem.Region.FileName != null)
-					return true;
-				else if (mem.DeclaringType != null)
-					return GetClassFileName (mem.DeclaringType) != null;
+				IdeApp.Workbench.OpenDocument (file, mem.Region.BeginLine, mem.Region.BeginColumn, true);
 			} else if (item is IClass) {
 				IClass cls = (IClass) item;
-				return cls.Region != null && GetClassFileName (cls) != null;
+				IdeApp.Workbench.OpenDocument (file, cls.Region.BeginLine, cls.Region.BeginColumn, true);
 			} else if (item is LocalVariable) {
-				LocalVariable cls = (LocalVariable) item;
-				return cls.Region != null;
+				LocalVariable lvar = (LocalVariable) item;
+				IdeApp.Workbench.OpenDocument (file, lvar.Region.BeginLine, lvar.Region.BeginColumn, true);
 			}
-			return false;
 		}
 		
 		string GetClassFileName (IClass cls)


More information about the Monodevelop-list mailing list