ページ

2008年9月13日土曜日

環境設定(3)

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク

動作確認ができたので一つづつ作り込んでいく。まずは一般のタブから。




- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *toolbar_item = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier] autorelease];

if ([itemIdentifier isEqualToString:TOOLBAR_GENERAL]) {
[toolbar_item setLabel:NSLocalizedString(@"General", @"")];
[toolbar_item setImage:[NSImage imageNamed:NSImageNamePreferencesGeneral]];
[toolbar_item setTarget:self];
[toolbar_item setAction:@selector(click:)];
} else {
toolbar_item = nil;
}

return toolbar_item;
}


文字列は多言語対応できるようにリソースに定義したものを使う。

初期状態はべた書き。
- (void)awakeFromNib
{
_toolbar = [[NSToolbar alloc] initWithIdentifier:PREFERENCE_TOOLBAR];
[_toolbar setDelegate:self];
[_window setToolbar:_toolbar];
[_toolbar setSelectedItemIdentifier:TOOLBAR_GENERAL];
[_window setTitle:NSLocalizedString(@"General", @"")];
}


Mail.app や Safari では選択したツールバーの名称をウィンドウのタイトルにしていたので、それに見習う。