Bug 341894: Style rules view should allow for Undo and handle multiple/no selection better, patch by Jason Barnabe (np) <jason_barnabe@fastmail.fm>, r=timeless, sr=neil

This commit is contained in:
gavin%gavinsharp.com 2006-07-05 21:14:31 +00:00
parent 583bdf9236
commit 8501919dae
19 changed files with 262 additions and 138 deletions

View File

@ -138,18 +138,69 @@ StyleRulesViewer.prototype =
this.mPropsBoxObject.view = null;
},
isCommandEnabled: function(aCommand)
isCommandEnabled: function isCommandEnabled(aCommand)
{
if (aCommand == "cmdEditCopy") {
switch (aCommand) {
case "cmdEditCopy":
case "cmdEditDelete":
case "cmdTogglePriority":
return this.mPropsTree.view.selection.count > 0;
case "cmdEditInsert":
return this.mRuleTree.view.selection.count == 1;
case "cmdEditEdit":
return this.mPropsTree.view.selection.count == 1;
}
return false;
},
getCommand: function(aCommand)
getCommand: function getCommand(aCommand)
{
if (aCommand == "cmdEditCopy") {
switch (aCommand) {
case "cmdEditCopy":
return new cmdEditCopy(this.mPropsView.getSelectedRowObjects());
case "cmdEditDelete":
return new cmdEditDelete(this.getSelectedDec(),
this.mPropsView.getSelectedRowObjects());
case "cmdEditInsert":
var bundle = this.mPanel.panelset.stringBundle;
var msg = bundle.getString("styleRulePropertyName.message");
var title = bundle.getString("styleRuleNewProperty.title");
var property = { value: "" };
var value = { value: "" };
var dummy = { value: false };
if (!gPromptService.prompt(window, title, msg, property, null, dummy)) {
return null;
}
msg = bundle.getString("styleRulePropertyValue.message");
if (!gPromptService.prompt(window, title, msg, value, null, dummy)) {
return null;
}
return new cmdEditInsert(this.getSelectedDec(), property.value,
value.value, "");
case "cmdEditEdit":
var rule = this.getSelectedDec();
var property = this.getSelectedProp();
var priority = rule.getPropertyPriority(property);
var bundle = this.mPanel.panelset.stringBundle;
var msg = bundle.getString("styleRulePropertyValue.message");
var title = bundle.getString("styleRuleEditProperty.title");
var value = { value: rule.getPropertyValue(property) };
var dummy = { value: false };
if (!gPromptService.prompt(window, title, msg, value, null, dummy)) {
return null;
}
return new cmdEditEdit(rule, property, value.value, priority);
case "cmdTogglePriority":
return new cmdTogglePriority(this.getSelectedDec(),
this.mPropsView.getSelectedRowObjects());
}
return null;
},
@ -215,80 +266,6 @@ StyleRulesViewer.prototype =
}
},
//////// property contextual commands
cmdNewProperty: function()
{
var bundle = this.mPanel.panelset.stringBundle;
var msg = bundle.getString("styleRulePropertyName.message");
var title = bundle.getString("styleRuleNewProperty.title");
var propName = { value: "" };
var propValue = { value: "" };
var dummy = { value: false };
if (!gPromptService.prompt(window, title, msg, propName, null, dummy)) {
return;
}
msg = bundle.getString("styleRulePropertyValue.message");
if (!gPromptService.prompt(window, title, msg, propValue, null, dummy)) {
return;
}
this.mPropsBoxObject.beginUpdateBatch();
var style = this.getSelectedDec();
style.setProperty(propName.value, propValue.value, "");
this.mPropsBoxObject.endUpdateBatch();
},
cmdEditSelectedProperty: function()
{
var style = this.getSelectedDec();
var propname = this.getSelectedProp();
var propval = style.getPropertyValue(propname);
var priority = style.getPropertyPriority(propname);
var bundle = this.mPanel.panelset.stringBundle;
var msg = bundle.getString("styleRulePropertyValue.message");
var title = bundle.getString("styleRuleEditProperty.title");
var propValue = { value: propval };
var dummy = { value: false };
if (!gPromptService.prompt(window, title, msg, propValue, null, dummy)) {
return;
}
style.removeProperty(propname);
style.setProperty(propname, propValue.value, priority);
this.mPropsBoxObject.invalidate();
},
cmdDeleteSelectedProperty: function()
{
this.mPropsBoxObject.beginUpdateBatch();
var style = this.getSelectedDec();
var propname = this.getSelectedProp();
style.removeProperty(propname);
this.mPropsBoxObject.endUpdateBatch();
},
cmdToggleSelectedImportant: function()
{
var style = this.getSelectedDec();
var propname = this.getSelectedProp();
var propval = style.getPropertyValue(propname);
var priority = style.getPropertyPriority(propname);
priority = priority == "important" ? "" : "important";
style.removeProperty(propname);
style.setProperty(propname, propval, priority);
this.mPropsBoxObject.invalidate();
},
////////////////////////////////////////////////////////////////////////////
//// Uncategorized
@ -310,6 +287,7 @@ StyleRulesViewer.prototype =
var dec = this.getSelectedDec();
this.mPropsView = new StylePropsView(dec);
this.mPropsBoxObject.view = this.mPropsView;
viewer.pane.panelset.updateAllCommands();
},
onPropSelect: function()
@ -319,6 +297,15 @@ StyleRulesViewer.prototype =
onCreateRulePopup: function()
{
},
propOnPopupShowing: function propOnPopupShowing()
{
var commandset = document.getElementById("cmdsProps");
for (var i = 0; i < commandset.childNodes.length; i++) {
var command = commandset.childNodes[i];
command.setAttribute("disabled", !viewer.isCommandEnabled(command.id));
}
}
};
@ -488,3 +475,185 @@ function getRowObjectFromIndex(aIndex)
return new CSSDeclaration(prop, this.mDec.getPropertyValue(prop),
this.mDec.getPropertyPriority(prop));
}
/**
* Handles inserting a CSS declaration
* @param aRule the rule that will contain the new declaration
* @param aProperty the property of the new declaration
* @param aValue the value of the new declaration
* @param aPriority the priority of the new declaration ("important" or "")
*/
function cmdEditInsert(aRule, aProperty, aValue, aPriority)
{
this.rule = aRule;
this.property = aProperty;
this.value = aValue;
this.priority = aPriority;
}
cmdEditInsert.prototype =
{
// remove this line for bug 179621, Phase Three
txnType: "standard",
// required for nsITransaction
QueryInterface: txnQueryInterface,
merge: txnMerge,
isTransient: false,
doTransaction: function doTransaction()
{
viewer.mPropsBoxObject.beginUpdateBatch();
try {
this.rule.setProperty(this.property, this.value, this.priority);
} finally {
viewer.mPropsBoxObject.endUpdateBatch();
}
},
undoTransaction: function undoTransaction()
{
this.rule.removeProperty(this.property);
viewer.mPropsBoxObject.invalidate();
},
redoTransaction: function redoTransaction()
{
this.doTransaction();
}
}
/**
* Handles deleting CSS declarations
* @param aRule the rule containing the declarations
* @param aDeclarations an array of CSSDeclarations to delete
*/
function cmdEditDelete(aRule, aDeclarations)
{
this.rule = aRule;
this.declarations = aDeclarations;
}
cmdEditDelete.prototype =
{
// remove this line for bug 179621, Phase Three
txnType: "standard",
// required for nsITransaction
QueryInterface: txnQueryInterface,
merge: txnMerge,
isTransient: false,
doTransaction: function doTransaction()
{
viewer.mPropsBoxObject.beginUpdateBatch();
for (var i = 0; i < this.declarations.length; i++)
this.rule.removeProperty(this.declarations[i].property);
viewer.mPropsBoxObject.endUpdateBatch();
},
undoTransaction: function undoTransaction()
{
viewer.mPropsBoxObject.beginUpdateBatch();
for (var i = 0; i < this.declarations.length; i++)
this.rule.setProperty(this.declarations[i].property,
this.declarations[i].value,
this.declarations[i].important ? "important" : "");
},
redoTransaction: function redoTransaction()
{
this.doTransaction();
}
}
/**
* Handles editing CSS declarations
* @param aRule the rule containing the declaration
* @param aProperty the property to change
* @param aNewValue the new value for the property
* @param aNewValue the new priority for the property ("important" or "")
*/
function cmdEditEdit(aRule, aProperty, aNewValue, aNewPriority)
{
this.rule = aRule;
this.property = aProperty;
this.oldValue = aRule.getPropertyValue(aProperty);
this.newValue = aNewValue;
this.oldPriority = aRule.getPropertyPriority(aProperty);
this.newPriority = aNewPriority;
}
cmdEditEdit.prototype =
{
// remove this line for bug 179621, Phase Three
txnType: "standard",
// required for nsITransaction
QueryInterface: txnQueryInterface,
merge: txnMerge,
isTransient: false,
doTransaction: function doTransaction()
{
this.rule.setProperty(this.property, this.newValue,
this.newPriority);
viewer.mPropsBoxObject.invalidate();
},
undoTransaction: function undoTransaction()
{
this.rule.setProperty(this.property, this.oldValue,
this.oldPriority);
viewer.mPropsBoxObject.invalidate();
},
redoTransaction: function redoTransaction()
{
this.doTransaction();
}
}
/**
* Handles toggling CSS !important.
* @param aRule the rule containing the declarations
* @param aDeclarations an array of CSSDeclarations to toggle
*/
function cmdTogglePriority(aRule, aDeclarations)
{
this.rule = aRule;
this.declarations = aDeclarations;
}
cmdTogglePriority.prototype =
{
// remove this line for bug 179621, Phase Three
txnType: "standard",
// required for nsITransaction
QueryInterface: txnQueryInterface,
merge: txnMerge,
isTransient: false,
doTransaction: function doTransaction()
{
for (var i = 0; i < this.declarations.length; i++) {
//XXX bug 305761 means we can't make something not important, so instead
// we'll delete this property and make a new one at the proper priority.
// this method also sucks because the property gets moved to the bottom.
var property = this.declarations[i].property;
var value = this.declarations[i].value;
var newPriority = this.rule.getPropertyPriority(property) == "" ?
"important" : "";
this.rule.removeProperty(property);
this.rule.setProperty(property, value, newPriority);
}
viewer.mPropsBoxObject.invalidate();
},
undoTransaction: function undoTransaction()
{
this.doTransaction();
},
redoTransaction: function redoTransaction()
{
this.doTransaction();
}
}

View File

@ -26,6 +26,10 @@
<!--============================ COMMANDS ============================= -->
<commandset id="cmdsEditing"/>
<commandset id="cmdsProps">
<command id="cmdTogglePriority"
oncommand="viewer.pane.panelset.execCommand('cmdTogglePriority')"/>
</commandset>
<!--============================= POPUPS ============================== -->
@ -38,21 +42,23 @@
<menuitem label="&openSelectedFileInEditor.label;" oncommand="viewer.cmdOpenSelectedFileInEditor()"/>
</popup>
<popup id="ppStylePropsContext">
<popup id="ppStylePropsContext"
onpopupshowing="viewer.propOnPopupShowing(this)">
<menuitem id="mnEditCopy"/>
<menuseparator/>
<menuitem label="&newProperty.label;" oncommand="viewer.cmdNewProperty()"/>
<menuitem label="&editSelectedProperty.label;" oncommand="viewer.cmdEditSelectedProperty()"/>
<menuitem label="&deleteSelectedProperty.label;" oncommand="viewer.cmdDeleteSelectedProperty()"/>
<menuitem id="mnEditInsert"/>
<menuitem id="mnEditEdit"/>
<menuitem id="mnEditDelete"/>
<menuseparator/>
<menuitem label="&toggleSelectedImportant.label;" oncommand="viewer.cmdToggleSelectedImportant()"/>
<menuitem label="&toggleSelectedImportant.label;"
command="cmdTogglePriority"/>
</popup>
</popupset>
<!--============================= CONTENT ============================== -->
<tree id="olStyleRules" class="plain" flex="1" persist="height"
onselect="viewer.onRuleSelect()">
seltype="single" onselect="viewer.onRuleSelect()">
<treecols>
<treecol id="olcRule" label="&styleRule.label;" flex="1"/>
<splitter class="tree-splitter"/>
@ -83,7 +89,7 @@
</treecols>
<treechildren id="olbStyleProps"
alternatingbackground="true"
ondblclick="viewer.cmdEditSelectedProperty()"/>
ondblclick="viewer.pane.panelset.execCommand('cmdEditEdit')"/>
</tree>
</page>

View File

@ -47,9 +47,6 @@
<!ENTITY disableSelectedRules.label "Inhabilita">
<!ENTITY openSelectedFileInEditor.label "Obre el fitxer a l'editor">
<!ENTITY newProperty.label "Nova propietat">
<!ENTITY editSelectedProperty.label "Edita">
<!ENTITY deleteSelectedProperty.label "Suprimeix">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Commuta !important">

View File

@ -41,9 +41,6 @@
<!ENTITY deleteSelectedRules.label "Odstranit">
<!ENTITY disableSelectedRules.label "deaktivovaný">
<!ENTITY openSelectedFileInEditor.label "Otevřít v editoru">
<!ENTITY newProperty.label "Nová vlastnost">
<!ENTITY editSelectedProperty.label "Upravit hodnotu">
<!ENTITY deleteSelectedProperty.label "Odstranit">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Přepnout !important">
<!ENTITY styleRule.label "Pravidlo">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Deaktiver">
<!ENTITY openSelectedFileInEditor.label "Åbn fil i editor">
<!ENTITY newProperty.label "Ny egenskab">
<!ENTITY editSelectedProperty.label "Rediger">
<!ENTITY deleteSelectedProperty.label "Slet">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Tænd/sluk !important">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Deaktivieren">
<!ENTITY openSelectedFileInEditor.label "Datei im Editor öffnen">
<!ENTITY newProperty.label "Neue Eigenschaft">
<!ENTITY editSelectedProperty.label "Bearbeiten">
<!ENTITY deleteSelectedProperty.label "Löschen">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "!important ein/ausschalten">

View File

@ -42,9 +42,6 @@
<!ENTITY disableSelectedRules.label "Απενεργοποίηση">
<!ENTITY openSelectedFileInEditor.label "Άνοιγμα αρχείου στον επεξεργαστή">
<!ENTITY newProperty.label "Νέα ιδιότητα">
<!ENTITY editSelectedProperty.label "Επεξεργασία">
<!ENTITY deleteSelectedProperty.label "Διαγραφή">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Εναλλαγή !important">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Disable">
<!ENTITY openSelectedFileInEditor.label "Open File in Editor">
<!ENTITY newProperty.label "New Property">
<!ENTITY editSelectedProperty.label "Edit">
<!ENTITY deleteSelectedProperty.label "Delete">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Toggle !important">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Désactiver">
<!ENTITY openSelectedFileInEditor.label "Ouvrir le fichier dans l'éditeur">
<!ENTITY newProperty.label "Nouvelle propriété">
<!ENTITY editSelectedProperty.label "Éditer">
<!ENTITY deleteSelectedProperty.label "Supprimer">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Basculer !important">

View File

@ -41,9 +41,6 @@
<!ENTITY deleteSelectedRules.label "Scrios">
<!ENTITY disableSelectedRules.label "Díchumasaigh">
<!ENTITY openSelectedFileInEditor.label "Oscail Comhad in Eagarthóir">
<!ENTITY newProperty.label "Airí Nua">
<!ENTITY editSelectedProperty.label "Eagar">
<!ENTITY deleteSelectedProperty.label "Scrios">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Scoránaigh !important">
<!ENTITY styleRule.label "Riail">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Letiltás">
<!ENTITY openSelectedFileInEditor.label "Fájl megnyitása szerkesztőben">
<!ENTITY newProperty.label "Új tulajdonság">
<!ENTITY editSelectedProperty.label "Szerkesztés">
<!ENTITY deleteSelectedProperty.label "Törlés">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "!important kapcsoló">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Deaktiver">
<!ENTITY openSelectedFileInEditor.label "Åpne i filredigerer">
<!ENTITY newProperty.label "Ny egenskap ...">
<!ENTITY editSelectedProperty.label "Rediger ...">
<!ENTITY deleteSelectedProperty.label "Slett">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Merk som !important">

View File

@ -44,9 +44,6 @@
<!ENTITY disableSelectedRules.label "Wyłącz">
<!ENTITY openSelectedFileInEditor.label "Otwórz plik w edytorze">
<!ENTITY newProperty.label "Nowa właściwość">
<!ENTITY editSelectedProperty.label "Edytuj">
<!ENTITY deleteSelectedProperty.label "Usuń">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Przełącz atrybut !important">

View File

@ -45,9 +45,6 @@
<!ENTITY disableSelectedRules.label "Desativar">
<!ENTITY openSelectedFileInEditor.label "Abrir arquivo no editor">
<!ENTITY newProperty.label "Nova propriedade...">
<!ENTITY editSelectedProperty.label "Editar...">
<!ENTITY deleteSelectedProperty.label "Excluir">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Inverter !important">

View File

@ -1,10 +1,7 @@
<!ENTITY deleteSelectedProperty.label "Удалить">
<!ENTITY deleteSelectedRules.label "Удалить">
<!ENTITY disableSelectedRules.label "Отключить">
<!ENTITY editSelectedProperty.label "Изменить">
<!ENTITY miFindCSSRules.accesskey "Н">
<!ENTITY miFindCSSRules.label "Найти правила CSS...">
<!ENTITY newProperty.label "Создать свойство">
<!ENTITY newRules.label "Создать">
<!ENTITY openSelectedFileInEditor.label "Открыть файл в редакторе">
<!ENTITY styleRule.label "Правило">

View File

@ -36,7 +36,6 @@
#endif
- ***** END LICENSE BLOCK ***** -->
<!ENTITY newProperty.label "Nová vlastnosť">
<!ENTITY disableSelectedRules.label "deaktivovaný">
<!ENTITY styleRulePropPriority.label "Priorita">
<!ENTITY styleRulePropName.label "Vlastnosť">
@ -45,10 +44,8 @@
<!ENTITY openSelectedFileInEditor.label "Otvoriť v editore">
<!ENTITY toggleSelectedImportant.label "Prepnúť !important">
<!ENTITY deleteSelectedRules.label "Odstrániť">
<!ENTITY editSelectedProperty.label "Upraviť hodnotu">
<!ENTITY styleRulePropValue.label "Hodnota">
<!ENTITY miFindCSSRules.accesskey "N">
<!ENTITY deleteSelectedProperty.label "Odstrániť">
<!ENTITY styleRuleLineNumber.label "Riadok">
<!ENTITY styleRule.label "Pravidlo">
<!ENTITY styleRuleURI.label "Súbor">

View File

@ -45,9 +45,6 @@
<!ENTITY disableSelectedRules.label "Avaktivera">
<!ENTITY openSelectedFileInEditor.label "Öppna fil i redigerare">
<!ENTITY newProperty.label "Ny egenskap">
<!ENTITY editSelectedProperty.label "Redigera">
<!ENTITY deleteSelectedProperty.label "Ta bort">
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE "!important" since it is a CSS API -->
<!ENTITY toggleSelectedImportant.label "Växla !important-läge">

View File

@ -1,10 +1,7 @@
<!ENTITY deleteSelectedProperty.label "删除">
<!ENTITY deleteSelectedRules.label "删除">
<!ENTITY disableSelectedRules.label "禁用">
<!ENTITY editSelectedProperty.label "编辑">
<!ENTITY miFindCSSRules.accesskey "F">
<!ENTITY miFindCSSRules.label "搜索CSS规则...">
<!ENTITY newProperty.label "新建属性">
<!ENTITY newRules.label "新建">
<!ENTITY openSelectedFileInEditor.label "在编辑器中打开文件">
<!ENTITY styleRule.label "规则">

View File

@ -5,9 +5,6 @@
<!ENTITY deleteSelectedRules.label "刪除">
<!ENTITY disableSelectedRules.label "暫停使用">
<!ENTITY openSelectedFileInEditor.label "用編輯器開啟">
<!ENTITY newProperty.label "新增屬性">
<!ENTITY editSelectedProperty.label "編輯">
<!ENTITY deleteSelectedProperty.label "刪除">
<!ENTITY toggleSelectedImportant.label "切換 !important">
<!ENTITY styleRule.label "規則">
<!ENTITY styleRuleURI.label "檔案">