Skip to content

Commit 41d923a

Browse files
committed
Add Command Button for testing
1 parent e9260dd commit 41d923a

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

src/editor.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { DocumentRegistry, DocumentWidget } from '@jupyterlab/docregistry';
1616

1717
import { MainMenu, JupyterLabMenu } from '@jupyterlab/mainmenu';
1818

19+
import { CommandToolbarButton } from '@jupyterlab/apputils';
20+
1921
import { IChangedArgs, PathExt } from '@jupyterlab/coreutils';
2022

2123
import { CommandRegistry } from '@lumino/commands';
@@ -41,6 +43,7 @@ export class DrawIODocumentWidget extends DocumentWidget<DrawIOWidget> {
4143
this._menubar = new MainMenu(this._commands);
4244

4345
this._menubar.clearMenus();
46+
this.toolbar.addClass('dio-toolbar');
4447

4548
//TODO:
4649
// Add toolbar actions to change the default style of arrows and conections.
@@ -208,11 +211,15 @@ export class DrawIODocumentWidget extends DocumentWidget<DrawIOWidget> {
208211
'zoomOut',
209212
new DrawIOToolbarButton(actions['zoomOut'])
210213
);
211-
212-
actions['undo'].iconCls = 'geSprite geSprite-undo';
213-
this.toolbar.addItem('undo', new DrawIOToolbarButton(actions['undo']));
214-
actions['redo'].iconCls = 'geSprite geSprite-redo';
215-
this.toolbar.addItem('redo', new DrawIOToolbarButton(actions['redo']));
214+
215+
this.toolbar.addItem('undo', new CommandToolbarButton({
216+
id: 'drawio:command/undo',
217+
commands: this._commands
218+
}));
219+
this.toolbar.addItem('redo', new CommandToolbarButton({
220+
id: 'drawio:command/redo',
221+
commands: this._commands
222+
}));
216223

217224
actions['delete'].iconCls = 'geSprite geSprite-delete';
218225
this.toolbar.addItem('delete', new DrawIOToolbarButton(actions['delete']));

src/index.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
3030

3131
import { ILauncher } from '@jupyterlab/launcher';
3232

33+
import {
34+
undoIcon,
35+
redoIcon,
36+
} from '@jupyterlab/ui-components';
37+
3338
import { CommandRegistry } from '@lumino/commands';
3439

3540
import { Token } from '@lumino/coreutils';
@@ -514,8 +519,8 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
514519
// Select vertices, select edges, select all, select none
515520
// lock/unlock
516521
const editCommands = [
517-
{ name: 'undo', label: 'Undo' }, //Ctrl+Z
518-
{ name: 'redo', label: 'Redo' }, //Ctrl+Shift+Z
522+
//{ name: 'undo', label: 'Undo' }, //Ctrl+Z
523+
//{ name: 'redo', label: 'Redo' }, //Ctrl+Shift+Z
519524
{ name: 'cut', label: 'Cut' }, //Ctrl+X
520525
{ name: 'copy', label: 'Copy' }, //Ctrl+C
521526
{ name: 'paste', label: 'Paste' }, //Ctrl+V
@@ -559,6 +564,56 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
559564
}
560565
});
561566
});
567+
app.commands.addCommand('drawio:command/undo', {
568+
label: 'Undo',
569+
caption: 'Undo (Ctrl+Z)',
570+
icon: undoIcon,
571+
isEnabled: () => {
572+
if (
573+
tracker.currentWidget !== null &&
574+
tracker.currentWidget === app.shell.currentWidget
575+
) {
576+
const wdg = app.shell.currentWidget as DrawIODocumentWidget;
577+
return wdg.getAction('undo').enabled;
578+
} else {
579+
return false;
580+
}
581+
},
582+
execute: () => {
583+
if (
584+
tracker.currentWidget !== null &&
585+
tracker.currentWidget === app.shell.currentWidget
586+
) {
587+
const wdg = app.shell.currentWidget as DrawIODocumentWidget;
588+
wdg.getAction('undo').funct();
589+
}
590+
}
591+
});
592+
app.commands.addCommand('drawio:command/redo', {
593+
label: 'Redo',
594+
caption: 'redo (Ctrl+Shift+Z)',
595+
icon: redoIcon,
596+
isEnabled: () => {
597+
if (
598+
tracker.currentWidget !== null &&
599+
tracker.currentWidget === app.shell.currentWidget
600+
) {
601+
const wdg = app.shell.currentWidget as DrawIODocumentWidget;
602+
return wdg.getAction('redo').enabled;
603+
} else {
604+
return false;
605+
}
606+
},
607+
execute: () => {
608+
if (
609+
tracker.currentWidget !== null &&
610+
tracker.currentWidget === app.shell.currentWidget
611+
) {
612+
const wdg = app.shell.currentWidget as DrawIODocumentWidget;
613+
wdg.getAction('redo').funct();
614+
}
615+
}
616+
});
562617

563618
// View MENU
564619
//Not Working:

style/base.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.dio-toolbar-dropdown:not(:-internal-list-box) {
22
overflow: visible !important;
3+
}
4+
5+
.dio-toolbar .jp-ToolbarButtonComponent-label {
6+
display: none;
37
}

0 commit comments

Comments
 (0)