PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloaterscriptdebug.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 173 lines | 103 code | 27 blank | 43 comment | 9 complexity | ea0a05da6bbf003d37a12472af4032ae MD5 | raw file
  1/** 
  2 * @file llfloaterscriptdebug.cpp
  3 * @brief Chat window for showing script errors and warnings
  4 *
  5 * $LicenseInfo:firstyear=2006&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 "llfloaterscriptdebug.h"
 30
 31#include "llfloaterreg.h"
 32#include "lluictrlfactory.h"
 33#include "llfontgl.h"
 34#include "llrect.h"
 35#include "llerror.h"
 36#include "llstring.h"
 37#include "message.h"
 38
 39// project include
 40#include "llviewertexteditor.h"
 41#include "llviewercontrol.h"
 42#include "llviewerobjectlist.h"
 43#include "llviewertexturelist.h"
 44
 45//
 46// Statics
 47//
 48
 49//
 50// Member Functions
 51//
 52LLFloaterScriptDebug::LLFloaterScriptDebug(const LLSD& key)
 53  : LLMultiFloater(key)
 54{
 55	// avoid resizing of the window to match 
 56	// the initial size of the tabbed-childs, whenever a tab is opened or closed
 57	mAutoResize = FALSE;
 58	// enabled autocous blocks controling focus via  LLFloaterReg::showInstance
 59	setAutoFocus(FALSE);
 60}
 61
 62LLFloaterScriptDebug::~LLFloaterScriptDebug()
 63{
 64}
 65
 66void LLFloaterScriptDebug::show(const LLUUID& object_id)
 67{
 68	addOutputWindow(object_id);
 69}
 70
 71BOOL LLFloaterScriptDebug::postBuild()
 72{
 73	LLMultiFloater::postBuild();
 74
 75	if (mTabContainer)
 76	{
 77		return TRUE;
 78	}
 79
 80	return FALSE;
 81}
 82
 83LLFloater* LLFloaterScriptDebug::addOutputWindow(const LLUUID &object_id)
 84{
 85	LLMultiFloater* host = LLFloaterReg::showTypedInstance<LLMultiFloater>("script_debug", LLSD());
 86	if (!host)
 87		return NULL;
 88
 89	LLFloater::setFloaterHost(host);
 90	// prevent stealing focus, see EXT-8040
 91	LLFloater* floaterp = LLFloaterReg::showInstance("script_debug_output", object_id, FALSE);
 92	LLFloater::setFloaterHost(NULL);
 93
 94	return floaterp;
 95}
 96
 97void LLFloaterScriptDebug::addScriptLine(const std::string &utf8mesg, const std::string &user_name, const LLColor4& color, const LLUUID& source_id)
 98{
 99	LLViewerObject* objectp = gObjectList.findObject(source_id);
100	std::string floater_label;
101
102	// Handle /me messages.
103	std::string prefix = utf8mesg.substr(0, 4);
104	std::string message = (prefix == "/me " || prefix == "/me'") ? user_name + utf8mesg.substr(3) : utf8mesg;
105
106	if (objectp)
107	{
108		objectp->setIcon(LLViewerTextureManager::getFetchedTextureFromFile("script_error.j2c", TRUE, LLViewerTexture::BOOST_UI));
109		floater_label = llformat("%s(%.2f, %.2f)", user_name.c_str(), objectp->getPositionRegion().mV[VX], objectp->getPositionRegion().mV[VY]);
110	}
111	else
112	{
113		floater_label = user_name;
114	}
115
116	addOutputWindow(LLUUID::null);
117	addOutputWindow(source_id);
118
119	// add to "All" floater
120	LLFloaterScriptDebugOutput* floaterp = 	LLFloaterReg::getTypedInstance<LLFloaterScriptDebugOutput>("script_debug_output", LLUUID::null);
121	if (floaterp)
122	{
123		floaterp->addLine(message, user_name, color);
124	}
125	
126	// add to specific script instance floater
127	floaterp = LLFloaterReg::getTypedInstance<LLFloaterScriptDebugOutput>("script_debug_output", source_id);
128	if (floaterp)
129	{
130		floaterp->addLine(message, floater_label, color);
131	}
132}
133
134//
135// LLFloaterScriptDebugOutput
136//
137
138LLFloaterScriptDebugOutput::LLFloaterScriptDebugOutput(const LLSD& object_id)
139  : LLFloater(LLSD(object_id)),
140	mObjectID(object_id.asUUID())
141{
142	// enabled autocous blocks controling focus via  LLFloaterReg::showInstance
143	setAutoFocus(FALSE);
144}
145
146BOOL LLFloaterScriptDebugOutput::postBuild()
147{
148	LLFloater::postBuild();
149	mHistoryEditor = getChild<LLViewerTextEditor>("Chat History Editor");
150	return TRUE;
151}
152
153LLFloaterScriptDebugOutput::~LLFloaterScriptDebugOutput()
154{
155}
156
157void LLFloaterScriptDebugOutput::addLine(const std::string &utf8mesg, const std::string &user_name, const LLColor4& color)
158{
159	if (mObjectID.isNull())
160	{
161		setCanTearOff(FALSE);
162		setCanClose(FALSE);
163	}
164	else
165	{
166		setTitle(user_name);
167		setShortTitle(user_name);
168	}
169
170	mHistoryEditor->appendText(utf8mesg, true, LLStyle::Params().color(color));
171	mHistoryEditor->blockUndo();
172}
173