Skip to content

Commit 4e50ae6

Browse files
committed
Prev/Next Panel item
1 parent 36a2a4b commit 4e50ae6

5 files changed

Lines changed: 90 additions & 1 deletion

File tree

src/vs/workbench/browser/parts/compositeBar.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export class CompositeBar extends Widget implements ICompositeBar {
7272
return this.model.items;
7373
}
7474

75+
getPinnedComposites(): ICompositeBarItem[] {
76+
return this.model.pinnedItems;
77+
}
78+
7579
create(parent: HTMLElement): HTMLElement {
7680
const actionBarDiv = parent.appendChild($('.composite-bar'));
7781
this.compositeSwitcherBar = this._register(new ActionBar(actionBarDiv, {
@@ -460,6 +464,10 @@ class CompositeBarModel {
460464
return this.items.filter(item => item.visible);
461465
}
462466

467+
get pinnedItems(): ICompositeBarItem[] {
468+
return this.items.filter(item => item.visible && item.pinned);
469+
}
470+
463471
private createCompositeBarItem(id: string, name: string, order: number, pinned: boolean, visible: boolean): ICompositeBarItem {
464472
const options = this.options;
465473
return {

src/vs/workbench/browser/parts/panel/panelActions.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,78 @@ export class PanelActivityAction extends ActivityAction {
169169
}
170170
}
171171

172+
export class SwitchPanelItemAction extends Action {
173+
174+
constructor(
175+
id: string,
176+
name: string,
177+
@IPanelService private panelService: IPanelService
178+
) {
179+
super(id, name);
180+
}
181+
182+
run(offset: number): TPromise<any> {
183+
const pinnedPanels = this.panelService.getPinnedPanels();
184+
const activePanel = this.panelService.getActivePanel();
185+
if (!activePanel) {
186+
return TPromise.as(null);
187+
}
188+
let targetPanelId: string;
189+
for (let i = 0; i < pinnedPanels.length; i++) {
190+
if (pinnedPanels[i].id === activePanel.getId()) {
191+
targetPanelId = pinnedPanels[(i + pinnedPanels.length + offset) % pinnedPanels.length].id;
192+
break;
193+
}
194+
}
195+
return this.panelService.openPanel(targetPanelId, true);
196+
}
197+
}
198+
199+
export class PreviousPanelViewAction extends SwitchPanelItemAction {
200+
201+
static readonly ID = 'workbench.action.previousPanelView';
202+
static LABEL = nls.localize('previousPanelView', 'Previous Panel View');
203+
204+
constructor(
205+
id: string,
206+
name: string,
207+
@IPanelService panelService: IPanelService
208+
) {
209+
super(id, name, panelService);
210+
}
211+
212+
run(): TPromise<any> {
213+
return super.run(-1);
214+
}
215+
}
216+
217+
export class NextPanelViewAction extends SwitchPanelItemAction {
218+
219+
static readonly ID = 'workbench.action.nextPanelView';
220+
static LABEL = nls.localize('nextPanelView', 'Next Panel View');
221+
222+
constructor(
223+
id: string,
224+
name: string,
225+
@IPanelService panelService: IPanelService
226+
) {
227+
super(id, name, panelService);
228+
}
229+
230+
public run(): TPromise<any> {
231+
return super.run(1);
232+
}
233+
}
234+
172235
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchExtensions.WorkbenchActions);
173236
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_J }), 'View: Toggle Panel', nls.localize('view', "View"));
174237
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusPanelAction, FocusPanelAction.ID, FocusPanelAction.LABEL), 'View: Focus into Panel', nls.localize('view', "View"));
175238
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, ToggleMaximizedPanelAction.LABEL), 'View: Toggle Maximized Panel', nls.localize('view', "View"));
176239
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ClosePanelAction, ClosePanelAction.ID, ClosePanelAction.LABEL), 'View: Close Panel', nls.localize('view', "View"));
177240
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelPositionAction, TogglePanelPositionAction.ID, TogglePanelPositionAction.LABEL), 'View: Toggle Panel Position', nls.localize('view', "View"));
178241
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMaximizedPanelAction, ToggleMaximizedPanelAction.ID, undefined), 'View: Toggle Panel Position', nls.localize('view', "View"));
242+
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(PreviousPanelViewAction, PreviousPanelViewAction.ID, PreviousPanelViewAction.LABEL), 'View: Open Previous Panel View', nls.localize('view', "View"));
243+
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(NextPanelViewAction, NextPanelViewAction.ID, NextPanelViewAction.LABEL), 'View: Open Next Panel View', nls.localize('view', "View"));
179244

180245
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
181246
group: '2_workbench_layout',

src/vs/workbench/browser/parts/panel/panelPart.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
198198
.sort((v1, v2) => v1.order - v2.order);
199199
}
200200

201+
getPinnedPanels(): PanelDescriptor[] {
202+
const pinnedCompositeIds = this.compositeBar.getPinnedComposites().map(c => c.id);
203+
return this.getPanels()
204+
.filter(p => pinnedCompositeIds.indexOf(p.id) !== -1)
205+
.sort((p1, p2) => pinnedCompositeIds.indexOf(p1.id) - pinnedCompositeIds.indexOf(p2.id));
206+
}
207+
201208
setPanelEnablement(id: string, enabled: boolean): void {
202209
const descriptor = Registry.as<PanelRegistry>(PanelExtensions.Panels).getPanels().filter(p => p.id === id).pop();
203210
if (descriptor && descriptor.enabled !== enabled) {

src/vs/workbench/services/panel/common/panelService.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ export interface IPanelService {
3434
getActivePanel(): IPanel;
3535

3636
/**
37-
* Returns all enabled panels
37+
* * Returns all built-in panels following the default order (Problems - Output - Debug Console - Terminal)
3838
*/
3939
getPanels(): IPanelIdentifier[];
4040

41+
/**
42+
* Returns pinned panels following the visual order
43+
*/
44+
getPinnedPanels(): IPanelIdentifier[];
45+
4146
/**
4247
* Enables or disables a panel. Disabled panels are completly hidden from UI.
4348
* By default all panels are enabled.

src/vs/workbench/services/progress/test/progressService.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class TestPanelService implements IPanelService {
7979
return [];
8080
}
8181

82+
public getPinnedPanels(): any[] {
83+
return [];
84+
}
85+
8286
public getActivePanel(): IViewlet {
8387
return activeViewlet;
8488
}

0 commit comments

Comments
 (0)