【问题标题】:How to add checkbox toggle in github atom editor plugin如何在 github atom 编辑器插件中添加复选框切换
【发布时间】:2016-11-17 09:55:58
【问题描述】:

我想为现有插件添加一个功能,并想在插件的菜单中添加一个附加选项。

我希望该选项看起来像下面的“无标题”条目:

选项的行为类似于我们在 eclipse“自动构建”切换中的现有功能。

我希望用户在 Atom 插件菜单中看到此选项后,他就知道它是否已启用。

我们在 ATOM 视图中是否存在一些东西。所以,我可以寻找参考。

【问题讨论】:

  • 这通常在包设置菜单中完成,而不是在 Atom 菜单中。
  • @MattSchuchard,这是有道理的。您能否将此评论作为答案。 :)

标签: github atom-editor


【解决方案1】:

您可以通过多种方式将其添加到包设置菜单而不是 Atom 菜单中。

首先,有一种方法可以将其直接放入您的代码中。在我的包linter-ansible-linting 中考虑main.js 中的以下内容:

config: {
  ansibleLintExecutablePath: {
    title: 'Ansible-Lint Executable Path',
    type: 'string',
    description: 'Path to Ansible-Lint executable (e.g. /usr/bin/ansible-lint) if not in shell env path.',
    default: 'ansible-lint',
  },
  useRulesDirs: {
    title: 'Use non-default rules directories with Ansible-Lint.',
    type: 'boolean',
    default: false,
  },
  rulesDirs: {
    title: 'Rules Directories',
    type: 'array',
    description: 'Non-default rules directories to use with Ansible-Lint. (only if use non-default rules directories checked)',
    default: ['/usr/local/lib/python2.7/site-packages/ansiblelint/rules', '/usr/local/lib/python2.7/dist-packages/ansiblelint/rules'],
    items: {
      type: 'string'
    }
  }
}

你也可以把它放在package.json。考虑以下内容,Atom-Linter 组织内的其他人放入我维护的包中 linter-puppet-lint

"configSchema": {
  "executablePath": {
    "title": "Executable path",
    "type": "string",
    "description": "Path to puppet-lint executable",
    "default": "puppet-lint"
  },
  "automaticFix": {
    "title": "Attempt to automatically fix warnings and errors",
    "type": "boolean",
    "default": false
  },
}

这些将使配置设置在您的包的设置菜单中可用。您的具体设置将是 boolean,因此我建议您遵循该类型的格式。

buildAutomatically: {
  title: 'Build Automatically',
  type: 'boolean',
  default: false,
}

"buildAutomatically: {
  "title": "Build Automatically",
  "type": "boolean",
  "default": false
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 2018-09-11
    相关资源
    最近更新 更多