Skip to content

Commit 346f789

Browse files
committed
Populate the dropdown on the debug-toolbar using DebugConfigManager
1 parent 0862a60 commit 346f789

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

debug-toolbar/debug-toolbar.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@
5353
<paper-icon-button id="startButton" icon="av:play-arrow" alt="Start Debugging"></paper-icon-button>
5454
<paper-icon-button id="stopButton" icon="av:stop" alt="Stop Debugging"></paper-icon-button>
5555
</div>
56-
<paper-dropdown-menu id="configs" label="Configurations" no-label-float>
56+
<paper-dropdown-menu id="configs" label="Configuration" no-label-float>
5757
<paper-menu class="dropdown-content">
5858
<paper-item id="newConfigItem">New...</paper-item>
59-
<paper-item>Launch</paper-item>
60-
<paper-item>Attach</paper-item>
59+
<template is="dom-repeat" items="[[debugConfigs]]">
60+
<paper-item>[[item]]</paper-item>
61+
</template>
6162
</paper-menu>
6263
</paper-dropdown-menu>
6364
<paper-icon-button icon="av:pause" alt="Pause Debugging" disabled></paper-icon-button>

debug-toolbar/debug-toolbar.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT License, see LICENSE file for full terms.
33

44
import * as pd from 'polymer-ts-decorators';
5-
import { Disposable } from 'event-kit';
5+
import { CompositeDisposable, Disposable } from 'event-kit';
66
import addDisposableListener from '../lib/disposable-dom-event-listener';
77
import * as debugWorkbench from '../lib/debug-workbench';
88
import { IDebugSession } from '../lib/debug-engine'
@@ -27,10 +27,18 @@ const START_DEBUGGING_EVENT = 'start-debugging';
2727
const STOP_DEBUGGING_EVENT = 'stop-debugging';
2828
const OPEN_SETTINGS_EVENT = 'open-settings';
2929

30+
function getDebugConfigNames(): string[] {
31+
return debugWorkbench.debugConfigs.getAll().map((debugConfig) => debugConfig.name);
32+
}
33+
3034
@pd.is('debug-workbench-debug-toolbar')
3135
export default class DebugToolbarElement {
36+
private subscriptions: CompositeDisposable;
3237
private debugSession: IDebugSession;
3338

39+
@pd.property({ type: Array, value: getDebugConfigNames })
40+
private debugConfigs: string[];
41+
3442
static create(): Promise<IDebugToolbarElement> {
3543
return debugWorkbench.createElement((<any> DebugToolbarElement.prototype).is);
3644
}
@@ -50,6 +58,41 @@ export default class DebugToolbarElement {
5058
return addDisposableListener(<any> this, OPEN_SETTINGS_EVENT, callback);
5159
}
5260

61+
created(): void {
62+
this.subscriptions = new CompositeDisposable();
63+
}
64+
65+
ready(): void {
66+
this.subscriptions.add(debugWorkbench.debugConfigs.onDidAddConfig(
67+
(addedConfig) => {
68+
base(this).push('debugConfigs', addedConfig.name);
69+
}
70+
));
71+
this.subscriptions.add(debugWorkbench.debugConfigs.onDidRemoveConfig(
72+
(removedConfig) => {
73+
const idx = this.debugConfigs.indexOf(removedConfig.name);
74+
if (idx > -1) {
75+
base(this).splice('debugConfigs', idx, 1);
76+
}
77+
}
78+
));
79+
this.subscriptions.add(debugWorkbench.debugConfigs.onDidRenameConfig(
80+
({ newName, oldName }) => {
81+
const idx = this.debugConfigs.indexOf(oldName);
82+
if (idx > -1) {
83+
base(this).set(['debugConfigs', idx], newName);
84+
}
85+
}
86+
));
87+
}
88+
89+
destroy(): void {
90+
if (this.subscriptions) {
91+
this.subscriptions.dispose();
92+
this.subscriptions = null;
93+
}
94+
}
95+
5396
@pd.listener('startButton.tap')
5497
private startDebugging(): void {
5598
base(this).fire(START_DEBUGGING_EVENT);

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,19 @@ declare module 'debug-workbench-core-components/lib/disposable-dom-event-listene
215215
declare module 'debug-workbench-core-components/debug-toolbar/debug-toolbar' {
216216
import { Disposable } from 'event-kit';
217217
export default class DebugToolbarElement {
218+
private subscriptions;
218219
private debugSession;
220+
private debugConfigs;
219221
static create(): Promise<IDebugToolbarElement>;
220222
/** Add a listener to be called when the Start button is pressed. */
221223
onStartButtonPressed(callback: EventListener): Disposable;
222224
/** Add a listener to be called when the Stop button is pressed. */
223225
onStopButtonPressed(callback: EventListener): Disposable;
224226
/** Add a listener to be called when the Settings button is pressed. */
225227
onSettingsButtonPressed(callback: EventListener): Disposable;
228+
created(): void;
229+
ready(): void;
230+
destroy(): void;
226231
private startDebugging();
227232
private stopDebugging();
228233
private openSettings();

0 commit comments

Comments
 (0)