diff options
Diffstat (limited to 'indra/newview/llpreviewnotecard.cpp')
-rw-r--r-- | indra/newview/llpreviewnotecard.cpp | 173 |
1 files changed, 41 insertions, 132 deletions
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp index 4abe390bc5..cadab71ba8 100644 --- a/indra/newview/llpreviewnotecard.cpp +++ b/indra/newview/llpreviewnotecard.cpp @@ -40,6 +40,7 @@ #include "llassetuploadresponders.h" #include "llviewerwindow.h" #include "llbutton.h" +#include "llfloaterreg.h" #include "llinventorymodel.h" #include "lllineeditor.h" #include "llnotify.h" @@ -62,91 +63,19 @@ #include "lluictrlfactory.h" ///---------------------------------------------------------------------------- -/// Local function declarations, constants, enums, and typedefs -///---------------------------------------------------------------------------- - -const S32 PREVIEW_MIN_WIDTH = - 2 * PREVIEW_BORDER + - 2 * PREVIEW_BUTTON_WIDTH + - PREVIEW_PAD + RESIZE_HANDLE_WIDTH + - PREVIEW_PAD; -const S32 PREVIEW_MIN_HEIGHT = - 2 * PREVIEW_BORDER + - 3*(20 + PREVIEW_PAD) + - 2 * SCROLLBAR_SIZE + 128; - -///---------------------------------------------------------------------------- /// Class LLPreviewNotecard ///---------------------------------------------------------------------------- // Default constructor -LLPreviewNotecard::LLPreviewNotecard(const std::string& name, - const LLRect& rect, - const std::string& title, - const LLUUID& item_id, - const LLUUID& object_id, - const LLUUID& asset_id, - BOOL show_keep_discard, - LLPointer<LLViewerInventoryItem> inv_item) : - LLPreview(name, rect, title, item_id, object_id, TRUE, - PREVIEW_MIN_WIDTH, - PREVIEW_MIN_HEIGHT, - inv_item), - mAssetID( asset_id ), - mNotecardItemID(item_id), - mObjectID(object_id) +LLPreviewNotecard::LLPreviewNotecard(const LLSD& key) //const LLUUID& item_id, + : LLPreview( key ) { - LLRect curRect = rect; - - if (show_keep_discard) - { - LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_notecard_keep_discard.xml"); - childSetAction("Keep",onKeepBtn,this); - childSetAction("Discard",onDiscardBtn,this); - } - else - { - LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_notecard.xml"); - childSetAction("Save",onClickSave,this); - - if( mAssetID.isNull() ) - { - const LLInventoryItem* item = getItem(); - if( item ) - { - mAssetID = item->getAssetUUID(); - } - } - } - - // only assert shape if not hosted in a multifloater - if (!getHost()) - { - reshape(curRect.getWidth(), curRect.getHeight(), TRUE); - setRect(curRect); - } - - childSetVisible("lock", FALSE); - - const LLInventoryItem* item = getItem(); - - childSetCommitCallback("desc", LLPreview::onText, this); + const LLInventoryItem *item = getItem(); if (item) - childSetText("desc", item->getDescription()); - childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe); - - setTitle(title); - - LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor"); - - if (editor) { - editor->setWordWrap(TRUE); - editor->setSourceID(item_id); - editor->setHandleEditKeysDirectly(TRUE); - } - - gAgent.changeCameraToDefault(); + mAssetID = item->getAssetUUID(); + } + //Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_notecard.xml", FALSE); } LLPreviewNotecard::~LLPreviewNotecard() @@ -158,25 +87,27 @@ BOOL LLPreviewNotecard::postBuild() LLViewerTextEditor *ed = getChild<LLViewerTextEditor>("Notecard Editor"); if (ed) { - ed->setNotecardInfo(mNotecardItemID, mObjectID); + ed->setNotecardInfo(mItemUUID, mObjectID, getKey()); ed->makePristine(); } - return TRUE; + + childSetAction("Save", onClickSave, this); + childSetVisible("lock", FALSE); + + const LLInventoryItem* item = getItem(); + + childSetCommitCallback("desc", LLPreview::onText, this); + if (item) + childSetText("desc", item->getDescription()); + childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe); + + return LLPreview::postBuild(); } -bool LLPreviewNotecard::saveItem(LLPointer<LLInventoryItem>* itemptr) +bool LLPreviewNotecard::saveItem() { - LLInventoryItem* item = NULL; - if (itemptr && itemptr->notNull()) - { - item = (LLInventoryItem*)(*itemptr); - } - bool res = saveIfNeeded(item); - if (res) - { - delete itemptr; - } - return res; + LLInventoryItem* item = gInventory.getItem(mItemUUID); + return saveIfNeeded(item); } void LLPreviewNotecard::setEnabled( BOOL enabled ) @@ -188,20 +119,15 @@ void LLPreviewNotecard::setEnabled( BOOL enabled ) childSetVisible("lock", !enabled); childSetEnabled("desc", enabled); childSetEnabled("Save", enabled && editor && (!editor->isPristine())); - } void LLPreviewNotecard::draw() { - - - //childSetFocus("Save", FALSE); - LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor"); - BOOL script_changed = !editor->isPristine(); + BOOL changed = !editor->isPristine(); - childSetEnabled("Save", script_changed && getEnabled()); + childSetEnabled("Save", changed && getEnabled()); LLPreview::draw(); } @@ -255,8 +181,13 @@ bool LLPreviewNotecard::hasEmbeddedInventory() return editor->hasEmbeddedInventory(); } -void LLPreviewNotecard::refreshFromInventory() +void LLPreviewNotecard::refreshFromInventory(const LLUUID& new_item_id) { + if (new_item_id.notNull()) + { + mItemUUID = new_item_id; + setKey(LLSD(new_item_id)); + } lldebugs << "LLPreviewNotecard::refreshFromInventory()" << llendl; loadAsset(); } @@ -287,7 +218,6 @@ void LLPreviewNotecard::loadAsset() } else { - LLUUID* new_uuid = new LLUUID(mItemUUID); LLHost source_sim = LLHost::invalid; if (mObjectUUID.notNull()) { @@ -305,7 +235,6 @@ void LLPreviewNotecard::loadAsset() editor->makePristine(); editor->setEnabled(FALSE); mAssetStatus = PREVIEW_ASSET_LOADED; - delete new_uuid; return; } } @@ -318,7 +247,7 @@ void LLPreviewNotecard::loadAsset() item->getAssetUUID(), item->getType(), &onLoadComplete, - (void*)new_uuid, + (void*)new LLUUID(mItemUUID), TRUE); mAssetStatus = PREVIEW_ASSET_LOADING; } @@ -343,7 +272,9 @@ void LLPreviewNotecard::loadAsset() editor->setText(LLStringUtil::null); editor->makePristine(); editor->setEnabled(TRUE); - mAssetStatus = PREVIEW_ASSET_LOADED; + // 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; } } @@ -355,7 +286,8 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs, { llinfos << "LLPreviewNotecard::onLoadComplete()" << llendl; LLUUID* item_id = (LLUUID*)user_data; - LLPreviewNotecard* preview = LLPreviewNotecard::getInstance(*item_id); + + LLPreviewNotecard* preview = LLFloaterReg::findTypedInstance<LLPreviewNotecard>("preview_notecard", LLSD(*item_id)); if( preview ) { if(0 == status) @@ -420,18 +352,6 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs, } // static -LLPreviewNotecard* LLPreviewNotecard::getInstance(const LLUUID& item_id) -{ - LLPreview* instance = NULL; - preview_map_t::iterator found_it = LLPreview::sInstances.find(item_id); - if(found_it != LLPreview::sInstances.end()) - { - instance = found_it->second; - } - return (LLPreviewNotecard*)instance; -} - -// static void LLPreviewNotecard::onClickSave(void* user_data) { //llinfos << "LLPreviewNotecard::onBtnSave()" << llendl; @@ -590,10 +510,11 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data } // Find our window and close it if requested. - LLPreviewNotecard* previewp = (LLPreviewNotecard*)LLPreview::find(info->mItemUUID); + + LLPreviewNotecard* previewp = LLFloaterReg::findTypedInstance<LLPreviewNotecard>("preview_notecard", info->mItemUUID); if (previewp && previewp->mCloseAfterSave) { - previewp->close(); + previewp->closeFloater(); } } else @@ -624,7 +545,7 @@ bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const case 1: // "No" mForceClose = TRUE; - close(); + closeFloater(); break; case 2: // "Cancel" @@ -636,16 +557,4 @@ bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const return false; } -void LLPreviewNotecard::reshape(S32 width, S32 height, BOOL called_from_parent) -{ - LLPreview::reshape( width, height, called_from_parent ); - - if( !isMinimized() ) - { - // So that next time you open a script it will have the same height and width - // (although not the same position). - gSavedSettings.setRect("NotecardEditorRect", getRect()); - } -} - // EOF |