2010年8月20日金曜日

【COCOA】NSOpenPanel クラス

概要
COCOAプログラムでファイルを選択するパネルを表示するのに使う.
NSSavePanelの継承.SnowLeopard以降ではNSSavePanelの使用を推奨しているようです.




タスク
パネルを作成
+ openPanel


パネルの設定
- allowMultipleSelection
- setAllowsMultipleSelection:
- canChooseFiles
- setCanChooseFiles:
- canChooseDirectories
- setCanChooseDirectories:
- resolvesAliases
- setResolvesAliases:


パネルの実行

– beginForDirectory:file:types:modelessDelegate:didEndSelector:contextInfo:
– beginSheetForDirectory:file:types:modalForWindow:modalDelegate:didEndSelector:contextInfo:
– runModalForDirectory:file:types:
– runModalForTypes:




クラス・メソッド


+ (NSOpenPanel*) openPanel
パネルを開き,初期化されたNSOpenPanel型のオブジェクトを返す.


- (BOOL) allowMultipleSelection
開いたパネルのプロパティが,複数ファイルの選択を許可しているか否か BOOL型の変数で返す.


- (void)setAllowsMultipleSelection:(BOOL)flag
パネルに複数ファイルの選択の設定をする.
YESを渡した場合は許可,NOを渡すと禁止する.



- (BOOL) canChooseFiles
開いたパネルのプロパティが,ファイルの選択を許可しているか否か BOOL型の変数で返す.

- (void) setCanChooseFiles:(BOOL)flag
パネルにファイルの選択の設定をする.
YESを渡した場合は許可,NOを渡すと禁止する.


- (BOOL) canChooseDirectories
開いたパネルのプロパティが,ディレクトリの選択を許可しているか否か BOOL型の変数で返す.


- (void) setCanChooseDirectories:(BOOL) flag
パネルにディレクトリの選択の設定をする.
YESを渡した場合は許可,NOを渡すと禁止する.

- (BOOL) resolvesAliases
開いたパネルのプロパティが,エリアスの選択を許可しているか否か BOOL型の変数で返す.


- (void) setResolvesAliases:(BOOL) flag
パネルにエリアスの選択の設定をする.
YESを渡した場合は許可,NOを渡すと禁止する.

- (void) beginForDirectory: (NSString *) absoluteDirectoryPath file: (NSString *) filename types: (NSArray *) fileTypes modelessDelegate: (id) modelessDelegate didEndSelector: (SEL) didEndSelector contextInfo: (void *) contextInfo
パネルを表示する
absoluteDirectoryPath一番初めに表示するディレクトリの絶対パス.nilを指定すると前回操作したディレクトリが表示される.

filenameabsoluteDirectoryPathで設定したディレクトリ内の特定のファイルを予め選択させておくときに,そのファイル名を設定.nilを設定すると何も選択されていない状態から始まる.

fileTypes:選択できるファイルタイプを設定.nilを設定すると全てのファイルが選択可能になる.

modelessDelegate:処理の委譲の設定.パネルが閉じられるまで一時的に処理の委譲をする.

didEndSelector:パネルが閉じられる前にセッションが修了した際にmodelessDelegateで設定された委譲先に渡されるメッセージを設定する.

contexInfo: