本文整理匯總了TypeScript中vs/workbench/services/untitled/common/untitledEditorService.IUntitledEditorService.getEncoding方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript IUntitledEditorService.getEncoding方法的具體用法?TypeScript IUntitledEditorService.getEncoding怎麽用?TypeScript IUntitledEditorService.getEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vs/workbench/services/untitled/common/untitledEditorService.IUntitledEditorService
的用法示例。
在下文中一共展示了IUntitledEditorService.getEncoding方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: toResource
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 };
});
示例2:
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)
}
});
}
});
示例3: save
function save(resource: URI, isSaveAs: boolean, editorService: IWorkbenchEditorService, fileService: IFileService, untitledEditorService: IUntitledEditorService,
textFileService: ITextFileService, editorGroupService: IEditorGroupService): TPromise<any> {
if (resource && (fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {
// Save As (or Save untitled with associated path)
if (isSaveAs || resource.scheme === Schemas.untitled) {
let encodingOfSource: string;
if (resource.scheme === Schemas.untitled) {
encodingOfSource = untitledEditorService.getEncoding(resource);
} else if (fileService.canHandleResource(resource)) {
const textModel = textFileService.models.get(resource);
encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file!
}
let viewStateOfSource: IEditorViewState;
const activeEditor = editorService.getActiveEditor();
const editor = getCodeEditor(activeEditor);
if (editor) {
const activeResource = toResource(activeEditor.input, { supportSideBySide: true });
if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) {
viewStateOfSource = editor.saveViewState();
}
}
// Special case: an untitled file with associated path gets saved directly unless "saveAs" is true
let savePromise: TPromise<URI>;
if (!isSaveAs && resource.scheme === Schemas.untitled && untitledEditorService.hasAssociatedFilePath(resource)) {
savePromise = textFileService.save(resource).then((result) => {
if (result) {
return URI.file(resource.fsPath);
}
return null;
});
}
// Otherwise, really "Save As..."
else {
savePromise = textFileService.saveAs(resource);
}
return savePromise.then((target) => {
if (!target || target.toString() === resource.toString()) {
return void 0; // save canceled or same resource used
}
const replaceWith: IResourceInput = {
resource: target,
encoding: encodingOfSource,
options: {
pinned: true,
viewState: viewStateOfSource
}
};
return editorService.replaceEditors([{
toReplace: { resource: resource },
replaceWith
}]).then(() => true);
});
}
// Pin the active editor if we are saving it
const editor = editorService.getActiveEditor();
const activeEditorResource = editor && editor.input && editor.input.getResource();
if (activeEditorResource && activeEditorResource.toString() === resource.toString()) {
editorGroupService.pinEditor(editor.position, editor.input);
}
// Just save
return textFileService.save(resource, { force: true /* force a change to the file to trigger external watchers if any */ });
}
return TPromise.as(false);
}
示例4: save
function save(
resource: URI | null,
isSaveAs: boolean,
options: ISaveOptions | undefined,
editorService: IEditorService,
fileService: IFileService,
untitledEditorService: IUntitledEditorService,
textFileService: ITextFileService,
editorGroupService: IEditorGroupsService
): Promise<any> {
function ensureForcedSave(options?: ISaveOptions): ISaveOptions {
if (!options) {
options = { force: true };
} else {
options.force = true;
}
return options;
}
if (resource && (fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {
// Save As (or Save untitled with associated path)
if (isSaveAs || resource.scheme === Schemas.untitled) {
let encodingOfSource: string | undefined;
if (resource.scheme === Schemas.untitled) {
encodingOfSource = untitledEditorService.getEncoding(resource);
} else if (fileService.canHandleResource(resource)) {
const textModel = textFileService.models.get(resource);
encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file!
}
let viewStateOfSource: IEditorViewState | null;
const activeTextEditorWidget = getCodeEditor(editorService.activeTextEditorWidget);
if (activeTextEditorWidget) {
const activeResource = toResource(editorService.activeEditor, { supportSideBySide: true });
if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) {
viewStateOfSource = activeTextEditorWidget.saveViewState();
}
}
// Special case: an untitled file with associated path gets saved directly unless "saveAs" is true
let savePromise: Promise<URI | undefined>;
if (!isSaveAs && resource.scheme === Schemas.untitled && untitledEditorService.hasAssociatedFilePath(resource)) {
savePromise = textFileService.save(resource, options).then((result) => {
if (result) {
return resource.with({ scheme: Schemas.file });
}
return undefined;
});
}
// Otherwise, really "Save As..."
else {
// Force a change to the file to trigger external watchers if any
// fixes https://github.com/Microsoft/vscode/issues/59655
options = ensureForcedSave(options);
savePromise = textFileService.saveAs(resource, undefined, options);
}
return savePromise.then((target) => {
if (!target || target.toString() === resource.toString()) {
return false; // save canceled or same resource used
}
const replacement: IResourceInput = {
resource: target,
encoding: encodingOfSource,
options: {
pinned: true,
viewState: viewStateOfSource || undefined
}
};
return Promise.all(editorGroupService.groups.map(g =>
editorService.replaceEditors([{
editor: { resource },
replacement
}], g))).then(() => true);
});
}
// Pin the active editor if we are saving it
const activeControl = editorService.activeControl;
const activeEditorResource = activeControl && activeControl.input && activeControl.input.getResource();
if (activeControl && activeEditorResource && activeEditorResource.toString() === resource.toString()) {
activeControl.group.pinEditor(activeControl.input);
}
// Just save (force a change to the file to trigger external watchers if any)
options = ensureForcedSave(options);
return textFileService.save(resource, options);
}
return Promise.resolve(false);
//.........這裏部分代碼省略.........