提交 4e50ae60 编写于 作者: P Pine Wu

Prev/Next Panel item

上级 36a2a4b9
......@@ -72,6 +72,10 @@ export class CompositeBar extends Widget implements ICompositeBar {
return this.model.items;
}
getPinnedComposites(): ICompositeBarItem[] {
return this.model.pinnedItems;
}
create(parent: HTMLElement): HTMLElement {
const actionBarDiv = parent.appendChild($('.composite-bar'));
this.compositeSwitcherBar = this._register(new ActionBar(actionBarDiv, {
......@@ -460,6 +464,10 @@ class CompositeBarModel {
return this.items.filter(item => item.visible);
}
get pinnedItems(): ICompositeBarItem[] {
return this.items.filter(item => item.visible && item.pinned);
}
private createCompositeBarItem(id: string, name: string, order: number, pinned: boolean, visible: boolean): ICompositeBarItem {
const options = this.options;
return {
......
......@@ -169,6 +169,69 @@ export class PanelActivityAction extends ActivityAction {
}
}
export class SwitchPanelItemAction extends Action {
constructor(
id: string,
name: string,
@IPanelService private panelService: IPanelService
) {
super(id, name);
}
run(offset: number): TPromise<any> {
const pinnedPanels = this.panelService.getPinnedPanels();
const activePanel = this.panelService.getActivePanel();
if (!activePanel) {
return TPromise.as(null);
}
let targetPanelId: string;
for (let i = 0; i < pinnedPanels.length; i++) {
if (pinnedPanels[i].id === activePanel.getId()) {
targetPanelId = pinnedPanels[(i + pinnedPanels.length + offset) % pinnedPanels.length].id;
break;
}
}
return this.panelService.openPanel(targetPanelId, true);
}
}
export class PreviousPanelViewAction extends SwitchPanelItemAction {
static readonly ID = 'workbench.action.previousPanelView';
static LABEL = nls.localize('previousPanelView', 'Previous Panel View');
constructor(
id: string,
name: string,
@IPanelService panelService: IPanelService
) {
super(id, name, panelService);
}
run(): TPromise<any> {
return super.run(-1);
}
}
export class NextPanelViewAction extends SwitchPanelItemAction {
static readonly ID = 'workbench.action.nextPanelView';
static LABEL = nls.localize('nextPanelView', 'Next Panel View');
constructor(
id: string,
name: string,
@IPanelService panelService: IPanelService
) {
super(id, name, panelService);
}
public run(): TPromise<any> {
return super.run(1);
}
}
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_J }), 'View: Toggle Panel', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusPanelAction, FocusPanelAction.ID, FocusPanelAction.LABEL), 'View: Focus into Panel', nls.localize('view', "View"));
......@@ -176,6 +239,8 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMaximizedP
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL), 'View: Close Panel', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelPositionAction, TogglePanelPositionAction.ID, TogglePanelPositionAction.LABEL), 'View: Toggle Panel Position', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, undefined), 'View: Toggle Panel Position', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PreviousPanelViewAction, PreviousPanelViewAction.ID, PreviousPanelViewAction.LABEL), 'View: Open Previous Panel View', nls.localize('view', "View"));
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(NextPanelViewAction, NextPanelViewAction.ID, NextPanelViewAction.LABEL), 'View: Open Next Panel View', nls.localize('view', "View"));
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
group: '2_workbench_layout',
......
......@@ -198,6 +198,13 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
.sort((v1, v2) => v1.order - v2.order);
}
getPinnedPanels(): PanelDescriptor[] {
const pinnedCompositeIds = this.compositeBar.getPinnedComposites().map(c => c.id);
return this.getPanels()
.filter(p => pinnedCompositeIds.indexOf(p.id) !== -1)
.sort((p1, p2) => pinnedCompositeIds.indexOf(p1.id) - pinnedCompositeIds.indexOf(p2.id));
}
setPanelEnablement(id: string, enabled: boolean): void {
const descriptor = Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels().filter(p => p.id === id).pop();
if (descriptor && descriptor.enabled !== enabled) {
......
......@@ -34,10 +34,15 @@ export interface IPanelService {
getActivePanel(): IPanel;
/**
* Returns all enabled panels
* * Returns all built-in panels following the default order (Problems - Output - Debug Console - Terminal)
*/
getPanels(): IPanelIdentifier[];
/**
* Returns pinned panels following the visual order
*/
getPinnedPanels(): IPanelIdentifier[];
/**
* Enables or disables a panel. Disabled panels are completly hidden from UI.
* By default all panels are enabled.
......
......@@ -79,6 +79,10 @@ class TestPanelService implements IPanelService {
return [];
}
public getPinnedPanels(): any[] {
return [];
}
public getActivePanel(): IViewlet {
return activeViewlet;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册