!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 the virtual folder properties dialog
16 *
17 * The Initial Developer of the Original Code is
18 * David Bienvenu.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * David Bienvenu <bienvenu@nventure.com>
24 * Scott MacGregor <mscott@mozilla.org>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 var gFolderPickerTree = null;
41
onLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function onLoad()
43 {
44 gFolderPickerTree = document.getElementById("folderPickerTree");
45
46 if (window.arguments[0].searchFolderURIs)
47 {
48 // for each folder uri,
49 var srchFolderUriArray = window.arguments[0].searchFolderURIs.split('|');
50 // get the folder for each search URI and set the searchThisFolder flag on it
51 for (var i in srchFolderUriArray)
52 {
53 var realFolderRes = GetResourceFromUri(srchFolderUriArray[i]);
54 var realFolder = realFolderRes.QueryInterface(Components.interfaces.nsIMsgFolder);
55 if (realFolder)
56 realFolder.setInVFEditSearchScope(true, false);
57 }
58 }
59 }
60
onUnLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
61 function onUnLoad()
62 {
63 resetFolderToSearchAttribute();
64 }
65
onOK
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
66 function onOK()
67 {
68 if ( window.arguments[0].okCallback )
69 window.arguments[0].okCallback(generateFoldersToSearchList());
70 }
71
onCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
72 function onCancel()
73 {
74 // onunload will clear out the folder attributes we changed
75 }
76
addFolderToSearchListString
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
77 function addFolderToSearchListString(aFolder, aCurrentSearchURIString)
78 {
79 if (aCurrentSearchURIString)
80 aCurrentSearchURIString += '|';
81 aCurrentSearchURIString += aFolder.URI;
82
83 return aCurrentSearchURIString;
84 }
85
processSearchSettingForFolder
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
86 function processSearchSettingForFolder(aFolder, aCurrentSearchURIString)
87 {
88 if (aFolder.inVFEditSearchScope)
89 aCurrentSearchURIString = addFolderToSearchListString(aFolder, aCurrentSearchURIString);
90
91 aFolder.setInVFEditSearchScope(false, false);
92 return aCurrentSearchURIString;
93 }
94
95 // warning: this routine also clears out the search property list from all of the msg folders
generateFoldersToSearchList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
96 function generateFoldersToSearchList()
97 {
98 var uriSearchString = "";
99
100 var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
101 var allServers = accountManager.allServers;
102 var numServers = allServers.Count();
103 for (var index = 0; index < numServers; index++)
104 {
105 var rootFolder = allServers.GetElementAt(index).QueryInterface(Components.interfaces.nsIMsgIncomingServer).rootFolder;
106 if (rootFolder)
107 {
108 uriSearchString = processSearchSettingForFolder(rootFolder, uriSearchString);
109 var allFolders = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
110 rootFolder.ListDescendents(allFolders);
111 var numFolders = allFolders.Count();
112 for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
113 uriSearchString = processSearchSettingForFolder(allFolders.GetElementAt(folderIndex).QueryInterface(Components.interfaces.nsIMsgFolder), uriSearchString);
114 }
115 } // for each account
116
117 return uriSearchString;
118 }
119
resetFolderToSearchAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
120 function resetFolderToSearchAttribute()
121 {
122 // iterates over all accounts and all folders, clearing out the inVFEditScope property in case
123 // we set it.
124 var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
125 var allServers = accountManager.allServers;
126 var numServers = allServers.Count();
127 for (var index = 0; index < numServers; index++)
128 {
129 var rootFolder = allServers.GetElementAt(index).QueryInterface(Components.interfaces.nsIMsgIncomingServer).rootFolder;
130 if (rootFolder)
131 {
132 var allFolders = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
133 rootFolder.ListDescendents(allFolders);
134 var numFolders = allFolders.Count();
135 for (var folderIndex = 0; folderIndex < numFolders; folderIndex++)
136 allFolders.GetElementAt(folderIndex).QueryInterface(Components.interfaces.nsIMsgFolder).setInVFEditSearchScope(false, false);
137 }
138 } // for each account
139 }
140
ReverseStateFromNode
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
141 function ReverseStateFromNode(row)
142 {
143 var folder = GetFolderResource(row).QueryInterface(Components.interfaces.nsIMsgFolder);
144 var currentState = folder.inVFEditSearchScope;
145
146 folder.setInVFEditSearchScope(!currentState, false);
147 }
148
GetFolderResource
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
149 function GetFolderResource(rowIndex)
150 {
151 return gFolderPickerTree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder).getResourceAtIndex(rowIndex);
152 }
153
selectFolderTreeOnClick
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
154 function selectFolderTreeOnClick(event)
155 {
156 // we only care about button 0 (left click) events
157 if (event.button != 0 || event.originalTarget.localName != "treechildren")
158 return;
159
160 var row = {}, col = {}, obj = {};
161 gFolderPickerTree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj);
162 if (row.value == -1 || row.value > (gFolderPickerTree.view.rowCount - 1))
163 return;
164
165 if (event.detail == 2) {
166 // only toggle the search folder state when double clicking something
167 // that isn't a container
168 if (!gFolderPickerTree.view.isContainer(row.value)) {
169 ReverseStateFromNode(row.value);
170 return;
171 }
172 }
173 else if (event.detail == 1)
174 {
175 if (obj.value != "twisty" && col.value.id == "selectedColumn")
176 ReverseStateFromNode(row.value)
177 }
178 }
179
onSelectFolderTreeKeyPress
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
180 function onSelectFolderTreeKeyPress(event)
181 {
182 // for now, only do something on space key
183 if (event.charCode != KeyEvent.DOM_VK_SPACE)
184 return;
185
186 var treeSelection = gFolderPickerTree.view.selection;
187 for (var i=0;i<treeSelection.getRangeCount();i++) {
188 var start = {}, end = {};
189 treeSelection.getRangeAt(i,start,end);
190 for (var k=start.value;k<=end.value;k++)
191 ReverseStateFromNode(k);
192 }
193 }