outline baby steps

This commit is contained in:
Johannes Rieken
2018-05-08 09:02:08 +02:00
parent 341100e1f7
commit 2fbc328d86
20 changed files with 477 additions and 0 deletions

View File

@@ -146,6 +146,10 @@
"name": "vs/workbench/parts/welcome",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/parts/outline",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/services/actions",
"project": "vscode-workbench"

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-bg{fill:#424242}.icon-vs-fg{fill:#f0eff1}.icon-vs-action-blue{fill:#00539c}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M2.879 14L1 12.121V3.879L2.879 2h10.242L15 3.879v8.242L13.121 14H2.879z" id="outline"/><path class="icon-vs-fg" d="M12.293 4H3.707L3 4.707v6.586l.707.707h8.586l.707-.707V4.707L12.293 4zM11 10H5V9h6v1zm0-3H5V6h6v1z" id="iconFg"/><g id="iconBg"><path class="icon-vs-bg" d="M12.707 13H3.293L2 11.707V4.293L3.293 3h9.414L14 4.293v7.414L12.707 13zm-9-1h8.586l.707-.707V4.707L12.293 4H3.707L3 4.707v6.586l.707.707z"/><path class="icon-vs-action-blue" d="M11 7H5V6h6v1zm0 2H5v1h6V9z"/></g></svg>

After

Width:  |  Height:  |  Size: 823 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#252526}.icon-vs-out{fill:#252526}.icon-vs-bg{fill:#c5c5c5}.icon-vs-fg{fill:#2b282e}.icon-vs-action-blue{fill:#75beff}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M2.879 14L1 12.121V3.879L2.879 2h10.242L15 3.879v8.242L13.121 14H2.879z" id="outline"/><path class="icon-vs-fg" d="M12.293 4H3.707L3 4.707v6.586l.707.707h8.586l.707-.707V4.707L12.293 4zM11 10H5V9h6v1zm0-3H5V6h6v1z" id="iconFg"/><g id="iconBg"><path class="icon-vs-bg" d="M12.707 13H3.293L2 11.707V4.293L3.293 3h9.414L14 4.293v7.414L12.707 13zm-9-1h8.586l.707-.707V4.707L12.293 4H3.707L3 4.707v6.586l.707.707z"/><path class="icon-vs-action-blue" d="M11 7H5V6h6v1zm0 2H5v1h6V9z"/></g></svg>

After

Width:  |  Height:  |  Size: 823 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-fg{fill:#f0eff1}.icon-vs-action-blue{fill:#00539c}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M0 15V6h6V2.586L7.585 1h6.829L16 2.586v5.829L14.414 10H10v5H0zm3-6z" id="outline"/><path class="icon-vs-fg" d="M8 3v3h5v1h-3v1h4V3H8zm5 2H9V4h4v1zM2 8v5h6V8H2zm5 3H3v-1h4v1z" id="iconFg"/><path class="icon-vs-action-blue" d="M10 6h3v1h-3V6zM9 4v1h4V4H9zm5-2H8L7 3v3h1V3h6v5h-4v1h4l1-1V3l-1-1zm-7 8H3v1h4v-1zm2-3v7H1V7h8zM8 8H2v5h6V8z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 664 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-fg{fill:#2b282e}.icon-vs-action-blue{fill:#75beff}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M0 15V6h6V2.586L7.585 1h6.829L16 2.586v5.829L14.414 10H10v5H0zm3-6z" id="outline"/><path class="icon-vs-fg" d="M8 3v3h5v1h-3v1h4V3H8zm5 2H9V4h4v1zM2 8v5h6V8H2zm5 3H3v-1h4v1z" id="iconFg"/><path class="icon-vs-action-blue" d="M10 6h3v1h-3V6zM9 4v1h4V4H9zm5-2H8L7 3v3h1V3h6v5h-4v1h4l1-1V3l-1-1zm-7 8H3v1h4v-1zm2-3v7H1V7h8zM8 8H2v5h6V8z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 664 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-action-orange{fill:#c27d1a}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M14 1.414L9.414 6H14v1.414L5.414 16H3v-1.234L5.371 10H2V8.764L6.382 0H14v1.414z" id="outline" style="display: none;"/><path class="icon-vs-action-orange" d="M7 7h6l-8 8H4l2.985-6H3l4-8h6L7 7z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 499 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-action-orange{fill:#e8ab53}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M14 1.414L9.414 6H14v1.414L5.414 16H3v-1.234L5.371 10H2V8.764L6.382 0H14v1.414z" id="outline" style="display: none;"/><path class="icon-vs-action-orange" d="M7 7h6l-8 8H4l2.985-6H3l4-8h6L7 7z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 499 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-fg{fill:#f0eff1}.icon-vs-action-blue{fill:#00539c}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M16 16H0V0h16v16z" id="outline" style="display: none;"/><path class="icon-vs-action-blue" d="M1 1v14h14V1H1zm6 12H3v-1h4v1zm0-3H3V9h4v1zm0-5H5v2H4V5H2V4h2V2h1v2h2v1zm3.281 8H8.719l3-4h1.563l-3.001 4zM14 5H9V4h5v1z" id="iconBg"/><path class="icon-vs-fg" d="M7 5H5v2H4V5H2V4h2V2h1v2h2v1zm7-1H9v1h5V4zM7 9H3v1h4V9zm0 3H3v1h4v-1zm3.281 1l3-4h-1.563l-3 4h1.563z" id="iconFg" style="display: none;"/></svg>

After

Width:  |  Height:  |  Size: 710 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-fg{fill:#2b282e}.icon-vs-action-blue{fill:#75beff}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M16 16H0V0h16v16z" id="outline" style="display: none;"/><path class="icon-vs-action-blue" d="M1 1v14h14V1H1zm6 12H3v-1h4v1zm0-3H3V9h4v1zm0-5H5v2H4V5H2V4h2V2h1v2h2v1zm3.281 8H8.719l3-4h1.563l-3.001 4zM14 5H9V4h5v1z" id="iconBg"/><path class="icon-vs-fg" d="M7 5H5v2H4V5H2V4h2V2h1v2h2v1zm7-1H9v1h5V4zM7 9H3v1h4V9zm0 3H3v1h4v-1zm3.281 1l3-4h-1.563l-3 4h1.563z" id="iconFg" style="display: none;"/></svg>

After

Width:  |  Height:  |  Size: 710 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-action-blue{fill:#00539c}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M9 14V8H7v6H1V2h14v12H9z" id="outline" style="display: none;"/><path class="icon-vs-action-blue" d="M10 9h4v4h-4V9zm-8 4h4V9H2v4zM2 3v4h12V3H2z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 449 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-action-blue{fill:#75beff}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M9 14V8H7v6H1V2h14v12H9z" id="outline" style="display: none;"/><path class="icon-vs-action-blue" d="M10 9h4v4h-4V9zm-8 4h4V9H2v4zM2 3v4h12V3H2z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 449 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#f6f6f6}.icon-vs-out{fill:#f6f6f6}.icon-vs-bg{fill:#424242}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M10.702 10.5l2-2-2-2 .5-.5H10v5h1v3H5v-3h1V6H4.798l.5.5-2 2 2 2L3 12.797l-3-3V7.201l3-3V2h10v2.201l3 3v2.596l-3 3-2.298-2.297z" id="outline" style="display: none;"/><path class="icon-vs-bg" d="M4 3h8v2h-1v-.5c0-.277-.224-.5-.5-.5H9v7.5c0 .275.224.5.5.5h.5v1H6v-1h.5a.5.5 0 0 0 .5-.5V4H5.5a.5.5 0 0 0-.5.5V5H4V3zM3 5.615L.116 8.5 3 11.383l.884-.883-2-2 2-2L3 5.615zm10 0l-.884.885 2 2-2 2 .884.883L15.884 8.5 13 5.615z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 714 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.icon-canvas-transparent{opacity:0;fill:#2d2d30}.icon-vs-out{fill:#2d2d30}.icon-vs-bg{fill:#c5c5c5}</style><path class="icon-canvas-transparent" d="M16 16H0V0h16v16z" id="canvas"/><path class="icon-vs-out" d="M10.702 10.5l2-2-2-2 .5-.5H10v5h1v3H5v-3h1V6H4.798l.5.5-2 2 2 2L3 12.797l-3-3V7.201l3-3V2h10v2.201l3 3v2.596l-3 3-2.298-2.297z" id="outline" style="display: none;"/><path class="icon-vs-bg" d="M4 3h8v2h-1v-.5c0-.277-.224-.5-.5-.5H9v7.5c0 .275.224.5.5.5h.5v1H6v-1h.5a.5.5 0 0 0 .5-.5V4H5.5a.5.5 0 0 0-.5.5V5H4V3zM3 5.615L.116 8.5 3 11.383l.884-.883-2-2 2-2L3 5.615zm10 0l-.884.885 2 2-2 2 .884.883L15.884 8.5 13 5.615z" id="iconBg"/></svg>

After

Width:  |  Height:  |  Size: 714 B

View File

@@ -0,0 +1,160 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.monaco-workbench .outline-item .icon {
display: inline-block;
height: 16px;
width: 16px;
}
.monaco-workbench .outline-item .icon.constant {
background-image: url('Constant_16x.svg');
background-repeat: no-repeat;
background-position: 0 -2px;
}
.vs-dark .monaco-workbench .outline-item .icon.constant,
.hc-black .monaco-workbench .outline-item .icon.constant {
background-image: url('Constant_16x_inverse.svg');
}
.monaco-workbench .outline-item .icon.enum-member {
background-image: url('EnumItem_16x.svg');
background-repeat: no-repeat;
background-position: 0 -2px;
}
.vs-dark .monaco-workbench .outline-item .icon.enum-member,
.hc-black .monaco-workbench .outline-item .icon.enum-member {
background-image: url('EnumItem_inverse_16x.svg');
}
.monaco-workbench .outline-item .icon.struct {
background-image: url('Structure_16x_vscode.svg');
background-repeat: no-repeat;
background-position: 0 -2px;
}
.vs-dark .monaco-workbench .outline-item .icon.struct,
.hc-black .monaco-workbench .outline-item .icon.struct {
background-image: url('Structure_16x_vscode_inverse.svg');
}
.monaco-workbench .outline-item .icon.event {
background-image: url('Event_16x_vscode.svg');
background-repeat: no-repeat;
background-position: 0 -2px;
}
.vs-dark .monaco-workbench .outline-item .icon.event,
.hc-black .monaco-workbench .outline-item .icon.event {
background-image: url('Event_16x_vscode_inverse.svg');
}
.monaco-workbench .outline-item .icon.operator {
background-image: url('Operator_16x_vscode.svg');
background-repeat: no-repeat;
background-position: 0 -2px;
}
.vs-dark .monaco-workbench .outline-item .icon.operator,
.hc-black .monaco-workbench .outline-item .icon.operator {
background-image: url('Operator_16x_vscode_inverse.svg');
}
.monaco-workbench .outline-item .icon.type-parameter {
background-image: url('Template_16x_vscode.svg');
background-repeat: no-repeat;
background-position: 0 -2px;
}
.vs-dark .monaco-workbench .outline-item .icon.type-parameter,
.hc-black .monaco-workbench .outline-item .icon.type-parameter {
background-image: url('Template_16x_vscode_inverse.svg');
}
.monaco-workbench .outline-item .icon.method,
.monaco-workbench .outline-item .icon.function,
.monaco-workbench .outline-item .icon.constructor,
.monaco-workbench .outline-item .icon.field,
.monaco-workbench .outline-item .icon.variable,
.monaco-workbench .outline-item .icon.class,
.monaco-workbench .outline-item .icon.interface,
.monaco-workbench .outline-item .icon.object,
.monaco-workbench .outline-item .icon.namespace,
.monaco-workbench .outline-item .icon.package,
.monaco-workbench .outline-item .icon.module,
.monaco-workbench .outline-item .icon.property,
.monaco-workbench .outline-item .icon.enum,
.monaco-workbench .outline-item .icon.key,
.monaco-workbench .outline-item .icon.string,
.monaco-workbench .outline-item .icon.rule,
.monaco-workbench .outline-item .icon.file,
.monaco-workbench .outline-item .icon.array,
.monaco-workbench .outline-item .icon.number,
.monaco-workbench .outline-item .icon.null,
.monaco-workbench .outline-item .icon.boolean {
background-image: url('symbol-sprite.svg');
background-repeat: no-repeat;
}
.vs .monaco-workbench .outline-item .icon.method,
.vs .monaco-workbench .outline-item .icon.function,
.vs .monaco-workbench .outline-item .icon.constructor { background-position: 0 -4px; }
.vs .monaco-workbench .outline-item .icon.field,
.vs .monaco-workbench .outline-item .icon.variable { background-position: -22px -4px; }
.vs .monaco-workbench .outline-item .icon.class { background-position: -43px -3px; }
.vs .monaco-workbench .outline-item .icon.interface { background-position: -63px -4px; }
.vs .monaco-workbench .outline-item .icon.object,
.vs .monaco-workbench .outline-item .icon.namespace,
.vs .monaco-workbench .outline-item .icon.package,
.vs .monaco-workbench .outline-item .icon.module { background-position: -82px -4px; }
.vs .monaco-workbench .outline-item .icon.property { background-position: -102px -3px; }
.vs .monaco-workbench .outline-item .icon.enum { background-position: -122px -3px; }
.vs .monaco-workbench .outline-item .icon.key,
.vs .monaco-workbench .outline-item .icon.string { background-position: -202px -3px; }
.vs .monaco-workbench .outline-item .icon.rule { background-position: -242px -4px; }
.vs .monaco-workbench .outline-item .icon.file { background-position: -262px -4px; }
.vs .monaco-workbench .outline-item .icon.array { background-position: -302px -4px; }
.vs .monaco-workbench .outline-item .icon.number { background-position: -322px -4px; }
.vs .monaco-workbench .outline-item .icon.null,
.vs .monaco-workbench .outline-item .icon.boolean { background-position: -343px -4px; }
.vs-dark .monaco-workbench .outline-item .icon.method,
.vs-dark .monaco-workbench .outline-item .icon.function,
.vs-dark .monaco-workbench .outline-item .icon.constructor,
.hc-black .monaco-workbench .outline-item .icon.method,
.hc-black .monaco-workbench .outline-item .icon.function,
.hc-black .monaco-workbench .outline-item .icon.constructor { background-position: 0 -24px; }
.vs-dark .monaco-workbench .outline-item .icon.field,
.hc-black .monaco-workbench .outline-item .icon.field,
.vs-dark .monaco-workbench .outline-item .icon.variable,
.hc-black .monaco-workbench .outline-item .icon.variable { background-position: -22px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.class,
.hc-black .monaco-workbench .outline-item .icon.class { background-position: -43px -23px; }
.vs-dark .monaco-workbench .outline-item .icon.interface,
.hc-black .monaco-workbench .outline-item .icon.interface { background-position: -63px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.object,
.vs-dark .monaco-workbench .outline-item .icon.namespace,
.vs-dark .monaco-workbench .outline-item .icon.package,
.vs-dark .monaco-workbench .outline-item .icon.module,
.hc-black .monaco-workbench .outline-item .icon.object,
.hc-black .monaco-workbench .outline-item .icon.namespace,
.hc-black .monaco-workbench .outline-item .icon.package,
.hc-black .monaco-workbench .outline-item .icon.module { background-position: -82px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.property,
.hc-black .monaco-workbench .outline-item .icon.property { background-position: -102px -23px; }
.vs-dark .monaco-workbench .outline-item .icon.key,
.vs-dark .monaco-workbench .outline-item .icon.string,
.hc-black .monaco-workbench .outline-item .icon.key,
.hc-black .monaco-workbench .outline-item .icon.string { background-position: -202px -23px; }
.vs-dark .monaco-workbench .outline-item .icon.enum,
.hc-black .monaco-workbench .outline-item .icon.enum { background-position: -122px -23px; }
.vs-dark .monaco-workbench .outline-item .icon.rule,
.hc-black .monaco-workbench .outline-item .icon.rule { background-position: -242px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.file,
.hc-black .monaco-workbench .outline-item .icon.file { background-position: -262px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.array,
.hc-black .monaco-workbench .outline-item .icon.array { background-position: -302px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.number,
.hc-black .monaco-workbench .outline-item .icon.number { background-position: -322px -24px; }
.vs-dark .monaco-workbench .outline-item .icon.null,
.vs-dark .monaco-workbench .outline-item .icon.boolean,
.hc-black .monaco-workbench .outline-item .icon.null,
.hc-black .monaco-workbench .outline-item .icon.boolean { background-position: -342px -24px; }

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,21 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { localize } from 'vs/nls';
import { ViewsRegistry, ViewLocation } from 'vs/workbench/common/views';
import { OutlinePanel } from './outlinePanel';
// get outline tree (per extension...)
// sorting by range, name, type
ViewsRegistry.registerViews([{
id: 'code.outline',
name: localize('name', "Outline"),
ctor: OutlinePanel,
location: ViewLocation.Explorer,
canToggleVisibility: true
}]);

View File

@@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { DocumentSymbolProviderRegistry, SymbolInformation } from 'vs/editor/common/modes';
import { ITextModel } from '../../../../editor/common/model';
import { asWinJsPromise } from '../../../../base/common/async';
import { TPromise } from 'vs/base/common/winjs.base';
export function getOutline(model: ITextModel): TPromise<OneOutline[]> {
let outlines = new Array<OneOutline>();
let promises = DocumentSymbolProviderRegistry.ordered(model).map((provider, i) => {
return asWinJsPromise(token => provider.provideDocumentSymbols(model, token)).then(result => {
let items = new Array<OutlineItem>();
let source = `provider${i}`;
for (const item of result) {
OutlineItem.convert(items, item, undefined);
}
outlines.push(new OneOutline(source, items));
}, err => {
//
});
});
return TPromise.join(promises).then(() => outlines);
}
export class OutlineItem {
static convert(bucket: OutlineItem[], info: SymbolInformation, parent: OutlineItem): void {
let res = new OutlineItem(
`${info.name}/${parent ? parent.id : ''}`,
info,
parent,
[]
);
if (info.children) {
for (const child of info.children) {
OutlineItem.convert(res.children, child, res);
}
}
bucket.push(res);
}
constructor(
readonly id: string,
readonly symbol: SymbolInformation,
readonly parent: OutlineItem,
readonly children: OutlineItem[],
) {
//
}
}
export class OneOutline {
constructor(
readonly source: string,
readonly items: OutlineItem[]
) {
//
}
}

View File

@@ -0,0 +1,124 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
import { DocumentSymbolProviderRegistry } from 'vs/editor/common/modes';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
import { IViewOptions, ViewsViewletPanel } from 'vs/workbench/browser/parts/views/viewsViewlet';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { Emitter, Event } from 'vs/base/common/event';
import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { getOutline, OneOutline } from './outlineModel';
import { OutlineDataSource, OutlineRenderer, OutlineSorter } from './outlineTree';
class OutlineRequestLogic {
private readonly _disposables = new Array<IDisposable>();
private readonly _onDidChangeActiveEditor = new Emitter<ICodeEditor>();
private _editorListener: IDisposable;
readonly onDidChangeActiveEditor: Event<ICodeEditor> = this._onDidChangeActiveEditor.event;
constructor(
@IEditorGroupService editorGroupService: IEditorGroupService,
@IWorkbenchEditorService private readonly _workbenchEditorService: IWorkbenchEditorService,
) {
editorGroupService.onEditorsChanged(this._update, this, this._disposables);
DocumentSymbolProviderRegistry.onDidChange(this._update, this, this._disposables);
}
dispose(): void {
dispose(this._disposables);
}
private _update(): void {
dispose(this._editorListener);
let editor = this._workbenchEditorService.getActiveEditor();
let control = editor && editor.getControl();
let codeEditor: ICodeEditor = undefined;
if (isCodeEditor(control)) {
codeEditor = control;
} else if (isDiffEditor(control)) {
codeEditor = control.getModifiedEditor();
}
this._editorListener = codeEditor && codeEditor.onDidChangeModelContent(e => this._onDidChangeActiveEditor.fire(codeEditor));
this._onDidChangeActiveEditor.fire(codeEditor);
}
}
export class OutlinePanel extends ViewsViewletPanel {
private readonly _disposables = new Array<IDisposable>();
private readonly _activeEditorOracle: OutlineRequestLogic;
private _tree: Tree;
constructor(
options: IViewOptions,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IKeybindingService keybindingService: IKeybindingService,
@IContextMenuService contextMenuService: IContextMenuService,
@IConfigurationService configurationService: IConfigurationService
) {
super(options, keybindingService, contextMenuService, configurationService);
this._activeEditorOracle = _instantiationService.createInstance(OutlineRequestLogic);
this._disposables.push(this._activeEditorOracle.onDidChangeActiveEditor(editor => {
if (editor) {
getOutline(editor.getModel()).then(outline => {
let model = <OneOutline>this._tree.getInput();
let [first] = outline;
if (first) {
if (model instanceof OneOutline && first.source === model.source) {
model.items.splice(0, model.items.length, ...first.items);
this._tree.refresh(undefined, true);
} else {
this._tree.setInput(first);
}
}
}, err => {
console.error(err);
});
}
}));
this._disposables.push(this._activeEditorOracle);
}
dispose(): void {
dispose(this._disposables);
super.dispose();
}
protected renderBody(container: HTMLElement): void {
const dataSource = new OutlineDataSource();
const renderer = new OutlineRenderer();
const sorter = new OutlineSorter();
this._tree = this._instantiationService.createInstance(
WorkbenchTree,
container,
{ dataSource, renderer, sorter },
{}
);
this._disposables.push(this._tree);
}
protected layoutBody(height: number): void {
this._tree.layout(height);
}
setVisible(visible: boolean): TPromise<void> {
return super.setVisible(visible);
}
}

View File

@@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./media/outline';
import { TPromise } from 'vs/base/common/winjs.base';
import * as dom from 'vs/base/browser/dom';
import { symbolKindToCssClass } from 'vs/editor/common/modes';
import { Range } from 'vs/editor/common/core/range';
import { IDataSource, IRenderer, ITree, ISorter } from 'vs/base/parts/tree/browser/tree';
import { OneOutline, OutlineItem } from './outlineModel';
export class OutlineSorter implements ISorter {
compare(tree: ITree, a: any, b: any): number {
return Range.compareRangesUsingStarts((<OutlineItem>a).symbol.location.range, (<OutlineItem>b).symbol.location.range);
}
}
export class OutlineDataSource implements IDataSource {
getId(tree: ITree, element: OneOutline | OutlineItem): string {
if (element instanceof OneOutline) {
return element.source;
} else {
return element.id;
}
}
hasChildren(tree: ITree, element: OneOutline | OutlineItem): boolean {
if (element instanceof OneOutline) {
return element.items.length > 0;
} else {
return element.children.length > 0;
}
}
async getChildren(tree: ITree, element: OneOutline | OutlineItem): TPromise<any, any> {
if (element instanceof OneOutline) {
return element.items;
} else {
return element.children;
}
}
getParent(tree: ITree, element: any): TPromise<any, any> {
return null;
}
}
export class OutlineItemTemplate {
readonly icon: HTMLSpanElement;
readonly label: HTMLSpanElement;
readonly detail: HTMLSpanElement;
constructor(container: HTMLElement) {
this.icon = document.createElement('span');
this.label = document.createElement('span');
this.detail = document.createElement('span');
container.appendChild(this.icon);
container.appendChild(this.label);
container.appendChild(this.detail);
dom.addClass(this.icon, 'icon');
dom.addClass(this.label, 'label');
dom.addClass(this.detail, 'detail');
dom.addClass(container, 'outline-item');
}
}
export class OutlineRenderer implements IRenderer {
getHeight(tree: ITree, element: any): number {
return 22;
}
getTemplateId(tree: ITree, element: any): string {
return 'outline.element';
}
renderTemplate(tree: ITree, templateId: string, container: HTMLElement) {
return new OutlineItemTemplate(container);
}
renderElement(tree: ITree, element: any, templateId: string, template: OutlineItemTemplate): void {
template.icon.classList.add(symbolKindToCssClass((<OutlineItem>element).symbol.kind));
template.label.innerText = (<OutlineItem>element).symbol.name;
}
disposeTemplate(tree: ITree, templateId: string, templateData: OutlineItemTemplate): void {
//todo@joh
}
}

View File

@@ -132,5 +132,7 @@ import 'vs/workbench/parts/watermark/electron-browser/watermark';
import 'vs/workbench/parts/welcome/overlay/browser/welcomeOverlay';
import 'vs/workbench/parts/outline/electron-browser/outline.contribution';
// services
import 'vs/workbench/services/bulkEdit/electron-browser/bulkEditService';