Bug #343875 --> add UI for adding/removing tags to the prefs dialog. Some of this UI may just be temporary. Still need support for editing tags. sr=bienvenu

This commit is contained in:
scott%scott-macgregor.org 2006-07-14 21:48:28 +00:00
parent e5bdbc81c4
commit 738f7f5433
5 changed files with 92 additions and 76 deletions

View File

@ -38,6 +38,7 @@
var gDisplayPane = {
mInitialized: false,
mTagListBox: null,
init: function ()
{
@ -51,6 +52,9 @@ var gDisplayPane = {
document.getElementById('mailnews.view_default_charset').value);
this.mInitialized = true;
this.mTagListBox = document.getElementById('tagList');
this.buildTagList();
},
tabSelectionChanged: function ()
@ -60,27 +64,56 @@ var gDisplayPane = {
.valueFromPreferences = document.getElementById("displayPrefs").selectedIndex;
},
restoreDefaultLabels: function()
{
for (var index = 1; index <= 5; index++)
{
// reset throws an exception if the pref value is already the default so
// work around that with some try/catch exception handling
try {
document.getElementById('mailnews.labels.description.' + index ).reset();
} catch (ex) {}
try {
document.getElementById('mailnews.labels.color.' + index ).reset();
} catch (ex) {}
}
},
fontOptionsDialog: function()
{
document.documentElement.openSubDialog("chrome://messenger/content/preferences/fonts.xul", "", null);
},
// appends the tag to the tag list box
appendTagItem: function(aTagName, aKey, aColor)
{
var item = this.mTagListBox.appendItem(aTagName, aKey);
item.style.color = aColor;
return item;
},
buildTagList: function()
{
var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"].getService(Components.interfaces.nsIMsgTagService);
var allTags = tagService.tagEnumerator;
var allKeys = tagService.keyEnumerator;
while (allTags.hasMore())
{
var key = allKeys.getNext();
this.appendTagItem(allTags.getNext(), key, tagService.getColorForKey(key));
}
},
removeTag: function()
{
var tagItemToRemove = this.mTagListBox.getSelectedItem();
var index = this.mTagListBox.selectedIndex;
if (index >= 0)
{
var itemToRemove = this.mTagListBox.getItemAtIndex(index);
var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"].getService(Components.interfaces.nsIMsgTagService);
tagService.deleteKey(itemToRemove.getAttribute("value"));
this.mTagListBox.removeItemAt(index);
var numItemsInListBox = this.mTagListBox.getRowCount();
this.mTagListBox.selectedIndex = index < numItemsInListBox ? index : numItemsInListBox - 1;
}
},
addTag: function()
{
var args = {result: "", okCallback: addTagCallback};
var dialog = window.openDialog(
"chrome://messenger/content/newTagDialog.xul",
"",
"chrome,titlebar,modal",
args);
},
addMenuItem: function(aMenuPopup, aLabel, aValue)
{
var menuItem = document.createElement('menuitem');
@ -136,3 +169,15 @@ var gDisplayPane = {
return undefined;
}
};
function addTagCallback(aName, aColor)
{
var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"].getService(Components.interfaces.nsIMsgTagService);
tagService.addTag(aName, aColor);
var item = gDisplayPane.appendTagItem(aName, tagService.getKeyForTag(aName), aColor);
var tagListBox = document.getElementById('tagList');
tagListBox.ensureElementIsVisible(item);
tagListBox.selectItem(item);
tagListBox.focus();
}

View File

@ -81,7 +81,7 @@
<tabbox id="displayPrefs" flex="1" onselect="gDisplayPane.tabSelectionChanged();">
<tabs>
<tab label="&itemFormatting.label;"/>
<tab label="&itemLabels.label;"/>
<tab label="&itemTags.label;"/>
<tab label="&itemFonts.label;"/>
</tabs>
@ -152,54 +152,16 @@
</tabpanel>
<tabpanel orient="vertical">
<groupbox>
<caption label="&labelsSettings.label;"/>
<description>&displayLabelsText.label;</description>
<hbox align="top">
<vbox>
<!-- label color: 1 (default red) -->
<hbox class="indent" align="center">
<textbox id="label1TextBox" preference="mailnews.labels.description.1" />
<colorpicker class="small-margin" type="button" id="labelColorPicker1"
palettename="standard" preference="mailnews.labels.color.1"/>
</hbox>
<!-- label color: 2 (default orange) -->
<hbox class="indent" align="center">
<textbox id="label2TextBox" preference="mailnews.labels.description.2" />
<colorpicker class="small-margin" type="button" id="labelColorPicker2"
palettename="standard" preference="mailnews.labels.color.2"/>
</hbox>
<!-- label color: 3 (default green) -->
<hbox class="indent" align="center">
<textbox id="label3TextBox" preference="mailnews.labels.description.3" />
<colorpicker class="small-margin" type="button" id="labelColorPicker3"
palettename="standard" preference="mailnews.labels.color.3"/>
</hbox>
</vbox>
<vbox>
<!-- label color: 4 (default blue) -->
<hbox class="indent" align="center">
<textbox id="label4TextBox" preference="mailnews.labels.description.4" />
<colorpicker class="small-margin" type="button" id="labelColorPicker4"
palettename="standard" preference="mailnews.labels.color.4"/>
</hbox>
<!-- label color: 5 (default purple) -->
<hbox class="indent" align="center">
<textbox id="label5TextBox" preference="mailnews.labels.description.5" />
<colorpicker class="small-margin" type="button" id="labelColorPicker5"
palettename="standard" preference="mailnews.labels.color.5"/>
</hbox>
</vbox>
</hbox>
<hbox pack="end">
<button label="&restoreDefaults.label;" accesskey="&restoreDefaults.accesskey;"
oncommand="gDisplayPane.restoreDefaultLabels();"/>
</hbox>
</groupbox>
<description>&displayTagsText.label;</description>
<hbox>
<listbox id="tagList" flex="1" rows="10"/>
<vbox>
<button label="&addTagButton.label;" accesskey="&addTagButton.accesskey;"
oncommand="gDisplayPane.addTag();"/>
<button label="&removeTagButton.label;" accesskey="&removeTagButton.accesskey;"
oncommand="gDisplayPane.removeTag();"/>
</vbox>
</hbox>
</tabpanel>
<tabpanel orient="vertical">

View File

@ -1,5 +1,5 @@
<!ENTITY itemFormatting.label "Formatting">
<!ENTITY itemLabels.label "Labels">
<!ENTITY itemTags.label "Tags">
<!ENTITY itemFonts.label "Fonts">
<!ENTITY textBegin.label "Quoted plain text appearance">
@ -33,17 +33,20 @@
<!ENTITY convertEmoticons.accesskey "D">
<!ENTITY htmlColors.label "HTML Messages">
<!ENTITY overrideSender.label "When displaying HTML messages, use the following:">
<!ENTITY overrideSender.accesskey "e">
<!ENTITY overrideSender.accesskey "n">
<!ENTITY textColor.label "Text Color:">
<!ENTITY textColor.accesskey "T">
<!ENTITY backgroundColor.label "Background Color:">
<!ENTITY backgroundColor.accesskey "b">
<!-- labels -->
<!ENTITY labelsSettings.label "Labels">
<!ENTITY displayLabelsText.label "Labels can be used to categorize and prioritize your messages.">
<!ENTITY restoreDefaults.label "Restore Defaults">
<!ENTITY restoreDefaults.accesskey "R">
<!ENTITY displayTagsText.label "Tags can be used to categorize and prioritize your messages.">
<!ENTITY addTagButton.label "Add">
<!ENTITY addTagButton.accesskey "A">
<!ENTITY editTagButton.label "Edit">
<!ENTITY editTagButton.accesskey "E">
<!ENTITY removeTagButton.label "Delete">
<!ENTITY removeTagButton.accesskey "l">
<!-- Fonts -->
<!ENTITY fontsDescription.label "Configure the fonts used by &brandShortName;">

View File

@ -64,7 +64,7 @@ interface nsIMsgTagService : nsISupports {
void addTagForKey(in ACString key, in AString tag, in ACString color);
void addTag(in AString tag, in ACString color);
ACString getColorForKey(in ACString key);
void deleteTag(in AString tag);
void deleteKey(in ACString key);
// we need some way to enumerate all tags. Or return a list of all tags.
readonly attribute nsIStringEnumerator tagEnumerator;
readonly attribute nsIUTF8StringEnumerator keyEnumerator;

View File

@ -158,11 +158,17 @@ NS_IMETHODIMP nsMsgTagService::GetColorForKey(const nsACString &key, nsACString
}
/* void deleteTag (in wstring tag); */
NS_IMETHODIMP nsMsgTagService::DeleteTag(const nsAString &tag)
NS_IMETHODIMP nsMsgTagService::DeleteKey(const nsACString &key)
{
// do we want to set a .deleted pref, or just set the tag
// property to "", or clear the pref(s)?
return NS_ERROR_NOT_IMPLEMENTED;
// clear the associated prefs
nsCAutoString prefName("mailnews.tags.");
prefName.Append(key);
prefName.AppendLiteral(".tag");
// this is the rv we're going to return - it's the interesting one.§
nsresult rv = m_prefBranch->ClearUserPref(prefName.get());
prefName.Replace(prefName.Length() - 3, 3, NS_LITERAL_CSTRING("color"));
m_prefBranch->ClearUserPref(prefName.get());
return rv;
}
/* readonly attribute nsIStringEnumerator tagEnumerator; */