Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Bug 528093 - Provide pluggable 'Declaration' command
- Loading branch information
Showing
6 changed files
with
161 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
bundles/org.eclipse.orion.client.ui/web/orion/openDeclaration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /******************************************************************************* | ||
| * @license | ||
| * Copyright (c) 2017 IBM Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License v1.0 | ||
| * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution | ||
| * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| /*eslint-env browser, amd*/ | ||
| /*eslint-disable no-implicit-coercion */ | ||
| define([], function() { | ||
|
|
||
| /** | ||
| * @name OpenDeclaration | ||
| * @description Creates a new instance of the OpenDeclaration command | ||
| * @constructor | ||
| * @param {ServiceRegistry} serviceRegistry The backing service registry | ||
| * @param {InputManager} inputManager The backing input manager to get content type information from | ||
| * @param {EditorView} editor The editor view to work against | ||
| * @since 17.0 | ||
| */ | ||
| function OpenDeclaration(serviceRegistry, inputManager, editor) { | ||
| this.serviceRegistry = serviceRegistry; | ||
| this.inputManager = inputManager; | ||
| this.editor = editor; | ||
| } | ||
|
|
||
| function _getDelegate(data) { | ||
| var inputManagerContentType = data.inputManager.getContentType(); | ||
| var refs = data.serviceRegistry.getServiceReferences("orion.edit.open.declaration"); | ||
| for (var i = 0; i < refs.length; i++) { | ||
| var serviceReference = refs[i]; | ||
| var contentTypes = serviceReference.getProperty("contentType"); | ||
| if (inputManagerContentType && inputManagerContentType.id) { | ||
| var inputContentType = inputManagerContentType.id; | ||
| if (Array.isArray(contentTypes)) { | ||
| for (var j = 0, max = contentTypes.length; j < max; j++) { | ||
| if (contentTypes[j] === inputContentType) { | ||
| return data.serviceRegistry.getService(serviceReference); | ||
| } | ||
| } | ||
| } else if (inputContentType === contentTypes) { | ||
| return data.serviceRegistry.getService(serviceReference); | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| OpenDeclaration.prototype = { | ||
| /** | ||
| * @name isVisible | ||
| * @description Returns if this command should be visible or not | ||
| * @function | ||
| * @returns {boolean} 'true' if there is a delegate for the backing content type, 'false' otherwise | ||
| */ | ||
| isVisible: function isVisible() { | ||
| return !!_getDelegate(this); | ||
| }, | ||
| /** | ||
| * @name findDeclaration | ||
| * @description The delegate function that calls the service contribution | ||
| * @function | ||
| * @returns {?} The declaration location object | ||
| */ | ||
| findDeclaration: function findDeclaration() { | ||
| var service = _getDelegate(this); | ||
| if (service) { | ||
| var selection = this.editor.getSelection(); | ||
| var context = { | ||
| start: selection.start, | ||
| end: selection.end, | ||
| offset: selection.start, | ||
| input: this.inputManager.getInput() | ||
| }; | ||
| return service.findDeclaration(this.editor.getEditorContext(), context); | ||
| } | ||
| } | ||
| }; | ||
| return { | ||
| OpenDeclaration: OpenDeclaration | ||
| }; | ||
| }); |