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.

1504 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 canLogin, bool requirePurchase = false,
  279. const String& loginName = String())
  280. : 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. ProjucerLicences::getInstance()->logout();
  324. ProjucerApplication::getApp().updateAllBuildTabs();
  325. }
  326. }
  327. Label infoLabel { "info", String() };
  328. TextButton loginButton { "Log-in..." };
  329. ScopedPointer<TextButton> signOutButton;
  330. bool 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_WINDOWS
  360. ignoreUnused (child);
  361. return new ProjucerDisabledComp ("Windows support is still under development - "
  362. "please check for updates at www.juce.com!", false);
  363. #elif JUCE_LINUX
  364. ignoreUnused (child);
  365. return new ProjucerDisabledComp ("Linux support is still under development - "
  366. "please check for updates at www.juce.com!", false);
  367. #else
  368. if (child != nullptr)
  369. {
  370. child->crashHandler = [this] (const String& m) { this->handleCrash (m); };
  371. return new BuildTabComponent (child, new ProjucerAppClasses::ErrorListComp (child->errorList));
  372. }
  373. auto& unlockStatus = *ProjucerLicences::getInstance();
  374. if (unlockStatus.hasLiveCodingLicence()
  375. && project != nullptr
  376. && LiveBuildProjectSettings::isBuildDisabled (*project))
  377. return new EnableBuildComp();
  378. if (unlockStatus.isLoggedIn())
  379. return new ProjucerDisabledComp (String ("The Projucer's live-build features are currently disabled!") + newLine
  380. + newLine
  381. + "Your account " + unlockStatus.getLoginName().quoted()
  382. + " does not have an asscociated JUCE Pro license:",
  383. true, true, unlockStatus.getLoginName());
  384. if (! unlockStatus.isDLLPresent())
  385. return new ProjucerDisabledComp (String ("The live-building DLL is missing!") + newLine
  386. + newLine
  387. + "To enable the compiler, you'll need to install the missing DLL "
  388. + CompileEngineDLL::getDLLName().quoted() + newLine
  389. + newLine
  390. + "Visit the JUCE website/forum for more help on getting and installing the DLL!", false);
  391. return new ProjucerDisabledComp ("The Projucer's live-build features are currently disabled!\n\n"
  392. "To enable them, you'll need to log-in with your JUCE account details:", true, false);
  393. #endif
  394. }
  395. BuildTabComponent* findBuildTab (const TabbedComponent& tabs)
  396. {
  397. return dynamic_cast<BuildTabComponent*> (tabs.getTabContentComponent (2));
  398. }
  399. bool ProjectContentComponent::isBuildTabShowing() const
  400. {
  401. return findBuildTab (treeViewTabs) != nullptr;
  402. }
  403. bool ProjectContentComponent::isLoggedInTabShowing() const
  404. {
  405. return isBuildTabShowing() || dynamic_cast<EnableBuildComp*> (treeViewTabs.getTabContentComponent (2)) != nullptr;
  406. }
  407. void ProjectContentComponent::createProjectTabs()
  408. {
  409. jassert (project != nullptr);
  410. const Colour tabColour (Colours::transparentBlack);
  411. treeViewTabs.addTab ("Files", tabColour, new FileTreePanel (*project), true);
  412. treeViewTabs.addTab ("Config", tabColour, new ConfigTreePanel (*project), true);
  413. const CompileEngineChildProcess::Ptr childProc (getChildProcess());
  414. treeViewTabs.addTab ("Build", Colours::transparentBlack, createBuildTab (childProc), true);
  415. if (childProc != nullptr)
  416. treeViewTabs.getTabbedButtonBar().getTabButton (2)
  417. ->setExtraComponent (new BuildStatusTabComp (childProc->errorList,
  418. childProc->activityList),
  419. TabBarButton::afterText);
  420. }
  421. void ProjectContentComponent::deleteProjectTabs()
  422. {
  423. if (project != nullptr && treeViewTabs.isShowing())
  424. {
  425. PropertiesFile& settings = project->getStoredProperties();
  426. if (treeViewTabs.getWidth() > 0)
  427. settings.setValue ("projectPanelWidth", treeViewTabs.getWidth());
  428. if (treeViewTabs.getNumTabs() > 0)
  429. settings.setValue ("lastTab", treeViewTabs.getCurrentTabName());
  430. }
  431. treeViewTabs.clearTabs();
  432. }
  433. void ProjectContentComponent::saveTreeViewState()
  434. {
  435. for (int i = treeViewTabs.getNumTabs(); --i >= 0;)
  436. if (TreePanelBase* t = dynamic_cast<TreePanelBase*> (treeViewTabs.getTabContentComponent (i)))
  437. t->saveOpenness();
  438. }
  439. void ProjectContentComponent::saveOpenDocumentList()
  440. {
  441. if (project != nullptr)
  442. {
  443. ScopedPointer<XmlElement> xml (recentDocumentList.createXML());
  444. if (xml != nullptr)
  445. project->getStoredProperties().setValue ("lastDocs", xml);
  446. }
  447. }
  448. void ProjectContentComponent::reloadLastOpenDocuments()
  449. {
  450. if (project != nullptr)
  451. {
  452. ScopedPointer<XmlElement> xml (project->getStoredProperties().getXmlValue ("lastDocs"));
  453. if (xml != nullptr)
  454. {
  455. recentDocumentList.restoreFromXML (*project, *xml);
  456. showDocument (recentDocumentList.getCurrentDocument(), true);
  457. }
  458. }
  459. }
  460. bool ProjectContentComponent::documentAboutToClose (OpenDocumentManager::Document* document)
  461. {
  462. hideDocument (document);
  463. return true;
  464. }
  465. void ProjectContentComponent::changeListenerCallback (ChangeBroadcaster*)
  466. {
  467. updateMissingFileStatuses();
  468. }
  469. void ProjectContentComponent::updateMissingFileStatuses()
  470. {
  471. if (FileTreePanel* tree = dynamic_cast<FileTreePanel*> (treeViewTabs.getTabContentComponent (0)))
  472. tree->updateMissingFileStatuses();
  473. }
  474. bool ProjectContentComponent::showEditorForFile (const File& f, bool grabFocus)
  475. {
  476. return getCurrentFile() == f
  477. || showDocument (ProjucerApplication::getApp().openDocumentManager.openFile (project, f), grabFocus);
  478. }
  479. bool ProjectContentComponent::hasFileInRecentList (const File& f) const
  480. {
  481. return recentDocumentList.contains (f);
  482. }
  483. File ProjectContentComponent::getCurrentFile() const
  484. {
  485. return currentDocument != nullptr ? currentDocument->getFile()
  486. : File::nonexistent;
  487. }
  488. bool ProjectContentComponent::showDocument (OpenDocumentManager::Document* doc, bool grabFocus)
  489. {
  490. if (doc == nullptr)
  491. return false;
  492. if (doc->hasFileBeenModifiedExternally())
  493. doc->reloadFromFile();
  494. if (doc == getCurrentDocument() && contentView != nullptr)
  495. {
  496. if (grabFocus)
  497. contentView->grabKeyboardFocus();
  498. return true;
  499. }
  500. recentDocumentList.newDocumentOpened (doc);
  501. bool opened = setEditorComponent (doc->createEditor(), doc);
  502. if (opened && grabFocus)
  503. contentView->grabKeyboardFocus();
  504. return opened;
  505. }
  506. void ProjectContentComponent::hideEditor()
  507. {
  508. currentDocument = nullptr;
  509. contentView = nullptr;
  510. updateMainWindowTitle();
  511. ProjucerApplication::getCommandManager().commandStatusChanged();
  512. resized();
  513. }
  514. void ProjectContentComponent::hideDocument (OpenDocumentManager::Document* doc)
  515. {
  516. if (doc == currentDocument)
  517. {
  518. if (OpenDocumentManager::Document* replacement = recentDocumentList.getClosestPreviousDocOtherThan (doc))
  519. showDocument (replacement, true);
  520. else
  521. hideEditor();
  522. }
  523. }
  524. bool ProjectContentComponent::setEditorComponent (Component* editor,
  525. OpenDocumentManager::Document* doc)
  526. {
  527. if (editor != nullptr)
  528. {
  529. contentView = nullptr;
  530. contentView = editor;
  531. currentDocument = doc;
  532. addAndMakeVisible (editor);
  533. resized();
  534. updateMainWindowTitle();
  535. ProjucerApplication::getCommandManager().commandStatusChanged();
  536. return true;
  537. }
  538. updateMainWindowTitle();
  539. return false;
  540. }
  541. void ProjectContentComponent::closeDocument()
  542. {
  543. if (currentDocument != nullptr)
  544. ProjucerApplication::getApp().openDocumentManager.closeDocument (currentDocument, true);
  545. else if (contentView != nullptr)
  546. if (! goToPreviousFile())
  547. hideEditor();
  548. }
  549. static void showSaveWarning (OpenDocumentManager::Document* currentDocument)
  550. {
  551. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  552. TRANS("Save failed!"),
  553. TRANS("Couldn't save the file:")
  554. + "\n" + currentDocument->getFile().getFullPathName());
  555. }
  556. void ProjectContentComponent::saveDocument()
  557. {
  558. if (currentDocument != nullptr)
  559. {
  560. if (! currentDocument->save())
  561. showSaveWarning (currentDocument);
  562. }
  563. else
  564. saveProject();
  565. updateMainWindowTitle();
  566. }
  567. void ProjectContentComponent::saveAs()
  568. {
  569. if (currentDocument != nullptr && ! currentDocument->saveAs())
  570. showSaveWarning (currentDocument);
  571. }
  572. bool ProjectContentComponent::goToPreviousFile()
  573. {
  574. OpenDocumentManager::Document* doc = recentDocumentList.getCurrentDocument();
  575. if (doc == nullptr || doc == getCurrentDocument())
  576. doc = recentDocumentList.getPrevious();
  577. return showDocument (doc, true);
  578. }
  579. bool ProjectContentComponent::goToNextFile()
  580. {
  581. return showDocument (recentDocumentList.getNext(), true);
  582. }
  583. bool ProjectContentComponent::canGoToCounterpart() const
  584. {
  585. return currentDocument != nullptr
  586. && currentDocument->getCounterpartFile().exists();
  587. }
  588. bool ProjectContentComponent::goToCounterpart()
  589. {
  590. if (currentDocument != nullptr)
  591. {
  592. const File file (currentDocument->getCounterpartFile());
  593. if (file.exists())
  594. return showEditorForFile (file, true);
  595. }
  596. return false;
  597. }
  598. bool ProjectContentComponent::saveProject()
  599. {
  600. return project != nullptr
  601. && project->save (true, true) == FileBasedDocument::savedOk;
  602. }
  603. void ProjectContentComponent::closeProject()
  604. {
  605. if (MainWindow* const mw = findParentComponentOfClass<MainWindow>())
  606. mw->closeCurrentProject();
  607. }
  608. void ProjectContentComponent::showFilesTab()
  609. {
  610. treeViewTabs.setCurrentTabIndex (0);
  611. }
  612. void ProjectContentComponent::showConfigTab()
  613. {
  614. treeViewTabs.setCurrentTabIndex (1);
  615. }
  616. void ProjectContentComponent::showProjectSettings()
  617. {
  618. showConfigTab();
  619. if (ConfigTreePanel* const tree = dynamic_cast<ConfigTreePanel*> (treeViewTabs.getCurrentContentComponent()))
  620. tree->showProjectSettings();
  621. }
  622. void ProjectContentComponent::showModules()
  623. {
  624. showConfigTab();
  625. if (ConfigTreePanel* const tree = dynamic_cast<ConfigTreePanel*> (treeViewTabs.getCurrentContentComponent()))
  626. tree->showModules();
  627. }
  628. void ProjectContentComponent::showModule (const String& moduleID)
  629. {
  630. showConfigTab();
  631. if (ConfigTreePanel* const tree = dynamic_cast<ConfigTreePanel*> (treeViewTabs.getCurrentContentComponent()))
  632. tree->showModule (moduleID);
  633. }
  634. StringArray ProjectContentComponent::getExportersWhichCanLaunch() const
  635. {
  636. StringArray s;
  637. if (project != nullptr)
  638. for (Project::ExporterIterator exporter (*project); exporter.next();)
  639. if (exporter->canLaunchProject())
  640. s.add (exporter->getName());
  641. return s;
  642. }
  643. void ProjectContentComponent::openInIDE (int exporterIndex, bool saveFirst)
  644. {
  645. if (saveFirst)
  646. saveProject();
  647. int i = 0;
  648. if (project != nullptr)
  649. for (Project::ExporterIterator exporter (*project); exporter.next();)
  650. if (exporter->canLaunchProject())
  651. if (i++ == exporterIndex && exporter->launchProject())
  652. break;
  653. }
  654. static void openIDEMenuCallback (int result, ProjectContentComponent* comp, bool saveFirst)
  655. {
  656. if (comp != nullptr && result > 0)
  657. comp->openInIDE (result - 1, saveFirst);
  658. }
  659. void ProjectContentComponent::openInIDE (bool saveFirst)
  660. {
  661. if (project != nullptr)
  662. {
  663. StringArray possibleExporters = getExportersWhichCanLaunch();
  664. if (possibleExporters.size() > 1)
  665. {
  666. PopupMenu menu;
  667. for (int i = 0; i < possibleExporters.size(); ++i)
  668. menu.addItem (i + 1, possibleExporters[i]);
  669. menu.showMenuAsync (PopupMenu::Options(),
  670. ModalCallbackFunction::forComponent (openIDEMenuCallback, this, saveFirst));
  671. }
  672. else
  673. {
  674. openInIDE (0, saveFirst);
  675. }
  676. }
  677. }
  678. static void newExporterMenuCallback (int result, ProjectContentComponent* comp)
  679. {
  680. if (comp != nullptr && result > 0)
  681. {
  682. if (Project* p = comp->getProject())
  683. {
  684. String exporterName (ProjectExporter::getExporterNames() [result - 1]);
  685. if (exporterName.isNotEmpty())
  686. p->addNewExporter (exporterName);
  687. }
  688. }
  689. }
  690. void ProjectContentComponent::showNewExporterMenu()
  691. {
  692. if (project != nullptr)
  693. {
  694. PopupMenu menu;
  695. menu.addSectionHeader ("Create a new export target:");
  696. Array<ProjectExporter::ExporterTypeInfo> exporters (ProjectExporter::getExporterTypes());
  697. for (int i = 0; i < exporters.size(); ++i)
  698. {
  699. const ProjectExporter::ExporterTypeInfo& type = exporters.getReference(i);
  700. menu.addItem (i + 1, type.name, true, false, type.getIcon());
  701. }
  702. menu.showMenuAsync (PopupMenu::Options(),
  703. ModalCallbackFunction::forComponent (newExporterMenuCallback, this));
  704. }
  705. }
  706. void ProjectContentComponent::deleteSelectedTreeItems()
  707. {
  708. if (TreePanelBase* const tree = dynamic_cast<TreePanelBase*> (treeViewTabs.getCurrentContentComponent()))
  709. tree->deleteSelectedItems();
  710. }
  711. void ProjectContentComponent::updateMainWindowTitle()
  712. {
  713. if (MainWindow* mw = findParentComponentOfClass<MainWindow>())
  714. {
  715. String title;
  716. File file;
  717. bool edited = false;
  718. if (currentDocument != nullptr)
  719. {
  720. title = currentDocument->getName();
  721. edited = currentDocument->needsSaving();
  722. file = currentDocument->getFile();
  723. }
  724. if (ComponentPeer* peer = mw->getPeer())
  725. {
  726. if (! peer->setDocumentEditedStatus (edited))
  727. if (edited)
  728. title << "*";
  729. peer->setRepresentedFile (file);
  730. }
  731. mw->updateTitle (title);
  732. }
  733. }
  734. void ProjectContentComponent::showBubbleMessage (Rectangle<int> pos, const String& text)
  735. {
  736. addChildComponent (bubbleMessage);
  737. bubbleMessage.setColour (BubbleComponent::backgroundColourId, Colours::white.withAlpha (0.7f));
  738. bubbleMessage.setColour (BubbleComponent::outlineColourId, Colours::black.withAlpha (0.8f));
  739. bubbleMessage.setAlwaysOnTop (true);
  740. bubbleMessage.showAt (pos, AttributedString (text), 3000, true, false);
  741. }
  742. //==============================================================================
  743. void ProjectContentComponent::showTranslationTool()
  744. {
  745. if (translationTool != nullptr)
  746. {
  747. translationTool->toFront (true);
  748. }
  749. else if (project != nullptr)
  750. {
  751. new FloatingToolWindow ("Translation File Builder",
  752. "transToolWindowPos",
  753. new TranslationToolComponent(),
  754. translationTool,
  755. 600, 700,
  756. 600, 400, 10000, 10000);
  757. }
  758. }
  759. //==============================================================================
  760. struct AsyncCommandRetrier : public Timer
  761. {
  762. AsyncCommandRetrier (const ApplicationCommandTarget::InvocationInfo& i) : info (i)
  763. {
  764. info.originatingComponent = nullptr;
  765. startTimer (500);
  766. }
  767. void timerCallback() override
  768. {
  769. stopTimer();
  770. ProjucerApplication::getCommandManager().invoke (info, true);
  771. delete this;
  772. }
  773. ApplicationCommandTarget::InvocationInfo info;
  774. JUCE_DECLARE_NON_COPYABLE (AsyncCommandRetrier)
  775. };
  776. bool reinvokeCommandAfterCancellingModalComps (const ApplicationCommandTarget::InvocationInfo& info)
  777. {
  778. if (ModalComponentManager::getInstance()->cancelAllModalComponents())
  779. {
  780. new AsyncCommandRetrier (info);
  781. return true;
  782. }
  783. return false;
  784. }
  785. //==============================================================================
  786. ApplicationCommandTarget* ProjectContentComponent::getNextCommandTarget()
  787. {
  788. return findFirstTargetParentComponent();
  789. }
  790. void ProjectContentComponent::getAllCommands (Array <CommandID>& commands)
  791. {
  792. const CommandID ids[] = { CommandIDs::saveDocument,
  793. CommandIDs::saveDocumentAs,
  794. CommandIDs::closeDocument,
  795. CommandIDs::saveProject,
  796. CommandIDs::closeProject,
  797. CommandIDs::openInIDE,
  798. CommandIDs::saveAndOpenInIDE,
  799. CommandIDs::createNewExporter,
  800. CommandIDs::showFilePanel,
  801. CommandIDs::showConfigPanel,
  802. CommandIDs::showProjectSettings,
  803. CommandIDs::showProjectModules,
  804. CommandIDs::goToPreviousDoc,
  805. CommandIDs::goToNextDoc,
  806. CommandIDs::goToCounterpart,
  807. CommandIDs::deleteSelectedItem,
  808. CommandIDs::showTranslationTool,
  809. CommandIDs::showBuildTab,
  810. CommandIDs::cleanAll,
  811. CommandIDs::enableBuild,
  812. CommandIDs::buildNow,
  813. CommandIDs::toggleContinuousBuild,
  814. CommandIDs::showWarnings,
  815. CommandIDs::reinstantiateComp,
  816. CommandIDs::launchApp,
  817. CommandIDs::killApp,
  818. CommandIDs::nextError,
  819. CommandIDs::prevError };
  820. commands.addArray (ids, numElementsInArray (ids));
  821. }
  822. void ProjectContentComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  823. {
  824. String documentName;
  825. if (currentDocument != nullptr)
  826. documentName = " '" + currentDocument->getName().substring (0, 32) + "'";
  827. #if JUCE_MAC
  828. const ModifierKeys cmdCtrl (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier);
  829. #else
  830. const ModifierKeys cmdCtrl (ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  831. #endif
  832. switch (commandID)
  833. {
  834. case CommandIDs::saveProject:
  835. result.setInfo ("Save Project",
  836. "Saves the current project",
  837. CommandCategories::general, 0);
  838. result.setActive (project != nullptr);
  839. break;
  840. case CommandIDs::closeProject:
  841. result.setInfo ("Close Project",
  842. "Closes the current project",
  843. CommandCategories::general, 0);
  844. result.setActive (project != nullptr);
  845. break;
  846. case CommandIDs::saveDocument:
  847. result.setInfo ("Save" + documentName,
  848. "Saves the current document",
  849. CommandCategories::general, 0);
  850. result.setActive (currentDocument != nullptr || project != nullptr);
  851. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier, 0));
  852. break;
  853. case CommandIDs::saveDocumentAs:
  854. result.setInfo ("Save As...",
  855. "Saves the current document to a new location",
  856. CommandCategories::general, 0);
  857. result.setActive (currentDocument != nullptr);
  858. result.defaultKeypresses.add (KeyPress ('s', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  859. break;
  860. case CommandIDs::closeDocument:
  861. result.setInfo ("Close" + documentName,
  862. "Closes the current document",
  863. CommandCategories::general, 0);
  864. result.setActive (contentView != nullptr);
  865. result.defaultKeypresses.add (KeyPress ('w', cmdCtrl, 0));
  866. break;
  867. case CommandIDs::goToPreviousDoc:
  868. result.setInfo ("Previous Document", "Go to previous document", CommandCategories::general, 0);
  869. result.setActive (recentDocumentList.canGoToPrevious());
  870. result.defaultKeypresses.add (KeyPress (KeyPress::leftKey, cmdCtrl, 0));
  871. break;
  872. case CommandIDs::goToNextDoc:
  873. result.setInfo ("Next Document", "Go to next document", CommandCategories::general, 0);
  874. result.setActive (recentDocumentList.canGoToNext());
  875. result.defaultKeypresses.add (KeyPress (KeyPress::rightKey, cmdCtrl, 0));
  876. break;
  877. case CommandIDs::goToCounterpart:
  878. result.setInfo ("Open corresponding header or cpp file", "Open counterpart file", CommandCategories::general, 0);
  879. result.setActive (canGoToCounterpart());
  880. result.defaultKeypresses.add (KeyPress (KeyPress::upKey, cmdCtrl, 0));
  881. break;
  882. case CommandIDs::openInIDE:
  883. result.setInfo ("Open in IDE...",
  884. "Launches the project in an external IDE",
  885. CommandCategories::general, 0);
  886. result.setActive (ProjectExporter::canProjectBeLaunched (project));
  887. break;
  888. case CommandIDs::saveAndOpenInIDE:
  889. result.setInfo ("Save Project and Open in IDE...",
  890. "Saves the project and launches it in an external IDE",
  891. CommandCategories::general, 0);
  892. result.setActive (ProjectExporter::canProjectBeLaunched (project));
  893. result.defaultKeypresses.add (KeyPress ('l', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  894. break;
  895. case CommandIDs::createNewExporter:
  896. result.setInfo ("Create New Exporter...",
  897. "Creates a new exporter for a compiler type",
  898. CommandCategories::general, 0);
  899. result.setActive (project != nullptr);
  900. break;
  901. case CommandIDs::showFilePanel:
  902. result.setInfo ("Show File Panel",
  903. "Shows the tree of files for this project",
  904. CommandCategories::general, 0);
  905. result.setActive (project != nullptr);
  906. result.defaultKeypresses.add (KeyPress ('p', ModifierKeys::commandModifier, 0));
  907. break;
  908. case CommandIDs::showConfigPanel:
  909. result.setInfo ("Show Config Panel",
  910. "Shows the build options for the project",
  911. CommandCategories::general, 0);
  912. result.setActive (project != nullptr);
  913. result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier, 0));
  914. break;
  915. case CommandIDs::showProjectSettings:
  916. result.setInfo ("Show Project Settings",
  917. "Shows the main project options page",
  918. CommandCategories::general, 0);
  919. result.setActive (project != nullptr);
  920. result.defaultKeypresses.add (KeyPress ('i', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  921. break;
  922. case CommandIDs::showProjectModules:
  923. result.setInfo ("Show Project Modules",
  924. "Shows the project's list of modules",
  925. CommandCategories::general, 0);
  926. result.setActive (project != nullptr);
  927. result.defaultKeypresses.add (KeyPress ('m', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  928. break;
  929. case CommandIDs::deleteSelectedItem:
  930. result.setInfo ("Delete Selected File", String::empty, CommandCategories::general, 0);
  931. result.defaultKeypresses.add (KeyPress (KeyPress::deleteKey, 0, 0));
  932. result.defaultKeypresses.add (KeyPress (KeyPress::backspaceKey, 0, 0));
  933. result.setActive (dynamic_cast<TreePanelBase*> (treeViewTabs.getCurrentContentComponent()) != nullptr);
  934. break;
  935. case CommandIDs::showTranslationTool:
  936. result.setInfo ("Translation File Builder", "Shows the translation file helper tool", CommandCategories::general, 0);
  937. break;
  938. case CommandIDs::showBuildTab:
  939. result.setInfo ("Show Build Panel", "Shows the build panel", CommandCategories::general, 0);
  940. //result.defaultKeypresses.add (KeyPress ('b', ModifierKeys::commandModifier, 0));
  941. break;
  942. case CommandIDs::cleanAll:
  943. result.setInfo ("Clean All", "Cleans all intermediate files", CommandCategories::general, 0);
  944. result.defaultKeypresses.add (KeyPress ('k', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  945. result.setActive (project != nullptr);
  946. break;
  947. case CommandIDs::enableBuild:
  948. result.setInfo ("Enable Compilation", "Enables/disables the compiler", CommandCategories::general, 0);
  949. result.defaultKeypresses.add (KeyPress ('b', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  950. result.setActive (project != nullptr);
  951. result.setTicked (childProcess != nullptr);
  952. break;
  953. case CommandIDs::buildNow:
  954. result.setInfo ("Build Now", "Recompiles any out-of-date files and updates the JIT engine", CommandCategories::general, 0);
  955. result.defaultKeypresses.add (KeyPress ('b', ModifierKeys::commandModifier, 0));
  956. result.setActive (childProcess != nullptr);
  957. break;
  958. case CommandIDs::toggleContinuousBuild:
  959. result.setInfo ("Enable Continuous Recompiling", "Continuously recompiles any changes made in code editors", CommandCategories::general, 0);
  960. result.setActive (childProcess != nullptr);
  961. result.setTicked (isContinuousRebuildEnabled());
  962. break;
  963. case CommandIDs::showWarnings:
  964. result.setInfo ("Show Warnings", "Shows or hides compilation warnings", CommandCategories::general, 0);
  965. result.setActive (project != nullptr);
  966. result.setTicked (areWarningsEnabled());
  967. break;
  968. case CommandIDs::launchApp:
  969. result.setInfo ("Launch Application", "Invokes the app's main() function", CommandCategories::general, 0);
  970. result.defaultKeypresses.add (KeyPress ('r', ModifierKeys::commandModifier, 0));
  971. result.setActive (childProcess != nullptr && childProcess->canLaunchApp());
  972. break;
  973. case CommandIDs::killApp:
  974. result.setInfo ("Stop Application", "Kills the app if it's running", CommandCategories::general, 0);
  975. result.defaultKeypresses.add (KeyPress ('.', ModifierKeys::commandModifier, 0));
  976. result.setActive (childProcess != nullptr && childProcess->canKillApp());
  977. break;
  978. case CommandIDs::reinstantiateComp:
  979. result.setInfo ("Re-instantiate Components", "Re-loads any component editors that are open", CommandCategories::general, 0);
  980. result.defaultKeypresses.add (KeyPress ('r', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  981. result.setActive (childProcess != nullptr);
  982. break;
  983. case CommandIDs::nextError:
  984. result.setInfo ("Highlight next error", "Jumps to the next error or warning", CommandCategories::general, 0);
  985. result.defaultKeypresses.add (KeyPress ('e', ModifierKeys::commandModifier, 0));
  986. result.setActive (childProcess != nullptr && ! childProcess->errorList.isEmpty());
  987. break;
  988. case CommandIDs::prevError:
  989. result.setInfo ("Highlight previous error", "Jumps to the last error or warning", CommandCategories::general, 0);
  990. result.defaultKeypresses.add (KeyPress ('e', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0));
  991. result.setActive (childProcess != nullptr && ! childProcess->errorList.isEmpty());
  992. break;
  993. default:
  994. break;
  995. }
  996. }
  997. bool ProjectContentComponent::perform (const InvocationInfo& info)
  998. {
  999. switch (info.commandID)
  1000. {
  1001. case CommandIDs::saveProject:
  1002. case CommandIDs::closeProject:
  1003. case CommandIDs::saveDocument:
  1004. case CommandIDs::saveDocumentAs:
  1005. case CommandIDs::closeDocument:
  1006. case CommandIDs::goToPreviousDoc:
  1007. case CommandIDs::goToNextDoc:
  1008. case CommandIDs::goToCounterpart:
  1009. case CommandIDs::saveAndOpenInIDE:
  1010. if (reinvokeCommandAfterCancellingModalComps (info))
  1011. {
  1012. grabKeyboardFocus(); // to force any open labels to close their text editors
  1013. return true;
  1014. }
  1015. break;
  1016. default:
  1017. break;
  1018. }
  1019. if (isCurrentlyBlockedByAnotherModalComponent())
  1020. return false;
  1021. switch (info.commandID)
  1022. {
  1023. case CommandIDs::saveProject: saveProject(); break;
  1024. case CommandIDs::closeProject: closeProject(); break;
  1025. case CommandIDs::saveDocument: saveDocument(); break;
  1026. case CommandIDs::saveDocumentAs: saveAs(); break;
  1027. case CommandIDs::closeDocument: closeDocument(); break;
  1028. case CommandIDs::goToPreviousDoc: goToPreviousFile(); break;
  1029. case CommandIDs::goToNextDoc: goToNextFile(); break;
  1030. case CommandIDs::goToCounterpart: goToCounterpart(); break;
  1031. case CommandIDs::showFilePanel: showFilesTab(); break;
  1032. case CommandIDs::showConfigPanel: showConfigTab(); break;
  1033. case CommandIDs::showProjectSettings: showProjectSettings(); break;
  1034. case CommandIDs::showProjectModules: showModules(); break;
  1035. case CommandIDs::openInIDE: openInIDE (false); break;
  1036. case CommandIDs::saveAndOpenInIDE: openInIDE (true); break;
  1037. case CommandIDs::createNewExporter: showNewExporterMenu(); break;
  1038. case CommandIDs::deleteSelectedItem: deleteSelectedTreeItems(); break;
  1039. case CommandIDs::showTranslationTool: showTranslationTool(); break;
  1040. case CommandIDs::showBuildTab: showBuildTab(); break;
  1041. case CommandIDs::cleanAll: cleanAll(); break;
  1042. case CommandIDs::enableBuild: setBuildEnabled (! isBuildEnabled()); break;
  1043. case CommandIDs::buildNow: rebuildNow(); break;
  1044. case CommandIDs::toggleContinuousBuild: setContinuousRebuildEnabled (! isContinuousRebuildEnabled()); break;
  1045. case CommandIDs::launchApp: launchApp(); break;
  1046. case CommandIDs::killApp: killApp(); break;
  1047. case CommandIDs::reinstantiateComp: reinstantiateLivePreviewWindows(); break;
  1048. case CommandIDs::showWarnings: toggleWarnings(); break;
  1049. case CommandIDs::nextError: showNextError(); break;
  1050. case CommandIDs::prevError: showPreviousError(); break;
  1051. default:
  1052. return false;
  1053. }
  1054. return true;
  1055. }
  1056. void ProjectContentComponent::getSelectedProjectItemsBeingDragged (const DragAndDropTarget::SourceDetails& dragSourceDetails,
  1057. OwnedArray<Project::Item>& selectedNodes)
  1058. {
  1059. FileTreeItemTypes::ProjectTreeItemBase::getSelectedProjectItemsBeingDragged (dragSourceDetails, selectedNodes);
  1060. }
  1061. //==============================================================================
  1062. void ProjectContentComponent::killChildProcess()
  1063. {
  1064. if (childProcess != nullptr)
  1065. {
  1066. deleteProjectTabs();
  1067. childProcess = nullptr;
  1068. ProjucerApplication::getApp().childProcessCache->removeOrphans();
  1069. }
  1070. }
  1071. void ProjectContentComponent::setBuildEnabled (bool b)
  1072. {
  1073. if (project != nullptr && b != isBuildEnabled())
  1074. {
  1075. LiveBuildProjectSettings::setBuildDisabled (*project, ! b);
  1076. killChildProcess();
  1077. refreshTabsIfBuildStatusChanged();
  1078. }
  1079. }
  1080. void ProjectContentComponent::showBuildTab()
  1081. {
  1082. WeakReference<Component> currentFocus (Component::getCurrentlyFocusedComponent());
  1083. treeViewTabs.setCurrentTabIndex (2);
  1084. if (currentFocus != nullptr)
  1085. currentFocus->grabKeyboardFocus();
  1086. }
  1087. void ProjectContentComponent::cleanAll()
  1088. {
  1089. lastCrashMessage = String();
  1090. if (childProcess != nullptr)
  1091. childProcess->cleanAll();
  1092. else if (Project* p = getProject())
  1093. CompileEngineChildProcess::cleanAllCachedFilesForProject (*p);
  1094. }
  1095. void ProjectContentComponent::handleCrash (const String& message)
  1096. {
  1097. lastCrashMessage = message.isEmpty() ? TRANS("JIT process stopped responding!")
  1098. : (TRANS("JIT process crashed!") + ":\n\n" + message);
  1099. if (project != nullptr)
  1100. {
  1101. setBuildEnabled (false);
  1102. showBuildTab();
  1103. }
  1104. }
  1105. bool ProjectContentComponent::isBuildEnabled() const
  1106. {
  1107. return project != nullptr
  1108. && ! LiveBuildProjectSettings::isBuildDisabled (*project)
  1109. && ProjucerLicences::getInstance()->hasLiveCodingLicence()
  1110. && ProjucerLicences::getInstance()->isLoggedIn();
  1111. }
  1112. void ProjectContentComponent::refreshTabsIfBuildStatusChanged()
  1113. {
  1114. if (project != nullptr
  1115. && (treeViewTabs.getNumTabs() < 3
  1116. || isBuildEnabled() != isBuildTabShowing()
  1117. || ProjucerLicences::getInstance()->isLoggedIn() != isLoggedInTabShowing()))
  1118. rebuildProjectTabs();
  1119. }
  1120. bool ProjectContentComponent::areWarningsEnabled() const
  1121. {
  1122. return project != nullptr && ! LiveBuildProjectSettings::areWarningsDisabled (*project);
  1123. }
  1124. void ProjectContentComponent::updateWarningState()
  1125. {
  1126. if (childProcess != nullptr)
  1127. childProcess->errorList.setWarningsEnabled (areWarningsEnabled());
  1128. }
  1129. void ProjectContentComponent::toggleWarnings()
  1130. {
  1131. if (project != nullptr)
  1132. {
  1133. LiveBuildProjectSettings::setWarningsDisabled (*project, areWarningsEnabled());
  1134. updateWarningState();
  1135. }
  1136. }
  1137. static ProjucerAppClasses::ErrorListComp* findErrorListComp (const TabbedComponent& tabs)
  1138. {
  1139. if (BuildTabComponent* bt = findBuildTab (tabs))
  1140. return bt->errorListComp;
  1141. return nullptr;
  1142. }
  1143. void ProjectContentComponent::showNextError()
  1144. {
  1145. if (ProjucerAppClasses::ErrorListComp* el = findErrorListComp (treeViewTabs))
  1146. {
  1147. showBuildTab();
  1148. el->showNext();
  1149. }
  1150. }
  1151. void ProjectContentComponent::showPreviousError()
  1152. {
  1153. if (ProjucerAppClasses::ErrorListComp* el = findErrorListComp (treeViewTabs))
  1154. {
  1155. showBuildTab();
  1156. el->showPrevious();
  1157. }
  1158. }
  1159. void ProjectContentComponent::reinstantiateLivePreviewWindows()
  1160. {
  1161. if (childProcess != nullptr)
  1162. childProcess->reinstantiatePreviews();
  1163. }
  1164. void ProjectContentComponent::launchApp()
  1165. {
  1166. if (childProcess != nullptr)
  1167. childProcess->launchApp();
  1168. }
  1169. void ProjectContentComponent::killApp()
  1170. {
  1171. if (childProcess != nullptr)
  1172. childProcess->killApp();
  1173. }
  1174. void ProjectContentComponent::rebuildNow()
  1175. {
  1176. if (childProcess != nullptr)
  1177. childProcess->flushEditorChanges();
  1178. }
  1179. void ProjectContentComponent::globalFocusChanged (Component* focusedComponent)
  1180. {
  1181. const bool nowForeground = (Process::isForegroundProcess()
  1182. && (focusedComponent == this || isParentOf (focusedComponent)));
  1183. if (nowForeground != isForeground)
  1184. {
  1185. isForeground = nowForeground;
  1186. if (childProcess != nullptr)
  1187. childProcess->processActivationChanged (isForeground);
  1188. }
  1189. }
  1190. void ProjectContentComponent::timerCallback()
  1191. {
  1192. if (! isBuildEnabled())
  1193. killChildProcess();
  1194. refreshTabsIfBuildStatusChanged();
  1195. }
  1196. ReferenceCountedObjectPtr<CompileEngineChildProcess> ProjectContentComponent::getChildProcess()
  1197. {
  1198. #if JUCE_MAC
  1199. if (childProcess == nullptr && isBuildEnabled())
  1200. {
  1201. childProcess = ProjucerApplication::getApp().childProcessCache->getOrCreate (*project);
  1202. if (childProcess != nullptr)
  1203. childProcess->setContinuousRebuild (isContinuousRebuildEnabled());
  1204. }
  1205. #endif
  1206. return childProcess;
  1207. }
  1208. void ProjectContentComponent::handleMissingSystemHeaders()
  1209. {
  1210. #if JUCE_MAC
  1211. const String tabMessage = "Compiler not available due to missing system headers\nPlease install a recent version of Xcode";
  1212. const String alertWindowMessage = "Missing system headers\nPlease install a recent version of Xcode";
  1213. #elif JUCE_WINDOWS
  1214. const String tabMessage = "Compiler not available due to missing system headers\nPlease install a recent version of Visual Studio and the Windows Desktop SDK";
  1215. const String alertWindowMessage = "Missing system headers\nPlease install a recent version of Visual Studio and the Windows Desktop SDK";
  1216. #elif JUCE_LINUX
  1217. const String tabMessage = "Compiler not available due to missing system headers\nPlease do a sudo apt-get install ...";
  1218. const String alertWindowMessage = "Missing system headers\nPlease do sudo apt-get install ...";
  1219. #endif
  1220. setBuildEnabled (false);
  1221. deleteProjectTabs();
  1222. createProjectTabs();
  1223. ProjucerDisabledComp* buildTab = new ProjucerDisabledComp (tabMessage, false);
  1224. treeViewTabs.addTab ("Build", Colours::transparentBlack, buildTab, true);
  1225. showBuildTab();
  1226. AlertWindow::showMessageBox (AlertWindow::AlertIconType::WarningIcon,
  1227. "Missing system headers", alertWindowMessage);
  1228. }