1 | var mcDatabasePropService = { |
---|
2 | |
---|
3 | get STRING() { return document.getElementById("mcDBPropString"); }, |
---|
4 | get TITLE() { return document.getElementById("mcDBPropTitleTextbox"); }, |
---|
5 | get COMMENT() { return document.getElementById("mcDBPropCommentTextbox"); }, |
---|
6 | get USE() { return document.getElementById("mcDBPropUseCheckbox"); }, |
---|
7 | get CONTEXTMENU() { return document.getElementById("mcDBPropContextmenuCheckbox"); }, |
---|
8 | get DEFAULT() { return document.getElementById("mcDBPropDefaultCheckbox"); }, |
---|
9 | get ACCEPTBTN() { return document.getElementById("mcDBPropWindow").getButton("accept"); }, |
---|
10 | get DB_PATH() { return document.getElementById("mcDBPropDBPath"); }, |
---|
11 | get DB_DATE() { return document.getElementById("mcDBPropDBDate"); }, |
---|
12 | get DB_SIZE() { return document.getElementById("mcDBPropDBSize"); }, |
---|
13 | get DB_GROUP() { return document.getElementById("mcDBPropDatabaseGroup"); }, |
---|
14 | |
---|
15 | get IO() { return Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService); }, |
---|
16 | |
---|
17 | item : null, |
---|
18 | dbFile : null, |
---|
19 | |
---|
20 | init : function(){ |
---|
21 | try { |
---|
22 | this.item = window.arguments[0]; |
---|
23 | }catch(ex){} |
---|
24 | if(!this.item) return; |
---|
25 | |
---|
26 | if(this.item.title) this.TITLE.value = this.item.title; |
---|
27 | try{this.TITLE.editor.transactionManager.clear();}catch(ex2){} |
---|
28 | if(this.item.comment) this.COMMENT.value = this.item.comment; |
---|
29 | try{this.COMMENT.editor.transactionManager.clear();}catch(ex2){} |
---|
30 | |
---|
31 | if(this.item.use != undefined) this.USE.checked = this.item.use; |
---|
32 | if(this.item.contextmenu != undefined) this.CONTEXTMENU.checked = this.item.contextmenu; |
---|
33 | if(this.item.default != undefined) this.DEFAULT.checked = this.item.default; |
---|
34 | this.DEFAULT.disabled = this.DEFAULT.checked; |
---|
35 | |
---|
36 | this.dbFile = null; |
---|
37 | this.dispDBFileInfo(); |
---|
38 | |
---|
39 | document.title = this.TITLE.value; |
---|
40 | }, |
---|
41 | |
---|
42 | done : function(){ |
---|
43 | }, |
---|
44 | |
---|
45 | commandDefault : function(e){ |
---|
46 | if(this.DEFAULT.checked){ |
---|
47 | this.USE.checked = this.DEFAULT.checked; |
---|
48 | }else if(!this.item.default && !this.item.use){ |
---|
49 | this.USE.checked = this.DEFAULT.checked; |
---|
50 | } |
---|
51 | }, |
---|
52 | |
---|
53 | commandUse : function(e){ |
---|
54 | this.CONTEXTMENU.checked = this.USE.checked; |
---|
55 | }, |
---|
56 | |
---|
57 | accept : function(){ |
---|
58 | var changed = false; |
---|
59 | var newVals = { |
---|
60 | title : this.TITLE.value != "" ? this.TITLE.value : null, |
---|
61 | comment : this.COMMENT.value != "" ? this.COMMENT.value : null, |
---|
62 | use : this.USE.checked, |
---|
63 | contextmenu : this.CONTEXTMENU.checked, |
---|
64 | default : this.DEFAULT.checked, |
---|
65 | }; |
---|
66 | if(newVals["title"]){ |
---|
67 | newVals["title"] = newVals["title"].replace(/\t/mg," "); |
---|
68 | newVals["title"] = newVals["title"].replace(/[\cA\cB\cC\cD\cE\cF\cG\cH\cI\cJ\cK\cL\cM\cN\cO\cP\cQ\cR\cS\cT\cU\cV\cW\cX\cY\cZ\c[\c\\\c]\c^\c_]/mg," "); |
---|
69 | newVals["title"] = newVals["title"].replace(/[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f]/mg," "); |
---|
70 | newVals["title"] = newVals["title"].replace(/[\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]/mg," "); |
---|
71 | newVals["title"] = newVals["title"].replace(/[\x7f]/mg," "); |
---|
72 | }else{ |
---|
73 | // window.acceptDialog(); |
---|
74 | // return; |
---|
75 | } |
---|
76 | if(newVals["comment"]){ |
---|
77 | newVals["comment"] = newVals["comment"].replace(/\t/mg," "); |
---|
78 | newVals["comment"] = newVals["comment"].replace(/[\r\n]/mg," __BR__ "); |
---|
79 | newVals["comment"] = newVals["comment"].replace(/[\cA\cB\cC\cD\cE\cF\cG\cH\cI\cJ\cK\cL\cM\cN\cO\cP\cQ\cR\cS\cT\cU\cV\cW\cX\cY\cZ\c[\c\\\c]\c^\c_]/mg," "); |
---|
80 | newVals["comment"] = newVals["comment"].replace(/[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f]/mg," "); |
---|
81 | newVals["comment"] = newVals["comment"].replace(/[\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]/mg," "); |
---|
82 | newVals["comment"] = newVals["comment"].replace(/[\x7f]/mg," "); |
---|
83 | newVals["comment"] = newVals["comment"].replace(/ __BR__ /mg,"\n"); |
---|
84 | } |
---|
85 | var props; |
---|
86 | for(props in newVals){ |
---|
87 | |
---|
88 | _dump(props+"=["+this.item[props]+"]["+newVals[props]+"]"); |
---|
89 | |
---|
90 | if(this.item[props] == newVals[props]) continue; |
---|
91 | this.item[props] = newVals[props]; |
---|
92 | changed = true; |
---|
93 | } |
---|
94 | if(window.arguments[0]) window.arguments[0].accept = true; |
---|
95 | return true; |
---|
96 | }, |
---|
97 | |
---|
98 | cancel : function(){ |
---|
99 | if(window.arguments[0]) window.arguments[0].accept = false; |
---|
100 | }, |
---|
101 | |
---|
102 | dialogaccept : function(){ |
---|
103 | try{this.TITLE.editor.transactionManager.undoTransaction();}catch(ex2){this.Common.alert(ex2)} |
---|
104 | this.TITLE.focus(); |
---|
105 | return false; |
---|
106 | }, |
---|
107 | |
---|
108 | input : function(){ |
---|
109 | if(this.TITLE.value == ""){ |
---|
110 | this.ACCEPTBTN.setAttribute("disabled","true"); |
---|
111 | }else{ |
---|
112 | this.ACCEPTBTN.removeAttribute("disabled"); |
---|
113 | } |
---|
114 | }, |
---|
115 | |
---|
116 | dispDBFileInfo : function(){ |
---|
117 | if(this.item.file){ |
---|
118 | var aURI = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI); |
---|
119 | aURI.spec = this.item.file; |
---|
120 | if(aURI.schemeIs("file")){ |
---|
121 | try { |
---|
122 | var fileHandler = this.IO.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler); |
---|
123 | this.dbFile = fileHandler.getFileFromURLSpec(this.item.file); |
---|
124 | }catch(ex){ |
---|
125 | _dump("init():ex="+ex); |
---|
126 | this.dbFile = null; |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | _dump("dispDBFileInfo():this.dbFile="+this.dbFile); |
---|
132 | if(this.dbFile && this.dbFile.exists()){ |
---|
133 | this.DB_GROUP.removeAttribute("hidden"); |
---|
134 | this.DB_PATH.value = this.dbFile.path; |
---|
135 | this.DB_DATE.value = (new Date(this.dbFile.lastModifiedTime)).toLocaleString(); |
---|
136 | this.DB_SIZE.value = this.formatFileSize(this.dbFile.fileSize); |
---|
137 | }else{ |
---|
138 | this.DB_GROUP.hidden = true; |
---|
139 | this.DB_PATH.value = ""; |
---|
140 | this.DB_DATE.value = ""; |
---|
141 | this.DB_SIZE.value = ""; |
---|
142 | } |
---|
143 | _dump("dispDBFileInfo():DB_DATE="+this.DB_DATE.value); |
---|
144 | }, |
---|
145 | |
---|
146 | formatFileSize : function(aBytes){ |
---|
147 | if(aBytes > 1000 * 1000){ |
---|
148 | return this.divideBy100( Math.round( aBytes / 1024 / 1024 * 100 ) ) + " MB"; |
---|
149 | }else if( aBytes == 0 ){ |
---|
150 | return "0 KB"; |
---|
151 | }else{ |
---|
152 | var kbytes = Math.round( aBytes / 1024 ); |
---|
153 | return (kbytes == 0 ? 1 : kbytes) + " KB"; |
---|
154 | } |
---|
155 | }, |
---|
156 | |
---|
157 | divideBy100 : function(aInt){ |
---|
158 | if(aInt % 100 == 0){ |
---|
159 | return aInt / 100 + ".00"; |
---|
160 | }else if(aInt % 10 == 0){ |
---|
161 | return aInt / 100 + "0"; |
---|
162 | }else{ |
---|
163 | return aInt / 100; |
---|
164 | } |
---|
165 | }, |
---|
166 | }; |
---|
167 | |
---|
168 | |
---|
169 | function _dump(aString){ |
---|
170 | if(nsPreferences.getBoolPref("wiredmarker.debug", false)) window.dump(aString+"\n"); |
---|
171 | } |
---|
172 | |
---|