當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ITextFileService.saveAll方法代碼示例

本文整理匯總了TypeScript中vs/workbench/services/textfile/common/textfiles.ITextFileService.saveAll方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ITextFileService.saveAll方法的具體用法?TypeScript ITextFileService.saveAll怎麽用?TypeScript ITextFileService.saveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vs/workbench/services/textfile/common/textfiles.ITextFileService的用法示例。


在下文中一共展示了ITextFileService.saveAll方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: saveAll

function saveAll(saveAllArguments: any, editorService: IEditorService, untitledEditorService: IUntitledEditorService,
	textFileService: ITextFileService, editorGroupService: IEditorGroupsService): Promise<any> {

	// Store some properties per untitled file to restore later after save is completed
	const groupIdToUntitledResourceInput = new Map<number, IResourceInput[]>();

	editorGroupService.groups.forEach(g => {
		const activeEditorResource = g.activeEditor && g.activeEditor.getResource();
		g.editors.forEach(e => {
			const resource = e.getResource();
			if (resource && untitledEditorService.isDirty(resource)) {
				if (!groupIdToUntitledResourceInput.has(g.id)) {
					groupIdToUntitledResourceInput.set(g.id, []);
				}

				groupIdToUntitledResourceInput.get(g.id)!.push({
					encoding: untitledEditorService.getEncoding(resource),
					resource,
					options: {
						inactive: activeEditorResource ? activeEditorResource.toString() !== resource.toString() : true,
						pinned: true,
						preserveFocus: true,
						index: g.getIndexOfEditor(e)
					}
				});
			}
		});
	});

	// Save all
	return textFileService.saveAll(saveAllArguments).then((result) => {
		groupIdToUntitledResourceInput.forEach((inputs, groupId) => {
			// Update untitled resources to the saved ones, so we open the proper files
			inputs.forEach(i => {
				const targetResult = result.results.filter(r => r.success && r.source.toString() === i.resource.toString()).pop();
				if (targetResult && targetResult.target) {
					i.resource = targetResult.target;
				}
			});
			editorService.openEditors(inputs, groupId);
		});
	});
}
開發者ID:joelday,項目名稱:vscode,代碼行數:43,代碼來源:fileCommands.ts

示例2: saveAll

function saveAll(saveAllArguments: any, editorService: IWorkbenchEditorService, untitledEditorService: IUntitledEditorService,
	textFileService: ITextFileService, editorGroupService: IEditorGroupService): TPromise<any> {

	const stacks = editorGroupService.getStacksModel();

	// Store some properties per untitled file to restore later after save is completed
	const mapUntitledToProperties: { [resource: string]: { encoding: string; indexInGroups: number[]; activeInGroups: boolean[] } } = Object.create(null);
	untitledEditorService.getDirty().forEach(resource => {
		const activeInGroups: boolean[] = [];
		const indexInGroups: number[] = [];
		const encoding = untitledEditorService.getEncoding(resource);

		// For each group
		stacks.groups.forEach((group, groupIndex) => {

			// Find out if editor is active in group
			const activeEditor = group.activeEditor;
			const activeResource = toResource(activeEditor, { supportSideBySide: true });
			activeInGroups[groupIndex] = (activeResource && activeResource.toString() === resource.toString());

			// Find index of editor in group
			indexInGroups[groupIndex] = -1;
			group.getEditors().forEach((editor, editorIndex) => {
				const editorResource = toResource(editor, { supportSideBySide: true });
				if (editorResource && editorResource.toString() === resource.toString()) {
					indexInGroups[groupIndex] = editorIndex;
					return;
				}
			});
		});

		mapUntitledToProperties[resource.toString()] = { encoding, indexInGroups, activeInGroups };
	});

	// Save all
	return textFileService.saveAll(saveAllArguments).then(results => {

		// Reopen saved untitled editors
		const untitledToReopen: { input: IResourceInput, position: Position }[] = [];

		results.results.forEach(result => {
			if (!result.success || result.source.scheme !== Schemas.untitled) {
				return;
			}

			const untitledProps = mapUntitledToProperties[result.source.toString()];
			if (!untitledProps) {
				return;
			}

			// For each position where the untitled file was opened
			untitledProps.indexInGroups.forEach((indexInGroup, index) => {
				if (indexInGroup >= 0) {
					untitledToReopen.push({
						input: {
							resource: result.target,
							encoding: untitledProps.encoding,
							options: {
								pinned: true,
								index: indexInGroup,
								preserveFocus: true,
								inactive: !untitledProps.activeInGroups[index]
							}
						},
						position: index
					});
				}
			});
		});

		if (untitledToReopen.length) {
			return editorService.openEditors(untitledToReopen).then(() => true);
		}

		return void 0;
	});
}
開發者ID:jinlongchen2018,項目名稱:vscode,代碼行數:77,代碼來源:fileCommands.ts


注:本文中的vs/workbench/services/textfile/common/textfiles.ITextFileService.saveAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。