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.

196 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../jucer_Headers.h"
  19. #include "jucer_StoredSettings.h"
  20. #include "../Application/jucer_Application.h"
  21. //==============================================================================
  22. StoredSettings& getAppSettings()
  23. {
  24. return *IntrojucerApp::getApp().settings;
  25. }
  26. PropertiesFile& getGlobalProperties()
  27. {
  28. return getAppSettings().getGlobalProperties();
  29. }
  30. //==============================================================================
  31. StoredSettings::StoredSettings()
  32. : appearance (true)
  33. {
  34. reload();
  35. }
  36. StoredSettings::~StoredSettings()
  37. {
  38. flush();
  39. }
  40. PropertiesFile& StoredSettings::getGlobalProperties()
  41. {
  42. return *propertyFiles.getUnchecked (0);
  43. }
  44. static PropertiesFile* createPropsFile (const String& filename)
  45. {
  46. return new PropertiesFile (IntrojucerApp::getApp()
  47. .getPropertyFileOptionsFor (filename));
  48. }
  49. PropertiesFile& StoredSettings::getProjectProperties (const String& projectUID)
  50. {
  51. const String filename ("Introjucer_Project_" + projectUID);
  52. for (int i = propertyFiles.size(); --i >= 0;)
  53. {
  54. PropertiesFile* const props = propertyFiles.getUnchecked(i);
  55. if (props->getFile().getFileNameWithoutExtension() == filename)
  56. return *props;
  57. }
  58. PropertiesFile* p = createPropsFile (filename);
  59. propertyFiles.add (p);
  60. return *p;
  61. }
  62. void StoredSettings::updateGlobalProps()
  63. {
  64. PropertiesFile& props = getGlobalProperties();
  65. {
  66. const ScopedPointer<XmlElement> xml (appearance.settings.createXml());
  67. props.setValue ("editorColours", xml);
  68. }
  69. props.setValue ("recentFiles", recentFiles.toString());
  70. props.removeValue ("keyMappings");
  71. if (commandManager != nullptr)
  72. {
  73. const ScopedPointer <XmlElement> keys (commandManager->getKeyMappings()->createXml (true));
  74. if (keys != nullptr)
  75. props.setValue ("keyMappings", keys);
  76. }
  77. }
  78. void StoredSettings::flush()
  79. {
  80. updateGlobalProps();
  81. saveSwatchColours();
  82. for (int i = propertyFiles.size(); --i >= 0;)
  83. propertyFiles.getUnchecked(i)->saveIfNeeded();
  84. }
  85. void StoredSettings::reload()
  86. {
  87. propertyFiles.clear();
  88. propertyFiles.add (createPropsFile ("Introjucer"));
  89. // recent files...
  90. recentFiles.restoreFromString (getGlobalProperties().getValue ("recentFiles"));
  91. recentFiles.removeNonExistentFiles();
  92. ScopedPointer<XmlElement> xml (getGlobalProperties().getXmlValue ("editorColours"));
  93. if (xml == nullptr)
  94. xml = XmlDocument::parse (BinaryData::colourscheme_dark_xml);
  95. appearance.readFromXML (*xml);
  96. appearance.updateColourScheme();
  97. loadSwatchColours();
  98. }
  99. Array<File> StoredSettings::getLastProjects()
  100. {
  101. StringArray s;
  102. s.addTokens (getGlobalProperties().getValue ("lastProjects"), "|", "");
  103. Array<File> f;
  104. for (int i = 0; i < s.size(); ++i)
  105. f.add (File (s[i]));
  106. return f;
  107. }
  108. void StoredSettings::setLastProjects (const Array<File>& files)
  109. {
  110. StringArray s;
  111. for (int i = 0; i < files.size(); ++i)
  112. s.add (files.getReference(i).getFullPathName());
  113. getGlobalProperties().setValue ("lastProjects", s.joinIntoString ("|"));
  114. }
  115. //==============================================================================
  116. void StoredSettings::loadSwatchColours()
  117. {
  118. swatchColours.clear();
  119. #define COL(col) Colours::col,
  120. const Colour colours[] =
  121. {
  122. #include "jucer_Colours.h"
  123. Colours::transparentBlack
  124. };
  125. #undef COL
  126. const int numSwatchColours = 24;
  127. PropertiesFile& props = getGlobalProperties();
  128. for (int i = 0; i < numSwatchColours; ++i)
  129. swatchColours.add (Colour::fromString (props.getValue ("swatchColour" + String (i),
  130. colours [2 + i].toString())));
  131. }
  132. void StoredSettings::saveSwatchColours()
  133. {
  134. PropertiesFile& props = getGlobalProperties();
  135. for (int i = 0; i < swatchColours.size(); ++i)
  136. props.setValue ("swatchColour" + String (i), swatchColours.getReference(i).toString());
  137. }
  138. int StoredSettings::ColourSelectorWithSwatches::getNumSwatches() const
  139. {
  140. return getAppSettings().swatchColours.size();
  141. }
  142. Colour StoredSettings::ColourSelectorWithSwatches::getSwatchColour (int index) const
  143. {
  144. return getAppSettings().swatchColours [index];
  145. }
  146. void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, const Colour& newColour) const
  147. {
  148. getAppSettings().swatchColours.set (index, newColour);
  149. }