<commit_before>/*
 * Copyright (c) 2014 <NAME>.
 *
 * Licensed under MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window, */

define(function (require, exports, module) {
    "use strict";

    var CommandManager      = brackets.getModule("command/CommandManager"),
        CodeMirror          = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror"),
        Menus               = brackets.getModule("command/Menus"),
        PreferencesManager  = brackets.getModule("preferences/PreferencesManager"),
        ExtensionUtils      = brackets.getModule("utils/ExtensionUtils"),
        FileSystem          = brackets.getModule("filesystem/FileSystem");

	var prefs = PreferencesManager.getExtensionPrefs("Themes-for-brackets"),
        menu = Menus.addMenu("Themes", "themes-for-brackets", Menus.AFTER, Menus.AppMenuBar.VIEW_MENU),
        moduleThemesDir = ExtensionUtils.getModulePath(module, "themes/"),
		customThemesDir = brackets.app.getApplicationSupportDirectory() + "/custom themes/";

	
	var Themes = {};
    
    //Define preferences
    prefs.definePreference("theme", "string", "default");
    prefs.definePreference("isCustom", "boolean", false);
	
	// If there is no currently selected theme, use default
	Themes.currentTheme = prefs.get("theme");
//    if (Themes.currentTheme === undefined) {
//        prefs.set("theme", "default");
//		Themes.currentTheme = "default";
//    }

	var __custom = prefs.get("isCustom");
//    if (__custom === undefined) {
//        prefs.set("isCustom", false);
//        __custom = false;
//    }
	
	Themes.getName = function (theme) {
		theme = theme || Themes.currentTheme;
		theme = theme.replace(new RegExp("-", "g"), " ");
		return theme.charAt(0).toUpperCase() + theme.slice(1);
	};
	
	Themes.load = function (theme, isCustom) {
        $("#editor-holder .CodeMirror").removeClass("cm-s-default");
		$("#editor-holder .CodeMirror").removeClass("cm-s-" + Themes.currentTheme);
		Themes.setCommand(Themes.currentTheme, false);
		Themes.currentTheme = theme;
		if (isCustom) {
			$("#currentTheme").attr("href", customThemesDir + Themes.currentTheme + ".css");
			prefs.set("isCustom", true);
		} else {
			$("#currentTheme").attr("href", moduleThemesDir + Themes.currentTheme + ".css");
			prefs.set("isCustom", false);
			if (theme !== "visual-studio" && theme !== "default") {
				$("#baseStyle").attr("href", ExtensionUtils.getModulePath(module, "") + "dark.css");
			} else {
				$("#baseStyle").attr("href", "");
			}
		}
		Themes.setCommand(Themes.currentTheme, true);
		prefs.set("theme", Themes.currentTheme);
		CodeMirror.defaults.theme = Themes.currentTheme;
        prefs.save();
		$("#editor-holder .CodeMirror").addClass("cm-s-" + Themes.currentTheme);
	};
	
	Themes.setCommand = function (theme, val) {
		CommandManager.get("jacse.themes-for-brackets.changetheme_" + theme).setChecked(val);
	};

	function addCommand(theme, isCustom, firstCustom) {
		var command = "jacse.themes-for-brackets.changetheme_" + theme;
		CommandManager.register(Themes.getName(theme), command, function () {
			Themes.load(theme, isCustom);
		});
        if (firstCustom) {
            menu.addMenuDivider();
        }
		menu.addMenuItem(command);
	}
	
	
	// Pass file names as an array and create the themes
    Themes.getDirFiles = function (themesNameArray) {
        var i,
            len = themesNameArray.length,
            findDefault = themesNameArray.indexOf('default'),
            firstCustom = true;
        if (findDefault !== -1) { //make sure default theme is on top
            themesNameArray = themesNameArray.splice(findDefault, 1).concat(themesNameArray);
        }
        for (i = 0; i < len; i++) {
            if (themesNameArray[i].indexOf(".css") > -1) { //I know this is a stupid way to check whether a theme is custom, but hey!
                if (firstCustom) {
                    addCommand(themesNameArray[i].replace(".css", ""), true, true);
                    firstCustom = false;
                } else {
                    addCommand(themesNameArray[i].replace(".css", ""), true);
                }
            } else {
                addCommand(themesNameArray[i]);
            }
            if (i === 0) { //Add menu divider after default theme
                menu.addMenuDivider();
            }
        }
	    $("body").append('<link id="themesCss" rel="stylesheet" href="' + ExtensionUtils.getModulePath(module, "") + 'stuff.css"/>');
        $("body").append('<link id="currentTheme" rel="stylesheet"/>');
	    $("body").append('<link id="baseStyle" rel="stylesheet"/>');
		
        Themes.load(Themes.currentTheme, __custom);
    };
	

    // Get standard themes
    console.log("Getting contents of themes directory...");
	FileSystem.getDirectoryForPath(moduleThemesDir).getContents(function (err, contents) {
		if (err) {
			console.log("Error getting themes:" + err);
		}
		var themesInDir = [], i;
		for (i = 0; i < contents.length; i++) {
			themesInDir.push(contents[i].name.replace(".css", ""));
		}
		
		//Make sure custom themes directory exists
		console.log("Creating custom themes directory...");
		FileSystem.getDirectoryForPath(customThemesDir).create(function () {
			// Get custom themes
			console.log("Getting contents of custom themes directory...");
			FileSystem.getDirectoryForPath(customThemesDir).getContents(function (err, contents) {
				if (err) {
					console.log("Error getting custom themes:" + err);
				}
				var themesInDir2 = [], i;
				for (i = 0; i < contents.length; i++) {
					themesInDir2.push(contents[i].name);
				}
				console.log("Adding all themes to themes menu...");
				Themes.getDirFiles(themesInDir.concat(themesInDir2));
			});
		});
	});
	
});<commit_msg>Whitespace Normalizer.<commit_after>/*
 * Copyright (c) 2014 <NAME>.
 *
 * Licensed under MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window, */

define(function (require, exports, module) {
    "use strict";

    var CommandManager      = brackets.getModule("command/CommandManager"),
        CodeMirror          = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror"),
        Menus               = brackets.getModule("command/Menus"),
        PreferencesManager  = brackets.getModule("preferences/PreferencesManager"),
        ExtensionUtils      = brackets.getModule("utils/ExtensionUtils"),
        FileSystem          = brackets.getModule("filesystem/FileSystem");

    var prefs = PreferencesManager.getExtensionPrefs("Themes-for-brackets"),
        menu = Menus.addMenu("Themes", "themes-for-brackets", Menus.AFTER, Menus.AppMenuBar.VIEW_MENU),
        moduleThemesDir = ExtensionUtils.getModulePath(module, "themes/"),
        customThemesDir = brackets.app.getApplicationSupportDirectory() + "/custom themes/";


    var Themes = {};

    //Define preferences
    prefs.definePreference("theme", "string", "default");
    prefs.definePreference("isCustom", "boolean", false);

    // If there is no currently selected theme, use default
    Themes.currentTheme = prefs.get("theme");
//    if (Themes.currentTheme === undefined) {
//        prefs.set("theme", "default");
//        Themes.currentTheme = "default";
//    }

    var __custom = prefs.get("isCustom");
//    if (__custom === undefined) {
//        prefs.set("isCustom", false);
//        __custom = false;
//    }

    Themes.getName = function (theme) {
        theme = theme || Themes.currentTheme;
        theme = theme.replace(new RegExp("-", "g"), " ");
        return theme.charAt(0).toUpperCase() + theme.slice(1);
    };

    Themes.load = function (theme, isCustom) {
        $("#editor-holder .CodeMirror").removeClass("cm-s-default");
        $("#editor-holder .CodeMirror").removeClass("cm-s-" + Themes.currentTheme);
        Themes.setCommand(Themes.currentTheme, false);
        Themes.currentTheme = theme;
        if (isCustom) {
            $("#currentTheme").attr("href", customThemesDir + Themes.currentTheme + ".css");
            prefs.set("isCustom", true);
        } else {
            $("#currentTheme").attr("href", moduleThemesDir + Themes.currentTheme + ".css");
            prefs.set("isCustom", false);
            if (theme !== "visual-studio" && theme !== "default") {
                $("#baseStyle").attr("href", ExtensionUtils.getModulePath(module, "") + "dark.css");
            } else {
                $("#baseStyle").attr("href", "");
            }
        }
        Themes.setCommand(Themes.currentTheme, true);
        prefs.set("theme", Themes.currentTheme);
        CodeMirror.defaults.theme = Themes.currentTheme;
        prefs.save();
        $("#editor-holder .CodeMirror").addClass("cm-s-" + Themes.currentTheme);
    };

    Themes.setCommand = function (theme, val) {
        CommandManager.get("jacse.themes-for-brackets.changetheme_" + theme).setChecked(val);
    };

    function addCommand(theme, isCustom, firstCustom) {
        var command = "jacse.themes-for-brackets.changetheme_" + theme;
        CommandManager.register(Themes.getName(theme), command, function () {
            Themes.load(theme, isCustom);
        });
        if (firstCustom) {
            menu.addMenuDivider();
        }
        menu.addMenuItem(command);
    }


    // Pass file names as an array and create the themes
    Themes.getDirFiles = function (themesNameArray) {
        var i,
            len = themesNameArray.length,
            findDefault = themesNameArray.indexOf('default'),
            firstCustom = true;
        if (findDefault !== -1) { //make sure default theme is on top
            themesNameArray = themesNameArray.splice(findDefault, 1).concat(themesNameArray);
        }
        for (i = 0; i < len; i++) {
            if (themesNameArray[i].indexOf(".css") > -1) { //I know this is a stupid way to check whether a theme is custom, but hey!
                if (firstCustom) {
                    addCommand(themesNameArray[i].replace(".css", ""), true, true);
                    firstCustom = false;
                } else {
                    addCommand(themesNameArray[i].replace(".css", ""), true);
                }
            } else {
                addCommand(themesNameArray[i]);
            }
            if (i === 0) { //Add menu divider after default theme
                menu.addMenuDivider();
            }
        }
        $("body").append('<link id="themesCss" rel="stylesheet" href="' + ExtensionUtils.getModulePath(module, "") + 'stuff.css"/>');
        $("body").append('<link id="currentTheme" rel="stylesheet"/>');
        $("body").append('<link id="baseStyle" rel="stylesheet"/>');

        Themes.load(Themes.currentTheme, __custom);
    };


    // Get standard themes
    console.log("Getting contents of themes directory...");
    FileSystem.getDirectoryForPath(moduleThemesDir).getContents(function (err, contents) {
        if (err) {
            console.log("Error getting themes:" + err);
        }
        var themesInDir = [], i;
        for (i = 0; i < contents.length; i++) {
            themesInDir.push(contents[i].name.replace(".css", ""));
        }

        //Make sure custom themes directory exists
        console.log("Creating custom themes directory...");
        FileSystem.getDirectoryForPath(customThemesDir).create(function () {
            // Get custom themes
            console.log("Getting contents of custom themes directory...");
            FileSystem.getDirectoryForPath(customThemesDir).getContents(function (err, contents) {
                if (err) {
                    console.log("Error getting custom themes:" + err);
                }
                var themesInDir2 = [], i;
                for (i = 0; i < contents.length; i++) {
                    themesInDir2.push(contents[i].name);
                }
                console.log("Adding all themes to themes menu...");
                Themes.getDirFiles(themesInDir.concat(themesInDir2));
            });
        });
    });

});
{'fraction_non_alphanumeric': 0.1383157894736842, 'fraction_numerical': 0.002807017543859649, 'mean_word_length': 2.8043246129204484, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1471871', 'n_tokens_mistral': 4218, 'n_tokens_neox': 3909, 'n_words': 1029}