~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/inspector/resources/content/viewers/dom/columnsDialog.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Netscape Public License
 
5
 * Version 1.1 (the "License"); you may not use this file except in
 
6
 * compliance with the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/NPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is mozilla.org code.
 
15
 *
 
16
 * The Initial Developer of the Original Code is 
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 2001
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Joe Hewitt <hewitt@netscape.com> (original author)
 
23
 *
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the NPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the NPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
/***************************************************************
 
40
* ColumnsDialog --------------------------------------------
 
41
*  Dialog box for editing the columns in the DOM Viewer tree.
 
42
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
43
* REQUIRED IMPORTS:
 
44
****************************************************************/
 
45
 
 
46
//////////// global variables /////////////////////
 
47
 
 
48
var dialog;
 
49
 
 
50
var gColumnTitles = [
 
51
  "nodeName",
 
52
  "nodeValue",
 
53
  "nodeType",
 
54
  "prefix",
 
55
  "localName",
 
56
  "namespaceURI"
 
57
];
 
58
 
 
59
//////////// global constants ////////////////////
 
60
 
 
61
//////////////////////////////////////////////////
 
62
 
 
63
window.addEventListener("load", ColumnsDialog_initialize, false);
 
64
window.addEventListener("unload", ColumnsDialog_destroy, false);
 
65
 
 
66
function ColumnsDialog_initialize()
 
67
{
 
68
  dialog = new ColumnsDialog();
 
69
  dialog.initialize();
 
70
}
 
71
 
 
72
function ColumnsDialog_destroy()
 
73
{
 
74
  dialog.destroy();
 
75
}
 
76
 
 
77
////////////////////////////////////////////////////////////////////////////
 
78
//// class ColumnsDialog
 
79
 
 
80
function ColumnsDialog()
 
81
{
 
82
  this.mViewer = window.arguments[0];
 
83
  this.mColBoxHash = {};
 
84
}
 
85
 
 
86
ColumnsDialog.prototype = 
 
87
{
 
88
  mBox: null,
 
89
  mDraggingBox: null,
 
90
  
 
91
  get box() { return this.mBox },
 
92
  
 
93
  initialize: function()
 
94
  {
 
95
    // bug 56270 - dragSession.sourceDocument is null --
 
96
    // causes me to code this very temporary, very nasty hack
 
97
    // to make sure I get notified when a column is dropped
 
98
    opener.viewer.mDOMTree.onClientDrop = ColumnsDialogDragDropOut;
 
99
    
 
100
    this.buildContents();
 
101
    
 
102
    // notify the dom viewer that we've opened
 
103
    this.mViewer.onColumnsDialogReady(this);
 
104
  },
 
105
  
 
106
  destroy: function()
 
107
  {
 
108
    // notify the dom viewer that we're going away
 
109
    this.mViewer.onColumnsDialogClose(this);
 
110
  },
 
111
  
 
112
  buildContents: function()
 
113
  {
 
114
    var box = document.getElementById("bxColumns");
 
115
    this.mBox = box;
 
116
    
 
117
    // create the special attribute box
 
118
    var item = this.createAttrItem();
 
119
    box.appendChild(item);
 
120
    
 
121
    // add all boxes except those that are already
 
122
    // in the viewer
 
123
    for (var i = 0; i < gColumnTitles.length; ++i)
 
124
      if (!this.mViewer.hasColumn(gColumnTitles[i])) {
 
125
        this.addItem(gColumnTitles[i]);
 
126
      }  
 
127
  },
 
128
  
 
129
  addItem: function(aValue)
 
130
  {
 
131
    if (!aValue || aValue.charAt(0) == "@") 
 
132
      return null;
 
133
      
 
134
    item = this.createItem(aValue);
 
135
    this.mColBoxHash[aValue] = item;
 
136
    if (item) {
 
137
      this.mBox.appendChild(item);
 
138
      window.sizeToContent();
 
139
    }
 
140
  },
 
141
  
 
142
  removeItem: function(aValue)
 
143
  {
 
144
    if (!aValue || aValue.charAt(0) == "@")
 
145
      return null;
 
146
      
 
147
    var colBox = this.mColBoxHash[aValue];
 
148
    if (!colBox._isAttrCol) {
 
149
      this.mBox.removeChild(colBox);
 
150
      window.sizeToContent();
 
151
    }
 
152
  },
 
153
  
 
154
  createItem: function(aValue)
 
155
  {
 
156
    var text = document.createElementNS(kXULNSURI, "text");
 
157
    text._ColValue = aValue;
 
158
    text._isColBox = true;
 
159
    text._isAttrCol = false;
 
160
    text.setAttribute("class", "column-selector");
 
161
    text.setAttribute("value", aValue);
 
162
 
 
163
    return text;
 
164
  },
 
165
  
 
166
  createAttrItem: function(aValue)
 
167
  {
 
168
    var box = document.createElementNS(kXULNSURI, "box");
 
169
    box._isColBox = true;
 
170
    box._isAttrCol = true;
 
171
    box.setAttribute("class", "column-selector");
 
172
    box.setAttribute("autostretch", "never");
 
173
 
 
174
    var text = document.createElementNS(kXULNSURI, "text");
 
175
    text.setAttribute("value", "Attr");
 
176
    box.appendChild(text);
 
177
 
 
178
    var txf = document.createElementNS(kXULNSURI, "textbox");
 
179
    txf.setAttribute("class", "attr-column-selector");
 
180
    txf.setAttribute("flex", 1);
 
181
    box.appendChild(txf);
 
182
 
 
183
    return box;
 
184
  },
 
185
    
 
186
  ////////////////////////////////////////////////////////////////////////////
 
187
  //// Drag and Drop
 
188
 
 
189
  onDragGesture: function(aEvent)
 
190
  {
 
191
    var box = this.getBoxTarget(aEvent.target);
 
192
    this.setDraggingBox(box);
 
193
    if (!box) return false;
 
194
    
 
195
    var column = this.getColumnValue(box);
 
196
    if (!column) return false;
 
197
    
 
198
    DNDUtils.invokeSession(aEvent.target, ["TreeBuilder/column-add"], [column]);
 
199
    
 
200
    return false;
 
201
  },
 
202
  
 
203
  onDragDropOut: function()
 
204
  {
 
205
    var box = document.getElementById("bxColumns");
 
206
    var value =  this.mDraggingBox._ColValue;
 
207
    this.setDraggingBox(null);
 
208
    this.removeItem(value);
 
209
  },
 
210
  
 
211
  onDragDropIn: function(aEvent)
 
212
  {
 
213
    var data = DNDUtils.getData("TreeBuilder/column-remove", 0);
 
214
    var string = XPCU.QI(data, "nsISupportsString");
 
215
    this.addItem(string.data);
 
216
  },
 
217
 
 
218
  setDraggingBox: function(aBox)
 
219
  {
 
220
    if (this.mDraggingBox) {
 
221
      this.mDraggingBox.removeAttribute("col-dragging");
 
222
    }
 
223
 
 
224
    this.mDraggingBox = aBox;
 
225
 
 
226
    if (aBox)
 
227
      aBox.setAttribute("col-dragging", "true");
 
228
  },
 
229
  
 
230
  getBoxTarget: function(aNode)
 
231
  {
 
232
    var node = aNode;
 
233
    while (node && !node._isColBox)
 
234
      node = node.parentNode;
 
235
    return node;
 
236
  },
 
237
  
 
238
  getColumnValue: function(aColBox)
 
239
  {
 
240
    if (aColBox._isAttrCol) {
 
241
      var txf = aColBox.getElementsByTagName("textbox")[0];
 
242
      return "@" + txf.value;
 
243
    } else {
 
244
      return aColBox._ColValue;
 
245
    }
 
246
  }
 
247
 
 
248
};
 
249
 
 
250
function ColumnsDialogDragDropOut()
 
251
{
 
252
  dialog.onDragDropOut();
 
253
}