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.cpp197
1 files changed, 51 insertions, 146 deletions
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index 4abe390bc5..cc70360528 100644
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -40,9 +40,10 @@
#include "llassetuploadresponders.h"
#include "llviewerwindow.h"
#include "llbutton.h"
+#include "llfloaterreg.h"
#include "llinventorymodel.h"
#include "lllineeditor.h"
-#include "llnotify.h"
+#include "llnotificationsutil.h"
#include "llresmgr.h"
#include "roles_constants.h"
#include "llscrollbar.h"
@@ -54,7 +55,6 @@
#include "llviewerobjectlist.h"
#include "llviewerregion.h"
#include "lldir.h"
-//#include "llfloaterchat.h"
#include "llviewerstats.h"
#include "llviewercontrol.h" // gSavedSettings
#include "llappviewer.h" // app_abort_quit()
@@ -62,91 +62,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()
@@ -156,27 +84,26 @@ LLPreviewNotecard::~LLPreviewNotecard()
BOOL LLPreviewNotecard::postBuild()
{
LLViewerTextEditor *ed = getChild<LLViewerTextEditor>("Notecard Editor");
- if (ed)
- {
- ed->setNotecardInfo(mNotecardItemID, mObjectID);
- ed->makePristine();
- }
- return TRUE;
+ ed->setNotecardInfo(mItemUUID, mObjectID, getKey());
+ ed->makePristine();
+
+ 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::prevalidateASCIIPrintableNoPipe);
+
+ 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 +115,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();
-
- childSetEnabled("Save", script_changed && getEnabled());
+ BOOL changed = !editor->isPristine();
+
+ childSetEnabled("Save", changed && getEnabled());
LLPreview::draw();
}
@@ -230,7 +152,7 @@ BOOL LLPreviewNotecard::canClose()
else
{
// Bring up view-modal dialog: Save changes? Yes, No, Cancel
- LLNotifications::instance().add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
+ LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
return FALSE;
}
@@ -255,8 +177,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 +214,6 @@ void LLPreviewNotecard::loadAsset()
}
else
{
- LLUUID* new_uuid = new LLUUID(mItemUUID);
LLHost source_sim = LLHost::invalid;
if (mObjectUUID.notNull())
{
@@ -305,7 +231,6 @@ void LLPreviewNotecard::loadAsset()
editor->makePristine();
editor->setEnabled(FALSE);
mAssetStatus = PREVIEW_ASSET_LOADED;
- delete new_uuid;
return;
}
}
@@ -318,7 +243,7 @@ void LLPreviewNotecard::loadAsset()
item->getAssetUUID(),
item->getType(),
&onLoadComplete,
- (void*)new_uuid,
+ (void*)new LLUUID(mItemUUID),
TRUE);
mAssetStatus = PREVIEW_ASSET_LOADING;
}
@@ -343,7 +268,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 +282,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)
@@ -401,15 +329,15 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs,
if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
LL_ERR_FILE_EMPTY == status)
{
- LLNotifications::instance().add("NotecardMissing");
+ LLNotificationsUtil::add("NotecardMissing");
}
else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
{
- LLNotifications::instance().add("NotecardNoPermissions");
+ LLNotificationsUtil::add("NotecardNoPermissions");
}
else
{
- LLNotifications::instance().add("UnableToLoadNotecard");
+ LLNotificationsUtil::add("UnableToLoadNotecard");
}
llwarns << "Problem loading notecard: " << status << llendl;
@@ -420,18 +348,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;
@@ -576,7 +492,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
}
else
{
- LLNotifications::instance().add("SaveNotecardFailObjectNotFound");
+ LLNotificationsUtil::add("SaveNotecardFailObjectNotFound");
}
}
// Perform item copy to inventory
@@ -590,10 +506,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
@@ -601,7 +518,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
llwarns << "Problem saving notecard: " << status << llendl;
LLSD args;
args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
- LLNotifications::instance().add("SaveNotecardFailReason", args);
+ LLNotificationsUtil::add("SaveNotecardFailReason", args);
}
std::string uuid_string;
@@ -614,7 +531,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const LLSD& response)
{
- S32 option = LLNotification::getSelectedOption(notification, response);
+ S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
switch(option)
{
case 0: // "Yes"
@@ -624,7 +541,7 @@ bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const
case 1: // "No"
mForceClose = TRUE;
- close();
+ closeFloater();
break;
case 2: // "Cancel"
@@ -636,16 +553,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