提交 ba8a1991 编写于 作者: B Benjamin Pasero

grid - better event handling for group

上级 2c0cac94
......@@ -10,7 +10,7 @@ import { localize } from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { GridOpenEditorsAction, GridCloseActiveEditorAction, GridRemoveActiveGroupAction, NextEditorContribution } from 'vs/workbench/browser/parts/editor2/nextEditorActions';
import { GridOpenEditorsAction, GridCloseActiveEditorAction, GridRemoveActiveGroupAction, NextEditorContribution, GridOpenOneEditorAction } from 'vs/workbench/browser/parts/editor2/nextEditorActions';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
......@@ -20,6 +20,7 @@ const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.Workbenc
registry.registerWorkbenchAction(new SyncActionDescriptor(GridOpenEditorsAction, GridOpenEditorsAction.ID, GridOpenEditorsAction.LABEL), 'Grid: Open Some Editors', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(GridCloseActiveEditorAction, GridCloseActiveEditorAction.ID, GridCloseActiveEditorAction.LABEL), 'Grid: Close Active Editor', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(GridRemoveActiveGroupAction, GridRemoveActiveGroupAction.ID, GridRemoveActiveGroupAction.LABEL), 'Grid: Remove Active Group', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(GridOpenOneEditorAction, GridOpenOneEditorAction.ID, GridOpenOneEditorAction.LABEL), 'Grid: Open One Editor', category);
// Register Workbench Contribution
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(NextEditorContribution, LifecyclePhase.Running);
\ No newline at end of file
......@@ -73,6 +73,28 @@ export class GridOpenEditorsAction extends Action {
}
}
export class GridOpenOneEditorAction extends Action {
static readonly ID = 'workbench.action.gridOpenOneEditor';
static readonly LABEL = localize('gridOpenOneEditor', "Grid: Open One Editor");
constructor(
id: string,
label: string,
@IWorkbenchEditorService private legacyEditorService: IWorkbenchEditorService,
@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
) {
super(id, label);
}
run(): TPromise<any> {
const path = join(process.cwd(), 'src/vs/workbench/browser/parts/editor2/editor2.contribution.ts');
this.nextEditorGroupsService.activeGroup.openEditor(this.legacyEditorService.createInput({ resource: URI.file(path) }) as EditorInput);
return TPromise.as(void 0);
}
}
export class GridCloseActiveEditorAction extends Action {
static readonly ID = 'workbench.action.gridCloseActiveEditor';
......
......@@ -131,17 +131,17 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
private registerListeners(): void {
// Model Events
this._register(this.group.onDidEditorsStructureChange(() => this.updateContainer()));
this._register(this.group.onDidEditorBecomeDirty(editor => this.pinEditor(editor)));
this._register(this.group.onDidEditorOpen(editor => this.onEditorOpened(editor)));
this._register(this.group.onDidEditorClose(editor => this.onEditorClosed(editor)));
this._register(this.group.onDidEditorDispose(editor => this.onEditorDisposed(editor)));
this._register(this.group.onDidEditorOpen(editor => this.onDidEditorOpen(editor)));
this._register(this.group.onDidEditorClose(editor => this.onDidEditorClose(editor)));
this._register(this.group.onDidEditorDispose(editor => this.onDidEditorDispose(editor)));
this._register(this.group.onDidEditorBecomeDirty(editor => this.onDidEditorBecomeDirty(editor)));
this._register(this.group.onDidEditorLabelChange(editor => this.onDidEditorLabelChange(editor)));
// Configuration Changes
this._register(this.configurationService.onDidChangeConfiguration(e => this.onDidChangeConfiguration(e)));
}
private onEditorOpened(editor: EditorInput): void {
private onDidEditorOpen(editor: EditorInput): void {
/* __GDPR__
"editorOpened" : {
"${include}": [
......@@ -150,9 +150,12 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
}
*/
this.telemetryService.publicLog('editorOpened', editor.getTelemetryDescriptor());
// Update container
this.updateContainer();
}
private onEditorClosed(event: EditorCloseEvent): void {
private onDidEditorClose(event: EditorCloseEvent): void {
// Before close
this._onWillCloseEditor.fire(event.editor);
......@@ -171,6 +174,9 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
}
*/
this.telemetryService.publicLog('editorClosed', event.editor.getTelemetryDescriptor());
// Update container
this.updateContainer();
}
private handleEditorClosed(editor: EditorInput): void {
......@@ -190,7 +196,7 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
});
}
private onEditorDisposed(editor: EditorInput): void {
private onDidEditorDispose(editor: EditorInput): void {
// To prevent race conditions, we handle disposed editors in our worker with a timeout
// because it can happen that an input is being disposed with the intent to replace
......@@ -232,6 +238,25 @@ export class NextEditorGroupView extends Themable implements IView, INextEditorG
// TODO@grid handle title area related settings (tabs, etc, see EditorGroupsControl#updateTabOptions())
}
private onDidEditorBecomeDirty(editor: EditorInput): void {
// Always show dirty editors pinned
this.pinEditor(editor);
// Forward to title control
if (this.titleAreaControl) {
this.titleAreaControl.updateEditorLabel(editor);
}
}
private onDidEditorLabelChange(editor: EditorInput): void {
// Forward to title control
if (this.titleAreaControl) {
this.titleAreaControl.updateEditorLabel(editor);
}
}
private doCreate(): void {
// Container
......
......@@ -50,6 +50,7 @@ export interface INextTitleAreaControl extends IDisposable {
moveEditor(editor: EditorInput, targetIndex: number): void;
setActive(isActive: boolean): void;
pinEditor(editor: EditorInput): void;
updateEditorLabel(editor: EditorInput): void;
layout(dimension: Dimension): void;
}
......@@ -401,6 +402,10 @@ export abstract class NextTitleControl extends Themable implements INextTitleAre
this.doScheduleUpdate(true); // TODO@grid optimize if possible
}
updateEditorLabel(editor: EditorInput): void {
this.doScheduleUpdate(); // TODO@grid optimize if possible
}
layout(dimension: Dimension): void {
// Optionally implemented in subclasses
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册