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.

178 lines
5.0KB

  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.filenameSuffix = "settings";
  75. options.osxLibrarySubFolder = "Application Support";
  76. #if JUCE_LINUX
  77. options.folderName = ".introjucer";
  78. #else
  79. options.folderName = "Introjucer";
  80. #endif
  81. props = new PropertiesFile (options);
  82. }
  83. // recent files...
  84. recentFiles.restoreFromString (props->getValue ("recentFiles"));
  85. recentFiles.removeNonExistentFiles();
  86. ScopedPointer<XmlElement> xml (props->getXmlValue ("editorColours"));
  87. if (xml == nullptr)
  88. xml = XmlDocument::parse (BinaryData::colourscheme_dark_xml);
  89. appearance.readFromXML (*xml);
  90. appearance.updateColourScheme();
  91. loadSwatchColours();
  92. }
  93. Array<File> StoredSettings::getLastProjects() const
  94. {
  95. StringArray s;
  96. s.addTokens (props->getValue ("lastProjects"), "|", "");
  97. Array<File> f;
  98. for (int i = 0; i < s.size(); ++i)
  99. f.add (File (s[i]));
  100. return f;
  101. }
  102. void StoredSettings::setLastProjects (const Array<File>& files)
  103. {
  104. StringArray s;
  105. for (int i = 0; i < files.size(); ++i)
  106. s.add (files.getReference(i).getFullPathName());
  107. props->setValue ("lastProjects", s.joinIntoString ("|"));
  108. }
  109. //==============================================================================
  110. void StoredSettings::loadSwatchColours()
  111. {
  112. swatchColours.clear();
  113. #define COL(col) Colours::col,
  114. const Colour colours[] =
  115. {
  116. #include "jucer_Colours.h"
  117. Colours::transparentBlack
  118. };
  119. #undef COL
  120. const int numSwatchColours = 24;
  121. for (int i = 0; i < numSwatchColours; ++i)
  122. swatchColours.add (Colour::fromString (props->getValue ("swatchColour" + String (i),
  123. colours [2 + i].toString())));
  124. }
  125. int StoredSettings::ColourSelectorWithSwatches::getNumSwatches() const
  126. {
  127. return getAppSettings().swatchColours.size();
  128. }
  129. Colour StoredSettings::ColourSelectorWithSwatches::getSwatchColour (int index) const
  130. {
  131. return getAppSettings().swatchColours [index];
  132. }
  133. void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, const Colour& newColour) const
  134. {
  135. getAppSettings().swatchColours.set (index, newColour);
  136. }