diff options
-rw-r--r-- | indra/newview/llpreviewnotecard.cpp | 175 | ||||
-rw-r--r-- | indra/newview/llpreviewnotecard.h | 17 |
2 files changed, 71 insertions, 121 deletions
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp index 620b7c8b2d..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) @@ -88,24 +87,30 @@ bool LLPreviewNotecard::postBuild() 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()); + mDescEditor->setValue(item->getDescription()); bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID()); - getChildView("Delete")->setEnabled(!source_library); + mDeleteBtn->setEnabled(!source_library); } - getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe); + mDescEditor->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe); return LLPreview::postBuild(); } @@ -118,22 +123,30 @@ bool LLPreviewNotecard::saveItem() 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(); } @@ -153,9 +166,7 @@ bool LLPreviewNotecard::handleKeyHere(KEY key, MASK mask) // virtual bool LLPreviewNotecard::canClose() { - LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor"); - - if(mForceClose || editor->isPristine()) + if(mForceClose || mEditor->isPristine()) { return true; } @@ -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,11 +229,6 @@ void LLPreviewNotecard::loadAsset() { // request the asset. const LLInventoryItem* item = getItem(); - LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor"); - - if (!editor) - return; - bool fail = false; if(item) @@ -249,9 +244,9 @@ void LLPreviewNotecard::loadAsset() 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; } @@ -301,22 +296,22 @@ void LLPreviewNotecard::loadAsset() 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 ) ) { @@ -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) @@ -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. @@ -731,7 +682,7 @@ bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const { case 0: // "Yes" mCloseAfterSave = true; - LLPreviewNotecard::onClickSave((void*)this); + saveIfNeeded(); break; case 1: // "No" diff --git a/indra/newview/llpreviewnotecard.h b/indra/newview/llpreviewnotecard.h index db677b1cf9..be3c804f9b 100644 --- a/indra/newview/llpreviewnotecard.h +++ b/indra/newview/llpreviewnotecard.h @@ -41,6 +41,7 @@ class LLViewerTextEditor; class LLButton; +class LLLineEditor; class LLPreviewNotecard : public LLPreview, public LLVOInventoryListener { @@ -93,12 +94,6 @@ protected: LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status); - static void onClickSave(void* data); - - static void onClickDelete(void* data); - - static void onClickEdit(void* data); - static void onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status); @@ -116,14 +111,18 @@ protected: std::string getTmpFileName(); protected: - LLViewerTextEditor* mEditor; - LLButton* mSaveBtn; + LLViewerTextEditor* mEditor = nullptr; + LLLineEditor* mDescEditor = nullptr; + LLButton* mSaveBtn = nullptr; + LLButton* mEditBtn = nullptr; + LLButton* mDeleteBtn = nullptr; + LLUICtrl* mLockBtn = nullptr; LLUUID mAssetID; LLUUID mObjectID; - LLLiveLSLFile* mLiveFile; + LLLiveLSLFile* mLiveFile = nullptr; }; |