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.

197 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::flush()
  74. {
  75. for (int i = propertyFiles.size(); --i >= 0;)
  76. {
  77. PropertiesFile* const props = propertyFiles.getUnchecked(i);
  78. {
  79. const ScopedPointer<XmlElement> xml (appearance.settings.createXml());
  80. props->setValue ("editorColours", xml);
  81. }
  82. props->setValue ("recentFiles", recentFiles.toString());
  83. props->removeValue ("keyMappings");
  84. if (commandManager != nullptr)
  85. {
  86. ScopedPointer <XmlElement> keys (commandManager->getKeyMappings()->createXml (true));
  87. if (keys != nullptr)
  88. props->setValue ("keyMappings", (XmlElement*) keys);
  89. }
  90. props->saveIfNeeded();
  91. }
  92. }
  93. void StoredSettings::reload()
  94. {
  95. propertyFiles.clear();
  96. propertyFiles.add (createPropsFile ("Introjucer"));
  97. // recent files...
  98. recentFiles.restoreFromString (getGlobalProperties().getValue ("recentFiles"));
  99. recentFiles.removeNonExistentFiles();
  100. ScopedPointer<XmlElement> xml (getGlobalProperties().getXmlValue ("editorColours"));
  101. if (xml == nullptr)
  102. xml = XmlDocument::parse (BinaryData::colourscheme_dark_xml);
  103. appearance.readFromXML (*xml);
  104. appearance.updateColourScheme();
  105. loadSwatchColours();
  106. }
  107. Array<File> StoredSettings::getLastProjects()
  108. {
  109. StringArray s;
  110. s.addTokens (getGlobalProperties().getValue ("lastProjects"), "|", "");
  111. Array<File> f;
  112. for (int i = 0; i < s.size(); ++i)
  113. f.add (File (s[i]));
  114. return f;
  115. }
  116. void StoredSettings::setLastProjects (const Array<File>& files)
  117. {
  118. StringArray s;
  119. for (int i = 0; i < files.size(); ++i)
  120. s.add (files.getReference(i).getFullPathName());
  121. getGlobalProperties().setValue ("lastProjects", s.joinIntoString ("|"));
  122. }
  123. //==============================================================================
  124. void StoredSettings::loadSwatchColours()
  125. {
  126. swatchColours.clear();
  127. #define COL(col) Colours::col,
  128. const Colour colours[] =
  129. {
  130. #include "jucer_Colours.h"
  131. Colours::transparentBlack
  132. };
  133. #undef COL
  134. const int numSwatchColours = 24;
  135. PropertiesFile& props = getGlobalProperties();
  136. for (int i = 0; i < numSwatchColours; ++i)
  137. swatchColours.add (Colour::fromString (props.getValue ("swatchColour" + String (i),
  138. colours [2 + i].toString())));
  139. }
  140. int StoredSettings::ColourSelectorWithSwatches::getNumSwatches() const
  141. {
  142. return getAppSettings().swatchColours.size();
  143. }
  144. Colour StoredSettings::ColourSelectorWithSwatches::getSwatchColour (int index) const
  145. {
  146. return getAppSettings().swatchColours [index];
  147. }
  148. void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, const Colour& newColour) const
  149. {
  150. getAppSettings().swatchColours.set (index, newColour);
  151. }