source: DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/shortcutProperty.js @ 2711

Last change on this file since 2711 was 2711, checked in by olof, 11 years ago

moved to trunk

File size: 5.6 KB
Line 
1var mcSCPropService = {
2        _opener : null,
3
4        get Common()     { return this._opener.top.bitsObjectMng.Common;     },
5
6        get STRING()     { return document.getElementById("mcSCPropString"); },
7        get DIALOG()     { return document.getElementById("mcSCPropDialog"); },
8        get TITLE()      { return document.getElementById("mcSCPropTitle"); },
9        get SHIFT()      { return document.getElementById("mcSCPropShift"); },
10        get ALT()        { return document.getElementById("mcSCPropAlt"); },
11        get ACCEL()      { return document.getElementById("mcSCPropAccel"); },
12        get KEY()        { return document.getElementById("mcSCPropKey"); },
13        get MOD()        { return document.getElementById("mcSCPropModifiers"); },
14
15        property : null,
16
17        init : function(){
18                var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
19                this._opener = wm.getMostRecentWindow("navigator:browser");
20                var osString = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS;
21                if(osString == "Darwin"){
22                        this.ALT.setAttribute('label','Option');
23                        this.ACCEL.setAttribute('label','Command');
24                }
25                try {
26                        this.property = window.arguments[0];
27                }catch(e){}
28                if(!this.property) return;
29                this.TITLE.value = this.property.title;
30                try{this.TITLE.editor.transactionManager.clear();}catch(ex2){}
31                if(!this.property.removed) this.TITLE.setAttribute("readonly","true");
32                this.KEY.value = this.property.key;
33                try{this.KEY.editor.transactionManager.clear();}catch(ex2){}
34                this.SHIFT.checked = this.property.shift;
35                this.ALT.checked = this.property.alt;
36                this.ACCEL.checked = this.property.accel;
37                var acceltext = [];
38                if(this.ACCEL.checked){
39                        if(osString == "Darwin"){
40                                acceltext.push('Command');
41                        }else{
42                                acceltext.push('Ctrl');
43                        }
44                }
45                if(this.SHIFT.checked) acceltext.push('Shift');
46                if(this.ALT.checked){
47                        if(osString == "Darwin"){
48                                acceltext.push('Option');
49                        }else{
50                                acceltext.push('Alt');
51                        }
52                }
53                this.MOD.value = acceltext.join("+")+" +";
54                document.title = this.property.title;
55                return;
56        },
57
58        accept : function(){
59                var changed = false;
60                var newVals = {
61                        title : this.TITLE.value,
62                        shift : this.SHIFT.checked,
63                        alt   : this.ALT.checked,
64                        accel : this.ACCEL.checked,
65                        key   : this.KEY.value
66                };
67                newVals.title = newVals.title.replace(/\t/mg,"        ");
68                newVals.title = this.Common.exceptCode(newVals.title);
69                newVals.title = newVals.title.replace(/[\r\n]/mg, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
70                newVals.key = newVals.key.replace(/\t/mg,"        ");
71                newVals.key = this.Common.exceptCode(newVals.key);
72                newVals.key = newVals.key.replace(/[\r\n]/mg, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
73                var key;
74                for(key in newVals){
75                        if(window.arguments[0][key] == newVals[key]) continue;
76                        window.arguments[0][key] = newVals[key];
77                        changed = true;
78                }
79                if(window.arguments[0]) window.arguments[0].accept = changed;
80                return true;
81        },
82
83        cancel : function(){
84                if(window.arguments[0]) window.arguments[0].accept = false;
85        },
86
87        inputTitle : function(aEvent){
88                var title = this.TITLE.value;
89                title = title.replace(/\t/mg,"        ");
90                title = this.Common.exceptCode(title);
91                title = title.replace(/[\r\n]/mg, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
92                var key = this.KEY.value;
93                key = key.replace(/\t/mg,"        ");
94                key = this.Common.exceptCode(key);
95                key = key.replace(/[\r\n]/mg, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
96                if(title.length == 0 || key.length == 0){
97                        this.DIALOG.setAttribute("buttondisabledaccept","true");
98                }else if(
99                        title              != this.property.title ||
100                        key                != this.property.key ||
101                        this.SHIFT.checked != this.property.shift ||
102                        this.ALT.checked   != this.property.alt ||
103                        this.ACCEL.checked != this.property.accel
104                ){
105                        this.DIALOG.removeAttribute("buttondisabledaccept");
106                }else{
107                        this.DIALOG.setAttribute("buttondisabledaccept","true");
108                }
109        },
110
111        inputKey : function(aEvent){
112                var title = this.TITLE.value;
113                title = title.replace(/\t/mg,"        ");
114                title = this.Common.exceptCode(title);
115                title = title.replace(/[\r\n]/mg, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
116                var osString = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS;
117                var sc = {
118                        key     : ""+String.fromCharCode(aEvent.charCode).toUpperCase(),
119                        shift   : aEvent.shiftKey,
120                        alt     : aEvent.altKey,
121                        accel   : (osString == "Darwin" ? aEvent.metaKey: aEvent.ctrlKey)
122                };
123                if(title.length == 0 || sc.key.length == 0){
124                        this.DIALOG.setAttribute("buttondisabledaccept","true");
125                }else if(
126                        title              != this.property.title ||
127                        sc.key             != this.property.key ||
128                        this.SHIFT.checked != this.property.shift ||
129                        this.ALT.checked   != this.property.alt ||
130                        this.ACCEL.checked != this.property.accel
131                ){
132                        this.DIALOG.removeAttribute("buttondisabledaccept");
133                }else{
134                        this.DIALOG.setAttribute("buttondisabledaccept","true");
135                }
136                this.KEY.value = '';
137                this.MOD.value = '';
138                if(!sc.key || !(sc.shift||sc.alt||sc.accel)) return;
139                this.SHIFT.checked = sc.shift;
140                this.ALT.checked = sc.alt;
141                this.ACCEL.checked = sc.accel;
142                var acceltext = [];
143                var sccnt=0;
144                if(sc.accel){
145                        if(osString == "Darwin"){
146                                acceltext.push('Command');
147                        }else{
148                                acceltext.push('Ctrl');
149                        }
150                }
151                if(sc.shift) acceltext.push('Shift');
152                if(sc.alt){
153                        if(osString == "Darwin"){
154                                acceltext.push('Option');
155                        }else{
156                                acceltext.push('Alt');
157                        }
158                }
159                this.MOD.value = acceltext.join("+")+" +";
160                this.KEY.value = sc.key;
161                this.KEY.focus();
162
163        },
164
165        _dump : function(aString){
166                this._opener.top.bitsMarkingCollection._dump(aString);
167        }
168};
169
170
171
Note: See TracBrowser for help on using the repository browser.