summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewnotecard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpreviewnotecard.cpp')
-rw-r--r--indra/newview/llpreviewnotecard.cpp221
1 files changed, 86 insertions, 135 deletions
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index aa04540536..9a991727b2 100644
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -67,8 +67,7 @@
// Default constructor
LLPreviewNotecard::LLPreviewNotecard(const LLSD& key) //const LLUUID& item_id,
- : LLPreview( key ),
- mLiveFile(NULL)
+ : LLPreview( key )
{
const LLInventoryItem *item = getItem();
if (item)
@@ -82,30 +81,36 @@ LLPreviewNotecard::~LLPreviewNotecard()
delete mLiveFile;
}
-BOOL LLPreviewNotecard::postBuild()
+bool LLPreviewNotecard::postBuild()
{
mEditor = getChild<LLViewerTextEditor>("Notecard Editor");
mEditor->setNotecardInfo(mItemUUID, mObjectID, getKey());
mEditor->makePristine();
- childSetAction("Save", onClickSave, this);
- getChildView("lock")->setVisible( FALSE);
+ mSaveBtn = getChild<LLButton>("Save");
+ mSaveBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::saveIfNeeded, this, nullptr, true));
- childSetAction("Delete", onClickDelete, this);
- getChildView("Delete")->setEnabled(false);
+ mLockBtn = getChild<LLUICtrl>("lock");
+ mLockBtn->setVisible(false);
- childSetAction("Edit", onClickEdit, this);
+ mDeleteBtn = getChild<LLButton>("Delete");
+ mDeleteBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::deleteNotecard, this));
+ mDeleteBtn->setEnabled(false);
+
+ mEditBtn = getChild<LLButton>("Edit");
+ mEditBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::openInExternalEditor, this));
const LLInventoryItem* item = getItem();
- childSetCommitCallback("desc", LLPreview::onText, this);
+ mDescEditor = getChild<LLLineEditor>("desc");
+ mDescEditor->setCommitCallback(boost::bind(&LLPreview::onText, mDescEditor, this));
if (item)
{
- getChild<LLUICtrl>("desc")->setValue(item->getDescription());
- BOOL source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID());
- getChildView("Delete")->setEnabled(!source_library);
+ mDescEditor->setValue(item->getDescription());
+ bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID());
+ mDeleteBtn->setEnabled(!source_library);
}
- getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
+ mDescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}
@@ -116,58 +121,64 @@ bool LLPreviewNotecard::saveItem()
return saveIfNeeded(item);
}
-void LLPreviewNotecard::setEnabled( BOOL enabled )
+void LLPreviewNotecard::setEnabled(bool enabled)
{
-
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
- getChildView("Notecard Editor")->setEnabled(enabled);
- getChildView("lock")->setVisible( !enabled);
- getChildView("desc")->setEnabled(enabled);
- getChildView("Save")->setEnabled(enabled && editor && (!editor->isPristine()));
+ if (mEditor)
+ {
+ mEditor->setEnabled(enabled);
+ }
+ if (mLockBtn)
+ {
+ mLockBtn->setVisible(!enabled);
+ }
+ if (mDescEditor)
+ {
+ mDescEditor->setEnabled(enabled);
+ }
+ if (mSaveBtn)
+ {
+ mSaveBtn->setEnabled(enabled && mEditor && (!mEditor->isPristine()));
+ }
}
void LLPreviewNotecard::draw()
{
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
- BOOL changed = !editor->isPristine();
+ bool changed = !mEditor->isPristine();
- getChildView("Save")->setEnabled(changed && getEnabled());
+ mSaveBtn->setEnabled(changed && getEnabled());
LLPreview::draw();
}
// virtual
-BOOL LLPreviewNotecard::handleKeyHere(KEY key, MASK mask)
+bool LLPreviewNotecard::handleKeyHere(KEY key, MASK mask)
{
if(('S' == key) && (MASK_CONTROL == (mask & MASK_CONTROL)))
{
saveIfNeeded();
- return TRUE;
+ return true;
}
return LLPreview::handleKeyHere(key, mask);
}
// virtual
-BOOL LLPreviewNotecard::canClose()
+bool LLPreviewNotecard::canClose()
{
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
- if(mForceClose || editor->isPristine())
+ if(mForceClose || mEditor->isPristine())
{
- return TRUE;
+ return true;
}
else
{
if(!mSaveDialogShown)
{
- mSaveDialogShown = TRUE;
+ mSaveDialogShown = true;
// Bring up view-modal dialog: Save changes? Yes, No, Cancel
LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
}
- return FALSE;
+ return false;
}
}
@@ -176,28 +187,18 @@ void LLPreviewNotecard::setObjectID(const LLUUID& object_id)
{
LLPreview::setObjectID(object_id);
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
- editor->setNotecardObjectID(mObjectUUID);
- editor->makePristine();
+ mEditor->setNotecardObjectID(mObjectUUID);
+ mEditor->makePristine();
}
const LLInventoryItem* LLPreviewNotecard::getDragItem()
{
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
- if(editor)
- {
- return editor->getDragItem();
- }
- return NULL;
+ return mEditor->getDragItem();
}
bool LLPreviewNotecard::hasEmbeddedInventory()
{
- LLViewerTextEditor* editor = NULL;
- editor = getChild<LLViewerTextEditor>("Notecard Editor");
- if (!editor) return false;
- return editor->hasEmbeddedInventory();
+ return mEditor->hasEmbeddedInventory();
}
void LLPreviewNotecard::refreshFromInventory(const LLUUID& new_item_id)
@@ -215,10 +216,9 @@ void LLPreviewNotecard::updateTitleButtons()
{
LLPreview::updateTitleButtons();
- LLUICtrl* lock_btn = getChild<LLUICtrl>("lock");
- if(lock_btn->getVisible() && !isMinimized()) // lock button stays visible if floater is minimized.
+ if(mLockBtn && mLockBtn->getVisible() && !isMinimized()) // lock button stays visible if floater is minimized.
{
- LLRect lock_rc = lock_btn->getRect();
+ LLRect lock_rc = mLockBtn->getRect();
LLRect buttons_rect = getDragHandle()->getButtonsRect();
buttons_rect.mLeft = lock_rc.mLeft;
getDragHandle()->setButtonsRect(buttons_rect);
@@ -229,29 +229,24 @@ void LLPreviewNotecard::loadAsset()
{
// request the asset.
const LLInventoryItem* item = getItem();
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
- if (!editor)
- return;
-
bool fail = false;
if(item)
{
LLPermissions perm(item->getPermissions());
- BOOL is_owner = gAgent.allowOperation(PERM_OWNER, perm, GP_OBJECT_MANIPULATE);
- BOOL allow_copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
- BOOL allow_modify = canModify(mObjectUUID, item);
- BOOL source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(mItemUUID, gInventory.getLibraryRootFolderID());
+ bool is_owner = gAgent.allowOperation(PERM_OWNER, perm, GP_OBJECT_MANIPULATE);
+ bool allow_copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
+ bool allow_modify = canModify(mObjectUUID, item);
+ bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(mItemUUID, gInventory.getLibraryRootFolderID());
if (allow_copy || gAgent.isGodlike())
{
mAssetID = item->getAssetUUID();
if(mAssetID.isNull())
{
- editor->setText(LLStringUtil::null);
- editor->makePristine();
- editor->setEnabled(TRUE);
+ mEditor->setText(LLStringUtil::null);
+ mEditor->makePristine();
+ mEditor->setEnabled(true);
mAssetStatus = PREVIEW_ASSET_LOADED;
}
else
@@ -270,9 +265,9 @@ void LLPreviewNotecard::loadAsset()
// The object that we're trying to look at disappeared, bail.
LL_WARNS() << "Can't find object " << mObjectUUID << " associated with notecard." << LL_ENDL;
mAssetID.setNull();
- editor->setText(getString("no_object"));
- editor->makePristine();
- editor->setEnabled(FALSE);
+ mEditor->setText(getString("no_object"));
+ mEditor->makePristine();
+ mEditor->setEnabled(false);
mAssetStatus = PREVIEW_ASSET_LOADED;
return;
}
@@ -294,29 +289,29 @@ void LLPreviewNotecard::loadAsset()
item->getType(),
&onLoadComplete,
(void*)user_data,
- TRUE);
+ true);
mAssetStatus = PREVIEW_ASSET_LOADING;
}
}
else
{
mAssetID.setNull();
- editor->setText(getString("not_allowed"));
- editor->makePristine();
- editor->setEnabled(FALSE);
+ mEditor->setText(getString("not_allowed"));
+ mEditor->makePristine();
+ mEditor->setEnabled(false);
mAssetStatus = PREVIEW_ASSET_LOADED;
}
if(!allow_modify)
{
- editor->setEnabled(FALSE);
- getChildView("lock")->setVisible( TRUE);
- getChildView("Edit")->setEnabled(FALSE);
+ mEditor->setEnabled(false);
+ mLockBtn->setVisible( true);
+ mEditBtn->setEnabled(false);
}
if((allow_modify || is_owner) && !source_library)
{
- getChildView("Delete")->setEnabled(TRUE);
+ mDeleteBtn->setEnabled(true);
}
}
else if (mObjectUUID.notNull() && mItemUUID.notNull())
@@ -345,9 +340,9 @@ void LLPreviewNotecard::loadAsset()
if (fail)
{
- editor->setText(LLStringUtil::null);
- editor->makePristine();
- editor->setEnabled(TRUE);
+ mEditor->setText(LLStringUtil::null);
+ mEditor->makePristine();
+ mEditor->setEnabled(true);
// Don't set asset status here; we may not have set the item id yet
// (e.g. when this gets called initially)
//mAssetStatus = PREVIEW_ASSET_LOADED;
@@ -377,7 +372,7 @@ void LLPreviewNotecard::onLoadComplete(const LLUUID& asset_uuid,
buffer[file_length] = 0;
- LLViewerTextEditor* previewEditor = preview->getChild<LLViewerTextEditor>("Notecard Editor");
+ LLViewerTextEditor* previewEditor = preview->mEditor;
if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
{
@@ -393,7 +388,7 @@ void LLPreviewNotecard::onLoadComplete(const LLUUID& asset_uuid,
}
previewEditor->makePristine();
- BOOL modifiable = preview->canModify(preview->mObjectID, preview->getItem());
+ bool modifiable = preview->canModify(preview->mObjectID, preview->getItem());
preview->setEnabled(modifiable);
preview->syncExternal();
preview->mAssetStatus = PREVIEW_ASSET_LOADED;
@@ -421,38 +416,6 @@ void LLPreviewNotecard::onLoadComplete(const LLUUID& asset_uuid,
delete floater_key;
}
-// static
-void LLPreviewNotecard::onClickSave(void* user_data)
-{
- //LL_INFOS() << "LLPreviewNotecard::onBtnSave()" << LL_ENDL;
- LLPreviewNotecard* preview = (LLPreviewNotecard*)user_data;
- if(preview)
- {
- preview->saveIfNeeded();
- }
-}
-
-
-// static
-void LLPreviewNotecard::onClickDelete(void* user_data)
-{
- LLPreviewNotecard* preview = (LLPreviewNotecard*)user_data;
- if(preview)
- {
- preview->deleteNotecard();
- }
-}
-
-// static
-void LLPreviewNotecard::onClickEdit(void* user_data)
-{
- LLPreviewNotecard* preview = (LLPreviewNotecard*)user_data;
- if (preview)
- {
- preview->openInExternalEditor();
- }
-}
-
struct LLSaveNotecardInfo
{
LLPreviewNotecard* mSelf;
@@ -515,23 +478,15 @@ void LLPreviewNotecard::finishTaskUpload(LLUUID itemId, LLUUID newAssetId, LLUUI
bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem, bool sync)
{
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
- if(!editor)
- {
- LL_WARNS() << "Cannot get handle to the notecard editor." << LL_ENDL;
- return false;
- }
-
- if(!editor->isPristine())
+ if(!mEditor->isPristine())
{
std::string buffer;
- if (!editor->exportBuffer(buffer))
+ if (!mEditor->exportBuffer(buffer))
{
return false;
}
- editor->makePristine();
+ mEditor->makePristine();
const LLInventoryItem* item = getItem();
// save it out to database
if (item)
@@ -593,13 +548,13 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem, bool sync)
LLSaveNotecardInfo* info = new LLSaveNotecardInfo(this, mItemUUID, mObjectUUID,
tid, copyitem);
- S32 size = buffer.length() + 1;
+ S32 size = static_cast<S32>(buffer.length()) + 1;
file.write((U8*)buffer.c_str(), size);
gAssetStorage->storeAssetData(tid, LLAssetType::AT_NOTECARD,
&onSaveComplete,
(void*)info,
- FALSE);
+ false);
return true;
}
else // !gAssetStorage
@@ -659,7 +614,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
new_item->setAssetUUID(asset_uuid);
new_item->setTransactionID(info->mTransactionID);
- new_item->updateServer(FALSE);
+ new_item->updateServer(false);
gInventory.updateItem(new_item);
gInventory.notifyObservers();
}
@@ -692,11 +647,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
// Perform item copy to inventory
if (info->mCopyItem.notNull())
{
- LLViewerTextEditor* editor = info->mSelf->getChild<LLViewerTextEditor>("Notecard Editor");
- if (editor)
- {
- editor->copyInventory(info->mCopyItem);
- }
+ info->mSelf->mEditor->copyInventory(info->mCopyItem);
}
// Find our window and close it if requested.
@@ -725,17 +676,17 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const LLSD& response)
{
- mSaveDialogShown = FALSE;
+ mSaveDialogShown = false;
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
switch(option)
{
case 0: // "Yes"
- mCloseAfterSave = TRUE;
- LLPreviewNotecard::onClickSave((void*)this);
+ mCloseAfterSave = true;
+ saveIfNeeded();
break;
case 1: // "No"
- mForceClose = TRUE;
+ mForceClose = true;
closeFloater();
break;
@@ -764,7 +715,7 @@ bool LLPreviewNotecard::handleConfirmDeleteDialog(const LLSD& notification, cons
if (item != NULL)
{
const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
- gInventory.changeItemParent(item, trash_id, FALSE);
+ gInventory.changeItemParent(item, trash_id, false);
}
}
else
@@ -782,7 +733,7 @@ bool LLPreviewNotecard::handleConfirmDeleteDialog(const LLSD& notification, cons
}
// close floater, ignore unsaved changes
- mForceClose = TRUE;
+ mForceClose = true;
closeFloater();
return false;
}