llpreviewnotecard.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. * @file llpreviewnotecard.h
  3. * @brief LLPreviewNotecard class declaration
  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_LLPREVIEWNOTECARD_H
  33. #define LL_LLPREVIEWNOTECARD_H
  34. #include "llassettype.h"
  35. #include "llextendedstatus.h"
  36. #include "hbfileselector.h"
  37. #include "llpreview.h"
  38. #include "llvoinventorylistener.h"
  39. class LLButton;
  40. class HBExternalEditor;
  41. class LLFontGL;
  42. class LLIconCtrl;
  43. class LLLineEditor;
  44. class LLMenuItemCheckGL;
  45. class LLTextEditor;
  46. class LLViewerTextEditor;
  47. // This class allows to edit notecards
  48. class LLPreviewNotecard final : public LLPreview, public LLVOInventoryListener
  49. {
  50. protected:
  51. LOG_CLASS(LLPreviewNotecard);
  52. public:
  53. LLPreviewNotecard(const std::string& name, const LLRect& rect,
  54. const std::string& title, const LLUUID& item_id,
  55. const LLUUID& object_id = LLUUID::null,
  56. const LLUUID& asset_id = LLUUID::null,
  57. bool show_keep_discard = false,
  58. LLPointer<LLViewerInventoryItem> itemp = NULL);
  59. ~LLPreviewNotecard() override;
  60. // LLPreview override
  61. bool saveItem(LLPointer<LLInventoryItem>* itemptr) override;
  62. // LLView overrides
  63. void draw() override;
  64. bool handleKeyHere(KEY key, MASK mask) override;
  65. void setEnabled(bool enabled) override;
  66. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  67. // LLFloater override
  68. bool canClose() override;
  69. // LLPanel override
  70. bool postBuild() override;
  71. const LLInventoryItem* getDragItem();
  72. // Returns true if there is any embedded inventory.
  73. bool hasEmbeddedInventory();
  74. // After saving a notecard, the tcp based upload system will change the
  75. // asset, therefore, we need to re-fetch it from the asset system. :(
  76. void refreshFromInventory();
  77. LL_INLINE LLTextEditor* getEditor() { return (LLTextEditor*)mEditor; }
  78. // LLVOInventoryListener override
  79. void inventoryChanged(LLViewerObject*, LLInventoryObject::object_list_t*,
  80. S32, void*) override;
  81. static void refreshCachedSettings();
  82. static LLFontGL* getCustomFont() { return sCustomFont; }
  83. private:
  84. // LLPreview overrides
  85. void loadAsset() override;
  86. LL_INLINE const char* getTitleName() const override { return "Note"; }
  87. bool loadFile(const std::string& filename);
  88. bool saveFile(std::string& filename);
  89. bool saveIfNeeded(LLInventoryItem* copyitem = NULL);
  90. static void finishInventoryUpload(LLUUID item_id, LLUUID new_asset_id,
  91. LLUUID new_item_id);
  92. static void finishTaskUpload(LLUUID item_id, LLUUID new_asset_id);
  93. void setNoteName(std::string name);
  94. void setObjectID(const LLUUID& object_id) override;
  95. static LLPreviewNotecard* getInstance(const LLUUID& uuid);
  96. static void onLoadComplete(const LLUUID& asset_uuid,
  97. LLAssetType::EType type, void* user_data,
  98. S32 status, LLExtStat);
  99. static void onClickSave(void* data);
  100. static void onSaveComplete(const LLUUID& asset_uuid, void* user_data,
  101. S32 status, LLExtStat);
  102. bool handleSaveChangesDialog(const LLSD& notification,
  103. const LLSD& response);
  104. static void onLoadFromFile(void* userdata);
  105. static void loadFromFileCallback(HBFileSelector::ELoadFilter,
  106. std::string& filename, void* userdata);
  107. static void onSaveToFile(void* userdata);
  108. static void saveToFileCallback(HBFileSelector::ESaveFilter,
  109. std::string& filename, void* userdata);
  110. static void onEditedFileChanged(const std::string& filename,
  111. void* userdata);
  112. static void onEditExternal(void* userdata);
  113. static void onSearchMenu(void* userdata);
  114. static void onUndoMenu(void* userdata);
  115. static void onRedoMenu(void* userdata);
  116. static void onCutMenu(void* userdata);
  117. static void onCopyMenu(void* userdata);
  118. static void onPasteMenu(void* userdata);
  119. static void onSelectAllMenu(void* userdata);
  120. static void onDeselectMenu(void* userdata);
  121. static void onSpellCheckMenu(void* userdata);
  122. static void onSetFontName(void* userdata);
  123. static void onSetFontSize(void* userdata);
  124. static bool hasChanged(void* userdata);
  125. static bool enableSaveLoadFile(void* userdata);
  126. static bool enableUndoMenu(void* userdata);
  127. static bool enableRedoMenu(void* userdata);
  128. static bool enableCutMenu(void* userdata);
  129. static bool enableCopyMenu(void* userdata);
  130. static bool enablePasteMenu(void* userdata);
  131. static bool enableSelectAllMenu(void* userdata);
  132. static bool enableDeselectMenu(void* userdata);
  133. static bool enableSpellCheckMenu(void* userdata);
  134. static bool checkSpellCheckMenu(void* userdata);
  135. static bool checkFontName(void* userdata);
  136. static bool checkFontSize(void* userdata);
  137. private:
  138. LLButton* mSaveButton;
  139. LLIconCtrl* mLockIcon;
  140. LLLineEditor* mDescription;
  141. LLViewerTextEditor* mEditor;
  142. HBExternalEditor* mExternalEditor;
  143. LLUUID mAssetID;
  144. LLUUID mNotecardItemID;
  145. LLUUID mObjectID;
  146. std::string mNoteName;
  147. std::string mTempFilename;
  148. struct CallbackData
  149. {
  150. LL_INLINE CallbackData(LLPreviewNotecard* floaterp,
  151. LLMenuItemCheckGL* ctrlp)
  152. : mFloater(floaterp),
  153. mCheck(ctrlp)
  154. {
  155. }
  156. LLPreviewNotecard* mFloater;
  157. LLMenuItemCheckGL* mCheck;
  158. };
  159. std::vector<CallbackData> mCallbackData;
  160. bool mShowKeepDiscard;
  161. static std::set<LLPreviewNotecard*> sInstances;
  162. static LLFontGL* sCustomFont;
  163. };
  164. #endif // LL_LLPREVIEWNOTECARD_H