Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f0dfae7c
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f0dfae7c
编写于
3月 17, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cache a theme to apply it fast on startup instead of waiting for extensions. fixes #22137
上级
bb3c3f0b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
94 addition
and
48 deletion
+94
-48
src/vs/workbench/services/themes/electron-browser/colorThemeData.ts
...kbench/services/themes/electron-browser/colorThemeData.ts
+33
-0
src/vs/workbench/services/themes/electron-browser/themeService.ts
...orkbench/services/themes/electron-browser/themeService.ts
+61
-48
未找到文件。
src/vs/workbench/services/themes/electron-browser/colorThemeData.ts
浏览文件 @
f0dfae7c
...
@@ -88,6 +88,23 @@ export class ColorThemeData implements IColorTheme {
...
@@ -88,6 +88,23 @@ export class ColorThemeData implements IColorTheme {
return
JSON
.
stringify
(
content
,
null
,
'
\t
'
);
return
JSON
.
stringify
(
content
,
null
,
'
\t
'
);
}
}
toStorageData
()
{
let
colorMapData
=
{};
for
(
let
key
in
this
.
colorMap
)
{
colorMapData
[
key
]
=
this
.
colorMap
[
key
].
toRGBAHex
(
true
);
}
return
JSON
.
stringify
({
id
:
this
.
id
,
label
:
this
.
label
,
settingsId
:
this
.
settingsId
,
selector
:
this
.
selector
,
tokenColors
:
this
.
tokenColors
,
isLoaded
:
true
,
extensionData
:
this
.
extensionData
,
colorMap
:
colorMapData
});
}
get
type
():
ThemeType
{
get
type
():
ThemeType
{
switch
(
this
.
getBaseThemeId
())
{
switch
(
this
.
getBaseThemeId
())
{
case
VS_LIGHT_THEME
:
return
'
light
'
;
case
VS_LIGHT_THEME
:
return
'
light
'
;
...
@@ -113,6 +130,22 @@ export class ColorThemeData implements IColorTheme {
...
@@ -113,6 +130,22 @@ export class ColorThemeData implements IColorTheme {
}
}
}
}
export
function
fromStorageData
(
input
:
string
):
ColorThemeData
{
let
data
=
JSON
.
parse
(
input
);
let
theme
=
new
ColorThemeData
();
for
(
let
key
in
data
)
{
if
(
key
!==
'
colorMap
'
)
{
theme
[
key
]
=
data
[
key
];
}
else
{
let
colorMapData
=
data
[
key
];
for
(
let
id
in
colorMapData
)
{
theme
.
colorMap
[
id
]
=
Color
.
fromHex
(
colorMapData
[
id
]);
}
}
}
return
theme
;
}
let
defaultThemeColors
:
{
[
baseTheme
:
string
]:
ITokenColorizationRule
[]
}
=
{
let
defaultThemeColors
:
{
[
baseTheme
:
string
]:
ITokenColorizationRule
[]
}
=
{
'
vs
'
:
[
'
vs
'
:
[
{
scope
:
'
token.info-token
'
,
settings
:
{
foreground
:
'
#316bcd
'
}
},
{
scope
:
'
token.info-token
'
,
settings
:
{
foreground
:
'
#316bcd
'
}
},
...
...
src/vs/workbench/services/themes/electron-browser/themeService.ts
浏览文件 @
f0dfae7c
...
@@ -26,8 +26,9 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
...
@@ -26,8 +26,9 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
ColorThemeData
}
from
'
./colorThemeData
'
;
import
{
ColorThemeData
,
fromStorageData
}
from
'
./colorThemeData
'
;
import
{
ITheme
,
Extensions
as
ThemingExtensions
,
IThemingRegistry
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
ITheme
,
Extensions
as
ThemingExtensions
,
IThemingRegistry
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
editorBackground
,
editorForeground
}
from
'
vs/platform/theme/common/colorRegistry
'
;
import
{
$
}
from
'
vs/base/browser/builder
'
;
import
{
$
}
from
'
vs/base/browser/builder
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
...
@@ -44,6 +45,8 @@ import { IDisposable } from 'vs/base/common/lifecycle';
...
@@ -44,6 +45,8 @@ import { IDisposable } from 'vs/base/common/lifecycle';
const
DEFAULT_THEME_ID
=
'
vs-dark vscode-theme-defaults-themes-dark_plus-json
'
;
const
DEFAULT_THEME_ID
=
'
vs-dark vscode-theme-defaults-themes-dark_plus-json
'
;
const
DEFAULT_THEME_SETTING_VALUE
=
'
Default Dark+
'
;
const
DEFAULT_THEME_SETTING_VALUE
=
'
Default Dark+
'
;
const
PERSISTED_THEME_STORAGE_KEY
=
'
colorThemeData
'
;
const
defaultBaseTheme
=
'
vs-dark
'
;
const
defaultBaseTheme
=
'
vs-dark
'
;
const
defaultThemeExtensionId
=
'
vscode-theme-defaults
'
;
const
defaultThemeExtensionId
=
'
vscode-theme-defaults
'
;
...
@@ -202,13 +205,30 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
...
@@ -202,13 +205,30 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this
.
container
=
container
;
this
.
container
=
container
;
this
.
knownColorThemes
=
[];
this
.
knownColorThemes
=
[];
this
.
onFileIconThemeChange
=
new
Emitter
<
IFileIconTheme
>
();
this
.
knownIconThemes
=
[];
this
.
onColorThemeChange
=
new
Emitter
<
IColorTheme
>
();
this
.
currentIconTheme
=
{
id
:
''
,
label
:
''
,
settingsId
:
null
,
isLoaded
:
false
,
hasFileIcons
:
false
,
hasFolderIcons
:
false
,
extensionData
:
null
};
let
persistedThemeData
=
this
.
storageService
.
get
(
PERSISTED_THEME_STORAGE_KEY
);
if
(
persistedThemeData
)
{
let
themeData
=
fromStorageData
(
persistedThemeData
);
this
.
updateDynamicCSSRules
(
themeData
);
this
.
applyTheme
(
themeData
,
null
,
true
);
}
else
{
// In order to avoid paint flashing for tokens, because
// In order to avoid paint flashing for tokens, because
// themes are loaded asynchronously, we need to initialize
// themes are loaded asynchronously, we need to initialize
// a color theme document with good defaults until the theme is loaded
// a color theme document with good defaults until the theme is loaded
let
isLightTheme
=
(
Array
.
prototype
.
indexOf
.
call
(
document
.
body
.
classList
,
'
vs
'
)
>=
0
);
let
isLightTheme
=
(
Array
.
prototype
.
indexOf
.
call
(
document
.
body
.
classList
,
'
vs
'
)
>=
0
);
let
foreground
=
isLightTheme
?
'
#000000
'
:
'
#D4D4D4
'
;
let
background
=
isLightTheme
?
'
#ffffff
'
:
'
#1E1E1E
'
;
let
initialTheme
=
new
ColorThemeData
();
let
initialTheme
=
new
ColorThemeData
();
initialTheme
.
id
=
isLightTheme
?
VS_LIGHT_THEME
:
VS_DARK_THEME
;
initialTheme
.
id
=
isLightTheme
?
VS_LIGHT_THEME
:
VS_DARK_THEME
;
...
@@ -218,24 +238,12 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
...
@@ -218,24 +238,12 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
initialTheme
.
isLoaded
=
false
;
initialTheme
.
isLoaded
=
false
;
initialTheme
.
tokenColors
=
[{
initialTheme
.
tokenColors
=
[{
settings
:
{
settings
:
{
foreground
:
foreground
,
foreground
:
initialTheme
.
getColor
(
editorForeground
).
toRGBAHex
()
,
background
:
background
background
:
initialTheme
.
getColor
(
editorBackground
).
toRGBAHex
()
}
}
}];
}];
this
.
currentColorTheme
=
initialTheme
;
this
.
currentColorTheme
=
initialTheme
;
}
this
.
onColorThemeChange
=
new
Emitter
<
IColorTheme
>
();
this
.
knownIconThemes
=
[];
this
.
currentIconTheme
=
{
id
:
''
,
label
:
''
,
settingsId
:
null
,
isLoaded
:
false
,
hasFileIcons
:
false
,
hasFolderIcons
:
false
,
extensionData
:
null
};
this
.
onFileIconThemeChange
=
new
Emitter
<
IFileIconTheme
>
();
themesExtPoint
.
setHandler
((
extensions
)
=>
{
themesExtPoint
.
setHandler
((
extensions
)
=>
{
for
(
let
ext
of
extensions
)
{
for
(
let
ext
of
extensions
)
{
...
@@ -381,33 +389,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
...
@@ -381,33 +389,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this
.
themingParticipantChangeListener
=
null
;
this
.
themingParticipantChangeListener
=
null
;
}
}
let
onApply
=
(
newTheme
:
ColorThemeData
)
=>
{
let
newThemeId
=
newTheme
.
id
;
if
(
this
.
container
)
{
if
(
this
.
currentColorTheme
)
{
$
(
this
.
container
).
removeClass
(
this
.
currentColorTheme
.
id
);
}
$
(
this
.
container
).
addClass
(
newThemeId
);
}
this
.
currentColorTheme
=
newTheme
;
this
.
themingParticipantChangeListener
=
themingRegistry
.
onThemingParticipantAdded
(
p
=>
this
.
updateDynamicCSSRules
(
this
.
currentColorTheme
));
this
.
sendTelemetry
(
newTheme
.
id
,
newTheme
.
extensionData
,
'
color
'
);
this
.
onColorThemeChange
.
fire
(
this
.
currentColorTheme
);
if
(
settingsTarget
!==
ConfigurationTarget
.
WORKSPACE
)
{
this
.
windowService
.
broadcast
({
channel
:
'
vscode:changeColorTheme
'
,
payload
:
newTheme
.
id
});
}
return
this
.
writeColorThemeConfiguration
(
settingsTarget
);
};
return
this
.
findThemeData
(
themeId
,
DEFAULT_THEME_ID
).
then
(
themeData
=>
{
return
this
.
findThemeData
(
themeId
,
DEFAULT_THEME_ID
).
then
(
themeData
=>
{
if
(
themeData
)
{
if
(
themeData
)
{
return
themeData
.
ensureLoaded
().
then
(
_
=>
{
return
themeData
.
ensureLoaded
().
then
(
_
=>
{
this
.
updateDynamicCSSRules
(
themeData
);
this
.
updateDynamicCSSRules
(
themeData
);
return
onApply
(
themeData
);
return
this
.
applyTheme
(
themeData
,
settingsTarget
);
},
error
=>
{
},
error
=>
{
return
TPromise
.
wrapError
(
nls
.
localize
(
'
error.cannotloadtheme
'
,
"
Unable to load {0}: {1}
"
,
themeData
.
path
,
error
.
message
));
return
TPromise
.
wrapError
(
nls
.
localize
(
'
error.cannotloadtheme
'
,
"
Unable to load {0}: {1}
"
,
themeData
.
path
,
error
.
message
));
});
});
...
@@ -431,6 +417,33 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
...
@@ -431,6 +417,33 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
_applyRules
(
cssRules
.
join
(
'
\n
'
),
colorThemeRulesClassName
);
_applyRules
(
cssRules
.
join
(
'
\n
'
),
colorThemeRulesClassName
);
}
}
private
applyTheme
(
newTheme
:
ColorThemeData
,
settingsTarget
:
ConfigurationTarget
,
silent
=
false
):
TPromise
<
IFileIconTheme
>
{
if
(
this
.
container
)
{
if
(
this
.
currentColorTheme
)
{
$
(
this
.
container
).
removeClass
(
this
.
currentColorTheme
.
id
);
}
$
(
this
.
container
).
addClass
(
newTheme
.
id
);
}
this
.
currentColorTheme
=
newTheme
;
this
.
themingParticipantChangeListener
=
themingRegistry
.
onThemingParticipantAdded
(
p
=>
this
.
updateDynamicCSSRules
(
this
.
currentColorTheme
));
if
(
silent
)
{
return
TPromise
.
as
(
null
);
}
this
.
sendTelemetry
(
newTheme
.
id
,
newTheme
.
extensionData
,
'
color
'
);
this
.
onColorThemeChange
.
fire
(
this
.
currentColorTheme
);
if
(
settingsTarget
!==
ConfigurationTarget
.
WORKSPACE
)
{
this
.
windowService
.
broadcast
({
channel
:
'
vscode:changeColorTheme
'
,
payload
:
newTheme
.
id
});
}
// remember theme data for a quick restore
this
.
storageService
.
store
(
PERSISTED_THEME_STORAGE_KEY
,
newTheme
.
toStorageData
());
return
this
.
writeColorThemeConfiguration
(
settingsTarget
);
};
private
writeColorThemeConfiguration
(
settingsTarget
:
ConfigurationTarget
):
TPromise
<
IFileIconTheme
>
{
private
writeColorThemeConfiguration
(
settingsTarget
:
ConfigurationTarget
):
TPromise
<
IFileIconTheme
>
{
if
(
!
types
.
isUndefinedOrNull
(
settingsTarget
))
{
if
(
!
types
.
isUndefinedOrNull
(
settingsTarget
))
{
return
this
.
configurationWriter
.
writeConfiguration
(
COLOR_THEME_SETTING
,
this
.
currentColorTheme
.
settingsId
,
settingsTarget
).
then
(
_
=>
this
.
currentColorTheme
);
return
this
.
configurationWriter
.
writeConfiguration
(
COLOR_THEME_SETTING
,
this
.
currentColorTheme
.
settingsId
,
settingsTarget
).
then
(
_
=>
this
.
currentColorTheme
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录