00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "lldirpicker.h"
00035
00036
00037 #include "llworld.h"
00038 #include "llviewerwindow.h"
00039 #include "llkeyboard.h"
00040 #include "lldir.h"
00041 #include "llframetimer.h"
00042
00043 #if LL_LINUX
00044 # include "llfilepicker.h"
00045 #endif
00046
00047
00048
00049
00050
00051 LLDirPicker LLDirPicker::sInstance;
00052
00053 #if LL_WINDOWS
00054 #include <shlobj.h>
00055 #endif
00056
00057
00058
00059
00060 #if LL_WINDOWS
00061
00062 LLDirPicker::LLDirPicker()
00063 {
00064 }
00065
00066 LLDirPicker::~LLDirPicker()
00067 {
00068
00069 }
00070
00071 BOOL LLDirPicker::getDir(LLString* filename)
00072 {
00073 if( mLocked )
00074 {
00075 return FALSE;
00076 }
00077 BOOL success = FALSE;
00078
00079
00080 send_agent_pause();
00081
00082 BROWSEINFO bi;
00083 memset(&bi, 0, sizeof(bi));
00084
00085 bi.ulFlags = BIF_USENEWUI;
00086 bi.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
00087 bi.lpszTitle = NULL;
00088
00089 ::OleInitialize(NULL);
00090
00091 LPITEMIDLIST pIDL = ::SHBrowseForFolder(&bi);
00092
00093 if(pIDL != NULL)
00094 {
00095 WCHAR buffer[_MAX_PATH] = {'\0'};
00096
00097 if(::SHGetPathFromIDList(pIDL, buffer) != 0)
00098 {
00099
00100
00101 mDir = utf16str_to_utf8str(llutf16string(buffer));
00102 success = TRUE;
00103 }
00104
00105
00106 CoTaskMemFree(pIDL);
00107 }
00108
00109 ::OleUninitialize();
00110
00111 send_agent_resume();
00112
00113
00114 LLFrameTimer::updateFrameTime();
00115 return success;
00116 }
00117
00118 LLString LLDirPicker::getDirName()
00119 {
00120 return mDir;
00121 }
00122
00124 #elif LL_DARWIN
00125
00126 LLDirPicker::LLDirPicker()
00127 {
00128 reset();
00129
00130 memset(&mNavOptions, 0, sizeof(mNavOptions));
00131 OSStatus error = NavGetDefaultDialogCreationOptions(&mNavOptions);
00132 if (error == noErr)
00133 {
00134 mNavOptions.modality = kWindowModalityAppModal;
00135 }
00136 }
00137
00138 LLDirPicker::~LLDirPicker()
00139 {
00140
00141 }
00142
00143
00144 pascal void LLDirPicker::doNavCallbackEvent(NavEventCallbackMessage callBackSelector,
00145 NavCBRecPtr callBackParms, void* callBackUD)
00146 {
00147 switch(callBackSelector)
00148 {
00149 case kNavCBStart:
00150 {
00151 if (!sInstance.mFileName) break;
00152
00153 OSStatus error = noErr;
00154 AEDesc theLocation = {typeNull, NULL};
00155 FSSpec outFSSpec;
00156
00157
00158 FSRef myFSRef;
00159
00160 const char* filename=sInstance.mFileName->c_str();
00161
00162 error = FSPathMakeRef ((UInt8*)filename, &myFSRef, NULL);
00163
00164 if (error != noErr) break;
00165
00166 error = FSGetCatalogInfo (&myFSRef, kFSCatInfoNone, NULL, NULL, &outFSSpec, NULL);
00167
00168 if (error != noErr) break;
00169
00170 error = AECreateDesc(typeFSS, &outFSSpec, sizeof(FSSpec), &theLocation);
00171
00172 if (error != noErr) break;
00173
00174 error = NavCustomControl(callBackParms->context,
00175 kNavCtlSetLocation, (void*)&theLocation);
00176
00177 }
00178 }
00179 }
00180
00181 OSStatus LLDirPicker::doNavChooseDialog()
00182 {
00183 OSStatus error = noErr;
00184 NavDialogRef navRef = NULL;
00185 NavReplyRecord navReply;
00186
00187 memset(&navReply, 0, sizeof(navReply));
00188
00189
00190
00191
00192
00193 error = NavCreateChooseFolderDialog(&mNavOptions, &doNavCallbackEvent, NULL, NULL, &navRef);
00194
00195 gViewerWindow->mWindow->beforeDialog();
00196
00197 if (error == noErr)
00198 error = NavDialogRun(navRef);
00199
00200 gViewerWindow->mWindow->afterDialog();
00201
00202 if (error == noErr)
00203 error = NavDialogGetReply(navRef, &navReply);
00204
00205 if (navRef)
00206 NavDialogDispose(navRef);
00207
00208 if (error == noErr && navReply.validRecord)
00209 {
00210 FSRef fsRef;
00211 AEKeyword theAEKeyword;
00212 DescType typeCode;
00213 Size actualSize = 0;
00214 char path[LL_MAX_PATH];
00215
00216 memset(&fsRef, 0, sizeof(fsRef));
00217 error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize);
00218
00219 if (error == noErr)
00220 error = FSRefMakePath(&fsRef, (UInt8*) path, sizeof(path));
00221
00222 if (error == noErr)
00223 mDir = path;
00224 }
00225
00226 return error;
00227 }
00228
00229 BOOL LLDirPicker::getDir(LLString* filename)
00230 {
00231 if( mLocked ) return FALSE;
00232 BOOL success = FALSE;
00233 OSStatus error = noErr;
00234
00235 mFileName = filename;
00236
00237
00238
00239
00240 send_agent_pause();
00241 {
00242 error = doNavChooseDialog();
00243 }
00244 send_agent_resume();
00245 if (error == noErr)
00246 {
00247 if (mDir.length() > 0)
00248 success = true;
00249 }
00250
00251
00252 LLFrameTimer::updateFrameTime();
00253 return success;
00254 }
00255
00256 LLString LLDirPicker::getDirName()
00257 {
00258 return mDir;
00259 }
00260
00261 void LLDirPicker::reset()
00262 {
00263 mLocked = FALSE;
00264 mDir = NULL;
00265 }
00266
00267 #elif LL_LINUX
00268
00269 LLDirPicker::LLDirPicker()
00270 {
00271 mFilePicker = new LLFilePicker();
00272 reset();
00273 }
00274
00275 LLDirPicker::~LLDirPicker()
00276 {
00277 delete mFilePicker;
00278 }
00279
00280
00281 void LLDirPicker::reset()
00282 {
00283 if (mFilePicker)
00284 mFilePicker->reset();
00285 }
00286
00287 BOOL LLDirPicker::getDir(LLString* filename)
00288 {
00289 reset();
00290 if (mFilePicker)
00291 {
00292 GtkWindow* picker = mFilePicker->buildFilePicker(false, true,
00293 "dirpicker");
00294
00295 if (picker)
00296 {
00297 gtk_window_set_title(GTK_WINDOW(picker), "Choose Directory");
00298 gtk_widget_show_all(GTK_WIDGET(picker));
00299 gtk_main();
00300 return (NULL != mFilePicker->getFirstFile());
00301 }
00302 }
00303 return FALSE;
00304 }
00305
00306 LLString LLDirPicker::getDirName()
00307 {
00308 if (mFilePicker)
00309 {
00310 const char* name = mFilePicker->getFirstFile();
00311 if (name)
00312 return name;
00313 }
00314 return "";
00315 }
00316
00317 #else // not implemented
00318
00319 LLDirPicker::LLDirPicker()
00320 {
00321 reset();
00322 }
00323
00324 LLDirPicker::~LLDirPicker()
00325 {
00326 }
00327
00328
00329 void LLDirPicker::reset()
00330 {
00331 }
00332
00333 BOOL LLDirPicker::getDir(LLString* filename)
00334 {
00335 return FALSE;
00336 }
00337
00338 LLString LLDirPicker::getDirName()
00339 {
00340 return "";
00341 }
00342
00343 #endif