提交 2ac36dca 编写于 作者: B Benjamin Pasero

debt - extract navigational actions

上级 bda7cadc
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { IEditorGroupsService, GroupDirection, GroupLocation, IFindGroupScope } from 'vs/workbench/services/group/common/editorGroupsService';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService, Parts, Position as PartPosition } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IPanel } from 'vs/workbench/common/panel';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
abstract class BaseNavigationAction extends Action {
constructor(
id: string,
label: string,
@IEditorGroupsService protected editorGroupService: IEditorGroupsService,
@IPanelService protected panelService: IPanelService,
@IPartService protected partService: IPartService,
@IViewletService protected viewletService: IViewletService
) {
super(id, label);
}
run(): Promise<any> {
const isEditorFocus = this.partService.hasFocus(Parts.EDITOR_PART);
const isPanelFocus = this.partService.hasFocus(Parts.PANEL_PART);
const isSidebarFocus = this.partService.hasFocus(Parts.SIDEBAR_PART);
const isSidebarPositionLeft = this.partService.getSideBarPosition() === PartPosition.LEFT;
const isPanelPositionDown = this.partService.getPanelPosition() === PartPosition.BOTTOM;
if (isEditorFocus) {
return this.navigateOnEditorFocus(isSidebarPositionLeft, isPanelPositionDown);
}
if (isPanelFocus) {
return this.navigateOnPanelFocus(isSidebarPositionLeft, isPanelPositionDown);
}
if (isSidebarFocus) {
return Promise.resolve(this.navigateOnSidebarFocus(isSidebarPositionLeft, isPanelPositionDown));
}
return Promise.resolve(false);
}
protected navigateOnEditorFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IViewlet | IPanel> {
return Promise.resolve(true);
}
protected navigateOnPanelFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IPanel> {
return Promise.resolve(true);
}
protected navigateOnSidebarFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): boolean | IViewlet {
return true;
}
protected navigateToPanel(): IPanel | boolean {
if (!this.partService.isVisible(Parts.PANEL_PART)) {
return false;
}
const activePanelId = this.panelService.getActivePanel().getId();
return this.panelService.openPanel(activePanelId, true);
}
protected navigateToSidebar(): Promise<IViewlet | boolean> {
if (!this.partService.isVisible(Parts.SIDEBAR_PART)) {
return Promise.resolve(false);
}
const activeViewletId = this.viewletService.getActiveViewlet().getId();
return this.viewletService.openViewlet(activeViewletId, true)
.then(value => value === null ? false : value);
}
protected navigateAcrossEditorGroup(direction: GroupDirection): boolean {
return this.doNavigateToEditorGroup({ direction });
}
protected navigateToEditorGroup(location: GroupLocation): boolean {
return this.doNavigateToEditorGroup({ location });
}
private doNavigateToEditorGroup(scope: IFindGroupScope): boolean {
const targetGroup = this.editorGroupService.findGroup(scope, this.editorGroupService.activeGroup);
if (targetGroup) {
targetGroup.focus();
return true;
}
return false;
}
}
class NavigateLeftAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateLeft';
static readonly LABEL = nls.localize('navigateLeft', "Navigate to the View on the Left");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IViewlet> {
const didNavigate = this.navigateAcrossEditorGroup(GroupDirection.LEFT);
if (didNavigate) {
return Promise.resolve(true);
}
if (isSidebarPositionLeft) {
return this.navigateToSidebar();
}
return Promise.resolve(false);
}
protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean | IViewlet> {
if (isPanelPositionDown && isSidebarPositionLeft) {
return this.navigateToSidebar();
}
if (!isPanelPositionDown) {
return Promise.resolve(this.navigateToEditorGroup(GroupLocation.LAST));
}
return Promise.resolve(false);
}
protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): boolean {
if (!isSidebarPositionLeft) {
return this.navigateToEditorGroup(GroupLocation.LAST);
}
return false;
}
}
class NavigateRightAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateRight';
static readonly LABEL = nls.localize('navigateRight', "Navigate to the View on the Right");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean | IViewlet | IPanel> {
const didNavigate = this.navigateAcrossEditorGroup(GroupDirection.RIGHT);
if (didNavigate) {
return Promise.resolve(true);
}
if (!isPanelPositionDown) {
return Promise.resolve(this.navigateToPanel());
}
if (!isSidebarPositionLeft) {
return this.navigateToSidebar();
}
return Promise.resolve(false);
}
protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IViewlet> {
if (!isSidebarPositionLeft) {
return this.navigateToSidebar();
}
return Promise.resolve(false);
}
protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): boolean {
if (isSidebarPositionLeft) {
return this.navigateToEditorGroup(GroupLocation.FIRST);
}
return false;
}
}
class NavigateUpAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateUp';
static readonly LABEL = nls.localize('navigateUp', "Navigate to the View Above");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean> {
return Promise.resolve(this.navigateAcrossEditorGroup(GroupDirection.UP));
}
protected navigateOnPanelFocus(_isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean> {
if (isPanelPositionDown) {
return Promise.resolve(this.navigateToEditorGroup(GroupLocation.LAST));
}
return Promise.resolve(false);
}
}
class NavigateDownAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateDown';
static readonly LABEL = nls.localize('navigateDown', "Navigate to the View Below");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(_isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean | IPanel> {
const didNavigate = this.navigateAcrossEditorGroup(GroupDirection.DOWN);
if (didNavigate) {
return Promise.resolve(true);
}
if (isPanelPositionDown) {
return Promise.resolve(this.navigateToPanel());
}
return Promise.resolve(false);
}
}
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
const viewCategory = nls.localize('view', "View");
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateUpAction, NavigateUpAction.ID, NavigateUpAction.LABEL, undefined), 'View: Navigate to the View Above', viewCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateDownAction, NavigateDownAction.ID, NavigateDownAction.LABEL, undefined), 'View: Navigate to the View Below', viewCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateLeftAction, NavigateLeftAction.ID, NavigateLeftAction.LABEL, undefined), 'View: Navigate to the View on the Left', viewCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateRightAction, NavigateRightAction.ID, NavigateRightAction.LABEL, undefined), 'View: Navigate to the View on the Right', viewCategory);
......@@ -7,13 +7,8 @@ import { Action } from 'vs/base/common/actions';
import * as nls from 'vs/nls';
import product from 'vs/platform/node/product';
import { isMacintosh, isLinux, language } from 'vs/base/common/platform';
import { IEditorGroupsService, GroupDirection, GroupLocation, IFindGroupScope } from 'vs/workbench/services/group/common/editorGroupsService';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService, Parts, Position as PartPosition } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
import { shell } from 'electron';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { IPanel } from 'vs/workbench/common/panel';
import { IssueType } from 'vs/platform/issue/common/issue';
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
......@@ -158,259 +153,6 @@ export class OpenTipsAndTricksUrlAction extends Action {
}
}
export const enum Direction {
Next,
Previous,
}
export abstract class BaseNavigationAction extends Action {
constructor(
id: string,
label: string,
@IEditorGroupsService protected editorGroupService: IEditorGroupsService,
@IPanelService protected panelService: IPanelService,
@IPartService protected partService: IPartService,
@IViewletService protected viewletService: IViewletService
) {
super(id, label);
}
run(): Promise<any> {
const isEditorFocus = this.partService.hasFocus(Parts.EDITOR_PART);
const isPanelFocus = this.partService.hasFocus(Parts.PANEL_PART);
const isSidebarFocus = this.partService.hasFocus(Parts.SIDEBAR_PART);
const isSidebarPositionLeft = this.partService.getSideBarPosition() === PartPosition.LEFT;
const isPanelPositionDown = this.partService.getPanelPosition() === PartPosition.BOTTOM;
if (isEditorFocus) {
return this.navigateOnEditorFocus(isSidebarPositionLeft, isPanelPositionDown);
}
if (isPanelFocus) {
return this.navigateOnPanelFocus(isSidebarPositionLeft, isPanelPositionDown);
}
if (isSidebarFocus) {
return Promise.resolve(this.navigateOnSidebarFocus(isSidebarPositionLeft, isPanelPositionDown));
}
return Promise.resolve(false);
}
protected navigateOnEditorFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IViewlet | IPanel> {
return Promise.resolve(true);
}
protected navigateOnPanelFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IPanel> {
return Promise.resolve(true);
}
protected navigateOnSidebarFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): boolean | IViewlet {
return true;
}
protected navigateToPanel(): IPanel | boolean {
if (!this.partService.isVisible(Parts.PANEL_PART)) {
return false;
}
const activePanelId = this.panelService.getActivePanel().getId();
return this.panelService.openPanel(activePanelId, true);
}
protected navigateToSidebar(): Promise<IViewlet | boolean> {
if (!this.partService.isVisible(Parts.SIDEBAR_PART)) {
return Promise.resolve(false);
}
const activeViewletId = this.viewletService.getActiveViewlet().getId();
return this.viewletService.openViewlet(activeViewletId, true)
.then(value => value === null ? false : value);
}
protected navigateAcrossEditorGroup(direction: GroupDirection): boolean {
return this.doNavigateToEditorGroup({ direction });
}
protected navigateToEditorGroup(location: GroupLocation): boolean {
return this.doNavigateToEditorGroup({ location });
}
private doNavigateToEditorGroup(scope: IFindGroupScope): boolean {
const targetGroup = this.editorGroupService.findGroup(scope, this.editorGroupService.activeGroup);
if (targetGroup) {
targetGroup.focus();
return true;
}
return false;
}
}
export class NavigateLeftAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateLeft';
static readonly LABEL = nls.localize('navigateLeft', "Navigate to the View on the Left");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IViewlet> {
const didNavigate = this.navigateAcrossEditorGroup(GroupDirection.LEFT);
if (didNavigate) {
return Promise.resolve(true);
}
if (isSidebarPositionLeft) {
return this.navigateToSidebar();
}
return Promise.resolve(false);
}
protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean | IViewlet> {
if (isPanelPositionDown && isSidebarPositionLeft) {
return this.navigateToSidebar();
}
if (!isPanelPositionDown) {
return Promise.resolve(this.navigateToEditorGroup(GroupLocation.LAST));
}
return Promise.resolve(false);
}
protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): boolean {
if (!isSidebarPositionLeft) {
return this.navigateToEditorGroup(GroupLocation.LAST);
}
return false;
}
}
export class NavigateRightAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateRight';
static readonly LABEL = nls.localize('navigateRight', "Navigate to the View on the Right");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean | IViewlet | IPanel> {
const didNavigate = this.navigateAcrossEditorGroup(GroupDirection.RIGHT);
if (didNavigate) {
return Promise.resolve(true);
}
if (!isPanelPositionDown) {
return Promise.resolve(this.navigateToPanel());
}
if (!isSidebarPositionLeft) {
return this.navigateToSidebar();
}
return Promise.resolve(false);
}
protected navigateOnPanelFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean | IViewlet> {
if (!isSidebarPositionLeft) {
return this.navigateToSidebar();
}
return Promise.resolve(false);
}
protected navigateOnSidebarFocus(isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): boolean {
if (isSidebarPositionLeft) {
return this.navigateToEditorGroup(GroupLocation.FIRST);
}
return false;
}
}
export class NavigateUpAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateUp';
static readonly LABEL = nls.localize('navigateUp', "Navigate to the View Above");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(_isSidebarPositionLeft: boolean, _isPanelPositionDown: boolean): Promise<boolean> {
return Promise.resolve(this.navigateAcrossEditorGroup(GroupDirection.UP));
}
protected navigateOnPanelFocus(_isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean> {
if (isPanelPositionDown) {
return Promise.resolve(this.navigateToEditorGroup(GroupLocation.LAST));
}
return Promise.resolve(false);
}
}
export class NavigateDownAction extends BaseNavigationAction {
static readonly ID = 'workbench.action.navigateDown';
static readonly LABEL = nls.localize('navigateDown', "Navigate to the View Below");
constructor(
id: string,
label: string,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@IViewletService viewletService: IViewletService
) {
super(id, label, editorGroupService, panelService, partService, viewletService);
}
protected navigateOnEditorFocus(_isSidebarPositionLeft: boolean, isPanelPositionDown: boolean): Promise<boolean | IPanel> {
const didNavigate = this.navigateAcrossEditorGroup(GroupDirection.DOWN);
if (didNavigate) {
return Promise.resolve(true);
}
if (isPanelPositionDown) {
return Promise.resolve(this.navigateToPanel());
}
return Promise.resolve(false);
}
}
// Resize focused view actions
export abstract class BaseResizeViewAction extends Action {
......
......@@ -12,7 +12,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions, Configur
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
import { KeybindingsReferenceAction, OpenDocumentationUrlAction, OpenIntroductoryVideosUrlAction, OpenTipsAndTricksUrlAction, OpenIssueReporterAction, ReportPerformanceIssueUsingReporterAction, NavigateUpAction, NavigateDownAction, NavigateLeftAction, NavigateRightAction, IncreaseViewSizeAction, DecreaseViewSizeAction, OpenProcessExplorer, OpenTwitterUrlAction, OpenRequestFeatureUrlAction, OpenPrivacyStatementUrlAction, OpenLicenseUrlAction } from 'vs/workbench/electron-browser/actions';
import { KeybindingsReferenceAction, OpenDocumentationUrlAction, OpenIntroductoryVideosUrlAction, OpenTipsAndTricksUrlAction, OpenIssueReporterAction, ReportPerformanceIssueUsingReporterAction, IncreaseViewSizeAction, DecreaseViewSizeAction, OpenProcessExplorer, OpenTwitterUrlAction, OpenRequestFeatureUrlAction, OpenPrivacyStatementUrlAction, OpenLicenseUrlAction } from 'vs/workbench/electron-browser/actions';
import { ToggleSharedProcessAction, InspectContextKeysAction, ToggleScreencastModeAction } from 'vs/workbench/electron-browser/actions/developerActions';
import { ShowAboutDialogAction, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleFullScreenAction, CloseCurrentWindowAction, SwitchWindow, NewWindowAction, QuickSwitchWindow, QuickOpenRecentAction, inRecentFilesPickerContextKey, OpenRecentAction } from 'vs/workbench/electron-browser/actions/windowActions';
import { AddRootFolderAction, GlobalRemoveRootFolderAction, OpenWorkspaceAction, SaveWorkspaceAsAction, OpenWorkspaceConfigFileAction, DuplicateWorkspaceInNewWindowAction, OpenFileFolderAction, OpenFileAction, OpenFolderAction, CloseWorkspaceAction } from 'vs/workbench/browser/actions/workspaceActions';
......@@ -118,10 +118,6 @@ workbenchActionsRegistry.registerWorkbenchAction(
);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleFullScreenAction, ToggleFullScreenAction.ID, ToggleFullScreenAction.LABEL, { primary: KeyCode.F11, mac: { primary: KeyMod.CtrlCmd | KeyMod.WinCtrl | KeyCode.KEY_F } }), 'View: Toggle Full Screen', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NavigateUpAction, NavigateUpAction.ID, NavigateUpAction.LABEL, undefined), 'View: Navigate to the View Above', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NavigateDownAction, NavigateDownAction.ID, NavigateDownAction.LABEL, undefined), 'View: Navigate to the View Below', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NavigateLeftAction, NavigateLeftAction.ID, NavigateLeftAction.LABEL, undefined), 'View: Navigate to the View on the Left', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NavigateRightAction, NavigateRightAction.ID, NavigateRightAction.LABEL, undefined), 'View: Navigate to the View on the Right', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(IncreaseViewSizeAction, IncreaseViewSizeAction.ID, IncreaseViewSizeAction.LABEL, undefined), 'View: Increase Current View Size', viewCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(DecreaseViewSizeAction, DecreaseViewSizeAction.ID, DecreaseViewSizeAction.LABEL, undefined), 'View: Decrease Current View Size', viewCategory);
......
......@@ -28,6 +28,7 @@ import 'vs/workbench/parts/localizations/electron-browser/localizations.contribu
// Workbench
import 'vs/workbench/browser/actions/layoutActions';
import 'vs/workbench/browser/actions/listCommands';
import 'vs/workbench/browser/actions/navigationActions';
import 'vs/workbench/parts/preferences/electron-browser/preferences.contribution';
import 'vs/workbench/parts/preferences/browser/keybindingsEditorContribution';
import 'vs/workbench/parts/logs/electron-browser/logs.contribution';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册