跳到正文
cccskills
免费在 GitHub 公开

context-menu

Guide for creating and displaying context menus in Wave Terminal. Use when implementing right-click menus, adding context menu items, creating submenus, or handling menu interactions with checkboxes and separators.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md3.8 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Context Menu Quick Reference

This guide provides a quick overview of how to create and display a context menu using our system.


ContextMenuItem Type

Define each menu item using the ContextMenuItem type:

type ContextMenuItem = {
  label?: string;
  type?: "separator" | "normal" | "submenu" | "checkbox" | "radio";
  role?: string; // Electron role (optional)
  click?: () => void; // Callback for item selection (not needed if role is set)
  submenu?: ContextMenuItem[]; // For nested menus
  checked?: boolean; // For checkbox or radio items
  visible?: boolean;
  enabled?: boolean;
  sublabel?: string;
};

Import and Show the Menu

Import the context menu module:

import { ContextMenuModel } from "@/app/store/contextmenu";

To display the context menu, call:

ContextMenuModel.getInstance().showContextMenu(menu, event);
  • menu: An array of ContextMenuItem.
  • event: The mouse event that triggered the context menu (typically from an onContextMenu handler).

Basic Example

A simple context menu with a separator:

const menu: ContextMenuItem[] = [
  {
    label: "New File",
    click: () => {
      /* create a new file */
    },
  },
  {
    label: "New Folder",
    click: () => {
      /* create a new folder */
    },
  },
  { type: "separator" },
  {
    label: "Rename",
    click: () => {
      /* rename item */
    },
  },
];

ContextMenuModel.getInstance().showContextMenu(menu, e);

Example with Submenu and Checkboxes

Toggle settings using a submenu with checkbox items:

const isClearOnStart = true; // Example setting

const menu: ContextMenuItem[] = [
  {
    label: "Clear Output On Restart",
    submenu: [
      {
        label: "On",
        type: "checkbox",
        checked: isClearOnStart,
        click: () => {
          // Set the config to enable clear on restart
        },
      },
      {
        label: "Off",
        type: "checkbox",
        checked: !isClearOnStart,
        click: () => {
          // Set the config to disable clear on restart
        },
      },
    ],
  },
];

ContextMenuModel.getInstance().showContextMenu(menu, e);

Editing a Config File Example

Open a configuration file (e.g., widgets.json) in preview mode:

{
    label: "Edit widgets.json",
    click: () => {
        fireAndForget(async () => {
            const path = `${getApi().getConfigDir()}/widgets.json`;
            const blockDef: BlockDef = {
                meta: { view: "preview", file: path },
            };
            await createBlock(blockDef, false, true);
        });
    },
}

Summary

  • Menu Definition: Use the ContextMenuItem type.
  • Actions: Use click for actions; use submenu for nested options.
  • Separators: Use type: "separator" to group items.
  • Toggles: Use type: "checkbox" or "radio" with the checked property.
  • Displaying: Use ContextMenuModel.getInstance().showContextMenu(menu, event) to render the menu.

Common Use Cases

File/Folder Operations

Context menus are commonly used for file operations like creating, renaming, and deleting files or folders.

Settings Toggles

Use checkbox menu items to toggle settings on and off, with the checked property reflecting the current state.

Nested Options

Use submenu to organize related options hierarchically, keeping the top-level menu clean and organized.

Conditional Items

Use the visible and enabled properties to dynamically show or disable menu items based on the current state.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Guide for adding new configuration settings to Wave Terminal. Use when adding a new setting to the configuration system, implementing a new config key, or adding user-customizable settings.

中文简介正在准备中。当前显示原文说明。

mits-pl/wove422026年6月20日 更新

add-rpc

免费

Guide for adding new RPC calls to Wave Terminal. Use when implementing new RPC commands, adding server-client communication methods, or extending the RPC interface with new functionality.

中文简介正在准备中。当前显示原文说明。

mits-pl/wove422026年6月20日 更新

Guide for adding new wsh commands to Wave Terminal. Use when implementing new CLI commands, adding command-line functionality, or extending the wsh command interface.

中文简介正在准备中。当前显示原文说明。

mits-pl/wove422026年6月20日 更新

Guide for implementing a new view type in Wave Terminal. Use when creating a new view component, implementing the ViewModel interface, registering a new view type in BlockRegistry, or adding a new content type to display within blocks.

中文简介正在准备中。当前显示原文说明。

mits-pl/wove422026年6月20日 更新

Guide for adding new Electron APIs to Wave Terminal. Use when implementing new frontend-to-electron communications via preload/IPC.

中文简介正在准备中。当前显示原文说明。

mits-pl/wove422026年6月20日 更新

Search and order products online. Compares prices across Polish marketplaces (Allegro, Ceneo, Google Shopping), presents options in a comparison table, and assists with checkout. Handles the full flow: priority selection, research, comparison, cart, and checkout handoff. Triggers on: "order", "buy", "find product", "compare prices", "cheapest", "zamow", "kup", "znajdz produkt", "porownaj ceny", "najtaniej".

中文简介正在准备中。当前显示原文说明。

mits-pl/wove422026年6月20日 更新

查看 mits-pl 的全部技能

报告此技能的问题