?? searchbar.js
字號:
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-# ***** BEGIN LICENSE BLOCK *****# Version: MPL 1.1/GPL 2.0/LGPL 2.1## The contents of this file are subject to the Mozilla Public License Version# 1.1 (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at# http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS IS" basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License# for the specific language governing rights and limitations under the# License.## The Original Code is Mozilla Communicator client code, released# March 31, 1998.## The Initial Developer of the Original Code is# Netscape Communications Corporation.# Portions created by the Initial Developer are Copyright (C) 1998-1999# the Initial Developer. All Rights Reserved.## Contributor(s):# Seth Spitzer <sspitzer@netscape.com># Scott MacGregor <mscott@mozilla.org># David Bienvenu <bienvenu@nventure.com>## Alternatively, the contents of this file may be used under the terms of# either of the GNU General Public License Version 2 or later (the "GPL"),# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),# in which case the provisions of the GPL or the LGPL are applicable instead# of those above. If you wish to allow use of your version of this file only# under the terms of either the GPL or the LGPL, and not to allow others to# use your version of this file under the terms of the MPL, indicate your# decision by deleting the provisions above and replace them with the notice# and other provisions required by the GPL or the LGPL. If you do not delete# the provisions above, a recipient may use your version of this file under# the terms of any one of the MPL, the GPL or the LGPL.## ***** END LICENSE BLOCK ***** var gSearchSession = null;var gPreQuickSearchView = null;var gSearchTimer = null;var gViewSearchListener;var gSearchBundle;var gStatusBar = null;var gSearchInProgress = false;var gSearchInput = null;var gDefaultSearchViewTerms = null;var gQSViewIsDirty = false;var gIgnoreFocus = false;var gIgnoreClick = false;var gNumTotalMessages;var gNumUnreadMessages;// search criteria mode values // Note: If you change these constants, please update the menuitem values in// quick-search-menupopup. Note: These values are stored in localstore.rdf so we // can remember the users last quick search state. If you add values here, you must add// them to the end of the list!const kQuickSearchSubject = 0;const kQuickSearchSender = 1;const kQuickSearchSenderOrSubject = 2;const kQuickSearchBody = 3;// const kQuickSearchHighlight = 4; // * We no longer support this quick search mode..*const kQuickSearchRecipient = 5;function SetQSStatusText(aNumHits){ var statusMsg; // if there are no hits, it means no matches were found in the search. if (aNumHits == 0) statusMsg = gSearchBundle.getString("searchFailureMessage"); else { if (aNumHits == 1) statusMsg = gSearchBundle.getString("searchSuccessMessage"); else statusMsg = gSearchBundle.getFormattedString("searchSuccessMessages", [aNumHits]); } statusFeedback.showStatusString(statusMsg);}// nsIMsgSearchNotify objectvar gSearchNotificationListener ={ onSearchHit: function(header, folder) { gNumTotalMessages++; if (!header.isRead) gNumUnreadMessages++; // XXX todo // update status text? }, onSearchDone: function(status) { SetQSStatusText(gDBView.QueryInterface(Components.interfaces.nsITreeView).rowCount) statusFeedback.showProgress(0); gStatusBar.setAttribute("mode","normal"); gSearchInProgress = false; // ### TODO need to find out if there's quick search within a virtual folder. if (gCurrentVirtualFolderUri && (!gSearchInput || gSearchInput.value == "" || gSearchInput.showingSearchCriteria)) { var vFolder = GetMsgFolderFromUri(gCurrentVirtualFolderUri, false); var dbFolderInfo = vFolder.getMsgDatabase(msgWindow).dBFolderInfo; dbFolderInfo.NumUnreadMessages = gNumUnreadMessages; dbFolderInfo.NumMessages = gNumTotalMessages; vFolder.updateSummaryTotals(true); // force update from db. var msgdb = vFolder.getMsgDatabase(msgWindow); msgdb.Commit(MSG_DB_LARGE_COMMIT); // now that we have finished loading a virtual folder, scroll to the correct message ScrollToMessageAfterFolderLoad(vFolder); } }, onNewSearch: function() { statusFeedback.showProgress(0); statusFeedback.showStatusString(gSearchBundle.getString("searchingMessage")); gStatusBar.setAttribute("mode","undetermined"); gSearchInProgress = true; gNumTotalMessages = 0; gNumUnreadMessages = 0; }}function getDocumentElements(){ gSearchBundle = document.getElementById("bundle_search"); gStatusBar = document.getElementById('statusbar-icon'); GetSearchInput();}function addListeners(){ gViewSearchListener = gDBView.QueryInterface(Components.interfaces.nsIMsgSearchNotify); gSearchSession.registerListener(gViewSearchListener);}function removeListeners(){ gSearchSession.unregisterListener(gViewSearchListener);}function removeGlobalListeners(){ removeListeners(); gSearchSession.unregisterListener(gSearchNotificationListener); }function initializeGlobalListeners(){ // Setup the javascript object as a listener on the search results gSearchSession.registerListener(gSearchNotificationListener);}function createQuickSearchView(){ //if not already in quick search view if (gDBView.viewType != nsMsgViewType.eShowQuickSearchResults) { var treeView = gDBView.QueryInterface(Components.interfaces.nsITreeView); //clear selection if (treeView && treeView.selection) treeView.selection.clearSelection(); gPreQuickSearchView = gDBView; if (gDBView.viewType == nsMsgViewType.eShowVirtualFolderResults) { // remove the view as a listener on the search results var saveViewSearchListener = gDBView.QueryInterface(Components.interfaces.nsIMsgSearchNotify); gSearchSession.unregisterListener(saveViewSearchListener); } // if grouped by sort, turn that off, as well as threaded, since we don't // group quick search results yet. var viewFlags = gDBView.viewFlags; if (viewFlags & nsMsgViewFlagsType.kGroupBySort) viewFlags &= ~(nsMsgViewFlagsType.kGroupBySort | nsMsgViewFlagsType.kThreadedDisplay); CreateDBView(gDBView.msgFolder, (gXFVirtualFolderTerms) ? nsMsgViewType.eShowVirtualFolderResults : nsMsgViewType.eShowQuickSearchResults, viewFlags, gDBView.sortType, gDBView.sortOrder); }}function initializeSearchBar(){ createQuickSearchView(); if (!gSearchSession) { getDocumentElements(); var searchSessionContractID = "@mozilla.org/messenger/searchSession;1"; gSearchSession = Components.classes[searchSessionContractID].createInstance(Components.interfaces.nsIMsgSearchSession); initializeGlobalListeners(); } else { if (gSearchInProgress) { onSearchStop(); gSearchInProgress = false; } removeListeners(); } addListeners();}function onEnterInSearchBar(){ if (!gSearchInput || gSearchInput.value == "" || gSearchInput.showingSearchCriteria) { if (gDBView.viewType == nsMsgViewType.eShowQuickSearchResults || gDBView.viewType == nsMsgViewType.eShowVirtualFolderResults) { statusFeedback.showStatusString(""); viewDebug ("onEnterInSearchBar gDefaultSearchViewTerms = " + gDefaultSearchViewTerms + "gVirtualFolderTerms = " + gVirtualFolderTerms + "gXFVirtualFolderTerms = " + gXFVirtualFolderTerms + "\n"); var addTerms = gDefaultSearchViewTerms || gVirtualFolderTerms || gXFVirtualFolderTerms; if (addTerms) { viewDebug ("addTerms = " + addTerms + " count = " + addTerms.Count() + "\n"); initializeSearchBar(); onSearch(addTerms); } else restorePreSearchView(); } else if (gPreQuickSearchView && !gDefaultSearchViewTerms)// may be a quick search from a cross-folder virtual folder restorePreSearchView(); if (gSearchInput) gSearchInput.showingSearchCriteria = true; gQSViewIsDirty = false; return; } initializeSearchBar(); ClearThreadPaneSelection(); ClearMessagePane(); onSearch(null); gQSViewIsDirty = false;}function restorePreSearchView(){ var selectedHdr = null; //save selection try { selectedHdr = gDBView.hdrForFirstSelectedMessage; } catch (ex) {} //we might have to sort the view coming out of quick search var sortType = gDBView.sortType; var sortOrder = gDBView.sortOrder; var viewFlags = gDBView.viewFlags; var folder = gDBView.msgFolder; gDBView.close(); gDBView = null; if (gPreQuickSearchView) { gDBView = gPreQuickSearchView; if (gDBView.viewType == nsMsgViewType.eShowVirtualFolderResults) { // readd the view as a listener on the search results var saveViewSearchListener = gDBView.QueryInterface(Components.interfaces.nsIMsgSearchNotify); if (gSearchSession) gSearchSession.registerListener(saveViewSearchListener); }// dump ("view type = " + gDBView.viewType + "\n"); if (sortType != gDBView.sortType || sortOrder != gDBView.sortOrder) { gDBView.sort(sortType, sortOrder); } UpdateSortIndicators(sortType, sortOrder); gPreQuickSearchView = null; } else //create default view type { CreateDBView(folder, nsMsgViewType.eShowAllThreads, viewFlags, sortType, sortOrder); } RerootThreadPane(); var scrolled = false; // now restore selection if (selectedHdr) { gDBView.selectMsgByKey(selectedHdr.messageKey); var treeView = gDBView.QueryInterface(Components.interfaces.nsITreeView); var selectedIndex = treeView.selection.currentIndex; if (selectedIndex >= 0) { // scroll EnsureRowInThreadTreeIsVisible(selectedIndex); scrolled = true; } else ClearMessagePane(); } if (!scrolled) ScrollToMessageAfterFolderLoad(null);}function onSearch(aSearchTerms){ viewDebug("in OnSearch, searchTerms = " + aSearchTerms + "\n"); RerootThreadPane(); if (aSearchTerms) createSearchTermsWithList(aSearchTerms); else createSearchTerms(); gDBView.searchSession = gSearchSession; try { gSearchSession.search(msgWindow); } catch(ex) { dump("Search Exception\n"); }}function createSearchTermsWithList(aTermsArray){ var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope; var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib; var nsMsgSearchOp = Components.interfaces.nsMsgSearchOp; gSearchSession.clearScopes(); var searchTerms = gSearchSession.searchTerms; var searchTermsArray = searchTerms.QueryInterface(Components.interfaces.nsISupportsArray); searchTermsArray.Clear(); var i; var selectedFolder = GetThreadPaneFolder(); var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -