浏览代码

Add `file-operations:new-untitled` command to document manager.

Afshin Darian 8 年之前
父节点
当前提交
3b41a85b95

+ 13 - 5
packages/docmanager-extension/src/index.ts

@@ -10,7 +10,7 @@ import {
 } from '@jupyterlab/apputils';
 
 import {
-  DocumentManager, IDocumentManager
+  DocumentManager, IDocumentManager, showErrorMessage
 } from '@jupyterlab/docmanager';
 
 import {
@@ -18,7 +18,7 @@ import {
 } from '@jupyterlab/docregistry';
 
 import {
-  IServiceManager
+  Contents, IServiceManager
 } from '@jupyterlab/services';
 
 
@@ -121,12 +121,20 @@ function addCommands(app: JupyterLab, docManager: IDocumentManager, palette: ICo
 
   commands.addCommand(CommandIDs.newUntitled, {
     execute: args => {
+      const errorMessage = args.error as string || 'Error';
+      let options: Partial<Contents.ICreateOptions> = {
+        type: args.type as Contents.ContentType,
+        path: args.path as string
+      };
+
       if (args.type === 'file') {
-        args.ext = args.ext || '.txt';
+        options.ext = args.ext as string || '.txt';
       }
 
-      return docManager.services.contents.newUntitled(args);
-    }
+      return docManager.services.contents.newUntitled(options)
+        .catch(error => showErrorMessage(errorMessage, error));
+    },
+    label: args => args.label as string || 'New Folder'
   });
 
   commands.addCommand(CommandIDs.restoreCheckpoint, {

+ 22 - 0
packages/docmanager/src/dialogs.ts

@@ -0,0 +1,22 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import {
+  Dialog, showDialog
+} from '@jupyterlab/apputils';
+
+
+/**
+ * An error message dialog to show in the filebrowser widget.
+ */
+export
+function showErrorMessage(title: string, error: Error): Promise<void> {
+  console.error(error);
+  let options = {
+    title: title,
+    body: error.message || `File ${title}`,
+    buttons: [Dialog.okButton()],
+    okText: 'DISMISS'
+  };
+  return showDialog(options).then(() => { /* no-op */ });
+}

+ 1 - 0
packages/docmanager/src/index.ts

@@ -1,6 +1,7 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+export * from './dialogs';
 export * from './manager';
 export * from './savehandler';
 export * from './widgetmanager';

+ 3 - 3
packages/docmanager/src/manager.ts

@@ -399,11 +399,11 @@ class DocumentManager implements IDisposable {
     this._activateRequested.emit(args);
   }
 
-  private _widgetManager: DocumentWidgetManager = null;
-  private _contexts: Private.IContext[] = [];
-  private _opener: DocumentManager.IWidgetOpener = null;
   private _activateRequested = new Signal<this, string>(this);
+  private _contexts: Private.IContext[] = [];
   private _modelDBFactory: ModelDB.IFactory = null;
+  private _opener: DocumentManager.IWidgetOpener = null;
+  private _widgetManager: DocumentWidgetManager = null;
 }