llpreviewscript.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * @file llpreviewscript.h
  3. * @brief LLPreviewScript and LLLiveLSLEditor classes definition
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLPREVIEWSCRIPT_H
  33. #define LL_LLPREVIEWSCRIPT_H
  34. #include "llassettype.h"
  35. #include "hbfileselector.h"
  36. #include "llpreview.h"
  37. class LLButton;
  38. class LLCheckBoxCtrl;
  39. class LLComboBox;
  40. class LLFontGL;
  41. class LLMessageSystem;
  42. class LLScriptEditor;
  43. class LLTextEditor;
  44. // Used to view and edit a LSL script in your inventory.
  45. class LLPreviewScript final : public LLPreview
  46. {
  47. protected:
  48. LOG_CLASS(LLPreviewScript);
  49. public:
  50. LLPreviewScript(const std::string& name, const LLRect& rect,
  51. const std::string& title, const LLUUID& item_uuid);
  52. void open() override;
  53. static LLPreviewScript* getInstance(const LLUUID& uuid);
  54. LLTextEditor* getEditor();
  55. // Wrapper methods to setup LLScriptEditor implementation class defaults
  56. static void loadFunctions(const std::string& filename);
  57. static void refreshCachedSettings();
  58. static LLFontGL* getCustomFont();
  59. protected:
  60. bool canClose() override;
  61. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  62. LL_INLINE const char* getTitleName() const override { return "Script"; }
  63. void loadAsset() override;
  64. static void onSearchReplace(void* userdata);
  65. static void onLoad(void* userdata);
  66. static void onSave(void* userdata, bool close_after_save);
  67. private:
  68. void saveIfNeeded();
  69. void closeIfNeeded();
  70. void callbackLSLCompileSucceeded();
  71. void callbackLSLCompileFailed(const LLSD& compile_errors);
  72. static void finishLSLUpload(LLUUID item_id, LLSD response);
  73. static void failedLSLUpload(LLUUID item_id, std::string reason);
  74. static void onLoadComplete(const LLUUID& asset_id, LLAssetType::EType type,
  75. void* user_data, S32 status, LLExtStat);
  76. static void* createScriptEdPanel(void* userdata);
  77. protected:
  78. LLScriptEditor* mScriptEd;
  79. };
  80. // Used to view and edit a LSL script that is attached to an object.
  81. class LLLiveLSLEditor final : public LLPreview
  82. {
  83. protected:
  84. LOG_CLASS(LLLiveLSLEditor);
  85. public:
  86. LLLiveLSLEditor(const std::string& name, const LLRect& rect,
  87. const std::string& title,
  88. const LLUUID& object_id, const LLUUID& item_id);
  89. ~LLLiveLSLEditor() override;
  90. static LLLiveLSLEditor* show(const LLUUID& item_id, const LLUUID& object_id);
  91. static void hide(const LLUUID& item_id, const LLUUID& object_id);
  92. static LLLiveLSLEditor* find(const LLUUID& item_id, const LLUUID& object_id);
  93. // Overide LLPreview::open() to avoid calling loadAsset twice.
  94. void open() override;
  95. void setExperienceIds(const LLSD& experience_ids);
  96. // Callback for message system, linked in llstartup.cpp
  97. static void processScriptRunningReply(LLMessageSystem* msg, void**);
  98. protected:
  99. bool canClose() override;
  100. void draw() override;
  101. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  102. // This is called via LLPreview::loadAsset() virtual method
  103. LL_INLINE void loadAsset() override { loadAsset(false); }
  104. // Evaluated on assert loading
  105. LL_INLINE bool getIsModifiable() const { return mIsModifiable; }
  106. static void finishLSLUpload(LLUUID item_id, LLUUID task_id,
  107. LLUUID new_asset_id, LLSD response,
  108. bool running);
  109. static void failedLSLUpload(LLUUID item_id, LLUUID task_id,
  110. std::string reason);
  111. static void receiveExperienceIds(LLSD result,
  112. LLHandle<LLLiveLSLEditor> parent);
  113. static void onSearchReplace(void* userdata);
  114. static void onLoad(void* userdata);
  115. static void onSave(void* userdata, bool close_after_save);
  116. private:
  117. void buildExperienceList();
  118. void updateExperienceControls();
  119. void requestExperiences();
  120. void saveIfNeeded();
  121. void closeIfNeeded();
  122. void loadAsset(bool is_new);
  123. void callbackLSLCompileSucceeded(const LLUUID& task_id,
  124. const LLUUID& item_id,
  125. bool is_script_running);
  126. void callbackLSLCompileFailed(const LLSD& compile_errors);
  127. static void onLoadComplete(const LLUUID& asset_id, LLAssetType::EType type,
  128. void* user_data, S32 status, LLExtStat);
  129. static void onRunningCheckboxClicked(LLUICtrl*, void* userdata);
  130. static void onReset(void* userdata);
  131. static void experienceChanged(LLUICtrl*, void* data);
  132. static void setAssociatedExperience(LLHandle<LLLiveLSLEditor> editor,
  133. const LLSD& experience);
  134. static void onToggleExperience(LLUICtrl*, void* userdata);
  135. static void onViewProfile(void* userdata);
  136. void loadScriptText(const LLUUID& id, LLAssetType::EType type);
  137. static void onErrorList(LLUICtrl*, void* user_data);
  138. static void* createScriptEdPanel(void* userdata);
  139. protected:
  140. typedef fast_hmap<LLUUID, LLLiveLSLEditor*> instances_map_t;
  141. static instances_map_t sInstances;
  142. LLPointer<LLViewerInventoryItem> mItem;
  143. // The inventory item this script is associated with:
  144. LLUUID mItemID;
  145. // The object this script is associated with:
  146. LLUUID mObjectID;
  147. LLScriptEditor* mScriptEd;
  148. LLButton* mResetButton;
  149. LLButton* mViewProfileButton;
  150. LLCheckBoxCtrl* mRunningCheckbox;
  151. LLCheckBoxCtrl* mExperienceEnabled;
  152. LLComboBox* mExperiences;
  153. LLSD mExperienceIds;
  154. std::string mScriptRunningText;
  155. std::string mCannotRunText;
  156. std::string mOutOfRange;
  157. bool mIsNew;
  158. bool mAskedForRunningInfo;
  159. bool mHaveRunningInfo;
  160. bool mCloseAfterSave;
  161. private:
  162. bool mIsModifiable;
  163. bool mIsSaving;
  164. };
  165. #endif // LL_LLPREVIEWSCRIPT_H