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.

172 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __PROJUCER_CLANGCLIENT_H_5AE7396F__
  18. #define __PROJUCER_CLANGCLIENT_H_5AE7396F__
  19. #include "projucer_ActivityList.h"
  20. #include "projucer_ErrorList.h"
  21. class Project;
  22. //==============================================================================
  23. class CompileEngineChildProcess : public ReferenceCountedObject,
  24. private OpenDocumentManager::DocumentCloseListener
  25. {
  26. public:
  27. CompileEngineChildProcess (Project&);
  28. ~CompileEngineChildProcess();
  29. bool openedOk() const { return process != nullptr; }
  30. void editorOpened (const File& file, CodeDocument& document);
  31. bool documentAboutToClose (OpenDocumentManager::Document*) override;
  32. void cleanAll();
  33. void openPreview (const ClassDatabase::Class&);
  34. void reinstantiatePreviews();
  35. void processActivationChanged (bool isForeground);
  36. bool canLaunchApp() const;
  37. void launchApp();
  38. bool canKillApp() const;
  39. void killApp();
  40. const ClassDatabase::ClassList& getComponentList() const { return lastComponentList; }
  41. void setContinuousRebuild (bool continuousBuild);
  42. void flushEditorChanges();
  43. static void cleanAllCachedFilesForProject (Project&);
  44. Project& project;
  45. ActivityList activityList;
  46. ErrorList errorList;
  47. std::function<void (const String&)> crashHandler;
  48. //==============================================================================
  49. // from server..
  50. void handleNewDiagnosticList (const ValueTree& newList);
  51. void handleClearErrors();
  52. void handleActivityListChanged (const StringArray&);
  53. void handleClassListChanged (const ValueTree& newList);
  54. void handleBuildFailed();
  55. void handleChangeCode (const SourceCodeRange& location, const String& newText);
  56. void handleAppLaunched();
  57. void handleAppQuit();
  58. void handleHighlightCode (const SourceCodeRange& location);
  59. void handlePing();
  60. void handleCrash (const String& message);
  61. void handleCloseIDE();
  62. void handleKeyPress (const String& className, const KeyPress& key);
  63. void handleUndoInEditor (const String& className);
  64. void handleRedoInEditor (const String& className);
  65. void handleMissingSystemHeaders();
  66. typedef ReferenceCountedObjectPtr<CompileEngineChildProcess> Ptr;
  67. private:
  68. //==============================================================================
  69. class ChildProcess;
  70. ScopedPointer<ChildProcess> process, runningAppProcess;
  71. ClassDatabase::ClassList lastComponentList;
  72. bool continuousRebuild;
  73. struct Editor;
  74. OwnedArray<Editor> editors;
  75. void updateAllEditors();
  76. void createProcess();
  77. Editor* getOrOpenEditorFor (const File&);
  78. ProjectContentComponent* findProjectContentComponent() const;
  79. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CompileEngineChildProcess)
  80. };
  81. //==============================================================================
  82. struct ChildProcessCache
  83. {
  84. ChildProcessCache() {}
  85. CompileEngineChildProcess::Ptr getExisting (Project& project) const noexcept
  86. {
  87. for (CompileEngineChildProcess* p : processes)
  88. if (&(p->project) == &project)
  89. return p;
  90. return nullptr;
  91. }
  92. CompileEngineChildProcess::Ptr getOrCreate (Project& project)
  93. {
  94. CompileEngineChildProcess::Ptr p (getExisting (project));
  95. if (p == nullptr)
  96. {
  97. p = new CompileEngineChildProcess (project);
  98. tellNewProcessAboutExistingEditors (p);
  99. processes.add (p);
  100. }
  101. return p;
  102. }
  103. static void tellNewProcessAboutExistingEditors (CompileEngineChildProcess* process)
  104. {
  105. OpenDocumentManager& odm = ProjucerApplication::getApp().openDocumentManager;
  106. for (int i = odm.getNumOpenDocuments(); --i >= 0;)
  107. if (SourceCodeDocument* d = dynamic_cast<SourceCodeDocument*> (odm.getOpenDocument (i)))
  108. process->editorOpened (d->getFile(), d->getCodeDocument());
  109. }
  110. void removeOrphans()
  111. {
  112. for (int i = processes.size(); --i >= 0;)
  113. if (processes.getObjectPointerUnchecked (i)->getReferenceCount() <= 1)
  114. processes.remove (i);
  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. };
  130. #endif // __PROJUCER_CLANGCLIENT_H_5AE7396F__