未验证 提交 4a45c746 编写于 作者: R Raymond Zhao 提交者: GitHub

Add panel maximization setting for #94930 (#106967)

Add panel maximization settings for #94930 
上级 f390f7ea
......@@ -14,7 +14,7 @@ import { pathsToEditors, SideBySideEditorInput } from 'vs/workbench/common/edito
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { Position, Parts, IWorkbenchLayoutService, positionFromString, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
import { Position, Parts, PanelOpensMaximizedOptions, IWorkbenchLayoutService, positionFromString, positionToString, panelOpensMaximizedFromString } from 'vs/workbench/services/layout/browser/layoutService';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IStorageService, StorageScope, WillSaveStateReason } from 'vs/platform/storage/common/storage';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
......@@ -54,6 +54,7 @@ export enum Settings {
SIDEBAR_POSITION = 'workbench.sideBar.location',
PANEL_POSITION = 'workbench.panel.defaultLocation',
PANEL_OPENS_MAXIMIZED = 'workbench.panel.opensMaximized',
ZEN_MODE_RESTORE = 'zenMode.restore',
}
......@@ -68,6 +69,7 @@ enum Storage {
PANEL_DIMENSION = 'workbench.panel.dimension',
PANEL_LAST_NON_MAXIMIZED_WIDTH = 'workbench.panel.lastNonMaximizedWidth',
PANEL_LAST_NON_MAXIMIZED_HEIGHT = 'workbench.panel.lastNonMaximizedHeight',
PANEL_LAST_IS_MAXIMIZED = 'workbench.panel.lastIsMaximized',
EDITOR_HIDDEN = 'workbench.editor.hidden',
......@@ -218,6 +220,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
position: Position.BOTTOM,
lastNonMaximizedWidth: 300,
lastNonMaximizedHeight: 300,
wasLastMaximized: false,
panelToRestore: undefined as string | undefined
},
......@@ -532,6 +535,9 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
// Panel visibility
this.state.panel.hidden = this.storageService.getBoolean(Storage.PANEL_HIDDEN, StorageScope.WORKSPACE, true);
// Whether or not the panel was last maximized
this.state.panel.wasLastMaximized = this.storageService.getBoolean(Storage.PANEL_LAST_IS_MAXIMIZED, StorageScope.WORKSPACE, false);
// Panel position
this.updatePanelPosition();
......@@ -1544,6 +1550,9 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return;
}
const isPanelMaximized = this.isPanelMaximized();
const panelOpensMaximized = this.panelOpensMaximized();
// Adjust CSS
if (hidden) {
this.container.classList.add(Classes.PANEL_HIDDEN);
......@@ -1567,24 +1576,40 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
}
}
// If not maximized and hiding, unmaximize before hiding to allow caching of size
if (this.isPanelMaximized() && hidden) {
// If maximized and in process of hiding, unmaximize before hiding to allow caching of non-maximized size
if (hidden && isPanelMaximized) {
this.toggleMaximizedPanel();
}
// Propagate to grid
this.workbenchGrid.setViewVisible(this.panelPartView, !hidden);
// Propagate layout changes to grid
if (!skipLayout) {
this.workbenchGrid.setViewVisible(this.panelPartView, !hidden);
// If in process of showing, toggle whether or not panel is maximized
if (!hidden) {
if (isPanelMaximized !== panelOpensMaximized) {
this.toggleMaximizedPanel();
}
}
else {
// If in process of hiding, remember whether the panel is maximized or not
this.state.panel.wasLastMaximized = isPanelMaximized;
}
}
// Remember in settings
if (!hidden) {
this.storageService.store(Storage.PANEL_HIDDEN, 'false', StorageScope.WORKSPACE);
} else {
this.storageService.remove(Storage.PANEL_HIDDEN, StorageScope.WORKSPACE);
}
else {
this.storageService.remove(Storage.PANEL_HIDDEN, StorageScope.WORKSPACE);
// The editor and panel cannot be hidden at the same time
if (hidden && this.state.editor.hidden) {
this.setEditorHidden(false, true);
// Remember this setting only when panel is hiding
if (this.state.panel.wasLastMaximized) {
this.storageService.store(Storage.PANEL_LAST_IS_MAXIMIZED, true, StorageScope.WORKSPACE);
}
else {
this.storageService.remove(Storage.PANEL_LAST_IS_MAXIMIZED, StorageScope.WORKSPACE);
}
}
if (focusEditor) {
......@@ -1612,6 +1637,16 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
}
}
/**
* Returns whether or not the panel opens maximized
*/
private panelOpensMaximized() {
const panelOpensMaximized = panelOpensMaximizedFromString(this.configurationService.getValue<string>(Settings.PANEL_OPENS_MAXIMIZED));
const panelLastIsMaximized = this.state.panel.wasLastMaximized;
return panelOpensMaximized === PanelOpensMaximizedOptions.ALWAYS || (panelOpensMaximized === PanelOpensMaximizedOptions.REMEMBER_LAST && panelLastIsMaximized);
}
hasWindowBorder(): boolean {
return this.state.windowBorder;
}
......
......@@ -118,9 +118,14 @@ export class ToggleMaximizedPanelAction extends Action {
async run(): Promise<void> {
if (!this.layoutService.isVisible(Parts.PANEL_PART)) {
this.layoutService.setPanelHidden(false);
// If the panel is not already maximized, maximize it
if (!this.layoutService.isPanelMaximized()) {
this.layoutService.toggleMaximizedPanel();
}
}
else {
this.layoutService.toggleMaximizedPanel();
}
this.layoutService.toggleMaximizedPanel();
}
}
......
......@@ -233,6 +233,17 @@ import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuratio
'default': 'bottom',
'description': nls.localize('panelDefaultLocation', "Controls the default location of the panel (terminal, debug console, output, problems). It can either show at the bottom, right, or left of the workbench.")
},
'workbench.panel.opensMaximized': {
'type': 'string',
'enum': ['always', 'never', 'preserve'],
'default': 'preserve',
'description': nls.localize('panelOpensMaximized', "Controls whether the panel opens maximized. It can either always open maximized, never open maximized, or open to the last state it was in before being closed."),
'enumDescriptions': [
nls.localize('workbench.panel.opensMaximized.always', "Always maximize the panel when opening it."),
nls.localize('workbench.panel.opensMaximized.never', "Never maximize the panel when opening it. The panel will open un-maximized."),
nls.localize('workbench.panel.opensMaximized.preserve', "Open the panel to the state that it was in, before it was closed.")
]
},
'workbench.statusBar.visible': {
'type': 'boolean',
'default': true,
......
......@@ -28,6 +28,12 @@ export const enum Position {
BOTTOM
}
export const enum PanelOpensMaximizedOptions {
ALWAYS,
NEVER,
REMEMBER_LAST
}
export function positionToString(position: Position): string {
switch (position) {
case Position.LEFT: return 'left';
......@@ -47,6 +53,25 @@ export function positionFromString(str: string): Position {
return positionsByString[str];
}
export function panelOpensMaximizedSettingToString(setting: PanelOpensMaximizedOptions): string {
switch (setting) {
case PanelOpensMaximizedOptions.ALWAYS: return 'always';
case PanelOpensMaximizedOptions.NEVER: return 'never';
case PanelOpensMaximizedOptions.REMEMBER_LAST: return 'preserve';
default: return 'preserve';
}
}
const panelOpensMaximizedByString: { [key: string]: PanelOpensMaximizedOptions } = {
[panelOpensMaximizedSettingToString(PanelOpensMaximizedOptions.ALWAYS)]: PanelOpensMaximizedOptions.ALWAYS,
[panelOpensMaximizedSettingToString(PanelOpensMaximizedOptions.NEVER)]: PanelOpensMaximizedOptions.NEVER,
[panelOpensMaximizedSettingToString(PanelOpensMaximizedOptions.REMEMBER_LAST)]: PanelOpensMaximizedOptions.REMEMBER_LAST
};
export function panelOpensMaximizedFromString(str: string): PanelOpensMaximizedOptions {
return panelOpensMaximizedByString[str];
}
export interface IWorkbenchLayoutService extends ILayoutService {
readonly _serviceBrand: undefined;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册