浏览代码

Add new file and new markdown file to context menu

resolves #4280
qntnrbns 5 年之前
父节点
当前提交
a7bfa38c6b
共有 1 个文件被更改,包括 47 次插入1 次删除
  1. 47 1
      packages/filebrowser-extension/src/index.ts

+ 47 - 1
packages/filebrowser-extension/src/index.ts

@@ -87,6 +87,10 @@ namespace CommandIDs {
 
   export const createNewDirectory = 'filebrowser:create-new-directory';
 
+  export const createNewFile = 'filebrowser:create-new-file';
+
+  export const createNewMarkdownFile = 'filebrowser:create-new-markdown-file';
+
   export const rename = 'filebrowser:rename';
 
   // For main browser only.
@@ -640,6 +644,36 @@ function addCommands(
     label: 'New Folder'
   });
 
+  commands.addCommand(CommandIDs.createNewFile, {
+    execute: () => {
+      const {
+        model: { path }
+      } = browser;
+      commands.execute('docmanager:new-untitled', {
+        path,
+        type: 'file',
+        ext: 'txt'
+      });
+    },
+    iconClass: 'jp-MaterialIcon jp-TextEditorIcon',
+    label: 'New File'
+  });
+
+  commands.addCommand(CommandIDs.createNewMarkdownFile, {
+    execute: () => {
+      const {
+        model: { path }
+      } = browser;
+      commands.execute('docmanager:new-untitled', {
+        path,
+        type: 'file',
+        ext: 'md'
+      });
+    },
+    iconClass: 'jp-MaterialIcon jp-MarkdownIcon',
+    label: 'New Markdown File'
+  });
+
   commands.addCommand(CommandIDs.rename, {
     execute: args => {
       const widget = tracker.currentWidget;
@@ -842,11 +876,23 @@ function addCommands(
   });
 
   app.contextMenu.addItem({
-    command: CommandIDs.paste,
+    command: CommandIDs.createNewFile,
     selector: selectorContent,
     rank: 2
   });
 
+  app.contextMenu.addItem({
+    command: CommandIDs.createNewMarkdownFile,
+    selector: selectorContent,
+    rank: 3
+  });
+
+  app.contextMenu.addItem({
+    command: CommandIDs.paste,
+    selector: selectorContent,
+    rank: 4
+  });
+
   app.contextMenu.addItem({
     command: CommandIDs.open,
     selector: selectorItem,