主要内容

addLabel

将标签附加到工程文件

说明

addLabel(proj,projectFiles,categoryName,labelName) 将指定类别中的指定标签附加到工程 proj 中的文件 projectFiles

示例

addLabel(proj,projectFiles,labelName) 将指定的标签附加到工程 proj 中的文件 projectFiles。仅当标签名称在工程中唯一时,才使用此语法。

addLabel(proj,projectFiles,categoryName,labelName,labelData) 将具有指定的文本或数值数据的标签附加到文件 projectFiles。您无法将标签数据添加到内置标签中。

示例

addLabel(fileObject,categoryName,labelName) 将指定类别中的指定标签附加到指定文件。

addLabel(fileObject,categoryName,labelName,labelData) 附加具有指定的文本或数值数据的标签。您无法将标签数据添加到内置标签,因为它们为只读。

示例

全部折叠

打开 Times Table App 工程。使用 currentProject 从当前加载的工程创建一个工程对象。

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

查询文件的现有标签。

filename = fullfile("source","timesTableGame.m");
myfile = findFiles(proj,filename,OutputFormat="ProjectFile");
existingLabel =  myfile.Labels
existingLabel = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'none'
            Data: []
            Name: "Design"
    CategoryName: "Classification"

将标签 "Artifact" 附加到 "Classification" 类别的文件上。

newLabel = addLabel(proj,myfile,"Classification","Artifact")
newLabel = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'none'
            Data: []
            Name: "Artifact"
    CategoryName: "Classification"

观察附加到 myfile 的标签。标签从 "Design" 更改为 "Artifact"

reviewLabel = myfile.Labels(1)
reviewLabel = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'none'
            Data: []
            Name: "Artifact"
    CategoryName: "Classification"

去除文件的新标签。文件现在没有标签。

removeLabel(proj,myfile,reviewLabel)
myfile
myfile = 

  ProjectFile with properties:

                   Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
                 Labels: [1×0 matlab.project.Label]
               Revision: "286043ae7ee557100902fb645a6c97eca5d50472"
    SourceControlStatus: Unmodified

"Classification" 类别中的标签 "Utility" 附加到工程中所有扩展名为 .m 的文件。

打开 Times Table App 工程。使用 currentProject 从当前加载的工程创建一个工程对象。

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

获取文件列表。

files = proj.Files;

将标签 "R2024b" 附加到工程中的所有文件。

addLabel(proj,files,"Classification","R2024b");

在工程的文件视图中,分类列对工程中的每个文件显示标签 R2024b

创建标签类别 "Review" 和标签 "To Review",然后将标签和标签数据附加到一个文件。您无法将标签数据添加到内置标签,因为它们为只读。

打开 Times Table App 工程。使用 currentProject 从当前加载的工程创建一个工程对象。

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

创建一个新类别 "Review"

createCategory(proj,"Review","char");

对于该新类别,创建标签 "To Review"

reviewCategory = findCategory(proj,"Review");
createLabel(reviewCategory,"To Review");

将标签 "To Review" 和标签数据字符向量附加到该文件。

filename = fullfile("source","timesTableGame.m");
newLabel = addLabel(proj,filename,"Review","To Review","Whole team design review")
newLabel = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'char'
            Data: 'Whole team design review'
            Name: "To Review"
    CategoryName: "Review"

您也可以使用 Data 属性设置或更改标签数据。

myfile = findFiles(proj,filename,OutputFormat="ProjectFile");
mylabel = myfile.Labels(2);
mylabel.Data = "Final review";

输入参数

全部折叠

工程,指定为 matlab.project.Project 对象。

要加标签的工程文件,指定为字符向量元胞数组、字符串数组或 ProjectFile 对象数组。文件必须在工程根文件夹中。

要添加标签的文件的对象,指定为 ProjectFile 对象。您可以通过检查工程的 Files 属性 (proj.Files) 来获取 ProjectFile 对象,或通过使用 findFiles 按名称查找文件。文件必须在工程中。

标签类别的名称,指定为字符向量或字符串标量。

要附加的标签的名称,指定为字符向量、字符串标量,或指定为 file.Label 属性或 findLabel 函数返回的 LabelDefinition 对象。您可以指定工程中尚不存在的新标签名称。

要附加到标签的数据,指定为字符向量、字符串标量或数值。数据类型取决于标签定义。使用 file.LabelfindLabel 获得标签以检查其 DataType 属性。

版本历史记录

在 R2019a 中推出

全部展开