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.

176 lines
4.9KB

  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. const ScopedPointer<XmlElement> xml (props->getXmlValue ("editorColours"));
  87. if (xml != nullptr)
  88. appearance.readFromXML (*xml);
  89. appearance.updateColourScheme();
  90. loadSwatchColours();
  91. }
  92. Array<File> StoredSettings::getLastProjects() const
  93. {
  94. StringArray s;
  95. s.addTokens (props->getValue ("lastProjects"), "|", "");
  96. Array<File> f;
  97. for (int i = 0; i < s.size(); ++i)
  98. f.add (File (s[i]));
  99. return f;
  100. }
  101. void StoredSettings::setLastProjects (const Array<File>& files)
  102. {
  103. StringArray s;
  104. for (int i = 0; i < files.size(); ++i)
  105. s.add (files.getReference(i).getFullPathName());
  106. props->setValue ("lastProjects", s.joinIntoString ("|"));
  107. }
  108. //==============================================================================
  109. void StoredSettings::loadSwatchColours()
  110. {
  111. swatchColours.clear();
  112. #define COL(col) Colours::col,
  113. const Colour colours[] =
  114. {
  115. #include "jucer_Colours.h"
  116. Colours::transparentBlack
  117. };
  118. #undef COL
  119. const int numSwatchColours = 24;
  120. for (int i = 0; i < numSwatchColours; ++i)
  121. swatchColours.add (Colour::fromString (props->getValue ("swatchColour" + String (i),
  122. colours [2 + i].toString())));
  123. }
  124. int StoredSettings::ColourSelectorWithSwatches::getNumSwatches() const
  125. {
  126. return getAppSettings().swatchColours.size();
  127. }
  128. Colour StoredSettings::ColourSelectorWithSwatches::getSwatchColour (int index) const
  129. {
  130. return getAppSettings().swatchColours [index];
  131. }
  132. void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, const Colour& newColour) const
  133. {
  134. getAppSettings().swatchColours.set (index, newColour);
  135. }