Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
a4a9a5e6
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,发现更多精彩内容 >>
提交
a4a9a5e6
编写于
1月 22, 2021
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - use css variables instead of dynamically injected style sheets
上级
534d5b08
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
60 deletion
+61
-60
src/vs/platform/actions/browser/menuEntryActionViewItem.css
src/vs/platform/actions/browser/menuEntryActionViewItem.css
+13
-0
src/vs/platform/actions/browser/menuEntryActionViewItem.ts
src/vs/platform/actions/browser/menuEntryActionViewItem.ts
+48
-60
未找到文件。
src/vs/platform/actions/browser/menuEntryActionViewItem.css
0 → 100644
浏览文件 @
a4a9a5e6
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.monaco-action-bar
.action-item.menu-entry
.action-label
{
background-image
:
var
(
--menu-entry-icon-light
);
}
.vs-dark
.monaco-action-bar
.action-item.menu-entry
.action-label
,
.hc-black
.monaco-action-bar
.action-item.menu-entry
.action-label
{
background-image
:
var
(
--menu-entry-icon-dark
);
}
src/vs/platform/actions/browser/menuEntryActionViewItem.ts
浏览文件 @
a4a9a5e6
...
...
@@ -3,10 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
createCSSRule
,
asCSSUrl
,
ModifierKeyEmitter
}
from
'
vs/base/browser/dom
'
;
import
'
vs/css!./menuEntryActionViewItem
'
;
import
{
asCSSUrl
,
ModifierKeyEmitter
}
from
'
vs/base/browser/dom
'
;
import
{
domEvent
}
from
'
vs/base/browser/event
'
;
import
{
IAction
,
Separator
}
from
'
vs/base/common/actions
'
;
import
{
IdGenerator
}
from
'
vs/base/common/idGenerator
'
;
import
{
IDisposable
,
toDisposable
,
MutableDisposable
,
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
ICommandAction
,
IMenu
,
IMenuActionOptions
,
MenuItemAction
,
SubmenuItemAction
,
Icon
}
from
'
vs/platform/actions/common/actions
'
;
...
...
@@ -65,10 +65,6 @@ function fillInActions(groups: ReadonlyArray<[string, ReadonlyArray<MenuItemActi
}
}
const
ids
=
new
IdGenerator
(
'
menu-item-action-item-icon-
'
);
const
ICON_PATH_TO_CSS_RULES
=
new
Map
<
string
/* path*/
,
string
/* CSS rule */
>
();
export
class
MenuEntryActionViewItem
extends
ActionViewItem
{
private
_wantsAltCommand
:
boolean
=
false
;
...
...
@@ -84,7 +80,7 @@ export class MenuEntryActionViewItem extends ActionViewItem {
this
.
_altKey
=
ModifierKeyEmitter
.
getInstance
();
}
protected
get
_commandAction
():
I
Action
{
protected
get
_commandAction
():
MenuItem
Action
{
return
this
.
_wantsAltCommand
&&
(
<
MenuItemAction
>
this
.
_action
).
alt
||
this
.
_action
;
}
...
...
@@ -92,12 +88,14 @@ export class MenuEntryActionViewItem extends ActionViewItem {
event
.
preventDefault
();
event
.
stopPropagation
();
this
.
actionRunner
.
run
(
this
.
_commandAction
,
this
.
_context
)
.
then
(
undefined
,
err
=>
this
.
_notificationService
.
error
(
err
));
this
.
actionRunner
.
run
(
this
.
_commandAction
,
this
.
_context
)
.
catch
(
err
=>
this
.
_notificationService
.
error
(
err
));
}
render
(
container
:
HTMLElement
):
void
{
super
.
render
(
container
);
container
.
classList
.
add
(
'
menu-entry
'
);
this
.
_updateItemClass
(
this
.
_action
.
item
);
...
...
@@ -166,46 +164,37 @@ export class MenuEntryActionViewItem extends ActionViewItem {
private
_updateItemClass
(
item
:
ICommandAction
):
void
{
this
.
_itemClassDispose
.
value
=
undefined
;
const
{
element
,
label
}
=
this
;
if
(
!
element
||
!
label
)
{
return
;
}
const
icon
=
this
.
_commandAction
.
checked
&&
(
item
.
toggled
as
{
icon
?:
Icon
})?.
icon
?
(
item
.
toggled
as
{
icon
:
Icon
}).
icon
:
item
.
icon
;
if
(
!
icon
)
{
return
;
}
if
(
ThemeIcon
.
isThemeIcon
(
icon
))
{
// theme icons
const
iconClass
=
ThemeIcon
.
asClassName
(
icon
);
if
(
this
.
label
&&
iconClass
)
{
this
.
label
.
classList
.
add
(...
iconClass
.
split
(
'
'
));
this
.
_itemClassDispose
.
value
=
toDisposable
(()
=>
{
if
(
this
.
label
)
{
this
.
label
.
classList
.
remove
(...
iconClass
.
split
(
'
'
));
}
});
}
}
else
if
(
icon
)
{
// icon path
let
iconClass
:
string
;
if
(
icon
.
dark
?.
scheme
)
{
label
.
classList
.
add
(...
iconClass
.
split
(
'
'
));
this
.
_itemClassDispose
.
value
=
toDisposable
(()
=>
{
label
.
classList
.
remove
(...
iconClass
.
split
(
'
'
));
});
const
iconPathMapKey
=
icon
.
dark
.
toString
();
if
(
ICON_PATH_TO_CSS_RULES
.
has
(
iconPathMapKey
))
{
iconClass
=
ICON_PATH_TO_CSS_RULES
.
get
(
iconPathMapKey
)
!
;
}
else
{
iconClass
=
ids
.
nextId
();
createCSSRule
(
`.icon.
${
iconClass
}
`
,
`background-image:
${
asCSSUrl
(
icon
.
light
||
icon
.
dark
)}
`
);
createCSSRule
(
`.vs-dark .icon.
${
iconClass
}
, .hc-black .icon.
${
iconClass
}
`
,
`background-image:
${
asCSSUrl
(
icon
.
dark
)}
`
);
ICON_PATH_TO_CSS_RULES
.
set
(
iconPathMapKey
,
iconClass
);
}
if
(
this
.
label
)
{
this
.
label
.
classList
.
add
(
'
icon
'
,
...
iconClass
.
split
(
'
'
));
this
.
_itemClassDispose
.
value
=
toDisposable
(()
=>
{
if
(
this
.
label
)
{
this
.
label
.
classList
.
remove
(
'
icon
'
,
...
iconClass
.
split
(
'
'
));
}
});
}
}
else
{
// icon path/url
if
(
icon
.
light
)
{
label
.
style
.
setProperty
(
'
--menu-entry-icon-light
'
,
asCSSUrl
(
icon
.
light
));
}
if
(
icon
.
dark
)
{
label
.
style
.
setProperty
(
'
--menu-entry-icon-dark
'
,
asCSSUrl
(
icon
.
dark
));
}
this
.
_itemClassDispose
.
value
=
toDisposable
(()
=>
{
label
.
style
.
removeProperty
(
'
--menu-entry-icon-light
'
);
label
.
style
.
removeProperty
(
'
--menu-entry-icon-dark
'
);
});
}
}
}
...
...
@@ -216,26 +205,25 @@ export class SubmenuEntryActionViewItem extends DropdownMenuActionViewItem {
action
:
SubmenuItemAction
,
@
IContextMenuService
contextMenuService
:
IContextMenuService
)
{
let
classNames
:
string
|
string
[]
|
undefined
;
if
(
action
.
item
.
icon
)
{
if
(
ThemeIcon
.
isThemeIcon
(
action
.
item
.
icon
))
{
classNames
=
ThemeIcon
.
asClassName
(
action
.
item
.
icon
)
!
;
}
else
if
(
action
.
item
.
icon
.
dark
?.
scheme
)
{
const
iconPathMapKey
=
action
.
item
.
icon
.
dark
.
toString
();
if
(
ICON_PATH_TO_CSS_RULES
.
has
(
iconPathMapKey
))
{
classNames
=
[
'
icon
'
,
ICON_PATH_TO_CSS_RULES
.
get
(
iconPathMapKey
)
!
];
}
else
{
const
className
=
ids
.
nextId
();
classNames
=
[
'
icon
'
,
className
];
createCSSRule
(
`.icon.
${
className
}
`
,
`background-image:
${
asCSSUrl
(
action
.
item
.
icon
.
light
||
action
.
item
.
icon
.
dark
)}
`
);
createCSSRule
(
`.vs-dark .icon.
${
className
}
, .hc-black .icon.
${
className
}
`
,
`background-image:
${
asCSSUrl
(
action
.
item
.
icon
.
dark
)}
`
);
ICON_PATH_TO_CSS_RULES
.
set
(
iconPathMapKey
,
className
);
super
(
action
,
action
.
actions
,
contextMenuService
,
{
menuAsChild
:
true
,
classNames
:
ThemeIcon
.
isThemeIcon
(
action
.
item
.
icon
)
?
ThemeIcon
.
asClassName
(
action
.
item
.
icon
)
:
undefined
,
});
}
render
(
container
:
HTMLElement
):
void
{
super
.
render
(
container
);
if
(
this
.
element
)
{
container
.
classList
.
add
(
'
menu-entry
'
);
const
{
icon
}
=
(
<
SubmenuItemAction
>
this
.
_action
).
item
;
if
(
icon
&&
!
ThemeIcon
.
isThemeIcon
(
icon
))
{
if
(
icon
.
light
)
{
this
.
element
.
style
.
setProperty
(
'
--menu-entry-icon-light
'
,
asCSSUrl
(
icon
.
light
));
}
if
(
icon
.
dark
)
{
this
.
element
.
style
.
setProperty
(
'
--menu-entry-icon-dark
'
,
asCSSUrl
(
icon
.
dark
));
}
}
}
super
(
action
,
action
.
actions
,
contextMenuService
,
{
classNames
:
classNames
,
menuAsChild
:
true
});
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录