1 | var bitsSearchAcross = { |
---|
2 | _id : 'searchacross', |
---|
3 | _timer : null, |
---|
4 | _value : "", |
---|
5 | |
---|
6 | get id(){return this._id;}, |
---|
7 | get value(){return this._value;}, |
---|
8 | |
---|
9 | get STRING() { return document.getElementById("MarkingCollectionOverlayString"); }, |
---|
10 | |
---|
11 | get DataSource() { return window.top.bitsObjectMng.DataSource; }, |
---|
12 | get Common() { return window.top.bitsObjectMng.Common; }, |
---|
13 | get Database() { return window.top.bitsObjectMng.Database; }, |
---|
14 | get XML() { return window.top.bitsObjectMng.XML; }, |
---|
15 | get XPath() { return window.top.bitsObjectMng.XPath; }, |
---|
16 | get gBrowser() { return window.top.bitsObjectMng.getBrowser();}, |
---|
17 | |
---|
18 | get TEXTBOX() { return document.getElementById("bitsSearchAcrossTextbox"); }, |
---|
19 | |
---|
20 | get SIDEBAR_TREETABBOX(){ return document.getElementById("mcTreeTabbox"); }, |
---|
21 | get SIDEBAR_TREETABPANEL(){ return document.getElementById("mcTreeTabCustom"); }, |
---|
22 | |
---|
23 | ///////////////////////////////////////////////////////////////////// |
---|
24 | init : function(){ |
---|
25 | var info = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo); |
---|
26 | this.app_version = parseInt(info.version); |
---|
27 | }, |
---|
28 | |
---|
29 | ///////////////////////////////////////////////////////////////////// |
---|
30 | done : function(){}, |
---|
31 | |
---|
32 | ///////////////////////////////////////////////////////////////////// |
---|
33 | rebuild : function(){ |
---|
34 | if(!mcTreeHandler.TREE.view.selection.isSelected(mcTreeHandler.TREE.currentIndex)) mcTreeHandler.TREE.view.selection.select(mcTreeHandler.TREE.currentIndex); |
---|
35 | mcTreeHandler.TREE.focus(); |
---|
36 | mcTreeHandler.TREE.treeBoxObject.ensureRowIsVisible(mcTreeHandler.TREE.currentIndex); |
---|
37 | mcPropertyView.dispProperty(); |
---|
38 | if(mcItemView.isChecked){ |
---|
39 | mcItemView.onTreeClick(); |
---|
40 | }else{ |
---|
41 | var objects; |
---|
42 | var viewmode = mcTreeViewModeService.viewmode; |
---|
43 | var findRegExp = new RegExp(this.value,"img"); |
---|
44 | if(viewmode == "all"){ |
---|
45 | objects = this.Database.findObject(findRegExp); |
---|
46 | }else{ |
---|
47 | var doc_url = window.top.bitsAutocacheService.convertCacheURLToOriginalURL(this.Common.getURLStringFromDocument(this.gBrowser.contentDocument)); |
---|
48 | objects = this.Database.findObject(findRegExp,undefined,{doc_url:doc_url}); |
---|
49 | } |
---|
50 | if(objects){ |
---|
51 | for(var i=0;i<objects.length;i++){ |
---|
52 | var about = this.DataSource.ABOUT_ITEM+this.Database._seqIdentify(objects[i].oid); |
---|
53 | this.addItem(this.Database.makeObjectToItem(objects[i],about),false); |
---|
54 | } |
---|
55 | this.DataSource.flush(); |
---|
56 | mcTreeHandler.TREE.builder.rebuild(); |
---|
57 | } |
---|
58 | } |
---|
59 | }, |
---|
60 | |
---|
61 | ///////////////////////////////////////////////////////////////////// |
---|
62 | search : function(aString){ |
---|
63 | if(aString == undefined && this._value=="") return; |
---|
64 | var currentIndex = mcTreeHandler.TREE.currentIndex; |
---|
65 | var isSelected = (currentIndex>=0?mcTreeHandler.TREE.view.selection.isSelected(currentIndex):false); |
---|
66 | var curRes = mcTreeHandler.resource; |
---|
67 | var object = null; |
---|
68 | if(aString != undefined){ |
---|
69 | this._value = (new String(aString)).replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/\s{2,}/g," ").replace(/^\s*/g,"").replace(/\s*$/g,""); |
---|
70 | this.removeItem(); |
---|
71 | }else if(!this.removeItem()){ |
---|
72 | return; |
---|
73 | } |
---|
74 | if(this.value.length > 0){ |
---|
75 | var newRes = this.createSearchFolder(this.value); |
---|
76 | mcTreeHandler.TREE.builder.rebuild(); |
---|
77 | var newIdx = mcTreeHandler.TREE.builderView.getIndexOfResource(newRes); |
---|
78 | if(aString != undefined){ |
---|
79 | this.SIDEBAR_TREETABBOX.selectedTab = this.SIDEBAR_TREETABPANEL; |
---|
80 | mcTreeHandler.TREE.currentIndex = newIdx; |
---|
81 | if(newIdx>=0){ |
---|
82 | this.rebuild(); |
---|
83 | mcTreeHandler.TREE.currentIndex = newIdx; |
---|
84 | if(!mcTreeHandler.TREE.view.selection.isSelected(mcTreeHandler.TREE.currentIndex)) mcTreeHandler.TREE.view.selection.select(mcTreeHandler.TREE.currentIndex); |
---|
85 | } |
---|
86 | }else if(mcItemView.isChecked){ |
---|
87 | if(curRes) currentIndex = mcTreeHandler.TREE.builderView.getIndexOfResource(curRes); |
---|
88 | if((currentIndex<0 || currentIndex == newIdx) && newIdx>=0){ |
---|
89 | mcTreeHandler.TREE.currentIndex = newIdx; |
---|
90 | this.rebuild(); |
---|
91 | }else if(currentIndex>=0){ |
---|
92 | mcTreeHandler.TREE.currentIndex = currentIndex; |
---|
93 | if(!mcTreeHandler.TREE.view.selection.isSelected(mcTreeHandler.TREE.currentIndex)) mcTreeHandler.TREE.view.selection.select(mcTreeHandler.TREE.currentIndex); |
---|
94 | mcTreeHandler.TREE.treeBoxObject.ensureRowIsVisible(mcTreeHandler.TREE.currentIndex); |
---|
95 | var curIdx=mcItemView.TREE.currentIndex; |
---|
96 | mcItemView.onTreeClick(); |
---|
97 | var object = null; |
---|
98 | if(curIdx>=0){ |
---|
99 | mcItemView.TREE.currentIndex = curIdx; |
---|
100 | if(!mcItemView.TREE.view.selection.isSelected(mcItemView.TREE.currentIndex)) mcItemView.TREE.view.selection.select(mcItemView.TREE.currentIndex); |
---|
101 | mcItemView.TREE.treeBoxObject.ensureRowIsVisible(mcItemView.TREE.currentIndex); |
---|
102 | object = mcItemView.object; |
---|
103 | }else{ |
---|
104 | object = mcTreeHandler.object; |
---|
105 | } |
---|
106 | } |
---|
107 | }else{ |
---|
108 | this.rebuild(); |
---|
109 | currentIndex = -1; |
---|
110 | if(curRes) currentIndex = mcTreeHandler.TREE.builderView.getIndexOfResource(curRes); |
---|
111 | mcTreeHandler.TREE.currentIndex = currentIndex; |
---|
112 | if(mcTreeHandler.TREE.currentIndex>=0){ |
---|
113 | if(!mcTreeHandler.TREE.view.selection.isSelected(mcTreeHandler.TREE.currentIndex)) mcTreeHandler.TREE.view.selection.select(mcTreeHandler.TREE.currentIndex); |
---|
114 | mcTreeHandler.TREE.treeBoxObject.ensureRowIsVisible(mcTreeHandler.TREE.currentIndex); |
---|
115 | object = mcTreeHandler.object; |
---|
116 | } |
---|
117 | } |
---|
118 | }else{ |
---|
119 | mcTreeHandler.TREE.builder.rebuild(); |
---|
120 | currentIndex = -1; |
---|
121 | if(curRes) currentIndex = mcTreeHandler.TREE.builderView.getIndexOfResource(curRes); |
---|
122 | mcTreeHandler.TREE.currentIndex = currentIndex; |
---|
123 | var object = null; |
---|
124 | if(currentIndex>=0){ |
---|
125 | if(isSelected && !mcTreeHandler.TREE.view.selection.isSelected(mcTreeHandler.TREE.currentIndex)) mcTreeHandler.TREE.view.selection.select(mcTreeHandler.TREE.currentIndex); |
---|
126 | mcTreeHandler.TREE.treeBoxObject.ensureRowIsVisible(mcTreeHandler.TREE.currentIndex); |
---|
127 | if(mcItemView.isChecked){ |
---|
128 | var curIdx=mcItemView.TREE.currentIndex; |
---|
129 | mcItemView.onTreeClick(); |
---|
130 | if(curIdx>=0){ |
---|
131 | mcItemView.TREE.currentIndex = curIdx; |
---|
132 | if(!mcItemView.TREE.view.selection.isSelected(mcItemView.TREE.currentIndex)) mcItemView.TREE.view.selection.select(mcItemView.TREE.currentIndex); |
---|
133 | mcItemView.TREE.treeBoxObject.ensureRowIsVisible(mcItemView.TREE.currentIndex); |
---|
134 | object = mcItemView.object; |
---|
135 | }else{ |
---|
136 | object = mcTreeHandler.object; |
---|
137 | } |
---|
138 | }else{ |
---|
139 | object = mcTreeHandler.object; |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | if(object){ |
---|
144 | mcPropertyView.dispProperty(object); |
---|
145 | }else{ |
---|
146 | mcPropertyView.dispProperty(); |
---|
147 | } |
---|
148 | }, |
---|
149 | |
---|
150 | ///////////////////////////////////////////////////////////////////// |
---|
151 | createSearchFolder : function(aString){ |
---|
152 | var newItem = this.Common.newItem(this.id); |
---|
153 | newItem.title = "Search ["+aString+"]"; |
---|
154 | newItem.type = "folder"; |
---|
155 | newItem.editmode = "false"; |
---|
156 | var newRes = this.addItem(newItem); |
---|
157 | var idx = mcTreeHandler.TREE.builderView.getIndexOfResource(newRes); |
---|
158 | if(idx>=0 && !mcTreeHandler.TREE.view.isContainerOpen(idx)) mcTreeHandler.TREE.view.toggleOpenState(idx); |
---|
159 | return newRes; |
---|
160 | }, |
---|
161 | |
---|
162 | ///////////////////////////////////////////////////////////////////// |
---|
163 | getAbout : function(){ |
---|
164 | return this.DataSource.ABOUT_ITEM + this.id; |
---|
165 | }, |
---|
166 | |
---|
167 | ///////////////////////////////////////////////////////////////////// |
---|
168 | getResource : function(){ |
---|
169 | return this.Common.RDF.GetResource(this.getAbout()); |
---|
170 | }, |
---|
171 | |
---|
172 | ///////////////////////////////////////////////////////////////////// |
---|
173 | getIndex : function(){ |
---|
174 | return mcTreeHandler.TREE.builderView.getIndexOfResource(this.getResource()); |
---|
175 | }, |
---|
176 | |
---|
177 | ///////////////////////////////////////////////////////////////////// |
---|
178 | removeItem : function(){ |
---|
179 | var idx = -1; |
---|
180 | var curRes = this.getResource(); |
---|
181 | if(curRes) idx = mcTreeHandler.TREE.builderView.getIndexOfResource(curRes); |
---|
182 | if(idx<0) return false; |
---|
183 | try{ |
---|
184 | var names = this.DataSource.data.ArcLabelsOut(curRes); |
---|
185 | while(names.hasMoreElements()){ |
---|
186 | try{ |
---|
187 | var name = names.getNext().QueryInterface(Components.interfaces.nsIRDFResource); |
---|
188 | var value = this.DataSource.data.GetTarget(curRes, name, true); |
---|
189 | this.DataSource.data.Unassert(curRes, name, value); |
---|
190 | }catch(e){} |
---|
191 | } |
---|
192 | }catch(e){} |
---|
193 | var cont = this.DataSource.getContainer(this.DataSource.ABOUT_ROOT, false); |
---|
194 | cont.RemoveElement(curRes,true); |
---|
195 | this.DataSource.flush(); |
---|
196 | return true; |
---|
197 | }, |
---|
198 | |
---|
199 | ///////////////////////////////////////////////////////////////////// |
---|
200 | addItem : function(aOMitem,aFlash){ |
---|
201 | if(aFlash == undefined) aFlash = true; |
---|
202 | for(var key in aOMitem){ |
---|
203 | if(typeof(aOMitem[key]) == "string") aOMitem[key] = this.DataSource.sanitize(aOMitem[key]); |
---|
204 | } |
---|
205 | try{ |
---|
206 | var cont; |
---|
207 | if(aOMitem.type == "folder"){ |
---|
208 | cont = this.DataSource.getContainer(this.DataSource.ABOUT_ROOT, false); |
---|
209 | }else{ |
---|
210 | cont = this.DataSource.getContainer(this.getAbout(), false); |
---|
211 | } |
---|
212 | var newRes; |
---|
213 | if(aOMitem.type == "folder"){ |
---|
214 | newRes = this.getResource(); |
---|
215 | }else{ |
---|
216 | if(aOMitem.about){ |
---|
217 | newRes = this.Common.RDF.GetResource(aOMitem.about); |
---|
218 | }else{ |
---|
219 | newRes = this.Common.RDF.GetResource(this.DataSource.ABOUT_ITEM + aOMitem.id); |
---|
220 | aOMitem.id = aOMitem.oid; |
---|
221 | delete aOMitem.oid; |
---|
222 | } |
---|
223 | } |
---|
224 | for(var key in aOMitem){ |
---|
225 | if(aOMitem[key] != undefined) this.DataSource.data.Assert(newRes, this.Common.RDF.GetResource(window.top.bitsObjectMng.NS_OBJECTMANAGEMENT + key), this.Common.RDF.GetLiteral(aOMitem[key]), true); |
---|
226 | } |
---|
227 | if(aOMitem.type == "folder"){ |
---|
228 | cont.InsertElementAt(newRes, 1, true); |
---|
229 | }else{ |
---|
230 | cont.AppendElement(newRes); |
---|
231 | } |
---|
232 | if(aOMitem.type == "folder") this.Common.RDFCU.MakeSeq(this.DataSource.data, this.Common.RDF.GetResource(newRes.Value)); |
---|
233 | if(aFlash) this.DataSource.flush(); |
---|
234 | return newRes; |
---|
235 | }catch(e){ |
---|
236 | this._dump("bitsSearchAcross.addItem():" + e); |
---|
237 | return null; |
---|
238 | } |
---|
239 | }, |
---|
240 | |
---|
241 | ///////////////////////////////////////////////////////////////////// |
---|
242 | onSearchButtonCommand : function(aEvent){ |
---|
243 | }, |
---|
244 | |
---|
245 | ///////////////////////////////////////////////////////////////////// |
---|
246 | onSearchKeyInput : function(aEvent){ |
---|
247 | var value = aEvent.target.value; |
---|
248 | if(this._timer) clearTimeout(this._timer); |
---|
249 | this._timer = setTimeout(function(){ bitsSearchAcross.search(value); },2000); |
---|
250 | }, |
---|
251 | |
---|
252 | ///////////////////////////////////////////////////////////////////// |
---|
253 | onSearchKeyPress : function(aEvent){ |
---|
254 | switch(aEvent.keyCode){ |
---|
255 | case aEvent.DOM_VK_RETURN : |
---|
256 | if(this._timer) clearTimeout(this._timer); |
---|
257 | this.search(aEvent.target.value); |
---|
258 | break; |
---|
259 | default: |
---|
260 | break; |
---|
261 | } |
---|
262 | }, |
---|
263 | |
---|
264 | ///////////////////////////////////////////////////////////////////// |
---|
265 | _dump : function(aString){ |
---|
266 | window.top.bitsMarkingCollection._dump(aString); |
---|
267 | }, |
---|
268 | }; |
---|