提交 8869632b 编写于 作者: P Pine Wu

Prev/Next Sidebar View

上级 4e50ae60
...@@ -5,26 +5,31 @@ ...@@ -5,26 +5,31 @@
'use strict'; 'use strict';
import 'vs/css!./media/activityaction';
import * as DOM from 'vs/base/browser/dom'; import * as DOM from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch'; import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
import { KeyCode } from 'vs/base/common/keyCodes';
import { dispose } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import 'vs/css!./media/activityaction';
import * as nls from 'vs/nls';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { Registry } from 'vs/platform/registry/common/platform';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { activeContrastBorder, focusBorder } from 'vs/platform/theme/common/colorRegistry';
import { ICssStyleCollector, ITheme, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { ActivityAction, ActivityActionItem, ICompositeBar, ICompositeBarColors, ToggleCompositePinnedAction } from 'vs/workbench/browser/parts/compositeBarActions';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet'; import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
import { IActivity, IGlobalActivity } from 'vs/workbench/common/activity'; import { IActivity, IGlobalActivity } from 'vs/workbench/common/activity';
import { dispose } from 'vs/base/common/lifecycle';
import { IViewletService, } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { IThemeService, ITheme, registerThemingParticipant, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { activeContrastBorder, focusBorder } from 'vs/platform/theme/common/colorRegistry';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { ActivityAction, ActivityActionItem, ICompositeBarColors, ToggleCompositePinnedAction, ICompositeBar } from 'vs/workbench/browser/parts/compositeBarActions';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { URI } from 'vs/base/common/uri';
import { ACTIVITY_BAR_FOREGROUND } from 'vs/workbench/common/theme'; import { ACTIVITY_BAR_FOREGROUND } from 'vs/workbench/common/theme';
import { IActivityService } from 'vs/workbench/services/activity/common/activity';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
export class ViewletActivityAction extends ActivityAction { export class ViewletActivityAction extends ActivityAction {
...@@ -191,6 +196,77 @@ export class PlaceHolderToggleCompositePinnedAction extends ToggleCompositePinne ...@@ -191,6 +196,77 @@ export class PlaceHolderToggleCompositePinnedAction extends ToggleCompositePinne
} }
} }
class SwitchSidebarViewAction extends Action {
constructor(
id: string,
name: string,
@IViewletService private viewletService: IViewletService,
@IActivityService private activityService: IActivityService
) {
super(id, name);
}
run(offset: number): TPromise<any> {
const pinnedViewletIds = this.activityService.getPinnedViewletIds();
const activeViewlet = this.viewletService.getActiveViewlet();
if (!activeViewlet) {
return TPromise.as(null);
}
let targetViewletId: string;
for (let i = 0; i < pinnedViewletIds.length; i++) {
if (pinnedViewletIds[i] === activeViewlet.getId()) {
targetViewletId = pinnedViewletIds[(i + pinnedViewletIds.length + offset) % pinnedViewletIds.length];
break;
}
}
return this.viewletService.openViewlet(targetViewletId, true);
}
}
export class PreviousSidebarViewAction extends SwitchSidebarViewAction {
static readonly ID = 'workbench.action.previousSidebarView';
static LABEL = nls.localize('previousSidebarView', 'Previous Sidebar View');
constructor(
id: string,
name: string,
@IViewletService viewletService: IViewletService,
@IActivityService activityService: IActivityService
) {
super(id, name, viewletService, activityService);
}
run(): TPromise<any> {
return super.run(-1);
}
}
export class NextSidebarViewAction extends SwitchSidebarViewAction {
static readonly ID = 'workbench.action.nextSidebarView';
static LABEL = nls.localize('nextSidebarView', 'Next Sidebar View');
constructor(
id: string,
name: string,
@IViewletService viewletService: IViewletService,
@IActivityService activityService: IActivityService
) {
super(id, name, viewletService, activityService);
}
run(): TPromise<any> {
return super.run(1);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(PreviousSidebarViewAction, PreviousSidebarViewAction.ID, PreviousSidebarViewAction.LABEL), 'View: Open Previous Sidebar View', nls.localize('view', "View"));
registry.registerWorkbenchAction(new SyncActionDescriptor(NextSidebarViewAction, NextSidebarViewAction.ID, NextSidebarViewAction.LABEL), 'View: Open Next Sidebar View', nls.localize('view', "View"));
registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => { registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
const activeForegroundColor = theme.getColor(ACTIVITY_BAR_FOREGROUND); const activeForegroundColor = theme.getColor(ACTIVITY_BAR_FOREGROUND);
......
...@@ -306,8 +306,12 @@ export class ActivitybarPart extends Part { ...@@ -306,8 +306,12 @@ export class ActivitybarPart extends Part {
} }
} }
getPinned(): string[] { getPinnedViewletIds(): string[] {
return this.viewletService.getViewlets().map(v => v.id).filter(id => this.compositeBar.isPinned(id)); const pinnedCompositeIds = this.compositeBar.getPinnedComposites().map(v => v.id);
return this.viewletService.getViewlets()
.filter(v => this.compositeBar.isPinned(v.id))
.sort((v1, v2) => pinnedCompositeIds.indexOf(v1.id) - pinnedCompositeIds.indexOf(v2.id))
.map(v => v.id);
} }
layout(dimension: Dimension): Dimension[] { layout(dimension: Dimension): Dimension[] {
......
...@@ -169,7 +169,7 @@ export class PanelActivityAction extends ActivityAction { ...@@ -169,7 +169,7 @@ export class PanelActivityAction extends ActivityAction {
} }
} }
export class SwitchPanelItemAction extends Action { export class SwitchPanelViewAction extends Action {
constructor( constructor(
id: string, id: string,
...@@ -196,7 +196,7 @@ export class SwitchPanelItemAction extends Action { ...@@ -196,7 +196,7 @@ export class SwitchPanelItemAction extends Action {
} }
} }
export class PreviousPanelViewAction extends SwitchPanelItemAction { export class PreviousPanelViewAction extends SwitchPanelViewAction {
static readonly ID = 'workbench.action.previousPanelView'; static readonly ID = 'workbench.action.previousPanelView';
static LABEL = nls.localize('previousPanelView', 'Previous Panel View'); static LABEL = nls.localize('previousPanelView', 'Previous Panel View');
...@@ -214,7 +214,7 @@ export class PreviousPanelViewAction extends SwitchPanelItemAction { ...@@ -214,7 +214,7 @@ export class PreviousPanelViewAction extends SwitchPanelItemAction {
} }
} }
export class NextPanelViewAction extends SwitchPanelItemAction { export class NextPanelViewAction extends SwitchPanelViewAction {
static readonly ID = 'workbench.action.nextPanelView'; static readonly ID = 'workbench.action.nextPanelView';
static LABEL = nls.localize('nextPanelView', 'Next Panel View'); static LABEL = nls.localize('nextPanelView', 'Next Panel View');
......
...@@ -762,7 +762,7 @@ export class Workbench extends Disposable implements IPartService { ...@@ -762,7 +762,7 @@ export class Workbench extends Disposable implements IPartService {
return { return {
customKeybindingsCount: this.keybindingService.customKeybindingsCount(), customKeybindingsCount: this.keybindingService.customKeybindingsCount(),
pinnedViewlets: this.activitybarPart.getPinned(), pinnedViewlets: this.activitybarPart.getPinnedViewletIds(),
restoredViewlet: viewletIdToRestore, restoredViewlet: viewletIdToRestore,
restoredEditorsCount: this.editorService.visibleEditors.length restoredEditorsCount: this.editorService.visibleEditors.length
}; };
......
...@@ -28,4 +28,9 @@ export class ActivityService implements IActivityService { ...@@ -28,4 +28,9 @@ export class ActivityService implements IActivityService {
return this.activitybarPart.showActivity(compositeOrActionId, badge, clazz, priority); return this.activitybarPart.showActivity(compositeOrActionId, badge, clazz, priority);
} }
getPinnedViewletIds(): string[] {
return this.activitybarPart.getPinnedViewletIds();
}
} }
...@@ -67,4 +67,9 @@ export interface IActivityService { ...@@ -67,4 +67,9 @@ export interface IActivityService {
* Show activity in the panel for the given panel or in the activitybar for the given viewlet or global action. * Show activity in the panel for the given panel or in the activitybar for the given viewlet or global action.
*/ */
showActivity(compositeOrActionId: string, badge: IBadge, clazz?: string, priority?: number): IDisposable; showActivity(compositeOrActionId: string, badge: IBadge, clazz?: string, priority?: number): IDisposable;
/**
* Returns id of pinned viewlets following the visual order
*/
getPinnedViewletIds(): string[];
} }
...@@ -42,7 +42,7 @@ export interface IViewletService { ...@@ -42,7 +42,7 @@ export interface IViewletService {
getViewlet(id: string): ViewletDescriptor; getViewlet(id: string): ViewletDescriptor;
/** /**
* Returns all viewlets * Returns all enabled viewlets following the default order (Explorer - Search - SCM - Debug - Extensions)
*/ */
getAllViewlets(): ViewletDescriptor[]; getAllViewlets(): ViewletDescriptor[];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册