Finder の predicatesList を模倣したいと思います。特に、「その他」(ドイツ語で「Andere...」) メニュー エントリを含む LeftExpressions ポップアップは、ユーザーが選択できる検索述語のリストを含む NSSheet をポップアップするのが好きです。
私のアプローチは、いくつかの NSPredicateEditorRowTemplates と、「other...」という名前の leftExpression を持つ最後のカスタム rowTemplate を 1 つ作成することでした。
次に、templateViews メソッドをオーバーライドして、separatorItem を追加しました。
-(NSArray *)templateViews{
NSMutableArray * views = [[super templateViews] mutableCopy];
// I tried already to add here my custom menu entry, but if I add more templates my custom entry (and the separator line) is not fixed at the last index.
if (!isCustomMenuItemAdded) {
NSPopUpButton *leftButton = views[0];
// Add a menu separator
[[leftButton menu]insertItem:[NSMenuItem separatorItem] atIndex:[leftButton menu].itemArray.count-1];
}
return views;
}
カスタムの predicateEditor が正しく表示されるようになりましたが、最後のメニュー項目 'Other..' をクリックすると、ダミーの NSPredicateRowTemplate が表示されます。
rowTemplate クラスの -(id)copy メソッドをオーバーライドして改行を抑制しようとしましたが、それは私には奇妙に感じます。
-(id)copy{
return nil; // OK, now there is no new row, but this throws an internal exception
}
私の質問は次のとおりです。左側の式 popupButton にカスタム メニュー エントリを追加するより良い方法はありますか? PredicateEditor に新しい predicateTemplateRow が表示されないようにするにはどうすればよいですか?