diff options
author | Lluis Sanchez <lluis@novell.com> | 2007-12-04 13:54:06 +0300 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2007-12-04 13:54:06 +0300 |
commit | fb3d82535d1eb51b03b9df5c8c3b24c0e6fa6d92 (patch) | |
tree | 5c9c507ec718981e2dda5406e126b8efd02fa3b2 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad | |
parent | 6342b2ae0820167754b9f39077777520e20c08a0 (diff) |
Directory reorganization
svn path=/branches/monodevelop/reorg/; revision=90640
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad')
12 files changed, 1174 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ClassData.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ClassData.cs new file mode 100644 index 0000000000..1e2f17a32c --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ClassData.cs @@ -0,0 +1,75 @@ +// +// ClassData.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class ClassData + { + IClass cls; + Project project; + + public ClassData (Project p, IClass c) + { + cls = c; + project = p; + } + + public IClass Class { + get { return cls; } + } + + public Project Project { + get { return project; } + } + + public override bool Equals (object ob) + { + ClassData other = ob as ClassData; + return (other != null && cls.FullyQualifiedName == other.cls.FullyQualifiedName && + project == other.project); + } + + public override int GetHashCode () + { + return (cls.FullyQualifiedName + project.Name).GetHashCode (); + } + + public override string ToString () + { + return base.ToString () + " [" + cls.FullyQualifiedName + ", " + project.Name + "]"; + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ClassNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ClassNodeBuilder.cs new file mode 100644 index 0000000000..1e4c06d157 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ClassNodeBuilder.cs @@ -0,0 +1,152 @@ +// +// ClassNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; +using System.Text; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Ide.Gui; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class ClassNodeBuilder: TypeNodeBuilder + { + public override Type NodeDataType { + get { return typeof(ClassData); } + } + + public override Type CommandHandlerType { + get { return typeof(ClassNodeCommandHandler); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Class"; } + } + + public override string GetNodeName (ITreeNavigator thisNode, object dataObject) + { + return GetNameWithGenericParameters(((ClassData)dataObject).Class); + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + ClassData classData = dataObject as ClassData; + label = GetNameWithGenericParameters(classData.Class); + icon = Context.GetIcon (Services.Icons.GetIcon (classData.Class)); + } + + private string GetNameWithGenericParameters (IClass c) + { + if (c.GenericParameters != null && c.GenericParameters.Count > 0) + { + StringBuilder builder = new StringBuilder (c.Name); + builder.Append("<"); + for (int i = 0; i < c.GenericParameters.Count; i++) + { + builder.Append(c.GenericParameters[i].Name); + if (i + 1 < c.GenericParameters.Count) builder.Append(", "); + } + builder.Append(">"); + return builder.ToString(); + } + else + return c.Name; + } + + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) + { + ClassData classData = dataObject as ClassData; + bool publicOnly = builder.Options ["PublicApiOnly"]; + + // Delegates have an Invoke method, which doesn't need to be shown. + if (classData.Class.ClassType == ClassType.Delegate) + return; + + foreach (IClass innerClass in classData.Class.InnerClasses) + if (innerClass.IsPublic || !publicOnly) + builder.AddChild (new ClassData (classData.Project, innerClass)); + + foreach (IMethod method in classData.Class.Methods) + if (method.IsPublic || !publicOnly) + builder.AddChild (method); + + foreach (IProperty property in classData.Class.Properties) + if (property.IsPublic || !publicOnly) + builder.AddChild (property); + + foreach (IField field in classData.Class.Fields) + if (field.IsPublic || !publicOnly) + builder.AddChild (field); + + foreach (IEvent e in classData.Class.Events) + if (e.IsPublic || !publicOnly) + builder.AddChild (e); + } + + public override bool HasChildNodes (ITreeBuilder builder, object dataObject) + { + ClassData classData = dataObject as ClassData; + return classData.Class.InnerClasses.Count > 0 || + classData.Class.Methods.Count > 0 || + classData.Class.Properties.Count > 0 || + classData.Class.Fields.Count > 0 || + classData.Class.Events.Count > 0; + } + + public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) + { + if (thisNode.DataItem is ClassData) + return DefaultSort; + else + return 1; + } + } + + public class ClassNodeCommandHandler: NodeCommandHandler + { + public override void ActivateItem () + { + ClassData cls = CurrentNode.DataItem as ClassData; + string file = GetFileName (); + int line = cls.Class.Region.BeginLine; + + IdeApp.Workbench.OpenDocument (file, Math.Max (1, line), 1, true); + } + + string GetFileName () + { + ClassData cls = (ClassData) CurrentNode.GetParentDataItem (typeof(ClassData), true); + if (cls != null && cls.Class.Region.FileName != null) return cls.Class.Region.FileName; + return null; + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/CombineNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/CombineNodeBuilder.cs new file mode 100644 index 0000000000..1683abdcb2 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/CombineNodeBuilder.cs @@ -0,0 +1,148 @@ +// +// CombineNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class CombineNodeBuilder: TypeNodeBuilder + { + CombineEntryChangeEventHandler combineEntryAdded; + CombineEntryChangeEventHandler combineEntryRemoved; + CombineEntryRenamedEventHandler combineNameChanged; + + public CombineNodeBuilder () + { + combineEntryAdded = (CombineEntryChangeEventHandler) DispatchService.GuiDispatch (new CombineEntryChangeEventHandler (OnEntryAdded)); + combineEntryRemoved = (CombineEntryChangeEventHandler) DispatchService.GuiDispatch (new CombineEntryChangeEventHandler (OnEntryRemoved)); + combineNameChanged = (CombineEntryRenamedEventHandler) DispatchService.GuiDispatch (new CombineEntryRenamedEventHandler (OnCombineRenamed)); + } + + public override Type NodeDataType { + get { return typeof(Combine); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Combine"; } + } + + public override string GetNodeName (ITreeNavigator thisNode, object dataObject) + { + return ((Combine)dataObject).Name; + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + Combine combine = dataObject as Combine; + label = GettextCatalog.GetString ("Solution {0}", combine.Name); + icon = Context.GetIcon (Stock.Solution); + } + + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) + { + Combine combine = (Combine) dataObject; + if (builder.Options ["ShowProjects"]) { + foreach (CombineEntry entry in combine.Entries) + builder.AddChild (entry); + } else { + AddClasses (builder, combine); + } + } + + void AddClasses (ITreeBuilder builder, CombineEntry entry) + { + if (entry is Combine) { + foreach (CombineEntry e in ((Combine)entry).Entries) + AddClasses (builder, e); + } else if (entry is Project) { + ProjectNodeBuilder.BuildChildNodes (builder, entry as Project); + } + } + + public override bool HasChildNodes (ITreeBuilder builder, object dataObject) + { + return ((Combine) dataObject).Entries.Count > 0; + } + + public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) + { + if (otherNode.DataItem is Combine) + return DefaultSort; + else + return -1; + } + + public override void OnNodeAdded (object dataObject) + { + Combine combine = (Combine) dataObject; + combine.EntryAdded += combineEntryAdded; + combine.EntryRemoved += combineEntryRemoved; + combine.NameChanged += combineNameChanged; + } + + public override void OnNodeRemoved (object dataObject) + { + Combine combine = (Combine) dataObject; + combine.EntryAdded -= combineEntryAdded; + combine.EntryRemoved -= combineEntryRemoved; + combine.NameChanged -= combineNameChanged; + } + + void OnEntryAdded (object sender, CombineEntryEventArgs e) + { + DispatchService.GuiDispatch (OnAddEntry, e.CombineEntry); + } + + void OnAddEntry (object newEntry) + { + CombineEntry e = (CombineEntry) newEntry; + ITreeBuilder tb = Context.GetTreeBuilder (e.ParentCombine); + if (tb != null) { + tb.AddChild (e, true); + tb.Expanded = true; + } + } + + void OnEntryRemoved (object sender, CombineEntryEventArgs e) + { + ITreeBuilder tb = Context.GetTreeBuilder (e.CombineEntry); + if (tb != null) tb.Remove (); + } + + void OnCombineRenamed (object sender, CombineEntryRenamedEventArgs e) + { + ITreeBuilder tb = Context.GetTreeBuilder (e.CombineEntry); + if (tb != null) tb.Update (); + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/EventNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/EventNodeBuilder.cs new file mode 100644 index 0000000000..853f2ebc19 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/EventNodeBuilder.cs @@ -0,0 +1,64 @@ +// +// EventNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class EventNodeBuilder: MemberNodeBuilder + { + public override Type NodeDataType { + get { return typeof(IEvent); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Event"; } + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + IEvent data = dataObject as IEvent; + label = data.Name; + icon = Context.GetIcon (Services.Icons.GetIcon (data)); + } + + public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) + { + if (thisNode.Options ["GroupByType"]) { + + } + return DefaultSort; + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/FieldNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/FieldNodeBuilder.cs new file mode 100644 index 0000000000..88855017f3 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/FieldNodeBuilder.cs @@ -0,0 +1,56 @@ +// +// FieldNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class FieldNodeBuilder: MemberNodeBuilder + { + public override Type NodeDataType { + get { return typeof(IField); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Field"; } + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + IField data = dataObject as IField; + label = data.Name; + icon = Context.GetIcon (Services.Icons.GetIcon (data)); + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeBuilder.cs new file mode 100644 index 0000000000..f5623c972c --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeBuilder.cs @@ -0,0 +1,86 @@ +// +// MemberNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public abstract class MemberNodeBuilder: TypeNodeBuilder + { + public override string GetNodeName (ITreeNavigator thisNode, object dataObject) + { + return ((IMember)dataObject).Name; + } + + public override Type CommandHandlerType { + get { return typeof(MemberNodeCommandHandler); } + } + + public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) + { + if (!(otherNode.DataItem is IMember)) return 1; + + if (thisNode.Options ["GroupByType"]) { + int v1 = GetTypeSortValue (thisNode.DataItem); + int v2 = GetTypeSortValue (otherNode.DataItem); + if (v1 < v2) return -1; + else if (v1 > v2) return 1; + } + if (thisNode.Options ["GroupByAccess"]) { + int v1 = GetAccessSortValue (((IMember)thisNode.DataItem).Modifiers); + int v2 = GetAccessSortValue (((IMember)otherNode.DataItem).Modifiers); + if (v1 < v2) return -1; + else if (v1 > v2) return 1; + } + return DefaultSort; + } + + int GetTypeSortValue (object member) + { + if (member is IField) return 0; + if (member is IEvent) return 1; + if (member is IProperty) return 2; + if (member is IMethod) return 3; + return 4; + } + + int GetAccessSortValue (ModifierEnum mods) + { + if ((mods & ModifierEnum.Private) != 0) return 0; + if ((mods & ModifierEnum.Internal) != 0) return 1; + if ((mods & ModifierEnum.Protected) != 0) return 2; + if ((mods & ModifierEnum.Public) != 0) return 3; + return 4; + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs new file mode 100644 index 0000000000..b01a321ed4 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MemberNodeCommandHandler.cs @@ -0,0 +1,46 @@ +// +// MemberNodeCommandHandler.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; + +using MonoDevelop.Projects.Parser; +using MonoDevelop.Core; +using MonoDevelop.Ide.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class MemberNodeCommandHandler: NodeCommandHandler + { + public override void ActivateItem () + { + ILanguageItem member = CurrentNode.DataItem as ILanguageItem; + IdeApp.ProjectOperations.JumpToDeclaration(member); + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MethodNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MethodNodeBuilder.cs new file mode 100644 index 0000000000..71f05fe145 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/MethodNodeBuilder.cs @@ -0,0 +1,56 @@ +// +// MethodNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class MethodNodeBuilder: MemberNodeBuilder + { + public override Type NodeDataType { + get { return typeof(IMethod); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Method"; } + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + IMethod data = dataObject as IMethod; + label = data.Name; + icon = Context.GetIcon (Services.Icons.GetIcon (data)); + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/NamespaceData.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/NamespaceData.cs new file mode 100644 index 0000000000..40a503c163 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/NamespaceData.cs @@ -0,0 +1,83 @@ +// +// NamespaceData.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class NamespaceData + { + string namesp; + Project project; + + public NamespaceData (Project p, string fullNamespace) + { + project = p; + namesp = fullNamespace; + } + + public string Name { + get { + int i = namesp.LastIndexOf ("."); + if (i != -1) return namesp.Substring (i+1); + else return namesp; + } + } + + public string FullName { + get { return namesp; } + } + + public Project Project { + get { return project; } + } + + public override bool Equals (object ob) + { + NamespaceData other = ob as NamespaceData; + return (other != null && namesp == other.namesp && project == other.project); + } + + public override int GetHashCode () + { + if (project != null) return (namesp + project.Name).GetHashCode (); + else return namesp.GetHashCode (); + } + + public override string ToString () + { + return base.ToString () + " [" + namesp + ", " + (project != null ? project.Name : "no project") + "]"; + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/NamespaceNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/NamespaceNodeBuilder.cs new file mode 100644 index 0000000000..6e51087110 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/NamespaceNodeBuilder.cs @@ -0,0 +1,216 @@ +// +// NamespaceNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Ide.Gui; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class NamespaceNodeBuilder: TypeNodeBuilder + { + ClassInformationEventHandler changeClassInformationHandler; + + public override Type NodeDataType { + get { return typeof(NamespaceData); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Namespace"; } + } + + protected override void Initialize () + { + changeClassInformationHandler = (ClassInformationEventHandler) DispatchService.GuiDispatch (new ClassInformationEventHandler (OnClassInformationChanged)); + IdeApp.ProjectOperations.ParserDatabase.ClassInformationChanged += changeClassInformationHandler; + } + + public override void Dispose () + { + IdeApp.ProjectOperations.ParserDatabase.ClassInformationChanged -= changeClassInformationHandler; + } + + public override string GetNodeName (ITreeNavigator thisNode, object dataObject) + { + return thisNode.Options ["NestedNamespaces"] ? ((NamespaceData)dataObject).Name : ((NamespaceData)dataObject).FullName; + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + NamespaceData nsData = dataObject as NamespaceData; + label = treeBuilder.Options ["NestedNamespaces"] ? nsData.Name : nsData.FullName; + icon = Context.GetIcon (Stock.NameSpace); + } + + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) + { + NamespaceData nsData = dataObject as NamespaceData; + + if (nsData.Project != null) { + IParserContext ctx = IdeApp.ProjectOperations.ParserDatabase.GetProjectParserContext (nsData.Project); + LanguageItemCollection list = ctx.GetNamespaceContents (nsData.FullName, false); + AddProjectContent (builder, nsData.Project, nsData, list); + } + else { + foreach (Project p in IdeApp.ProjectOperations.CurrentOpenCombine.GetAllProjects ()) { + IParserContext ctx = IdeApp.ProjectOperations.ParserDatabase.GetProjectParserContext (p); + LanguageItemCollection list = ctx.GetNamespaceContents (nsData.FullName, false); + AddProjectContent (builder, p, nsData, list); + } + } + + } + + void AddProjectContent (ITreeBuilder builder, Project project, NamespaceData nsData, LanguageItemCollection list) + { + bool nestedNs = builder.Options ["NestedNamespaces"]; + bool publicOnly = builder.Options ["PublicApiOnly"]; + + foreach (ILanguageItem ob in list) { + if (ob is Namespace && nestedNs) { + Namespace nsob = (Namespace)ob; + string ns = nsData.FullName + "." + nsob.Name; + if (!builder.HasChild (nsob.Name, typeof(NamespaceData))) + builder.AddChild (new NamespaceData (project, ns)); + } + else if (ob is IClass) { + if (!publicOnly || ((IClass)ob).IsPublic) + builder.AddChild (new ClassData (project, ob as IClass)); + } + } + } + + void OnClassInformationChanged (object sender, ClassInformationEventArgs e) + { + Hashtable oldStatus = new Hashtable (); + ArrayList namespacesToClean = new ArrayList (); + ITreeBuilder tb = Context.GetTreeBuilder (); + + foreach (IClass cls in e.ClassInformation.Removed) { + if (tb.MoveToObject (new ClassData (e.Project, cls))) { + oldStatus [tb.DataItem] = tb.Expanded; + + ITreeNavigator np = tb.Clone (); + np.MoveToParent (); + oldStatus [np.DataItem] = np.Expanded; + + tb.Remove (true); + } + namespacesToClean.Add (cls.Namespace); + } + + foreach (IClass cls in e.ClassInformation.Modified) { + if (tb.MoveToObject (new ClassData (e.Project, cls))) { + oldStatus [tb.DataItem] = tb.Expanded; + + ITreeNavigator np = tb.Clone (); + np.MoveToParent (); + oldStatus [np.DataItem] = np.Expanded; + + tb.Remove (true); + tb.AddChild (new ClassData (e.Project, cls)); + } + } + + foreach (IClass cls in e.ClassInformation.Added) { + AddClass (e.Project, cls); + } + + // Clean empty namespaces + + foreach (string ns in namespacesToClean) { + string subns = ns; + while (subns != null) { + bool found = tb.MoveToObject (new NamespaceData (e.Project, subns)); + if (!found) found = tb.MoveToObject (new NamespaceData (null, subns)); + if (found) { + while (tb.DataItem is NamespaceData && !tb.HasChildren()) + tb.Remove (true); + break; + } + int i = subns.LastIndexOf ('.'); + if (i != -1) subns = subns.Substring (0,i); + else subns = null; + } + } + + // Restore expand status + + foreach (DictionaryEntry de in oldStatus) { + if ((bool)de.Value && tb.MoveToObject (de.Key)) { + tb.ExpandToNode (); + tb.Expanded = true; + } + } + } + + void AddClass (Project project, IClass cls) + { + ITreeBuilder builder = Context.GetTreeBuilder (); + if (!builder.MoveToObject (project)) { + return; // The project is not there or may not yet be expanded + } + + if (cls.Namespace == "") { + builder.AddChild (new ClassData (project, cls)); + } else { + if (builder.Options ["NestedNamespaces"]) { + string[] nsparts = cls.Namespace.Split ('.'); + string ns = ""; + foreach (string nsp in nsparts) { + if (builder.Filled) { + if (ns.Length > 0) ns += "."; + ns += nsp; + if (!builder.MoveToChild (nsp, typeof(NamespaceData))) { + builder.AddChild (new NamespaceData (project, ns), true); + break; + } + } else + break; + } + builder.AddChild (new ClassData (project, cls)); + } else { + if (builder.MoveToChild (cls.Namespace, typeof(NamespaceData))) + builder.AddChild (new ClassData (project, cls)); + else + builder.AddChild (new NamespaceData (project, cls.Namespace)); + } + } + } + + public override bool HasChildNodes (ITreeBuilder builder, object dataObject) + { + return true; + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ProjectNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ProjectNodeBuilder.cs new file mode 100644 index 0000000000..f527aa3e2a --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/ProjectNodeBuilder.cs @@ -0,0 +1,136 @@ +// +// ProjectNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; +using System.Collections; +using System.Text; + +using MonoDevelop.Projects; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Core; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class ProjectNodeBuilder: TypeNodeBuilder + { + CombineEntryRenamedEventHandler projectNameChanged; + + public ProjectNodeBuilder () + { + projectNameChanged = (CombineEntryRenamedEventHandler) DispatchService.GuiDispatch (new CombineEntryRenamedEventHandler (OnProjectRenamed)); + } + + public override Type NodeDataType { + get { return typeof(Project); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Project"; } + } + + public override void OnNodeAdded (object dataObject) + { + Project project = (Project) dataObject; + project.NameChanged += projectNameChanged; + } + + public override void OnNodeRemoved (object dataObject) + { + Project project = (Project) dataObject; + project.NameChanged -= projectNameChanged; + } + + public override string GetNodeName (ITreeNavigator thisNode, object dataObject) + { + return ((Project)dataObject).Name; + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + Project p = dataObject as Project; + label = p.Name; + string iconName = Services.Icons.GetImageForProjectType (p.ProjectType); + icon = Context.GetIcon (iconName); + } + + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) + { + Project project = (Project) dataObject; + BuildChildNodes (builder, project); + } + + public static void BuildChildNodes (ITreeBuilder builder, Project project) + { + bool publicOnly = builder.Options ["PublicApiOnly"]; + + IParserContext ctx = IdeApp.ProjectOperations.ParserDatabase.GetProjectParserContext (project); + LanguageItemCollection list = ctx.GetNamespaceContents ("", false); + foreach (ILanguageItem ob in list) { + if (ob is Namespace) { + if (builder.Options ["NestedNamespaces"]) + builder.AddChild (new NamespaceData (project, ((Namespace)ob).Name)); + else { + FillNamespaces (builder, project, ((Namespace)ob).Name); + } + } + else if (!publicOnly || ((IClass)ob).IsPublic) + builder.AddChild (new ClassData (project, ob as IClass)); + } + } + + public static void FillNamespaces (ITreeBuilder builder, Project project, string ns) + { + IParserContext ctx = IdeApp.ProjectOperations.ParserDatabase.GetProjectParserContext (project); + if (ctx.GetClassList (ns, false, true).Length > 0) { + if (builder.Options ["ShowProjects"]) + builder.AddChild (new NamespaceData (project, ns)); + else { + if (!builder.HasChild (ns, typeof (NamespaceData))) + builder.AddChild (new NamespaceData (null, ns)); + } + } + + string[] list = ctx.GetNamespaceList (ns, false, true); + foreach (string subns in list) + FillNamespaces (builder, project, ns + "." + subns); + } + + public override bool HasChildNodes (ITreeBuilder builder, object dataObject) + { + return true; + } + + void OnProjectRenamed (object sender, CombineEntryRenamedEventArgs e) + { + ITreeBuilder tb = Context.GetTreeBuilder (e.CombineEntry); + if (tb != null) tb.Update (); + } + } +} diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/PropertyNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/PropertyNodeBuilder.cs new file mode 100644 index 0000000000..42451b062f --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ClassPad/PropertyNodeBuilder.cs @@ -0,0 +1,56 @@ +// +// PropertyNodeBuilder.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Parser; +using MonoDevelop.Core.Gui; + +namespace MonoDevelop.Ide.Gui.Pads.ClassPad +{ + public class PropertyNodeBuilder: MemberNodeBuilder + { + public override Type NodeDataType { + get { return typeof(IProperty); } + } + + public override string ContextMenuAddinPath { + get { return "/MonoDevelop/Ide/ContextMenu/ClassPad/Property"; } + } + + public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) + { + IProperty data = dataObject as IProperty; + label = data.Name; + icon = Context.GetIcon (Services.Icons.GetIcon (data)); + } + } +} |