【问题标题】:How to generate files conditionally when Git is selected?选择Git时如何有条件地生成文件?
【发布时间】:2018-11-08 06:25:09
【问题描述】:

为了使用 Qt Creator 加快我的工作流程,我创建了一个 JSON 格式的自定义项目向导,作为其中的一部分,我添加了一个 Summary page

{
    "trDisplayName": "Project Management",
    "trShortTitle": "Summary",
    "typeId": "Summary"
}

File generator 中,我将两个文件,即.gitattributes.gitignore,复制到项目目录:

{
    "source": ".gitattributes",
    "target": "%{TargetPath}/.gitattributes"
},
{
    "source": ".gitignore",
    "target": "%{TargetPath}/.gitignore"
}

这样写,文件总是被复制,即使没有选择 Git 作为版本控制系统。我希望仅在需要时才复制文件。

摘要页面的文档说:

它将 VersionControl 设置为正在使用的版本控制系统的 ID

但没有添加有关 VersionControl 变量及其值的更多信息。

如何达到预期的效果?

【问题讨论】:

    标签: qt-creator wizard


    【解决方案1】:

    我会建议你以下解决方案:

    1. 通过转至为Wizard.Inspect 命令分配键盘快捷键

      工具 -> 选项 -> 环境 -> 键盘 -> 快捷键

    2. 启动自定义向导并导航到​​摘要页面

    3. 按下选择的快捷键

      这将打开一个窗口,其中列出了触发操作时向导中所有已定义的字段和变量。在那里你可以找到:

      Key            | Type    | Value | Eval
      VersionControl | QString | G.Git | G.Git
      
    4. 有了这些信息,像这样改变文件生成器代码:

      {
          "source": ".gitattributes",
          "target": "%{TargetPath}/.gitattributes",
          "condition": "%{JS: '%{VersionControl}' === 'G.Git'}"
      },
      {
          "source": ".gitignore",
          "target": "%{TargetPath}/.gitignore",
          "condition": "%{JS: '%{VersionControl}' === 'G.Git'}"
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 2018-03-21
      • 1970-01-01
      • 2020-06-01
      • 2012-10-24
      • 1970-01-01
      • 2019-04-20
      相关资源
      最近更新 更多