提交 19bba67c 编写于 作者: B Benjamin Pasero

grid - add copy editor/group to addView() method

上级 bef10712
......@@ -420,6 +420,14 @@ export class ResourceMap<T> {
public keys(): URI[] {
return keys(this.map).map(URI.parse);
}
public clone(): ResourceMap<T> {
const resourceMap = new ResourceMap<T>();
resourceMap.map.forEach((value, key) => resourceMap.map.set(key, value));
return resourceMap;
}
}
// We should fold BoundedMap and LinkedMap. See https://github.com/Microsoft/vscode/issues/28496
......
......@@ -86,20 +86,20 @@
/** TODO@grid revisit the split editor action (vertical-layout/horizontal-layout does not exist anymore) */
.monaco-workbench > .part.editor > .content.vertical-layout .editor-group-container > .title .split-editor-action {
.monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-right-action {
background: url('split-editor-vertical.svg') center center no-repeat;
}
.vs-dark .monaco-workbench > .part.editor > .content.vertical-layout .editor-group-container > .title .split-editor-action,
.hc-black .monaco-workbench > .part.editor > .content.vertical-layout .editor-group-container > .title .split-editor-action {
.vs-dark .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-right-action,
.hc-black .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-right-action {
background: url('split-editor-vertical-inverse.svg') center center no-repeat;
}
.monaco-workbench > .part.editor > .content.horizontal-layout .editor-group-container > .title .split-editor-action {
.monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-down-action {
background: url('split-editor-horizontal.svg') center center no-repeat;
}
.vs-dark .monaco-workbench > .part.editor > .content.horizontal-layout .editor-group-container > .title .split-editor-action,
.hc-black .monaco-workbench > .part.editor > .content.horizontal-layout .editor-group-container > .title .split-editor-action {
.vs-dark .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-down-action,
.hc-black .monaco-workbench > .part.editor > .content .editor-group-container > .title .split-editor-down-action {
background: url('split-editor-horizontal-inverse.svg') center center no-repeat;
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
private group: EditorGroup;
private isActive: boolean;
private dimension: Dimension;
private _dimension: Dimension;
private scopedInstantiationService: IInstantiationService;
private titleContainer: HTMLElement;
......@@ -78,6 +78,7 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
private progressBar: ProgressBar;
constructor(
sourceView: NextEditorGroupView,
private groupsAccessor: IGroupsAccessor,
@IInstantiationService private instantiationService: IInstantiationService,
@IContextKeyService private contextKeyService: IContextKeyService,
......@@ -87,7 +88,11 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
) {
super(themeService);
this.group = this._register(instantiationService.createInstance(EditorGroup, ''));
if (sourceView) {
this.group = this._register(sourceView.group.clone());
} else {
this.group = this._register(instantiationService.createInstance(EditorGroup, ''));
}
this.group.label = `Group <${this.group.id}>`;
this.doCreate();
......@@ -147,6 +152,10 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
}
}
get dimension(): Dimension {
return this._dimension;
}
setActive(isActive: boolean): void {
this.isActive = isActive;
......@@ -168,6 +177,10 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
return this.group.count === 0;
}
isPinned(editor: EditorInput): boolean {
return this.group.isPinned(editor);
}
//#region INextEditorGroup
get id(): GroupIdentifier {
......@@ -477,7 +490,7 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
get onDidChange() { return Event.None; }
layout(width: number, height: number): void {
this.dimension = new Dimension(width, height);
this._dimension = new Dimension(width, height);
// Forward to controls
this.doLayoutTitleControl();
......@@ -486,13 +499,13 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
private doLayoutTitleControl(): void {
if (this.titleAreaControl) {
this.titleAreaControl.layout(new Dimension(this.dimension.width, NextEditorGroupView.EDITOR_TITLE_HEIGHT));
this.titleAreaControl.layout(new Dimension(this._dimension.width, NextEditorGroupView.EDITOR_TITLE_HEIGHT));
}
}
private doLayoutEditorControl(): void {
if (this.editorControl) {
this.editorControl.layout(new Dimension(this.dimension.width, this.dimension.height - NextEditorGroupView.EDITOR_TITLE_HEIGHT));
this.editorControl.layout(new Dimension(this._dimension.width, this._dimension.height - NextEditorGroupView.EDITOR_TITLE_HEIGHT));
}
}
......
......@@ -12,11 +12,11 @@ import { Part } from 'vs/workbench/browser/part';
import { Dimension, addClass, isAncestor } from 'vs/base/browser/dom';
import { Event, Emitter, once } from 'vs/base/common/event';
import { editorBackground, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { INextEditorGroupsService, Direction } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
import { INextEditorGroupsService, Direction, IAddGroupOptions } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { SplitGridView, Direction as GridViewDirection } from 'vs/base/browser/ui/grid/gridview';
import { NextEditorGroupView } from 'vs/workbench/browser/parts/editor2/nextEditorGroupView';
import { GroupIdentifier } from 'vs/workbench/common/editor';
import { GroupIdentifier, EditorOptions } from 'vs/workbench/common/editor';
import { values } from 'vs/base/common/map';
import { EDITOR_GROUP_BORDER } from 'vs/workbench/common/theme';
......@@ -79,16 +79,34 @@ export class NextEditorPart extends Part implements INextEditorGroupsService {
return groupView;
}
addGroup(fromGroup: NextEditorGroupView | GroupIdentifier, direction: Direction): NextEditorGroupView {
const groupView = this.doCreateGroupView();
addGroup(fromGroup: NextEditorGroupView | GroupIdentifier, direction: Direction, options: IAddGroupOptions = Object.create(null)): NextEditorGroupView {
const { copyGroup, copyEditor } = options;
const fromGroupView = this.asGroupView(fromGroup);
const newGroupView = this.doCreateGroupView(copyGroup ? fromGroupView : void 0);
// Add to grid widget
this.gridWidget.splitView(
this.asGroupView(fromGroup),
fromGroupView,
this.toGridViewDirection(direction),
groupView, direction === Direction.DOWN ? this.dimension.height / 2 : this.dimension.width / 2 /* TODO@grid what size? */
newGroupView,
direction === Direction.DOWN ? fromGroupView.dimension.height / 2 : fromGroupView.dimension.width / 2 /* TODO@grid what size? */
);
return groupView;
// Check for options
const activeEditor = fromGroupView.activeEditor;
if ((copyGroup || copyEditor) && activeEditor) {
let options: EditorOptions;
if (copyGroup) {
options = EditorOptions.create({ pinned: fromGroupView.isPinned(activeEditor) }); // copy group preserves all pinned state
} else {
options = EditorOptions.create({ pinned: true }); // copy of single editor is a sign of importance, so pin it
}
newGroupView.openEditor(activeEditor, options);
}
return newGroupView;
}
removeGroup(group: NextEditorGroupView | GroupIdentifier): void {
......@@ -171,8 +189,8 @@ export class NextEditorPart extends Part implements INextEditorGroupsService {
this._onDidActiveGroupChange.fire(group);
}
private doCreateGroupView(): NextEditorGroupView {
const groupView = this.instantiationService.createInstance(NextEditorGroupView, {
private doCreateGroupView(sourceView?: NextEditorGroupView): NextEditorGroupView {
const groupView = this.instantiationService.createInstance(NextEditorGroupView, sourceView, {
isOpenedInOtherGroup: editor => {
return this.groups.some(group => group !== groupView && group.contains(editor));
}
......
......@@ -37,7 +37,7 @@ import { isDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { Dimension } from 'vs/base/browser/dom';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { INextEditorGroupsService } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
import { INextEditorGroupsService, Direction } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
export interface IToolbarActions {
primary: IAction[];
......@@ -276,7 +276,20 @@ export abstract class NextTitleControl extends Themable implements INextTitleAre
if (isActive) {
primaryEditorActions = prepareActions(editorActions.primary);
if (editor instanceof EditorInput && editor.supportsSplitEditor()) {
primaryEditorActions.push(this.splitEditorAction);
// TODO@grid temporary actions to play with
// primaryEditorActions.push(this.splitEditorAction);
primaryEditorActions.push(new Action('split.right', 'Split Right', 'split-editor-right-action', true, () => {
this.nextEditorGroupsService.addGroup(this.nextEditorGroupsService.activeGroup, Direction.RIGHT, { copyEditor: true });
return TPromise.as(true);
}));
primaryEditorActions.push(new Action('split.down', 'Split Down', 'split-editor-down-action', true, () => {
this.nextEditorGroupsService.addGroup(this.nextEditorGroupsService.activeGroup, Direction.DOWN, { copyEditor: true });
return TPromise.as(true);
}));
}
}
......
......@@ -685,6 +685,18 @@ export class EditorGroup extends Disposable implements IEditorGroup {
this.active = this.mru[0];
this.preview = this.editors[data.preview];
}
public clone(): EditorGroup {
const group = this.instantiationService.createInstance(EditorGroup, '');
group.editors = this.editors.slice(0);
group.mru = this.mru.slice(0);
group.mapResourceToEditorCount = this.mapResourceToEditorCount.clone();
group.preview = this.preview;
group.active = this.active;
group.editorOpenPositioning = this.editorOpenPositioning;
return group;
}
}
interface ISerializedEditorStacksModel {
......
......@@ -57,6 +57,11 @@ export interface INextEditorGroup {
pinEditor(editor?: IEditorInput): void;
}
export interface IAddGroupOptions {
copyGroup?: boolean;
copyEditor?: boolean;
}
export interface INextEditorGroupsService {
_serviceBrand: ServiceIdentifier<any>;
......@@ -71,6 +76,6 @@ export interface INextEditorGroupsService {
setGroupActive(group: INextEditorGroup | GroupIdentifier): INextEditorGroup;
isGroupActive(group: INextEditorGroup | GroupIdentifier): boolean;
addGroup(fromGroup: INextEditorGroup | GroupIdentifier, direction: Direction): INextEditorGroup;
addGroup(fromGroup: INextEditorGroup | GroupIdentifier, direction: Direction, options?: IAddGroupOptions): INextEditorGroup;
removeGroup(group: INextEditorGroup | GroupIdentifier): void;
}
\ No newline at end of file
......@@ -1995,4 +1995,25 @@ suite('Editor Stacks Model', () => {
assert.equal(notfound2, null);
assert.equal(notfound3, null);
});
test('Stack - Clone Group', function () {
const model = create();
const group = model.openGroup('group');
const input1 = input();
const input2 = input();
const input3 = input();
// Pinned and Active
group.openEditor(input1, { pinned: true, active: true });
group.openEditor(input2, { pinned: true, active: true });
group.openEditor(input3, { pinned: false, active: true });
const clone = group.clone();
assert.equal(clone.count, 3);
assert.equal(clone.isPinned(input1), true);
assert.equal(clone.isPinned(input2), true);
assert.equal(clone.isPinned(input3), false);
assert.equal(clone.isActive(input3), true);
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册