Prechádzať zdrojové kódy

Merge branch 'master' of https://github.com/jupyter/jupyter-js-plugins into notebookshortcuts

Jason Grout 9 rokov pred
rodič
commit
2440adc989
4 zmenil súbory, kde vykonal 55 pridanie a 4 odobranie
  1. 2 2
      package.json
  2. 11 1
      src/fileopener/index.ts
  3. 41 0
      src/fileopener/plugin.ts
  4. 1 1
      src/notebook/plugin.ts

+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jupyter-js-plugins",
-  "version": "0.3.2",
+  "version": "0.4.0",
   "description": "Plugins for JupyterLab",
   "main": "lib/index.js",
   "typings": "lib/index.d.ts",
@@ -9,7 +9,7 @@
     "jquery": "^2.2.0",
     "jquery-ui": "^1.10.5",
     "jupyter-js-cells": "^0.2.5",
-    "jupyter-js-filebrowser": "^0.6.1",
+    "jupyter-js-filebrowser": "^0.7.1",
     "jupyter-js-notebook": "^0.3.7",
     "jupyter-js-services": "^0.4.2",
     "jupyter-js-terminal": "^0.1.12",

+ 11 - 1
src/fileopener/index.ts

@@ -30,10 +30,20 @@ interface IFileHandler {
   finished: ISignal<IFileHandler, IContentsModel>;
 
   /**
-   * he list of file extensions supported by the handler.
+   * The list of file extensions supported by the handler.
    */
   fileExtensions: string[];
 
+  /**
+   * The list of mime types explicitly supported by the handler.
+   */
+  mimeTypes: string[];
+
+  /**
+   * The current set of widgets managed by the handler.
+   */
+  widgets: Widget[];
+
   /**
    * Open the file and return a populated widget.
    */

+ 41 - 0
src/fileopener/plugin.ts

@@ -14,6 +14,9 @@ import {
   IAppShell, ICommandPalette, ICommandRegistry, IShortcutManager
 } from 'phosphide';
 
+import * as arrays
+ from 'phosphor-arrays';
+
 import {
   SimpleCommand
 } from 'phosphor-command';
@@ -43,6 +46,13 @@ import {
 } from './index';
 
 
+/**
+ * The class name added to focused widgets.
+ */
+export
+const FOCUS_CLASS = 'jp-mod-focus';
+
+
 /**
  * Register the plugin contributions.
  */
@@ -152,6 +162,17 @@ class FileOpener implements IFileOpener {
     this._appShell = appShell;
     browser.openRequested.connect(this._openRequested,
       this);
+    document.addEventListener('focus', this._onFocus.bind(this), true);
+  }
+
+  /**
+   * Get the most recently focused widget.
+   *
+   * #### Notes
+   * This is a read-only property.
+   */
+  get currentWidget(): Widget {
+    return this._currentWidget;
   }
 
   /**
@@ -232,7 +253,27 @@ class FileOpener implements IFileOpener {
     return widget;
   }
 
+  /**
+   * Handle a focus event on the document.
+   */
+  private _onFocus(event: Event) {
+    for (let h of this._handlers) {
+      // If the widget belongs to the handler, update the focused widget.
+      let widget = arrays.find(h.widgets,
+        w => { return w.node.contains(event.target as HTMLElement); });
+      if (widget === this._currentWidget) {
+        return;
+      } else if (widget) {
+        if (this._currentWidget) this._currentWidget.removeClass(FOCUS_CLASS);
+        this._currentWidget = widget;
+        widget.addClass(FOCUS_CLASS);
+        return;
+      }
+    }
+  }
+
   private _handlers: IFileHandler[] = [];
   private _appShell: IAppShell = null;
   private _defaultHandler: IFileHandler = null;
+  private _currentWidget: Widget = null;
 }

+ 1 - 1
src/notebook/plugin.ts

@@ -233,7 +233,7 @@ class NotebookFileHandler extends AbstractFileHandler {
       // specific `.jp-active-document` class, for example. Then the keyboard shortcut
       // selects on that. The application state would also have a handle on this active
       // document (model or widget), and so we could execute the current active cell.
-      let prefix = `.${notebookContainerClass}.notebook-id-${n22otebookId}`
+      let prefix = `.${notebookContainerClass}.notebook-id-${notebookId}`
       this.shortcuts.add([{
         sequence: ['Shift Enter'],
         selector: `${prefix} .jp-CodeCell`,