diff options
author | Tak <levi@unity3d.com> | 2011-03-02 18:52:49 +0300 |
---|---|---|
committer | Lluis Sanchez <slluis.devel@gmail.com> | 2011-03-04 17:59:25 +0300 |
commit | 381c41f459f26793a39fb2715ad4e75d9a5d2d73 (patch) | |
tree | 51efa7f0b8489131e621eb1e5aac7a1a921d753a /main/src/addins/CBinding | |
parent | 9df7114e385ff13236b0ee48b88de0a18cc84f0c (diff) |
[C] Primitive 'Go to Declaration'
* CBinding.addin.xml:
* Project/CProject.cs: Add GoToDeclaration command.
* Gui/CTextEditorExtension.cs: Primitive 'Go to Declaration' implementation.
Diffstat (limited to 'main/src/addins/CBinding')
-rw-r--r-- | main/src/addins/CBinding/CBinding.addin.xml | 5 | ||||
-rw-r--r-- | main/src/addins/CBinding/Gui/CTextEditorExtension.cs | 42 | ||||
-rw-r--r-- | main/src/addins/CBinding/Project/CProject.cs | 3 |
3 files changed, 49 insertions, 1 deletions
diff --git a/main/src/addins/CBinding/CBinding.addin.xml b/main/src/addins/CBinding/CBinding.addin.xml index ef7f08e2df..3dd4bb4426 100644 --- a/main/src/addins/CBinding/CBinding.addin.xml +++ b/main/src/addins/CBinding/CBinding.addin.xml @@ -188,6 +188,7 @@ <Command id = "CBinding.CProjectCommands.AddPackage" _label = "Edit Packages..." /> <Command id = "CBinding.CProjectCommands.UpdateClassPad" _label = "Update class pad" icon = "res:update" /> <Command id = "CBinding.CProjectCommands.ShowPackageDetails" _label = "Details..." /> + <Command id = "CBinding.CProjectCommands.GotoDeclaration" _label = "Go to Declaration" /> </Category> </Extension> @@ -266,4 +267,8 @@ <Parser class = "CBinding.Parser.CDocumentParser" id = "CDocumentParser" fileExtensions=".c,.cpp,.cxx,.cc,.h,.hpp,.hh,.hxx" /> </Extension> + + <Extension path="/MonoDevelop/SourceEditor2/ContextMenu/Editor"> + <CommandItem id = "CBinding.CProjectCommands.GotoDeclaration"/> + </Extension> </Addin> diff --git a/main/src/addins/CBinding/Gui/CTextEditorExtension.cs b/main/src/addins/CBinding/Gui/CTextEditorExtension.cs index c9d40b51e9..124ef630d1 100644 --- a/main/src/addins/CBinding/Gui/CTextEditorExtension.cs +++ b/main/src/addins/CBinding/Gui/CTextEditorExtension.cs @@ -598,5 +598,47 @@ namespace CBinding completionContext.TriggerOffset = i-1; return accumulator+1; }// ResetTriggerOffset + + [CommandHandler (CBinding.CProjectCommands.GotoDeclaration)] + public void GotoDeclaration () + { + LanguageItem item = GetLanguageItemAt (Editor.Caret.Location); + if (item != null) + IdeApp.Workbench.OpenDocument ((FilePath)item.File, (int)item.Line, 1, true); + } + + [CommandUpdateHandler (CBinding.CProjectCommands.GotoDeclaration)] + public void CanGotoDeclaration (CommandInfo item) + { + item.Visible = (GetLanguageItemAt (Editor.Caret.Location) != null); + } + + private LanguageItem GetLanguageItemAt (DocumentLocation location) + { + CProject project = Document.Project as CProject; + string token = GetTokenAt (location); + if (project != null && !string.IsNullOrEmpty (token)) { + ProjectInformation info = ProjectInformationManager.Instance.Get (project); + return info.AllItems ().FirstOrDefault (i => i.Name.Equals (token, StringComparison.Ordinal)); + } + + return null; + } + + private string GetTokenAt (DocumentLocation location) + { + int lineOffset = location.Column-1; + string line = Editor.GetLineText (location.Line); + int first = line.LastIndexOfAny (allowedChars, lineOffset)+1, + last = line.IndexOfAny (allowedChars, lineOffset); + if (last < 0) last = line.Length - 1; + string token = string.Empty; + + if (first >= 0 && first < last && last < line.Length) { + token = line.Substring (first, last-first); + } + + return token.Trim (); + } } } diff --git a/main/src/addins/CBinding/Project/CProject.cs b/main/src/addins/CBinding/Project/CProject.cs index ce83b1e833..451bf39b07 100644 --- a/main/src/addins/CBinding/Project/CProject.cs +++ b/main/src/addins/CBinding/Project/CProject.cs @@ -59,7 +59,8 @@ namespace CBinding public enum CProjectCommands { AddPackage, UpdateClassPad, - ShowPackageDetails + ShowPackageDetails, + GotoDeclaration, } [DataInclude(typeof(CProjectConfiguration))] |