1 | var bitsSubstitutionTreeOverlay = { |
---|
2 | _init : false, |
---|
3 | _pref : {}, |
---|
4 | _app_version : 0, |
---|
5 | _changed : false, |
---|
6 | |
---|
7 | get POS_DEFAULT() { return this.POS_TREE_RIGHT; }, |
---|
8 | get POS_TREE_BOTTOM() { return "tree_bottom"; }, |
---|
9 | get POS_TREE_RIGHT() { return "tree_right"; }, |
---|
10 | |
---|
11 | get BUTTON() { |
---|
12 | try{ |
---|
13 | return bitsMarkingCollection._contentWindow.document.getElementById("mcToolbarItemTreeButton"); |
---|
14 | }catch(e){ return undefined; } |
---|
15 | }, |
---|
16 | |
---|
17 | get TREE() { return document.getElementById("bitsSubstitutionTree"); }, |
---|
18 | get ADD() { return document.getElementById("bitsSubstitutionTreeAdd"); }, |
---|
19 | get EDIT() { return document.getElementById("bitsSubstitutionTreeEdit"); }, |
---|
20 | get DEL() { return document.getElementById("bitsSubstitutionTreeDel"); }, |
---|
21 | |
---|
22 | get STRING() { return window.opener.top.document.getElementById("MarkingCollectionOverlayString"); }, |
---|
23 | get DataSource() { return window.opener.top.bitsObjectMng.DataSource; }, |
---|
24 | get Common() { return window.opener.top.bitsObjectMng.Common; }, |
---|
25 | get XPath() { return window.opener.top.bitsObjectMng.XPath; }, |
---|
26 | get Database() { return window.opener.top.bitsObjectMng.Database; }, |
---|
27 | get XML() { return window.opener.top.bitsObjectMng.XML; }, |
---|
28 | get gBrowser() { return window.opener.top.bitsObjectMng.getBrowser();}, |
---|
29 | |
---|
30 | |
---|
31 | get bitsSubstitutionTree(){ return window.opener.top.bitsSubstitutionTree; }, |
---|
32 | get xmldoc() { return this.bitsSubstitutionTree.xmldoc; }, |
---|
33 | get confirmRemovingFor() { return this.bitsSubstitutionTree._confirmRemovingFor; }, |
---|
34 | |
---|
35 | ///////////////////////////////////////////////////////////////////// |
---|
36 | init : function(aEvent){ |
---|
37 | if(!this._init){ |
---|
38 | this.rebuild(); |
---|
39 | this._init = true; |
---|
40 | } |
---|
41 | }, |
---|
42 | |
---|
43 | ///////////////////////////////////////////////////////////////////// |
---|
44 | disp : function(aEvent){ |
---|
45 | this.treeDispChange(); |
---|
46 | this.rebuild(); |
---|
47 | this.SPLITTER.setAttribute("hidden",!this._pref.disp); |
---|
48 | this.VBOX.setAttribute("hidden",!this._pref.disp); |
---|
49 | }, |
---|
50 | |
---|
51 | ///////////////////////////////////////////////////////////////////// |
---|
52 | done : function(aEvent){ |
---|
53 | if(this._changed) this.bitsSubstitutionTree.xmlflash(); |
---|
54 | }, |
---|
55 | |
---|
56 | ///////////////////////////////////////////////////////////////////// |
---|
57 | // TREE 衚瀺å¶åŸ¡é¢é£ |
---|
58 | ///////////////////////////////////////////////////////////////////// |
---|
59 | get rowCount(){ |
---|
60 | var results = this.XPath.evaluateArray('//item',this.xmldoc); |
---|
61 | return results.length; |
---|
62 | }, |
---|
63 | getCellText : function(row,column){ |
---|
64 | var results = this.XPath.evaluateArray('//item',this.xmldoc); |
---|
65 | if(!results[row]) return null; |
---|
66 | if(column.id == "bitsSubstitutionTreeSrcCol"){ |
---|
67 | return results[row].getAttribute("src"); |
---|
68 | }else if(column.id == "bitsSubstitutionTreeAltCol"){ |
---|
69 | return results[row].getAttribute("alt"); |
---|
70 | }else{ |
---|
71 | return null; |
---|
72 | } |
---|
73 | }, |
---|
74 | setTree: function(treebox){ this.treebox = treebox; }, |
---|
75 | isContainer: function(row){ return false; }, |
---|
76 | isSeparator: function(row){ return false; }, |
---|
77 | isSorted: function(){ return true; }, |
---|
78 | getLevel: function(row){ return 0; }, |
---|
79 | getImageSrc: function(row,column){ return null; }, |
---|
80 | getRowProperties: function(row,prop){ |
---|
81 | }, |
---|
82 | getCellProperties: function(row, column, prop) { |
---|
83 | }, |
---|
84 | getColumnProperties: function(column, element, prop) {}, |
---|
85 | cycleHeader : function(col){}, |
---|
86 | setCellText : function(row,column,text){}, |
---|
87 | getParentIndex: function(idx) { return -1; }, |
---|
88 | canDrop : function(index, orient){ |
---|
89 | return false; |
---|
90 | }, |
---|
91 | onDrop : function(row, orient){}, |
---|
92 | drop : function(row, orient){}, |
---|
93 | |
---|
94 | |
---|
95 | ///////////////////////////////////////////////////////////////////// |
---|
96 | rebuild : function(){ |
---|
97 | this.TREE.view = bitsSubstitutionTreeOverlay; |
---|
98 | }, |
---|
99 | |
---|
100 | ///////////////////////////////////////////////////////////////////// |
---|
101 | // TREE ã€ãã³ãé¢é£ |
---|
102 | ///////////////////////////////////////////////////////////////////// |
---|
103 | onClick : function(aEvent){ |
---|
104 | if(this.TREE.view.selection.count == 0) return false; |
---|
105 | var idxList = this.getSelection(); |
---|
106 | if(this.validateMultipleSelection(idxList) == false) return false; |
---|
107 | this.EDIT.removeAttribute("disabled"); |
---|
108 | this.DEL.removeAttribute("disabled"); |
---|
109 | }, |
---|
110 | |
---|
111 | onDblClick : function(aEvent){ |
---|
112 | this.onEdit(aEvent); |
---|
113 | }, |
---|
114 | |
---|
115 | onAdd : function(aEvent){ |
---|
116 | var src = {value: ""}; |
---|
117 | var alt = {value: ""}; |
---|
118 | var check = {value: false}; |
---|
119 | var result = false; |
---|
120 | do{ |
---|
121 | result = this.Common.PROMPT.prompt(window, this.STRING.getString("MSG_SUBSTITUTION_ADD"), this.STRING.getString("MSG_SUBSTITUTION_INPUT_FILENAME"), src, null, check); |
---|
122 | if(!result) return; |
---|
123 | src.value = src.value.replace(/^\s*/mg,"").replace(/\s*$/mg,""); |
---|
124 | }while(src.value == ""); |
---|
125 | var src_results = this.XPath.evaluateArray('//item[@src="'+src.value+'"]',this.xmldoc); |
---|
126 | if(src_results.length){ |
---|
127 | alert(this.STRING.getString("ALERT_REGISTERED")); |
---|
128 | return; |
---|
129 | } |
---|
130 | result = this.Common.PROMPT.prompt(window, this.STRING.getString("MSG_SUBSTITUTION_ADD"), this.STRING.getString("MSG_SUBSTITUTION_FILENAME") + ":["+src.value+"]\n" + this.STRING.getString("MSG_SUBSTITUTION_INPUT_SUBSTITUTE_TEXT"), alt, null, check); |
---|
131 | if(!result) return; |
---|
132 | var node = this.xmldoc.createElement("item"); |
---|
133 | node.setAttribute("src",src.value); |
---|
134 | node.setAttribute("alt",alt.value); |
---|
135 | this.xmldoc.documentElement.appendChild(node); |
---|
136 | this.rebuild(); |
---|
137 | this._changed = true; |
---|
138 | }, |
---|
139 | |
---|
140 | onEdit : function(aEvent){ |
---|
141 | if(this.TREE.view.selection.count == 0) return false; |
---|
142 | var idxList = this.getSelection(); |
---|
143 | if(this.validateMultipleSelection(idxList) == false) return false; |
---|
144 | var src = {value: ""}; |
---|
145 | var alt = {value: ""}; |
---|
146 | var check = {value: false}; |
---|
147 | var result = false; |
---|
148 | var results = this.XPath.evaluateArray('//item',this.xmldoc); |
---|
149 | var i; |
---|
150 | for(i=0;i<idxList.length;i++){ |
---|
151 | var row = idxList[i]; |
---|
152 | if(!results[row]) continue; |
---|
153 | var org_src = results[row].getAttribute("src"); |
---|
154 | src.value = org_src; |
---|
155 | alt.value = results[row].getAttribute("alt"); |
---|
156 | do{ |
---|
157 | result = this.Common.PROMPT.prompt(window, this.STRING.getString("MSG_SUBSTITUTION_EDIT"), this.STRING.getString("MSG_SUBSTITUTION_INPUT_FILENAME"), src, null, check); |
---|
158 | if(!result) return; |
---|
159 | src.value = src.value.replace(/^\s*/mg,"").replace(/\s*$/mg,""); |
---|
160 | if(src.value != org_src){ |
---|
161 | var src_results = this.XPath.evaluateArray('//item[@src="'+src.value+'"]',this.xmldoc); |
---|
162 | if(src_results.length){ |
---|
163 | alert(this.STRING.getString("ALERT_REGISTERED")); |
---|
164 | return; |
---|
165 | } |
---|
166 | } |
---|
167 | }while(src.value == ""); |
---|
168 | result = this.Common.PROMPT.prompt(window, this.STRING.getString("MSG_SUBSTITUTION_EDIT"), this.STRING.getString("MSG_SUBSTITUTION_FILENAME") + ":["+src.value+"]\n" + this.STRING.getString("MSG_SUBSTITUTION_INPUT_SUBSTITUTE_TEXT"), alt, null, check); |
---|
169 | if(!result) return; |
---|
170 | results[row].setAttribute("src",src.value); |
---|
171 | results[row].setAttribute("alt",alt.value); |
---|
172 | } |
---|
173 | this._changed = true; |
---|
174 | }, |
---|
175 | |
---|
176 | onDel : function(aEvent){ |
---|
177 | if(this.TREE.view.selection.count == 0) return false; |
---|
178 | var idxList = this.getSelection(); |
---|
179 | if(this.validateMultipleSelection(idxList) == false) return false; |
---|
180 | if(!this.confirmRemovingFor()) return false; |
---|
181 | var results = this.XPath.evaluateArray('//item',this.xmldoc); |
---|
182 | var i; |
---|
183 | for(i=idxList.length-1;i>=0;i--){ |
---|
184 | var row = idxList[i]; |
---|
185 | if(!results[row]) continue; |
---|
186 | this.xmldoc.documentElement.removeChild(results[row]); |
---|
187 | } |
---|
188 | this.rebuild(); |
---|
189 | this._changed = true; |
---|
190 | }, |
---|
191 | |
---|
192 | ///////////////////////////////////////////////////////////////////// |
---|
193 | getSelection : function(){ |
---|
194 | var ret = []; |
---|
195 | var rc; |
---|
196 | var i; |
---|
197 | for(rc=0;rc<this.TREE.view.selection.getRangeCount();rc++){ |
---|
198 | var start = {}, end = {}; |
---|
199 | this.TREE.view.selection.getRangeAt(rc, start, end); |
---|
200 | for(i=start.value;i<= end.value;i++){ |
---|
201 | if(!this.TREE.view.selection.isSelected(i)) continue; |
---|
202 | ret.push(i); |
---|
203 | } |
---|
204 | } |
---|
205 | return ret; |
---|
206 | }, |
---|
207 | |
---|
208 | validateMultipleSelection : function(aIdxList){ |
---|
209 | if(aIdxList.length != this.TREE.view.selection.count){ |
---|
210 | alert(this.STRING.getString("ERROR_MULTIPLE_SELECTION")); |
---|
211 | return false; |
---|
212 | } |
---|
213 | return true; |
---|
214 | }, |
---|
215 | |
---|
216 | ///////////////////////////////////////////////////////////////////// |
---|
217 | _dump : function(aString){ |
---|
218 | if(nsPreferences.getBoolPref("wiredmarker.debug", false)) window.dump(this.Common.convertFormUnicode(aString,"Shift_jis")+"\n"); |
---|
219 | }, |
---|
220 | }; |
---|