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.

149 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. #include "jucer_ActivityList.h"
  15. #include "jucer_ErrorList.h"
  16. class Project;
  17. //==============================================================================
  18. class CompileEngineChildProcess : public ReferenceCountedObject,
  19. private OpenDocumentManager::DocumentCloseListener
  20. {
  21. public:
  22. CompileEngineChildProcess (Project&);
  23. ~CompileEngineChildProcess() override;
  24. //==============================================================================
  25. bool openedOk() const { return process != nullptr; }
  26. void editorOpened (const File& file, CodeDocument& document);
  27. bool documentAboutToClose (OpenDocumentManager::Document*) override;
  28. //==============================================================================
  29. void cleanAll();
  30. void openPreview (const ClassDatabase::Class&);
  31. void reinstantiatePreviews();
  32. void processActivationChanged (bool isForeground);
  33. //==============================================================================
  34. bool canLaunchApp() const;
  35. void launchApp();
  36. bool canKillApp() const;
  37. void killApp();
  38. bool isAppRunning() const noexcept;
  39. //==============================================================================
  40. const ClassDatabase::ClassList& getComponentList() const { return lastComponentList; }
  41. //==============================================================================
  42. void flushEditorChanges();
  43. static void cleanAllCachedFilesForProject (Project&);
  44. //==============================================================================
  45. Project& project;
  46. ActivityList activityList;
  47. ErrorList errorList;
  48. //==============================================================================
  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. using Ptr = ReferenceCountedObjectPtr<CompileEngineChildProcess>;
  69. private:
  70. //==============================================================================
  71. class ChildProcess;
  72. std::unique_ptr<ChildProcess> process, runningAppProcess;
  73. ClassDatabase::ClassList lastComponentList;
  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 (auto& p : processes)
  89. if (&(p->project) == &project)
  90. return *p;
  91. return {};
  92. }
  93. CompileEngineChildProcess::Ptr getOrCreate (Project& project)
  94. {
  95. if (auto p = getExisting (project))
  96. return p;
  97. auto p = new CompileEngineChildProcess (project);
  98. tellNewProcessAboutExistingEditors (*p);
  99. processes.add (p);
  100. return *p;
  101. }
  102. static void tellNewProcessAboutExistingEditors (CompileEngineChildProcess& process)
  103. {
  104. auto& odm = ProjucerApplication::getApp().openDocumentManager;
  105. for (int i = odm.getNumOpenDocuments(); --i >= 0;)
  106. if (auto d = dynamic_cast<SourceCodeDocument*> (odm.getOpenDocument (i)))
  107. process.editorOpened (d->getFile(), d->getCodeDocument());
  108. }
  109. void removeOrphans()
  110. {
  111. processes.clear();
  112. }
  113. private:
  114. ReferenceCountedArray<CompileEngineChildProcess> processes;
  115. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcessCache)
  116. };