Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
add updateToolbar function
Browse files Browse the repository at this point in the history
  • Loading branch information
KsavinN committed Dec 2, 2019
1 parent 4515241 commit a1040cd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
21 changes: 0 additions & 21 deletions src/handlers/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { EditorHandler } from '../handlers/editor';

import { Debugger } from '../debugger';

import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';
import { IDebugger } from '../tokens';

export class ConsoleHandler implements IDisposable {
Expand All @@ -33,24 +32,6 @@ export class ConsoleHandler implements IDisposable {
this.promptCellCreated,
this
);

const toolbar = new Toolbar();
toolbar.addItem(
'debugger-lifeCycle-button',
new ToolbarButton({
className: 'jp-debugger-switch-button',
iconClassName: 'jp-toggle-switch',
onClick: () => {
this.toogleState = !this.toogleState;
this.consolePanel.node.setAttribute(
'data-debugger-on',
this.toogleState.toString()
);
},
tooltip: 'ON/OFF Debugger state'
})
);
this.consolePanel.insertWidget(0, toolbar);
}

isDisposed: boolean;
Expand All @@ -73,8 +54,6 @@ export class ConsoleHandler implements IDisposable {
private debuggerModel: Debugger.Model;
private debuggerService: IDebugger;
private editorHandler: EditorHandler;
// We probably will remove that, now only for UI mock up
private toogleState: boolean = false;
}

export namespace DebuggerConsoleHandler {
Expand Down
45 changes: 44 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
IClientSession,
ICommandPalette,
MainAreaWidget,
Toolbar,
ToolbarButton,
WidgetTracker
} from '@jupyterlab/apputils';

Expand Down Expand Up @@ -88,6 +90,47 @@ async function setDebugSession(
app.commands.notifyCommandChanged();
}

function updateToolbar(
widget: NotebookPanel | ConsolePanel | FileEditor
): void {
console.log({ widget });

const isConsolePanel = widget instanceof ConsolePanel;
let toogleState = false;
const getToolbar = (): Toolbar => {
if (isConsolePanel) {
return (
((widget as ConsolePanel).widgets.find(
widget => widget instanceof Toolbar
) as Toolbar) || new Toolbar()
);
} else {
return (widget as NotebookPanel)?.toolbar;
}
};

const insertItemAndCheckIfExist = (toolbar: Toolbar) => {
return toolbar.addItem(
'debugger-lifeCycle-button',
new ToolbarButton({
className: 'jp-debugger-switch-button',
iconClassName: 'jp-toggle-switch',
onClick: () => {
toogleState = !toogleState;
widget.node.setAttribute('data-debugger-on', toogleState.toString());
},
tooltip: 'Enable / Disable Debugger'
})
);
};

const toolbar = getToolbar();

if (insertItemAndCheckIfExist(toolbar) && isConsolePanel) {
(widget as ConsolePanel).insertWidget(0, toolbar);
}
}

class DebuggerHandler<
H extends ConsoleHandler | NotebookHandler | FileHandler
> {
Expand All @@ -102,6 +145,7 @@ class DebuggerHandler<
if (!debug.model || this.handlers[widget.id] || !debug.isDebuggingEnabled) {
return;
}
updateToolbar(widget);
const handler = new this.builder({
debuggerService: debug,
widget
Expand All @@ -112,7 +156,6 @@ class DebuggerHandler<
handler.dispose();
delete this.handlers[widget.id];
});

debug.model.disposed.connect(async () => {
const handlerIds = Object.keys(this.handlers);
if (handlerIds.length === 0) {
Expand Down

0 comments on commit a1040cd

Please sign in to comment.