API change of AIFilePicker.

Call AIFilePicker::create() instead of new AIFilePicker.
Renamed deleteMe() to kill() and bs_deleted to bs_killed.
Only default to auto destruct when created with create(true),
otherwise kill() has to be called explicitely.
This commit is contained in:
Aleric Inglewood
2011-05-18 03:52:15 +02:00
parent 4eb87268bd
commit e1fb1fa6b7
23 changed files with 63 additions and 57 deletions

View File

@@ -459,7 +459,7 @@ LocalAssetBrowser::~LocalAssetBrowser()
void LocalAssetBrowser::AddBitmap()
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_IMAGE, "", "image", true);
filepicker->run(boost::bind(&LocalAssetBrowser::AddBitmap_continued, filepicker));
}

View File

@@ -241,7 +241,7 @@ void LLFloaterBlacklist::saveToDisk()
//static
void LLFloaterBlacklist::onClickSave(void* user_data)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open("untitled.blacklist", FFSAVE_BLACKLIST);
filepicker->run(boost::bind(&LLFloaterBlacklist::onClickSave_continued, filepicker));
}
@@ -266,7 +266,7 @@ void LLFloaterBlacklist::onClickSave_continued(AIFilePicker* filepicker)
//static
void LLFloaterBlacklist::onClickLoad(void* user_data)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_BLACKLIST);
filepicker->run(boost::bind(&LLFloaterBlacklist::onClickLoad_continued, filepicker));
}

View File

@@ -1850,7 +1850,7 @@ void LLFloaterCustomize::setCurrentWearableType( EWearableType type )
// reX: new function
void LLFloaterCustomize::onBtnImport( void* userdata )
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_XML);
filepicker->run(boost::bind(&LLFloaterCustomize::onBtnImport_continued, filepicker));
}
@@ -1910,7 +1910,7 @@ void LLFloaterCustomize::onBtnImport_continued(AIFilePicker* filepicker)
// reX: new function
void LLFloaterCustomize::onBtnExport( void* userdata )
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open("", FFSAVE_XML);
filepicker->run(boost::bind(&LLFloaterCustomize::onBtnExport_continued, filepicker));
}

View File

@@ -1082,7 +1082,7 @@ void LLPanelFriends::onClickExport(void* user_data)
{
std::string agn;
gAgent.getName(agn);
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(agn + ".friendlist", FFSAVE_ALL);
filepicker->run(boost::bind(&LLPanelFriends::onClickExport_continued, user_data, filepicker));
}
@@ -1132,7 +1132,7 @@ bool LLPanelFriends::merging;
void LLPanelFriends::onClickImport(void* user_data)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open();
filepicker->run(boost::bind(&LLPanelFriends::onClickImport_filepicker_continued, filepicker));
}

View File

@@ -1325,7 +1325,7 @@ void LLPanelRegionTerrainInfo::onChangeSunHour(LLUICtrl* ctrl, void*)
void LLPanelRegionTerrainInfo::onClickDownloadRaw(void* data)
{
LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open("terrain.raw", FFSAVE_RAW);
filepicker->run(boost::bind(&LLPanelRegionTerrainInfo::onClickUploadRaw_continued, self, filepicker));
}
@@ -1350,7 +1350,7 @@ void LLPanelRegionTerrainInfo::onClickDownloadRaw_continued(AIFilePicker* filepi
void LLPanelRegionTerrainInfo::onClickUploadRaw(void* data)
{
LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_RAW);
filepicker->run(boost::bind(&LLPanelRegionTerrainInfo::onClickUploadRaw_continued, self, filepicker));
}

View File

@@ -234,7 +234,7 @@ void LLFloaterVFS::setEditEnabled(bool enabled)
void LLFloaterVFS::onClickAdd(void* user_data)
{
if(!user_data) return;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open();
filepicker->run(boost::bind(&LLFloaterVFS::onClickAdd_continued, user_data, filepicker));
}

View File

@@ -570,7 +570,7 @@ class LLLoadInvCacheFloater : public inventory_listener_t
{
LLInventoryModel* model = mPtr->getPanel()->getModel();
if(!model) return false;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_INVGZ, "", "invgz");
filepicker->run(boost::bind(&LLLoadInvCacheFloater::filepicker_callback, this, filepicker));
return true;

View File

@@ -357,7 +357,7 @@ void LLInventoryBackup::imageCallback(BOOL success,
return;
}
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(LLDir::getScrubbedFileName(item->getName()), getSaveFilter(item));
filepicker->run(boost::bind(&LLInventoryBackup::imageCallback_continued, src, filepicker));
}
@@ -421,7 +421,7 @@ void LLInventoryBackup::assetCallback(LLVFS *vfs,
// Write it back out...
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(LLDir::getScrubbedFileName(item->getName()), getSaveFilter(item));
filepicker->run(boost::bind(&LLInventoryBackup::assetCallback_continued, buffer, size, filepicker));
}

View File

@@ -1109,7 +1109,7 @@ void LLItemBridge::performAction(LLFolderView* folder, LLInventoryModel* model,
LLInventoryItem* item = model->getItem(mUUID);
if (item && item->getType() == LLAssetType::AT_TEXTURE)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_IMAGE, "", "image");
filepicker->run(boost::bind(&LLItemBridge::showFloaterImagePreview, item, filepicker));
}

View File

@@ -203,7 +203,7 @@ void LLPanelPick::initNewPick()
//Imports a new pick from an xml - RK
void LLPanelPick::importNewPick(void (*callback)(void*, bool), void* data)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_XML, "", "export");
filepicker->run(boost::bind(&LLPanelPick::importNewPick_continued, this, callback, data, filepicker));
}
@@ -244,7 +244,7 @@ void LLPanelPick::importNewPick_continued(void (*callback)(void*, bool), void* d
//Exports a pick to an XML - RK
void LLPanelPick::exportPick()
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open("", FFSAVE_XML, "", "export");
filepicker->run(boost::bind(&LLPanelPick::exportPick_continued, this, filepicker));
}

View File

@@ -392,7 +392,7 @@ void LLPreviewAnim::gotAssetForSave(LLVFS *vfs,
// Write it back out...
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(LLDir::getScrubbedFileName(self->getItem()->getName()) + ".animatn", FFSAVE_ANIMATN);
filepicker->run(boost::bind(&LLPreviewAnim::gotAssetForSave_continued, buffer, size, filepicker));
}

View File

@@ -720,7 +720,7 @@ void LLPreviewNotecard::saveAs()
default_filename = LLDir::getScrubbedFileName(item->getName()) + ".notecard";
}
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(default_filename, FFSAVE_NOTECARD);
filepicker->run(boost::bind(&LLPreviewNotecard::saveAs_continued, this, filepicker));
}

View File

@@ -1704,7 +1704,7 @@ void LLPreviewLSL::saveAs()
default_filename = LLDir::getScrubbedFileName(item->getName()) + ".lsl";
}
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(default_filename, FFSAVE_LSL);
filepicker->run(boost::bind(&LLPreviewLSL::saveAs_continued, this, filepicker));
}
@@ -2655,7 +2655,7 @@ void LLLiveLSLEditor::saveAs()
default_filename = LLDir::getScrubbedFileName(item->getName());
}
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(default_filename, FFSAVE_LSL);
filepicker->run(boost::bind(&LLLiveLSLEditor::saveAs_continued, this, filepicker));
}

View File

@@ -330,7 +330,7 @@ void LLPreviewSound::gotAssetForSave(LLVFS *vfs,
// Write it back out...
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(LLDir::getScrubbedFileName(self->getItem()->getName()) + ".ogg", FFSAVE_OGG);
filepicker->run(boost::bind(&LLPreviewSound::gotAssetForSave_continued, buffer, size, filepicker));
}

View File

@@ -381,7 +381,7 @@ void LLPreviewTexture::saveAs()
return;
const LLViewerInventoryItem* item = getItem() ;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(item ? LLDir::getScrubbedFileName(item->getName()) + ".tga" : LLStringUtil::null, FFSAVE_TGA, "", "image");
filepicker->run(boost::bind(&LLPreviewTexture::saveAs_continued, this, item, filepicker));
}

View File

@@ -1241,7 +1241,7 @@ void init_debug_world_menu(LLMenuGL* menu)
static void handle_export_menus_to_xml_continued(AIFilePicker* filepicker);
void handle_export_menus_to_xml(void*)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open("", FFSAVE_XML);
filepicker->run(boost::bind(&handle_export_menus_to_xml_continued, filepicker));
}
@@ -8519,7 +8519,7 @@ void handle_mesh_save_llm(void* data)
return;
}
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(*mesh_name, FFSAVE_ALL, default_path, "mesh_llm");
filepicker->run(boost::bind(&handle_mesh_save_llm_continued, data, filepicker));
}
@@ -8595,7 +8595,7 @@ void handle_mesh_save_current_obj(void* data)
std::string file_name = *mesh_name + "_current.obj";
std::string default_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER, "");
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(file_name, FFSAVE_ALL, default_path, "mesh_obj");
filepicker->run(boost::bind(&handle_mesh_save_current_obj_continued, data, filepicker));
}
@@ -8644,7 +8644,7 @@ void handle_mesh_save_obj(void* data)
std::string file_name = *mesh_name + ".obj";
std::string default_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER, "");
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(file_name, FFSAVE_ALL, default_path, "mesh_obj");
filepicker->run(boost::bind(&handle_mesh_save_obj_continued, data, filepicker));
}
@@ -8687,7 +8687,7 @@ void handle_mesh_load_obj(void* data)
return;
}
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_ALL, default_path, "mesh_obj");
filepicker->run(boost::bind(&handle_mesh_load_obj_continued, data, filepicker));
}
@@ -8737,7 +8737,7 @@ void handle_morph_save_obj(void* data)
std::string file_name = *mesh_name + "." + morph_name + ".obj";
std::string default_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER, "");
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(file_name, FFSAVE_ALL, default_path, "mesh_obj");
filepicker->run(boost::bind(&handle_morph_save_obj_continued, data, filepicker));
}
@@ -8782,7 +8782,7 @@ void handle_morph_load_obj(void* data)
llinfos << "Load morph OBJ " << morph_name << " of mesh " << *mesh_name <<llendl;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_ALL, default_path, "mesh_obj");
filepicker->run(boost::bind(&handle_morph_load_obj_continued, data, filepicker));
}
@@ -9091,7 +9091,7 @@ void handle_save_to_xml(void*)
LLStringUtil::replaceChar(default_name, ':', '_');
LLStringUtil::replaceChar(default_name, '"', '_');
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(default_name, FFSAVE_XML);
filepicker->run(boost::bind(&handle_save_to_xml_continued, frontmost, filepicker));
}
@@ -9108,7 +9108,7 @@ static void handle_save_to_xml_continued(LLFloater* frontmost, AIFilePicker* fil
static void handle_load_from_xml_continued(AIFilePicker* filepicker);
void handle_load_from_xml(void*)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_XML);
filepicker->run(boost::bind(&handle_load_from_xml_continued, filepicker));
}

View File

@@ -179,7 +179,7 @@ void AIFileUpload::start_filepicker(ELoadFilter filter, char const* context)
}
llassert(!mPicker);
mPicker = new AIFilePicker;
mPicker = AIFilePicker::create();
mPicker->open(filter, "", context);
mPicker->run(boost::bind(&AIFileUpload::filepicker_callback, this, filter));
}
@@ -370,7 +370,7 @@ class LLFileUploadBulk : public view_listener_t
else // cancel
return false;
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_ALL, "", "openfile", true);
filepicker->run(boost::bind(&LLFileUploadBulk::onConfirmBulkUploadTemp_continued, enabled, filepicker));
return true;
@@ -586,7 +586,7 @@ class LLFileQuit : public view_listener_t
static void handle_compress_image_continued(AIFilePicker* filepicker);
void handle_compress_image(void*)
{
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_IMAGE, "", "openfile", true);
filepicker->run(boost::bind(&handle_compress_image_continued, filepicker));
}

View File

@@ -341,7 +341,7 @@ void LLObjectBackup::exportObject()
mThisGroup.clear();
// Open the file save dialog
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open("", FFSAVE_XML);
filepicker->run(boost::bind(&LLObjectBackup::exportObject_continued, this, filepicker));
}
@@ -739,7 +739,7 @@ void LLObjectBackup::importObject(bool upload)
mRetexture = upload;
// Open the file open dialog
AIFilePicker* filepicker = new AIFilePicker;
AIFilePicker* filepicker = AIFilePicker::create();
filepicker->open(FFLOAD_XML, "", "import");
filepicker->run(boost::bind(&LLObjectBackup::importObject_continued, this, filepicker));

View File

@@ -4018,7 +4018,7 @@ void LLViewerWindow::saveImageNumbered(LLPointer<LLImageFormatted> image)
// AIFilePicker will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in.
// pick a directory in which to save
AIFilePicker* filepicker = new AIFilePicker; // Deleted in LLViewerWindow::saveImageNumbered_continued1
AIFilePicker* filepicker = AIFilePicker::create(); // Deleted in LLViewerWindow::saveImageNumbered_continued1
filepicker->open(proposed_name, pick_type, "", "snapshot");
filepicker->run(boost::bind(&LLViewerWindow::saveImageNumbered_continued1, this, image, extension, filepicker));
return;

View File

@@ -60,7 +60,7 @@ char const* AIFilePicker::state_str_impl(state_type run_state) const
return "UNKNOWN STATE";
}
AIFilePicker::AIFilePicker(void) : mPluginManager(NULL), mCanceled(false)
AIFilePicker::AIFilePicker(void) : mPluginManager(NULL), mAutoKill(false), mCanceled(false)
{
}
@@ -400,9 +400,12 @@ void AIFilePicker::finish_impl(void)
mPluginManager = NULL;
}
mFilter.clear(); // Check that open is called before calling run (again).
// The default behavior is to delete the plugin. This can be overridden in
// the callback by calling run() again.
deleteMe();
if (mAutoKill)
{
// The default behavior is to delete the plugin. This can be overridden in
// the callback by calling run() again.
kill();
}
}
// This function is called when a new message is received from the plugin.

View File

@@ -132,7 +132,7 @@ new AIFilePicker
which sets the state to AIFilePicker_canceled or AIFilePicker_done
respectively, causing a call to AIStateMachine::finish(), which calls
AIFilePicker::finish_impl which destroys the plugin (mPluginBase),
the plugin manager (mPluginManager) and calls AIStateMachine::deleteMe()
the plugin manager (mPluginManager) and calls AIStateMachine::kill()
causing the AIFilePicker to be deleted.
*/
@@ -150,6 +150,9 @@ class AIFilePicker : public AIStateMachine {
public:
AIFilePicker(void);
// Create a dynamically created AIFilePicker object.
static AIFilePicker* create(bool auto_kill = true) { AIFilePicker* filepicker = new AIFilePicker; filepicker->mAutoKill = auto_kill; return filepicker; }
// The starting directory that the user will be in when the file picker opens
// will be the same as the directory used the last time the file picker was
// opened with the same context. If the file picker was never opened before
@@ -184,6 +187,7 @@ private:
typedef std::map<std::string, std::string> context_map_type; //!< Type of mContextMap.
static AIThreadSafeSimple<context_map_type> sContextMap; //!< Map context (ie, "snapshot" or "image") to last used folder.
std::string mContext; //!< Some key to indicate the context (remembers the folder per key).
bool mAutoKill; //!< True if the default behavior is to delete itself after being finished.
// Input variables (cache variable between call to open and run).
open_type mOpenType; //!< Set to whether opening a filepicker to select for saving one file, for loading one file, or loading multiple files.

View File

@@ -71,7 +71,6 @@ namespace {
bool calling_mainloop;
};
static AITHREADSAFE(cscm_type, continued_statemachines_and_calling_mainloop, );
}
// static
@@ -177,8 +176,8 @@ void AIStateMachine::finish(void)
idle();
mState = bs_finish;
finish_impl();
// Did finish_impl call deleteMe? Then that is only the default. Remember it.
bool default_delete = (mState == bs_deleted);
// Did finish_impl call kill()? Then that is only the default. Remember it.
bool default_delete = (mState == bs_killed);
mState = bs_finish;
if (mParent)
{
@@ -202,20 +201,20 @@ void AIStateMachine::finish(void)
mState = bs_initialize;
if (mCallback)
{
mCallback->callback(!mAborted); // This can/may call deleteMe(), in which case the whole AIStateMachine will be deleted from the mainloop.
mCallback->callback(!mAborted); // This can/may call kill(), in which case the whole AIStateMachine will be deleted from the mainloop.
delete mCallback;
mCallback = NULL;
}
// Restore the request for deletion if we weren't started again from the callback.
if (default_delete && mState == bs_initialize)
mState = bs_deleted;
mState = bs_killed;
}
void AIStateMachine::deleteMe(void)
void AIStateMachine::kill(void)
{
// Should only be called from finish().
llassert(mIdle && (mState == bs_initialize || mState == bs_finish));
mState = bs_deleted;
mState = bs_killed;
}
// Return stringified 'state'.
@@ -229,7 +228,7 @@ char const* AIStateMachine::state_str(state_type state)
AI_CASE_RETURN(bs_run);
AI_CASE_RETURN(bs_abort);
AI_CASE_RETURN(bs_finish);
AI_CASE_RETURN(bs_deleted);
AI_CASE_RETURN(bs_killed);
}
}
return state_str_impl(state);
@@ -326,7 +325,7 @@ void AIStateMachine::mainloop(void*)
{
Dout(dc::statemachine, "Erasing " << (void*)&statemachine << " from active_statemachines");
iter = active_statemachines.erase(iter);
if (statemachine.mState == bs_deleted)
if (statemachine.mState == bs_killed)
{
Dout(dc::statemachine, "Deleting " << (void*)&statemachine);
delete &statemachine;

View File

@@ -169,7 +169,7 @@ class AIStateMachine {
bs_run,
bs_abort,
bs_finish,
bs_deleted
bs_killed
};
public:
@@ -178,7 +178,7 @@ class AIStateMachine {
//! Integral value equal to the state with the lowest value.
static state_type const min_state = bs_initialize;
//! Integral value one more than the state with the highest value.
static state_type const max_state = bs_deleted + 1;
static state_type const max_state = bs_killed + 1;
private:
base_state_type mState; //!< State of the base class.
@@ -214,8 +214,8 @@ class AIStateMachine {
AIStateMachine(void) : mState(bs_initialize), mIdle(true), mAborted(true), mSleep(0), mParent(NULL), mCallback(NULL) { updateSettings(); }
protected:
//! The user should call 'deleteMe()', not delete a AIStateMachine (derived) directly.
virtual ~AIStateMachine() { llassert(mState == bs_deleted); }
//! The user should call 'kill()', not delete a AIStateMachine (derived) directly.
virtual ~AIStateMachine() { llassert(mState == bs_killed); }
public:
//! Halt the state machine until cont() is called.
@@ -286,8 +286,8 @@ class AIStateMachine {
//! Refine state while in the bs_run state. May only be called while in the bs_run state.
void set_state(state_type run_state);
//! Change state to 'bs_deleted'. May only be called while in the bs_finish state.
void deleteMe(void);
//! Change state to 'bs_killed'. May only be called while in the bs_finish state.
void kill(void);
//---------------------------------------
// Other.