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.

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