diff options
author | Levi Bard <levi@unity3d.com> | 2010-11-05 20:08:29 +0300 |
---|---|---|
committer | Lluis Sanchez <slluis.devel@gmail.com> | 2010-12-23 18:44:38 +0300 |
commit | 6b2c51ea74c9da8a3f1bdc8d475261924d8d607c (patch) | |
tree | 2deecad1963422753710b87af1507399a6031c78 /extras/ValaBinding | |
parent | 0f283d995f66a014bf128f1c9ef4734f8c06eb32 (diff) |
[Vala] Add pathbar support.
* Makefile.am:
* ValaBinding.csproj:
* Gui/DataProvider.cs:
* Gui/ParameterDataProvider.cs:
* Gui/CompilationUnitDataProvider.cs:
* Gui/ValaTextEditorExtension.cs:
Add pathbar support.
License: MIT/X11
Diffstat (limited to 'extras/ValaBinding')
-rw-r--r-- | extras/ValaBinding/Gui/CompilationUnitDataProvider.cs | 98 | ||||
-rw-r--r-- | extras/ValaBinding/Gui/DataProvider.cs | 307 | ||||
-rw-r--r-- | extras/ValaBinding/Gui/ParameterDataProvider.cs | 285 | ||||
-rw-r--r-- | extras/ValaBinding/Gui/ValaTextEditorExtension.cs | 123 | ||||
-rw-r--r-- | extras/ValaBinding/Makefile.am | 2 | ||||
-rw-r--r-- | extras/ValaBinding/ValaBinding.csproj | 4 |
6 files changed, 581 insertions, 238 deletions
diff --git a/extras/ValaBinding/Gui/CompilationUnitDataProvider.cs b/extras/ValaBinding/Gui/CompilationUnitDataProvider.cs new file mode 100644 index 0000000000..1e74f3138b --- /dev/null +++ b/extras/ValaBinding/Gui/CompilationUnitDataProvider.cs @@ -0,0 +1,98 @@ +// +// CompilationUnitDataProvider.cs +// +// Author: +// Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com> +// +// Copyright (c) 2010 Levi Bard +// +// This source code is licenced under The MIT License: +// +// 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.Linq; + +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.Ide.Gui.Content; +using MonoDevelop.Ide.CodeCompletion; +using MonoDevelop.Components; +using MonoDevelop.Projects.Dom; + +using Gtk; + +namespace MonoDevelop.ValaBinding +{ + // Yoinked from C# binding + public class CompilationUnitDataProvider : DropDownBoxListWindow.IListDataProvider + { + Document Document { get; set; } + + public CompilationUnitDataProvider (Document document) + { + this.Document = document; + }// constructor + + #region IListDataProvider implementation + public void Reset () { } + + public string GetText (int n) + { + return Document.ParsedDocument.UserRegions.ElementAt (n).Name; + }// GetText + + internal static Gdk.Pixbuf Pixbuf + { + get { return ImageService.GetPixbuf (Gtk.Stock.Add, IconSize.Menu); } + }// Pixbuf + + public Gdk.Pixbuf GetIcon (int n) + { + return Pixbuf; + }// GetIcon + + public object GetTag (int n) + { + return Document.ParsedDocument.UserRegions.ElementAt (n); + }// GetTag + + + public void ActivateItem (int n) + { + var reg = Document.ParsedDocument.UserRegions.ElementAt (n); + MonoDevelop.Ide.Gui.Content.IExtensibleTextEditor extEditor = Document.GetContent<MonoDevelop.Ide.Gui.Content.IExtensibleTextEditor> (); + if (extEditor != null) + extEditor.SetCaretTo (Math.Max (1, reg.Region.Start.Line), reg.Region.Start.Column); + }// ActivateItem + + public int IconCount + { + get { + if (Document.ParsedDocument == null) + return 0; + return Document.ParsedDocument.UserRegions.Count (); + } + }// IconCount + + #endregion + }// CompilationUnitDataProvider +} + diff --git a/extras/ValaBinding/Gui/DataProvider.cs b/extras/ValaBinding/Gui/DataProvider.cs index d047bca3ef..e49d6f2a41 100644 --- a/extras/ValaBinding/Gui/DataProvider.cs +++ b/extras/ValaBinding/Gui/DataProvider.cs @@ -1,12 +1,11 @@ -// -// DataProvider.cs -// -// Authors: -// Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com> -// -// Copyright (C) 2008 Levi Bard -// Based on CBinding by Marcos David Marin Amador <MarcosMarin@gmail.com> -// +// +// DataProvider.cs +// +// Author: +// Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com> +// +// Copyright (c) 2010 Levi Bard +// // This source code is licenced under The MIT License: // // Permission is hereby granted, free of charge, to any person obtaining @@ -28,258 +27,92 @@ // 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.Collections.Generic; -using System.Text.RegularExpressions; -using System.Threading; -using MonoDevelop.Core; - +using MonoDevelop.Ide; using MonoDevelop.Ide.Gui; +using MonoDevelop.Ide.Gui.Content; using MonoDevelop.Ide.CodeCompletion; +using MonoDevelop.Components; +using MonoDevelop.Projects.Dom; +using MonoDevelop.Projects.Dom.Output; -using MonoDevelop.ValaBinding.Parser; -using MonoDevelop.ValaBinding.Parser.Afrodite; +using Gtk; namespace MonoDevelop.ValaBinding { - public class ParameterDataProvider : IParameterDataProvider + // Yoinked from C# binding + public class DataProvider : DropDownBoxListWindow.IListDataProvider { - Document document; - private IList<Symbol> functions; - private string functionName; + object tag; + Ambience amb; + List<IMember> memberList = new List<IMember> (); - public ParameterDataProvider (Document document, ProjectInformation info, string functionName) - { - this.document = document; - this.functionName = functionName; - - functions = new List<Symbol> (); - Symbol function = info.GetFunction (functionName, document.FileName, document.Editor.Caret.Line + 1, document.Editor.Caret.Column + 1); - if (null != function){ functions.Add (function); } - }// member function constructor + Document Document { get; set; } - /// <summary> - /// Create a ParameterDataProvider for a constructor - /// </summary> - /// <param name="constructorOverload"> - /// A <see cref="System.String"/>: The named of the pertinent constructor overload - /// </param> - public ParameterDataProvider (Document document, ProjectInformation info, string typename, string constructorOverload) + public DataProvider (Document doc, object tag, Ambience amb) + { + this.Document = doc; + this.tag = ((INode)tag).Parent; + this.amb = amb; + Reset (); + }// constructor + + #region IListDataProvider implementation + public void Reset () { - this.functionName = constructorOverload; - this.document = document; - - List<Symbol> myfunctions = info.GetConstructorsForType (typename, document.FileName, document.Editor.Caret.Line + 1, document.Editor.Caret.Column + 1, null); // bottleneck - if (1 < myfunctions.Count) { - foreach (Symbol function in myfunctions) { - if (functionName.Equals (function.Name, StringComparison.Ordinal)) { - functions = new List<Symbol> () {function}; - return; - } + memberList.Clear (); + if (tag is ICompilationUnit) { + Stack<IType> types = new Stack<IType> (((ICompilationUnit)tag).Types); + while (types.Count > 0) { + IType type = types.Pop (); + memberList.Add (type); + foreach (IType innerType in type.InnerTypes) + types.Push (innerType); } + } else if (tag is IType) { + memberList.AddRange (((IType)tag).Members); } - - functions = myfunctions; - }// constructor constructor - - /// <summary> - /// The number of overloads for this method - /// </summary> - public int OverloadCount { - get { return functions.Count; } - } + memberList.Sort ((x, y) => String.Compare (GetString (amb, x), GetString (amb, y), StringComparison.OrdinalIgnoreCase)); + }// Reset - /// <summary> - /// Get the index of the parameter where the cursor is currently positioned. - /// </summary> - /// <param name="ctx"> - /// A <see cref="CodeCompletionContext"/> - /// </param> - /// <returns> - /// A <see cref="System.Int32"/>: The index of the parameter, - /// 0 for no parameter entered, - /// -1 for outside the list - /// </returns> - public int GetCurrentParameterIndex (ICompletionWidget widget, CodeCompletionContext ctx) + string GetString (Ambience amb, IMember x) { - int cursor = document.Editor.Caret.Offset; - int i = ctx.TriggerOffset; - - if (i > cursor) - return -1; - else if (i == cursor) - return 1; - - int parameterIndex = 1; - - while (i++ < cursor) { - char ch = document.Editor.GetCharAt (i-1); - if (ch == ',') - parameterIndex++; - else if (ch == ')') - return -1; - } - - return parameterIndex; - } + if (tag is ICompilationUnit) + return amb.GetString (x, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.UseFullInnerTypeName | OutputFlags.ReformatDelegates); + return amb.GetString (x, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates); + }// GetString - /// <summary> - /// Get the markup to use to represent the specified method overload - /// in the parameter information window. - /// </summary> - public string GetMethodMarkup (int overload, string[] parameterMarkup, int currentParameter) + public string GetText (int n) { - string paramTxt = string.Join (", ", parameterMarkup); - Symbol function = functions[overload]; - - int len = function.FullyQualifiedName.LastIndexOf ("."); - string prename = null; - - if (len > 0) - prename = function.FullyQualifiedName.Substring (0, len + 1); - -// string cons = string.Empty; - -// if (function.IsConst) -// cons = " const"; + return GetString (amb, memberList[n]); + }// GetText - return string.Format ("{2} {3}<b>{0}</b>({1})", GLib.Markup.EscapeText (function.Name), - paramTxt, - GLib.Markup.EscapeText (function.ReturnType.TypeName), - GLib.Markup.EscapeText (prename)); - // return prename + "<b>" + function.Name + "</b>" + " (" + paramTxt + ")" + cons; - } - - /// <summary> - /// Get the text to use to represent the specified parameter - /// </summary> - public string GetParameterMarkup (int overload, int paramIndex) - { - Symbol function = functions[overload]; - - if (null != function && null != function.Parameters[paramIndex]) { - string name = function.Parameters[paramIndex].Name; - string type = function.Parameters[paramIndex].TypeName; - return GLib.Markup.EscapeText (string.Format ("{1} {0}", name, type)); - } - - return string.Empty; - } - - /// <summary> - /// Get the number of parameters of the specified method - /// </summary> - public int GetParameterCount (int overload) - { - if (null != functions && null != functions[overload] && null != functions[overload].Parameters) { - return functions[overload].Parameters.Count; - } - return 0; - } - } - - /// <summary> - /// Data for Vala completion - /// </summary> - internal class CompletionData : MonoDevelop.Ide.CodeCompletion.CompletionData - { - private string image; - private string text; - private string description; - private string completion_string; - - public CompletionData (Symbol item) + public Gdk.Pixbuf GetIcon (int n) { - this.text = item.Name; - this.completion_string = item.Name; - this.description = item.DisplayText; - this.image = item.Icon; - DisplayFlags = DisplayFlags.None; - CompletionCategory = new ValaCompletionCategory (text, image); - } - - public override IconId Icon { - get { return image; } - } - - public override string DisplayText { - get { return text; } - } - - public override string Description { - get { return description; } - } + return ImageService.GetPixbuf (memberList[n].StockIcon, IconSize.Menu); + }// GetIcon - public override string CompletionText { - get { return completion_string; } - } - } - - internal class ValaCompletionDataList: CompletionDataList, IMutableCompletionDataList - { - public ValaCompletionDataList (): base () + public object GetTag (int n) { - IsChanging = true; - Add (string.Empty); - } - - internal virtual void AddRange (IEnumerable<CompletionData> vals) + return memberList[n]; + }// GetTag + + public void ActivateItem (int n) { - foreach (CompletionData item in vals) { - Add (item); - } - } - - #region IMutableCompletionDataList implementation - - public event EventHandler Changed; - public event EventHandler Changing; - - - public bool IsChanging { - get { return isChanging; } - set { - isChanging = value; - if (value){ OnChanging (this, null); } - else{ OnChanged (this, null); } + var member = memberList[n]; + MonoDevelop.Ide.Gui.Content.IExtensibleTextEditor extEditor = Document.GetContent<MonoDevelop.Ide.Gui.Content.IExtensibleTextEditor> (); + if (extEditor != null) + extEditor.SetCaretTo (Math.Max (1, member.Location.Line), member.Location.Column); + }// ActivateItem + + public int IconCount { + get { + return memberList.Count; } - } - private bool isChanging; - + }// IconCount #endregion - - protected virtual void OnChanging (object sender, EventArgs args) - { - if (null != Changing) { - Changing (sender, args); - } - } - - protected virtual void OnChanged (object sender, EventArgs args) - { - if (null != Changed) { - Changed (sender, args); - } - } - - public void Dispose () - { - } - }// ValaCompletionDataList - - internal class ValaCompletionCategory: CompletionCategory - { - public ValaCompletionCategory (string text, string image): base (text, image) - { - } - - public override int CompareTo (CompletionCategory other) - { - return DisplayText.CompareTo (other.DisplayText); - } - } + }// DataProvider } + diff --git a/extras/ValaBinding/Gui/ParameterDataProvider.cs b/extras/ValaBinding/Gui/ParameterDataProvider.cs new file mode 100644 index 0000000000..d047bca3ef --- /dev/null +++ b/extras/ValaBinding/Gui/ParameterDataProvider.cs @@ -0,0 +1,285 @@ +// +// DataProvider.cs +// +// Authors: +// Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com> +// +// Copyright (C) 2008 Levi Bard +// Based on CBinding by Marcos David Marin Amador <MarcosMarin@gmail.com> +// +// This source code is licenced under The MIT License: +// +// 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.Collections.Generic; +using System.Text.RegularExpressions; +using System.Threading; + +using MonoDevelop.Core; + +using MonoDevelop.Ide.Gui; +using MonoDevelop.Ide.CodeCompletion; + +using MonoDevelop.ValaBinding.Parser; +using MonoDevelop.ValaBinding.Parser.Afrodite; + +namespace MonoDevelop.ValaBinding +{ + public class ParameterDataProvider : IParameterDataProvider + { + Document document; + private IList<Symbol> functions; + private string functionName; + + public ParameterDataProvider (Document document, ProjectInformation info, string functionName) + { + this.document = document; + this.functionName = functionName; + + functions = new List<Symbol> (); + Symbol function = info.GetFunction (functionName, document.FileName, document.Editor.Caret.Line + 1, document.Editor.Caret.Column + 1); + if (null != function){ functions.Add (function); } + }// member function constructor + + /// <summary> + /// Create a ParameterDataProvider for a constructor + /// </summary> + /// <param name="constructorOverload"> + /// A <see cref="System.String"/>: The named of the pertinent constructor overload + /// </param> + public ParameterDataProvider (Document document, ProjectInformation info, string typename, string constructorOverload) + { + this.functionName = constructorOverload; + this.document = document; + + List<Symbol> myfunctions = info.GetConstructorsForType (typename, document.FileName, document.Editor.Caret.Line + 1, document.Editor.Caret.Column + 1, null); // bottleneck + if (1 < myfunctions.Count) { + foreach (Symbol function in myfunctions) { + if (functionName.Equals (function.Name, StringComparison.Ordinal)) { + functions = new List<Symbol> () {function}; + return; + } + } + } + + functions = myfunctions; + }// constructor constructor + + /// <summary> + /// The number of overloads for this method + /// </summary> + public int OverloadCount { + get { return functions.Count; } + } + + /// <summary> + /// Get the index of the parameter where the cursor is currently positioned. + /// </summary> + /// <param name="ctx"> + /// A <see cref="CodeCompletionContext"/> + /// </param> + /// <returns> + /// A <see cref="System.Int32"/>: The index of the parameter, + /// 0 for no parameter entered, + /// -1 for outside the list + /// </returns> + public int GetCurrentParameterIndex (ICompletionWidget widget, CodeCompletionContext ctx) + { + int cursor = document.Editor.Caret.Offset; + int i = ctx.TriggerOffset; + + if (i > cursor) + return -1; + else if (i == cursor) + return 1; + + int parameterIndex = 1; + + while (i++ < cursor) { + char ch = document.Editor.GetCharAt (i-1); + if (ch == ',') + parameterIndex++; + else if (ch == ')') + return -1; + } + + return parameterIndex; + } + + /// <summary> + /// Get the markup to use to represent the specified method overload + /// in the parameter information window. + /// </summary> + public string GetMethodMarkup (int overload, string[] parameterMarkup, int currentParameter) + { + string paramTxt = string.Join (", ", parameterMarkup); + Symbol function = functions[overload]; + + int len = function.FullyQualifiedName.LastIndexOf ("."); + string prename = null; + + if (len > 0) + prename = function.FullyQualifiedName.Substring (0, len + 1); + +// string cons = string.Empty; + +// if (function.IsConst) +// cons = " const"; + + return string.Format ("{2} {3}<b>{0}</b>({1})", GLib.Markup.EscapeText (function.Name), + paramTxt, + GLib.Markup.EscapeText (function.ReturnType.TypeName), + GLib.Markup.EscapeText (prename)); + // return prename + "<b>" + function.Name + "</b>" + " (" + paramTxt + ")" + cons; + } + + /// <summary> + /// Get the text to use to represent the specified parameter + /// </summary> + public string GetParameterMarkup (int overload, int paramIndex) + { + Symbol function = functions[overload]; + + if (null != function && null != function.Parameters[paramIndex]) { + string name = function.Parameters[paramIndex].Name; + string type = function.Parameters[paramIndex].TypeName; + return GLib.Markup.EscapeText (string.Format ("{1} {0}", name, type)); + } + + return string.Empty; + } + + /// <summary> + /// Get the number of parameters of the specified method + /// </summary> + public int GetParameterCount (int overload) + { + if (null != functions && null != functions[overload] && null != functions[overload].Parameters) { + return functions[overload].Parameters.Count; + } + return 0; + } + } + + /// <summary> + /// Data for Vala completion + /// </summary> + internal class CompletionData : MonoDevelop.Ide.CodeCompletion.CompletionData + { + private string image; + private string text; + private string description; + private string completion_string; + + public CompletionData (Symbol item) + { + this.text = item.Name; + this.completion_string = item.Name; + this.description = item.DisplayText; + this.image = item.Icon; + DisplayFlags = DisplayFlags.None; + CompletionCategory = new ValaCompletionCategory (text, image); + } + + public override IconId Icon { + get { return image; } + } + + public override string DisplayText { + get { return text; } + } + + public override string Description { + get { return description; } + } + + public override string CompletionText { + get { return completion_string; } + } + } + + internal class ValaCompletionDataList: CompletionDataList, IMutableCompletionDataList + { + public ValaCompletionDataList (): base () + { + IsChanging = true; + Add (string.Empty); + } + + internal virtual void AddRange (IEnumerable<CompletionData> vals) + { + foreach (CompletionData item in vals) { + Add (item); + } + } + + #region IMutableCompletionDataList implementation + + public event EventHandler Changed; + public event EventHandler Changing; + + + public bool IsChanging { + get { return isChanging; } + set { + isChanging = value; + if (value){ OnChanging (this, null); } + else{ OnChanged (this, null); } + } + } + private bool isChanging; + + #endregion + + protected virtual void OnChanging (object sender, EventArgs args) + { + if (null != Changing) { + Changing (sender, args); + } + } + + protected virtual void OnChanged (object sender, EventArgs args) + { + if (null != Changed) { + Changed (sender, args); + } + } + + public void Dispose () + { + } + }// ValaCompletionDataList + + internal class ValaCompletionCategory: CompletionCategory + { + public ValaCompletionCategory (string text, string image): base (text, image) + { + } + + public override int CompareTo (CompletionCategory other) + { + return DisplayText.CompareTo (other.DisplayText); + } + } +} diff --git a/extras/ValaBinding/Gui/ValaTextEditorExtension.cs b/extras/ValaBinding/Gui/ValaTextEditorExtension.cs index b751da0d31..e7a12f3aee 100644 --- a/extras/ValaBinding/Gui/ValaTextEditorExtension.cs +++ b/extras/ValaBinding/Gui/ValaTextEditorExtension.cs @@ -33,13 +33,22 @@ using System; using System.IO; using System.Text; +using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Threading; +using MonoDevelop.Ide; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Content; using MonoDevelop.Ide.CodeCompletion; +using MonoDevelop.Projects.Dom; +using MonoDevelop.Projects.Dom.Output; + +using MonoDevelop.Core; +using MonoDevelop.Components; + +using Gtk; using MonoDevelop.ValaBinding.Parser; @@ -65,6 +74,8 @@ namespace MonoDevelop.ValaBinding } }// Parser + protected Mono.TextEditor.TextEditorData textEditorData{ get; set; } + public override bool KeyPress (Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { string lineText = Editor.GetLineText (Editor.Caret.Line); @@ -296,5 +307,117 @@ namespace MonoDevelop.ValaBinding return true; } + + #region IPathedDocument implementation + public event EventHandler<DocumentPathChangedEventArgs> PathChanged; + + public Gtk.Widget CreatePathWidget (int index) + { + PathEntry[] path = CurrentPath; + if (null == path || 0 > index || path.Length <= index) { + return null; + } + + object tag = path[index].Tag; + DropDownBoxListWindow.IListDataProvider provider = null; + if (tag is ICompilationUnit) { + provider = new CompilationUnitDataProvider (Document); + } else { + provider = new DataProvider (Document, tag, GetAmbience ()); + } + + DropDownBoxListWindow window = new DropDownBoxListWindow (provider); + window.SelectItem (tag); + return window; + } + + public PathEntry[] CurrentPath { + get; + private set; + } + + protected virtual void OnPathChanged (DocumentPathChangedEventArgs args) + { + if (null != PathChanged) { + PathChanged (this, args); + } + } + #endregion + + // Yoinked from C# binding + void UpdatePath (object sender, Mono.TextEditor.DocumentLocationEventArgs e) + { + var unit = Document.CompilationUnit; + if (unit == null) + return; + + var loc = textEditorData.Caret.Location; + IType type = unit.GetTypeAt (loc.Line, loc.Column); + List<PathEntry> result = new List<PathEntry> (); + Ambience amb = GetAmbience (); + IMember member = null; + INode node = (INode)unit; + + if (type != null && type.ClassType != ClassType.Delegate) { + member = type.GetMemberAt (loc.Line, loc.Column); + } + + if (null != member) { + node = member; + } else if (null != type) { + node = type; + } + + while (node != null) { + PathEntry entry; + if (node is ICompilationUnit) { + if (!Document.ParsedDocument.UserRegions.Any ()) + break; + FoldingRegion reg = Document.ParsedDocument.UserRegions.Where (r => r.Region.Contains (loc.Line, loc.Column)).LastOrDefault (); + if (reg == null) { + entry = new PathEntry (GettextCatalog.GetString ("No region")); + } else { + entry = new PathEntry (CompilationUnitDataProvider.Pixbuf, reg.Name); + } + entry.Position = EntryPosition.Right; + } else { + entry = new PathEntry (ImageService.GetPixbuf (((IMember)node).StockIcon, IconSize.Menu), amb.GetString ((IMember)node, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates)); + } + entry.Tag = node; + result.Insert (0, entry); + node = node.Parent; + } + + PathEntry noSelection = null; + if (type == null) { + noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = new CustomNode (Document.CompilationUnit) }; + } else if (member == null && type.ClassType != ClassType.Delegate) + noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = new CustomNode (type) }; + if (noSelection != null) { + result.Add (noSelection); + } + + var prev = CurrentPath; + CurrentPath = result.ToArray (); + OnPathChanged (new DocumentPathChangedEventArgs (prev)); + } + + public override void Initialize () + { + base.Initialize (); + textEditorData = Document.Editor; + UpdatePath (null, null); + textEditorData.Caret.PositionChanged += UpdatePath; + Document.DocumentParsed += delegate { UpdatePath (null, null); }; + } + + // Yoinked from C# binding + class CustomNode : MonoDevelop.Projects.Dom.AbstractNode + { + public CustomNode (INode parent) + { + this.Parent = parent; + } + } } } diff --git a/extras/ValaBinding/Makefile.am b/extras/ValaBinding/Makefile.am index 7afab3c76d..1203dad655 100644 --- a/extras/ValaBinding/Makefile.am +++ b/extras/ValaBinding/Makefile.am @@ -27,11 +27,13 @@ FILES = \ Gui/AddLibraryDialog.cs \ Gui/AddPathDialog.cs \ Gui/CodeGenerationPanel.cs \ + Gui/CompilationUnitDataProvider.cs \ Gui/DataProvider.cs \ Gui/EditPackagesDialog.cs \ Gui/GeneralOptionsPanel.cs \ Gui/OutputOptionsPanel.cs \ Gui/PackageDetails.cs \ + Gui/ParameterDataProvider.cs \ Gui/ValaTextEditorExtension.cs \ Navigation/ClassPadEventArgs.cs \ Navigation/LanguageItemCommandHandler.cs \ diff --git a/extras/ValaBinding/ValaBinding.csproj b/extras/ValaBinding/ValaBinding.csproj index 836799124d..7bcd2d0894 100644 --- a/extras/ValaBinding/ValaBinding.csproj +++ b/extras/ValaBinding/ValaBinding.csproj @@ -210,7 +210,6 @@ <Compile Include="Parser\ProjectInformation.cs" /> <Compile Include="Parser\ProjectInformationManager.cs" /> <Compile Include="Gui\ValaTextEditorExtension.cs" /> - <Compile Include="Gui\DataProvider.cs" /> <Compile Include="gtk-gui\MonoDevelop.ValaBinding.AddLibraryDialog.cs" /> <Compile Include="gtk-gui\MonoDevelop.ValaBinding.CodeGenerationPanel.cs" /> <Compile Include="gtk-gui\MonoDevelop.ValaBinding.AddPathDialog.cs" /> @@ -233,6 +232,9 @@ <Compile Include="Navigation\LanguageItemNodeBuilder.cs" /> <Compile Include="Navigation\ProjectNodeBuilderExtension.cs" /> <Compile Include="Parser\ValaDocumentParser.cs" /> + <Compile Include="Gui\ParameterDataProvider.cs" /> + <Compile Include="Gui\CompilationUnitDataProvider.cs" /> + <Compile Include="Gui\DataProvider.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> |