gcsx_folder.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* GCSx
  2. ** FOLDER.H
  3. **
  4. ** Folders within world browser (user-definable)
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program 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
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_FOLDER_H_
  24. #define __GCSx_FOLDER_H_
  25. // Note that folders currently store no content- all data is
  26. // stored as header data (hence no locking/caching needed) as
  27. // there would never be a reason or opportunity to cache out
  28. // anything relating to a folder during editing. If we later add
  29. // "folder notes" or something, this might change.
  30. class FolderEdit : virtual public SaveLoad {
  31. protected:
  32. // Is the library cached to our file and not in memory?
  33. int cached;
  34. FileRead* cacheFile;
  35. int lockCount;
  36. // Name of folder, where it's located
  37. std::string name;
  38. class World* world;
  39. // Numeric ID- computer-generated- unique to world- nonzero
  40. int id;
  41. // Contents of folder
  42. struct FolderItem {
  43. // We track the item's type using already-defined file block types
  44. // We mostly only need type/id for saving and loading
  45. int itemBlockType;
  46. int itemId;
  47. // Most folder functionality just passes on to the items themselves
  48. // We do not own these pointers
  49. SaveLoad* item;
  50. };
  51. std::vector<FolderItem> items;
  52. // Currently sorted? (and add items sorted)
  53. int sorted;
  54. // Default folder for adding new items of given type?
  55. int defaultFont;
  56. int defaultTileSet;
  57. int defaultScene;
  58. int defaultAnimGroup;
  59. int defaultScript;
  60. int defaultLibrary;
  61. // Icon to use
  62. int icon;
  63. // Has the folder been modified from initial state (from empty if new)
  64. int headerModified;
  65. int contentModified;
  66. int disassociated;
  67. // Our node on the world browser
  68. TreeView* browserNode;
  69. // Set us as modified
  70. // Setting content modified also loads from cache if needed
  71. // Call these before actually making any modifications
  72. // (if header changes affect content, call both modifieds first)
  73. void setHeaderModified();
  74. void setContentModified();
  75. public:
  76. // Id of 0 = we're going to load immediately
  77. // Any other id = we start out modified
  78. FolderEdit(class WorldEdit* myWorld, int myId = 0); // Starts with default settings
  79. virtual ~FolderEdit();
  80. // Accessors
  81. int getId() const { return id; }
  82. int getBlockType() const { return WorldFileLoad::BLOCKTYPE_FOLDER; }
  83. const std::string& getName() const { return name; }
  84. // Tells us to disassociate ourselves from anything, we've been "deleted"
  85. // or that we've been "readded" again
  86. // FileException means couldn't decache, and nothing was done
  87. void disassociate() throw_File;
  88. // Node is world browser node that we readd to
  89. void reassociate(TreeView* node);
  90. class WorldEdit* getWorldEdit() { return dynamic_cast<WorldEdit*>(world); }
  91. // Change properties; handles undo/update events
  92. void setName(const std::string& newName, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  93. //@TODO:void setSort(int nSorted) throw_Undo;
  94. //@TODO:void setIcon(int nIcon) throw_Undo;
  95. //@TODO:void setDefaults(int nFont, int nTileSet, int nScene, int nAnimGroup, int nScript, int nLibrary) throw_Undo;
  96. // Handles undo/update events; updates world browser node appropriately,
  97. // including expanding/cursor focus (presumes focus on newly added items)
  98. void addItem(SaveLoad* item, int index = -1, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  99. void removeItem(SaveLoad* item, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  100. //@TODO:void moveItem(SaveLoad* item, int pos, Window* srcWin = NULL, Window* exWin = NULL) throw_Undo;
  101. // Returns true if OK pressed
  102. int propertiesDialog(Window* srcWin = NULL, Window* exWin = NULL);
  103. // Tells folder to add itself to the world browser node
  104. void addToBrowser(TreeView* node, int makeCurrent = 1);
  105. void dropBrowser(); // Called if animgroup gets dropped from browser
  106. // Treeview event handling
  107. int treeviewEvent(int code, int command, int check);
  108. static int treeviewEventWrap(void* ptr, int code, int command, int check);
  109. // File access
  110. void loadHeader(FileRead* file) throw_File;
  111. void loadContent(FileRead* file);
  112. int isContentCached() const;
  113. void cacheLoad() throw_File;
  114. int markLock() throw_File;
  115. int markUnlock();
  116. int isLocked() const;
  117. int isHeaderModified() const;
  118. int isContentModified() const;
  119. Uint32 saveHeader(FileWrite* file) throw_File;
  120. void saveContent(FileWrite* file) throw_File;
  121. void saveSuccess();
  122. void cachedContent(FileRead* file, int oldData);
  123. };
  124. #endif