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.

187 lines
5.4KB

  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 *JucerApplication::getApp().settings;
  25. }
  26. PropertiesFile& getAppProperties()
  27. {
  28. return getAppSettings().getProps();
  29. }
  30. //==============================================================================
  31. StoredSettings::StoredSettings()
  32. : appearance (true)
  33. {
  34. }
  35. StoredSettings::~StoredSettings()
  36. {
  37. flush();
  38. }
  39. void StoredSettings::initialise()
  40. {
  41. reload();
  42. }
  43. PropertiesFile& StoredSettings::getProps()
  44. {
  45. jassert (props != nullptr);
  46. return *props;
  47. }
  48. void StoredSettings::flush()
  49. {
  50. if (props != nullptr)
  51. {
  52. {
  53. const ScopedPointer<XmlElement> xml (appearance.settings.createXml());
  54. props->setValue ("editorColours", xml);
  55. }
  56. props->setValue ("recentFiles", recentFiles.toString());
  57. props->removeValue ("keyMappings");
  58. if (commandManager != nullptr)
  59. {
  60. ScopedPointer <XmlElement> keys (commandManager->getKeyMappings()->createXml (true));
  61. if (keys != nullptr)
  62. props->setValue ("keyMappings", (XmlElement*) keys);
  63. }
  64. props->saveIfNeeded();
  65. }
  66. }
  67. void StoredSettings::reload()
  68. {
  69. props = nullptr;
  70. {
  71. // These settings are used in defining the properties file's location.
  72. PropertiesFile::Options options;
  73. options.applicationName = "Introjucer";
  74. options.folderName = "Introjucer";
  75. options.filenameSuffix = "settings";
  76. options.osxLibrarySubFolder = "Application Support";
  77. props = new PropertiesFile (options);
  78. // Because older versions of the introjucer saved their settings under a different
  79. // name, this code is an example of how to migrate your old settings files...
  80. if (! props->getFile().exists())
  81. {
  82. PropertiesFile::Options oldOptions;
  83. oldOptions.applicationName = "Jucer2";
  84. oldOptions.filenameSuffix = "settings";
  85. oldOptions.osxLibrarySubFolder = "Preferences";
  86. PropertiesFile oldProps (oldOptions);
  87. if (oldProps.getFile().exists())
  88. props->addAllPropertiesFrom (oldProps);
  89. }
  90. }
  91. // recent files...
  92. recentFiles.restoreFromString (props->getValue ("recentFiles"));
  93. recentFiles.removeNonExistentFiles();
  94. const ScopedPointer<XmlElement> xml (props->getXmlValue ("editorColours"));
  95. if (xml != nullptr)
  96. appearance.readFromXML (*xml);
  97. appearance.updateColourScheme();
  98. loadSwatchColours();
  99. }
  100. Array<File> StoredSettings::getLastProjects() const
  101. {
  102. StringArray s;
  103. s.addTokens (props->getValue ("lastProjects"), "|", "");
  104. Array<File> f;
  105. for (int i = 0; i < s.size(); ++i)
  106. f.add (File (s[i]));
  107. return f;
  108. }
  109. void StoredSettings::setLastProjects (const Array<File>& files)
  110. {
  111. StringArray s;
  112. for (int i = 0; i < files.size(); ++i)
  113. s.add (files.getReference(i).getFullPathName());
  114. props->setValue ("lastProjects", s.joinIntoString ("|"));
  115. }
  116. //==============================================================================
  117. void StoredSettings::loadSwatchColours()
  118. {
  119. swatchColours.clear();
  120. #define COL(col) Colours::col,
  121. const Colour colours[] =
  122. {
  123. #include "jucer_Colours.h"
  124. Colours::transparentBlack
  125. };
  126. #undef COL
  127. const int numSwatchColours = 24;
  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. int StoredSettings::ColourSelectorWithSwatches::getNumSwatches() const
  133. {
  134. return getAppSettings().swatchColours.size();
  135. }
  136. Colour StoredSettings::ColourSelectorWithSwatches::getSwatchColour (int index) const
  137. {
  138. return getAppSettings().swatchColours [index];
  139. }
  140. void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, const Colour& newColour) const
  141. {
  142. getAppSettings().swatchColours.set (index, newColour);
  143. }