|
1 | 1 | "use strict"; |
| 2 | +var __extends = (this && this.__extends) || (function () { |
| 3 | + var extendStatics = Object.setPrototypeOf || |
| 4 | + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 5 | + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| 6 | + return function (d, b) { |
| 7 | + extendStatics(d, b); |
| 8 | + function __() { this.constructor = d; } |
| 9 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 10 | + }; |
| 11 | +})(); |
2 | 12 | Object.defineProperty(exports, "__esModule", { value: true }); |
3 | 13 | var disposable_1 = require("@phosphor/disposable"); |
| 14 | +var application_1 = require("@jupyterlab/application"); |
4 | 15 | var apputils_1 = require("@jupyterlab/apputils"); |
| 16 | +var services_1 = require("@jupyterlab/services"); |
| 17 | +var coreutils_1 = require("@phosphor/coreutils"); |
| 18 | +var widgets_1 = require("@phosphor/widgets"); |
5 | 19 | require("../style/index.css"); |
6 | 20 | /** |
7 | | - * The plugin registration information. |
| 21 | + * Initialization data for the jupyterlab_xkcd extension. |
8 | 22 | */ |
9 | | -var plugin = { |
10 | | - activate: activate, |
11 | | - id: 'jupyter.extensions.new-button', |
12 | | - autoStart: true |
| 23 | +var extension = { |
| 24 | + id: 'jupyterlab_kr', |
| 25 | + autoStart: true, |
| 26 | + requires: [apputils_1.ICommandPalette, application_1.ILayoutRestorer], |
| 27 | + activate: activate |
13 | 28 | }; |
14 | 29 | /** |
15 | 30 | * A notebook widget extension that adds a button to the toolbar. |
@@ -53,13 +68,76 @@ var ButtonExtension = (function () { |
53 | 68 | }()); |
54 | 69 | exports.ButtonExtension = ButtonExtension; |
55 | 70 | /** |
56 | | - * Activate the extension. |
| 71 | + * An new widget. |
| 72 | + */ |
| 73 | +var NewWidget = (function (_super) { |
| 74 | + __extends(NewWidget, _super); |
| 75 | + /** |
| 76 | + * Construct a new xkcd widget. |
| 77 | + */ |
| 78 | + function NewWidget() { |
| 79 | + var _this = _super.call(this) || this; |
| 80 | + _this.settings = services_1.ServerConnection.makeSettings(); |
| 81 | + _this.id = 'newwidget'; |
| 82 | + _this.title.label = 'My Widget'; |
| 83 | + _this.title.closable = true; |
| 84 | + _this.addClass('jp-newWidget'); |
| 85 | + return _this; |
| 86 | + } |
| 87 | + /** |
| 88 | + * Handle update requests for the widget. |
| 89 | + */ |
| 90 | + NewWidget.prototype.onUpdateRequest = function (msg) { |
| 91 | + }; |
| 92 | + return NewWidget; |
| 93 | +}(widgets_1.Widget)); |
| 94 | +; |
| 95 | +/** |
| 96 | + * Activate the xckd widget extension. |
57 | 97 | */ |
58 | | -function activate(app) { |
| 98 | +function activate(app, palette, restorer) { |
| 99 | + console.log('JupyterLab extension newwidget is activated!'); |
59 | 100 | app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension()); |
| 101 | + // Declare a widget variable |
| 102 | + var widget; |
| 103 | + // Add an application command |
| 104 | + var command = 'newwidget:open'; |
| 105 | + app.commands.addCommand(command, { |
| 106 | + label: 'New Widget', |
| 107 | + execute: function () { |
| 108 | + if (!widget) { |
| 109 | + // Create a new widget if one does not exist |
| 110 | + widget = new NewWidget(); |
| 111 | + widget.update(); |
| 112 | + } |
| 113 | + if (!tracker.has(widget)) { |
| 114 | + // Track the state of the widget for later restoration |
| 115 | + tracker.add(widget); |
| 116 | + } |
| 117 | + if (!widget.isAttached) { |
| 118 | + // Attach the widget to the main area if it's not there |
| 119 | + app.shell.addToMainArea(widget); |
| 120 | + } |
| 121 | + else { |
| 122 | + // Refresh the widget |
| 123 | + widget.update(); |
| 124 | + } |
| 125 | + // Activate the widget |
| 126 | + app.shell.activateById(widget.id); |
| 127 | + } |
| 128 | + }); |
| 129 | + // Add the command to the palette. |
| 130 | + palette.addItem({ command: command, category: 'Tools' }); |
| 131 | + // Track and restore the widget state |
| 132 | + var tracker = new apputils_1.InstanceTracker({ namespace: 'tools' }); |
| 133 | + restorer.restore(tracker, { |
| 134 | + command: command, |
| 135 | + args: function () { return coreutils_1.JSONExt.emptyObject; }, |
| 136 | + name: function () { return 'newwidget'; } |
| 137 | + }); |
60 | 138 | } |
61 | 139 | ; |
62 | 140 | /** |
63 | 141 | * Export the plugin as default. |
64 | 142 | */ |
65 | | -exports.default = plugin; |
| 143 | +exports.default = extension; |
0 commit comments