PageRenderTime 30ms CodeModel.GetById 1ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

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