Archived
Add a New File menu item for plain text files (#6240)
* Add a New File menu item for plain text files * Correct handling of saved files * Fix command palette text to avoid duplicate entry
This commit is contained in:
@@ -36,8 +36,10 @@ export const notebookModeId = 'notebook';
|
|||||||
* @param instantiationService The instantiation service to use to create the new input types
|
* @param instantiationService The instantiation service to use to create the new input types
|
||||||
*/
|
*/
|
||||||
export function convertEditorInput(input: EditorInput, options: IQueryEditorOptions, instantiationService: IInstantiationService): EditorInput {
|
export function convertEditorInput(input: EditorInput, options: IQueryEditorOptions, instantiationService: IInstantiationService): EditorInput {
|
||||||
let denyQueryEditor = options && options.denyQueryEditor;
|
let denyQueryEditor: boolean = options && options.denyQueryEditor;
|
||||||
if (input && !denyQueryEditor) {
|
let untitledEditorInput: UntitledEditorInput = input as UntitledEditorInput;
|
||||||
|
let mode: string = (untitledEditorInput && untitledEditorInput.getMode) ? untitledEditorInput.getMode() : 'sql';
|
||||||
|
if (input && !denyQueryEditor && mode === 'sql') {
|
||||||
//QueryInput
|
//QueryInput
|
||||||
let uri: URI = getQueryEditorFileUri(input);
|
let uri: URI = getQueryEditorFileUri(input);
|
||||||
if (uri) {
|
if (uri) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import * as nls from 'vs/nls';
|
import * as nls from 'vs/nls';
|
||||||
import { Registry } from 'vs/platform/registry/common/platform';
|
import { Registry } from 'vs/platform/registry/common/platform';
|
||||||
import { ToggleAutoSaveAction, GlobalNewUntitledFileAction, ShowOpenedFileInNewWindow, FocusFilesExplorer, GlobalCompareResourcesAction, SaveAllAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler } from 'vs/workbench/contrib/files/browser/fileActions';
|
import { ToggleAutoSaveAction, GlobalNewUntitledFileAction, GlobalNewUntitledPlainFileAction, ShowOpenedFileInNewWindow, FocusFilesExplorer, GlobalCompareResourcesAction, SaveAllAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler } from 'vs/workbench/contrib/files/browser/fileActions';
|
||||||
import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/browser/saveErrorHandler';
|
import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/browser/saveErrorHandler';
|
||||||
import { SyncActionDescriptor, MenuId, MenuRegistry, ILocalizedString } from 'vs/platform/actions/common/actions';
|
import { SyncActionDescriptor, MenuId, MenuRegistry, ILocalizedString } from 'vs/platform/actions/common/actions';
|
||||||
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
|
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
|
||||||
@@ -37,6 +37,8 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ShowActiveFileInExplor
|
|||||||
registry.registerWorkbenchAction(new SyncActionDescriptor(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL), 'File: Collapse Folders in Explorer', category);
|
registry.registerWorkbenchAction(new SyncActionDescriptor(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL), 'File: Collapse Folders in Explorer', category);
|
||||||
registry.registerWorkbenchAction(new SyncActionDescriptor(RefreshExplorerView, RefreshExplorerView.ID, RefreshExplorerView.LABEL), 'File: Refresh Explorer', category);
|
registry.registerWorkbenchAction(new SyncActionDescriptor(RefreshExplorerView, RefreshExplorerView.ID, RefreshExplorerView.LABEL), 'File: Refresh Explorer', category);
|
||||||
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalNewUntitledFileAction, GlobalNewUntitledFileAction.ID, GlobalNewUntitledFileAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_N }), 'File: New Untitled File', category);
|
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalNewUntitledFileAction, GlobalNewUntitledFileAction.ID, GlobalNewUntitledFileAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_N }), 'File: New Untitled File', category);
|
||||||
|
// {{SQL CARBON EDIT}} -- Add 'New File' command for plain untitled files
|
||||||
|
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalNewUntitledPlainFileAction, GlobalNewUntitledPlainFileAction.ID, GlobalNewUntitledPlainFileAction.LABEL), 'File: New Plain Text File', category);
|
||||||
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowOpenedFileInNewWindow, ShowOpenedFileInNewWindow.ID, ShowOpenedFileInNewWindow.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_O) }), 'File: Open Active File in New Window', category);
|
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowOpenedFileInNewWindow, ShowOpenedFileInNewWindow.ID, ShowOpenedFileInNewWindow.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_O) }), 'File: Open Active File in New Window', category);
|
||||||
registry.registerWorkbenchAction(new SyncActionDescriptor(CompareWithClipboardAction, CompareWithClipboardAction.ID, CompareWithClipboardAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_C) }), 'File: Compare Active File with Clipboard', category);
|
registry.registerWorkbenchAction(new SyncActionDescriptor(CompareWithClipboardAction, CompareWithClipboardAction.ID, CompareWithClipboardAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_C) }), 'File: Compare Active File with Clipboard', category);
|
||||||
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleAutoSaveAction, ToggleAutoSaveAction.ID, ToggleAutoSaveAction.LABEL), 'File: Toggle Auto Save', category);
|
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleAutoSaveAction, ToggleAutoSaveAction.ID, ToggleAutoSaveAction.LABEL), 'File: Toggle Auto Save', category);
|
||||||
@@ -534,11 +536,12 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
|
|||||||
// Empty Editor Group Context Menu
|
// Empty Editor Group Context Menu
|
||||||
// {{SQL CARBON EDIT}} - Use "New Query" instead of "New File"
|
// {{SQL CARBON EDIT}} - Use "New Query" instead of "New File"
|
||||||
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: GlobalNewUntitledFileAction.ID, title: nls.localize('newFile', "New Query") }, group: '1_file', order: 10 });
|
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: GlobalNewUntitledFileAction.ID, title: nls.localize('newFile', "New Query") }, group: '1_file', order: 10 });
|
||||||
|
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: GlobalNewUntitledPlainFileAction.ID, title: nls.localize('newPlainFile', "New File") }, group: '1_file', order: 15 });
|
||||||
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: 'workbench.action.quickOpen', title: nls.localize('openFile', "Open File...") }, group: '1_file', order: 20 });
|
MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, { command: { id: 'workbench.action.quickOpen', title: nls.localize('openFile', "Open File...") }, group: '1_file', order: 20 });
|
||||||
|
|
||||||
// File menu
|
// File menu
|
||||||
|
|
||||||
// {{SQL CARBON EDIT}} - Use "New Query" instead of "New File"
|
// {{SQL CARBON EDIT}} - Use "New Query"
|
||||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||||
group: '1_new',
|
group: '1_new',
|
||||||
command: {
|
command: {
|
||||||
@@ -548,6 +551,16 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|||||||
order: 1
|
order: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// {{SQL CARBON EDIT}} - Use "New File"
|
||||||
|
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||||
|
group: '1_new',
|
||||||
|
command: {
|
||||||
|
id: GlobalNewUntitledPlainFileAction.ID,
|
||||||
|
title: nls.localize({ key: 'miNewPlainFile', comment: ['&& denotes a mnemonic'] }, "New &&File")
|
||||||
|
},
|
||||||
|
order: 1.1
|
||||||
|
});
|
||||||
|
|
||||||
// {{SQL CARBON EDIT}} - Add "New Notebook" item
|
// {{SQL CARBON EDIT}} - Add "New Notebook" item
|
||||||
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
||||||
group: '1_new',
|
group: '1_new',
|
||||||
@@ -555,7 +568,7 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|||||||
id: 'notebook.command.new',
|
id: 'notebook.command.new',
|
||||||
title: nls.localize({ key: 'miNewNotebook', comment: ['&& denotes a mnemonic'] }, "&&New Notebook")
|
title: nls.localize({ key: 'miNewNotebook', comment: ['&& denotes a mnemonic'] }, "&&New Notebook")
|
||||||
},
|
},
|
||||||
order: 1.1
|
order: 1.2
|
||||||
});
|
});
|
||||||
// {{SQL CARBON EDIT}} - End
|
// {{SQL CARBON EDIT}} - End
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,27 @@ export class NewFolderAction extends Action {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create new file from anywhere: Open untitled */
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
export class GlobalNewUntitledPlainFileAction extends Action {
|
||||||
|
// {{SQL CARBON EDIT}} - Use different command name to reserve original name for SQL files
|
||||||
|
public static readonly ID = 'workbench.action.files.newUntitledPlainFile';
|
||||||
|
public static readonly LABEL = nls.localize('newPlainTextFile', "New Plain Text File");
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
id: string,
|
||||||
|
label: string,
|
||||||
|
@IEditorService private readonly editorService: IEditorService
|
||||||
|
) {
|
||||||
|
super(id, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public run(): Promise<any> {
|
||||||
|
// {{SQL CARBON EDIT}} - set as plain text
|
||||||
|
return this.editorService.openEditor({ options: { pinned: true }, mode: 'txt' }); // untitled are always pinned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Create new file from anywhere: Open untitled */
|
/* Create new file from anywhere: Open untitled */
|
||||||
export class GlobalNewUntitledFileAction extends Action {
|
export class GlobalNewUntitledFileAction extends Action {
|
||||||
public static readonly ID = 'workbench.action.files.newUntitledFile';
|
public static readonly ID = 'workbench.action.files.newUntitledFile';
|
||||||
|
|||||||
Reference in New Issue
Block a user