PageRenderTime 1050ms CodeModel.GetById 817ms app.highlight 8ms RepoModel.GetById 223ms app.codeStats 0ms

/indra/newview/llsaveoutfitcombobtn.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 92 lines | 50 code | 13 blank | 29 comment | 3 complexity | fc33dfc41cfff60da60f513e8e5ed49e MD5 | raw file
 1/** 
 2 * @file llsaveoutfitcombobtn.cpp
 3 * @brief Represents outfit save/save as combo button.
 4 *
 5 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#include "llviewerprecompiledheaders.h"
28
29#include "llappearancemgr.h"
30#include "llpaneloutfitsinventory.h"
31#include "llsidepanelappearance.h"
32#include "llsaveoutfitcombobtn.h"
33#include "llviewermenu.h"
34
35static const std::string SAVE_BTN("save_btn");
36static const std::string SAVE_FLYOUT_BTN("save_flyout_btn");
37
38LLSaveOutfitComboBtn::LLSaveOutfitComboBtn(LLPanel* parent, bool saveAsDefaultAction):
39	mParent(parent), mSaveAsDefaultAction(saveAsDefaultAction)
40{
41	// register action mapping before creating menu
42	LLUICtrl::CommitCallbackRegistry::ScopedRegistrar save_registar;
43	save_registar.add("Outfit.Save.Action", boost::bind(
44			&LLSaveOutfitComboBtn::saveOutfit, this, false));
45	save_registar.add("Outfit.SaveAs.Action", boost::bind(
46			&LLSaveOutfitComboBtn::saveOutfit, this, true));
47
48	mParent->childSetAction(SAVE_BTN, boost::bind(&LLSaveOutfitComboBtn::saveOutfit, this, mSaveAsDefaultAction));
49	mParent->childSetAction(SAVE_FLYOUT_BTN, boost::bind(&LLSaveOutfitComboBtn::showSaveMenu, this));
50
51	mSaveMenu = LLUICtrlFactory::getInstance()->createFromFile<
52			LLToggleableMenu> ("menu_save_outfit.xml", gMenuHolder,
53			LLViewerMenuHolderGL::child_registry_t::instance());
54}
55
56void LLSaveOutfitComboBtn::showSaveMenu()
57{
58	S32 x, y;
59	LLUI::getMousePositionLocal(mParent, &x, &y);
60
61	mSaveMenu->updateParent(LLMenuGL::sMenuContainer);
62	LLMenuGL::showPopup(mParent, mSaveMenu, x, y);
63}
64
65void LLSaveOutfitComboBtn::saveOutfit(bool as_new)
66{
67	if (!as_new && LLAppearanceMgr::getInstance()->updateBaseOutfit())
68	{
69		// we don't need to ask for an outfit name, and updateBaseOutfit() successfully saved.
70		// If updateBaseOutfit fails, ask for an outfit name anyways
71		return;
72	}
73
74	LLPanelOutfitsInventory* panel_outfits_inventory =
75			LLPanelOutfitsInventory::findInstance();
76	if (panel_outfits_inventory)
77	{
78		panel_outfits_inventory->onSave();
79	}
80
81	//*TODO how to get to know when base outfit is updated or new outfit is created?
82}
83
84void LLSaveOutfitComboBtn::setMenuItemEnabled(const std::string& item, bool enabled)
85{
86	mSaveMenu->setItemEnabled("save_outfit", enabled);
87}
88
89void LLSaveOutfitComboBtn::setSaveBtnEnabled(bool enabled)
90{
91	mParent->getChildView(SAVE_BTN)->setEnabled(enabled);
92}