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.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. const ClassDatabase::ClassList& getComponentList() const { return lastComponentList; }
  42. void setContinuousRebuild (bool continuousBuild);
  43. void flushEditorChanges();
  44. static void cleanAllCachedFilesForProject (Project&);
  45. Project& project;
  46. ActivityList activityList;
  47. ErrorList errorList;
  48. std::function<void (const String&)> crashHandler;
  49. //==============================================================================
  50. // from server..
  51. void handleNewDiagnosticList (const ValueTree& newList);
  52. void handleClearErrors();
  53. void handleActivityListChanged (const StringArray&);
  54. void handleClassListChanged (const ValueTree& newList);
  55. void handleBuildFailed();
  56. void handleChangeCode (const SourceCodeRange& location, const String& newText);
  57. void handleAppLaunched();
  58. void handleAppQuit();
  59. void handleHighlightCode (const SourceCodeRange& location);
  60. void handlePing();
  61. void handleCrash (const String& message);
  62. void handleCloseIDE();
  63. void handleKeyPress (const String& className, const KeyPress& key);
  64. void handleUndoInEditor (const String& className);
  65. void handleRedoInEditor (const String& className);
  66. void handleMissingSystemHeaders();
  67. typedef ReferenceCountedObjectPtr<CompileEngineChildProcess> Ptr;
  68. private:
  69. //==============================================================================
  70. class ChildProcess;
  71. ScopedPointer<ChildProcess> process, runningAppProcess;
  72. ClassDatabase::ClassList lastComponentList;
  73. bool continuousRebuild;
  74. struct Editor;
  75. OwnedArray<Editor> editors;
  76. void updateAllEditors();
  77. void createProcess();
  78. Editor* getOrOpenEditorFor (const File&);
  79. ProjectContentComponent* findProjectContentComponent() const;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CompileEngineChildProcess)
  81. };
  82. //==============================================================================
  83. struct ChildProcessCache
  84. {
  85. ChildProcessCache() {}
  86. CompileEngineChildProcess::Ptr getExisting (Project& project) const noexcept
  87. {
  88. for (CompileEngineChildProcess* p : processes)
  89. if (&(p->project) == &project)
  90. return p;
  91. return nullptr;
  92. }
  93. CompileEngineChildProcess::Ptr getOrCreate (Project& project)
  94. {
  95. CompileEngineChildProcess::Ptr p (getExisting (project));
  96. if (p == nullptr)
  97. {
  98. p = new CompileEngineChildProcess (project);
  99. tellNewProcessAboutExistingEditors (p);
  100. processes.add (p);
  101. }
  102. return p;
  103. }
  104. static void tellNewProcessAboutExistingEditors (CompileEngineChildProcess* process)
  105. {
  106. OpenDocumentManager& odm = ProjucerApplication::getApp().openDocumentManager;
  107. for (int i = odm.getNumOpenDocuments(); --i >= 0;)
  108. if (SourceCodeDocument* d = dynamic_cast<SourceCodeDocument*> (odm.getOpenDocument (i)))
  109. process->editorOpened (d->getFile(), d->getCodeDocument());
  110. }
  111. void removeOrphans()
  112. {
  113. processes.clear();
  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. };