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.

137 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. //==============================================================================
  21. StoredSettings::StoredSettings()
  22. : props (0)
  23. {
  24. flush();
  25. }
  26. StoredSettings::~StoredSettings()
  27. {
  28. flush();
  29. props = 0;
  30. clearSingletonInstance();
  31. }
  32. juce_ImplementSingleton (StoredSettings);
  33. //==============================================================================
  34. PropertiesFile& StoredSettings::getProps()
  35. {
  36. jassert (props != 0);
  37. return *props;
  38. }
  39. void StoredSettings::flush()
  40. {
  41. if (props != 0)
  42. {
  43. props->setValue ("recentFiles", recentFiles.toString());
  44. props->removeValue ("keyMappings");
  45. if (commandManager != 0)
  46. {
  47. ScopedPointer <XmlElement> keys (commandManager->getKeyMappings()->createXml (true));
  48. if (keys != 0)
  49. props->setValue ("keyMappings", (XmlElement*) keys);
  50. }
  51. }
  52. props = 0;
  53. props = PropertiesFile::createDefaultAppPropertiesFile ("Jucer2",
  54. "settings",
  55. String::empty,
  56. false, 3000,
  57. PropertiesFile::storeAsXML);
  58. // recent files...
  59. recentFiles.restoreFromString (props->getValue ("recentFiles"));
  60. recentFiles.removeNonExistentFiles();
  61. // swatch colours...
  62. swatchColours.clear();
  63. #define COL(col) Colours::col,
  64. const Colour colours[] =
  65. {
  66. #include "jucer_Colours.h"
  67. Colours::transparentBlack
  68. };
  69. #undef COL
  70. for (int i = 0; i < numSwatchColours; ++i)
  71. {
  72. Colour defaultCol (colours [2 + i]);
  73. swatchColours.add (Colour (props->getValue ("swatchColour" + String (i),
  74. hexString8Digits (defaultCol.getARGB())).getHexValue32()));
  75. }
  76. }
  77. const File StoredSettings::getLastProject() const
  78. {
  79. return props->getValue ("lastProject");
  80. }
  81. void StoredSettings::setLastProject (const File& file)
  82. {
  83. props->setValue ("lastProject", file.getFullPathName());
  84. }
  85. const File StoredSettings::getLastKnownJuceFolder() const
  86. {
  87. File defaultJuceFolder (findDefaultJuceFolder());
  88. File f (props->getValue ("lastJuceFolder", defaultJuceFolder.getFullPathName()));
  89. if ((! isJuceFolder (f)) && isJuceFolder (defaultJuceFolder))
  90. f = defaultJuceFolder;
  91. return f;
  92. }
  93. void StoredSettings::setLastKnownJuceFolder (const File& file)
  94. {
  95. jassert (isJuceFolder (file));
  96. props->setValue ("lastJuceFolder", file.getFullPathName());
  97. }
  98. const StringArray& StoredSettings::getFontNames()
  99. {
  100. if (fontNames.size() == 0)
  101. fontNames = Font::findAllTypefaceNames();
  102. return fontNames;
  103. }