| @@ -51,7 +51,7 @@ namespace AppearanceColours | |||
| } | |||
| //============================================================================== | |||
| AppearanceSettings::AppearanceSettings (const CodeEditorComponent& editor) | |||
| AppearanceSettings::AppearanceSettings() | |||
| : settings ("COLOUR_SCHEME") | |||
| { | |||
| IntrojucerLookAndFeel lf; | |||
| @@ -59,6 +59,10 @@ AppearanceSettings::AppearanceSettings (const CodeEditorComponent& editor) | |||
| for (int i = 0; i < sizeof (AppearanceColours::colours) / sizeof (AppearanceColours::colours[0]); ++i) | |||
| getColourValue (AppearanceColours::colours[i].name) = lf.findColour (AppearanceColours::colours[i].colourID).toString(); | |||
| CodeDocument doc; | |||
| CPlusPlusCodeTokeniser tokeniser; | |||
| CodeEditorComponent editor (doc, &tokeniser); | |||
| const CodeEditorComponent::ColourScheme cs (editor.getColourScheme()); | |||
| for (int i = cs.types.size(); --i >= 0;) | |||
| @@ -74,6 +78,44 @@ AppearanceSettings::AppearanceSettings (const CodeEditorComponent& editor) | |||
| settings.addListener (this); | |||
| } | |||
| File AppearanceSettings::getSchemesFolder() | |||
| { | |||
| File f (getAppProperties().getFile().getSiblingFile ("Colour Schemes")); | |||
| f.createDirectory(); | |||
| return f; | |||
| } | |||
| void AppearanceSettings::refreshPresetSchemeList() | |||
| { | |||
| const File defaultSchemeFile (getSchemesFolder().getChildFile ("Default").withFileExtension (getSchemeFileSuffix())); | |||
| if (! defaultSchemeFile.exists()) | |||
| AppearanceSettings().writeToFile (defaultSchemeFile); | |||
| Array<File> newSchemes; | |||
| getSchemesFolder().findChildFiles (newSchemes, File::findFiles, false, String ("*") + getSchemeFileSuffix()); | |||
| if (newSchemes != presetSchemeFiles) | |||
| { | |||
| presetSchemeFiles.swapWithArray (newSchemes); | |||
| commandManager->commandStatusChanged(); | |||
| } | |||
| } | |||
| StringArray AppearanceSettings::getPresetSchemes() | |||
| { | |||
| StringArray s; | |||
| for (int i = 0; i < presetSchemeFiles.size(); ++i) | |||
| s.add (presetSchemeFiles.getReference(i).getFileNameWithoutExtension()); | |||
| return s; | |||
| } | |||
| void AppearanceSettings::selectPresetScheme (int index) | |||
| { | |||
| readFromFile (presetSchemeFiles [index]); | |||
| } | |||
| bool AppearanceSettings::readFromXML (const XmlElement& xml) | |||
| { | |||
| if (xml.hasTagName (settings.getType().toString())) | |||
| @@ -321,20 +363,21 @@ struct AppearanceEditor | |||
| void saveScheme() | |||
| { | |||
| FileChooser fc ("Select a file in which to save this colour-scheme...", | |||
| getAppSettings().getSchemesFolder().getNonexistentChildFile ("Scheme", ".editorscheme"), | |||
| getAppSettings().appearance.getSchemesFolder().getNonexistentChildFile ("Scheme", ".editorscheme"), | |||
| "*.editorscheme"); | |||
| if (fc.browseForFileToSave (true)) | |||
| { | |||
| File file (fc.getResult().withFileExtension (".editorscheme")); | |||
| getAppSettings().appearance.writeToFile (file); | |||
| getAppSettings().appearance.refreshPresetSchemeList(); | |||
| } | |||
| } | |||
| void loadScheme() | |||
| { | |||
| FileChooser fc ("Please select a colour-scheme file to load...", | |||
| getAppSettings().getSchemesFolder(), | |||
| getAppSettings().appearance.getSchemesFolder(), | |||
| "*.editorscheme"); | |||
| if (fc.browseForFileToOpen()) | |||
| @@ -30,13 +30,12 @@ | |||
| class AppearanceSettings : private ValueTree::Listener | |||
| { | |||
| public: | |||
| AppearanceSettings (const CodeEditorComponent& editorToCopyFrom); | |||
| AppearanceSettings(); | |||
| bool readFromFile (const File& file); | |||
| bool readFromXML (const XmlElement&); | |||
| bool writeToFile (const File& file) const; | |||
| void applyToLookAndFeel (LookAndFeel&) const; | |||
| void applyToCodeEditor (CodeEditorComponent& editor) const; | |||
| StringArray getColourNames() const; | |||
| @@ -48,18 +47,29 @@ public: | |||
| ValueTree settings; | |||
| static Component* createEditorWindow(); | |||
| File getSchemesFolder(); | |||
| StringArray getPresetSchemes(); | |||
| void refreshPresetSchemeList(); | |||
| void selectPresetScheme (int index); | |||
| static void intialiseLookAndFeel (LookAndFeel&); | |||
| static Component* createEditorWindow(); | |||
| private: | |||
| static const char* getSchemeFileSuffix() { return ".editorscheme"; } | |||
| Array<File> presetSchemeFiles; | |||
| void applyToLookAndFeel (LookAndFeel&) const; | |||
| void updateColourScheme(); | |||
| void valueTreePropertyChanged (ValueTree&, const Identifier&) { updateColourScheme(); } | |||
| void valueTreeChildAdded (ValueTree&, ValueTree&) { updateColourScheme(); } | |||
| void valueTreeChildRemoved (ValueTree&, ValueTree&) { updateColourScheme(); } | |||
| void valueTreeChildOrderChanged (ValueTree&) { updateColourScheme(); } | |||
| void valueTreeParentChanged (ValueTree&) { updateColourScheme(); } | |||
| void valueTreeRedirected (ValueTree&) { updateColourScheme(); } | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AppearanceSettings); | |||
| }; | |||
| //============================================================================== | |||
| @@ -67,6 +67,8 @@ public: | |||
| doExtraInitialisation(); | |||
| settings.appearance.refreshPresetSchemeList(); | |||
| ImageCache::setCacheTimeout (30 * 1000); | |||
| if (commandLine.trim().isNotEmpty() && ! commandLine.trim().startsWithChar ('-')) | |||
| @@ -168,21 +170,32 @@ public: | |||
| void menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/) | |||
| { | |||
| if (menuItemID >= 100 && menuItemID < 200) | |||
| if (menuItemID >= recentProjectsBaseID && menuItemID < recentProjectsBaseID + 100) | |||
| { | |||
| // open a file from the "recent files" menu | |||
| getApp().openFile (getAppSettings().recentFiles.getFile (menuItemID - 100)); | |||
| getApp().openFile (getAppSettings().recentFiles.getFile (menuItemID - recentProjectsBaseID)); | |||
| } | |||
| else if (menuItemID >= 300 && menuItemID < 400) | |||
| else if (menuItemID >= activeDocumentsBaseID && menuItemID < activeDocumentsBaseID + 200) | |||
| { | |||
| OpenDocumentManager::Document* doc = getApp().openDocumentManager.getOpenDocument (menuItemID - 300); | |||
| OpenDocumentManager::Document* doc = getApp().openDocumentManager.getOpenDocument (menuItemID - activeDocumentsBaseID); | |||
| jassert (doc != nullptr); | |||
| getApp().mainWindowList.openDocument (doc); | |||
| } | |||
| else if (menuItemID >= colourSchemeBaseID && menuItemID < colourSchemeBaseID + 200) | |||
| { | |||
| getApp().settings.appearance.selectPresetScheme (menuItemID - colourSchemeBaseID); | |||
| } | |||
| } | |||
| }; | |||
| enum | |||
| { | |||
| recentProjectsBaseID = 100, | |||
| activeDocumentsBaseID = 300, | |||
| colourSchemeBaseID = 1000 | |||
| }; | |||
| virtual StringArray getMenuNames() | |||
| { | |||
| const char* const names[] = { "File", "Edit", "View", "Window", "Tools", nullptr }; | |||
| @@ -206,7 +219,7 @@ public: | |||
| menu.addCommandItem (commandManager, CommandIDs::open); | |||
| PopupMenu recentFiles; | |||
| getAppSettings().recentFiles.createPopupMenuItems (recentFiles, 100, true, true); | |||
| getAppSettings().recentFiles.createPopupMenuItems (recentFiles, recentProjectsBaseID, true, true); | |||
| menu.addSubMenu ("Open recent file", recentFiles); | |||
| menu.addSeparator(); | |||
| @@ -251,7 +264,24 @@ public: | |||
| menu.addCommandItem (commandManager, CommandIDs::showFilePanel); | |||
| menu.addCommandItem (commandManager, CommandIDs::showConfigPanel); | |||
| menu.addSeparator(); | |||
| createColourSchemeItems (menu); | |||
| } | |||
| void createColourSchemeItems (PopupMenu& menu) | |||
| { | |||
| menu.addCommandItem (commandManager, CommandIDs::showAppearanceSettings); | |||
| const StringArray presetSchemes (settings.appearance.getPresetSchemes()); | |||
| if (presetSchemes.size() > 0) | |||
| { | |||
| PopupMenu schemes; | |||
| for (int i = 0; i < presetSchemes.size(); ++i) | |||
| schemes.addItem (colourSchemeBaseID + i, presetSchemes[i]); | |||
| menu.addSubMenu ("Colour Scheme", schemes); | |||
| } | |||
| } | |||
| virtual void createWindowMenu (PopupMenu& menu) | |||
| @@ -269,7 +299,7 @@ public: | |||
| { | |||
| OpenDocumentManager::Document* doc = getApp().openDocumentManager.getOpenDocument(i); | |||
| menu.addItem (300 + i, doc->getName()); | |||
| menu.addItem (activeDocumentsBaseID + i, doc->getName()); | |||
| } | |||
| menu.addSeparator(); | |||
| @@ -38,17 +38,8 @@ PropertiesFile& getAppProperties() | |||
| return getAppSettings().getProps(); | |||
| } | |||
| static AppearanceSettings getDefaultScheme() | |||
| { | |||
| CodeDocument doc; | |||
| CPlusPlusCodeTokeniser tokeniser; | |||
| CodeEditorComponent defaultComp (doc, &tokeniser); | |||
| return AppearanceSettings (defaultComp); | |||
| } | |||
| //============================================================================== | |||
| StoredSettings::StoredSettings() | |||
| : appearance (getDefaultScheme()) | |||
| { | |||
| } | |||
| @@ -60,11 +51,6 @@ StoredSettings::~StoredSettings() | |||
| void StoredSettings::initialise() | |||
| { | |||
| reload(); | |||
| const File defaultSchemeFile (getSchemesFolder().getChildFile ("Default").withFileExtension (getSchemeFileSuffix())); | |||
| if (! defaultSchemeFile.exists()) | |||
| appearance.writeToFile (defaultSchemeFile); | |||
| } | |||
| PropertiesFile& StoredSettings::getProps() | |||
| @@ -205,13 +191,6 @@ void StoredSettings::ColourSelectorWithSwatches::setSwatchColour (int index, con | |||
| getAppSettings().swatchColours.set (index, newColour); | |||
| } | |||
| File StoredSettings::getSchemesFolder() | |||
| { | |||
| File f (getProps().getFile().getSiblingFile ("Colour Schemes")); | |||
| f.createDirectory(); | |||
| return f; | |||
| } | |||
| //============================================================================== | |||
| const Icons& getIcons() | |||
| { | |||
| @@ -66,9 +66,6 @@ public: | |||
| //============================================================================== | |||
| AppearanceSettings appearance; | |||
| const char* getSchemeFileSuffix() const { return ".editorscheme"; } | |||
| File getSchemesFolder(); | |||
| private: | |||
| ScopedPointer<PropertiesFile> props; | |||
| StringArray fontNames; | |||