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.6KB

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