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.

169 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "jucer_ActivityList.h"
  21. #include "jucer_ErrorList.h"
  22. class Project;
  23. //==============================================================================
  24. class CompileEngineChildProcess : public ReferenceCountedObject,
  25. private OpenDocumentManager::DocumentCloseListener
  26. {
  27. public:
  28. CompileEngineChildProcess (Project&);
  29. ~CompileEngineChildProcess();
  30. bool openedOk() const { return process != nullptr; }
  31. void editorOpened (const File& file, CodeDocument& document);
  32. bool documentAboutToClose (OpenDocumentManager::Document*) override;
  33. void cleanAll();
  34. void openPreview (const ClassDatabase::Class&);
  35. void reinstantiatePreviews();
  36. void processActivationChanged (bool isForeground);
  37. bool canLaunchApp() const;
  38. void launchApp();
  39. bool canKillApp() const;
  40. void killApp();
  41. bool isAppRunning() const noexcept;
  42. const ClassDatabase::ClassList& getComponentList() const { return lastComponentList; }
  43. void setContinuousRebuild (bool continuousBuild);
  44. void flushEditorChanges();
  45. static void cleanAllCachedFilesForProject (Project&);
  46. Project& project;
  47. ActivityList activityList;
  48. ErrorList errorList;
  49. std::function<void (const String&)> crashHandler;
  50. //==============================================================================
  51. // from server..
  52. void handleNewDiagnosticList (const ValueTree& newList);
  53. void handleClearErrors();
  54. void handleActivityListChanged (const StringArray&);
  55. void handleClassListChanged (const ValueTree& newList);
  56. void handleBuildFailed();
  57. void handleChangeCode (const SourceCodeRange& location, const String& newText);
  58. void handleAppLaunched();
  59. void handleAppQuit();
  60. void handleHighlightCode (const SourceCodeRange& location);
  61. void handlePing();
  62. void handleCrash (const String& message);
  63. void handleCloseIDE();
  64. void handleKeyPress (const String& className, const KeyPress& key);
  65. void handleUndoInEditor (const String& className);
  66. void handleRedoInEditor (const String& className);
  67. void handleMissingSystemHeaders();
  68. typedef ReferenceCountedObjectPtr<CompileEngineChildProcess> Ptr;
  69. private:
  70. //==============================================================================
  71. class ChildProcess;
  72. ScopedPointer<ChildProcess> process, runningAppProcess;
  73. ClassDatabase::ClassList lastComponentList;
  74. bool continuousRebuild;
  75. struct Editor;
  76. OwnedArray<Editor> editors;
  77. void updateAllEditors();
  78. void createProcess();
  79. Editor* getOrOpenEditorFor (const File&);
  80. ProjectContentComponent* findProjectContentComponent() const;
  81. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CompileEngineChildProcess)
  82. };
  83. //==============================================================================
  84. struct ChildProcessCache
  85. {
  86. ChildProcessCache() {}
  87. CompileEngineChildProcess::Ptr getExisting (Project& project) const noexcept
  88. {
  89. for (CompileEngineChildProcess* p : processes)
  90. if (&(p->project) == &project)
  91. return p;
  92. return nullptr;
  93. }
  94. CompileEngineChildProcess::Ptr getOrCreate (Project& project)
  95. {
  96. CompileEngineChildProcess::Ptr p (getExisting (project));
  97. if (p == nullptr)
  98. {
  99. p = new CompileEngineChildProcess (project);
  100. tellNewProcessAboutExistingEditors (p);
  101. processes.add (p);
  102. }
  103. return p;
  104. }
  105. static void tellNewProcessAboutExistingEditors (CompileEngineChildProcess* process)
  106. {
  107. OpenDocumentManager& odm = ProjucerApplication::getApp().openDocumentManager;
  108. for (int i = odm.getNumOpenDocuments(); --i >= 0;)
  109. if (SourceCodeDocument* d = dynamic_cast<SourceCodeDocument*> (odm.getOpenDocument (i)))
  110. process->editorOpened (d->getFile(), d->getCodeDocument());
  111. }
  112. void removeOrphans()
  113. {
  114. processes.clear();
  115. }
  116. private:
  117. ReferenceCountedArray<CompileEngineChildProcess> processes;
  118. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcessCache)
  119. };
  120. //==============================================================================
  121. struct LiveBuildProjectSettings
  122. {
  123. static void getLiveSettings (Project&, PropertyListBuilder&);
  124. static void updateNewlyOpenedProject (Project& p);
  125. static bool isBuildDisabled (Project&);
  126. static void setBuildDisabled (Project&, bool);
  127. static bool areWarningsDisabled (Project&);
  128. static void setWarningsDisabled (Project&, bool);
  129. };