1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    By using JUCE, you agree to the terms of both the JUCE 6 End-User License
11    Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
12 
13    End User License Agreement: www.juce.com/juce-6-licence
14    Privacy Policy: www.juce.com/juce-privacy-policy
15 
16    Or: You may also use this code under the terms of the GPL v3 (see
17    www.gnu.org/licenses).
18 
19    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21    DISCLAIMED.
22 
23   ==============================================================================
24 */
25 
26 #pragma once
27 
28 
29 //==============================================================================
30 class AppearanceSettings    : private ValueTree::Listener
31 {
32 public:
33     AppearanceSettings (bool updateAppWhenChanged);
34 
35     bool readFromFile (const File& file);
36     bool readFromXML (const XmlElement&);
37     bool writeToFile (const File& file) const;
38 
39     void updateColourScheme();
40     void applyToCodeEditor (CodeEditorComponent& editor) const;
41 
42     StringArray getColourNames() const;
43     Value getColourValue (const String& colourName);
44     bool getColour (const String& name, Colour& resultIfFound) const;
45 
46     Font getCodeFont() const;
47     Value getCodeFontValue();
48 
49     ValueTree settings;
50 
51     static File getSchemesFolder();
52     StringArray getPresetSchemes();
53     void refreshPresetSchemeList();
54     void selectPresetScheme (int index);
55 
56     static Font getDefaultCodeFont();
57 
getSchemeFileSuffix()58     static const char* getSchemeFileSuffix()      { return ".scheme"; }
getSchemeFileWildCard()59     static const char* getSchemeFileWildCard()    { return "*.scheme"; }
60 
61 private:
62 
63     Array<File> presetSchemeFiles;
64 
65     static void writeDefaultSchemeFile (const String& xml, const String& name);
66 
valueTreePropertyChanged(ValueTree &,const Identifier &)67     void valueTreePropertyChanged (ValueTree&, const Identifier&) override   { updateColourScheme(); }
valueTreeChildAdded(ValueTree &,ValueTree &)68     void valueTreeChildAdded (ValueTree&, ValueTree&) override               { updateColourScheme(); }
valueTreeChildRemoved(ValueTree &,ValueTree &,int)69     void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override        { updateColourScheme(); }
valueTreeChildOrderChanged(ValueTree &,int,int)70     void valueTreeChildOrderChanged (ValueTree&, int, int) override          { updateColourScheme(); }
valueTreeParentChanged(ValueTree &)71     void valueTreeParentChanged (ValueTree&) override                        { updateColourScheme(); }
valueTreeRedirected(ValueTree &)72     void valueTreeRedirected (ValueTree&) override                           { updateColourScheme(); }
73 
74     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AppearanceSettings)
75 };
76