diff options
Diffstat (limited to 'indra/newview/llviewertexteditor.cpp')
-rw-r--r-- | indra/newview/llviewertexteditor.cpp | 244 |
1 files changed, 79 insertions, 165 deletions
diff --git a/indra/newview/llviewertexteditor.cpp b/indra/newview/llviewertexteditor.cpp index 728509e39c..290e6f50ff 100644 --- a/indra/newview/llviewertexteditor.cpp +++ b/indra/newview/llviewertexteditor.cpp @@ -32,13 +32,14 @@ #include "llviewerprecompiledheaders.h" +#include "llfloaterreg.h" #include "llfocusmgr.h" #include "audioengine.h" #include "llagent.h" #include "llinventory.h" +#include "llinventorybridge.h" #include "llinventorymodel.h" #include "llinventoryview.h" -#include "llinventorybridge.h" // for landmark prefix string #include "llviewertexteditor.h" @@ -51,6 +52,7 @@ #include "llpreviewlandmark.h" #include "llscrollbar.h" #include "lltooldraganddrop.h" +#include "lltrans.h" #include "llviewercontrol.h" #include "llviewerimagelist.h" #include "llviewerwindow.h" @@ -96,31 +98,9 @@ public: } else { - // See if we can bring an existing preview to the front - if(!LLPreview::show(item->getUUID(), true)) + if(!gSavedSettings.getBOOL("ShowNewInventory")) { - if(!gSavedSettings.getBOOL("ShowNewInventory")) - { - // There isn't one, so make a new preview - S32 left, top; - gFloaterView->getNewFloaterPosition(&left, &top); - LLRect rect = gSavedSettings.getRect("NotecardEditorRect"); - rect.translate(left - rect.mLeft, top - rect.mTop); - LLPreviewNotecard* preview; - preview = new LLPreviewNotecard("preview notecard", - rect, - std::string("Embedded Note: ") + item->getName(), - item->getUUID(), - LLUUID::null, - item->getAssetUUID(), - true, - (LLViewerInventoryItem*)item); - preview->setSourceID(LLUUID::null); - preview->setFocus(TRUE); - - // Force to be entirely onscreen. - gFloaterView->adjustToFitScreen(preview, FALSE); - } + LLFloaterReg::showInstance("preview_notecard", LLSD(item->getUUID()), TAKE_FOCUS_YES); } } } @@ -430,6 +410,8 @@ void LLEmbeddedItems::bindEmbeddedChars( const LLFontGL* font ) const case LLAssetType::AT_BODYPART: img_name = "inv_item_skin.tga"; break; case LLAssetType::AT_ANIMATION: img_name = "inv_item_animation.tga";break; case LLAssetType::AT_GESTURE: img_name = "inv_item_gesture.tga"; break; + //TODO need img_name + case LLAssetType::AT_FAVORITE: img_name = "inv_item_landmark.tga"; break; default: llassert(0); continue; } @@ -561,32 +543,15 @@ struct LLNotecardCopyInfo // // Member functions // - -LLViewerTextEditor::LLViewerTextEditor(const std::string& name, - const LLRect& rect, - S32 max_length, - const std::string& default_text, - const LLFontGL* font, - BOOL allow_embedded_items) - : LLTextEditor(name, rect, max_length, default_text, font, allow_embedded_items), - mDragItemSaved(FALSE), - mInventoryCallback(new LLEmbeddedNotecardOpener) +LLViewerTextEditor::LLViewerTextEditor(const LLViewerTextEditor::Params& p) +: LLTextEditor(p), + mDragItemChar(0), + mDragItemSaved(FALSE), + mInventoryCallback(new LLEmbeddedNotecardOpener) { + mParseHTML = p.allow_html; mEmbeddedItemList = new LLEmbeddedItems(this); mInventoryCallback->setEditor(this); - - // *TODO: Add right click menus for SLURLs - // Build the right click menu - // make the popup menu available - - //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_slurl.xml", this); - //if (!menu) - //{ - // menu = new LLMenuGL(LLStringUtil::null); - //} - //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); - //// menu->setVisible(FALSE); - //mPopupMenuHandle = menu->getHandle(); } LLViewerTextEditor::~LLViewerTextEditor() @@ -694,6 +659,7 @@ BOOL LLViewerTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) if (item_at_pos) { mDragItem = item_at_pos; + mDragItemChar = wc; mDragItemSaved = LLEmbeddedItems::getEmbeddedItemSaved(wc); gFocusMgr.setMouseCapture( this ); mMouseDownX = x; @@ -779,6 +745,7 @@ BOOL LLViewerTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) BOOL LLViewerTextEditor::handleHover(S32 x, S32 y, MASK mask) { + static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0); BOOL handled = FALSE; if (!mDragItem) @@ -823,7 +790,7 @@ BOOL LLViewerTextEditor::handleHover(S32 x, S32 y, MASK mask) LLAssetType::lookupDragAndDropType( mDragItem->getType() ), mDragItem->getUUID(), LLToolDragAndDrop::SOURCE_NOTECARD, - getSourceID(), mObjectID); + mPreviewID, mObjectID); return LLToolDragAndDrop::getInstance()->handleHover( x, y, mask ); } @@ -876,7 +843,7 @@ BOOL LLViewerTextEditor::handleHover(S32 x, S32 y, MASK mask) if( !handled ) { lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; - if (!mScrollbar->getVisible() || x < getRect().getWidth() - SCROLLBAR_SIZE) + if (!mScrollbar->getVisible() || x < getRect().getWidth() - scrollbar_size) { getWindow()->setCursor(UI_CURSOR_IBEAM); } @@ -907,8 +874,9 @@ BOOL LLViewerTextEditor::handleMouseUp(S32 x, S32 y, MASK mask) { if(mDragItemSaved) { - openEmbeddedItem(mDragItem); - }else + openEmbeddedItem(mDragItem, mDragItemChar); + } + else { showUnsavedAlertDialog(mDragItem); } @@ -1060,7 +1028,15 @@ BOOL LLViewerTextEditor::handleDragAndDrop(S32 x, S32 y, MASK mask, std::string& tooltip_msg) { BOOL handled = FALSE; - + + LLToolDragAndDrop::ESource source = LLToolDragAndDrop::getInstance()->getSource(); + if (LLToolDragAndDrop::SOURCE_NOTECARD == source) + { + // We currently do not handle dragging items from one notecard to another + // since items in a notecard must be in Inventory to be verified. See DEV-2891. + return FALSE; + } + if (mTakesNonScrollClicks) { if (getEnabled() && acceptsTextInput()) @@ -1096,7 +1072,7 @@ BOOL LLViewerTextEditor::handleDragAndDrop(S32 x, S32 y, MASK mask, case DAD_GESTURE: { LLInventoryItem *item = (LLInventoryItem *)cargo_data; - if( allowsEmbeddedItems() ) + if( item && allowsEmbeddedItems() ) { U32 mask_next = item->getPermissions().getMaskNextOwner(); if((mask_next & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) @@ -1123,6 +1099,7 @@ BOOL LLViewerTextEditor::handleDragAndDrop(S32 x, S32 y, MASK mask, *accept = ACCEPT_NO; if (tooltip_msg.empty()) { + // *TODO: Translate tooltip_msg.assign("Only items with unrestricted\n" "'next owner' permissions \n" "can be attached to notecards."); @@ -1236,17 +1213,14 @@ std::string LLViewerTextEditor::appendTime(bool prepend_newline) time_t utc_time; utc_time = time_corrected(); - // There's only one internal tm buffer. - struct tm* timep; - - // Convert to Pacific, based on server's opinion of whether - // it's daylight savings time there. - timep = utc_to_pacific_time(utc_time, gPacificDaylightTime); + std::string timeStr = LLTrans::getString("TextEditorTimeStr"); + LLSD substitution; - std::string text = llformat("[%d:%02d] ", timep->tm_hour, timep->tm_min); - appendColoredText(text, false, prepend_newline, LLColor4::grey); + substitution["datetime"] = (S32) utc_time; + LLStringUtil::format (timeStr, substitution); + appendColoredText(timeStr, false, prepend_newline, LLColor4::grey); - return text; + return timeStr; } //---------------------------------------------------------------------------- @@ -1302,13 +1276,14 @@ BOOL LLViewerTextEditor::openEmbeddedItemAtPos(S32 pos) { if( pos < getLength()) { - LLInventoryItem* item = LLEmbeddedItems::getEmbeddedItem( getWChar(pos) ); + llwchar wc = getWChar(pos); + LLInventoryItem* item = LLEmbeddedItems::getEmbeddedItem( wc ); if( item ) { - BOOL saved = LLEmbeddedItems::getEmbeddedItemSaved( getWChar(pos) ); + BOOL saved = LLEmbeddedItems::getEmbeddedItemSaved( wc ); if (saved) { - return openEmbeddedItem(item); + return openEmbeddedItem(item, wc); } else { @@ -1320,25 +1295,25 @@ BOOL LLViewerTextEditor::openEmbeddedItemAtPos(S32 pos) } -BOOL LLViewerTextEditor::openEmbeddedItem(LLInventoryItem* item) +BOOL LLViewerTextEditor::openEmbeddedItem(LLInventoryItem* item, llwchar wc) { switch( item->getType() ) { case LLAssetType::AT_TEXTURE: - openEmbeddedTexture( item ); + openEmbeddedTexture( item, wc ); return TRUE; case LLAssetType::AT_SOUND: - openEmbeddedSound( item ); + openEmbeddedSound( item, wc ); return TRUE; case LLAssetType::AT_NOTECARD: - openEmbeddedNotecard( item ); + openEmbeddedNotecard( item, wc ); return TRUE; case LLAssetType::AT_LANDMARK: - openEmbeddedLandmark( item ); + openEmbeddedLandmark( item, wc ); return TRUE; case LLAssetType::AT_LSL_TEXT: @@ -1347,7 +1322,7 @@ BOOL LLViewerTextEditor::openEmbeddedItem(LLInventoryItem* item) case LLAssetType::AT_BODYPART: case LLAssetType::AT_ANIMATION: case LLAssetType::AT_GESTURE: - showCopyToInvDialog( item ); + showCopyToInvDialog( item, wc ); return TRUE; default: return FALSE; @@ -1356,35 +1331,22 @@ BOOL LLViewerTextEditor::openEmbeddedItem(LLInventoryItem* item) } -void LLViewerTextEditor::openEmbeddedTexture( LLInventoryItem* item ) +void LLViewerTextEditor::openEmbeddedTexture( LLInventoryItem* item, llwchar wc ) { - // See if we can bring an existing preview to the front // *NOTE: Just for embedded Texture , we should use getAssetUUID(), // not getUUID(), because LLPreviewTexture pass in AssetUUID into // LLPreview constructor ItemUUID parameter. - - if( !LLPreview::show( item->getAssetUUID() ) ) + if (!item) + return; + LLPreviewTexture* preview = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", LLSD(item->getAssetUUID()), TAKE_FOCUS_YES); + if (preview) { - // There isn't one, so make a new preview - if(item) - { - S32 left, top; - gFloaterView->getNewFloaterPosition(&left, &top); - LLRect rect = gSavedSettings.getRect("PreviewTextureRect"); - rect.translate( left - rect.mLeft, top - rect.mTop ); - - LLPreviewTexture* preview = new LLPreviewTexture("preview texture", - rect, - item->getName(), - item->getAssetUUID(), - TRUE); - preview->setAuxItem( item ); - preview->setNotecardInfo(mNotecardInventoryID, mObjectID); - } + preview->setAuxItem( item ); + preview->setNotecardInfo(mNotecardInventoryID, mObjectID); } } -void LLViewerTextEditor::openEmbeddedSound( LLInventoryItem* item ) +void LLViewerTextEditor::openEmbeddedSound( LLInventoryItem* item, llwchar wc ) { // Play sound locally LLVector3d lpos_global = gAgent.getPositionGlobal(); @@ -1393,18 +1355,22 @@ void LLViewerTextEditor::openEmbeddedSound( LLInventoryItem* item ) { gAudiop->triggerSound(item->getAssetUUID(), gAgentID, SOUND_GAIN, LLAudioEngine::AUDIO_TYPE_UI, lpos_global); } - showCopyToInvDialog( item ); + showCopyToInvDialog( item, wc ); } -void LLViewerTextEditor::openEmbeddedLandmark( LLInventoryItem* item ) +void LLViewerTextEditor::openEmbeddedLandmark( LLInventoryItem* item, llwchar wc ) { - std::string title = - std::string(" ") + LLLandmarkBridge::prefix() + item->getName(); - open_landmark((LLViewerInventoryItem*)item, title, FALSE, item->getUUID(), TRUE); + if (!item) + return; + LLPreviewLandmark* preview = LLFloaterReg::showTypedInstance<LLPreviewLandmark>("preview_landmark", LLSD(item->getUUID()), TAKE_FOCUS_YES); + if (preview) + { + preview->setItem( item ); + } } -void LLViewerTextEditor::openEmbeddedNotecard( LLInventoryItem* item ) +void LLViewerTextEditor::openEmbeddedNotecard( LLInventoryItem* item, llwchar wc ) { copyInventory(item, gInventoryCallbacks.registerCB(mInventoryCallback)); } @@ -1423,20 +1389,23 @@ bool LLViewerTextEditor::onNotecardDialog(const LLSD& notification, const LLSD& S32 option = LLNotification::getSelectedOption(notification, response); if( option == 0 ) { - // itemptr is deleted by LLPreview::save - LLPointer<LLInventoryItem>* itemptr = new LLPointer<LLInventoryItem>(gInventory.getItem(notification["payload"]["item_id"].asUUID())); - LLPreview::save( notification["payload"]["notecard_id"].asUUID() , itemptr); + LLPreviewNotecard* preview = LLFloaterReg::findTypedInstance<LLPreviewNotecard>("preview_notecard", notification["payload"]["notecard_id"]);; + if (preview) + { + preview->saveItem(); + } } return false; } -void LLViewerTextEditor::showCopyToInvDialog( LLInventoryItem* item ) +void LLViewerTextEditor::showCopyToInvDialog( LLInventoryItem* item, llwchar wc ) { LLSD payload; - payload["item_id"] = item->getUUID(); - payload["notecard_id"] = mNotecardInventoryID; + LLUUID item_id = item->getUUID(); + payload["item_id"] = item_id; + payload["item_wc"] = LLSD::Integer(wc); LLNotifications::instance().add( "ConfirmItemCopy", LLSD(), payload, boost::bind(&LLViewerTextEditor::onCopyToInvDialog, this, _1, _2)); } @@ -1446,8 +1415,11 @@ bool LLViewerTextEditor::onCopyToInvDialog(const LLSD& notification, const LLSD& S32 option = LLNotification::getSelectedOption(notification, response); if( 0 == option ) { - LLInventoryItem* itemp = gInventory.getItem(notification["payload"]["item_id"].asUUID()); - copyInventory(itemp); + LLUUID item_id = notification["payload"]["item_id"].asUUID(); + llwchar wc = llwchar(notification["payload"]["item_wc"].asInteger()); + LLInventoryItem* itemp = LLEmbeddedItems::getEmbeddedItem(wc); + if (itemp) + copyInventory(itemp); } return false; } @@ -1525,61 +1497,3 @@ BOOL LLViewerTextEditor::exportBuffer( std::string& buffer ) return TRUE; } -LLView* LLViewerTextEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory) -{ - std::string name("text_editor"); - node->getAttributeString("name", name); - - LLRect rect; - createRect(node, rect, parent, LLRect()); - - U32 max_text_length = 255; - node->getAttributeU32("max_length", max_text_length); - - BOOL allow_embedded_items = FALSE; - node->getAttributeBOOL("embedded_items", allow_embedded_items); - - LLFontGL* font = LLView::selectFont(node); - - // std::string text = node->getValue(); - std::string text = node->getTextContents().substr(0, max_text_length - 1); - - if (text.size() > max_text_length) - { - // Erase everything from max_text_length on. - text.erase(max_text_length); - } - - LLViewerTextEditor* text_editor = new LLViewerTextEditor(name, - rect, - max_text_length, - LLStringUtil::null, - font, - allow_embedded_items); - - BOOL ignore_tabs = text_editor->tabsToNextField(); - node->getAttributeBOOL("ignore_tab", ignore_tabs); - text_editor->setTabsToNextField(ignore_tabs); - - text_editor->setTextEditorParameters(node); - - BOOL hide_scrollbar = FALSE; - node->getAttributeBOOL("hide_scrollbar",hide_scrollbar); - text_editor->setHideScrollbarForShortDocs(hide_scrollbar); - - BOOL hide_border = !text_editor->isBorderVisible(); - node->getAttributeBOOL("hide_border", hide_border); - text_editor->setBorderVisible(!hide_border); - - BOOL parse_html = text_editor->mParseHTML; - node->getAttributeBOOL("allow_html", parse_html); - text_editor->setParseHTML(parse_html); - text_editor->setParseHighlights(TRUE); - - text_editor->initFromXML(node, parent); - - // add text after all parameters have been set - text_editor->appendStyledText(text, FALSE, FALSE); - - return text_editor; -} |