From a242e8bee2c7f0b0906c850e065adddd5314275d Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Sun, 18 Aug 2024 18:21:55 -0400 Subject: Fix findChild during draw in notecard previews --- indra/newview/llpreviewnotecard.cpp | 175 +++++++++++++----------------------- 1 file changed, 63 insertions(+), 112 deletions(-) (limited to 'indra/newview/llpreviewnotecard.cpp') 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("Save"); + mSaveBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::saveIfNeeded, this, nullptr, true)); - childSetAction("Delete", onClickDelete, this); - getChildView("Delete")->setEnabled(false); + mLockBtn = getChild("lock"); + mLockBtn->setVisible(false); - childSetAction("Edit", onClickEdit, this); + mDeleteBtn = getChild("Delete"); + mDeleteBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::deleteNotecard, this)); + mDeleteBtn->setEnabled(false); + + mEditBtn = getChild("Edit"); + mEditBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::openInExternalEditor, this)); const LLInventoryItem* item = getItem(); - childSetCommitCallback("desc", LLPreview::onText, this); + mDescEditor = getChild("desc"); + mDescEditor->setCommitCallback(boost::bind(&LLPreview::onText, mDescEditor, this)); if (item) { - getChild("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("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("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("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("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("Notecard Editor"); - editor->setNotecardObjectID(mObjectUUID); - editor->makePristine(); + mEditor->setNotecardObjectID(mObjectUUID); + mEditor->makePristine(); } const LLInventoryItem* LLPreviewNotecard::getDragItem() { - LLViewerTextEditor* editor = getChild("Notecard Editor"); - - if(editor) - { - return editor->getDragItem(); - } - return NULL; + return mEditor->getDragItem(); } bool LLPreviewNotecard::hasEmbeddedInventory() { - LLViewerTextEditor* editor = NULL; - editor = getChild("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("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("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("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("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("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" -- cgit v1.2.3