提交 b284ed56 编写于 作者: I isidor

panel: address Ben's feedback

上级 b19445e3
......@@ -23,8 +23,9 @@ export const EventType = {
};
/**
* Composites are layed out in the sidebar part of the workbench. Only one composite can be open
* at a time. Each composite has a minimized representation that is good enough to provide some
* Composites are layed out in the sidebar and panel part of the workbench. At a time only one composite
* can be open in the sidebar, and only one composite can be open in the panel.
* Each composite has a minimized representation that is good enough to provide some
* information about the state of the composite data.
* The workbench will keep a composite alive after it has been created and show/hide it based on
* user interaction. The lifecycle of a composite goes in the order create(), setVisible(true|false),
......
......@@ -3,17 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import nls = require('vs/nls');
import {Promise} from 'vs/base/common/winjs.base';
import {Action} from 'vs/base/common/actions';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import {Registry} from 'vs/platform/platform';
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IPanel} from 'vs/workbench/common/panel';
import {IWorkbenchActionRegistry, Extensions as WorkbenchExtensions} from 'vs/workbench/common/actionRegistry';
import {Composite, CompositeDescriptor, CompositeRegistry} from 'vs/workbench/browser/composite';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
export abstract class Panel extends Composite implements IPanel { }
......@@ -64,44 +57,3 @@ export class PanelRegistry extends CompositeRegistry<Panel> {
export const Extensions = {
Panels: 'workbench.contributions.panels'
};
export class ClosePanelAction extends Action {
static ID = 'workbench.action.closePanelAction';
static LABEL = nls.localize('closePanel', "Close");
constructor(
id: string,
name: string,
@IPartService private partService: IPartService
) {
super(id, name, 'close-editor-action');
}
public run(): Promise {
this.partService.setPanelHidden(true);
return Promise.as(true);
}
}
export class TogglePanelAction extends Action {
static ID = 'workbench.action.togglePanelAction';
static LABEL = nls.localize('togglePanel', "Toggle Panel Visibility");
constructor(
id: string,
name: string,
@IPartService private partService: IPartService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
super(id, name, null, !!contextService.getWorkspace());
}
public run(): Promise {
this.partService.setPanelHidden(!this.partService.isPanelHidden());
return Promise.as(true);
}
}
Registry.add(Extensions.Panels, new PanelRegistry());
let actionRegistry = <IWorkbenchActionRegistry>Registry.as(WorkbenchExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_L }), nls.localize('view', "View"));
......@@ -4,10 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/panelPart';
import {TPromise} from 'vs/base/common/winjs.base';
import nls = require('vs/nls');
import {TPromise, Promise} from 'vs/base/common/winjs.base';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import strings = require('vs/base/common/strings');
import {Action} from 'vs/base/common/actions';
import {Builder} from 'vs/base/browser/builder';
import {Registry} from 'vs/platform/platform';
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IWorkbenchActionRegistry, Extensions as WorkbenchExtensions} from 'vs/workbench/common/actionRegistry';
import {IPanel} from 'vs/workbench/common/panel';
import {EventType as WorkbenchEventType, CompositeEvent} from 'vs/workbench/common/events';
import {CompositePart} from 'vs/workbench/browser/parts/compositePart';
......@@ -19,6 +24,7 @@ import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
import {IEventService} from 'vs/platform/event/common/event';
import {IMessageService, Severity} from 'vs/platform/message/common/message';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
export class PanelPart extends CompositePart<Panel> implements IPanelService {
......@@ -63,7 +69,7 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
public createTitleArea(parent: Builder): Builder {
const result = super.createTitleArea(parent);
result.addClass('monaco-editor-background');
return result;
}
......@@ -91,3 +97,45 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
return this.hideActiveComposite();
}
}
export class ClosePanelAction extends Action {
static ID = 'workbench.action.closePanelAction';
static LABEL = nls.localize('closePanel', "Close");
constructor(
id: string,
name: string,
@IPartService private partService: IPartService
) {
super(id, name, 'close-editor-action');
}
public run(): Promise {
this.partService.setPanelHidden(true);
return Promise.as(true);
}
}
export class TogglePanelAction extends Action {
static ID = 'workbench.action.togglePanelAction';
static LABEL = nls.localize('togglePanel', "Toggle Panel Visibility");
constructor(
id: string,
name: string,
@IPartService private partService: IPartService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
super(id, name, null, !!contextService.getWorkspace());
}
public run(): Promise {
this.partService.setPanelHidden(!this.partService.isPanelHidden());
return Promise.as(true);
}
}
Registry.add(PanelExtensions.Panels, new PanelRegistry());
let actionRegistry = <IWorkbenchActionRegistry>Registry.as(WorkbenchExtensions.WorkbenchActions);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_L }), nls.localize('view', "View"));
......@@ -199,8 +199,8 @@ export class Workbench implements IPartService {
// Register Emitters
this.registerEmitters();
// Load viewlet and editors in parallel
let viewletAndEditorPromises: Promise[] = [];
// Load composits and editors in parallel
let compositeAndEditorPromises: Promise[] = [];
// Show default viewlet unless sidebar is hidden or we dont have a default viewlet
let registry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
......@@ -211,12 +211,12 @@ export class Workbench implements IPartService {
if (!this.sideBarHidden && !!viewletId) {
let viewletTimerEvent = timer.start(timer.Topic.STARTUP, strings.format('Opening Viewlet: {0}', viewletId));
viewletAndEditorPromises.push(this.sidebarPart.openViewlet(viewletId, false).then(() => viewletTimerEvent.stop()));
compositeAndEditorPromises.push(this.sidebarPart.openViewlet(viewletId, false).then(() => viewletTimerEvent.stop()));
}
if (!this.panelHidden) {
const panelId = this.storageService.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE);
viewletAndEditorPromises.push(this.panelPart.openPanel(panelId, false));
compositeAndEditorPromises.push(this.panelPart.openPanel(panelId, false));
}
// Check for configured options to open files on startup and resolve if any or open untitled for empty workbench
......@@ -249,7 +249,7 @@ export class Workbench implements IPartService {
}
// Restore editor state (either from last session or with given inputs)
viewletAndEditorPromises.push(resolveEditorInputsPromise.then((inputs) => {
compositeAndEditorPromises.push(resolveEditorInputsPromise.then((inputs) => {
return this.editorPart.restoreEditorState(inputs, options).then(() => {
this.onEditorOpenedOrClosed(); // make sure we show the proper background in the editor area
editorTimerEvent.stop();
......@@ -257,7 +257,7 @@ export class Workbench implements IPartService {
}));
// Flag workbench as created once done
Promise.join(viewletAndEditorPromises).then(() => {
Promise.join(compositeAndEditorPromises).then(() => {
this.workbenchCreated = true;
this.eventService.emit(EventType.WORKBENCH_CREATED);
this.creationPromiseComplete(true);
......@@ -418,15 +418,17 @@ export class Workbench implements IPartService {
this.sideBarHidden = true; // we hide sidebar in single-file-mode
}
let registry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
if (!registry.getDefaultViewletId()) {
let viewletRegistry = (<ViewletRegistry>Registry.as(ViewletExtensions.Viewlets));
if (!viewletRegistry.getDefaultViewletId()) {
this.sideBarHidden = true; // can only hide sidebar if we dont have a default viewlet id
}
// Panel part visibility
let panelRegistry = (<PanelRegistry>Registry.as(PanelExtensions.Panels));
this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenSettingKey, StorageScope.WORKSPACE, true);
if (!!this.workbenchParams.options.singleFileMode) {
this.panelHidden = true; // we hide panel part in single-file-mode
if (!!this.workbenchParams.options.singleFileMode || !panelRegistry.getDefaultPanelId()) {
// we hide panel part in single-file-mode or if there is no default panel
this.panelHidden = true;
}
// Sidebar position
......
......@@ -17,7 +17,8 @@ import viewer = require('vs/workbench/parts/debug/browser/replViewer');
import debug = require('vs/workbench/parts/debug/common/debug');
import debugactions = require('vs/workbench/parts/debug/electron-browser/debugActions');
import replhistory = require('vs/workbench/parts/debug/common/replHistory');
import { Panel, ClosePanelAction } from 'vs/workbench/browser/panel';
import { Panel } from 'vs/workbench/browser/panel';
import { ClosePanelAction } from 'vs/workbench/browser/parts/panel/panelPart';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService, INullService } from 'vs/platform/instantiation/common/instantiation';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册