1 #pragma once 2 3 #ifndef TPROJECT_INCLUDED 4 #define TPROJECT_INCLUDED 5 #include <set> 6 7 #include "tfilepath.h" 8 #include "tsmartpointer.h" 9 10 class ToonzScene; 11 class TSceneProperties; 12 13 #undef DVAPI 14 #undef DVVAR 15 #ifdef TOONZLIB_EXPORTS 16 #define DVAPI DV_EXPORT_API 17 #define DVVAR DV_EXPORT_VAR 18 #else 19 #define DVAPI DV_IMPORT_API 20 #define DVVAR DV_IMPORT_VAR 21 #endif 22 23 class DVAPI TProject final : public TSmartObject { 24 TFilePath m_name, m_path; 25 std::vector<std::string> m_folderNames; 26 std::map<std::string, TFilePath> m_folders; 27 std::map<std::string, bool> m_useScenePathFlags; 28 TSceneProperties *m_sprop; 29 30 public: 31 // default folders names 32 static const std::string Inputs; 33 static const std::string Drawings; 34 static const std::string Scenes; 35 static const std::string Extras; 36 static const std::string Outputs; 37 static const std::string Scripts; 38 static const std::string Palettes; 39 40 static const TFilePath SandboxProjectName; 41 42 // TProject 43 TProject(); 44 ~TProject(); 45 getName()46 TFilePath getName() const { return m_name; } getProjectPath()47 TFilePath getProjectPath() const { return m_path; } getProjectFolder()48 TFilePath getProjectFolder() const { return m_path.getParentDir(); } 49 50 void setFolder(std::string name, TFilePath path); 51 void setFolder(std::string name); 52 53 int getFolderCount() const; 54 std::string getFolderName(int index) const; 55 int getFolderIndex(std::string folderName) const; 56 57 bool isConstantFolder(int index) const; 58 59 TFilePath getFolder(int index) const; 60 TFilePath getFolder(std::string name, bool absolute = false) const; 61 62 TFilePath getScenesPath() const; 63 64 TFilePath decode(TFilePath fp) const; 65 66 bool isCurrent() const; 67 68 void setSceneProperties(const TSceneProperties &sprop); getSceneProperties()69 const TSceneProperties &getSceneProperties() const { return *m_sprop; } 70 71 //????????????????????????????????????????????? 72 void setUseScenePath(std::string folderName, bool on); 73 //????????????????????????????????????????????? 74 bool getUseScenePath(std::string folderName) const; 75 76 // nei due metodi seguenti fp e' un path assoluto (possibilmente con 77 // $scenepath) 78 //???????????????????????????????????????????????? 79 int getFolderIndexFromPath(const TFilePath &fp); 80 std::wstring getFolderNameFromPath(const TFilePath &fp); 81 82 bool save(const TFilePath &projectPath); 83 bool save(); 84 void load(const TFilePath &projectPath); 85 86 static bool isAProjectPath(const TFilePath &fp); 87 88 private: 89 // not implemented 90 TProject(const TProject &src); 91 TProject &operator=(const TProject &); 92 }; 93 94 #ifdef _WIN32 95 template class DVAPI TSmartPointerT<TProject>; 96 #endif 97 typedef TSmartPointerT<TProject> TProjectP; 98 99 //=================================================================== 100 101 class DVAPI TProjectManager { // singleton 102 public: 103 class Listener { 104 public: 105 virtual void onProjectSwitched() = 0; 106 virtual void onProjectChanged() = 0; ~Listener()107 virtual ~Listener() {} 108 }; 109 110 private: 111 std::vector<TFilePath> m_projectsRoots; 112 std::vector<TFilePath> m_svnProjectsRoots; 113 std::set<Listener *> m_listeners; 114 115 void addDefaultProjectsRoot(); 116 117 TProjectManager(); 118 void notifyListeners(); 119 120 bool m_tabMode; 121 bool m_tabKidsMode; 122 123 public: 124 ~TProjectManager(); 125 126 void notifyProjectChanged(); 127 128 static TProjectManager *instance(); 129 130 TFilePath getCurrentProjectPath(); 131 void setCurrentProjectPath(const TFilePath &fp); 132 TProjectP getCurrentProject(); 133 134 void initializeScene(ToonzScene *scene); 135 136 void saveTemplate(ToonzScene *scene); 137 138 void addProjectsRoot(const TFilePath &fp); 139 void addSVNProjectsRoot(const TFilePath &fp); 140 141 //! returns the project root of the current project (if this fails, then 142 //! returns the first project root) 143 TFilePath getCurrentProjectRoot(); 144 145 TFilePath projectPathToProjectName(const TFilePath &projectPath); 146 TFilePath projectNameToProjectPath(const TFilePath &projectName); 147 TFilePath projectFolderToProjectPath(const TFilePath &projectFolder); 148 TFilePath getProjectPathByName(const TFilePath &projectName); 149 TFilePath getProjectPathByProjectFolder(const TFilePath &projectFolder); 150 151 TProjectP loadSceneProject(const TFilePath &scenePath); 152 void getFolderNames(std::vector<std::string> &names); 153 154 void addListener(Listener *listener); 155 void removeListener(Listener *listener); 156 157 TProjectP createStandardProject(); 158 void createSandboxIfNeeded(); 159 isTabKidsModeEnabled()160 bool isTabKidsModeEnabled() const { return m_tabKidsMode; } enableTabKidsMode(bool tabKidsMode)161 void enableTabKidsMode(bool tabKidsMode) { m_tabKidsMode = tabKidsMode; } 162 isTabModeEnabled()163 bool isTabModeEnabled() const { return m_tabMode; } enableTabMode(bool tabMode)164 void enableTabMode(bool tabMode) { m_tabMode = tabMode; } 165 166 TFilePath getSandboxProjectFolder(); 167 TFilePath getSandboxProjectPath(); 168 getProjectRoots(std::vector<TFilePath> & projectRoots)169 void getProjectRoots(std::vector<TFilePath> &projectRoots) const { 170 projectRoots = m_projectsRoots; 171 } 172 173 bool isProject(const TFilePath &projectFolder); 174 }; 175 176 #endif 177