The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
11KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "jucer_ProjectContentComponent.h"
  19. #include "../Application/jucer_MainWindow.h"
  20. #include "../Code Editor/jucer_SourceCodeEditor.h"
  21. #include "jucer_ProjectInformationComponent.h"
  22. #include "jucer_TreeViewTypes.h"
  23. #include "jucer_ProjectExporter.h"
  24. //==============================================================================
  25. ProjectContentComponent::ProjectContentComponent()
  26. : projectTree (0), project (0),
  27. currentDocument (0), resizerBar (0)
  28. {
  29. setItemLayout (0, 100, 500, 300);
  30. setItemLayout (1, 4, 4, 4);
  31. setItemLayout (2, 100, 10000, 800);
  32. setOpaque (true);
  33. setWantsKeyboardFocus (true);
  34. }
  35. ProjectContentComponent::~ProjectContentComponent()
  36. {
  37. setProject (0);
  38. contentView = 0;
  39. jassert (getNumChildComponents() == 0);
  40. }
  41. void ProjectContentComponent::paint (Graphics& g)
  42. {
  43. g.fillAll (Colour::greyLevel (0.8f));
  44. }
  45. void ProjectContentComponent::hasBeenMoved()
  46. {
  47. resized();
  48. }
  49. void ProjectContentComponent::resized()
  50. {
  51. Component* comps[] = { projectTree, resizerBar, contentView };
  52. layOutComponents (comps, 3, 0, 0, getWidth(), getHeight(), false, true);
  53. }
  54. void ProjectContentComponent::setProject (Project* newProject)
  55. {
  56. if (project != newProject)
  57. {
  58. if (project != 0)
  59. project->removeChangeListener (this);
  60. if (projectTree != 0)
  61. projectTree->deleteRootItem();
  62. projectTree = 0;
  63. contentView = 0;
  64. resizerBar = 0;
  65. project = newProject;
  66. if (project != 0)
  67. {
  68. addAndMakeVisible (projectTree = new TreeView());
  69. projectTree->setRootItemVisible (true);
  70. projectTree->setMultiSelectEnabled (true);
  71. projectTree->setDefaultOpenness (true);
  72. projectTree->setColour (TreeView::backgroundColourId, Colour::greyLevel (0.93f));
  73. projectTree->setIndentSize (14);
  74. addAndMakeVisible (resizerBar = new StretchableLayoutResizerBar (this, 1, true));
  75. resized();
  76. projectTree->setRootItem (new GroupTreeViewItem (project->getMainGroup()));
  77. projectTree->getRootItem()->setOpen (true);
  78. project->addChangeListener (this);
  79. if (currentDocument == 0)
  80. invokeDirectly (CommandIDs::showProjectSettings, true);
  81. updateMissingFileStatuses();
  82. }
  83. }
  84. }
  85. void ProjectContentComponent::changeListenerCallback (ChangeBroadcaster*)
  86. {
  87. updateMissingFileStatuses();
  88. }
  89. void ProjectContentComponent::updateMissingFileStatuses()
  90. {
  91. if (projectTree != 0)
  92. {
  93. ProjectTreeViewBase* p = dynamic_cast <ProjectTreeViewBase*> (projectTree->getRootItem());
  94. if (p != 0)
  95. p->checkFileStatus();
  96. }
  97. }
  98. bool ProjectContentComponent::showEditorForFile (const File& f)
  99. {
  100. return showDocument (OpenDocumentManager::getInstance()
  101. ->getDocumentForFile (project, f));
  102. }
  103. bool ProjectContentComponent::showDocument (OpenDocumentManager::Document* doc)
  104. {
  105. if (doc == 0)
  106. return false;
  107. OpenDocumentManager::getInstance()->moveDocumentToTopOfStack (doc);
  108. if (doc->hasFileBeenModifiedExternally())
  109. doc->reloadFromFile();
  110. return setEditorComponent (doc->createEditor(), doc);
  111. }
  112. void ProjectContentComponent::hideDocument (OpenDocumentManager::Document* doc)
  113. {
  114. if (doc == currentDocument)
  115. {
  116. currentDocument = 0;
  117. contentView = 0;
  118. updateMainWindowTitle();
  119. commandManager->commandStatusChanged();
  120. }
  121. }
  122. bool ProjectContentComponent::setEditorComponent (Component* editor, OpenDocumentManager::Document* doc)
  123. {
  124. if (editor != 0)
  125. {
  126. contentView = editor;
  127. currentDocument = doc;
  128. addAndMakeVisible (editor);
  129. resized();
  130. updateMainWindowTitle();
  131. commandManager->commandStatusChanged();
  132. return true;
  133. }
  134. updateMainWindowTitle();
  135. return false;
  136. }
  137. void ProjectContentComponent::updateMainWindowTitle()
  138. {
  139. MainWindow* mw = Component::findParentComponentOfClass ((MainWindow*) 0);
  140. if (mw != 0)
  141. mw->updateTitle (currentDocument != 0 ? currentDocument->getName() : String::empty);
  142. }
  143. ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget()
  144. {
  145. return findFirstTargetParentComponent();
  146. }
  147. void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
  148. {
  149. const CommandID ids[] = { CommandIDs::saveProject,
  150. CommandIDs::saveProjectAs,
  151. CommandIDs::closeProject,
  152. CommandIDs::openInIDE,
  153. CommandIDs::saveAndOpenInIDE,
  154. CommandIDs::showProjectSettings,
  155. StandardApplicationCommandIDs::del};
  156. commands.addArray (ids, numElementsInArray (ids));
  157. }
  158. void ProjectContentComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  159. {
  160. switch (commandID)
  161. {
  162. case CommandIDs::saveProject:
  163. result.setInfo ("Save Project",
  164. "Saves the current project",
  165. CommandCategories::general, 0);
  166. result.setActive (project != 0);
  167. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
  168. break;
  169. case CommandIDs::saveProjectAs:
  170. result.setInfo ("Save Project As...",
  171. "Saves the current project to a different filename",
  172. CommandCategories::general, 0);
  173. result.setActive (project != 0);
  174. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  175. break;
  176. case CommandIDs::closeProject:
  177. result.setInfo ("Close Project",
  178. "Closes the current project",
  179. CommandCategories::general, 0);
  180. result.setActive (project != 0);
  181. result.defaultKeypresses.add (KeyPress ('w', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  182. break;
  183. case CommandIDs::openInIDE:
  184. #if JUCE_MAC
  185. result.setInfo ("Open in XCode...",
  186. #elif JUCE_WINDOWS
  187. result.setInfo ("Open in Visual Studio...",
  188. #else
  189. result.setInfo ("Open as a Makefile...",
  190. #endif
  191. "Launches the project in an external IDE",
  192. CommandCategories::general, 0);
  193. result.setActive (project != 0);
  194. break;
  195. case CommandIDs::saveAndOpenInIDE:
  196. #if JUCE_MAC
  197. result.setInfo ("Save Project and Open in XCode...",
  198. #elif JUCE_WINDOWS
  199. result.setInfo ("Save Project and Open in Visual Studio...",
  200. #else
  201. result.setInfo ("Save Project and Open as a Makefile...",
  202. #endif
  203. "Saves the project and launches it in an external IDE",
  204. CommandCategories::general, 0);
  205. result.setActive (project != 0);
  206. result.defaultKeypresses.add (KeyPress ('l', ModifierKeys::commandModifier, 0));
  207. break;
  208. case CommandIDs::showProjectSettings:
  209. result.setInfo ("Show Project Build Settings",
  210. "Shows the build options for the project",
  211. CommandCategories::general, 0);
  212. result.setActive (project != 0);
  213. result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  214. break;
  215. case StandardApplicationCommandIDs::del:
  216. result.setInfo ("Delete", String::empty, CommandCategories::general, 0);
  217. result.defaultKeypresses.add (KeyPress (KeyPress::deleteKey, 0, 0));
  218. result.defaultKeypresses.add (KeyPress (KeyPress::backspaceKey, 0, 0));
  219. result.setActive (projectTree != 0);
  220. break;
  221. default:
  222. break;
  223. }
  224. }
  225. bool ProjectContentComponent::isCommandActive (const CommandID commandID)
  226. {
  227. return project != 0;
  228. }
  229. bool ProjectContentComponent::perform (const InvocationInfo& info)
  230. {
  231. switch (info.commandID)
  232. {
  233. case CommandIDs::saveProject:
  234. if (project != 0)
  235. project->save (true, true);
  236. break;
  237. case CommandIDs::saveProjectAs:
  238. if (project != 0)
  239. project->saveAsInteractive (true);
  240. break;
  241. case CommandIDs::closeProject:
  242. {
  243. MainWindow* mw = Component::findParentComponentOfClass ((MainWindow*) 0);
  244. if (mw != 0)
  245. mw->closeCurrentProject();
  246. }
  247. break;
  248. case CommandIDs::openInIDE:
  249. if (project != 0)
  250. {
  251. ScopedPointer <ProjectExporter> exporter (ProjectExporter::createPlatformDefaultExporter (*project));
  252. exporter->launchProject();
  253. }
  254. break;
  255. case CommandIDs::saveAndOpenInIDE:
  256. if (project != 0 && project->save (true, true) == FileBasedDocument::savedOk)
  257. {
  258. ScopedPointer <ProjectExporter> exporter (ProjectExporter::createPlatformDefaultExporter (*project));
  259. exporter->launchProject();
  260. }
  261. break;
  262. case CommandIDs::showProjectSettings:
  263. if (projectTree != 0)
  264. projectTree->getRootItem()->setSelected (true, true);
  265. break;
  266. case StandardApplicationCommandIDs::del:
  267. if (projectTree != 0)
  268. {
  269. ProjectTreeViewBase* p = dynamic_cast <ProjectTreeViewBase*> (projectTree->getRootItem());
  270. if (p != 0)
  271. p->deleteAllSelectedItems();
  272. }
  273. break;
  274. default:
  275. return false;
  276. }
  277. return true;
  278. }