/indra/newview/llpreviewscript.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 290 lines · 201 code · 57 blank · 32 comment · 0 complexity · 2b23edd3534fa91b8b4f4461ec4c20c6 MD5 · raw file

  1. /**
  2. * @file llpreviewscript.h
  3. * @brief LLPreviewScript class definition
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #ifndef LL_LLPREVIEWSCRIPT_H
  27. #define LL_LLPREVIEWSCRIPT_H
  28. #include "lldarray.h"
  29. #include "llpreview.h"
  30. #include "lltabcontainer.h"
  31. #include "llinventory.h"
  32. #include "llcombobox.h"
  33. #include "lliconctrl.h"
  34. #include "llframetimer.h"
  35. class LLLiveLSLFile;
  36. class LLMessageSystem;
  37. class LLTextEditor;
  38. class LLButton;
  39. class LLCheckBoxCtrl;
  40. class LLScrollListCtrl;
  41. class LLViewerObject;
  42. struct LLEntryAndEdCore;
  43. class LLMenuBarGL;
  44. class LLFloaterScriptSearch;
  45. class LLKeywordToken;
  46. class LLVFS;
  47. class LLViewerInventoryItem;
  48. class LLScriptEdContainer;
  49. // Inner, implementation class. LLPreviewScript and LLLiveLSLEditor each own one of these.
  50. class LLScriptEdCore : public LLPanel
  51. {
  52. friend class LLPreviewScript;
  53. friend class LLPreviewLSL;
  54. friend class LLLiveLSLEditor;
  55. friend class LLFloaterScriptSearch;
  56. friend class LLScriptEdContainer;
  57. protected:
  58. // Supposed to be invoked only by the container.
  59. LLScriptEdCore(
  60. LLScriptEdContainer* container,
  61. const std::string& sample,
  62. const LLHandle<LLFloater>& floater_handle,
  63. void (*load_callback)(void* userdata),
  64. void (*save_callback)(void* userdata, BOOL close_after_save),
  65. void (*search_replace_callback)(void* userdata),
  66. void* userdata,
  67. S32 bottom_pad = 0); // pad below bottom row of buttons
  68. public:
  69. ~LLScriptEdCore();
  70. void initMenu();
  71. virtual void draw();
  72. /*virtual*/ BOOL postBuild();
  73. BOOL canClose();
  74. void setEnableEditing(bool enable);
  75. bool canLoadOrSaveToFile( void* userdata );
  76. void setScriptText(const std::string& text, BOOL is_valid);
  77. bool loadScriptText(const std::string& filename);
  78. bool writeToFile(const std::string& filename);
  79. void sync();
  80. void doSave( BOOL close_after_save );
  81. bool handleSaveChangesDialog(const LLSD& notification, const LLSD& response);
  82. bool handleReloadFromServerDialog(const LLSD& notification, const LLSD& response);
  83. void openInExternalEditor();
  84. static void onCheckLock(LLUICtrl*, void*);
  85. static void onHelpComboCommit(LLUICtrl* ctrl, void* userdata);
  86. static void onClickBack(void* userdata);
  87. static void onClickForward(void* userdata);
  88. static void onBtnInsertSample(void*);
  89. static void onBtnInsertFunction(LLUICtrl*, void*);
  90. static void onBtnLoadFromFile(void*);
  91. static void onBtnSaveToFile(void*);
  92. static bool enableSaveToFileMenu(void* userdata);
  93. static bool enableLoadFromFileMenu(void* userdata);
  94. virtual bool hasAccelerators() const { return true; }
  95. private:
  96. void onBtnHelp();
  97. void onBtnDynamicHelp();
  98. void onBtnUndoChanges();
  99. bool hasChanged();
  100. void selectFirstError();
  101. virtual BOOL handleKeyHere(KEY key, MASK mask);
  102. void enableSave(BOOL b) {mEnableSave = b;}
  103. protected:
  104. void deleteBridges();
  105. void setHelpPage(const std::string& help_string);
  106. void updateDynamicHelp(BOOL immediate = FALSE);
  107. void addHelpItemToHistory(const std::string& help_string);
  108. static void onErrorList(LLUICtrl*, void* user_data);
  109. private:
  110. std::string mSampleText;
  111. LLTextEditor* mEditor;
  112. void (*mLoadCallback)(void* userdata);
  113. void (*mSaveCallback)(void* userdata, BOOL close_after_save);
  114. void (*mSearchReplaceCallback) (void* userdata);
  115. void* mUserdata;
  116. LLComboBox *mFunctions;
  117. BOOL mForceClose;
  118. LLPanel* mCodePanel;
  119. LLScrollListCtrl* mErrorList;
  120. LLDynamicArray<LLEntryAndEdCore*> mBridges;
  121. LLHandle<LLFloater> mLiveHelpHandle;
  122. LLKeywordToken* mLastHelpToken;
  123. LLFrameTimer mLiveHelpTimer;
  124. S32 mLiveHelpHistorySize;
  125. BOOL mEnableSave;
  126. BOOL mHasScriptData;
  127. LLLiveLSLFile* mLiveFile;
  128. LLScriptEdContainer* mContainer; // parent view
  129. };
  130. class LLScriptEdContainer : public LLPreview
  131. {
  132. friend class LLScriptEdCore;
  133. public:
  134. LLScriptEdContainer(const LLSD& key);
  135. protected:
  136. std::string getTmpFileName();
  137. bool onExternalChange(const std::string& filename);
  138. virtual void saveIfNeeded(bool sync = true) = 0;
  139. LLScriptEdCore* mScriptEd;
  140. };
  141. // Used to view and edit a LSL from your inventory.
  142. class LLPreviewLSL : public LLScriptEdContainer
  143. {
  144. public:
  145. LLPreviewLSL(const LLSD& key );
  146. virtual void callbackLSLCompileSucceeded();
  147. virtual void callbackLSLCompileFailed(const LLSD& compile_errors);
  148. /*virtual*/ BOOL postBuild();
  149. protected:
  150. virtual BOOL canClose();
  151. void closeIfNeeded();
  152. virtual void loadAsset();
  153. /*virtual*/ void saveIfNeeded(bool sync = true);
  154. void uploadAssetViaCaps(const std::string& url,
  155. const std::string& filename,
  156. const LLUUID& item_id);
  157. void uploadAssetLegacy(const std::string& filename,
  158. const LLUUID& item_id,
  159. const LLTransactionID& tid);
  160. static void onSearchReplace(void* userdata);
  161. static void onLoad(void* userdata);
  162. static void onSave(void* userdata, BOOL close_after_save);
  163. static void onLoadComplete(LLVFS *vfs, const LLUUID& uuid,
  164. LLAssetType::EType type,
  165. void* user_data, S32 status, LLExtStat ext_status);
  166. static void onSaveComplete(const LLUUID& uuid, void* user_data, S32 status, LLExtStat ext_status);
  167. static void onSaveBytecodeComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status);
  168. protected:
  169. static void* createScriptEdPanel(void* userdata);
  170. protected:
  171. // Can safely close only after both text and bytecode are uploaded
  172. S32 mPendingUploads;
  173. };
  174. // Used to view and edit an LSL that is attached to an object.
  175. class LLLiveLSLEditor : public LLScriptEdContainer
  176. {
  177. friend class LLLiveLSLFile;
  178. public:
  179. LLLiveLSLEditor(const LLSD& key);
  180. static void processScriptRunningReply(LLMessageSystem* msg, void**);
  181. virtual void callbackLSLCompileSucceeded(const LLUUID& task_id,
  182. const LLUUID& item_id,
  183. bool is_script_running);
  184. virtual void callbackLSLCompileFailed(const LLSD& compile_errors);
  185. /*virtual*/ BOOL postBuild();
  186. void setIsNew() { mIsNew = TRUE; }
  187. private:
  188. virtual BOOL canClose();
  189. void closeIfNeeded();
  190. virtual void draw();
  191. virtual void loadAsset();
  192. void loadAsset(BOOL is_new);
  193. /*virtual*/ void saveIfNeeded(bool sync = true);
  194. void uploadAssetViaCaps(const std::string& url,
  195. const std::string& filename,
  196. const LLUUID& task_id,
  197. const LLUUID& item_id,
  198. BOOL is_running);
  199. void uploadAssetLegacy(const std::string& filename,
  200. LLViewerObject* object,
  201. const LLTransactionID& tid,
  202. BOOL is_running);
  203. BOOL monoChecked() const;
  204. static void onSearchReplace(void* userdata);
  205. static void onLoad(void* userdata);
  206. static void onSave(void* userdata, BOOL close_after_save);
  207. static void onLoadComplete(LLVFS *vfs, const LLUUID& asset_uuid,
  208. LLAssetType::EType type,
  209. void* user_data, S32 status, LLExtStat ext_status);
  210. static void onSaveTextComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status);
  211. static void onSaveBytecodeComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status);
  212. static void onRunningCheckboxClicked(LLUICtrl*, void* userdata);
  213. static void onReset(void* userdata);
  214. void loadScriptText(LLVFS *vfs, const LLUUID &uuid, LLAssetType::EType type);
  215. static void onErrorList(LLUICtrl*, void* user_data);
  216. static void* createScriptEdPanel(void* userdata);
  217. static void onMonoCheckboxClicked(LLUICtrl*, void* userdata);
  218. private:
  219. bool mIsNew;
  220. //LLUUID mTransmitID;
  221. LLCheckBoxCtrl* mRunningCheckbox;
  222. BOOL mAskedForRunningInfo;
  223. BOOL mHaveRunningInfo;
  224. LLButton* mResetButton;
  225. LLPointer<LLViewerInventoryItem> mItem;
  226. BOOL mCloseAfterSave;
  227. // need to save both text and script, so need to decide when done
  228. S32 mPendingUploads;
  229. BOOL getIsModifiable() const { return mIsModifiable; } // Evaluated on load assert
  230. LLCheckBoxCtrl* mMonoCheckbox;
  231. BOOL mIsModifiable;
  232. };
  233. #endif // LL_LLPREVIEWSCRIPT_H