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.

1516 lines
53KB

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