<commit_before>var fpvsPrefRoot = "extensions.FolderPaneSwitcher.";

fpvsUtils = {
    event_handlers: [],
    pref_observers: [],

    init: function() {
        this.prefService = Components
            .classes["@mozilla.org/preferences-service;1"]
            .getService(Components.interfaces.nsIPrefService);
        this.prefBranch = this.prefService.getBranch(fpvsPrefRoot);
        this.viewsBranch = this.prefService.getBranch(fpvsPrefRoot + "views.");
    },

    uninit: function() {
        for (var args of this.event_handlers) {
            args[0].removeEventListener(args[1], args[2], args[3]);
        }
        for (var args of this.pref_observers) {
            args[0].removeObserver(args[1], args[2]);
        }
    },

    addEventListener: function(target, type, listener, useCapture) {
        target.addEventListener(type, listener, useCapture);
        this.event_handlers.push([target, type, listener, useCapture]);
    },

    addObserver: function(branch, pref, observer, holdWeak) {
        branch.addObserver(pref, observer, holdWeak);
        this.pref_observers.push([branch, pref, observer]);
    },

    getStringPref: function(branch, prefName) {
        return branch.getStringPref(prefName);
    },

    setStringPref: function(branch, prefName, value) {
        return branch.setStringPref(prefName, value);
    },

    getViews: function(byName) {
        var views = {};
        var obj = {};
        var children = this.viewsBranch.getChildList("", obj);
        var regex = /^(\d+)\./;
        for (var child of children) {
            var match = regex.exec(child);
            var num = match[1];
            if (num in views) {
                continue;
            }
            var view = {
                display_name: this.getStringPref(this.viewsBranch,
                                                 num + ".display_name"),
                menu_enabled: this.viewsBranch.getBoolPref(
                    num + ".menu_enabled"),
                arrows_enabled: this.viewsBranch.getBoolPref(
                    num + ".arrows_enabled")
            };
            var name = this.getStringPref(this.viewsBranch, num + ".name");
            // The All Folders view can't be completely disabled.
            if (name == "all") {
                view['menu_enabled'] = true;
            }
            if (byName) {
                view['number'] = num;
                views[name] = view;
            }
            else {
                view['name'] = name;
                views[num] = view;
            }
        }
        return views;
    },

    getViewDisplayName: function(treeView, commonName) {
        if (commonName in treeView._modeDisplayNames) {
            return treeView._modeDisplayNames[commonName];
        }
        var key = "folderPaneModeHeader_" + commonName;
        return treeView.messengerBundle.getString(key);
    },<commit_msg>Fix bug which prevents the add-on from working when it is first installed<commit_after>var fpvsPrefRoot = "extensions.FolderPaneSwitcher.";

fpvsUtils = {
    event_handlers: [],
    pref_observers: [],

    init: function() {
        this.prefService = Components
            .classes["@mozilla.org/preferences-service;1"]
            .getService(Components.interfaces.nsIPrefService);
        this.prefBranch = this.prefService.getBranch(fpvsPrefRoot);
        this.viewsBranch = this.prefService.getBranch(fpvsPrefRoot + "views.");
    },

    uninit: function() {
        for (var args of this.event_handlers) {
            args[0].removeEventListener(args[1], args[2], args[3]);
        }
        for (var args of this.pref_observers) {
            args[0].removeObserver(args[1], args[2]);
        }
    },

    addEventListener: function(target, type, listener, useCapture) {
        target.addEventListener(type, listener, useCapture);
        this.event_handlers.push([target, type, listener, useCapture]);
    },

    addObserver: function(branch, pref, observer, holdWeak) {
        branch.addObserver(pref, observer, holdWeak);
        this.pref_observers.push([branch, pref, observer]);
    },

    getStringPref: function(branch, prefName) {
        return branch.getStringPref(prefName);
    },

    setStringPref: function(branch, prefName, value) {
        return branch.setStringPref(prefName, value);
    },

    getViews: function(byName) {
        var views = {};
        var obj = {};
        var children = this.viewsBranch.getChildList("", obj);
        var regex = /^(\d+)\./;
        for (var child of children) {
            var match = regex.exec(child);
            var num = match[1];
            if (num in views) {
                continue;
            }
            try {
                var display_name = this.getStringPref(this.viewsBranch,
                                                      num + ".display_name");
            }
            catch (ex) {
                continue;
            }
            var view = {
                display_name: display_name,
                menu_enabled: this.viewsBranch.getBoolPref(
                    num + ".menu_enabled"),
                arrows_enabled: this.viewsBranch.getBoolPref(
                    num + ".arrows_enabled")
            };
            var name = this.getStringPref(this.viewsBranch, num + ".name");
            // The All Folders view can't be completely disabled.
            if (name == "all") {
                view['menu_enabled'] = true;
            }
            if (byName) {
                view['number'] = num;
                views[name] = view;
            }
            else {
                view['name'] = name;
                views[num] = view;
            }
        }
        return views;
    },

    getViewDisplayName: function(treeView, commonName) {
        if (commonName in treeView._modeDisplayNames) {
            return treeView._modeDisplayNames[commonName];
        }
        var key = "folderPaneModeHeader_" + commonName;
        return treeView.messengerBundle.getString(key);
    },
{'fraction_non_alphanumeric': 0.11536548980606663, 'fraction_numerical': 0.0029835902536051715, 'mean_word_length': 1.8235844642021526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5288799', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1620, 'n_words': 335}