Skip to content

Commit 9acebf6

Browse files
committed
- Debt reduction. Clean up views. - Implement Composed views viewlet - Adopt explorer debug viewlet to composed views viewlet
1 parent ed5bc91 commit 9acebf6

13 files changed

Lines changed: 361 additions & 524 deletions

File tree

src/vs/base/browser/ui/splitview/splitview.ts

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'vs/css!./splitview';
99
import lifecycle = require('vs/base/common/lifecycle');
1010
import ee = require('vs/base/common/eventEmitter');
1111
import types = require('vs/base/common/types');
12-
import objects = require('vs/base/common/objects');
1312
import dom = require('vs/base/browser/dom');
1413
import numbers = require('vs/base/common/numbers');
1514
import sash = require('vs/base/browser/ui/sash/sash');
@@ -240,10 +239,9 @@ export abstract class HeaderView extends View {
240239
}
241240

242241
export interface ICollapsibleViewOptions {
243-
ariaHeaderLabel?: string;
244-
fixedSize?: number;
245-
minimumSize?: number;
246-
headerSize?: number;
242+
sizing: ViewSizing;
243+
ariaHeaderLabel: string;
244+
bodySize?: number;
247245
initialState?: CollapsibleState;
248246
}
249247

@@ -260,14 +258,43 @@ export abstract class AbstractCollapsibleView extends HeaderView {
260258
private headerClickListener: lifecycle.IDisposable;
261259
private headerKeyListener: lifecycle.IDisposable;
262260
private focusTracker: dom.IFocusTracker;
261+
private _bodySize: number;
262+
private _previousSize: number = null;
263+
private readonly viewSizing: ViewSizing;
263264

264265
constructor(opts: ICollapsibleViewOptions) {
265266
super(opts);
267+
this.viewSizing = opts.sizing;
268+
this.ariaHeaderLabel = opts.ariaHeaderLabel;
266269

267-
this.ariaHeaderLabel = opts && opts.ariaHeaderLabel;
270+
this.setBodySize(types.isUndefined(opts.bodySize) ? 22 : opts.bodySize);
268271
this.changeState(types.isUndefined(opts.initialState) ? CollapsibleState.EXPANDED : opts.initialState);
269272
}
270273

274+
get previousSize(): number {
275+
return this._previousSize;
276+
}
277+
278+
setBodySize(bodySize: number) {
279+
this._bodySize = bodySize;
280+
this.updateSize();
281+
}
282+
283+
private updateSize() {
284+
if (this.viewSizing === ViewSizing.Fixed) {
285+
this.setFixed(this.state === CollapsibleState.EXPANDED ? this._bodySize + this.headerSize : this.headerSize);
286+
} else {
287+
this._minimumSize = this._bodySize + this.headerSize;
288+
this._previousSize = !this.previousSize || this._previousSize < this._minimumSize ? this._minimumSize : this._previousSize;
289+
if (this.state === CollapsibleState.EXPANDED) {
290+
this.setFlexible(this._previousSize || this._minimumSize);
291+
} else {
292+
this._previousSize = this.size || this._minimumSize;
293+
this.setFixed(this.headerSize);
294+
}
295+
}
296+
}
297+
271298
render(container: HTMLElement, orientation: Orientation): void {
272299
super.render(container, orientation);
273300

@@ -377,6 +404,7 @@ export abstract class AbstractCollapsibleView extends HeaderView {
377404
}
378405

379406
this.layoutHeader();
407+
this.updateSize();
380408
}
381409

382410
dispose(): void {
@@ -399,55 +427,6 @@ export abstract class AbstractCollapsibleView extends HeaderView {
399427
}
400428
}
401429

402-
export abstract class CollapsibleView extends AbstractCollapsibleView {
403-
404-
private previousSize: number;
405-
406-
constructor(opts: ICollapsibleViewOptions) {
407-
super(opts);
408-
this.previousSize = null;
409-
}
410-
411-
protected changeState(state: CollapsibleState): void {
412-
super.changeState(state);
413-
414-
if (state === CollapsibleState.EXPANDED) {
415-
this.setFlexible(this.previousSize || this._minimumSize);
416-
} else {
417-
this.previousSize = this.size;
418-
this.setFixed();
419-
}
420-
}
421-
}
422-
423-
export interface IFixedCollapsibleViewOptions extends ICollapsibleViewOptions {
424-
expandedBodySize?: number;
425-
}
426-
427-
export abstract class FixedCollapsibleView extends AbstractCollapsibleView {
428-
429-
private _expandedBodySize: number;
430-
431-
constructor(opts: IFixedCollapsibleViewOptions) {
432-
super(objects.mixin({ sizing: ViewSizing.Fixed }, opts));
433-
this._expandedBodySize = types.isUndefined(opts.expandedBodySize) ? 22 : opts.expandedBodySize;
434-
}
435-
436-
get fixedSize(): number { return this.state === CollapsibleState.EXPANDED ? this.expandedSize : this.headerSize; }
437-
private get expandedSize(): number { return this.expandedBodySize + this.headerSize; }
438-
439-
get expandedBodySize(): number { return this._expandedBodySize; }
440-
set expandedBodySize(size: number) {
441-
this._expandedBodySize = size;
442-
this.setFixed(this.fixedSize);
443-
}
444-
445-
protected changeState(state: CollapsibleState): void {
446-
super.changeState(state);
447-
this.setFixed(this.fixedSize);
448-
}
449-
}
450-
451430
class PlainView extends View {
452431
render() { }
453432
focus() { }
@@ -555,7 +534,7 @@ export class SplitView implements
555534
}
556535

557536
/**
558-
* Reset size to null. This will layout newly added viees to initial weights.
537+
* Reset size to null. This will layout newly added views to initial weights.
559538
*/
560539
this.size = null;
561540

@@ -599,13 +578,22 @@ export class SplitView implements
599578
this.viewFocusNextListeners.splice(index, 0, view.addListener('focusNext', () => index < this.views.length && this.views[index + 1].focus()));
600579
}
601580

581+
updateWeight(view: IView, weight: number) {
582+
let index = this.views.indexOf(view);
583+
if (index < 0) {
584+
return;
585+
}
586+
this.initialWeights[index] = weight;
587+
}
588+
602589
removeView(view: IView): void {
603590
let index = this.views.indexOf(view);
604591

605592
if (index < 0) {
606593
return;
607594
}
608595

596+
this.size = null;
609597
let deadView = new DeadView(view);
610598
this.views[index] = deadView;
611599
this.onViewChange(deadView, 0);

src/vs/workbench/parts/debug/browser/debugViewRegistry.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/vs/workbench/parts/debug/browser/debugViewlet.ts

Lines changed: 21 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,108 +4,49 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import 'vs/css!./media/debugViewlet';
7-
import { Builder, Dimension } from 'vs/base/browser/builder';
7+
import { Builder } from 'vs/base/browser/builder';
8+
import * as DOM from 'vs/base/browser/dom';
89
import { TPromise } from 'vs/base/common/winjs.base';
9-
import * as lifecycle from 'vs/base/common/lifecycle';
1010
import { IAction } from 'vs/base/common/actions';
1111
import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
12-
import { SplitView, HeaderView } from 'vs/base/browser/ui/splitview/splitview';
13-
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
14-
import { Scope } from 'vs/workbench/common/memento';
15-
import { Viewlet } from 'vs/workbench/browser/viewlet';
16-
import { IViewletView } from 'vs/workbench/parts/views/browser/views';
12+
import { ComposedViewsViewlet } from 'vs/workbench/parts/views/browser/views';
1713
import { IDebugService, VIEWLET_ID, State } from 'vs/workbench/parts/debug/common/debug';
18-
import { DebugViewRegistry } from 'vs/workbench/parts/debug/browser/debugViewRegistry';
1914
import { StartAction, ToggleReplAction, ConfigureAction } from 'vs/workbench/parts/debug/browser/debugActions';
2015
import { StartDebugActionItem } from 'vs/workbench/parts/debug/browser/debugActionItems';
2116
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2217
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
2318
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2419
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
25-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
20+
import { IStorageService } from 'vs/platform/storage/common/storage';
2621
import { IThemeService } from 'vs/platform/theme/common/themeService';
27-
import { attachHeaderViewStyler } from 'vs/platform/theme/common/styler';
22+
import { ViewLocation } from 'vs/workbench/parts/views/browser/viewsRegistry';
23+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2824

29-
const DEBUG_VIEWS_WEIGHTS = 'debug.viewsweights';
25+
export class DebugViewlet extends ComposedViewsViewlet {
3026

31-
export class DebugViewlet extends Viewlet {
32-
33-
private toDispose: lifecycle.IDisposable[];
3427
private actions: IAction[];
3528
private startDebugActionItem: StartDebugActionItem;
3629
private progressRunner: IProgressRunner;
37-
private viewletSettings: any;
38-
39-
private $el: Builder;
40-
private splitView: SplitView;
41-
private views: IViewletView[];
4230

4331
constructor(
4432
@ITelemetryService telemetryService: ITelemetryService,
4533
@IProgressService private progressService: IProgressService,
4634
@IDebugService private debugService: IDebugService,
47-
@IInstantiationService private instantiationService: IInstantiationService,
48-
@IWorkspaceContextService private contextService: IWorkspaceContextService,
49-
@IStorageService private storageService: IStorageService,
50-
@ILifecycleService lifecycleService: ILifecycleService,
51-
@IThemeService themeService: IThemeService
35+
@IInstantiationService instantiationService: IInstantiationService,
36+
@IWorkspaceContextService contextService: IWorkspaceContextService,
37+
@IStorageService storageService: IStorageService,
38+
@IThemeService themeService: IThemeService,
39+
@IContextKeyService contextKeyService: IContextKeyService
5240
) {
53-
super(VIEWLET_ID, telemetryService, themeService);
41+
super(VIEWLET_ID, ViewLocation.Debug, `${VIEWLET_ID}.state`, telemetryService, storageService, instantiationService, themeService, contextService, contextKeyService);
5442

5543
this.progressRunner = null;
56-
this.viewletSettings = this.getMemento(storageService, Scope.WORKSPACE);
57-
this.toDispose = [];
58-
this.views = [];
59-
this.toDispose.push(this.debugService.onDidChangeState(state => {
60-
this.onDebugServiceStateChange(state);
61-
}));
62-
lifecycleService.onShutdown(this.store, this);
63-
}
64-
65-
// viewlet
66-
67-
public create(parent: Builder): TPromise<void> {
68-
super.create(parent);
69-
this.$el = parent.div().addClass('debug-viewlet');
70-
71-
const actionRunner = this.getActionRunner();
72-
const registeredViews = DebugViewRegistry.getDebugViews();
73-
this.views = registeredViews.map(viewConstructor => this.instantiationService.createInstance(
74-
viewConstructor.view,
75-
actionRunner,
76-
this.viewletSettings)
77-
);
78-
79-
this.views.forEach((view, index) => {
80-
if (view instanceof HeaderView) {
81-
attachHeaderViewStyler(view, this.themeService, { noContrastBorder: index === 0 });
82-
}
83-
});
84-
85-
this.splitView = new SplitView(this.$el.getHTMLElement());
86-
this.toDispose.push(this.splitView);
87-
let weights: number[] = JSON.parse(this.storageService.get(DEBUG_VIEWS_WEIGHTS, StorageScope.WORKSPACE, '[]'));
88-
if (!weights.length) {
89-
weights = registeredViews.map(v => v.weight);
90-
}
91-
92-
for (let i = 0; i < this.views.length; i++) {
93-
this.splitView.addView(this.views[i], Math.max(weights[i], 1));
94-
}
95-
96-
return TPromise.as(null);
97-
}
9844

99-
public setVisible(visible: boolean): TPromise<any> {
100-
return super.setVisible(visible).then(() => {
101-
return TPromise.join(this.views.map(view => view.setVisible(visible)));
102-
});
45+
this._register(this.debugService.onDidChangeState(state => this.onDebugServiceStateChange(state)));
10346
}
10447

105-
public layout(dimension: Dimension): void {
106-
if (this.splitView) {
107-
this.splitView.layout(dimension.height);
108-
}
48+
public create(parent: Builder): TPromise<void> {
49+
return super.create(parent).then(() => DOM.addClass(this.viewletContainer, 'debug-viewlet'));
10950
}
11051

11152
public focus(): void {
@@ -127,16 +68,16 @@ export class DebugViewlet extends Viewlet {
12768
if (this.contextService.hasWorkspace()) {
12869
this.actions.push(this.instantiationService.createInstance(ConfigureAction, ConfigureAction.ID, ConfigureAction.LABEL));
12970
}
130-
this.actions.push(this.instantiationService.createInstance(ToggleReplAction, ToggleReplAction.ID, ToggleReplAction.LABEL));
131-
132-
this.actions.forEach(a => {
133-
this.toDispose.push(a);
134-
});
71+
this.actions.push(this._register(this.instantiationService.createInstance(ToggleReplAction, ToggleReplAction.ID, ToggleReplAction.LABEL)));
13572
}
13673

13774
return this.actions;
13875
}
13976

77+
public getSecondaryActions(): IAction[] {
78+
return [];
79+
}
80+
14081
public getActionItem(action: IAction): IActionItem {
14182
if (action.id === StartAction.ID && this.contextService.hasWorkspace()) {
14283
this.startDebugActionItem = this.instantiationService.createInstance(StartDebugActionItem, null, action);
@@ -157,19 +98,4 @@ export class DebugViewlet extends Viewlet {
15798
this.progressRunner = null;
15899
}
159100
}
160-
161-
private store(): void {
162-
this.storageService.store(DEBUG_VIEWS_WEIGHTS, JSON.stringify(this.views.map(view => view.size)), StorageScope.WORKSPACE);
163-
}
164-
165-
public dispose(): void {
166-
this.toDispose = lifecycle.dispose(this.toDispose);
167-
168-
super.dispose();
169-
}
170-
171-
public shutdown(): void {
172-
this.views.forEach(v => v.shutdown());
173-
super.shutdown();
174-
}
175101
}

src/vs/workbench/parts/debug/electron-browser/debug.contribution.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'v
1515
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionRegistryExtensions } from 'vs/workbench/common/actionRegistry';
1616
import { ToggleViewletAction, Extensions as ViewletExtensions, ViewletRegistry, ViewletDescriptor } from 'vs/workbench/browser/viewlet';
1717
import { TogglePanelAction, Extensions as PanelExtensions, PanelRegistry, PanelDescriptor } from 'vs/workbench/browser/panel';
18-
import { DebugViewRegistry } from 'vs/workbench/parts/debug/browser/debugViewRegistry';
1918
import { VariablesView, WatchExpressionsView, CallStackView, BreakpointsView } from 'vs/workbench/parts/debug/electron-browser/debugViews';
2019
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
2120
import { IDebugService, VIEWLET_ID, REPL_ID, CONTEXT_NOT_IN_DEBUG_MODE, CONTEXT_IN_DEBUG_MODE, INTERNAL_CONSOLE_OPTIONS_SCHEMA } from 'vs/workbench/parts/debug/common/debug';
@@ -35,6 +34,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
3534
import * as debugCommands from 'vs/workbench/parts/debug/electron-browser/debugCommands';
3635
import { IQuickOpenRegistry, Extensions as QuickOpenExtensions, QuickOpenHandlerDescriptor } from 'vs/workbench/browser/quickopen';
3736
import { StatusBarColorProvider } from 'vs/workbench/parts/debug/electron-browser/statusbarColorProvider';
37+
import { ViewLocation, ViewsRegistry } from 'vs/workbench/parts/views/browser/viewsRegistry';
3838

3939
class OpenDebugViewletAction extends ToggleViewletAction {
4040
public static ID = VIEWLET_ID;
@@ -94,10 +94,10 @@ Registry.as<PanelRegistry>(PanelExtensions.Panels).registerPanel(new PanelDescri
9494
Registry.as<PanelRegistry>(PanelExtensions.Panels).setDefaultPanelId(REPL_ID);
9595

9696
// Register default debug views
97-
DebugViewRegistry.registerDebugView(VariablesView, 10, 40);
98-
DebugViewRegistry.registerDebugView(WatchExpressionsView, 20, 10);
99-
DebugViewRegistry.registerDebugView(CallStackView, 30, 30);
100-
DebugViewRegistry.registerDebugView(BreakpointsView, 40, 20);
97+
ViewsRegistry.registerViews([{ id: 'workbench.debug.variablesView', name: '', ctor: VariablesView, order: 10, size: 40, location: ViewLocation.Debug }]);
98+
ViewsRegistry.registerViews([{ id: 'workbench.debug.watchExpressionsView', name: '', ctor: WatchExpressionsView, order: 20, size: 10, location: ViewLocation.Debug }]);
99+
ViewsRegistry.registerViews([{ id: 'workbench.debug.callStackView', name: '', ctor: CallStackView, order: 30, size: 30, location: ViewLocation.Debug }]);
100+
ViewsRegistry.registerViews([{ id: 'workbench.debug.breakPointsView', name: '', ctor: BreakpointsView, order: 40, size: 20, location: ViewLocation.Debug }]);
101101

102102
// register action to open viewlet
103103
const registry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionRegistryExtensions.WorkbenchActions);

0 commit comments

Comments
 (0)