!import
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2002
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Scott MacGregor <mscott@netscape.com>
25 * Seth Spitzer <sspitzer@netscape.com>
26 * Stefan Borggraefe <borggraefe@despammed.com>
27 * Gervase Markham <gerv@gerv.net>
28 * Karsten Düsterloh <mnyromyr@tprac.de>
29 *
30 * Alternatively, the contents of this file may be used under the terms of
31 * either of the GNU General Public License Version 2 or later (the "GPL"),
32 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33 * in which case the provisions of the GPL or the LGPL are applicable instead
34 * of those above. If you wish to allow use of your version of this file only
35 * under the terms of either the GPL or the LGPL, and not to allow others to
36 * use your version of this file under the terms of the MPL, indicate your
37 * decision by deleting the provisions above and replace them with the notice
38 * and other provisions required by the GPL or the LGPL. If you do not delete
39 * the provisions above, a recipient may use your version of this file under
40 * the terms of any one of the MPL, the GPL or the LGPL.
41 *
42 * ***** END LICENSE BLOCK ***** */
43
44
45 var gMailListView;
46 var gListBox;
47 var gEditButton;
48 var gDeleteButton;
49
mailViewListOnLoad
50 function mailViewListOnLoad()
51 {
52 gMailListView = Components.classes["@mozilla.org/messenger/mailviewlist;1"].getService(Components.interfaces.nsIMsgMailViewList);;
53 gListBox = document.getElementById('mailViewList');
54
55 // Construct list view based on current mail view list data
56 refreshListView(null);
57 gEditButton = document.getElementById('editButton');
58 gDeleteButton = document.getElementById('deleteButton');
59
60 updateButtons();
61 }
62
refreshListView
63 function refreshListView(aSelectedMailView)
64 {
65 // remove any existing items in the view...
66 for (var index = gListBox.getRowCount(); index > 0; index--)
67 gListBox.removeChild(gListBox.getItemAtIndex(index - 1));
68
69 var numItems = gMailListView.mailViewCount;
70 var mailView;
71 for (index = 0; index < numItems; index++)
72 {
73 mailView = gMailListView.getMailViewAt(index);
74 gListBox.appendItem(mailView.prettyName, index);
75 if (aSelectedMailView && (mailView.prettyName == aSelectedMailView.prettyName) )
76 gListBox.selectedIndex = index;
77 }
78 }
79
onNewMailView
80 function onNewMailView()
81 {
82 window.openDialog('chrome://messenger/content/mailViewSetup.xul', "", 'centerscreen,resizable,modal,titlebar,chrome', {onOkCallback: refreshListView});
83 }
84
onDeleteMailView
85 function onDeleteMailView()
86 {
87 var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].
88 getService(Components.interfaces.nsIStringBundleService);
89 var bundle = strBundleService.createBundle("chrome://messenger/locale/messenger.properties");
90
91 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
92 if (!promptService.confirm(window, bundle.GetStringFromName("confirmViewDeleteTitle"), bundle.GetStringFromName("confirmViewDeleteMessage")))
93 return;
94
95 // get the selected index
96 var selectedIndex = gListBox.selectedIndex;
97 if (selectedIndex >= 0)
98 {
99 var mailView = gMailListView.getMailViewAt(selectedIndex);
100 if (mailView)
101 {
102 gMailListView.removeMailView(mailView);
103 // now remove it from the view...
104 gListBox.removeChild(gListBox.selectedItem);
105
106 // select the next item in the list..
107 if (selectedIndex < gListBox.getRowCount())
108 gListBox.selectedIndex = selectedIndex;
109 else
110 gListBox.selectedIndex = gListBox.getRowCount() - 1;
111
112 gMailListView.save();
113 }
114 }
115 }
116
onEditMailView
117 function onEditMailView()
118 {
119 // get the selected index
120 var selectedIndex = gListBox.selectedIndex;
121 if (selectedIndex >= 0)
122 {
123 var selMailView = gMailListView.getMailViewAt(selectedIndex);
124 // open up the mail view setup dialog passing in the mail view as an argument....
125
126 var args = {mailView: selMailView, onOkCallback: refreshListView};
127
128 window.openDialog('chrome://messenger/content/mailViewSetup.xul', "", 'centerscreen,modal,resizable,titlebar,chrome', args);
129 }
130 }
131
onMailViewSelect
132 function onMailViewSelect(event)
133 {
134 updateButtons();
135 }
136
updateButtons
137 function updateButtons()
138 {
139 var selectedIndex = gListBox.selectedIndex;
140 // "edit" and "delete" only enabled when one filter selected
141 gEditButton.disabled = selectedIndex < 0;
142 gDeleteButton.disabled = selectedIndex < 0;
143 }