提交 54bc4ffa 编写于 作者: M Matt Bierner

Strict null work in fileActions

上级 7bf13604
......@@ -33,7 +33,7 @@ export const VIEWLET_ID = 'workbench.view.explorer';
export const VIEW_CONTAINER: ViewContainer = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).registerViewContainer(VIEWLET_ID);
export interface IEditableData {
validationMessage: (value: string) => string;
validationMessage: (value: string) => string | null;
onFinish: (value: string, success: boolean) => void;
}
......@@ -47,7 +47,7 @@ export interface IExplorerService {
readonly onDidSelectItem: Event<{ item?: ExplorerItem, reveal?: boolean }>;
readonly onDidCopyItems: Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>;
setEditable(stat: ExplorerItem, data: IEditableData): void;
setEditable(stat: ExplorerItem, data: IEditableData | null): void;
getEditableData(stat: ExplorerItem): IEditableData | undefined;
isEditable(stat: ExplorerItem): boolean;
findClosest(resource: URI): ExplorerItem | null;
......
......@@ -17,7 +17,7 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { VIEWLET_ID, IExplorerService } from 'vs/workbench/contrib/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IFileService, AutoSaveConfiguration } from 'vs/platform/files/common/files';
import { toResource, IUntitledResourceInput } from 'vs/workbench/common/editor';
import { toResource, IUntitledResourceInput, ITextEditor } from 'vs/workbench/common/editor';
import { ExplorerViewlet } from 'vs/workbench/contrib/files/electron-browser/explorerViewlet';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
......@@ -40,7 +40,6 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Constants } from 'vs/editor/common/core/uint';
import { CLOSE_EDITORS_AND_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { coalesce } from 'vs/base/common/arrays';
import { AsyncDataTree } from 'vs/base/browser/ui/tree/asyncDataTree';
import { ExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
......@@ -117,7 +116,7 @@ export class NewFileAction extends BaseErrorReportingAction {
let folder: ExplorerItem;
const element = this.getElement();
if (element) {
folder = element.isDirectory ? element : element.parent;
folder = element.isDirectory ? element : element.parent!;
} else {
folder = this.explorerService.roots[0];
}
......@@ -173,7 +172,7 @@ export class NewFolderAction extends BaseErrorReportingAction {
let folder: ExplorerItem;
const element = this.getElement();
if (element) {
folder = element.isDirectory ? element : element.parent;
folder = element.isDirectory ? element : element.parent!;
} else {
folder = this.explorerService.roots[0];
}
......@@ -351,7 +350,7 @@ class BaseDeleteFileAction extends BaseErrorReportingAction {
.then(undefined, (error: any) => {
// Handle error to delete file(s) from a modal confirmation dialog
let errorMessage: string;
let detailMessage: string;
let detailMessage: string | undefined;
let primaryButton: string;
if (this.useTrash) {
errorMessage = isWindows ? nls.localize('binFailed', "Failed to delete using the Recycle Bin. Do you want to permanently delete instead?") : nls.localize('trashFailed', "Failed to delete using the Trash. Do you want to permanently delete instead?");
......@@ -469,16 +468,16 @@ class PasteFileAction extends BaseErrorReportingAction {
// Find target
let target: ExplorerItem;
if (this.element.resource.toString() === fileToPaste.toString()) {
target = this.element.parent;
target = this.element.parent!;
} else {
target = this.element.isDirectory ? this.element : this.element.parent;
target = this.element.isDirectory ? this.element : this.element.parent!;
}
const targetFile = findValidPasteFileTarget(target, { resource: fileToPaste, isDirectory: fileToPasteStat.isDirectory, allowOverwirte: pasteShouldMove });
// Copy File
const promise = pasteShouldMove ? this.fileService.moveFile(fileToPaste, targetFile) : this.fileService.copyFile(fileToPaste, targetFile);
return promise.then(stat => {
return promise.then<ITextEditor | undefined>(stat => {
if (pasteShouldMove) {
// Cut is done. Make sure to clear cut state.
this.explorerService.setToCopy([], false);
......@@ -504,7 +503,7 @@ export function findValidPasteFileTarget(targetFolder: ExplorerItem, fileToPaste
break;
}
name = incrementFileName(name, fileToPaste.isDirectory);
name = incrementFileName(name, !!fileToPaste.isDirectory);
candidate = resources.joinPath(targetFolder.resource, name);
}
......@@ -708,7 +707,7 @@ export abstract class BaseSaveAllAction extends BaseErrorReportingAction {
public run(context?: any): Promise<boolean> {
return this.doRun(context).then(() => true, error => {
this.onError(error);
return null;
return false;
});
}
......@@ -890,7 +889,7 @@ export class ShowOpenedFileInNewWindow extends Action {
}
}
export function validateFileName(item: ExplorerItem, name: string): string {
export function validateFileName(item: ExplorerItem, name: string): string | null {
// Produce a well formed file name
name = getWellFormedFileName(name);
......@@ -978,7 +977,7 @@ export class CompareWithClipboardAction extends Action {
}
public run(): Promise<any> {
const resource: URI = toResource(this.editorService.activeEditor, { supportSideBySide: true });
const resource = toResource(this.editorService.activeEditor, { supportSideBySide: true });
if (resource && (this.fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {
if (!this.registrationDisposal) {
const provider = this.instantiationService.createInstance(ClipboardContentProvider);
......@@ -1018,7 +1017,7 @@ class ClipboardContentProvider implements ITextModelContentProvider {
}
interface IExplorerContext {
stat: ExplorerItem;
stat?: ExplorerItem;
selection: ExplorerItem[];
}
......@@ -1030,7 +1029,7 @@ function getContext(listWidget: ListWidget): IExplorerContext {
const selection = tree.getSelection();
// Only respect the selection if user clicked inside it (focus belongs to it)
return { stat, selection: selection && selection.indexOf(stat) >= 0 ? selection : [] };
return { stat, selection: selection && typeof stat !== 'undefined' && selection.indexOf(stat) >= 0 ? selection : [] };
}
// TODO@isidor these commands are calling into actions due to the complex inheritance action structure.
......@@ -1040,7 +1039,7 @@ function openExplorerAndRunAction(accessor: ServicesAccessor, constructor: ICons
const listService = accessor.get(IListService);
const viewletService = accessor.get(IViewletService);
const activeViewlet = viewletService.getActiveViewlet();
let explorerPromise: Promise<IViewlet> = Promise.resolve(activeViewlet);
let explorerPromise = Promise.resolve(activeViewlet);
if (!activeViewlet || activeViewlet.getId() !== VIEWLET_ID) {
explorerPromise = viewletService.openViewlet(VIEWLET_ID, true);
}
......
......@@ -27,7 +27,7 @@ export const SIDE_GROUP = -2;
export type SIDE_GROUP_TYPE = typeof SIDE_GROUP;
export interface IOpenEditorOverrideHandler {
(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions, group: IEditorGroup): IOpenEditorOverride;
(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions, group: IEditorGroup): IOpenEditorOverride | undefined;
}
export interface IOpenEditorOverride {
......@@ -36,7 +36,7 @@ export interface IOpenEditorOverride {
* If defined, will prevent the opening of an editor and replace the resulting
* promise with the provided promise for the openEditor() call.
*/
override?: Promise<IEditor>;
override?: Promise<IEditor | undefined>;
}
export interface IActiveEditor extends IEditor {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册