Bug 1186138 - Part 2: Ensure the property remains disabled after ESC editing a disabled property r=bgrins

This commit is contained in:
Gabriel Luong 2015-07-27 21:40:20 -07:00
parent 3a948d934e
commit 0e974ce785

View File

@ -3301,25 +3301,36 @@ TextPropertyEditor.prototype = {
* True if the change should be applied. * True if the change should be applied.
*/ */
_onNameDone: function(aValue, aCommit) { _onNameDone: function(aValue, aCommit) {
if (aCommit && !this.ruleEditor.isEditing) { if ((!aCommit && this.ruleEditor.isEditing) ||
this.committed.name == aValue) {
// Disable the property if the property was originally disabled.
if (!this.prop.enabled) {
this.rule.setPropertyEnabled(this.prop, this.prop.enabled);
}
return;
}
// Unlike the value editor, if a name is empty the entire property // Unlike the value editor, if a name is empty the entire property
// should always be removed. // should always be removed.
if (aValue.trim() === "") { if (aValue.trim() === "") {
this.remove(); this.remove();
} else { return;
}
// Adding multiple rules inside of name field overwrites the current // Adding multiple rules inside of name field overwrites the current
// property with the first, then adds any more onto the property list. // property with the first, then adds any more onto the property list.
let properties = parseDeclarations(aValue); let properties = parseDeclarations(aValue);
if (properties.length) { if (properties.length) {
this.prop.setName(properties[0].name); this.prop.setName(properties[0].name);
this.committed.name = this.prop.name;
if (properties.length > 1) { if (properties.length > 1) {
this.prop.setValue(properties[0].value, properties[0].priority); this.prop.setValue(properties[0].value, properties[0].priority);
this.ruleEditor.addProperties(properties.slice(1), this.prop); this.ruleEditor.addProperties(properties.slice(1), this.prop);
} }
} }
}
}
}, },
/** /**
@ -3349,35 +3360,33 @@ TextPropertyEditor.prototype = {
* @param {bool} aCommit * @param {bool} aCommit
* True if the change should be applied. * True if the change should be applied.
*/ */
_onValueDone: function(aValue, aCommit) { _onValueDone: function(aValue="", aCommit) {
if (!aCommit && !this.ruleEditor.isEditing) { let parsedProperties = this._getValueAndExtraProperties(aValue);
let val = parseSingleValue(parsedProperties.firstValue);
let isValueUnchanged =
!parsedProperties.propertiesToAdd.length &&
this.committed.value == val.value &&
this.committed.priority == val.priority;
if ((!aCommit && !this.ruleEditor.isEditing) || isValueUnchanged) {
// A new property should be removed when escape is pressed. // A new property should be removed when escape is pressed.
if (this.removeOnRevert) { if (this.removeOnRevert) {
this.remove(); this.remove();
} else { } else {
// update the editor back to committed value // Disable the property if the property was originally disabled.
this.update(); this.rule.setPropertyEnabled(this.prop, this.prop.enabled);
// undo the preview in content style
this.ruleEditor.rule.previewPropertyValue(this.prop,
this.prop.value, this.prop.priority);
} }
return; return;
} }
let {propertiesToAdd, firstValue} =
this._getValueAndExtraProperties(aValue);
// First, set this property value (common case, only modified a property) // First, set this property value (common case, only modified a property)
let val = parseSingleValue(firstValue);
this.prop.setValue(val.value, val.priority); this.prop.setValue(val.value, val.priority);
this.removeOnRevert = false; this.removeOnRevert = false;
this.committed.value = this.prop.value; this.committed.value = this.prop.value;
this.committed.priority = this.prop.priority; this.committed.priority = this.prop.priority;
// If needed, add any new properties after this.prop. // If needed, add any new properties after this.prop.
this.ruleEditor.addProperties(propertiesToAdd, this.prop); this.ruleEditor.addProperties(parsedProperties.propertiesToAdd, this.prop);
// If the name or value is not actively being edited, and the value is // If the name or value is not actively being edited, and the value is
// empty, then remove the whole property. // empty, then remove the whole property.