提交 15177f20 编写于 作者: C Christof Marti

Use file system service (#31450)

上级 6b524707
......@@ -125,6 +125,12 @@ export interface IFileService {
*/
createFile(resource: URI, content?: string, options?: ICreateFileOptions): TPromise<IFileStat>;
/**
* Reads a folder's content with the given path. The returned promise
* will have the list of children as a result.
*/
readFolder(resource: URI): TPromise<string[]>;
/**
* Creates a new folder with the given path. The returned promise
* will have the stat model object as a result.
......
......@@ -5,8 +5,8 @@
import 'vs/css!./welcomePage';
import { URI } from 'vs/base/common/uri';
import * as strings from 'vs/base/common/strings';
import * as path from 'path';
import { readdir } from 'vs/base/node/extfs';
import { ICommandService } from 'vs/platform/commands/common/commands';
import * as arrays from 'vs/base/common/arrays';
import { WalkThroughInput } from 'vs/workbench/parts/welcome/walkThrough/node/walkThroughInput';
......@@ -27,7 +27,7 @@ import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { getInstalledExtensions, IExtensionStatus, onExtensionChanged, isKeymapExtension } from 'vs/workbench/parts/extensions/electron-browser/extensionsUtils';
import { IExtensionEnablementService, IExtensionManagementService, IExtensionGalleryService, IExtensionTipsService, EnablementState, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
import { used } from 'vs/workbench/parts/welcome/page/electron-browser/vs_code_welcome_page';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { ILifecycleService, StartupKind } from 'vs/platform/lifecycle/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { tildify, getBaseLabel } from 'vs/base/common/labels';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
......@@ -41,6 +41,7 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
import { TimeoutTimer } from 'vs/base/common/async';
import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { ILabelService } from 'vs/platform/label/common/label';
import { IFileService } from 'vs/platform/files/common/files';
used();
......@@ -55,44 +56,46 @@ export class WelcomePageContribution implements IWorkbenchContribution {
@IConfigurationService configurationService: IConfigurationService,
@IEditorService editorService: IEditorService,
@IBackupFileService backupFileService: IBackupFileService,
@IFileService fileService: IFileService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@ILifecycleService lifecycleService: ILifecycleService,
@ICommandService private commandService: ICommandService,
) {
const enabled = isWelcomePageEnabled(configurationService, contextService);
if (enabled /* && lifecycleService.startupKind !== StartupKind.ReloadedWindow */) {
if (enabled && lifecycleService.startupKind !== StartupKind.ReloadedWindow) {
backupFileService.hasBackups().then(hasBackups => {
const activeEditor = editorService.activeEditor;
if (!activeEditor && !hasBackups) {
const openWithReadme = configurationService.getValue(configurationKey) === 'readme';
if (openWithReadme) {
let foldersChecked = 0;
let readmeOpened = false;
const workSpaceFolders = contextService.getWorkspace().folders.map(el => el.uri);
for (const workSpaceFolder of workSpaceFolders) {
readdir(workSpaceFolder.path, (err, files) => {
foldersChecked++;
if (err) {
onUnexpectedError(err);
} else if (!readmeOpened) {
for (const content of files) {
if (content.toLowerCase().lastIndexOf('readme', 0) === 0) {
readmeOpened = true;
const readmeLocation = path.join(workSpaceFolder.path, content);
if (readmeLocation.toLowerCase().slice(readmeLocation.length - 3) === '.md') {
this.commandService.executeCommand('markdown.showPreview', URI.file(readmeLocation));
} else {
editorService.openEditor({ resource: URI.file(readmeLocation) });
}
}
return Promise.all(contextService.getWorkspace().folders.map(folder => {
const folderUri = folder.uri;
return fileService.readFolder(folderUri)
.then(files => {
const file = arrays.find(files.sort(), file => strings.startsWith(file.toLowerCase(), 'readme'));
if (file) {
return folderUri.with({
path: path.posix.join(folderUri.path, file)
});
}
return undefined;
}, onUnexpectedError);
})).then(results => results.filter(result => !!result))
.then<any>(readmes => {
if (!editorService.activeEditor) {
if (readmes.length) {
const isMarkDown = (readme: URI) => strings.endsWith(readme.path.toLowerCase(), '.md');
return Promise.all([
this.commandService.executeCommand('markdown.showPreview', null, readmes.filter(isMarkDown), { locked: true }),
editorService.openEditors(readmes.filter(readme => !isMarkDown(readme))
.map(readme => ({ resource: readme }))),
]);
} else {
return instantiationService.createInstance(WelcomePage).openEditor();
}
}
if (!readmeOpened && foldersChecked === workSpaceFolders.length) {
return instantiationService.createInstance(WelcomePage).openEditor();
}
return undefined;
});
}
} else {
return instantiationService.createInstance(WelcomePage).openEditor();
}
......
......@@ -751,6 +751,11 @@ export class FileService extends Disposable implements IFileService {
});
}
readFolder(resource: uri): TPromise<string[]> {
const absolutePath = this.toAbsolutePath(resource);
return pfs.readdir(absolutePath);
}
createFolder(resource: uri): TPromise<IFileStat> {
// 1.) Create folder
......
......@@ -520,6 +520,16 @@ export class RemoteFileService extends FileService {
}
}
readFolder(resource: URI): TPromise<string[]> {
if (resource.scheme === Schemas.file) {
return super.readFolder(resource);
} else {
return this._withProvider(resource).then(provider => {
return provider.readdir(resource);
}).then(list => list.map(l => l[0]));
}
}
createFolder(resource: URI): TPromise<IFileStat> {
if (resource.scheme === Schemas.file) {
return super.createFolder(resource);
......
......@@ -874,6 +874,10 @@ export class TestFileService implements IFileService {
return TPromise.as(null);
}
readFolder(_resource: URI) {
return TPromise.as([]);
}
createFolder(_resource: URI): TPromise<IFileStat> {
return TPromise.as(null);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册