Skip to content

Commit

Permalink
Merge pull request #7483 from qntnrbns/new-file-in-context-menu
Browse files Browse the repository at this point in the history
Add new file and new markdown file to file browser context menu
  • Loading branch information
blink1073 committed Nov 7, 2019
2 parents 3881726 + a7bfa38 commit a32aae0
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion packages/filebrowser-extension/src/index.ts
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a32aae0

Please sign in to comment.