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