提交 7cbf2790 编写于 作者: J Johannes Rieken

Merge pull request #6040 from Microsoft/joh/zonedebt

Joh/zonedebt
...@@ -28,7 +28,7 @@ import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/edito ...@@ -28,7 +28,7 @@ import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/edito
import {IReference, ReferenceSearchRegistry} from 'vs/editor/common/modes'; import {IReference, ReferenceSearchRegistry} from 'vs/editor/common/modes';
import {ICodeEditor} from 'vs/editor/browser/editorBrowser'; import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions'; import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {Events, IPeekViewService, getOuterEditor} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget'; import {IPeekViewService, getOuterEditor} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
import {findReferences} from '../common/referenceSearch'; import {findReferences} from '../common/referenceSearch';
import {EventType, ReferencesModel} from './referenceSearchModel'; import {EventType, ReferencesModel} from './referenceSearchModel';
import {ReferenceWidget} from './referenceSearchWidget'; import {ReferenceWidget} from './referenceSearchWidget';
...@@ -37,12 +37,12 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -37,12 +37,12 @@ export class FindReferencesController implements editorCommon.IEditorContributio
public static ID = 'editor.contrib.findReferencesController'; public static ID = 'editor.contrib.findReferencesController';
private editor:ICodeEditor; private _editor:ICodeEditor;
private widget:ReferenceWidget; private _widget:ReferenceWidget;
private requestIdPool: number; private _requestIdPool: number;
private callOnClear:Function[]; private _callOnClear:Function[];
private model:ReferencesModel; private _model:ReferencesModel;
private modelRevealing:boolean; private _modelRevealing:boolean;
private editorService: IEditorService; private editorService: IEditorService;
private telemetryService: ITelemetryService; private telemetryService: ITelemetryService;
...@@ -68,8 +68,8 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -68,8 +68,8 @@ export class FindReferencesController implements editorCommon.IEditorContributio
@IWorkspaceContextService contextService: IWorkspaceContextService, @IWorkspaceContextService contextService: IWorkspaceContextService,
@optional(IPeekViewService) peekViewService: IPeekViewService @optional(IPeekViewService) peekViewService: IPeekViewService
) { ) {
this.requestIdPool = 0; this._requestIdPool = 0;
this.callOnClear = []; this._callOnClear = [];
this.editorService = editorService; this.editorService = editorService;
this.telemetryService = telemetryService; this.telemetryService = telemetryService;
this.messageService = messageService; this.messageService = messageService;
...@@ -77,8 +77,8 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -77,8 +77,8 @@ export class FindReferencesController implements editorCommon.IEditorContributio
this.peekViewService = peekViewService; this.peekViewService = peekViewService;
this.contextService = contextService; this.contextService = contextService;
this.keybindingService = keybindingService; this.keybindingService = keybindingService;
this.modelRevealing = false; this._modelRevealing = false;
this.editor = editor; this._editor = editor;
this._referenceSearchVisible = keybindingService.createKey(CONTEXT_REFERENCE_SEARCH_VISIBLE, false); this._referenceSearchVisible = keybindingService.createKey(CONTEXT_REFERENCE_SEARCH_VISIBLE, false);
} }
...@@ -87,11 +87,11 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -87,11 +87,11 @@ export class FindReferencesController implements editorCommon.IEditorContributio
} }
public dispose(): void { public dispose(): void {
if (this.widget) { if (this._widget) {
this.widget.dispose(); this._widget.dispose();
this.widget = null; this._widget = null;
} }
this.editor = null; this._editor = null;
} }
public isInPeekView() : boolean { public isInPeekView() : boolean {
...@@ -103,7 +103,7 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -103,7 +103,7 @@ export class FindReferencesController implements editorCommon.IEditorContributio
} }
public processRequest(range: editorCommon.IEditorRange, referencesPromise: TPromise<IReference[]>, metaTitleFn:(references:IReference[])=>string) : ReferenceWidget { public processRequest(range: editorCommon.IEditorRange, referencesPromise: TPromise<IReference[]>, metaTitleFn:(references:IReference[])=>string) : ReferenceWidget {
var widgetPosition = !this.widget ? null : this.widget.position; var widgetPosition = !this._widget ? null : this._widget.position;
// clean up from previous invocation // clean up from previous invocation
var widgetClosed = this.clear(); var widgetClosed = this.clear();
...@@ -116,22 +116,26 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -116,22 +116,26 @@ export class FindReferencesController implements editorCommon.IEditorContributio
this._referenceSearchVisible.set(true); this._referenceSearchVisible.set(true);
// close the widget on model/mode changes // close the widget on model/mode changes
this.callOnClear.push(this.editor.addListener(editorCommon.EventType.ModelModeChanged, () => { this.clear(); })); this._callOnClear.push(this._editor.addListener(editorCommon.EventType.ModelModeChanged, () => { this.clear(); }));
this.callOnClear.push(this.editor.addListener(editorCommon.EventType.ModelChanged, () => { this._callOnClear.push(this._editor.addListener(editorCommon.EventType.ModelChanged, () => {
if(!this.modelRevealing) { if(!this._modelRevealing) {
this.clear(); this.clear();
} }
})); }));
this.widget = new ReferenceWidget(this.editorService, this.keybindingService, this.contextService, this.instantiationService, this.editor); this._widget = new ReferenceWidget(this.editorService, this.keybindingService, this.contextService, this.instantiationService, this._editor);
this.widget.setTitle(nls.localize('labelLoading', "Loading...")); this._widget.setTitle(nls.localize('labelLoading', "Loading..."));
this.widget.show(range, 18); this._widget.show(range, 18);
this.callOnClear.push(this.widget.addListener(Events.Closed, () => { this._callOnClear.push(this._widget.onDidClose(() => {
this.widget = null; this._widget = null;
referencesPromise.cancel();
this.clear(); this.clear();
})); }).dispose);
this.callOnClear.push(this.widget.addListener(ReferenceWidget.Events.EditorDoubleClick, (event:any) => {
this._callOnClear.push(() => {
referencesPromise.cancel();
});
this._callOnClear.push(this._widget.onDidDoubleClick(event => {
if(!event.reference) { if(!event.reference) {
return; return;
...@@ -147,9 +151,9 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -147,9 +151,9 @@ export class FindReferencesController implements editorCommon.IEditorContributio
if (!(event.originalEvent.ctrlKey || event.originalEvent.metaKey)) { if (!(event.originalEvent.ctrlKey || event.originalEvent.metaKey)) {
this.clear(); this.clear();
} }
})); }).dispose);
var requestId = ++this.requestIdPool, var requestId = ++this._requestIdPool,
editorModel = this.editor.getModel(); editorModel = this._editor.getModel();
var timer = this.telemetryService.timedPublicLog('findReferences', { var timer = this.telemetryService.timedPublicLog('findReferences', {
mode: editorModel.getMode().getId() mode: editorModel.getMode().getId()
...@@ -158,31 +162,31 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -158,31 +162,31 @@ export class FindReferencesController implements editorCommon.IEditorContributio
referencesPromise.then((references:IReference[]) => { referencesPromise.then((references:IReference[]) => {
// still current request? widget still open? // still current request? widget still open?
if(requestId !== this.requestIdPool || !this.widget) { if(requestId !== this._requestIdPool || !this._widget) {
timer.stop(); timer.stop();
return; return;
} }
// has a result // has a result
if (isFalsyOrEmpty(references)) { if (isFalsyOrEmpty(references)) {
this.widget.showMessage(nls.localize('noResults', "No results")); this._widget.showMessage(nls.localize('noResults', "No results"));
timer.stop(); timer.stop();
return; return;
} }
// create result model // create result model
this.model = new ReferencesModel(references, this.editorService); this._model = new ReferencesModel(references, this.editorService);
this.model.currentReference = this.model.findReference(editorModel.getAssociatedResource(), range.getStartPosition()); this._model.currentReference = this._model.findReference(editorModel.getAssociatedResource(), range.getStartPosition());
var unbind = this.model.addListener(EventType.CurrentReferenceChanged, () => { var unbind = this._model.addListener(EventType.CurrentReferenceChanged, () => {
this.modelRevealing = true; this._modelRevealing = true;
this.editorService.openEditor({ this.editorService.openEditor({
resource: this.model.currentReference.resource, resource: this._model.currentReference.resource,
options: { selection: this.model.currentReference.range } options: { selection: this._model.currentReference.range }
}).done((openedEditor) => { }).done((openedEditor) => {
if(!openedEditor || openedEditor.getControl() !== this.editor) { if(!openedEditor || openedEditor.getControl() !== this._editor) {
// TODO@Alex TODO@Joh // TODO@Alex TODO@Joh
// when opening the current reference we might end up // when opening the current reference we might end up
// in a different editor instance. that means we also have // in a different editor instance. that means we also have
...@@ -193,22 +197,22 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -193,22 +197,22 @@ export class FindReferencesController implements editorCommon.IEditorContributio
this.clear(); this.clear();
return; return;
} }
this.modelRevealing = false; this._modelRevealing = false;
this.widget.show(this.model.currentReference.range, 18); this._widget.show(this._model.currentReference.range, 18);
this.widget.focus(); this._widget.focus();
}, (err) => { }, (err) => {
this.modelRevealing = false; this._modelRevealing = false;
onUnexpectedError(err); onUnexpectedError(err);
}); });
}); });
this.callOnClear.push(unbind); this._callOnClear.push(unbind);
// show widget // show widget
this._startTime = Date.now(); this._startTime = Date.now();
if (this.widget) { if (this._widget) {
this.widget.setMetaTitle(metaTitleFn(references)); this._widget.setMetaTitle(metaTitleFn(references));
this.widget.setModel(this.model); this._widget.setModel(this._model);
} }
timer.stop(); timer.stop();
...@@ -217,7 +221,7 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -217,7 +221,7 @@ export class FindReferencesController implements editorCommon.IEditorContributio
timer.stop(); timer.stop();
}); });
return this.widget; return this._widget;
} }
private clear():boolean { private clear():boolean {
...@@ -232,19 +236,19 @@ export class FindReferencesController implements editorCommon.IEditorContributio ...@@ -232,19 +236,19 @@ export class FindReferencesController implements editorCommon.IEditorContributio
this._referenceSearchVisible.reset(); this._referenceSearchVisible.reset();
cAll(this.callOnClear); cAll(this._callOnClear);
this.model = null; this._model = null;
var result = false; var result = false;
if(this.widget) { if(this._widget) {
this.widget.dispose(); this._widget.dispose();
this.widget = null; this._widget = null;
result = true; result = true;
} }
this.editor.focus(); this._editor.focus();
this.requestIdPool += 1; // Cancel pending requests this._requestIdPool += 1; // Cancel pending requests
return result; return result;
} }
......
...@@ -9,6 +9,7 @@ import * as nls from 'vs/nls'; ...@@ -9,6 +9,7 @@ import * as nls from 'vs/nls';
import * as collections from 'vs/base/common/collections'; import * as collections from 'vs/base/common/collections';
import {onUnexpectedError} from 'vs/base/common/errors'; import {onUnexpectedError} from 'vs/base/common/errors';
import {getPathLabel} from 'vs/base/common/labels'; import {getPathLabel} from 'vs/base/common/labels';
import Event, {Emitter} from 'vs/base/common/event';
import {IDisposable, cAll, dispose} from 'vs/base/common/lifecycle'; import {IDisposable, cAll, dispose} from 'vs/base/common/lifecycle';
import {Schemas} from 'vs/base/common/network'; import {Schemas} from 'vs/base/common/network';
import * as strings from 'vs/base/common/strings'; import * as strings from 'vs/base/common/strings';
...@@ -47,25 +48,24 @@ class DecorationsManager implements IDisposable { ...@@ -47,25 +48,24 @@ class DecorationsManager implements IDisposable {
private _decorationSet = collections.createStringDictionary<OneReference>(); private _decorationSet = collections.createStringDictionary<OneReference>();
private _decorationIgnoreSet = collections.createStringDictionary<OneReference>(); private _decorationIgnoreSet = collections.createStringDictionary<OneReference>();
private _callOnDispose:Function[] = [];
private callOnDispose:Function[] = []; private _callOnModelChange:Function[] = [];
private callOnModelChange:Function[] = [];
constructor(private editor:ICodeEditor, private model:ReferencesModel) { constructor(private editor:ICodeEditor, private model:ReferencesModel) {
this.callOnDispose.push(this.editor.addListener(editorCommon.EventType.ModelChanged, () => this.onModelChanged())); this._callOnDispose.push(this.editor.addListener(editorCommon.EventType.ModelChanged, () => this._onModelChanged()));
this.onModelChanged(); this._onModelChanged();
} }
public dispose(): void { public dispose(): void {
this.callOnModelChange = cAll(this.callOnModelChange); this._callOnModelChange = cAll(this._callOnModelChange);
this.callOnDispose = cAll(this.callOnDispose); this._callOnDispose = cAll(this._callOnDispose);
this.removeDecorations(); this.removeDecorations();
} }
private onModelChanged():void { private _onModelChanged():void {
this.removeDecorations(); this.removeDecorations();
this.callOnModelChange = cAll(this.callOnModelChange); this._callOnModelChange = cAll(this._callOnModelChange);
var model = this.editor.getModel(); var model = this.editor.getModel();
if(!model) { if(!model) {
...@@ -74,14 +74,14 @@ class DecorationsManager implements IDisposable { ...@@ -74,14 +74,14 @@ class DecorationsManager implements IDisposable {
for(var i = 0, len = this.model.children.length; i < len; i++) { for(var i = 0, len = this.model.children.length; i < len; i++) {
if(this.model.children[i].resource.toString() === model.getAssociatedResource().toString()) { if(this.model.children[i].resource.toString() === model.getAssociatedResource().toString()) {
this.addDecorations(this.model.children[i]); this._addDecorations(this.model.children[i]);
return; return;
} }
} }
} }
private addDecorations(reference:FileReferences):void { private _addDecorations(reference:FileReferences):void {
this.callOnModelChange.push(this.editor.getModel().addListener(editorCommon.EventType.ModelDecorationsChanged, (event) => this.onDecorationChanged(event))); this._callOnModelChange.push(this.editor.getModel().addListener(editorCommon.EventType.ModelDecorationsChanged, (event) => this._onDecorationChanged(event)));
this.editor.getModel().changeDecorations((accessor) => { this.editor.getModel().changeDecorations((accessor) => {
var newDecorations: editorCommon.IModelDeltaDecoration[] = []; var newDecorations: editorCommon.IModelDeltaDecoration[] = [];
...@@ -107,7 +107,7 @@ class DecorationsManager implements IDisposable { ...@@ -107,7 +107,7 @@ class DecorationsManager implements IDisposable {
}); });
} }
private onDecorationChanged(event:any):void { private _onDecorationChanged(event:any):void {
var addedOrChangedDecorations = <any[]> event.addedOrChangedDecorations, var addedOrChangedDecorations = <any[]> event.addedOrChangedDecorations,
toRemove:string[] = []; toRemove:string[] = [];
...@@ -212,7 +212,7 @@ class Controller extends DefaultController { ...@@ -212,7 +212,7 @@ class Controller extends DefaultController {
if (element instanceof FileReferences) { if (element instanceof FileReferences) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return this.expandCollapse(tree, element); return this._expandCollapse(tree, element);
} }
var result = super.onClick(tree, element, event); var result = super.onClick(tree, element, event);
...@@ -237,7 +237,7 @@ class Controller extends DefaultController { ...@@ -237,7 +237,7 @@ class Controller extends DefaultController {
return super.onClick(tree, element, event); return super.onClick(tree, element, event);
} }
private expandCollapse(tree:tree.ITree, element:any):boolean { private _expandCollapse(tree:tree.ITree, element:any):boolean {
if (tree.isExpanded(element)) { if (tree.isExpanded(element)) {
tree.collapse(element).done(null, onUnexpectedError); tree.collapse(element).done(null, onUnexpectedError);
...@@ -254,7 +254,7 @@ class Controller extends DefaultController { ...@@ -254,7 +254,7 @@ class Controller extends DefaultController {
public onEnter(tree:tree.ITree, event:IKeyboardEvent):boolean { public onEnter(tree:tree.ITree, event:IKeyboardEvent):boolean {
var element = tree.getFocus(); var element = tree.getFocus();
if (element instanceof FileReferences) { if (element instanceof FileReferences) {
return this.expandCollapse(tree, element); return this._expandCollapse(tree, element);
} }
var result = super.onEnter(tree, event); var result = super.onEnter(tree, event);
...@@ -268,41 +268,41 @@ class Controller extends DefaultController { ...@@ -268,41 +268,41 @@ class Controller extends DefaultController {
public onUp(tree:tree.ITree, event:IKeyboardEvent):boolean { public onUp(tree:tree.ITree, event:IKeyboardEvent):boolean {
super.onUp(tree, event); super.onUp(tree, event);
this.fakeFocus(tree, event); this._fakeFocus(tree, event);
return true; return true;
} }
public onPageUp(tree:tree.ITree, event:IKeyboardEvent):boolean { public onPageUp(tree:tree.ITree, event:IKeyboardEvent):boolean {
super.onPageUp(tree, event); super.onPageUp(tree, event);
this.fakeFocus(tree, event); this._fakeFocus(tree, event);
return true; return true;
} }
public onLeft(tree:tree.ITree, event:IKeyboardEvent):boolean { public onLeft(tree:tree.ITree, event:IKeyboardEvent):boolean {
super.onLeft(tree, event); super.onLeft(tree, event);
this.fakeFocus(tree, event); this._fakeFocus(tree, event);
return true; return true;
} }
public onDown(tree:tree.ITree, event:IKeyboardEvent):boolean { public onDown(tree:tree.ITree, event:IKeyboardEvent):boolean {
super.onDown(tree, event); super.onDown(tree, event);
this.fakeFocus(tree, event); this._fakeFocus(tree, event);
return true; return true;
} }
public onPageDown(tree:tree.ITree, event:IKeyboardEvent):boolean { public onPageDown(tree:tree.ITree, event:IKeyboardEvent):boolean {
super.onPageDown(tree, event); super.onPageDown(tree, event);
this.fakeFocus(tree, event); this._fakeFocus(tree, event);
return true; return true;
} }
public onRight(tree:tree.ITree, event:IKeyboardEvent):boolean { public onRight(tree:tree.ITree, event:IKeyboardEvent):boolean {
super.onRight(tree, event); super.onRight(tree, event);
this.fakeFocus(tree, event); this._fakeFocus(tree, event);
return true; return true;
} }
private fakeFocus(tree:tree.ITree, event:IKeyboardEvent):void { private _fakeFocus(tree:tree.ITree, event:IKeyboardEvent):void {
// focus next item // focus next item
var focus = tree.getFocus(); var focus = tree.getFocus();
tree.setSelection([focus]); tree.setSelection([focus]);
...@@ -372,89 +372,91 @@ export class ReferenceWidget extends PeekViewWidget { ...@@ -372,89 +372,91 @@ export class ReferenceWidget extends PeekViewWidget {
public static INNER_EDITOR_CONTEXT_KEY = 'inReferenceSearchEditor'; public static INNER_EDITOR_CONTEXT_KEY = 'inReferenceSearchEditor';
public static Events = { private _editorService: IEditorService;
EditorDoubleClick: 'editorDoubleClick' private _contextService: IWorkspaceContextService;
}; private _instantiationService: IInstantiationService;
private editorService:IEditorService; private _decorationsManager: DecorationsManager;
private contextService:IWorkspaceContextService; private _model: ReferencesModel;
private instantiationService:IInstantiationService; private _callOnModel: IDisposable[] = [];
private _onDidDoubleClick = new Emitter<{ reference: URI, range: Range, originalEvent: MouseEvent }>();
private decorationsManager:DecorationsManager;
private model:ReferencesModel; private _tree: Tree;
private callOnModel:IDisposable[]; private _treeContainer: Builder;
private _preview: ICodeEditor;
private tree:Tree; private _previewNotAvailableMessage: Model;
private treeContainer:Builder; private _previewContainer: Builder;
private _messageContainer: Builder;
private preview:ICodeEditor;
private previewNotAvailableMessage:Model; private _lastHeight: string;
private previewContainer: Builder;
private previewDecorations:string[]; constructor(
private messageContainer: Builder; editorService: IEditorService,
keybindingService: IKeybindingService,
private lastHeight:string; contextService: IWorkspaceContextService,
instantiationService: IInstantiationService,
constructor(editorService:IEditorService, keybindingService: IKeybindingService, contextService:IWorkspaceContextService, instantiationService:IInstantiationService, editor:ICodeEditor) { editor: ICodeEditor
) {
super(editor, keybindingService, ReferenceWidget.INNER_EDITOR_CONTEXT_KEY, { frameColor: '#007ACC', showFrame: false, showArrow: true }); super(editor, keybindingService, ReferenceWidget.INNER_EDITOR_CONTEXT_KEY, { frameColor: '#007ACC', showFrame: false, showArrow: true });
this.editorService = editorService; this._editorService = editorService;
this.contextService = contextService; this._contextService = contextService;
this.instantiationService = instantiationService.createChild(new ServiceCollection([IPeekViewService, this])); this._instantiationService = instantiationService.createChild(new ServiceCollection([IPeekViewService, this]));
this.callOnModel = [];
this.tree = null; this._tree = null;
this.treeContainer = null; this._treeContainer = null;
this.preview = null; this._preview = null;
this.previewContainer = null; this._previewContainer = null;
this.previewDecorations = [];
this.lastHeight = null; this._lastHeight = null;
this.create(); this.create();
} }
_onTitleClick(e:Event):void { get onDidDoubleClick():Event<{ reference: URI, range: Range, originalEvent: MouseEvent }> {
if(!this.preview || !this.preview.getModel()) { return this._onDidDoubleClick.event;
}
protected _onTitleClick(e: MouseEvent): void {
if (!this._preview || !this._preview.getModel()) {
return; return;
} }
var model = this.preview.getModel(), var model = this._preview.getModel(),
lineNumber = this.preview.getPosition().lineNumber, lineNumber = this._preview.getPosition().lineNumber,
titleRange = new Range(lineNumber, 1, lineNumber, model.getLineMaxColumn(lineNumber)); titleRange = new Range(lineNumber, 1, lineNumber, model.getLineMaxColumn(lineNumber));
this.emit(ReferenceWidget.Events.EditorDoubleClick, { reference: this.getFocusedReference(), range: titleRange, originalEvent:e }); this._onDidDoubleClick.fire({ reference: this._getFocusedReference(), range: titleRange, originalEvent: e });
} }
_fillBody(containerElement:HTMLElement):void { protected _fillBody(containerElement: HTMLElement): void {
var container = $(containerElement); var container = $(containerElement);
container.addClass('reference-zone-widget'); container.addClass('reference-zone-widget');
// message pane // message pane
container.div({ 'class': 'messages' }, div => { container.div({ 'class': 'messages' }, div => {
this.messageContainer = div.hide(); this._messageContainer = div.hide();
}); });
// editor // editor
container.div({ 'class': 'preview inline' }, (div:Builder) => { container.div({ 'class': 'preview inline' }, (div: Builder) => {
var options:editorCommon.IEditorOptions = { var options: editorCommon.IEditorOptions = {
scrollBeyondLastLine: false, scrollBeyondLastLine: false,
scrollbar: DefaultConfig.editor.scrollbar, scrollbar: DefaultConfig.editor.scrollbar,
overviewRulerLanes: 2 overviewRulerLanes: 2
}; };
this.preview = this.instantiationService.createInstance(EmbeddedCodeEditorWidget, div.getHTMLElement(), options, this.editor); this._preview = this._instantiationService.createInstance(EmbeddedCodeEditorWidget, div.getHTMLElement(), options, this.editor);
this.previewContainer = div.hide(); this._previewContainer = div.hide();
this.previewNotAvailableMessage = new Model(nls.localize('missingPreviewMessage', "no preview available"), Model.DEFAULT_CREATION_OPTIONS, null); this._previewNotAvailableMessage = new Model(nls.localize('missingPreviewMessage', "no preview available"), Model.DEFAULT_CREATION_OPTIONS, null);
}); });
// tree // tree
container.div({ 'class': 'ref-tree inline' }, (div:Builder) => { container.div({ 'class': 'ref-tree inline' }, (div: Builder) => {
var config = { var config = {
dataSource: this.instantiationService.createInstance(DataSource), dataSource: this._instantiationService.createInstance(DataSource),
renderer: this.instantiationService.createInstance(Renderer, this.editor), renderer: this._instantiationService.createInstance(Renderer, this.editor),
//sorter: new Sorter(), //sorter: new Sorter(),
controller: new Controller() controller: new Controller()
}; };
...@@ -464,77 +466,77 @@ export class ReferenceWidget extends PeekViewWidget { ...@@ -464,77 +466,77 @@ export class ReferenceWidget extends PeekViewWidget {
twistiePixels: 20, twistiePixels: 20,
ariaLabel: nls.localize('treeAriaLabel', "References") ariaLabel: nls.localize('treeAriaLabel', "References")
}; };
this.tree = new Tree(div.getHTMLElement(), config, options); this._tree = new Tree(div.getHTMLElement(), config, options);
this.treeContainer = div.hide(); this._treeContainer = div.hide();
}); });
} }
_doLayoutBody(heightInPixel:number):void { protected _doLayoutBody(heightInPixel: number): void {
super._doLayoutBody(heightInPixel); super._doLayoutBody(heightInPixel);
var h = heightInPixel + 'px'; var h = heightInPixel + 'px';
if(h === this.lastHeight) { if (h === this._lastHeight) {
return; return;
} }
// set height // set height
this.treeContainer.style({ height: h }); this._treeContainer.style({ height: h });
this.previewContainer.style({ height: h }); this._previewContainer.style({ height: h });
// forward // forward
this.tree.layout(heightInPixel); this._tree.layout(heightInPixel);
this.preview.layout(); this._preview.layout();
this.lastHeight = h; this._lastHeight = h;
} }
public onWidth(widthInPixel:number):void { public onWidth(widthInPixel: number): void {
this.preview.layout(); this._preview.layout();
} }
public setModel(newModel: ReferencesModel): void { public setModel(newModel: ReferencesModel): void {
// clean up // clean up
this.callOnModel = dispose(this.callOnModel); this._callOnModel = dispose(this._callOnModel);
this.model = newModel; this._model = newModel;
if (this.model) { if (this._model) {
this._onNewModel(); this._onNewModel();
} }
} }
public showMessage(message: string): void{ public showMessage(message: string): void {
this.setTitle(''); this.setTitle('');
this.messageContainer.innerHtml(message).show(); this._messageContainer.innerHtml(message).show();
} }
private _onNewModel():void { private _onNewModel(): void {
this.messageContainer.hide(); this._messageContainer.hide();
this.decorationsManager = new DecorationsManager(this.preview, this.model); this._decorationsManager = new DecorationsManager(this._preview, this._model);
this.callOnModel.push(this.decorationsManager); this._callOnModel.push(this._decorationsManager);
// listen on model changes // listen on model changes
this.callOnModel.push(this.model.addListener2(EventType.OnReferenceRangeChanged, (reference:OneReference) => { this._callOnModel.push(this._model.addListener2(EventType.OnReferenceRangeChanged, (reference: OneReference) => {
this.tree.refresh(reference); this._tree.refresh(reference);
})); }));
// listen on selection and focus // listen on selection and focus
this.callOnModel.push(this.tree.addListener2(Controller.Events.FOCUSED, (element) => { this._callOnModel.push(this._tree.addListener2(Controller.Events.FOCUSED, (element) => {
if (element instanceof OneReference) { if (element instanceof OneReference) {
this.showReferencePreview(element); this._showReferencePreview(element);
} }
})); }));
this.callOnModel.push(this.tree.addListener2(Controller.Events.SELECTED, (element:any) => { this._callOnModel.push(this._tree.addListener2(Controller.Events.SELECTED, (element: any) => {
if (element instanceof OneReference) { if (element instanceof OneReference) {
this.showReferencePreview(element); this._showReferencePreview(element);
this.model.currentReference = element; this._model.currentReference = element;
} }
})); }));
this.callOnModel.push(this.tree.addListener2(Controller.Events.OPEN_TO_SIDE, (element:any) => { this._callOnModel.push(this._tree.addListener2(Controller.Events.OPEN_TO_SIDE, (element: any) => {
if (element instanceof OneReference) { if (element instanceof OneReference) {
this.editorService.openEditor({ this._editorService.openEditor({
resource: (<OneReference> element).resource, resource: (<OneReference>element).resource,
options: { options: {
selection: element.range selection: element.range
} }
...@@ -542,65 +544,65 @@ export class ReferenceWidget extends PeekViewWidget { ...@@ -542,65 +544,65 @@ export class ReferenceWidget extends PeekViewWidget {
} }
})); }));
var input = this.model.children.length === 1 ? <any> this.model.children[0] : <any> this.model; var input = this._model.children.length === 1 ? <any>this._model.children[0] : <any>this._model;
this.tree.setInput(input).then(() => { this._tree.setInput(input).then(() => {
this.tree.setSelection([this.model.currentReference]); this._tree.setSelection([this._model.currentReference]);
}).done(null, onUnexpectedError); }).done(null, onUnexpectedError);
// listen on editor // listen on editor
this.callOnModel.push(this.preview.addListener2(editorCommon.EventType.MouseDown, (e:{ event:MouseEvent; target:IMouseTarget; }) => { this._callOnModel.push(this._preview.addListener2(editorCommon.EventType.MouseDown, (e: { event: MouseEvent; target: IMouseTarget; }) => {
if(e.event.detail === 2) { if (e.event.detail === 2) {
this.emit(ReferenceWidget.Events.EditorDoubleClick, { reference: this.getFocusedReference(), range: e.target.range, originalEvent: e.event }); this._onDidDoubleClick.fire({ reference: this._getFocusedReference(), range: e.target.range, originalEvent: e.event });
} }
})); }));
// make sure things are rendered // make sure things are rendered
dom.addClass(this.container, 'results-loaded'); dom.addClass(this.container, 'results-loaded');
this.treeContainer.show(); this._treeContainer.show();
this.previewContainer.show(); this._previewContainer.show();
this.preview.layout(); this._preview.layout();
this.tree.layout(); this._tree.layout();
this.focus(); this.focus();
// preview the current reference // preview the current reference
this.showReferencePreview(this.model.nextReference(this.model.currentReference)); this._showReferencePreview(this._model.nextReference(this._model.currentReference));
} }
private getFocusedReference(): URI { private _getFocusedReference(): URI {
var element = this.tree.getFocus(); var element = this._tree.getFocus();
if(element instanceof OneReference) { if (element instanceof OneReference) {
return (<OneReference> element).resource; return (<OneReference>element).resource;
} else if(element instanceof FileReferences) { } else if (element instanceof FileReferences) {
var referenceFile = (<FileReferences> element); var referenceFile = (<FileReferences>element);
if(referenceFile.children.length > 0) { if (referenceFile.children.length > 0) {
return referenceFile.children[0].resource; return referenceFile.children[0].resource;
} }
} }
return null; return null;
} }
public focus():void { public focus(): void {
this.tree.DOMFocus(); this._tree.DOMFocus();
} }
private showReferencePreview(reference:OneReference):void { private _showReferencePreview(reference: OneReference): void {
// show in editor // show in editor
this.editorService.resolveEditorModel({ resource: reference.resource }).done((model) => { this._editorService.resolveEditorModel({ resource: reference.resource }).done((model) => {
if(model) { if (model) {
this.preview.setModel(model.textEditorModel); this._preview.setModel(model.textEditorModel);
var sel = Range.lift(reference.range).collapseToStart(); var sel = Range.lift(reference.range).collapseToStart();
this.preview.setSelection(sel); this._preview.setSelection(sel);
this.preview.revealRangeInCenter(sel); this._preview.revealRangeInCenter(sel);
} else { } else {
this.preview.setModel(this.previewNotAvailableMessage); this._preview.setModel(this._previewNotAvailableMessage);
} }
// Update widget header // Update widget header
if(reference.resource.scheme !== Schemas.inMemory) { if (reference.resource.scheme !== Schemas.inMemory) {
this.setTitle(reference.name, getPathLabel(reference.directory, this.contextService)); this.setTitle(reference.name, getPathLabel(reference.directory, this._contextService));
} else { } else {
this.setTitle(nls.localize('peekView.alternateTitle', "References")); this.setTitle(nls.localize('peekView.alternateTitle', "References"));
} }
...@@ -608,17 +610,17 @@ export class ReferenceWidget extends PeekViewWidget { ...@@ -608,17 +610,17 @@ export class ReferenceWidget extends PeekViewWidget {
}, onUnexpectedError); }, onUnexpectedError);
// show in tree // show in tree
this.tree.reveal(reference) this._tree.reveal(reference)
.then(() => { .then(() => {
this.tree.setSelection([reference]); this._tree.setSelection([reference]);
this.tree.setFocus(reference); this._tree.setFocus(reference);
}) })
.done(null, onUnexpectedError); .done(null, onUnexpectedError);
} }
public dispose(): void { public dispose(): void {
this.setModel(null); this.setModel(null);
dispose(<IDisposable[]>[this.preview, this.previewNotAvailableMessage, this.tree]); dispose(<IDisposable[]>[this._preview, this._previewNotAvailableMessage, this._tree]);
super.dispose(); super.dispose();
} }
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import * as nls from 'vs/nls'; ...@@ -10,6 +10,7 @@ import * as nls from 'vs/nls';
import {Action} from 'vs/base/common/actions'; import {Action} from 'vs/base/common/actions';
import * as strings from 'vs/base/common/strings'; import * as strings from 'vs/base/common/strings';
import {$} from 'vs/base/browser/builder'; import {$} from 'vs/base/browser/builder';
import Event, {Emitter} from 'vs/base/common/event';
import * as dom from 'vs/base/browser/dom'; import * as dom from 'vs/base/browser/dom';
import {ActionBar} from 'vs/base/browser/ui/actionbar/actionbar'; import {ActionBar} from 'vs/base/browser/ui/actionbar/actionbar';
import {ServiceIdentifier, ServicesAccessor, createDecorator} from 'vs/platform/instantiation/common/instantiation'; import {ServiceIdentifier, ServicesAccessor, createDecorator} from 'vs/platform/instantiation/common/instantiation';
...@@ -23,18 +24,14 @@ export var IPeekViewService = createDecorator<IPeekViewService>('peekViewService ...@@ -23,18 +24,14 @@ export var IPeekViewService = createDecorator<IPeekViewService>('peekViewService
export interface IPeekViewService { export interface IPeekViewService {
serviceId: ServiceIdentifier<any>; serviceId: ServiceIdentifier<any>;
isActive:boolean; isActive: boolean;
contextKey:string; contextKey: string;
getActiveWidget(): PeekViewWidget; getActiveWidget(): PeekViewWidget;
} }
export namespace Events {
export var Closed = 'closed';
}
var CONTEXT_OUTER_EDITOR = 'outerEditorId'; var CONTEXT_OUTER_EDITOR = 'outerEditorId';
export function getOuterEditor(accessor:ServicesAccessor, args: any): ICommonCodeEditor { export function getOuterEditor(accessor: ServicesAccessor, args: any): ICommonCodeEditor {
var outerEditorId = args.context[CONTEXT_OUTER_EDITOR]; var outerEditorId = args.context[CONTEXT_OUTER_EDITOR];
if (!outerEditorId) { if (!outerEditorId) {
return null; return null;
...@@ -43,47 +40,53 @@ export function getOuterEditor(accessor:ServicesAccessor, args: any): ICommonCod ...@@ -43,47 +40,53 @@ export function getOuterEditor(accessor:ServicesAccessor, args: any): ICommonCod
} }
export class PeekViewWidget extends ZoneWidget implements IPeekViewService { export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
public serviceId = IPeekViewService; public serviceId = IPeekViewService;
public contextKey:string; public contextKey: string;
private _isActive:boolean; private _onDidClose = new Emitter<PeekViewWidget>();
private _isActive = false;
_headElement:HTMLDivElement; protected _headElement: HTMLDivElement;
_primaryHeading:HTMLElement; protected _primaryHeading: HTMLElement;
_secondaryHeading:HTMLElement; protected _secondaryHeading: HTMLElement;
_metaHeading:HTMLElement; protected _metaHeading: HTMLElement;
_actionbarWidget:ActionBar; protected _actionbarWidget: ActionBar;
_bodyElement:HTMLDivElement; protected _bodyElement: HTMLDivElement;
constructor(editor: ICodeEditor, keybindingService:IKeybindingService, contextKey:string, options: IOptions = {}) { constructor(editor: ICodeEditor, keybindingService: IKeybindingService, contextKey: string, options: IOptions = {}) {
super(editor, options); super(editor, options);
this.contextKey = contextKey; this.contextKey = contextKey;
keybindingService.createKey(CONTEXT_OUTER_EDITOR, editor.getId()); keybindingService.createKey(CONTEXT_OUTER_EDITOR, editor.getId());
} }
public dispose(): void{ public dispose(): void {
this._isActive = false; this._isActive = false;
super.dispose(); super.dispose();
} }
public get isActive():boolean { public get onDidClose(): Event<PeekViewWidget> {
return this._onDidClose.event;
}
public get isActive(): boolean {
return this._isActive; return this._isActive;
} }
public getActiveWidget():PeekViewWidget { public getActiveWidget(): PeekViewWidget {
return this; return this;
} }
public show(where:any, heightInLines:number):void { public show(where: any, heightInLines: number): void {
this._isActive = true; this._isActive = true;
super.show(where, heightInLines); super.show(where, heightInLines);
} }
public fillContainer(container:HTMLElement):void { public fillContainer(container: HTMLElement): void {
$(container).addClass('peekview-widget'); $(container).addClass('peekview-widget');
this._headElement = <HTMLDivElement> $('.head').getHTMLElement(); this._headElement = <HTMLDivElement>$('.head').getHTMLElement();
this._bodyElement = <HTMLDivElement> $('.body').getHTMLElement(); this._bodyElement = <HTMLDivElement>$('.body').getHTMLElement();
this._fillHead(this._headElement); this._fillHead(this._headElement);
this._fillBody(this._bodyElement); this._fillBody(this._bodyElement);
...@@ -92,9 +95,9 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService { ...@@ -92,9 +95,9 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
container.appendChild(this._bodyElement); container.appendChild(this._bodyElement);
} }
_fillHead(container:HTMLElement):void { protected _fillHead(container: HTMLElement): void {
var titleElement = $('.peekview-title'). var titleElement = $('.peekview-title').
on(dom.EventType.CLICK, (e) => this._onTitleClick(e)). on(dom.EventType.CLICK, e => this._onTitleClick(<MouseEvent>e)).
appendTo(this._headElement). appendTo(this._headElement).
getHTMLElement(); getHTMLElement();
...@@ -104,23 +107,23 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService { ...@@ -104,23 +107,23 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
this._actionbarWidget = new ActionBar( this._actionbarWidget = new ActionBar(
$('.peekview-actions'). $('.peekview-actions').
appendTo(this._headElement) appendTo(this._headElement)
); );
this._actionbarWidget.push(new Action('peekview.close', nls.localize('label.close', "Close"), 'close-peekview-action', true, () => { this._actionbarWidget.push(new Action('peekview.close', nls.localize('label.close', "Close"), 'close-peekview-action', true, () => {
this.dispose(); this.dispose();
this.emit(Events.Closed, this); this._onDidClose.fire(this);
return null; return null;
}), { label: false, icon: true }); }), { label: false, icon: true });
} }
_onTitleClick(event:Event):void { protected _onTitleClick(event: MouseEvent): void {
// implement me // implement me
} }
public setTitle(primaryHeading:string, secondaryHeading?:string):void { public setTitle(primaryHeading: string, secondaryHeading?: string): void {
$(this._primaryHeading).safeInnerHtml(primaryHeading); $(this._primaryHeading).safeInnerHtml(primaryHeading);
if(secondaryHeading) { if (secondaryHeading) {
$(this._secondaryHeading).safeInnerHtml(secondaryHeading); $(this._secondaryHeading).safeInnerHtml(secondaryHeading);
} else { } else {
dom.clearNode(this._secondaryHeading); dom.clearNode(this._secondaryHeading);
...@@ -135,16 +138,16 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService { ...@@ -135,16 +138,16 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
} }
} }
_fillBody(container:HTMLElement):void { protected _fillBody(container: HTMLElement): void {
// implement me // implement me
} }
public doLayout(heightInPixel:number):void { public doLayout(heightInPixel: number): void {
if (heightInPixel < 0) { if (heightInPixel < 0) {
// Looks like the view zone got folded away! // Looks like the view zone got folded away!
this.dispose(); this.dispose();
this.emit(Events.Closed, this); this._onDidClose.fire(this);
return; return;
} }
...@@ -155,12 +158,12 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService { ...@@ -155,12 +158,12 @@ export class PeekViewWidget extends ZoneWidget implements IPeekViewService {
this._doLayoutBody(bodyHeight); this._doLayoutBody(bodyHeight);
} }
_doLayoutHead(heightInPixel:number):void { protected _doLayoutHead(heightInPixel: number): void {
this._headElement.style.height = strings.format('{0}px', heightInPixel); this._headElement.style.height = strings.format('{0}px', heightInPixel);
this._headElement.style.lineHeight = this._headElement.style.height; this._headElement.style.lineHeight = this._headElement.style.height;
} }
_doLayoutBody(heightInPixel:number):void { protected _doLayoutBody(heightInPixel: number): void {
this._bodyElement.style.height = strings.format('{0}px', heightInPixel); this._bodyElement.style.height = strings.format('{0}px', heightInPixel);
} }
} }
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
'use strict'; 'use strict';
import 'vs/css!./zoneWidget'; import 'vs/css!./zoneWidget';
import {EventEmitter, ListenerUnbind} from 'vs/base/common/eventEmitter'; import {ListenerUnbind} from 'vs/base/common/eventEmitter';
import * as objects from 'vs/base/common/objects'; import * as objects from 'vs/base/common/objects';
import * as dom from 'vs/base/browser/dom'; import * as dom from 'vs/base/browser/dom';
import {EventType, IEditorLayoutInfo, IPosition, IRange} from 'vs/editor/common/editorCommon'; import {EventType, IEditorLayoutInfo, IPosition, IRange} from 'vs/editor/common/editorCommon';
...@@ -80,8 +80,7 @@ class OverlayWidgetDelegate implements IOverlayWidget { ...@@ -80,8 +80,7 @@ class OverlayWidgetDelegate implements IOverlayWidget {
} }
// TODO@Joh - this is an event emitter, why? export class ZoneWidget {
export class ZoneWidget extends EventEmitter {
private zoneId:number; private zoneId:number;
private lastView:any; private lastView:any;
...@@ -98,7 +97,6 @@ export class ZoneWidget extends EventEmitter { ...@@ -98,7 +97,6 @@ export class ZoneWidget extends EventEmitter {
private listenersToRemove:ListenerUnbind[]; private listenersToRemove:ListenerUnbind[];
constructor(editor:ICodeEditor, options:IOptions = {}) { constructor(editor:ICodeEditor, options:IOptions = {}) {
super();
this.editor = editor; this.editor = editor;
this.options = objects.mixin(objects.clone(defaultOptions), options); this.options = objects.mixin(objects.clone(defaultOptions), options);
this.zoneId = -1; this.zoneId = -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册