<commit_before>/* See license.txt for terms of usage */

// ************************************************************************************************
// Constants

const prefs = fbXPCOMUtils.CCSV("@mozilla.org/preferences-service;1", "nsIPrefBranch");
const names = ["label", "executable", "cmdline", "image"];

// ************************************************************************************************
// Globals

var gEditorManager =
{
    _tree : null,
    _data : [],
    _removeButton : null,
    _changeButton : null,
    _moveUpButton : null,

    init: function()
    {
        var args = window.arguments[0];
        this._FBL = args.FBL;
        this._prefName = args.prefName;

        (this._removeButton = document.getElementById("removeEditor")).disabled = true;
        (this._changeButton = document.getElementById("changeEditor")).disabled = true;
        (this._moveUpButton = document.getElementById("moveUpEditor")).disabled = true;

        this._tree = document.getElementById("editorsList");

        this._treeView =
        {
            data: this._data,
            selection: null,

            get rowCount() { return this.data.length; },
            getCellText: function(row, column)
            {
                switch(column.id)
                {
                case "editorName":
                    return " "+this.data[row].label;
                case "editorExecutable":
                    return this.data[row].executable;
                case "editorParams":
                    return this.data[row].cmdline;
                }
                return "";
            },
            setTree: function(treebox){ this.treebox = treebox; },
            isContainer: function(row) { return false; },
            isContainerOpen: function(row) { return false; },
            isContainerEmpty: function(row) { return false; },
            isSeparator: function(row) { return false; },
            isSorted: function() { return false; },
            getLevel: function(row) { return 0; },
            getImageSrc: function(row,column) { return column.id=="editorName" ? this.data[row].image : null; },
            getRowProperties: function(row,props) {},
            getCellProperties: function(row,column,props) {},
            getColumnProperties: function(colid,column,props) {}
        };

        this._load();
        this._tree.view = this._treeView;

        this.internationalizeUI(document);
    },

    uninit: function()
    {
    },

    internationalizeUI: function(doc)
    {
        var elements = doc.getElementsByClassName("fbInternational");
        var attributes = ["title", "label", "value"];
        for (var i=0; i<elements.length; i++)
        {
            for(var j=0; j<attributes.length; j++)
            {
                if (elements[i].hasAttribute(attributes[j]))
                    this._FBL.internationalize(elements[i], attributes[j]);
            }
        }
    },

    onSelectionChanged: function()
    {
        var selection = this._tree.view.selection;
        this._removeButton.disabled = (selection.count != 1);
        this._changeButton.disabled = (selection.count != 1);
        this._moveUpButton.disabled = (selection.count != 1) || (selection.currentIndex == 0);
    },

    addEditorHandler: function()
    {
        var item = { label: "", executable: null, cmdline: "" };
        var result = {};
        var args = {
            item: item,
            FBL: this._FBL
        };
        openDialog("chrome://firebug/content/external/changeeditor.xul",  "_blank", "modal,centerscreen,resizable", args, result);
        if (result.saveChanges)
        {
            item.id = item.label.replace(/\W/g, "_");
            this._saveItem(item);

            this._loadItem(item);
            this._data.push(item);
            this._tree.view = this._treeView;

            var editors = [];
            try {
                editors = prefs.getCharPref(this._prefName).split(",");
                for( var i = 0; i < editors.length; ++i )
                {
                    if ( editors[i].replace(/^\s+|\s+$/,"") == "" )
                        editors.splice(i, 1);
                }
            }
            catch(exc)
            {
                this._FBL.ERROR(exc);
            }
            editors.push(item.id);
            prefs.setCharPref(this._prefName, editors.join(","));
        }
    },

    removeEditorHandler: function()
    {
        var selection = this._tree.view.selection;
        if (selection.count < 1)
            return;
        var item = this._data[selection.currentIndex];
        this._data.splice(selection.currentIndex, 1);
        this._tree.view = this._treeView;

        try {
            var editors = prefs.getCharPref(this._prefName).split(",");
            this._FBL.remove(editors, item.id);
            prefs.setCharPref(this._prefName, editors.join(","));
            prefs.deleteBranch(this._prefName+"."+item.id);
        }
        catch(exc)
        {
            this._FBL.ERROR(exc);
        }
    },

    changeEditorHandler: function()
    {
        var selection = this._tree.view.selection;
        if (selection.count != 1)
            return;
        var item = this._data[selection.currentIndex];
        var args = {
            item: item,
            FBL: this._FBL
        };
        var result = {};
        openDialog("chrome://firebug/content/external/changeeditor.xul",  "_blank", "modal,centerscreen", args, result);
        if (result.saveChanges)
        {
            this._saveItem(item);
        }
        this._loadItem(item);
        this._tree.view = this._treeView;
    },

    moveUpEditorHandler: function()
    {
        var selection = this._tree.view.selection;
        if (selection.count < 1)
            return;<commit_msg>[1.8 &1.7] Issue 4366: Remove and Change button are still active after deleting all external editors<commit_after>/* See license.txt for terms of usage */

// ************************************************************************************************
// Constants

const prefs = fbXPCOMUtils.CCSV("@mozilla.org/preferences-service;1", "nsIPrefBranch");
const names = ["label", "executable", "cmdline", "image"];

// ************************************************************************************************
// Globals

var gEditorManager =
{
    _tree : null,
    _data : [],
    _removeButton : null,
    _changeButton : null,
    _moveUpButton : null,

    init: function()
    {
        var args = window.arguments[0];
        this._FBL = args.FBL;
        this._prefName = args.prefName;

        (this._removeButton = document.getElementById("removeEditor")).disabled = true;
        (this._changeButton = document.getElementById("changeEditor")).disabled = true;
        (this._moveUpButton = document.getElementById("moveUpEditor")).disabled = true;

        this._tree = document.getElementById("editorsList");

        this._treeView =
        {
            data: this._data,
            selection: null,

            get rowCount() { return this.data.length; },
            getCellText: function(row, column)
            {
                switch(column.id)
                {
                case "editorName":
                    return " "+this.data[row].label;
                case "editorExecutable":
                    return this.data[row].executable;
                case "editorParams":
                    return this.data[row].cmdline;
                }
                return "";
            },
            setTree: function(treebox){ this.treebox = treebox; },
            isContainer: function(row) { return false; },
            isContainerOpen: function(row) { return false; },
            isContainerEmpty: function(row) { return false; },
            isSeparator: function(row) { return false; },
            isSorted: function() { return false; },
            getLevel: function(row) { return 0; },
            getImageSrc: function(row,column) { return column.id=="editorName" ? this.data[row].image : null; },
            getRowProperties: function(row,props) {},
            getCellProperties: function(row,column,props) {},
            getColumnProperties: function(colid,column,props) {}
        };

        this._load();
        this._tree.view = this._treeView;

        this.internationalizeUI(document);
    },

    uninit: function()
    {
    },

    internationalizeUI: function(doc)
    {
        var elements = doc.getElementsByClassName("fbInternational");
        var attributes = ["title", "label", "value"];
        for (var i=0; i<elements.length; i++)
        {
            for(var j=0; j<attributes.length; j++)
            {
                if (elements[i].hasAttribute(attributes[j]))
                    this._FBL.internationalize(elements[i], attributes[j]);
            }
        }
    },

    onSelectionChanged: function()
    {
        var selection = this._tree.view.selection, disabled = (selection.count != 1);
        this._removeButton.disabled = disabled;
        this._changeButton.disabled = disabled;
        this._moveUpButton.disabled = disabled || (selection.currentIndex == 0);
    },

    addEditorHandler: function()
    {
        var item = { label: "", executable: null, cmdline: "" };
        var result = {};
        var args = {
            item: item,
            FBL: this._FBL
        };
        openDialog("chrome://firebug/content/external/changeeditor.xul",  "_blank", "modal,centerscreen,resizable", args, result);
        if (result.saveChanges)
        {
            item.id = item.label.replace(/\W/g, "_");
            this._saveItem(item);

            this._loadItem(item);
            this._data.push(item);
            this._tree.view = this._treeView;

            var editors = [];
            try {
                editors = prefs.getCharPref(this._prefName).split(",");
                for( var i = 0; i < editors.length; ++i )
                {
                    if ( editors[i].replace(/^\s+|\s+$/,"") == "" )
                        editors.splice(i, 1);
                }
            }
            catch(exc)
            {
                this._FBL.ERROR(exc);
            }
            editors.push(item.id);
            prefs.setCharPref(this._prefName, editors.join(","));
        }
    },

    removeEditorHandler: function()
    {
        var selection = this._tree.view.selection;
        if (selection.count < 1)
            return;
        var item = this._data[selection.currentIndex];
        this._data.splice(selection.currentIndex, 1);
        this._tree.view = this._treeView;

        try {
            var editors = prefs.getCharPref(this._prefName).split(",");
            this._FBL.remove(editors, item.id);
            prefs.setCharPref(this._prefName, editors.join(","));
            prefs.deleteBranch(this._prefName+"."+item.id);
        }
        catch(exc)
        {
            this._FBL.ERROR(exc);
        }
        // update disabled state of buttons
        if (this._data.length == 0)
            selection.clearSelection();
    },

    changeEditorHandler: function()
    {
        var selection = this._tree.view.selection;
        if (selection.count != 1)
            return;
        var item = this._data[selection.currentIndex];
        var args = {
            item: item,
            FBL: this._FBL
        };
        var result = {};
        openDialog("chrome://firebug/content/external/changeeditor.xul",  "_blank", "modal,centerscreen", args, result);
        if (result.saveChanges)
        {
            this._saveItem(item);
        }
        this._loadItem(item);
        this._tree.view = this._treeView;
    },

    moveUpEditorHandler: function()
    {
        var selection = this._tree.view.selection;
        if (selection.count < 1)
            return;
{'fraction_non_alphanumeric': 0.16035822913146333, 'fraction_numerical': 0.0031260561000337954, 'mean_word_length': 1.8737557659626123, 'pattern_counts': {'":': 6, '<': 13, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7477944', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3140, 'n_words': 581}