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.

1512 lines
52KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_ProjectContentComponent.h"
  19. #include "jucer_Module.h"
  20. #include "../Application/jucer_MainWindow.h"
  21. #include "../Application/jucer_Application.h"
  22. #include "../Code Editor/jucer_SourceCodeEditor.h"
  23. #include "../Utility/jucer_FilePathPropertyComponent.h"
  24. #include "jucer_TreeItemTypes.h"
  25. //==============================================================================
  26. class FileTreePanel : public TreePanelBase
  27. {
  28. public:
  29. FileTreePanel (Project& p)
  30. : TreePanelBase (&p, "fileTreeState")
  31. {
  32. tree.setMultiSelectEnabled (true);
  33. setRoot (new FileTreeItemTypes::GroupItem (p.getMainGroup()));
  34. }
  35. void updateMissingFileStatuses()
  36. {
  37. if (FileTreeItemTypes::ProjectTreeItemBase* p = dynamic_cast<FileTreeItemTypes::ProjectTreeItemBase*> (rootItem.get()))
  38. p->checkFileStatus();
  39. }
  40. };
  41. //==============================================================================
  42. class ConfigTreePanel : public TreePanelBase
  43. {
  44. public:
  45. ConfigTreePanel (Project& p)
  46. : TreePanelBase (&p, "settingsTreeState")
  47. {
  48. tree.setMultiSelectEnabled (false);
  49. setRoot (new ConfigTreeItemTypes::RootItem (p));
  50. if (tree.getNumSelectedItems() == 0)
  51. tree.getRootItem()->setSelected (true, true);
  52. #if JUCE_MAC || JUCE_WINDOWS
  53. ApplicationCommandManager& commandManager = ProjucerApplication::getCommandManager();
  54. addAndMakeVisible (createExporterButton);
  55. createExporterButton.setCommandToTrigger (&commandManager, CommandIDs::createNewExporter, true);
  56. createExporterButton.setButtonText (commandManager.getNameOfCommand (CommandIDs::createNewExporter));
  57. createExporterButton.setColour (TextButton::buttonColourId, Colours::white.withAlpha (0.5f));
  58. addAndMakeVisible (openProjectButton);
  59. openProjectButton.setCommandToTrigger (&commandManager, CommandIDs::openInIDE, true);
  60. openProjectButton.setButtonText (commandManager.getNameOfCommand (CommandIDs::openInIDE));
  61. openProjectButton.setColour (TextButton::buttonColourId, Colours::white.withAlpha (0.5f));
  62. addAndMakeVisible (saveAndOpenButton);
  63. saveAndOpenButton.setCommandToTrigger (&commandManager, CommandIDs::saveAndOpenInIDE, true);
  64. saveAndOpenButton.setButtonText (commandManager.getNameOfCommand (CommandIDs::saveAndOpenInIDE));
  65. saveAndOpenButton.setColour (TextButton::buttonColourId, Colours::white.withAlpha (0.5f));
  66. #endif
  67. }
  68. void resized() override
  69. {
  70. Rectangle<int> r (getAvailableBounds());
  71. r.removeFromBottom (6);
  72. if (saveAndOpenButton.isVisible())
  73. saveAndOpenButton.setBounds (r.removeFromBottom (30).reduced (16, 4));
  74. if (openProjectButton.isVisible())
  75. openProjectButton.setBounds (r.removeFromBottom (30).reduced (16, 4));
  76. if (createExporterButton.isVisible())
  77. {
  78. r.removeFromBottom (10);
  79. createExporterButton.setBounds (r.removeFromBottom (30).reduced (16, 4));
  80. }
  81. tree.setBounds (r);
  82. }
  83. static void reselect (TreeViewItem& item)
  84. {
  85. item.setSelected (false, true);
  86. item.setSelected (true, true);
  87. }
  88. void showProjectSettings()
  89. {
  90. if (ConfigTreeItemTypes::ConfigTreeItemBase* root = dynamic_cast<ConfigTreeItemTypes::ConfigTreeItemBase*> (rootItem.get()))
  91. if (root->isProjectSettings())
  92. reselect (*root);
  93. }
  94. void showModules()
  95. {
  96. if (ConfigTreeItemTypes::ConfigTreeItemBase* mods = getModulesItem())
  97. reselect (*mods);
  98. }
  99. void showModule (const String& moduleID)
  100. {
  101. if (ConfigTreeItemTypes::ConfigTreeItemBase* mods = getModulesItem())
  102. {
  103. mods->setOpen (true);
  104. for (int i = mods->getNumSubItems(); --i >= 0;)
  105. if (ConfigTreeItemTypes::ModuleItem* m = dynamic_cast<ConfigTreeItemTypes::ModuleItem*> (mods->getSubItem (i)))
  106. if (m->moduleID == moduleID)
  107. reselect (*m);
  108. }
  109. }
  110. TextButton createExporterButton, openProjectButton, saveAndOpenButton;
  111. private:
  112. ConfigTreeItemTypes::ConfigTreeItemBase* getModulesItem()
  113. {
  114. if (ConfigTreeItemTypes::ConfigTreeItemBase* root = dynamic_cast<ConfigTreeItemTypes::ConfigTreeItemBase*> (rootItem.get()))
  115. if (root->isProjectSettings())
  116. if (ConfigTreeItemTypes::ConfigTreeItemBase* mods = dynamic_cast<ConfigTreeItemTypes::ConfigTreeItemBase*> (root->getSubItem (0)))
  117. if (mods->isModulesList())
  118. return mods;
  119. return nullptr;
  120. }
  121. };
  122. //==============================================================================
  123. struct LogoComponent : public Component
  124. {
  125. LogoComponent()
  126. {
  127. ScopedPointer<XmlElement> svg (XmlDocument::parse (BinaryData::background_logo_svg));
  128. logo = Drawable::createFromSVG (*svg);
  129. }
  130. void paint (Graphics& g) override
  131. {
  132. g.setColour (findColour (mainBackgroundColourId).contrasting (0.3f));
  133. Rectangle<int> r (getLocalBounds());
  134. g.setFont (15.0f);
  135. g.drawFittedText (getVersionInfo(), r.removeFromBottom (50), Justification::centredBottom, 3);
  136. logo->drawWithin (g, r.withTrimmedBottom (r.getHeight() / 4).toFloat(),
  137. RectanglePlacement (RectanglePlacement::centred), 1.0f);
  138. }
  139. static String getVersionInfo()
  140. {
  141. return SystemStats::getJUCEVersion()
  142. + newLine
  143. + ProjucerApplication::getApp().getVersionDescription();
  144. }
  145. ScopedPointer<Drawable> logo;
  146. };
  147. //==============================================================================
  148. ProjectContentComponent::ProjectContentComponent()
  149. : project (nullptr),
  150. currentDocument (nullptr),
  151. treeViewTabs (TabbedButtonBar::TabsAtTop)
  152. {
  153. setOpaque (true);
  154. setWantsKeyboardFocus (true);
  155. addAndMakeVisible (logo = new LogoComponent());
  156. treeSizeConstrainer.setMinimumWidth (200);
  157. treeSizeConstrainer.setMaximumWidth (500);
  158. treeViewTabs.setOutline (0);
  159. treeViewTabs.getTabbedButtonBar().setMinimumTabScaleFactor (0.3);
  160. ProjucerApplication::getApp().openDocumentManager.addListener (this);
  161. Desktop::getInstance().addFocusChangeListener (this);
  162. startTimer (1600);
  163. }
  164. ProjectContentComponent::~ProjectContentComponent()
  165. {
  166. Desktop::getInstance().removeFocusChangeListener (this);
  167. killChildProcess();
  168. ProjucerApplication::getApp().openDocumentManager.removeListener (this);
  169. logo = nullptr;
  170. setProject (nullptr);
  171. contentView = nullptr;
  172. removeChildComponent (&bubbleMessage);
  173. jassert (getNumChildComponents() <= 1);
  174. }
  175. void ProjectContentComponent::paint (Graphics& g)
  176. {
  177. ProjucerLookAndFeel::fillWithBackgroundTexture (*this, g);
  178. }
  179. void ProjectContentComponent::paintOverChildren (Graphics& g)
  180. {
  181. if (resizerBar != nullptr)
  182. {
  183. const int shadowSize = 15;
  184. const int x = resizerBar->getX();
  185. ColourGradient cg (Colours::black.withAlpha (0.25f), (float) x, 0,
  186. Colours::transparentBlack, (float) (x - shadowSize), 0, false);
  187. cg.addColour (0.4, Colours::black.withAlpha (0.07f));
  188. cg.addColour (0.6, Colours::black.withAlpha (0.02f));
  189. g.setGradientFill (cg);
  190. g.fillRect (x - shadowSize, 0, shadowSize, getHeight());
  191. }
  192. }
  193. void ProjectContentComponent::resized()
  194. {
  195. Rectangle<int> r (getLocalBounds());
  196. if (treeViewTabs.isVisible())
  197. treeViewTabs.setBounds (r.removeFromLeft (treeViewTabs.getWidth()));
  198. if (resizerBar != nullptr)
  199. resizerBar->setBounds (r.withWidth (4));
  200. if (contentView != nullptr)
  201. contentView->setBounds (r);
  202. if (logo != nullptr)
  203. logo->setBounds (r.reduced (r.getWidth() / 4, r.getHeight() / 4));
  204. }
  205. void ProjectContentComponent::lookAndFeelChanged()
  206. {
  207. repaint();
  208. }
  209. void ProjectContentComponent::childBoundsChanged (Component* child)
  210. {
  211. if (child == &treeViewTabs)
  212. resized();
  213. }
  214. void ProjectContentComponent::setProject (Project* newProject)
  215. {
  216. if (project != newProject)
  217. {
  218. lastCrashMessage = String();
  219. killChildProcess();
  220. if (project != nullptr)
  221. project->removeChangeListener (this);
  222. contentView = nullptr;
  223. resizerBar = nullptr;
  224. deleteProjectTabs();
  225. project = newProject;
  226. rebuildProjectTabs();
  227. }
  228. }
  229. void ProjectContentComponent::rebuildProjectTabs()
  230. {
  231. deleteProjectTabs();
  232. if (project != nullptr)
  233. {
  234. addAndMakeVisible (treeViewTabs);
  235. createProjectTabs();
  236. PropertiesFile& settings = project->getStoredProperties();
  237. const String lastTabName (settings.getValue ("lastTab"));
  238. int lastTabIndex = treeViewTabs.getTabNames().indexOf (lastTabName);
  239. if (lastTabIndex < 0 || lastTabIndex > treeViewTabs.getNumTabs())
  240. lastTabIndex = 1;
  241. treeViewTabs.setCurrentTabIndex (lastTabIndex);
  242. int lastTreeWidth = settings.getValue ("projectPanelWidth").getIntValue();
  243. if (lastTreeWidth < 150)
  244. lastTreeWidth = 240;
  245. treeViewTabs.setBounds (0, 0, lastTreeWidth, getHeight());
  246. addAndMakeVisible (resizerBar = new ResizableEdgeComponent (&treeViewTabs, &treeSizeConstrainer,
  247. ResizableEdgeComponent::rightEdge));
  248. resizerBar->setAlwaysOnTop (true);
  249. project->addChangeListener (this);
  250. updateMissingFileStatuses();
  251. }
  252. else
  253. {
  254. treeViewTabs.setVisible (false);
  255. }
  256. resized();
  257. }
  258. //==============================================================================
  259. struct BuildTabComponent : public ConcertinaPanel
  260. {
  261. BuildTabComponent (CompileEngineChildProcess* child, ProjucerAppClasses::ErrorListComp* errorList)
  262. : errorListComp (errorList)
  263. {
  264. CurrentActivitiesComp* activities = new CurrentActivitiesComp (child->activityList);
  265. ComponentListComp* comps = new ComponentListComp (*child);
  266. addPanel (-1, errorList, true);
  267. addPanel (-1, comps, true);
  268. addPanel (-1, activities, true);
  269. setMaximumPanelSize (activities, CurrentActivitiesComp::getMaxPanelHeight());
  270. setPanelSize (errorList, 200, false);
  271. setPanelSize (comps, 300, false);
  272. }
  273. Component::SafePointer<ProjucerAppClasses::ErrorListComp> errorListComp;
  274. };
  275. struct ProjucerDisabledComp : public Component,
  276. private Button::Listener
  277. {
  278. ProjucerDisabledComp (String message, bool loggedIn, bool canLogin, bool requirePurchase = false,
  279. const String& loginName = String())
  280. : isLoggedIn (loggedIn), isPurchaseButton (requirePurchase)
  281. {
  282. infoLabel.setColour (Label::textColourId, findColour (mainBackgroundColourId).contrasting (0.7f));
  283. infoLabel.setJustificationType (Justification::centred);
  284. infoLabel.setText (message, dontSendNotification);
  285. addAndMakeVisible (infoLabel);
  286. if (canLogin)
  287. {
  288. addAndMakeVisible (loginButton);
  289. loginButton.addListener (this);
  290. if (isPurchaseButton)
  291. {
  292. loginButton.setButtonText ("Purchase JUCE Pro...");
  293. signOutButton = new TextButton (String ("Sign Out ") + loginName);
  294. addAndMakeVisible (*signOutButton);
  295. signOutButton->addListener (this);
  296. }
  297. }
  298. }
  299. void resized() override
  300. {
  301. infoLabel.centreWithSize (proportionOfWidth (0.9f), 200);
  302. loginButton.setSize (jmin (getWidth() - 10, 150), 22);
  303. loginButton.setCentrePosition (infoLabel.getBounds().getCentreX(),
  304. infoLabel.getBottom() + loginButton.getHeight() * 2);
  305. if (signOutButton != nullptr)
  306. {
  307. signOutButton->setSize (jmin (getWidth() - 10, 150), 22);
  308. signOutButton->setCentrePosition (infoLabel.getBounds().getCentreX(),
  309. loginButton.getBottom() + 20);
  310. }
  311. }
  312. void buttonClicked (Button* btn) override
  313. {
  314. if (btn == &loginButton)
  315. {
  316. if (isPurchaseButton)
  317. URL ("http://www.juce.com").launchInDefaultBrowser();
  318. else
  319. ProjucerApplication::getApp().showLoginForm();
  320. }
  321. else if (btn == signOutButton.get())
  322. {
  323. ProjucerLicenses::getInstance()->logout();
  324. ProjucerApplication::getApp().updateAllBuildTabs();
  325. }
  326. }
  327. Label infoLabel { "info", String() };
  328. TextButton loginButton { "Log-in..." };
  329. ScopedPointer<TextButton> signOutButton;
  330. bool isLoggedIn, isPurchaseButton;
  331. };
  332. struct EnableBuildComp : public Component
  333. {
  334. EnableBuildComp()
  335. {
  336. addAndMakeVisible (&enableButton);
  337. enableButton.setCommandToTrigger (&ProjucerApplication::getCommandManager(), CommandIDs::enableBuild, true);
  338. }
  339. void resized() override
  340. {
  341. enableButton.centreWithSize (jmin (getWidth() - 10, 150), 22);
  342. }
  343. void paint (Graphics& g) override
  344. {
  345. if (ProjectContentComponent* ppc = findParentComponentOfClass<ProjectContentComponent>())
  346. {
  347. g.setColour (findColour (mainBackgroundColourId).contrasting (0.7f));
  348. g.setFont (13.0f);
  349. g.drawFittedText (ppc->lastCrashMessage,
  350. getLocalBounds().reduced (8).withBottom (enableButton.getY() - 20),
  351. Justification::centredBottom, 10);
  352. }
  353. }
  354. TextButton enableButton { "Restart Compiler" };
  355. };
  356. //==============================================================================
  357. Component* ProjectContentComponent::createBuildTab (CompileEngineChildProcess* child)
  358. {
  359. #if JUCE_LINUX
  360. ignoreUnused (child);
  361. return new ProjucerDisabledComp ("Linux support is still under development - "
  362. "please check for updates at www.juce.com!", false, false);
  363. #else
  364. if (child != nullptr)
  365. {
  366. child->crashHandler = [this] (const String& m) {
  367. this->handleCrash (m);
  368. };
  369. return new BuildTabComponent (child, new ProjucerAppClasses::ErrorListComp (child->errorList));
  370. }
  371. auto& unlockStatus = *ProjucerLicenses::getInstance();
  372. if (unlockStatus.hasLiveCodingLicence()
  373. && project != nullptr
  374. && LiveBuildProjectSettings::isBuildDisabled (*project))
  375. return new EnableBuildComp();
  376. if (unlockStatus.isLoggedIn())
  377. return new ProjucerDisabledComp (String ("The Projucer's live-build features are currently disabled!") + newLine
  378. + newLine
  379. + "Your account " + unlockStatus.getLoginName().quoted()
  380. + " does not have an asscociated JUCE Pro license:",
  381. true, true, true, unlockStatus.getLoginName());
  382. if (! unlockStatus.isDLLPresent())
  383. return new ProjucerDisabledComp (String ("The live-building DLL is missing!") + newLine
  384. + newLine
  385. + "To enable the compiler, you'll need to install the missing DLL "
  386. + CompileEngineDLL::getDLLName().quoted() + newLine
  387. + newLine
  388. + "Visit the JUCE website/forum for more help on getting and installing the DLL!",
  389. false, false);
  390. return new ProjucerDisabledComp ("The Projucer's live-build features are currently disabled!\n\n"
  391. "To enable them, you'll need to log-in with your JUCE account details:",
  392. false, true, false);
  393. #endif
  394. }
  395. BuildTabComponent* findBuildTab (const TabbedComponent& tabs)
  396. {
  397. return dynamic_cast<BuildTabComponent*> (tabs.getTabContentComponent (2));
  398. }
  399. bool ProjectContentComponent::isBuildTabEnabled() const
  400. {
  401. return findBuildTab (treeViewTabs) != nullptr;
  402. }
  403. bool ProjectContentComponent::isBuildTabSuitableForLoggedInUser() const
  404. {
  405. return isBuildTabEnabled()
  406. || isBuildTabLoggedInWithoutLicense()
  407. || dynamic_cast<EnableBuildComp*> (treeViewTabs.getTabContentComponent (2)) != nullptr;
  408. }
  409. bool ProjectContentComponent::isBuildTabLoggedInWithoutLicense() const
  410. {
  411. if (auto* c = dynamic_cast<ProjucerDisabledComp*> (treeViewTabs.getTabContentComponent (2)))
  412. return c->isLoggedIn;
  413. return false;
  414. }
  415. void ProjectContentComponent::createProjectTabs()
  416. {
  417. jassert (project != nullptr);
  418. const Colour tabColour (Colours::transparentBlack);
  419. treeViewTabs.addTab ("Files", tabColour, new FileTreePanel (*project), true);
  420. treeViewTabs.addTab ("Config", tabColour, new ConfigTreePanel (*project), true);
  421. const CompileEngineChildProcess::Ptr childProc (getChildProcess());
  422. treeViewTabs.addTab ("Build", Colours::transparentBlack, createBuildTab (childProc), true);
  423. if (childProc != nullptr)
  424. treeViewTabs.getTabbedButtonBar().getTabButton (2)
  425. ->setExtraComponent (new BuildStatusTabComp (childProc->errorList,
  426. childProc->activityList),
  427. TabBarButton::afterText);
  428. }
  429. void ProjectContentComponent::deleteProjectTabs()
  430. {
  431. if (project != nullptr && treeViewTabs.isShowing())
  432. {
  433. PropertiesFile& settings = project->getStoredProperties();
  434. if (treeViewTabs.getWidth() > 0)
  435. settings.setValue ("projectPanelWidth", treeViewTabs.getWidth());
  436. if (treeViewTabs.getNumTabs() > 0)
  437. settings.setValue ("lastTab", treeViewTabs.getCurrentTabName());
  438. }
  439. treeViewTabs.clearTabs();
  440. }
  441. void ProjectContentComponent::saveTreeViewState()
  442. {
  443. for (int i = treeViewTabs.getNumTabs(); --i >= 0;)
  444. if (TreePanelBase* t = dynamic_cast<TreePanelBase*> (treeViewTabs.getTabContentComponent (i)))
  445. t->saveOpenness();
  446. }
  447. void ProjectContentComponent::saveOpenDocumentList()
  448. {
  449. if (project != nullptr)
  450. {
  451. ScopedPointer<XmlElement> xml (recentDocumentList.createXML());
  452. if (xml != nullptr)
  453. project->getStoredProperties().setValue ("lastDocs", xml);
  454. }
  455. }
  456. void ProjectContentComponent::reloadLastOpenDocuments()
  457. {
  458. if (project != nullptr)
  459. {
  460. ScopedPointer<XmlElement> xml (project->getStoredProperties().getXmlValue ("lastDocs"));
  461. if (xml != nullptr)
  462. {
  463. recentDocumentList.restoreFromXML (*project, *xml);
  464. showDocument (recentDocumentList.getCurrentDocument(), true);
  465. }
  466. }
  467. }
  468. bool ProjectContentComponent::documentAboutToClose (OpenDocumentManager::Document* document)
  469. {
  470. hideDocument (document);
  471. return true;
  472. }
  473. void ProjectContentComponent::changeListenerCallback (ChangeBroadcaster*)
  474. {
  475. updateMissingFileStatuses();
  476. }
  477. void ProjectContentComponent::updateMissingFileStatuses()
  478. {
  479. if (FileTreePanel* tree = dynamic_cast<FileTreePanel*> (treeViewTabs.getTabContentComponent (0)))
  480. tree->updateMissingFileStatuses();
  481. }
  482. bool ProjectContentComponent::showEditorForFile (const File& f, bool grabFocus)
  483. {
  484. return getCurrentFile() == f
  485. || showDocument (ProjucerApplication::getApp().openDocumentManager.openFile (project, f), grabFocus);
  486. }
  487. bool ProjectContentComponent::hasFileInRecentList (const File& f) const
  488. {
  489. return recentDocumentList.contains (f);
  490. }
  491. File ProjectContentComponent::getCurrentFile() const
  492. {
  493. return currentDocument != nullptr ? currentDocument->getFile()
  494. : File::nonexistent;
  495. }
  496. bool ProjectContentComponent::showDocument (OpenDocumentManager::Document* doc, bool grabFocus)
  497. {
  498. if (doc == nullptr)
  499. return false;
  500. if (doc->hasFileBeenModifiedExternally())
  501. doc->reloadFromFile();
  502. if (doc == getCurrentDocument() && contentView != nullptr)
  503. {
  504. if (grabFocus)
  505. contentView->grabKeyboardFocus();
  506. return true;
  507. }
  508. recentDocumentList.newDocumentOpened (doc);
  509. bool opened = setEditorComponent (doc->createEditor(), doc);
  510. if (opened && grabFocus)
  511. contentView->grabKeyboardFocus();
  512. return opened;
  513. }
  514. void ProjectContentComponent::hideEditor()
  515. {
  516. currentDocument = nullptr;
  517. contentView = nullptr;
  518. updateMainWindowTitle();
  519. ProjucerApplication::getCommandManager().commandStatusChanged();
  520. resized();
  521. }
  522. void ProjectContentComponent::hideDocument (OpenDocumentManager::Document* doc)
  523. {
  524. if (doc == currentDocument)
  525. {
  526. if (OpenDocumentManager::Document* replacement = recentDocumentList.getClosestPreviousDocOtherThan (doc))
  527. showDocument (replacement, true);
  528. else
  529. hideEditor();
  530. }
  531. }
  532. bool ProjectContentComponent::setEditorComponent (Component* editor,
  533. OpenDocumentManager::Document* doc)
  534. {
  535. if (editor != nullptr)
  536. {
  537. contentView = nullptr;
  538. contentView = editor;
  539. currentDocument = doc;
  540. addAndMakeVisible (editor);
  541. resized();
  542. updateMainWindowTitle();
  543. ProjucerApplication::getCommandManager().commandStatusChanged();
  544. return true;
  545. }
  546. updateMainWindowTitle();
  547. return false;
  548. }
  549. void ProjectContentComponent::closeDocument()
  550. {
  551. if (currentDocument != nullptr)
  552. ProjucerApplication::getApp().openDocumentManager.closeDocument (currentDocument, true);
  553. else if (contentView != nullptr)
  554. if (! goToPreviousFile())
  555. hideEditor();
  556. }
  557. static void showSaveWarning (OpenDocumentManager::Document* currentDocument)
  558. {
  559. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  560. TRANS("Save failed!"),
  561. TRANS("Couldn't save the file:")
  562. + "\n" + currentDocument->getFile().getFullPathName());
  563. }
  564. void ProjectContentComponent::saveDocument()
  565. {
  566. if (currentDocument != nullptr)
  567. {
  568. if (! currentDocument->save())
  569. showSaveWarning (currentDocument);
  570. }
  571. else
  572. saveProject();
  573. updateMainWindowTitle();
  574. }
  575. void ProjectContentComponent::saveAs()
  576. {
  577. if (currentDocument != nullptr && ! currentDocument->saveAs())
  578. showSaveWarning (currentDocument);
  579. }
  580. bool ProjectContentComponent::goToPreviousFile()
  581. {
  582. OpenDocumentManager::Document* doc = recentDocumentList.getCurrentDocument();
  583. if (doc == nullptr || doc == getCurrentDocument())
  584. doc = recentDocumentList.getPrevious();
  585. return showDocument (doc, true);
  586. }
  587. bool ProjectContentComponent::goToNextFile()
  588. {
  589. return showDocument (recentDocumentList.getNext(), true);
  590. }
  591. bool ProjectContentComponent::canGoToCounterpart() const
  592. {
  593. return currentDocument != nullptr
  594. && currentDocument->getCounterpartFile().exists();
  595. }
  596. bool ProjectContentComponent::goToCounterpart()
  597. {
  598. if (currentDocument != nullptr)
  599. {
  600. const File file (currentDocument->getCounterpartFile());
  601. if (file.exists())
  602. return showEditorForFile (file, true);
  603. }
  604. return false;
  605. }
  606. bool ProjectContentComponent::saveProject()
  607. {
  608. return project != nullptr
  609. && project->save (true, true) == FileBasedDocument::savedOk;
  610. }
  611. void ProjectContentComponent::closeProject()
  612. {
  613. if (MainWindow* const mw = findParentComponentOfClass<MainWindow>())
  614. mw->closeCurrentProject();
  615. }
  616. void ProjectContentComponent::showFilesTab()
  617. {
  618. treeViewTabs.setCurrentTabIndex (0);
  619. }
  620. void ProjectContentComponent::showConfigTab()
  621. {
  622. treeViewTabs.setCurrentTabIndex (1);
  623. }
  624. void ProjectContentComponent::showProjectSettings()
  625. {
  626. showConfigTab();
  627. if (ConfigTreePanel* const tree = dynamic_cast<ConfigTreePanel*> (treeViewTabs.getCurrentContentComponent()))
  628. tree->showProjectSettings();
  629. }
  630. void ProjectContentComponent::showModules()
  631. {
  632. showConfigTab();
  633. if (ConfigTreePanel* const tree = dynamic_cast<ConfigTreePanel*> (treeViewTabs.getCurrentContentComponent()))
  634. tree->showModules();
  635. }
  636. void ProjectContentComponent::showModule (const String& moduleID)
  637. {
  638. showConfigTab();
  639. if (ConfigTreePanel* const tree = dynamic_cast<ConfigTreePanel*> (treeViewTabs.getCurrentContentComponent()))
  640. tree->showModule (moduleID);
  641. }
  642. StringArray ProjectContentComponent::getExportersWhichCanLaunch() const
  643. {
  644. StringArray s;
  645. if (project != nullptr)
  646. for (Project::ExporterIterator exporter (*project); exporter.next();)
  647. if (exporter->canLaunchProject())
  648. s.add (exporter->getName());
  649. return s;
  650. }
  651. void ProjectContentComponent::openInIDE (int exporterIndex, bool saveFirst)
  652. {
  653. if (saveFirst)
  654. saveProject();
  655. int i = 0;
  656. if (project != nullptr)
  657. for (Project::ExporterIterator exporter (*project); exporter.next();)
  658. if (exporter->canLaunchProject())
  659. if (i++ == exporterIndex && exporter->launchProject())
  660. break;
  661. }
  662. static void openIDEMenuCallback (int result, ProjectContentComponent* comp, bool saveFirst)
  663. {
  664. if (comp != nullptr && result > 0)
  665. comp->openInIDE (result - 1, saveFirst);
  666. }
  667. void ProjectContentComponent::openInIDE (bool saveFirst)
  668. {
  669. if (project != nullptr)
  670. {
  671. StringArray possibleExporters = getExportersWhichCanLaunch();
  672. if (possibleExporters.size() > 1)
  673. {
  674. PopupMenu menu;
  675. for (int i = 0; i < possibleExporters.size(); ++i)
  676. menu.addItem (i + 1, possibleExporters[i]);
  677. menu.showMenuAsync (PopupMenu::Options(),
  678. ModalCallbackFunction::forComponent (openIDEMenuCallback, this, saveFirst));
  679. }
  680. else
  681. {
  682. openInIDE (0, saveFirst);
  683. }
  684. }
  685. }
  686. static void newExporterMenuCallback (int result, ProjectContentComponent* comp)
  687. {
  688. if (comp != nullptr && result > 0)
  689. {
  690. if (Project* p = comp->getProject())
  691. {
  692. String exporterName (ProjectExporter::getExporterNames() [result - 1]);
  693. if (exporterName.isNotEmpty())
  694. p->addNewExporter (exporterName);
  695. }
  696. }
  697. }
  698. void ProjectContentComponent::showNewExporterMenu()
  699. {
  700. if (project != nullptr)
  701. {
  702. PopupMenu menu;
  703. menu.addSectionHeader ("Create a new export target:");
  704. Array<ProjectExporter::ExporterTypeInfo> exporters (ProjectExporter::getExporterTypes());
  705. for (int i = 0; i < exporters.size(); ++i)
  706. {
  707. const ProjectExporter::ExporterTypeInfo& type = exporters.getReference(i);
  708. menu.addItem (i + 1, type.name, true, false, type.getIcon());
  709. }
  710. menu.showMenuAsync (PopupMenu::Options(),
  711. ModalCallbackFunction::forComponent (newExporterMenuCallback, this));
  712. }
  713. }
  714. void ProjectContentComponent::deleteSelectedTreeItems()
  715. {
  716. if (TreePanelBase* const tree = dynamic_cast<TreePanelBase*> (treeViewTabs.getCurrentContentComponent()))
  717. tree->deleteSelectedItems();
  718. }
  719. void ProjectContentComponent::updateMainWindowTitle()
  720. {
  721. if (MainWindow* mw = findParentComponentOfClass<MainWindow>())
  722. {
  723. String title;
  724. File file;
  725. bool edited = false;
  726. if (currentDocument != nullptr)
  727. {
  728. title = currentDocument->getName();
  729. edited = currentDocument->needsSaving();
  730. file = currentDocument->getFile();
  731. }
  732. if (ComponentPeer* peer = mw->getPeer())
  733. {
  734. if (! peer->setDocumentEditedStatus (edited))
  735. if (edited)
  736. title << "*";
  737. peer->setRepresentedFile (file);
  738. }
  739. mw->updateTitle (title);
  740. }
  741. }
  742. void ProjectContentComponent::showBubbleMessage (Rectangle<int> pos, const String& text)
  743. {
  744. addChildComponent (bubbleMessage);
  745. bubbleMessage.setColour (BubbleComponent::backgroundColourId, Colours::white.withAlpha (0.7f));
  746. bubbleMessage.setColour (BubbleComponent::outlineColourId, Colours::black.withAlpha (0.8f));
  747. bubbleMessage.setAlwaysOnTop (true);
  748. bubbleMessage.showAt (pos, AttributedString (text), 3000, true, false);
  749. }
  750. //==============================================================================
  751. void ProjectContentComponent::showTranslationTool()
  752. {
  753. if (translationTool != nullptr)
  754. {
  755. translationTool->toFront (true);
  756. }
  757. else if (project != nullptr)
  758. {
  759. new FloatingToolWindow ("Translation File Builder",
  760. "transToolWindowPos",
  761. new TranslationToolComponent(),
  762. translationTool,
  763. 600, 700,
  764. 600, 400, 10000, 10000);
  765. }
  766. }
  767. //==============================================================================
  768. struct AsyncCommandRetrier : public Timer
  769. {
  770. AsyncCommandRetrier (const ApplicationCommandTarget::InvocationInfo& i) : info (i)
  771. {
  772. info.originatingComponent = nullptr;
  773. startTimer (500);
  774. }
  775. void timerCallback() override
  776. {
  777. stopTimer();
  778. ProjucerApplication::getCommandManager().invoke (info, true);
  779. delete this;
  780. }
  781. ApplicationCommandTarget::InvocationInfo info;
  782. JUCE_DECLARE_NON_COPYABLE (AsyncCommandRetrier)
  783. };
  784. bool reinvokeCommandAfterCancellingModalComps (const ApplicationCommandTarget::InvocationInfo& info)
  785. {
  786. if (ModalComponentManager::getInstance()->cancelAllModalComponents())
  787. {
  788. new AsyncCommandRetrier (info);
  789. return true;
  790. }
  791. return false;
  792. }
  793. //==============================================================================
  794. ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget()
  795. {
  796. return findFirstTargetParentComponent();
  797. }
  798. void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
  799. {
  800. const CommandID ids[] = { CommandIDs::saveDocument,
  801. CommandIDs::saveDocumentAs,
  802. CommandIDs::closeDocument,
  803. CommandIDs::saveProject,
  804. CommandIDs::closeProject,
  805. CommandIDs::openInIDE,
  806. CommandIDs::saveAndOpenInIDE,
  807. CommandIDs::createNewExporter,
  808. CommandIDs::showFilePanel,
  809. CommandIDs::showConfigPanel,
  810. CommandIDs::showProjectSettings,
  811. CommandIDs::showProjectModules,
  812. CommandIDs::goToPreviousDoc,
  813. CommandIDs::goToNextDoc,
  814. CommandIDs::goToCounterpart,
  815. CommandIDs::deleteSelectedItem,
  816. CommandIDs::showTranslationTool,
  817. CommandIDs::showBuildTab,
  818. CommandIDs::cleanAll,
  819. CommandIDs::enableBuild,
  820. CommandIDs::buildNow,
  821. CommandIDs::toggleContinuousBuild,
  822. CommandIDs::showWarnings,
  823. CommandIDs::reinstantiateComp,
  824. CommandIDs::launchApp,
  825. CommandIDs::killApp,
  826. CommandIDs::nextError,
  827. CommandIDs::prevError };
  828. commands.addArray (ids, numElementsInArray (ids));
  829. }
  830. void ProjectContentComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  831. {
  832. String documentName;
  833. if (currentDocument != nullptr)
  834. documentName = " '" + currentDocument->getName().substring (0, 32) + "'";
  835. #if JUCE_MAC
  836. const ModifierKeys cmdCtrl (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier);
  837. #else
  838. const ModifierKeys cmdCtrl (ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  839. #endif
  840. switch (commandID)
  841. {
  842. case CommandIDs::saveProject:
  843. result.setInfo ("Save Project",
  844. "Saves the current project",
  845. CommandCategories::general, 0);
  846. result.setActive (project != nullptr);
  847. break;
  848. case CommandIDs::closeProject:
  849. result.setInfo ("Close Project",
  850. "Closes the current project",
  851. CommandCategories::general, 0);
  852. result.setActive (project != nullptr);
  853. break;
  854. case CommandIDs::saveDocument:
  855. result.setInfo ("Save" + documentName,
  856. "Saves the current document",
  857. CommandCategories::general, 0);
  858. result.setActive (currentDocument != nullptr || project != nullptr);
  859. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
  860. break;
  861. case CommandIDs::saveDocumentAs:
  862. result.setInfo ("Save As...",
  863. "Saves the current document to a new location",
  864. CommandCategories::general, 0);
  865. result.setActive (currentDocument != nullptr);
  866. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  867. break;
  868. case CommandIDs::closeDocument:
  869. result.setInfo ("Close" + documentName,
  870. "Closes the current document",
  871. CommandCategories::general, 0);
  872. result.setActive (contentView != nullptr);
  873. result.defaultKeypresses.add (KeyPress ('w', cmdCtrl, 0));
  874. break;
  875. case CommandIDs::goToPreviousDoc:
  876. result.setInfo ("Previous Document", "Go to previous document", CommandCategories::general, 0);
  877. result.setActive (recentDocumentList.canGoToPrevious());
  878. result.defaultKeypresses.add (KeyPress (KeyPress::leftKey, cmdCtrl, 0));
  879. break;
  880. case CommandIDs::goToNextDoc:
  881. result.setInfo ("Next Document", "Go to next document", CommandCategories::general, 0);
  882. result.setActive (recentDocumentList.canGoToNext());
  883. result.defaultKeypresses.add (KeyPress (KeyPress::rightKey, cmdCtrl, 0));
  884. break;
  885. case CommandIDs::goToCounterpart:
  886. result.setInfo ("Open corresponding header or cpp file", "Open counterpart file", CommandCategories::general, 0);
  887. result.setActive (canGoToCounterpart());
  888. result.defaultKeypresses.add (KeyPress (KeyPress::upKey, cmdCtrl, 0));
  889. break;
  890. case CommandIDs::openInIDE:
  891. result.setInfo ("Open in IDE...",
  892. "Launches the project in an external IDE",
  893. CommandCategories::general, 0);
  894. result.setActive (ProjectExporter::canProjectBeLaunched (project));
  895. break;
  896. case CommandIDs::saveAndOpenInIDE:
  897. result.setInfo ("Save Project and Open in IDE...",
  898. "Saves the project and launches it in an external IDE",
  899. CommandCategories::general, 0);
  900. result.setActive (ProjectExporter::canProjectBeLaunched (project));
  901. result.defaultKeypresses.add (KeyPress ('l', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  902. break;
  903. case CommandIDs::createNewExporter:
  904. result.setInfo ("Create New Exporter...",
  905. "Creates a new exporter for a compiler type",
  906. CommandCategories::general, 0);
  907. result.setActive (project != nullptr);
  908. break;
  909. case CommandIDs::showFilePanel:
  910. result.setInfo ("Show File Panel",
  911. "Shows the tree of files for this project",
  912. CommandCategories::general, 0);
  913. result.setActive (project != nullptr);
  914. result.defaultKeypresses.add (KeyPress ('p', ModifierKeys::commandModifier, 0));
  915. break;
  916. case CommandIDs::showConfigPanel:
  917. result.setInfo ("Show Config Panel",
  918. "Shows the build options for the project",
  919. CommandCategories::general, 0);
  920. result.setActive (project != nullptr);
  921. result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier, 0));
  922. break;
  923. case CommandIDs::showProjectSettings:
  924. result.setInfo ("Show Project Settings",
  925. "Shows the main project options page",
  926. CommandCategories::general, 0);
  927. result.setActive (project != nullptr);
  928. result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  929. break;
  930. case CommandIDs::showProjectModules:
  931. result.setInfo ("Show Project Modules",
  932. "Shows the project's list of modules",
  933. CommandCategories::general, 0);
  934. result.setActive (project != nullptr);
  935. result.defaultKeypresses.add (KeyPress ('m', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  936. break;
  937. case CommandIDs::deleteSelectedItem:
  938. result.setInfo ("Delete Selected File", String::empty, CommandCategories::general, 0);
  939. result.defaultKeypresses.add (KeyPress (KeyPress::deleteKey, 0, 0));
  940. result.defaultKeypresses.add (KeyPress (KeyPress::backspaceKey, 0, 0));
  941. result.setActive (dynamic_cast<TreePanelBase*> (treeViewTabs.getCurrentContentComponent()) != nullptr);
  942. break;
  943. case CommandIDs::showTranslationTool:
  944. result.setInfo ("Translation File Builder", "Shows the translation file helper tool", CommandCategories::general, 0);
  945. break;
  946. case CommandIDs::showBuildTab:
  947. result.setInfo ("Show Build Panel", "Shows the build panel", CommandCategories::general, 0);
  948. //result.defaultKeypresses.add (KeyPress ('b', ModifierKeys::commandModifier, 0));
  949. break;
  950. case CommandIDs::cleanAll:
  951. result.setInfo ("Clean All", "Cleans all intermediate files", CommandCategories::general, 0);
  952. result.defaultKeypresses.add (KeyPress ('k', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  953. result.setActive (project != nullptr);
  954. break;
  955. case CommandIDs::enableBuild:
  956. result.setInfo ("Enable Compilation", "Enables/disables the compiler", CommandCategories::general, 0);
  957. result.defaultKeypresses.add (KeyPress ('b', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  958. result.setActive (project != nullptr);
  959. result.setTicked (childProcess != nullptr);
  960. break;
  961. case CommandIDs::buildNow:
  962. result.setInfo ("Build Now", "Recompiles any out-of-date files and updates the JIT engine", CommandCategories::general, 0);
  963. result.defaultKeypresses.add (KeyPress ('b', ModifierKeys::commandModifier, 0));
  964. result.setActive (childProcess != nullptr);
  965. break;
  966. case CommandIDs::toggleContinuousBuild:
  967. result.setInfo ("Enable Continuous Recompiling", "Continuously recompiles any changes made in code editors", CommandCategories::general, 0);
  968. result.setActive (childProcess != nullptr);
  969. result.setTicked (isContinuousRebuildEnabled());
  970. break;
  971. case CommandIDs::showWarnings:
  972. result.setInfo ("Show Warnings", "Shows or hides compilation warnings", CommandCategories::general, 0);
  973. result.setActive (project != nullptr);
  974. result.setTicked (areWarningsEnabled());
  975. break;
  976. case CommandIDs::launchApp:
  977. result.setInfo ("Launch Application", "Invokes the app's main() function", CommandCategories::general, 0);
  978. result.defaultKeypresses.add (KeyPress ('r', ModifierKeys::commandModifier, 0));
  979. result.setActive (childProcess != nullptr && childProcess->canLaunchApp());
  980. break;
  981. case CommandIDs::killApp:
  982. result.setInfo ("Stop Application", "Kills the app if it's running", CommandCategories::general, 0);
  983. result.defaultKeypresses.add (KeyPress ('.', ModifierKeys::commandModifier, 0));
  984. result.setActive (childProcess != nullptr && childProcess->canKillApp());
  985. break;
  986. case CommandIDs::reinstantiateComp:
  987. result.setInfo ("Re-instantiate Components", "Re-loads any component editors that are open", CommandCategories::general, 0);
  988. result.defaultKeypresses.add (KeyPress ('r', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  989. result.setActive (childProcess != nullptr);
  990. break;
  991. case CommandIDs::nextError:
  992. result.setInfo ("Highlight next error", "Jumps to the next error or warning", CommandCategories::general, 0);
  993. result.defaultKeypresses.add (KeyPress ('e', ModifierKeys::commandModifier, 0));
  994. result.setActive (childProcess != nullptr && ! childProcess->errorList.isEmpty());
  995. break;
  996. case CommandIDs::prevError:
  997. result.setInfo ("Highlight previous error", "Jumps to the last error or warning", CommandCategories::general, 0);
  998. result.defaultKeypresses.add (KeyPress ('e', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  999. result.setActive (childProcess != nullptr && ! childProcess->errorList.isEmpty());
  1000. break;
  1001. default:
  1002. break;
  1003. }
  1004. }
  1005. bool ProjectContentComponent::perform (const InvocationInfo& info)
  1006. {
  1007. switch (info.commandID)
  1008. {
  1009. case CommandIDs::saveProject:
  1010. case CommandIDs::closeProject:
  1011. case CommandIDs::saveDocument:
  1012. case CommandIDs::saveDocumentAs:
  1013. case CommandIDs::closeDocument:
  1014. case CommandIDs::goToPreviousDoc:
  1015. case CommandIDs::goToNextDoc:
  1016. case CommandIDs::goToCounterpart:
  1017. case CommandIDs::saveAndOpenInIDE:
  1018. if (reinvokeCommandAfterCancellingModalComps (info))
  1019. {
  1020. grabKeyboardFocus(); // to force any open labels to close their text editors
  1021. return true;
  1022. }
  1023. break;
  1024. default:
  1025. break;
  1026. }
  1027. if (isCurrentlyBlockedByAnotherModalComponent())
  1028. return false;
  1029. switch (info.commandID)
  1030. {
  1031. case CommandIDs::saveProject: saveProject(); break;
  1032. case CommandIDs::closeProject: closeProject(); break;
  1033. case CommandIDs::saveDocument: saveDocument(); break;
  1034. case CommandIDs::saveDocumentAs: saveAs(); break;
  1035. case CommandIDs::closeDocument: closeDocument(); break;
  1036. case CommandIDs::goToPreviousDoc: goToPreviousFile(); break;
  1037. case CommandIDs::goToNextDoc: goToNextFile(); break;
  1038. case CommandIDs::goToCounterpart: goToCounterpart(); break;
  1039. case CommandIDs::showFilePanel: showFilesTab(); break;
  1040. case CommandIDs::showConfigPanel: showConfigTab(); break;
  1041. case CommandIDs::showProjectSettings: showProjectSettings(); break;
  1042. case CommandIDs::showProjectModules: showModules(); break;
  1043. case CommandIDs::openInIDE: openInIDE (false); break;
  1044. case CommandIDs::saveAndOpenInIDE: openInIDE (true); break;
  1045. case CommandIDs::createNewExporter: showNewExporterMenu(); break;
  1046. case CommandIDs::deleteSelectedItem: deleteSelectedTreeItems(); break;
  1047. case CommandIDs::showTranslationTool: showTranslationTool(); break;
  1048. case CommandIDs::showBuildTab: showBuildTab(); break;
  1049. case CommandIDs::cleanAll: cleanAll(); break;
  1050. case CommandIDs::enableBuild: setBuildEnabled (! isBuildEnabled()); break;
  1051. case CommandIDs::buildNow: rebuildNow(); break;
  1052. case CommandIDs::toggleContinuousBuild: setContinuousRebuildEnabled (! isContinuousRebuildEnabled()); break;
  1053. case CommandIDs::launchApp: launchApp(); break;
  1054. case CommandIDs::killApp: killApp(); break;
  1055. case CommandIDs::reinstantiateComp: reinstantiateLivePreviewWindows(); break;
  1056. case CommandIDs::showWarnings: toggleWarnings(); break;
  1057. case CommandIDs::nextError: showNextError(); break;
  1058. case CommandIDs::prevError: showPreviousError(); break;
  1059. default:
  1060. return false;
  1061. }
  1062. return true;
  1063. }
  1064. void ProjectContentComponent::getSelectedProjectItemsBeingDragged (const DragAndDropTarget::SourceDetails& dragSourceDetails,
  1065. OwnedArray<Project::Item>& selectedNodes)
  1066. {
  1067. FileTreeItemTypes::ProjectTreeItemBase::getSelectedProjectItemsBeingDragged (dragSourceDetails, selectedNodes);
  1068. }
  1069. //==============================================================================
  1070. void ProjectContentComponent::killChildProcess()
  1071. {
  1072. if (childProcess != nullptr)
  1073. {
  1074. deleteProjectTabs();
  1075. childProcess = nullptr;
  1076. ProjucerApplication::getApp().childProcessCache->removeOrphans();
  1077. }
  1078. }
  1079. void ProjectContentComponent::setBuildEnabled (bool b)
  1080. {
  1081. if (project != nullptr && b != isBuildEnabled())
  1082. {
  1083. LiveBuildProjectSettings::setBuildDisabled (*project, ! b);
  1084. killChildProcess();
  1085. refreshTabsIfBuildStatusChanged();
  1086. }
  1087. }
  1088. void ProjectContentComponent::showBuildTab()
  1089. {
  1090. WeakReference<Component> currentFocus (Component::getCurrentlyFocusedComponent());
  1091. treeViewTabs.setCurrentTabIndex (2);
  1092. if (currentFocus != nullptr)
  1093. currentFocus->grabKeyboardFocus();
  1094. }
  1095. void ProjectContentComponent::cleanAll()
  1096. {
  1097. lastCrashMessage = String();
  1098. if (childProcess != nullptr)
  1099. childProcess->cleanAll();
  1100. else if (Project* p = getProject())
  1101. CompileEngineChildProcess::cleanAllCachedFilesForProject (*p);
  1102. }
  1103. void ProjectContentComponent::handleCrash (const String& message)
  1104. {
  1105. lastCrashMessage = message.isEmpty() ? TRANS("JIT process stopped responding!")
  1106. : (TRANS("JIT process crashed!") + ":\n\n" + message);
  1107. if (project != nullptr)
  1108. {
  1109. setBuildEnabled (false);
  1110. showBuildTab();
  1111. }
  1112. }
  1113. bool ProjectContentComponent::isBuildEnabled() const
  1114. {
  1115. return project != nullptr
  1116. && ! LiveBuildProjectSettings::isBuildDisabled (*project)
  1117. && ProjucerLicenses::getInstance()->hasLiveCodingLicence()
  1118. && ProjucerLicenses::getInstance()->isLoggedIn();
  1119. }
  1120. void ProjectContentComponent::refreshTabsIfBuildStatusChanged()
  1121. {
  1122. if (project != nullptr
  1123. && (treeViewTabs.getNumTabs() < 3
  1124. || isBuildEnabled() != isBuildTabEnabled()
  1125. || ProjucerLicenses::getInstance()->isLoggedIn() != isBuildTabSuitableForLoggedInUser()))
  1126. rebuildProjectTabs();
  1127. }
  1128. bool ProjectContentComponent::areWarningsEnabled() const
  1129. {
  1130. return project != nullptr && ! LiveBuildProjectSettings::areWarningsDisabled (*project);
  1131. }
  1132. void ProjectContentComponent::updateWarningState()
  1133. {
  1134. if (childProcess != nullptr)
  1135. childProcess->errorList.setWarningsEnabled (areWarningsEnabled());
  1136. }
  1137. void ProjectContentComponent::toggleWarnings()
  1138. {
  1139. if (project != nullptr)
  1140. {
  1141. LiveBuildProjectSettings::setWarningsDisabled (*project, areWarningsEnabled());
  1142. updateWarningState();
  1143. }
  1144. }
  1145. static ProjucerAppClasses::ErrorListComp* findErrorListComp (const TabbedComponent& tabs)
  1146. {
  1147. if (BuildTabComponent* bt = findBuildTab (tabs))
  1148. return bt->errorListComp;
  1149. return nullptr;
  1150. }
  1151. void ProjectContentComponent::showNextError()
  1152. {
  1153. if (ProjucerAppClasses::ErrorListComp* el = findErrorListComp (treeViewTabs))
  1154. {
  1155. showBuildTab();
  1156. el->showNext();
  1157. }
  1158. }
  1159. void ProjectContentComponent::showPreviousError()
  1160. {
  1161. if (ProjucerAppClasses::ErrorListComp* el = findErrorListComp (treeViewTabs))
  1162. {
  1163. showBuildTab();
  1164. el->showPrevious();
  1165. }
  1166. }
  1167. void ProjectContentComponent::reinstantiateLivePreviewWindows()
  1168. {
  1169. if (childProcess != nullptr)
  1170. childProcess->reinstantiatePreviews();
  1171. }
  1172. void ProjectContentComponent::launchApp()
  1173. {
  1174. if (childProcess != nullptr)
  1175. childProcess->launchApp();
  1176. }
  1177. void ProjectContentComponent::killApp()
  1178. {
  1179. if (childProcess != nullptr)
  1180. childProcess->killApp();
  1181. }
  1182. void ProjectContentComponent::rebuildNow()
  1183. {
  1184. if (childProcess != nullptr)
  1185. childProcess->flushEditorChanges();
  1186. }
  1187. void ProjectContentComponent::globalFocusChanged (Component* focusedComponent)
  1188. {
  1189. const bool nowForeground = (Process::isForegroundProcess()
  1190. && (focusedComponent == this || isParentOf (focusedComponent)));
  1191. if (nowForeground != isForeground)
  1192. {
  1193. isForeground = nowForeground;
  1194. if (childProcess != nullptr)
  1195. childProcess->processActivationChanged (isForeground);
  1196. }
  1197. }
  1198. void ProjectContentComponent::timerCallback()
  1199. {
  1200. if (! isBuildEnabled())
  1201. killChildProcess();
  1202. refreshTabsIfBuildStatusChanged();
  1203. }
  1204. ReferenceCountedObjectPtr<CompileEngineChildProcess> ProjectContentComponent::getChildProcess()
  1205. {
  1206. if (childProcess == nullptr && isBuildEnabled())
  1207. {
  1208. childProcess = ProjucerApplication::getApp().childProcessCache->getOrCreate (*project);
  1209. if (childProcess != nullptr)
  1210. childProcess->setContinuousRebuild (isContinuousRebuildEnabled());
  1211. }
  1212. return childProcess;
  1213. }
  1214. void ProjectContentComponent::handleMissingSystemHeaders()
  1215. {
  1216. #if JUCE_MAC
  1217. const String tabMessage = "Compiler not available due to missing system headers\nPlease install a recent version of Xcode";
  1218. const String alertWindowMessage = "Missing system headers\nPlease install a recent version of Xcode";
  1219. #elif JUCE_WINDOWS
  1220. const String tabMessage = "Compiler not available due to missing system headers\nPlease install a recent version of Visual Studio and the Windows Desktop SDK";
  1221. const String alertWindowMessage = "Missing system headers\nPlease install a recent version of Visual Studio and the Windows Desktop SDK";
  1222. #elif JUCE_LINUX
  1223. const String tabMessage = "Compiler not available due to missing system headers\nPlease do a sudo apt-get install ...";
  1224. const String alertWindowMessage = "Missing system headers\nPlease do sudo apt-get install ...";
  1225. #endif
  1226. setBuildEnabled (false);
  1227. deleteProjectTabs();
  1228. createProjectTabs();
  1229. ProjucerDisabledComp* buildTab = new ProjucerDisabledComp (tabMessage, false, false);
  1230. treeViewTabs.addTab ("Build", Colours::transparentBlack, buildTab, true);
  1231. showBuildTab();
  1232. AlertWindow::showMessageBox (AlertWindow::AlertIconType::WarningIcon,
  1233. "Missing system headers", alertWindowMessage);
  1234. }