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.

168 lines
5.6KB

  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. #pragma once
  18. #include "projucer_ActivityList.h"
  19. #include "projucer_ErrorList.h"
  20. class Project;
  21. //==============================================================================
  22. class CompileEngineChildProcess : public ReferenceCountedObject,
  23. private OpenDocumentManager::DocumentCloseListener
  24. {
  25. public:
  26. CompileEngineChildProcess (Project&);
  27. ~CompileEngineChildProcess();
  28. bool openedOk() const { return process != nullptr; }
  29. void editorOpened (const File& file, CodeDocument& document);
  30. bool documentAboutToClose (OpenDocumentManager::Document*) override;
  31. void cleanAll();
  32. void openPreview (const ClassDatabase::Class&);
  33. void reinstantiatePreviews();
  34. void processActivationChanged (bool isForeground);
  35. bool canLaunchApp() const;
  36. void launchApp();
  37. bool canKillApp() const;
  38. void killApp();
  39. const ClassDatabase::ClassList& getComponentList() const { return lastComponentList; }
  40. void setContinuousRebuild (bool continuousBuild);
  41. void flushEditorChanges();
  42. static void cleanAllCachedFilesForProject (Project&);
  43. Project& project;
  44. ActivityList activityList;
  45. ErrorList errorList;
  46. std::function<void (const String&)> crashHandler;
  47. //==============================================================================
  48. // from server..
  49. void handleNewDiagnosticList (const ValueTree& newList);
  50. void handleClearErrors();
  51. void handleActivityListChanged (const StringArray&);
  52. void handleClassListChanged (const ValueTree& newList);
  53. void handleBuildFailed();
  54. void handleChangeCode (const SourceCodeRange& location, const String& newText);
  55. void handleAppLaunched();
  56. void handleAppQuit();
  57. void handleHighlightCode (const SourceCodeRange& location);
  58. void handlePing();
  59. void handleCrash (const String& message);
  60. void handleCloseIDE();
  61. void handleKeyPress (const String& className, const KeyPress& key);
  62. void handleUndoInEditor (const String& className);
  63. void handleRedoInEditor (const String& className);
  64. void handleMissingSystemHeaders();
  65. typedef ReferenceCountedObjectPtr<CompileEngineChildProcess> Ptr;
  66. private:
  67. //==============================================================================
  68. class ChildProcess;
  69. ScopedPointer<ChildProcess> process, runningAppProcess;
  70. ClassDatabase::ClassList lastComponentList;
  71. bool continuousRebuild;
  72. struct Editor;
  73. OwnedArray<Editor> editors;
  74. void updateAllEditors();
  75. void createProcess();
  76. Editor* getOrOpenEditorFor (const File&);
  77. ProjectContentComponent* findProjectContentComponent() const;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CompileEngineChildProcess)
  79. };
  80. //==============================================================================
  81. struct ChildProcessCache
  82. {
  83. ChildProcessCache() {}
  84. CompileEngineChildProcess::Ptr getExisting (Project& project) const noexcept
  85. {
  86. for (CompileEngineChildProcess* p : processes)
  87. if (&(p->project) == &project)
  88. return p;
  89. return nullptr;
  90. }
  91. CompileEngineChildProcess::Ptr getOrCreate (Project& project)
  92. {
  93. CompileEngineChildProcess::Ptr p (getExisting (project));
  94. if (p == nullptr)
  95. {
  96. p = new CompileEngineChildProcess (project);
  97. tellNewProcessAboutExistingEditors (p);
  98. processes.add (p);
  99. }
  100. return p;
  101. }
  102. static void tellNewProcessAboutExistingEditors (CompileEngineChildProcess* process)
  103. {
  104. OpenDocumentManager& odm = ProjucerApplication::getApp().openDocumentManager;
  105. for (int i = odm.getNumOpenDocuments(); --i >= 0;)
  106. if (SourceCodeDocument* d = dynamic_cast<SourceCodeDocument*> (odm.getOpenDocument (i)))
  107. process->editorOpened (d->getFile(), d->getCodeDocument());
  108. }
  109. void removeOrphans()
  110. {
  111. for (int i = processes.size(); --i >= 0;)
  112. if (processes.getObjectPointerUnchecked (i)->getReferenceCount() <= 1)
  113. processes.remove (i);
  114. }
  115. private:
  116. ReferenceCountedArray<CompileEngineChildProcess> processes;
  117. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcessCache)
  118. };
  119. //==============================================================================
  120. struct LiveBuildProjectSettings
  121. {
  122. static void getLiveSettings (Project&, PropertyListBuilder&);
  123. static void updateNewlyOpenedProject (Project& p);
  124. static bool isBuildDisabled (Project&);
  125. static void setBuildDisabled (Project&, bool);
  126. static bool areWarningsDisabled (Project&);
  127. static void setWarningsDisabled (Project&, bool);
  128. };