Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
13a11b39
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
13a11b39
编写于
3月 04, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - split more layout things out of workbench
上级
5b324d0a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
111 addition
and
103 deletion
+111
-103
src/vs/workbench/electron-browser/workbench.ts
src/vs/workbench/electron-browser/workbench.ts
+111
-103
未找到文件。
src/vs/workbench/electron-browser/workbench.ts
浏览文件 @
13a11b39
...
...
@@ -158,10 +158,7 @@ enum Settings {
ZEN_MODE_RESTORE
=
'
zenMode.restore
'
}
type
FontAliasingOption
=
'
default
'
|
'
antialiased
'
|
'
none
'
|
'
auto
'
;
const
fontAliasingValues
:
FontAliasingOption
[]
=
[
'
antialiased
'
,
'
none
'
,
'
auto
'
];
enum
State
{
enum
Storage
{
SIDEBAR_HIDDEN
=
'
workbench.sidebar.hidden
'
,
PANEL_HIDDEN
=
'
workbench.panel.hidden
'
,
...
...
@@ -213,8 +210,6 @@ export class Workbench extends Disposable implements IPartService {
private
notificationsCenter
:
NotificationsCenter
;
private
notificationsToasts
:
NotificationsToasts
;
private
fontAliasing
:
FontAliasingOption
;
constructor
(
private
container
:
HTMLElement
,
private
configuration
:
IWindowConfiguration
,
...
...
@@ -325,11 +320,12 @@ export class Workbench extends Disposable implements IPartService {
// Register Listeners
this
.
registerListeners
();
this
.
registerLayoutListeners
();
//
Settings
this
.
initState
();
//
Layout State
this
.
init
Layout
State
();
//
Create Workbench and Parts
//
Render Workbench
this
.
renderWorkbench
();
// Workbench Layout
...
...
@@ -571,73 +567,16 @@ export class Workbench extends Disposable implements IPartService {
(
this
.
configuration
.
filesToDiff
&&
this
.
configuration
.
filesToDiff
.
length
>
0
));
}
//#region event handling
private
registerListeners
():
void
{
// Storage
this
.
_register
(
this
.
storageService
.
onWillSaveState
(
e
=>
this
.
saveState
(
e
)));
// Restore editor if hidden and it changes
this
.
_register
(
this
.
editorService
.
onDidVisibleEditorsChange
(()
=>
this
.
setEditorHidden
(
false
)));
this
.
_register
(
this
.
editorPart
.
onDidActivateGroup
(()
=>
this
.
setEditorHidden
(
false
)));
// Configuration changes
this
.
_register
(
this
.
configurationService
.
onDidChangeConfiguration
(()
=>
this
.
setFontAliasing
()));
this
.
_register
(
this
.
configurationService
.
onDidChangeConfiguration
(()
=>
this
.
onDidUpdateConfiguration
()));
// Fullscreen changes
this
.
_register
(
onDidChangeFullscreen
(()
=>
this
.
onFullscreenChanged
()));
// Group changes
this
.
_register
(
this
.
editorGroupService
.
onDidAddGroup
(()
=>
this
.
centerEditorLayout
(
this
.
state
.
editor
.
centered
)));
this
.
_register
(
this
.
editorGroupService
.
onDidRemoveGroup
(()
=>
this
.
centerEditorLayout
(
this
.
state
.
editor
.
centered
)));
// Prevent workbench from scrolling #55456
this
.
_register
(
addDisposableListener
(
this
.
workbench
,
EventType
.
SCROLL
,
()
=>
this
.
workbench
.
scrollTop
=
0
));
// Menubar visibility changes
if
((
isWindows
||
isLinux
)
&&
getTitleBarStyle
(
this
.
configurationService
,
this
.
environmentService
)
===
'
custom
'
)
{
this
.
_register
(
this
.
titlebarPart
.
onMenubarVisibilityChange
(
visible
=>
this
.
onMenubarToggled
(
visible
)));
}
}
private
onMenubarToggled
(
visible
:
boolean
)
{
if
(
visible
!==
this
.
state
.
menuBar
.
toggled
)
{
this
.
state
.
menuBar
.
toggled
=
visible
;
if
(
isFullscreen
()
&&
(
this
.
state
.
menuBar
.
visibility
===
'
toggle
'
||
this
.
state
.
menuBar
.
visibility
===
'
default
'
))
{
this
.
_onTitleBarVisibilityChange
.
fire
();
this
.
layout
();
}
}
}
private
onFullscreenChanged
():
void
{
// Apply as CSS class
if
(
isFullscreen
())
{
addClass
(
this
.
workbench
,
'
fullscreen
'
);
}
else
{
removeClass
(
this
.
workbench
,
'
fullscreen
'
);
if
(
this
.
state
.
zenMode
.
transitionedToFullScreen
&&
this
.
state
.
zenMode
.
active
)
{
this
.
toggleZenMode
();
}
}
// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
if
(
getTitleBarStyle
(
this
.
configurationService
,
this
.
environmentService
)
===
'
custom
'
)
{
this
.
_onTitleBarVisibilityChange
.
fire
();
this
.
layout
();
// handle title bar when fullscreen changes
}
}
//#endregion
private
renderWorkbench
():
void
{
// Apply sidebar state as CSS class
if
(
this
.
state
.
sideBar
.
hidden
)
{
addClass
(
this
.
workbench
,
'
nosidebar
'
);
}
...
...
@@ -650,14 +589,13 @@ export class Workbench extends Disposable implements IPartService {
addClass
(
this
.
workbench
,
'
nostatusbar
'
);
}
// Apply font aliasing
this
.
setFontAliasing
();
// Apply fullscreen state
if
(
isFullscreen
())
{
if
(
this
.
state
.
fullscreen
)
{
addClass
(
this
.
workbench
,
'
fullscreen
'
);
}
// Apply font aliasing
this
.
setFontAliasing
();
// Create Parts
this
.
createTitlebarPart
();
this
.
createActivityBarPart
();
...
...
@@ -673,8 +611,9 @@ export class Workbench extends Disposable implements IPartService {
this
.
container
.
appendChild
(
this
.
workbench
);
}
private
fontAliasing
:
'
default
'
|
'
antialiased
'
|
'
none
'
|
'
auto
'
;
private
setFontAliasing
()
{
const
aliasing
=
this
.
configurationService
.
getValue
<
FontAliasingOption
>
(
Settings
.
FONT_ALIASING
);
const
aliasing
=
this
.
configurationService
.
getValue
<
'
default
'
|
'
antialiased
'
|
'
none
'
|
'
auto
'
>
(
Settings
.
FONT_ALIASING
);
if
(
this
.
fontAliasing
===
aliasing
)
{
return
;
}
...
...
@@ -682,6 +621,7 @@ export class Workbench extends Disposable implements IPartService {
this
.
fontAliasing
=
aliasing
;
// Remove all
const
fontAliasingValues
:
(
typeof
aliasing
)[]
=
[
'
antialiased
'
,
'
none
'
,
'
auto
'
];
removeClasses
(
this
.
workbench
,
...
fontAliasingValues
.
map
(
value
=>
`monaco-font-aliasing-
${
value
}
`
));
// Add specific
...
...
@@ -882,19 +822,6 @@ export class Workbench extends Disposable implements IPartService {
private
saveState
(
e
:
IWillSaveStateEvent
):
void
{
// Zen Mode
if
(
this
.
state
.
zenMode
.
active
)
{
this
.
storageService
.
store
(
State
.
ZEN_MODE_ENABLED
,
true
,
StorageScope
.
WORKSPACE
);
}
else
{
this
.
storageService
.
remove
(
State
.
ZEN_MODE_ENABLED
,
StorageScope
.
WORKSPACE
);
}
if
(
e
.
reason
===
WillSaveStateReason
.
SHUTDOWN
&&
this
.
state
.
zenMode
.
active
)
{
if
(
!
this
.
configurationService
.
getValue
(
Settings
.
ZEN_MODE_RESTORE
))
{
this
.
toggleZenMode
(
true
);
// We will not restore zen mode, need to clear all zen mode state changes
}
}
// Font info
saveFontInfo
(
this
.
storageService
);
}
...
...
@@ -922,7 +849,9 @@ export class Workbench extends Disposable implements IPartService {
private
editorPartView
:
View
;
private
statusBarPartView
:
View
;
private
state
=
{
private
readonly
state
=
{
fullscreen
:
false
,
menuBar
:
{
visibility
:
undefined
as
MenuBarVisibility
,
toggled
:
false
...
...
@@ -969,7 +898,67 @@ export class Workbench extends Disposable implements IPartService {
}
};
private
onDidUpdateConfiguration
(
skipLayout
?:
boolean
):
void
{
private
registerLayoutListeners
():
void
{
// Storage
this
.
_register
(
this
.
storageService
.
onWillSaveState
(
e
=>
this
.
saveLayoutState
(
e
)));
// Restore editor if hidden and it changes
this
.
_register
(
this
.
editorService
.
onDidVisibleEditorsChange
(()
=>
this
.
setEditorHidden
(
false
)));
this
.
_register
(
this
.
editorPart
.
onDidActivateGroup
(()
=>
this
.
setEditorHidden
(
false
)));
// Configuration changes
this
.
_register
(
this
.
configurationService
.
onDidChangeConfiguration
(()
=>
this
.
doUpdateLayoutConfiguration
()));
// Fullscreen changes
this
.
_register
(
onDidChangeFullscreen
(()
=>
this
.
onFullscreenChanged
()));
// Group changes
this
.
_register
(
this
.
editorGroupService
.
onDidAddGroup
(()
=>
this
.
centerEditorLayout
(
this
.
state
.
editor
.
centered
)));
this
.
_register
(
this
.
editorGroupService
.
onDidRemoveGroup
(()
=>
this
.
centerEditorLayout
(
this
.
state
.
editor
.
centered
)));
// Prevent workbench from scrolling #55456
this
.
_register
(
addDisposableListener
(
this
.
workbench
,
EventType
.
SCROLL
,
()
=>
this
.
workbench
.
scrollTop
=
0
));
// Menubar visibility changes
if
((
isWindows
||
isLinux
)
&&
getTitleBarStyle
(
this
.
configurationService
,
this
.
environmentService
)
===
'
custom
'
)
{
this
.
_register
(
this
.
titlebarPart
.
onMenubarVisibilityChange
(
visible
=>
this
.
onMenubarToggled
(
visible
)));
}
}
private
onMenubarToggled
(
visible
:
boolean
)
{
if
(
visible
!==
this
.
state
.
menuBar
.
toggled
)
{
this
.
state
.
menuBar
.
toggled
=
visible
;
if
(
this
.
state
.
fullscreen
&&
(
this
.
state
.
menuBar
.
visibility
===
'
toggle
'
||
this
.
state
.
menuBar
.
visibility
===
'
default
'
))
{
this
.
_onTitleBarVisibilityChange
.
fire
();
this
.
layout
();
}
}
}
private
onFullscreenChanged
():
void
{
this
.
state
.
fullscreen
=
isFullscreen
();
// Apply as CSS class
if
(
this
.
state
.
fullscreen
)
{
addClass
(
this
.
workbench
,
'
fullscreen
'
);
}
else
{
removeClass
(
this
.
workbench
,
'
fullscreen
'
);
if
(
this
.
state
.
zenMode
.
transitionedToFullScreen
&&
this
.
state
.
zenMode
.
active
)
{
this
.
toggleZenMode
();
}
}
// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
if
(
getTitleBarStyle
(
this
.
configurationService
,
this
.
environmentService
)
===
'
custom
'
)
{
this
.
_onTitleBarVisibilityChange
.
fire
();
this
.
layout
();
// handle title bar when fullscreen changes
}
}
private
doUpdateLayoutConfiguration
(
skipLayout
?:
boolean
):
void
{
// Sidebar Position
const
newSidebarPositionValue
=
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
SIDEBAR_POSITION
);
...
...
@@ -1001,7 +990,10 @@ export class Workbench extends Disposable implements IPartService {
this
.
setMenubarVisibility
(
newMenubarVisibility
,
!!
skipLayout
);
}
private
initState
():
void
{
private
initLayoutState
():
void
{
// Fullscreen
this
.
state
.
fullscreen
=
isFullscreen
();
// Menubar visibility
this
.
state
.
menuBar
.
visibility
=
this
.
configurationService
.
getValue
<
MenuBarVisibility
>
(
Settings
.
MENUBAR_VISIBLE
);
...
...
@@ -1010,7 +1002,7 @@ export class Workbench extends Disposable implements IPartService {
this
.
state
.
activityBar
.
hidden
=
!
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
ACTIVITYBAR_VISIBLE
);
// Sidebar visibility
this
.
state
.
sideBar
.
hidden
=
this
.
storageService
.
getBoolean
(
St
at
e
.
SIDEBAR_HIDDEN
,
StorageScope
.
WORKSPACE
,
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
);
this
.
state
.
sideBar
.
hidden
=
this
.
storageService
.
getBoolean
(
St
orag
e
.
SIDEBAR_HIDDEN
,
StorageScope
.
WORKSPACE
,
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
);
// Sidebar position
this
.
state
.
sideBar
.
position
=
(
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
SIDEBAR_POSITION
)
===
'
right
'
)
?
Position
.
RIGHT
:
Position
.
LEFT
;
...
...
@@ -1035,13 +1027,13 @@ export class Workbench extends Disposable implements IPartService {
}
// Editor centered layout
this
.
state
.
editor
.
restoreCentered
=
this
.
storageService
.
getBoolean
(
St
at
e
.
CENTERED_LAYOUT_ENABLED
,
StorageScope
.
WORKSPACE
,
false
);
this
.
state
.
editor
.
restoreCentered
=
this
.
storageService
.
getBoolean
(
St
orag
e
.
CENTERED_LAYOUT_ENABLED
,
StorageScope
.
WORKSPACE
,
false
);
// Editors to open
this
.
state
.
editor
.
editorsToOpen
=
this
.
resolveEditorsToOpen
();
// Panel visibility
this
.
state
.
panel
.
hidden
=
this
.
storageService
.
getBoolean
(
St
at
e
.
PANEL_HIDDEN
,
StorageScope
.
WORKSPACE
,
true
);
this
.
state
.
panel
.
hidden
=
this
.
storageService
.
getBoolean
(
St
orag
e
.
PANEL_HIDDEN
,
StorageScope
.
WORKSPACE
,
true
);
// Panel position
this
.
setPanelPositionFromStorageOrConfig
();
...
...
@@ -1067,7 +1059,7 @@ export class Workbench extends Disposable implements IPartService {
this
.
state
.
statusBar
.
hidden
=
!
statusBarVisible
;
// Zen mode enablement
const
wasZenActive
=
this
.
storageService
.
getBoolean
(
St
at
e
.
ZEN_MODE_ENABLED
,
StorageScope
.
WORKSPACE
,
false
);
const
wasZenActive
=
this
.
storageService
.
getBoolean
(
St
orag
e
.
ZEN_MODE_ENABLED
,
StorageScope
.
WORKSPACE
,
false
);
this
.
state
.
zenMode
.
restore
=
wasZenActive
&&
this
.
configurationService
.
getValue
(
Settings
.
ZEN_MODE_RESTORE
);
}
...
...
@@ -1154,7 +1146,7 @@ export class Workbench extends Disposable implements IPartService {
private
setPanelPositionFromStorageOrConfig
()
{
const
defaultPanelPosition
=
this
.
configurationService
.
getValue
<
string
>
(
Settings
.
PANEL_POSITION
);
const
panelPosition
=
this
.
storageService
.
get
(
St
at
e
.
PANEL_POSITION
,
StorageScope
.
WORKSPACE
,
defaultPanelPosition
);
const
panelPosition
=
this
.
storageService
.
get
(
St
orag
e
.
PANEL_POSITION
,
StorageScope
.
WORKSPACE
,
defaultPanelPosition
);
this
.
state
.
panel
.
position
=
(
panelPosition
===
'
right
'
)
?
Position
.
RIGHT
:
Position
.
BOTTOM
;
}
...
...
@@ -1198,7 +1190,7 @@ export class Workbench extends Disposable implements IPartService {
case
Parts
.
TITLEBAR_PART
:
if
(
getTitleBarStyle
(
this
.
configurationService
,
this
.
environmentService
)
===
'
native
'
)
{
return
false
;
}
else
if
(
!
isFullscreen
()
)
{
}
else
if
(
!
this
.
state
.
fullscreen
)
{
return
true
;
}
else
if
(
isMacintosh
)
{
return
false
;
...
...
@@ -1272,7 +1264,7 @@ export class Workbench extends Disposable implements IPartService {
hideLineNumbers
:
boolean
;
}
=
this
.
configurationService
.
getValue
(
'
zenMode
'
);
toggleFullScreen
=
!
isFullscreen
()
&&
config
.
fullScreen
;
toggleFullScreen
=
!
this
.
state
.
fullscreen
&&
config
.
fullScreen
;
this
.
state
.
zenMode
.
transitionedToFullScreen
=
restoring
?
config
.
fullScreen
:
toggleFullScreen
;
this
.
state
.
zenMode
.
transitionedToCenteredEditorLayout
=
!
this
.
isEditorLayoutCentered
()
&&
config
.
centerLayout
;
this
.
state
.
zenMode
.
wasSideBarVisible
=
this
.
isVisible
(
Parts
.
SIDEBAR_PART
);
...
...
@@ -1319,11 +1311,11 @@ export class Workbench extends Disposable implements IPartService {
setLineNumbers
(
this
.
configurationService
.
getValue
(
'
editor.lineNumbers
'
));
// Status bar and activity bar visibility come from settings -> update their visibility.
this
.
onDidUpdate
Configuration
(
true
);
this
.
doUpdateLayout
Configuration
(
true
);
this
.
editorGroupService
.
activeGroup
.
focus
();
toggleFullScreen
=
this
.
state
.
zenMode
.
transitionedToFullScreen
&&
isFullscreen
()
;
toggleFullScreen
=
this
.
state
.
zenMode
.
transitionedToFullScreen
&&
this
.
state
.
fullscreen
;
}
if
(
!
skipLayout
)
{
...
...
@@ -1512,7 +1504,7 @@ export class Workbench extends Disposable implements IPartService {
}
centerEditorLayout
(
active
:
boolean
,
skipLayout
?:
boolean
):
void
{
this
.
storageService
.
store
(
St
at
e
.
CENTERED_LAYOUT_ENABLED
,
active
,
StorageScope
.
WORKSPACE
);
this
.
storageService
.
store
(
St
orag
e
.
CENTERED_LAYOUT_ENABLED
,
active
,
StorageScope
.
WORKSPACE
);
this
.
state
.
editor
.
centered
=
active
;
let
smartActive
=
active
;
...
...
@@ -1617,9 +1609,9 @@ export class Workbench extends Disposable implements IPartService {
// Remember in settings
const
defaultHidden
=
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
;
if
(
hidden
!==
defaultHidden
)
{
this
.
storageService
.
store
(
St
at
e
.
SIDEBAR_HIDDEN
,
hidden
?
'
true
'
:
'
false
'
,
StorageScope
.
WORKSPACE
);
this
.
storageService
.
store
(
St
orag
e
.
SIDEBAR_HIDDEN
,
hidden
?
'
true
'
:
'
false
'
,
StorageScope
.
WORKSPACE
);
}
else
{
this
.
storageService
.
remove
(
St
at
e
.
SIDEBAR_HIDDEN
,
StorageScope
.
WORKSPACE
);
this
.
storageService
.
remove
(
St
orag
e
.
SIDEBAR_HIDDEN
,
StorageScope
.
WORKSPACE
);
}
// Layout
...
...
@@ -1659,9 +1651,9 @@ export class Workbench extends Disposable implements IPartService {
// Remember in settings
if
(
!
hidden
)
{
this
.
storageService
.
store
(
St
at
e
.
PANEL_HIDDEN
,
'
false
'
,
StorageScope
.
WORKSPACE
);
this
.
storageService
.
store
(
St
orag
e
.
PANEL_HIDDEN
,
'
false
'
,
StorageScope
.
WORKSPACE
);
}
else
{
this
.
storageService
.
remove
(
St
at
e
.
PANEL_HIDDEN
,
StorageScope
.
WORKSPACE
);
this
.
storageService
.
remove
(
St
orag
e
.
PANEL_HIDDEN
,
StorageScope
.
WORKSPACE
);
}
// The editor and panel cannot be hidden at the same time
...
...
@@ -1779,7 +1771,7 @@ export class Workbench extends Disposable implements IPartService {
const
newPositionValue
=
(
position
===
Position
.
BOTTOM
)
?
'
bottom
'
:
'
right
'
;
const
oldPositionValue
=
(
this
.
state
.
panel
.
position
===
Position
.
BOTTOM
)
?
'
bottom
'
:
'
right
'
;
this
.
state
.
panel
.
position
=
position
;
this
.
storageService
.
store
(
St
at
e
.
PANEL_POSITION
,
PositionToString
(
this
.
state
.
panel
.
position
).
toLowerCase
(),
StorageScope
.
WORKSPACE
);
this
.
storageService
.
store
(
St
orag
e
.
PANEL_POSITION
,
PositionToString
(
this
.
state
.
panel
.
position
).
toLowerCase
(),
StorageScope
.
WORKSPACE
);
// Adjust CSS
removeClass
(
this
.
panelPart
.
getContainer
(),
oldPositionValue
);
...
...
@@ -1817,5 +1809,21 @@ export class Workbench extends Disposable implements IPartService {
}
}
private
saveLayoutState
(
e
:
IWillSaveStateEvent
):
void
{
// Zen Mode
if
(
this
.
state
.
zenMode
.
active
)
{
this
.
storageService
.
store
(
Storage
.
ZEN_MODE_ENABLED
,
true
,
StorageScope
.
WORKSPACE
);
}
else
{
this
.
storageService
.
remove
(
Storage
.
ZEN_MODE_ENABLED
,
StorageScope
.
WORKSPACE
);
}
if
(
e
.
reason
===
WillSaveStateReason
.
SHUTDOWN
&&
this
.
state
.
zenMode
.
active
)
{
if
(
!
this
.
configurationService
.
getValue
(
Settings
.
ZEN_MODE_RESTORE
))
{
this
.
toggleZenMode
(
true
);
// We will not restore zen mode, need to clear all zen mode state changes
}
}
}
//#endregion
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录