1 /* See license.txt for terms of usage */ 2 3 define([ 4 "firebug/firebug", 5 "firebug/lib/events", 6 ], 7 function(Firebug, Events) { 8 9 // ********************************************************************************************* // 10 // Reusable code for modules that support editing 11 12 Firebug.EditorSelector = 13 { 14 // Override for each module 15 getEditorOptionKey: function() 16 { 17 return "cssEditMode"; 18 }, 19 20 editors: {}, 21 22 registerEditor: function(name, editor) 23 { 24 this.editors[name] = editor; 25 }, 26 27 unregisterEditor: function(name, editor) 28 { 29 delete this.editors[name]; 30 }, 31 32 getEditorByName: function(name) 33 { 34 return this.editors[name]; 35 }, 36 37 getEditorsNames: function() 38 { 39 var names = []; 40 for (var p in this.editors) 41 { 42 if (this.editors.hasOwnProperty(p)) 43 names.push(p); 44 } 45 return names; 46 }, 47 48 setCurrentEditorName: function(name) 49 { 50 this.currentEditorName = name; 51 Firebug.Options.set(this.getEditorOptionKey(), name); 52 }, 53 54 getCurrentEditorName: function() 55 { 56 if (!this.currentEditorName) 57 this.currentEditorName = Firebug.Options.get(this.getEditorOptionKey()); 58 59 return this.currentEditorName; 60 }, 61 62 getCurrentEditor: function() 63 { 64 return this.getEditorByName(this.getCurrentEditorName()); 65 }, 66 67 onEditMode: function(event, menuitem) 68 { 69 var mode = menuitem.getAttribute("mode"); 70 if (mode) 71 this.setCurrentEditorName(mode); 72 73 this.updateEditButton(); 74 Events.cancelEvent(event); 75 }, 76 77 updateEditButton: function() 78 { 79 // Update label and tooltip text of the edit button. 80 var mode = this.getCurrentEditorName(); 81 if (!mode) 82 return; 83 84 var menuitem = Firebug.chrome.$("menu_firebug_" + this.getEditorOptionKey() + mode); 85 var command = Firebug.chrome.$("cmd_firebug_toggle" + this.getEditorOptionKey()); 86 command.setAttribute("label", menuitem.label); 87 command.setAttribute("tooltiptext", menuitem.tooltipText); 88 }, 89 90 onOptionsShowing: function(popup) 91 { 92 var mode = this.getCurrentEditorName(); 93 if (!mode) 94 return; 95 96 for (var child = popup.firstChild; child; child = child.nextSibling) 97 { 98 if (child.localName == "menuitem") 99 { 100 if (child.id == "menu_firebug_" + this.getEditorOptionKey()+mode) 101 child.setAttribute("checked", true); 102 else 103 child.removeAttribute("checked"); 104 } 105 } 106 }, 107 }; 108 109 // ********************************************************************************************* // 110 // Registration 111 112 return Firebug.EditorSelector; 113 114 // ********************************************************************************************* // 115 }); 116