提交 9b7255b1 编写于 作者: B Benjamin Pasero

grid - update todo

上级 5b4225ca
......@@ -53,69 +53,6 @@ import { dispose } from 'vs/base/common/lifecycle';
*/
export class EditorPart extends Part implements IEditorPart, IEditorGroupService {
//#region TODO@grid replaceEditors()
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: EditorOptions }[], position?: Position): TPromise<IEditor[]> {
const activeReplacements: IEditorReplacement[] = [];
const hiddenReplacements: IEditorReplacement[] = [];
// Find editors across groups to close
editors.forEach(editor => {
if (editor.toReplace.isDirty()) {
return; // we do not handle dirty in this method, so ignore all dirty
}
// For each group
this.stacks.groups.forEach(group => {
if (position === void 0 || this.stacks.positionOfGroup(group) === position) {
const index = group.indexOf(editor.toReplace);
if (index >= 0) {
if (editor.options) {
editor.options.index = index; // make sure we respect the index of the editor to replace!
} else {
editor.options = EditorOptions.create({ index });
}
const replacement = { group, editor: editor.toReplace, replaceWith: editor.replaceWith, options: editor.options };
if (group.activeEditor.matches(editor.toReplace)) {
activeReplacements.push(replacement);
} else {
hiddenReplacements.push(replacement);
}
}
}
});
});
// Deal with hidden replacements first
hiddenReplacements.forEach(replacement => {
const group = replacement.group;
group.openEditor(replacement.replaceWith, { active: false, pinned: true, index: replacement.options.index });
group.closeEditor(replacement.editor);
});
// Now deal with active editors to be opened
const res = this.openEditors(activeReplacements.map(replacement => {
const group = replacement.group;
return {
input: replacement.replaceWith,
position: this.stacks.positionOfGroup(group),
options: replacement.options
};
}));
// Close active editors to be replaced now (they are no longer active)
activeReplacements.forEach(replacement => {
this.doCloseEditor(replacement.group, replacement.editor, false);
});
return res;
}
//#endregion
//#region Handled or Adopted or Obsolete
public _serviceBrand: any;
......@@ -231,6 +168,65 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this.registerListeners();
}
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: EditorOptions }[], position?: Position): TPromise<IEditor[]> {
const activeReplacements: IEditorReplacement[] = [];
const hiddenReplacements: IEditorReplacement[] = [];
// Find editors across groups to close
editors.forEach(editor => {
if (editor.toReplace.isDirty()) {
return; // we do not handle dirty in this method, so ignore all dirty
}
// For each group
this.stacks.groups.forEach(group => {
if (position === void 0 || this.stacks.positionOfGroup(group) === position) {
const index = group.indexOf(editor.toReplace);
if (index >= 0) {
if (editor.options) {
editor.options.index = index; // make sure we respect the index of the editor to replace!
} else {
editor.options = EditorOptions.create({ index });
}
const replacement = { group, editor: editor.toReplace, replaceWith: editor.replaceWith, options: editor.options };
if (group.activeEditor.matches(editor.toReplace)) {
activeReplacements.push(replacement);
} else {
hiddenReplacements.push(replacement);
}
}
}
});
});
// Deal with hidden replacements first
hiddenReplacements.forEach(replacement => {
const group = replacement.group;
group.openEditor(replacement.replaceWith, { active: false, pinned: true, index: replacement.options.index });
group.closeEditor(replacement.editor);
});
// Now deal with active editors to be opened
const res = this.openEditors(activeReplacements.map(replacement => {
const group = replacement.group;
return {
input: replacement.replaceWith,
position: this.stacks.positionOfGroup(group),
options: replacement.options
};
}));
// Close active editors to be replaced now (they are no longer active)
activeReplacements.forEach(replacement => {
this.doCloseEditor(replacement.group, replacement.editor, false);
});
return res;
}
public closeEditors(positions?: Position[]): TPromise<void>;
public closeEditors(position: Position, filter?: ICloseEditorsFilter): TPromise<void>;
public closeEditors(position: Position, editors: EditorInput[]): TPromise<void>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册