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