Bladeren bron

Add save/revert/close commands

Steven Silvester 9 jaren geleden
bovenliggende
commit
316fdfe2b1
3 gewijzigde bestanden met toevoegingen van 100 en 10 verwijderingen
  1. 98 9
      src/documentmanager/plugin.ts
  2. 1 0
      src/imagehandler/plugin.ts
  3. 1 1
      src/notebook/plugin.ts

+ 98 - 9
src/documentmanager/plugin.ts

@@ -46,6 +46,13 @@ import {
 } from './index';
 
 
+/**
+ * The class name added to document widgets.
+ */
+export
+const DOCUMENT_CLASS = 'jp-Document';
+
+
 /**
  * The class name added to focused widgets.
  */
@@ -111,6 +118,26 @@ function resolve(container: Container): Promise<void> {
         }
       });
 
+      registry.add([
+        {
+          id: newNotebookId,
+          command: newNotebookCommand
+        }
+      ]);
+      shortcuts.add([
+        {
+          sequence: ['Ctrl Shift N'],
+          selector: '*',
+          command: newNotebookId
+        }
+      ]);
+      palette.add([
+        {
+          id: newNotebookId,
+          args: void 0
+        }
+      ]);
+
       // Add the command for saving a document.
       let saveDocumentId = 'file-operations:save';
       let saveDocumentCommand = new SimpleCommand({
@@ -123,6 +150,26 @@ function resolve(container: Container): Promise<void> {
         }
       });
 
+      registry.add([
+        {
+          id: saveDocumentId,
+          command: saveDocumentCommand
+        }
+      ]);
+      shortcuts.add([
+        {
+          sequence: ['Accel S'],
+          selector: '*',
+          command: saveDocumentId
+        }
+      ]);
+      palette.add([
+        {
+          id: saveDocumentId,
+          args: void 0
+        }
+      ]);
+
       // Add the command for reverting a document.
       let revertDocumentId = 'file-operations:revert';
       let revertDocumentCommand = new SimpleCommand({
@@ -135,6 +182,26 @@ function resolve(container: Container): Promise<void> {
         }
       });
 
+      registry.add([
+        {
+          id: revertDocumentId,
+          command: revertDocumentCommand
+        }
+      ]);
+      shortcuts.add([
+        {
+          sequence: ['Accel R'],
+          selector: '*',
+          command: revertDocumentId
+        }
+      ]);
+      palette.add([
+        {
+          id: revertDocumentId,
+          args: void 0
+        }
+      ]);
+
       // Add the command for closing a document.
       let closeDocumentId = 'file-operations:close';
       let closeDocumentCommand = new SimpleCommand({
@@ -147,6 +214,26 @@ function resolve(container: Container): Promise<void> {
         }
       });
 
+      registry.add([
+        {
+          id: closeDocumentId,
+          command: closeDocumentCommand
+        }
+      ]);
+      shortcuts.add([
+        {
+          sequence: ['Ctrl Q'],
+          selector: '*',
+          command: closeDocumentId
+        }
+      ]);
+      palette.add([
+        {
+          id: closeDocumentId,
+          args: void 0
+        }
+      ]);
+
       // Add the command for closing all documents.
       let closeAllId = 'file-operations:close-all';
       let closeAllCommand = new SimpleCommand({
@@ -161,20 +248,20 @@ function resolve(container: Container): Promise<void> {
 
       registry.add([
         {
-          id: newNotebookId,
-          command: newNotebookCommand
+          id: closeAllId,
+          command: closeAllCommand
         }
       ]);
       shortcuts.add([
         {
-          sequence: ['Ctrl Shift N'],
+          sequence: ['Ctrl Shift Q'],
           selector: '*',
-          command: newNotebookId
+          command: closeAllId
         }
       ]);
       palette.add([
         {
-          id: newNotebookId,
+          id: saveDocumentId,
           args: void 0
         }
       ]);
@@ -255,15 +342,15 @@ class DocumentManager implements IDocumentManager {
     for (let h of this._handlers) {
       if (h.fileExtensions.indexOf(ext) !== -1) handlers.push(h);
     }
-
+    let widget: Widget;
     // If there was only one match, use it.
     if (handlers.length === 1) {
-      return this._open(handlers[0], model);
+      widget = this._open(handlers[0], model);
 
     // If there were no matches, use default handler.
     } else if (handlers.length === 0) {
       if (this._defaultHandler !== null) {
-        return this._open(this._defaultHandler, model);
+        widget = this._open(this._defaultHandler, model);
       } else {
         throw new Error(`Could not open file '${path}'`);
       }
@@ -271,8 +358,10 @@ class DocumentManager implements IDocumentManager {
     // There are more than one possible handlers.
     } else {
       // TODO: Ask the user to choose one.
-      return this._open(handlers[0], model);
+      widget = this._open(handlers[0], model);
     }
+    widget.addClass(DOCUMENT_CLASS);
+    return widget;
   }
 
   /**

+ 1 - 0
src/imagehandler/plugin.ts

@@ -67,6 +67,7 @@ class ImageHandler extends AbstractFileHandler {
   protected createWidget(model: IContentsModel): Widget {
     let ext = model.path.split('.').pop();
     var widget = new Widget();
+    widget.node.tabIndex = 1;
     let image = document.createElement('img');
     widget.node.appendChild(image);
     widget.node.style.overflowX = 'auto';

+ 1 - 1
src/notebook/plugin.ts

@@ -41,7 +41,7 @@ import {
 } from 'phosphor-widget';
 
 import {
-  IServicesProvider, IDocumentManager
+  IServicesProvider, IDocumentManager, IFileHandler
 } from '../index';
 
 import {