本文整理汇总了TypeScript中vs/workbench/services/group/common/groupService.IEditorGroupService.pinEditor方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IEditorGroupService.pinEditor方法的具体用法?TypeScript IEditorGroupService.pinEditor怎么用?TypeScript IEditorGroupService.pinEditor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/workbench/services/group/common/groupService.IEditorGroupService
的用法示例。
在下文中一共展示了IEditorGroupService.pinEditor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
}