Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
58a0b8d5
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,发现更多精彩内容 >>
提交
58a0b8d5
编写于
3月 25, 2020
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#93332 Adopt and enable views visibility for sync
上级
53de9e0f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
85 addition
and
20 deletion
+85
-20
src/vs/workbench/browser/parts/views/views.ts
src/vs/workbench/browser/parts/views/views.ts
+85
-20
未找到文件。
src/vs/workbench/browser/parts/views/views.ts
浏览文件 @
58a0b8d5
...
...
@@ -7,7 +7,7 @@ import 'vs/css!./media/views';
import
{
Disposable
,
IDisposable
,
toDisposable
,
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
IViewDescriptorService
,
ViewContainer
,
IViewDescriptor
,
IViewContainersRegistry
,
Extensions
as
ViewExtensions
,
IView
,
ViewContainerLocation
,
IViewsService
,
IViewPaneContainer
,
getVisbileViewContextKey
}
from
'
vs/workbench/common/views
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IStorageService
,
StorageScope
,
IWorkspaceStorageChangeEvent
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IViewletService
}
from
'
vs/workbench/services/viewlet/browser/viewlet
'
;
import
{
ContextKeyExpr
,
IContextKey
,
IContextKeyService
,
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
...
...
@@ -34,6 +34,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import
{
IWorkbenchLayoutService
}
from
'
vs/workbench/services/layout/browser/layoutService
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
IProgressIndicator
}
from
'
vs/platform/progress/common/progress
'
;
import
{
IStorageKeysSyncRegistryService
}
from
'
vs/platform/userDataSync/common/storageKeys
'
;
export
interface
IViewState
{
visibleGlobal
:
boolean
|
undefined
;
...
...
@@ -101,30 +102,46 @@ export class ContributableViewsModel extends Disposable {
}
setVisible
(
id
:
string
,
visible
:
boolean
,
size
?:
number
):
void
{
const
{
visibleIndex
,
viewDescriptor
,
state
}
=
this
.
find
(
id
);
this
.
doSetVisible
([{
id
,
visible
,
size
}]);
}
if
(
!
viewDescriptor
.
canToggleVisibility
)
{
throw
new
Error
(
`Can't toggle this view's visibility`
)
;
}
protected
doSetVisible
(
viewDescriptors
:
{
id
:
string
,
visible
:
boolean
,
size
?:
number
}[]):
void
{
const
added
:
IAddedViewDescriptorRef
[]
=
[]
;
const
removed
:
IViewDescriptorRef
[]
=
[];
if
(
this
.
isViewDescriptorVisible
(
viewDescriptor
)
===
visible
)
{
return
;
}
for
(
const
{
id
,
visible
,
size
}
of
viewDescriptors
)
{
const
{
visibleIndex
,
viewDescriptor
,
state
}
=
this
.
find
(
id
);
if
(
viewDescriptor
.
workspace
)
{
state
.
visibleWorkspace
=
visible
;
}
else
{
state
.
visibleGlobal
=
visible
;
}
if
(
!
viewDescriptor
.
canToggleVisibility
)
{
throw
new
Error
(
`Can't toggle this view's visibility`
);
}
if
(
typeof
size
===
'
number
'
)
{
state
.
size
=
size
;
if
(
this
.
isViewDescriptorVisible
(
viewDescriptor
)
===
visible
)
{
return
;
}
if
(
viewDescriptor
.
workspace
)
{
state
.
visibleWorkspace
=
visible
;
}
else
{
state
.
visibleGlobal
=
visible
;
}
if
(
typeof
size
===
'
number
'
)
{
state
.
size
=
size
;
}
if
(
visible
)
{
added
.
push
({
index
:
visibleIndex
,
viewDescriptor
,
size
:
state
.
size
,
collapsed
:
!!
state
.
collapsed
});
}
else
{
removed
.
push
({
index
:
visibleIndex
,
viewDescriptor
});
}
}
if
(
visible
)
{
this
.
_onDidAdd
.
fire
([{
index
:
visibleIndex
,
viewDescriptor
,
size
:
state
.
size
,
collapsed
:
!!
state
.
collapsed
}]);
}
else
{
this
.
_onDidRemove
.
fire
([{
index
:
visibleIndex
,
viewDescriptor
}]);
if
(
added
.
length
)
{
this
.
_onDidAdd
.
fire
(
added
);
}
if
(
removed
.
length
)
{
this
.
_onDidRemove
.
fire
(
removed
);
}
}
...
...
@@ -318,6 +335,7 @@ export class PersistentContributableViewsModel extends ContributableViewsModel {
viewletStateStorageId
:
string
,
@
IViewDescriptorService
viewDescriptorService
:
IViewDescriptorService
,
@
IStorageService
storageService
:
IStorageService
,
@
IStorageKeysSyncRegistryService
storageKeysSyncRegistryService
:
IStorageKeysSyncRegistryService
)
{
const
globalViewsStateStorageId
=
`
${
viewletStateStorageId
}
.hidden`
;
const
viewStates
=
PersistentContributableViewsModel
.
loadViewsStates
(
viewletStateStorageId
,
globalViewsStateStorageId
,
storageService
);
...
...
@@ -334,6 +352,30 @@ export class PersistentContributableViewsModel extends ContributableViewsModel {
Event
.
map
(
this
.
onDidMove
,
({
from
,
to
})
=>
[
from
,
to
]),
Event
.
map
(
this
.
onDidChangeViewState
,
viewDescriptorRef
=>
[
viewDescriptorRef
]))
(
viewDescriptorRefs
=>
this
.
saveViewsStates
()));
storageKeysSyncRegistryService
.
registerStorageKey
({
key
:
this
.
globalViewsStateStorageId
,
version
:
1
});
this
.
_globalViewsStatesValue
=
this
.
getStoredGlobalViewsStatesValue
();
this
.
_register
(
this
.
storageService
.
onDidChangeStorage
(
e
=>
this
.
onDidStorageChange
(
e
)));
}
private
onDidStorageChange
(
e
:
IWorkspaceStorageChangeEvent
):
void
{
if
(
e
.
key
===
this
.
globalViewsStateStorageId
&&
e
.
scope
===
StorageScope
.
GLOBAL
&&
this
.
globalViewsStatesValue
!==
this
.
getStoredGlobalViewsStatesValue
()
/* This checks if current window changed the value or not */
)
{
this
.
_globalViewsStatesValue
=
undefined
;
const
storedViewsVisibilityStates
=
PersistentContributableViewsModel
.
loadGlobalViewsState
(
this
.
globalViewsStateStorageId
,
this
.
storageService
,
StorageScope
.
GLOBAL
);
const
changedViews
:
{
id
:
string
,
visible
:
boolean
}[]
=
[];
for
(
const
[
id
,
state
]
of
storedViewsVisibilityStates
)
{
const
viewState
=
this
.
viewStates
.
get
(
id
);
if
(
viewState
)
{
if
(
viewState
.
visibleGlobal
!==
!
state
.
isHidden
)
{
changedViews
.
push
({
id
,
visible
:
!
state
.
isHidden
});
}
}
}
if
(
changedViews
.
length
)
{
this
.
doSetVisible
(
changedViews
);
}
}
}
private
saveViewsStates
():
void
{
...
...
@@ -372,9 +414,32 @@ export class PersistentContributableViewsModel extends ContributableViewsModel {
order
:
!
viewDescriptor
.
workspace
&&
viewState
?
viewState
.
order
:
undefined
});
}
this
.
storageService
.
store
(
this
.
globalViewsStateStorageId
,
JSON
.
stringify
(
values
(
storedViewsVisibilityStates
)),
StorageScope
.
GLOBAL
);
this
.
globalViewsStatesValue
=
JSON
.
stringify
(
values
(
storedViewsVisibilityStates
)
);
}
private
_globalViewsStatesValue
:
string
|
undefined
;
private
get
globalViewsStatesValue
():
string
{
if
(
!
this
.
_globalViewsStatesValue
)
{
this
.
_globalViewsStatesValue
=
this
.
getStoredGlobalViewsStatesValue
();
}
return
this
.
_globalViewsStatesValue
;
}
private
set
globalViewsStatesValue
(
globalViewsStatesValue
:
string
)
{
if
(
this
.
globalViewsStatesValue
!==
globalViewsStatesValue
)
{
this
.
_globalViewsStatesValue
=
globalViewsStatesValue
;
this
.
setStoredGlobalViewsStatesValue
(
globalViewsStatesValue
);
}
}
private
getStoredGlobalViewsStatesValue
():
string
{
return
this
.
storageService
.
get
(
this
.
globalViewsStateStorageId
,
StorageScope
.
GLOBAL
,
'
[]
'
);
}
private
setStoredGlobalViewsStatesValue
(
value
:
string
):
void
{
this
.
storageService
.
store
(
this
.
globalViewsStateStorageId
,
value
,
StorageScope
.
GLOBAL
);
}
private
static
loadViewsStates
(
workspaceViewsStateStorageId
:
string
,
globalViewsStateStorageId
:
string
,
storageService
:
IStorageService
):
Map
<
string
,
IViewState
>
{
const
viewStates
=
new
Map
<
string
,
IViewState
>
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录