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.

200 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. }
  35. StoredSettings::~StoredSettings()
  36. {
  37. flush();
  38. }
  39. void StoredSettings::initialise()
  40. {
  41. reload();
  42. }
  43. PropertiesFile& StoredSettings::getGlobalProperties()
  44. {
  45. return *propertyFiles.getUnchecked (0);
  46. }
  47. static PropertiesFile* createPropsFile (const String& filename)
  48. {
  49. PropertiesFile::Options options;
  50. options.applicationName = filename;
  51. options.filenameSuffix = "settings";
  52. options.osxLibrarySubFolder = "Application Support";
  53. #if JUCE_LINUX
  54. options.folderName = ".introjucer";
  55. #else
  56. options.folderName = "Introjucer";
  57. #endif
  58. return new PropertiesFile (options);
  59. }
  60. PropertiesFile& StoredSettings::getProjectProperties (const String& projectUID)
  61. {
  62. const String filename ("Introjucer_Project_" + projectUID);
  63. for (int i = propertyFiles.size(); --i >= 0;)
  64. {
  65. PropertiesFile* const props = propertyFiles.getUnchecked(i);
  66. if (props->getFile().getFileNameWithoutExtension() == filename)
  67. return *props;
  68. }
  69. PropertiesFile* p = createPropsFile (filename);
  70. propertyFiles.add (p);
  71. return *p;
  72. }
  73. void StoredSettings::updateGlobalProps()
  74. {
  75. PropertiesFile& props = getGlobalProperties();
  76. {
  77. const ScopedPointer<XmlElement> xml (appearance.settings.createXml());
  78. props.setValue ("editorColours", xml);
  79. }
  80. props.setValue ("recentFiles", recentFiles.toString());
  81. props.removeValue ("keyMappings");
  82. if (commandManager != nullptr)
  83. {
  84. const ScopedPointer <XmlElement> keys (commandManager->getKeyMappings()->createXml (true));
  85. if (keys != nullptr)
  86. props.setValue ("keyMappings", keys);
  87. }
  88. }
  89. void StoredSettings::flush()
  90. {
  91. updateGlobalProps();
  92. for (int i = propertyFiles.size(); --i >= 0;)
  93. propertyFiles.getUnchecked(i)->saveIfNeeded();
  94. }
  95. void StoredSettings::reload()
  96. {
  97. propertyFiles.clear();
  98. propertyFiles.add (createPropsFile ("Introjucer"));
  99. // recent files...
  100. recentFiles.restoreFromString (getGlobalProperties().getValue ("recentFiles"));
  101. recentFiles.removeNonExistentFiles();
  102. ScopedPointer<XmlElement> xml (getGlobalProperties().getXmlValue ("editorColours"));
  103. if (xml == nullptr)
  104. xml = XmlDocument::parse (BinaryData::colourscheme_dark_xml);
  105. appearance.readFromXML (*xml);
  106. appearance.updateColourScheme();
  107. loadSwatchColours();
  108. }
  109. Array<File> StoredSettings::getLastProjects()
  110. {
  111. StringArray s;
  112. s.addTokens (getGlobalProperties().getValue ("lastProjects"), "|", "");
  113. Array<File> f;
  114. for (int i = 0; i < s.size(); ++i)
  115. f.add (File (s[i]));
  116. return f;
  117. }
  118. void StoredSettings::setLastProjects (const Array<File>& files)
  119. {
  120. StringArray s;
  121. for (int i = 0; i < files.size(); ++i)
  122. s.add (files.getReference(i).getFullPathName());
  123. getGlobalProperties().setValue ("lastProjects", s.joinIntoString ("|"));
  124. }
  125. //==============================================================================
  126. void StoredSettings::loadSwatchColours()
  127. {
  128. swatchColours.clear();
  129. #define COL(col) Colours::col,
  130. const Colour colours[] =
  131. {
  132. #include "jucer_Colours.h"
  133. Colours::transparentBlack
  134. };
  135. #undef COL
  136. const int numSwatchColours = 24;
  137. PropertiesFile& props = getGlobalProperties();
  138. for (int i = 0; i < numSwatchColours; ++i)
  139. swatchColours.add (Colour::fromString (props.getValue ("swatchColour" + String (i),
  140. colours [2 + i].toString())));
  141. }
  142. int StoredSettings::ColourSelectorWithSwatches::getNumSwatches() const
  143. {
  144. return getAppSettings().swatchColours.size();
  145. }
  146. Colour StoredSettings::ColourSelectorWithSwatches::getSwatchColour (int index) const
  147. {
  148. return getAppSettings().swatchColours [index];
  149. }
  150. void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, const Colour& newColour) const
  151. {
  152. getAppSettings().swatchColours.set (index, newColour);
  153. }