Skip to content

[Question] 编辑器右上角按钮菜单,如何控制按钮的enable disable #2144

Answered by erha19
767746649zyy asked this question in Q&A
Discussion options

You must be logged in to vote

@767746649zyy 如果想动态控制 EditorTitle 区域的菜单是否可用状态,可用通过注册时追加 enabledWhen 属性,与在 Command 中使用 isEnabled 区别的是,when 类型的参数会动态响应条件变化,但需要你自主注册条件,如,你可以直接通过使用 IContextKeyService 去注册自定义 ContextKey,伪代码如下:

@Autowired(IContextKeyService)
private readonly contextKeyService: IContextKeyService;

const key = contextKeyService.createKey<boolean>('customAction.isRunning', false);

// 更新
key.set(true);

注册伪代码:

  menuRegistry.registerMenuItem(MenuId.DebugBreakpointsContext, {
     ...
     enableWhen: `... && custom.isRunning`
  });

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@767746649zyy
Comment options

Answer selected by erha19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
💬 question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #2140 on December 30, 2022 06:03.