~jetsaredim/firefox-extensions/firebug.upstream

« back to all changes in this revision

Viewing changes to content/firebug/.svn/text-base/editors.js.svn-base

  • Committer: Jared Greenwald
  • Date: 2008-04-22 18:20:42 UTC
  • Revision ID: jgreenwa@4lom-20080422182042-90kbumm805h2hjt6
 * new upstream source (v1.2~b21+svn572)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* See license.txt for terms of usage */
2
 
 
3
 
// ************************************************************************************************
4
 
// Constants
5
 
 
6
 
const prefs = XPCOMUtils.CCSV("@mozilla.org/preferences-service;1", "nsIPrefBranch");
7
 
const names = ["label", "executable", "cmdline", "image"];
8
 
 
9
 
// ************************************************************************************************
10
 
// Globals
11
 
 
12
 
var gEditorManager =
13
 
{
14
 
    _tree : null,
15
 
    _data : [],
16
 
    _removeButton : null,
17
 
    _changeButton : null,
18
 
 
19
 
    init: function()
20
 
    {
21
 
        var args = window.arguments[0];
22
 
        this._FBL = args.FBL;
23
 
        this._prefName = args.prefName;
24
 
 
25
 
        (this._removeButton = document.getElementById("removeEditor")).disabled = true;
26
 
        (this._changeButton = document.getElementById("changeEditor")).disabled = true;
27
 
 
28
 
        this._tree = document.getElementById("editorsList");
29
 
 
30
 
        this._treeView =
31
 
        {
32
 
            data: this._data,
33
 
            selection: null,
34
 
 
35
 
            get rowCount() { return this.data.length; },
36
 
            getCellText: function(row, column)
37
 
            {
38
 
                switch(column.id)
39
 
                {
40
 
                case "editorName":
41
 
                    return " "+this.data[row].label;
42
 
                case "editorExecutable":
43
 
                    return this.data[row].executable;
44
 
                case "editorParams":
45
 
                    return this.data[row].cmdline;
46
 
                }
47
 
                return "";
48
 
            },
49
 
            setTree: function(treebox){ this.treebox = treebox; },
50
 
            isContainer: function(row) { return false; },
51
 
            isContainerOpen: function(row) { return false; },
52
 
            isContainerEmpty: function(row) { return false; },
53
 
            isSeparator: function(row) { return false; },
54
 
            isSorted: function() { return false; },
55
 
            getLevel: function(row) { return 0; },
56
 
            getImageSrc: function(row,column) { return column.id=="editorName" ? this.data[row].image : null; },
57
 
            getRowProperties: function(row,props) {},
58
 
            getCellProperties: function(row,column,props) {},
59
 
            getColumnProperties: function(colid,column,props) {}
60
 
        };
61
 
 
62
 
        this._load();
63
 
        this._tree.view = this._treeView;
64
 
    },
65
 
 
66
 
    uninit: function()
67
 
    {
68
 
    },
69
 
 
70
 
    onSelectionChanged: function()
71
 
    {
72
 
        var selection = this._tree.view.selection;
73
 
        this._removeButton.disabled = (selection.count != 1);
74
 
        this._changeButton.disabled = (selection.count != 1);
75
 
    },
76
 
 
77
 
    addEditorHandler: function()
78
 
    {
79
 
        var item = { label: "", executable: null, cmdline: "" };
80
 
        var result = {};
81
 
        openDialog("chrome://firebug/content/changeeditor.xul",  "_blank", "modal,centerscreen", item, result);
82
 
        if (result.saveChanges)
83
 
        {
84
 
            item.id = item.label.replace(/\W/g, "_");
85
 
            this._saveItem(item);
86
 
 
87
 
            this._loadItem(item);
88
 
            this._data.push(item);
89
 
            this._tree.view = this._treeView;
90
 
 
91
 
            var editors = [];
92
 
            try {
93
 
                editors = prefs.getCharPref(this._prefName).split(",");
94
 
                for( var i = 0; i < editors.length; ++i )
95
 
                {
96
 
                    if ( editors[i].replace(/^\s+|\s+$/,"") == "" )
97
 
                        editors.splice(i, 1);
98
 
                }
99
 
            }
100
 
            catch(exc)
101
 
            {
102
 
                this._FBL.ERROR(exc);
103
 
            }
104
 
            editors.push(item.id);
105
 
            prefs.setCharPref(this._prefName, editors.join(","));
106
 
        }
107
 
    },
108
 
 
109
 
    removeEditorHandler: function()
110
 
    {
111
 
        var selection = this._tree.view.selection;
112
 
        if (selection.count < 1)
113
 
            return;
114
 
        var item = this._data[selection.currentIndex];
115
 
        this._data.splice(selection.currentIndex, 1);
116
 
        this._tree.view = this._treeView;
117
 
 
118
 
        try {
119
 
            var editors = prefs.getCharPref(this._prefName).split(",");
120
 
            this._FBL.remove(editors, item.id);
121
 
            prefs.setCharPref(this._prefName, editors.join(","));
122
 
            prefs.deleteBranch(this._prefName+"."+item.id);
123
 
        }
124
 
        catch(exc)
125
 
        {
126
 
            this._FBL.ERROR(exc);
127
 
        }
128
 
    },
129
 
 
130
 
    changeEditorHandler: function()
131
 
    {
132
 
        var selection = this._tree.view.selection;
133
 
        if (selection.count != 1)
134
 
            return;
135
 
        var item = this._data[selection.currentIndex];
136
 
        var result = {};
137
 
        openDialog("chrome://firebug/content/changeeditor.xul",  "_blank", "modal,centerscreen", item, result);
138
 
        if (result.saveChanges)
139
 
        {
140
 
            this._saveItem(item);
141
 
        }
142
 
        this._loadItem(item);
143
 
        this._tree.view = this._treeView;
144
 
    },
145
 
 
146
 
    _loadItem: function(item)
147
 
    {
148
 
        const prefName = this._prefName;
149
 
        for( var i = 0; i < names.length; ++i )
150
 
        {
151
 
            try {
152
 
                item[names[i]] = prefs.getCharPref(prefName+"."+item.id+"."+names[i]);
153
 
            }
154
 
            catch(exc)
155
 
            {}
156
 
        }
157
 
        if (!item.image)
158
 
            item.image = this._FBL.getIconURLForFile(item.executable);
159
 
    },
160
 
 
161
 
    _saveItem: function(item)
162
 
    {
163
 
        if ( item.image && item.image == this._FBL.getIconURLForFile(item.executable) )
164
 
            item.image = null;
165
 
 
166
 
        const prefName = this._prefName;
167
 
        for( var i = 0; i < names.length; ++i )
168
 
        {
169
 
            try {
170
 
                var value = item[names[i]];
171
 
                if ( value )
172
 
                    prefs.setCharPref(prefName+"."+item.id+"."+names[i], value);
173
 
                else
174
 
                    prefs.clearUserPref(prefName+"."+item.id+"."+names[i]);
175
 
            }
176
 
            catch(exc)
177
 
            {}
178
 
        }
179
 
    },
180
 
 
181
 
    _load: function()
182
 
    {
183
 
        try {
184
 
            var list = prefs.getCharPref(this._prefName).split(",");
185
 
            for (var i = 0; i < list.length; ++i)
186
 
            {
187
 
                var editorId = list[i].replace(/\s/g, "_");
188
 
                if ( !editorId )
189
 
                    continue;
190
 
                var item = { id: editorId };
191
 
                this._data.push(item);
192
 
                this._loadItem(item);
193
 
            }
194
 
        }
195
 
        catch(exc)
196
 
        {
197
 
            this._FBL.ERROR(exc);
198
 
        }
199
 
    }
200
 
 
201
 
};
202
 
 
203
 
// ************************************************************************************************