Main Content

addLabel

プロジェクト ファイルにラベルを追加

説明

addLabel(file,categoryName,labelName) は、指定されたカテゴリの指定されたラベルを指定されたファイルに追加します。

addLabel(file,categoryName,labelName,labelData) は、指定されたテキストまたは数値データをもつラベルを追加します。組み込みのラベルは読み取り専用であるため、ラベル データを追加することはできません。

すべて折りたたむ

プロジェクト Times Table App を開きます。currentProject を使用して、現在読み込まれているプロジェクトからプロジェクト オブジェクトを作成します。

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

名前を指定してファイルを取得します。

myfile = findFile(proj,"source/timesTableGame.m")
myfile = 

  ProjectFile with properties:

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

ファイルの Labels プロパティを取得して、既存のラベルを表示します。

myfile.Labels
ans = 

  Label with properties:

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

ラベル "Artifact" をカテゴリ "Classification" のファイルに追加します。

addLabel(myfile,"Classification","Artifact")
ans = 

  Label with properties:

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

現在は、2 つのラベル (元のラベルと追加されたラベル) があります。追加されたラベルのみを表示するには、Labels プロパティにインデックスを付けます。

reviewlabel = myfile.Labels(1)
reviewlabel = 

  Label with properties:

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

ファイルから新規ラベルを削除します。現在、ファイルに付けられているラベルは 1 つのみです。

removeLabel(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;

各ファイルに対して作業を繰り返します。ファイル拡張子のみを取得するには、関数 fileparts を使用して最後の部分を取り出します。ファイルに .m という拡張子が含まれる場合、ラベル "Utility" を追加します。

for fileIndex = 1:numel(files)
   file = files(fileIndex);
   [~, ~, fileExtension] = fileparts(file.Path);
   if strcmp(fileExtension,".m")
       addLabel(file,"Classification","Utility");
   end
end

プロジェクトの [ファイル] ビューで、[Classification] 列に utilities フォルダーの各 .m ファイルに対してラベル "Utility" が表示されます。

ラベル カテゴリ "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");

名前を指定してファイルを取得します。

myfile = findFile(proj,"source/timesTableGame.m")
myfile = 

  ProjectFile with properties:

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

ファイルに "To Review" ラベル、およびラベル データの文字ベクトルを追加します。

addLabel(myfile,"Review","To Review","Whole team design review")
ans = 

  Label with properties:

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

プロジェクトの [ファイル] ビューで timesTableGame.m ファイルに対し、[Review] 列にラベル データとラベル "To Review" が表示されます。

あるいは、Data プロパティを使用してラベル データを設定または変更できます。

mylabel = myfile.Labels(1);
mylabel.Data = "Final review";

入力引数

すべて折りたたむ

ラベルを付けるファイル。ProjectFile オブジェクトとして指定します。ProjectFile オブジェクトを取得するには、プロジェクトの Files プロパティ (proj.Files) を調べるか、関数 findFile を使用して名前でファイルを検索します。ファイルはプロジェクト内になければなりません。

ラベルのカテゴリ名。文字ベクトルまたは string スカラーとして指定します。

追加するラベルの名前。文字ベクトル、string スカラー、または file.Label プロパティや関数 findLabel によって返される LabelDefinition オブジェクトとして指定します。プロジェクトに存在しない新規ラベル名を指定することができます。

ラベルに追加するデータ。文字ベクトル、string スカラー、または数値として指定します。データ型は、ラベルの定義によって異なります。その DataType プロパティを調べるには、file.Label または関数 findLabel を使用してラベルを取得します。

バージョン履歴

R2019a で導入