From 0355910ba5b0ed56aabcf290f940987ad5aec1b4 Mon Sep 17 00:00:00 2001
From: Vadim Savchuk <vsavchuk@productengine.com>
Date: Thu, 12 Aug 2010 16:16:57 +0300
Subject: [PATCH] EXT-8473 FIXED Fixed renaming inventory items without hitting
 Enter.

Problem:

The bug was caused by the fix of EXT-6682 that prematurely forgets the item
being renamed (by resetting mRenameItem) whenever the renamer input field loses focus.
That's why we couldn't actually finish renaming item.

Fix:

The code is quite messy, but I'll try to explain.

There are three cases when we should hide the renamer:
1) ESC key is hit (just hide).
2) ENTER key is hit (rename, then hide).
3) renamer loses focus (rename, then hide).

In the first two cases we manually remove the renamer from the popups
list -- by calling gViewerWindow->removePopup(mRenamer).
In the third case that's done automatically.
So, in all cases the onRenamerLost() pop-up is called that hides the renamer
and only *then* resets mRenameItem.
Not only this approach fixes the bug -- I hope it's a bit more straightforward too.

Reviewed by Seraph at https://codereview.productengine.com/secondlife/r/854/

--HG--
branch : product-engine
---
 indra/newview/llfolderview.cpp | 67 ++++++++++++----------------------
 indra/newview/llfolderview.h   |  6 +--
 2 files changed, 26 insertions(+), 47 deletions(-)

diff --git a/indra/newview/llfolderview.cpp b/indra/newview/llfolderview.cpp
index ab36a761534..81f00af9486 100644
--- a/indra/newview/llfolderview.cpp
+++ b/indra/newview/llfolderview.cpp
@@ -62,7 +62,6 @@
 #include "llviewerwindow.h"
 #include "llvoavatar.h"
 #include "llfloaterproperties.h"
-#include "llnotificationsutil.h"
 
 // Linden library includes
 #include "lldbstrings.h"
@@ -105,7 +104,6 @@ void copy_selected_item(void* user_data);
 void open_selected_items(void* user_data);
 void properties_selected_items(void* user_data);
 void paste_items(void* user_data);
-void renamer_focus_lost( LLFocusableElement* handler, void* user_data );
 
 
 //---------------------------------------------------------------------------
@@ -185,6 +183,7 @@ LLFolderView::LLFolderView(const Params& p)
 	mSourceID(p.task_id),
 	mRenameItem( NULL ),
 	mNeedsScroll( FALSE ),
+	mEnableScroll( true ),
 	mUseLabelSuffix(p.use_label_suffix),
 	mPinningSelectedItem(FALSE),
 	mNeedsAutoSelect( FALSE ),
@@ -250,7 +249,7 @@ LLFolderView::LLFolderView(const Params& p)
 	text_p.name(std::string(p.name));
 	text_p.font(font);
 	text_p.visible(false);
-	text_p.parse_urls(true);
+	text_p.allow_html(true);
 	text_p.wrap(true); // allow multiline text. See EXT-7564, EXT-7047
 	// set text padding the same as in People panel. EXT-7047, EXT-4837
 	text_p.h_pad(STATUS_TEXT_HPAD);
@@ -275,6 +274,8 @@ LLFolderView::LLFolderView(const Params& p)
 // Destroys the object
 LLFolderView::~LLFolderView( void )
 {
+	closeRenamer();
+
 	// The release focus call can potentially call the
 	// scrollcontainer, which can potentially be called with a partly
 	// destroyed scollcontainer. Just null it out here, and no worries
@@ -290,8 +291,6 @@ LLFolderView::~LLFolderView( void )
 
 	LLView::deleteViewByHandle(mPopupMenuHandle);
 
-	gViewerWindow->removePopup(mRenamer);
-
 	mAutoOpenItems.removeAllNodes();
 	clearSelection();
 	mItems.clear();
@@ -998,12 +997,7 @@ void LLFolderView::finishRenamingItem( void )
 		mRenameItem->rename( mRenamer->getText() );
 	}
 
-	gViewerWindow->removePopup(mRenamer);
-
-	if( mRenameItem )
-	{
-		setSelectionFromRoot( mRenameItem, TRUE );
-	}
+	closeRenamer();
 
 	// List is re-sorted alphabeticly, so scroll to make sure the selected item is visible.
 	scrollToShowSelection();
@@ -1011,31 +1005,15 @@ void LLFolderView::finishRenamingItem( void )
 
 void LLFolderView::closeRenamer( void )
 {
-	// will commit current name (which could be same as original name)
-	mRenamer->setFocus( FALSE );
-	mRenamer->setVisible( FALSE );
-	gViewerWindow->removePopup(mRenamer);
-
-	if( mRenameItem )
+	if (mRenamer && mRenamer->getVisible())
 	{
-		setSelectionFromRoot( mRenameItem, TRUE );
-		mRenameItem = NULL;
+		// Triggers onRenamerLost() that actually closes the renamer.
+		gViewerWindow->removePopup(mRenamer);
 	}
 }
 
 void LLFolderView::removeSelectedItems( void )
 {
-	if (mSelectedItems.empty()) return;
-	LLSD args;
-	args["QUESTION"] = LLTrans::getString(mSelectedItems.size() > 1 ? "DeleteItems" :  "DeleteItem");
-	LLNotificationsUtil::add("DeleteItems", args, LLSD(), boost::bind(&LLFolderView::onItemsRemovalConfirmation, this, _1, _2));
-}
-
-void LLFolderView::onItemsRemovalConfirmation(const LLSD& notification, const LLSD& response)
-{
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return; // canceled
-
 	if(getVisible() && getEnabled())
 	{
 		// just in case we're removing the renaming item.
@@ -1455,8 +1433,7 @@ void LLFolderView::startRenamingSelectedItem( void )
 		mRenamer->setVisible( TRUE );
 		// set focus will fail unless item is visible
 		mRenamer->setFocus( TRUE );
-		mRenamer->setTopLostCallback(boost::bind(&LLFolderView::onRenamerLost, this, _1));
-		mRenamer->setFocusLostCallback(boost::bind(&LLFolderView::onRenamerLost, this, _1));
+		mRenamer->setTopLostCallback(boost::bind(&LLFolderView::onRenamerLost, this));
 		gViewerWindow->addPopup(mRenamer);
 	}
 }
@@ -1977,10 +1954,7 @@ BOOL LLFolderView::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
 
 void LLFolderView::deleteAllChildren()
 {
-	if(mRenamer == gFocusMgr.getTopCtrl())
-	{
-		gViewerWindow->removePopup(mRenamer);
-	}
+	closeRenamer();
 	LLView::deleteViewByHandle(mPopupMenuHandle);
 	mPopupMenuHandle = LLHandle<LLView>();
 	mRenamer = NULL;
@@ -1991,9 +1965,7 @@ void LLFolderView::deleteAllChildren()
 
 void LLFolderView::scrollToShowSelection()
 {
-	// If items are filtered while background fetch is in progress
-	// scrollbar resets to the first filtered item. See EXT-3981.
-	if (!LLInventoryModelBackgroundFetch::instance().backgroundFetchActive() && mSelectedItems.size())
+	if (mEnableScroll && mSelectedItems.size())
 	{
 		mNeedsScroll = TRUE;
 	}
@@ -2465,13 +2437,20 @@ S32	LLFolderView::notify(const LLSD& info)
 /// Local function definitions
 ///----------------------------------------------------------------------------
 
-void LLFolderView::onRenamerLost( LLFocusableElement* renamer)
+void LLFolderView::onRenamerLost()
 {
-	mRenameItem = NULL;
-	LLUICtrl* uictrl = dynamic_cast<LLUICtrl*>(renamer);
-	if (uictrl)
+	if (mRenamer && mRenamer->getVisible())
 	{
-		uictrl->setVisible(FALSE);
+		mRenamer->setVisible(FALSE);
+
+		// will commit current name (which could be same as original name)
+		mRenamer->setFocus(FALSE);
+	}
+
+	if( mRenameItem )
+	{
+		setSelectionFromRoot( mRenameItem, TRUE );
+		mRenameItem = NULL;
 	}
 }
 
diff --git a/indra/newview/llfolderview.h b/indra/newview/llfolderview.h
index f5f229a6029..31352d04bfe 100644
--- a/indra/newview/llfolderview.h
+++ b/indra/newview/llfolderview.h
@@ -274,6 +274,7 @@ class LLFolderView : public LLFolderViewFolder, public LLEditMenuHandler
 	void dumpSelectionInformation();
 
 	virtual S32	notify(const LLSD& info) ;
+	void setEnableScroll(bool enable_scroll) { mEnableScroll = enable_scroll; }
 	
 	bool useLabelSuffix() { return mUseLabelSuffix; }
 private:
@@ -283,7 +284,7 @@ class LLFolderView : public LLFolderViewFolder, public LLEditMenuHandler
 	LLScrollContainer* mScrollContainer;  // NULL if this is not a child of a scroll container.
 
 	void commitRename( const LLSD& data );
-	void onRenamerLost( LLFocusableElement* renamer);
+	void onRenamerLost();
 
 	void finishRenamingItem( void );
 	void closeRenamer( void );
@@ -293,8 +294,6 @@ class LLFolderView : public LLFolderViewFolder, public LLEditMenuHandler
 	
 	BOOL addNoOptions(LLMenuGL* menu) const;
 
-	void onItemsRemovalConfirmation(const LLSD& notification, const LLSD& response);
-
 protected:
 	LLHandle<LLView>					mPopupMenuHandle;
 	
@@ -310,6 +309,7 @@ class LLFolderView : public LLFolderViewFolder, public LLEditMenuHandler
 	LLLineEditor*					mRenamer;
 
 	BOOL							mNeedsScroll;
+	bool							mEnableScroll;
 	BOOL							mPinningSelectedItem;
 	LLRect							mScrollConstraintRect;
 	BOOL							mNeedsAutoSelect;
-- 
GitLab