mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
explorer: add download command
This commit is contained in:
parent
8cb79b297f
commit
f50edc3f32
|
@ -5,7 +5,7 @@
|
|||
|
||||
import * as nls from 'vs/nls';
|
||||
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, 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, DOWNLOAD_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileActions';
|
||||
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 { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
|
||||
|
@ -195,6 +195,8 @@ function appendToCommandPalette(id: string, title: ILocalizedString, category: I
|
|||
when
|
||||
});
|
||||
}
|
||||
|
||||
const downloadLabel = nls.localize('download', "Download");
|
||||
appendToCommandPalette(COPY_PATH_COMMAND_ID, { value: nls.localize('copyPathOfActive', "Copy Path of Active File"), original: 'Copy Path of Active File' }, category);
|
||||
appendToCommandPalette(COPY_RELATIVE_PATH_COMMAND_ID, { value: nls.localize('copyRelativePathOfActive', "Copy Relative Path of Active File"), original: 'Copy Relative Path of Active File' }, category);
|
||||
appendToCommandPalette(SAVE_FILE_COMMAND_ID, { value: SAVE_FILE_LABEL, original: 'Save' }, category);
|
||||
|
@ -208,6 +210,7 @@ appendToCommandPalette(SAVE_FILE_AS_COMMAND_ID, { value: SAVE_FILE_AS_LABEL, ori
|
|||
appendToCommandPalette(CLOSE_EDITOR_COMMAND_ID, { value: nls.localize('closeEditor', "Close Editor"), original: 'Close Editor' }, { value: nls.localize('view', "View"), original: 'View' });
|
||||
appendToCommandPalette(NEW_FILE_COMMAND_ID, { value: NEW_FILE_LABEL, original: 'New File' }, category);
|
||||
appendToCommandPalette(NEW_FOLDER_COMMAND_ID, { value: NEW_FOLDER_LABEL, original: 'New Folder' }, category);
|
||||
appendToCommandPalette(DOWNLOAD_COMMAND_ID, { value: downloadLabel, original: 'Download' }, category, ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeRemote));
|
||||
|
||||
// Menu registration - open editors
|
||||
|
||||
|
@ -459,6 +462,16 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
|
|||
when: ExplorerFolderContext
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
|
||||
group: '5_cutcopypaste',
|
||||
order: 30,
|
||||
command: {
|
||||
id: DOWNLOAD_COMMAND_ID,
|
||||
title: downloadLabel,
|
||||
},
|
||||
when: ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeRemote)
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
|
||||
group: '6_copypath',
|
||||
order: 30,
|
||||
|
|
|
@ -36,7 +36,7 @@ import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/c
|
|||
import { IListService, ListWidget } from 'vs/platform/list/browser/listService';
|
||||
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IDialogService, IConfirmationResult, getConfirmMessage } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { IDialogService, IConfirmationResult, getConfirmMessage, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { Constants } from 'vs/editor/common/core/uint';
|
||||
|
@ -45,6 +45,8 @@ import { coalesce } from 'vs/base/common/arrays';
|
|||
import { AsyncDataTree } from 'vs/base/browser/ui/tree/asyncDataTree';
|
||||
import { ExplorerItem, NewExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { join, basename } from 'vs/base/common/path';
|
||||
|
||||
export const NEW_FILE_COMMAND_ID = 'explorer.newFile';
|
||||
export const NEW_FILE_LABEL = nls.localize('newFile', "New File");
|
||||
|
@ -974,6 +976,34 @@ export const cutFileHandler = (accessor: ServicesAccessor) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const DOWNLOAD_COMMAND_ID = 'explorer.download';
|
||||
const downloadFileHandler = (accessor: ServicesAccessor) => {
|
||||
const listService = accessor.get(IListService);
|
||||
if (!listService.lastFocusedList) {
|
||||
return;
|
||||
}
|
||||
const explorerContext = getContext(listService.lastFocusedList);
|
||||
const textFileService = accessor.get(ITextFileService);
|
||||
const fileDialogService = accessor.get(IFileDialogService);
|
||||
const environmentService = accessor.get(IEnvironmentService);
|
||||
|
||||
if (explorerContext.stat) {
|
||||
const stats = explorerContext.selection.length > 1 ? explorerContext.selection : [explorerContext.stat];
|
||||
stats.forEach(async s => {
|
||||
const resource = await fileDialogService.showSaveDialog({
|
||||
defaultUri: URI.file(join(environmentService.userHome, basename(s.resource.path)))
|
||||
});
|
||||
if (resource) {
|
||||
await textFileService.saveAs(s.resource, resource);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
CommandsRegistry.registerCommand({
|
||||
id: DOWNLOAD_COMMAND_ID,
|
||||
handler: downloadFileHandler
|
||||
});
|
||||
|
||||
export const pasteFileHandler = (accessor: ServicesAccessor) => {
|
||||
const listService = accessor.get(IListService);
|
||||
const clipboardService = accessor.get(IClipboardService);
|
||||
|
|
Loading…
Reference in a new issue