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.

156 lines
5.5KB

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