瀏覽代碼

Reimplement the + (create from...) dropdown menu of file browser.

Afshin Darian 8 年之前
父節點
當前提交
40e5d176f0
共有 2 個文件被更改,包括 15 次插入26 次删除
  1. 1 2
      packages/docmanager-extension/src/index.ts
  2. 14 24
      packages/filebrowser/src/buttons.ts

+ 1 - 2
packages/docmanager-extension/src/index.ts

@@ -118,8 +118,7 @@ function addCommands(app: JupyterLab, docManager: IDocumentManager, palette: ICo
   });
 
   commands.addCommand(CommandIDs.createFrom, {
-    label: args => (args['label'] as string) ||
-      `Create ${args['creatorName'] as string}`,
+    label: args => args['creatorName'] as string,
     execute: args => {
       const path = args['path'] as string;
       const creatorName = args['creatorName'] as string;

+ 14 - 24
packages/filebrowser/src/buttons.ts

@@ -14,12 +14,12 @@ import {
 } from '@jupyterlab/services';
 
 import {
-  CommandRegistry
-} from '@phosphor/commands';
+  each, toArray
+} from '@phosphor/algorithm';
 
 import {
-  DisposableSet
-} from '@phosphor/disposable';
+  CommandRegistry
+} from '@phosphor/commands';
 
 import {
   Menu, Widget
@@ -393,11 +393,7 @@ namespace Private {
    */
   export
   function createDropdownMenu(widget: FileButtons, commands: CommandRegistry): Menu {
-    let menu = new Menu({ commands });
-    let disposables = new DisposableSet();
-
-    // Remove all the commands associated with this menu upon disposal.
-    menu.disposed.connect(() => disposables.dispose());
+    const menu = new Menu({ commands });
 
     // Add new folder menu item.
     menu.addItem({
@@ -410,21 +406,15 @@ namespace Private {
       command: 'file-operations:new-untitled'
     });
 
-    console.log('TODO: implement create from menu in file browser buttons');
-    // let prefix = `file-buttons-${++id}`;
-    // let registry = widget.manager.registry;
-    // let command: string;
-    // each(registry.creators(), creator => {
-    //   console.log('boom', creator.name);
-    //   command = `${prefix}:new-${creator.name}`;
-    //   disposables.add(commands.addCommand(command, {
-    //     execute: () => {
-    //       widget.createFrom(creator.name);
-    //     },
-    //     label: creator.name
-    //   }));
-    //   menu.addItem({ command });
-    // });
+    const { registry } = widget.manager;
+    const items = toArray(widget.model.items()).map(item => item.path);
+    const path = widget.model.path;
+    each(registry.creators(), creator => {
+      const command = 'file-operations:create-from';
+      const creatorName = creator.name;
+      const args = { creatorName, items, path };
+      menu.addItem({ args, command });
+    });
     return menu;
   }