浏览代码

work in progress

Afshin Darian 8 年之前
父节点
当前提交
90ae6451c4
共有 1 个文件被更改,包括 52 次插入3 次删除
  1. 52 3
      src/tooltip/plugin.ts

+ 52 - 3
src/tooltip/plugin.ts

@@ -5,6 +5,18 @@ import {
   JupyterLab, JupyterLabPlugin
 } from '../application';
 
+import {
+  CodeEditor
+} from '../codeeditor';
+
+import {
+  IConsoleTracker
+} from '../console';
+
+import {
+  INotebookTracker
+} from '../notebook';
+
 import {
   TooltipWidget
 } from './index';
@@ -16,7 +28,8 @@ import {
 const plugin: JupyterLabPlugin<void> = {
   activate,
   id: 'jupyter.extensions.tooltip',
-  autoStart: true
+  autoStart: true,
+  requires: [IConsoleTracker, INotebookTracker]
 };
 
 
@@ -29,6 +42,42 @@ export default plugin;
 /**
  * Activate the tooltip.
  */
-function activate(app: JupyterLab): void {
-  console.log('initialized tooltip plugin', TooltipWidget);
+function activate(app: JupyterLab, consoles: IConsoleTracker, notebooks: INotebookTracker): void {
+  const command = 'tooltip:launch';
+  const keymap = app.keymap;
+  const registry = app.commands;
+  registry.addCommand(command, {
+    execute: args => {
+      let notebook = args['notebook'] as boolean;
+      let editor: CodeEditor.IEditor | null = null;
+      if (notebook) {
+        let widget = notebooks.currentWidget;
+        if (widget) {
+          editor = widget.notebook.activeCell.editor;
+        }
+      } else {
+        let widget = consoles.currentWidget;
+        if (widget) {
+          editor = widget.console.prompt.editor;
+        }
+      }
+      if (editor) {
+        let tooltip = new TooltipWidget();
+        console.log('add tooltip for editor', editor, tooltip);
+      }
+    }
+  });
+  keymap.addBinding({
+    command,
+    args: { notebook: true },
+    keys: ['Shift Tab'],
+    selector: '.jp-Notebook'
+  });
+  keymap.addBinding({
+    command,
+    args: { notebook: false },
+    keys: ['Shift Tab'],
+    selector: '.jp-ConsolePanel'
+  });
+  console.log('initialized tooltip plugin', consoles, notebooks);
 }