void LLTeleportHistoryStorage::onTeleportHistoryChange()
{
	LLTeleportHistory *th = LLTeleportHistory::getInstance();
	if (!th)
		return;

	// Hacky sanity check. (EXT-6798)
	if (th->getItems().size() == 0)
	{
		llassert(!"Inconsistent teleport history state");
		return;
	}

	const LLTeleportHistoryItem &item = th->getItems()[th->getCurrentItemIndex()];
// [RLVa:KB] - Checked: 2010-09-03 (RLVa-1.2.1b) | Added: RLVa-1.2.1b
	// Make sure we don't attempt to save zero'ed out teleport history items
	if (item.mGlobalPos.isExactlyZero())
	{
		return;
	}
// [/RLVa:KB]

	addItem(item.mTitle, item.mGlobalPos);
	save();
}
void LLNavigationBar::onTeleportHistoryChanged()
{
	// Update navigation controls.
	LLTeleportHistory* h = LLTeleportHistory::getInstance();
	int cur_item = h->getCurrentItemIndex();
	mBtnBack->setEnabled(cur_item > 0);
	mBtnForward->setEnabled(cur_item < ((int)h->getItems().size() - 1));
}
void LLTeleportHistoryStorage::onTeleportHistoryChange()
{
    LLTeleportHistory *th = LLTeleportHistory::getInstance();
    if (!th)
        return;

    // Hacky sanity check. (EXT-6798)
    if (th->getItems().size() == 0)
    {
        llassert(!"Inconsistent teleport history state");
        return;
    }

    const LLTeleportHistoryItem &item = th->getItems()[th->getCurrentItemIndex()];

    addItem(item.mTitle, item.mGlobalPos);
    save();
}
void LLLocationInputCtrl::onLocationPrearrange(const LLSD& data)
{
	std::string filter = data.asString();
	rebuildLocationHistory(filter);

	//Let's add landmarks to the top of the list if any
	if(!filter.empty() )
	{
		LLInventoryModel::item_array_t landmark_items = LLLandmarkActions::fetchLandmarksByName(filter, TRUE);

		for(U32 i=0; i < landmark_items.size(); i++)
		{
			LLSD value;
			//TODO:: DO we need tooltip for Landmark??
			
			value["item_type"] = LANDMARK;
			value["AssetUUID"] =  landmark_items[i]->getAssetUUID(); 
			add(landmark_items[i]->getName(), value);
			
		}
	//Let's add teleport history items
		LLTeleportHistory* th = LLTeleportHistory::getInstance();
		LLTeleportHistory::slurl_list_t th_items = th->getItems();

		std::set<std::string> new_item_titles;// duplicate control
		LLTeleportHistory::slurl_list_t::iterator result = std::find_if(
				th_items.begin(), th_items.end(), boost::bind(
						&LLLocationInputCtrl::findTeleportItemsByTitle, this,
						_1, filter));

		while (result != th_items.end())
		{
			//mTitile format - region_name[, parcel_name]
			//mFullTitile format - region_name[, parcel_name] (local_x,local_y, local_z)
			if (new_item_titles.insert(result->mFullTitle).second)
			{
				LLSD value;
				value["item_type"] = TELEPORT_HISTORY;
				value["global_pos"] = result->mGlobalPos.getValue();
				std::string region_name = result->mTitle.substr(0, result->mTitle.find(','));
				//TODO*: add Surl to teleportitem or parse region name from title
				value["tooltip"] = LLSLURL::buildSLURLfromPosGlobal(region_name,
						result->mGlobalPos,	false);
				add(result->getTitle(), value); 
			}
			result = std::find_if(result + 1, th_items.end(), boost::bind(
									&LLLocationInputCtrl::findTeleportItemsByTitle, this,
									_1, filter));
		}
	}
	sortByName();
	
	mList->mouseOverHighlightNthItem(-1); // Clear highlight on the last selected item.
}
void LLNavigationBar::rebuildTeleportHistoryMenu()
{
	// Has the pop-up menu been built?
	if (mTeleportHistoryMenu)
	{
		// Clear it.
		mTeleportHistoryMenu->empty();
	}
	else
	{
		// Create it.
		LLMenuGL::Params menu_p;
		menu_p.name("popup");
		menu_p.can_tear_off(false);
		menu_p.visible(false);
		menu_p.bg_visible(true);
		menu_p.scrollable(true);
		mTeleportHistoryMenu = LLUICtrlFactory::create<LLMenuGL>(menu_p);
		
		addChild(mTeleportHistoryMenu);
	}
	
	// Populate the menu with teleport history items.
	LLTeleportHistory* hist = LLTeleportHistory::getInstance();
	const LLTeleportHistory::slurl_list_t& hist_items = hist->getItems();
	int cur_item = hist->getCurrentItemIndex();
	
	// Items will be shown in the reverse order, just like in Firefox.
	for (int i = (int)hist_items.size()-1; i >= 0; i--)
	{
		LLTeleportHistoryMenuItem::EType type;
		if (i < cur_item)
			type = LLTeleportHistoryMenuItem::TYPE_BACKWARD;
		else if (i > cur_item)
			type = LLTeleportHistoryMenuItem::TYPE_FORWARD;
		else
			type = LLTeleportHistoryMenuItem::TYPE_CURRENT;

		LLTeleportHistoryMenuItem::Params item_params;
		item_params.label = item_params.name = hist_items[i].mTitle;
		item_params.item_type = type;
		item_params.on_click.function(boost::bind(&LLNavigationBar::onTeleportHistoryMenuItemClicked, this, i));
		LLTeleportHistoryMenuItem* new_itemp = LLUICtrlFactory::create<LLTeleportHistoryMenuItem>(item_params);
		//new_itemp->setFont()
		mTeleportHistoryMenu->addChild(new_itemp);
	}
}
// Checked: 2010-04-22 (RLVa-1.2.0f) | Modified: RLVa-1.2.0f
void RlvUIEnabler::onToggleShowLoc()
{
    bool fEnable = !gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC);

    if (LLNavigationBar::instanceExists())
        LLNavigationBar::instance().refreshLocationCtrl();
    if (LLPanelTopInfoBar::instanceExists())
        LLPanelTopInfoBar::instance().update();

    if (!fEnable)
    {
        // Hide the "About Land" floater if it's currently visible
        if (LLFloaterReg::instanceVisible("about_land"))
            LLFloaterReg::hideInstance("about_land");
        // Hide the "Region / Estate" floater if it's currently visible
        if (LLFloaterReg::instanceVisible("region_info"))
            LLFloaterReg::hideInstance("region_info");
        // Hide the "God Tools" floater if it's currently visible
        if (LLFloaterReg::instanceVisible("god_tools"))
            LLFloaterReg::hideInstance("god_tools");

        //
        // Manipulate the teleport history
        //

        // If the last entry in the persistent teleport history matches the current teleport history entry then we should remove it
        LLTeleportHistory* pTpHistory = LLTeleportHistory::getInstance();
        LLTeleportHistoryStorage* pTpHistoryStg = LLTeleportHistoryStorage::getInstance();
        RLV_ASSERT( (pTpHistory) && (pTpHistoryStg) && (pTpHistory->getItems().size() > 0) && (pTpHistory->getCurrentItemIndex() >= 0) );
        if ( (pTpHistory) && (pTpHistory->getItems().size() > 0) && (pTpHistory->getCurrentItemIndex() >= 0) &&
                (pTpHistoryStg) && (pTpHistory->getItems().size() > 0) )
        {
            const LLTeleportHistoryItem& tpItem = pTpHistory->getItems().back();
            const LLTeleportHistoryPersistentItem& tpItemStg = pTpHistoryStg->getItems().back();
            if (pTpHistoryStg->compareByTitleAndGlobalPos(tpItemStg, LLTeleportHistoryPersistentItem(tpItem.mTitle, tpItem.mGlobalPos)))
            {
                // TODO-RLVa: [RLVa-1.2.2] Is there a reason why LLTeleportHistoryStorage::removeItem() doesn't trigger history changed?
                pTpHistoryStg->removeItem(pTpHistoryStg->getItems().size() - 1);
                pTpHistoryStg->mHistoryChangedSignal(-1);
            }
        }

        // Clear the current location in the teleport history
        if (pTpHistory)
            pTpHistory->updateCurrentLocation(gAgent.getPositionGlobal());
    }
    else
    {
        // Reset the current location in the teleport history (also takes care of adding it to the persistent teleport history)
        LLTeleportHistory* pTpHistory = LLTeleportHistory::getInstance();
        if ( (pTpHistory) && (NULL != gAgent.getRegion()) )
            pTpHistory->updateCurrentLocation(gAgent.getPositionGlobal());
    }

    // Start or stop filtering the "About Land" and "Region / Estate" floaters
    if ( (!fEnable) && (!m_ConnFloaterShowLoc.connected()) )
    {
        m_ConnFloaterShowLoc = LLFloaterReg::setValidateCallback(boost::bind(&RlvUIEnabler::filterFloaterShowLoc, this, _1, _2));
        m_ConnPanelShowLoc = LLFloaterSidePanelContainer::setValidateCallback(boost::bind(&RlvUIEnabler::filterPanelShowLoc, this, _1, _2, _3));
    }
    else if ( (fEnable) && (m_ConnFloaterShowLoc.connected()) )
    {
        m_ConnFloaterShowLoc.disconnect();
        m_ConnPanelShowLoc.disconnect();
    }
}