?? searchbar.js
字號:
var termsArray = aTermsArray.QueryInterface(Components.interfaces.nsISupportsArray); if (gXFVirtualFolderTerms) { var msgDatabase = selectedFolder.getMsgDatabase(msgWindow); if (msgDatabase) { var dbFolderInfo = msgDatabase.dBFolderInfo; var srchFolderUri = dbFolderInfo.getCharPtrProperty("searchFolderUri"); viewDebug("createSearchTermsWithList xf vf scope = " + srchFolderUri + "\n"); var srchFolderUriArray = srchFolderUri.split('|'); for (i in srchFolderUriArray) { var realFolderRes = GetResourceFromUri(srchFolderUriArray[i]); var realFolder = realFolderRes.QueryInterface(Components.interfaces.nsIMsgFolder); if (!realFolder.isServer) gSearchSession.addScopeTerm(getScopeToUse(termsArray, realFolder, ioService.offline), realFolder); } } } else { viewDebug ("in createSearchTermsWithList, adding scope term for selected folder\n"); gSearchSession.addScopeTerm(getScopeToUse(termsArray, selectedFolder, ioService.offline), selectedFolder); } // add each item in termsArray to the search session for (i = 0; i < termsArray.Count(); ++i) gSearchSession.appendTerm(termsArray.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgSearchTerm));}function getScopeToUse(aTermsArray, aFolderToSearch, aIsOffline){ if (aIsOffline || aFolderToSearch.server.type != 'imap') return nsMsgSearchScope.offlineMail; var scopeToUse = gSearchInput && gSearchInput.searchMode == kQuickSearchBody && !gSearchInput.showingSearchCriteria ? nsMsgSearchScope.onlineMail : nsMsgSearchScope.offlineMail; // it's possible one of our search terms may require us to use an online mail scope (such as imap body searches) for (var i = 0; scopeToUse != nsMsgSearchScope.onlineMail && i < aTermsArray.Count(); i++) if (aTermsArray.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgSearchTerm).attrib == nsMsgSearchAttrib.Body) scopeToUse = nsMsgSearchScope.onlineMail; return scopeToUse;}function createSearchTerms(){ var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope; var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib; var nsMsgSearchOp = Components.interfaces.nsMsgSearchOp; // create an i supports array to store our search terms var searchTermsArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); var selectedFolder = GetThreadPaneFolder(); var searchAttrib = (IsSpecialFolder(selectedFolder, MSG_FOLDER_FLAG_SENTMAIL | MSG_FOLDER_FLAG_DRAFTS | MSG_FOLDER_FLAG_QUEUE, true)) ? nsMsgSearchAttrib.ToOrCC : nsMsgSearchAttrib.Sender; // implement | for QS // does this break if the user types "foo|bar" expecting to see subjects with that string? // I claim no, since "foo|bar" will be a hit for "foo" || "bar" // they just might get more false positives if (!gSearchInput.showingSearchCriteria) // ignore the text box value if it's just showing the search criteria string { var termList = gSearchInput.value.split("|"); for (var i = 0; i < termList.length; i ++) { // if the term is empty, skip it if (termList[i] == "") continue; // create, fill, and append the subject term var term; var value; // if our search criteria is subject or subject|sender then add a term for the subject if (gSearchInput.searchMode == kQuickSearchSubject || gSearchInput.searchMode == kQuickSearchSenderOrSubject) { term = gSearchSession.createTerm(); value = term.value; value.str = termList[i]; term.value = value; term.attrib = nsMsgSearchAttrib.Subject; term.op = nsMsgSearchOp.Contains; term.booleanAnd = false; searchTermsArray.AppendElement(term); } if (gSearchInput.searchMode == kQuickSearchBody) { // what do we do for news and imap users that aren't configured for offline use? // in these cases the body search will never return any matches. Should we try to // see if body is a valid search scope in this particular case before doing the search? // should we switch back to a subject/sender search behind the scenes? term = gSearchSession.createTerm(); value = term.value; value.str = termList[i]; term.value = value; term.attrib = nsMsgSearchAttrib.Body; term.op = nsMsgSearchOp.Contains; term.booleanAnd = false; searchTermsArray.AppendElement(term); } // create, fill, and append the sender (or recipient) term if (gSearchInput.searchMode == kQuickSearchSender || gSearchInput.searchMode == kQuickSearchSenderOrSubject) { term = gSearchSession.createTerm(); value = term.value; value.str = termList[i]; term.value = value; term.attrib = searchAttrib; term.op = nsMsgSearchOp.Contains; term.booleanAnd = false; searchTermsArray.AppendElement(term); } // create, fill, and append the recipient if (gSearchInput.searchMode == kQuickSearchRecipient) { term = gSearchSession.createTerm(); value = term.value; value.str = termList[i]; term.value = value; term.attrib = nsMsgSearchAttrib.ToOrCC; term.op = nsMsgSearchOp.Contains; term.booleanAnd = false; searchTermsArray.AppendElement(term); } } } // now append the default view or virtual folder criteria to the quick search // so we don't lose any default view information viewDebug("gDefaultSearchViewTerms = " + gDefaultSearchViewTerms + "gVirtualFolderTerms = " + gVirtualFolderTerms + "gXFVirtualFolderTerms = " + gXFVirtualFolderTerms + "\n"); var defaultSearchTerms = (gDefaultSearchViewTerms || gVirtualFolderTerms || gXFVirtualFolderTerms); if (defaultSearchTerms) { var isupports = null; var searchTerm; var termsArray = defaultSearchTerms.QueryInterface(Components.interfaces.nsISupportsArray); for (i = 0; i < termsArray.Count(); i++) { isupports = termsArray.GetElementAt(i); searchTerm = isupports.QueryInterface(Components.interfaces.nsIMsgSearchTerm); searchTermsArray.AppendElement(searchTerm); } } createSearchTermsWithList(searchTermsArray); // now that we've added the terms, clear out our input array searchTermsArray.Clear();}function onAdvancedSearch(){ MsgSearchMessages();}function onSearchStop() { gSearchSession.interruptSearch();}function onSearchKeyPress(event){ if (gSearchInput.showingSearchCriteria) gSearchInput.showingSearchCriteria = false; // 13 == return if (event && event.keyCode == 13) onSearchInput(true);}function onSearchInputFocus(event){ GetSearchInput(); // search bar has focus, ...clear the showing search criteria flag if (gSearchInput.showingSearchCriteria) { gSearchInput.value = ""; gSearchInput.showingSearchCriteria = false; } if (gIgnoreFocus) // got focus via mouse click, don't need to anything else gIgnoreFocus = false; else { gSearchInput.select(); gQuickSearchFocusEl = gSearchInput; // only important that this be non-null }}function onSearchInputMousedown(event){ GetSearchInput(); if (gSearchInput.hasAttribute("focused")) { gIgnoreClick = true; // already focused, don't need to restore focus elsewhere (if the Clear button was clicked) // ##HACK## Need to check 'clearButtonHidden' because the field is blurred when it has // focus and the hidden button is clicked, in which case we want to perform the normal // onBlur function. gQuickSearchFocusEl = gSearchInput.clearButtonHidden ? gSearchInput : null; } else { gIgnoreFocus = true; gIgnoreClick = false; // save the last focused element so that focus can be restored (if the Clear button was clicked) gQuickSearchFocusEl = gLastFocusedElement; } // (if Clear button was clicked, onClearSearch() is called before onSearchInputClick())}function onSearchInputClick(event){ if (!gIgnoreClick) { gQuickSearchFocusEl = null; // ##HACK## avoid onSearchInputBlur() side effects gSearchInput.select(); // ## triggers onSearchInputBlur(), but focus returns to field } if (!gQuickSearchFocusEl) gQuickSearchFocusEl = gSearchInput; // mousedown wasn't on Clear button}function onSearchInputBlur(event){ if (!gQuickSearchFocusEl) // ignore the blur if we are in the middle of processing the clear button return; gQuickSearchFocusEl = null; if (!gSearchInput.value) gSearchInput.showingSearchCriteria = true; if (gSearchInput.showingSearchCriteria) gSearchInput.setSearchCriteriaText();}function onSearchInput(returnKeyHit){ if (gSearchInput.showingSearchCriteria && !(returnKeyHit && gSearchInput.value == "")) return; if (gSearchTimer) { clearTimeout(gSearchTimer); gSearchTimer = null; } // only select the text when the return key was hit if (returnKeyHit) { gSearchInput.select(); onEnterInSearchBar(); } else { gSearchTimer = setTimeout("onEnterInSearchBar();", 800); }}// temporary global used to make sure we restore focus to the correct element after clearing the quick search box// because clearing quick search means stealing focus.var gQuickSearchFocusEl = null; function onClearSearch(){ if (!gSearchInput.showingSearchCriteria) // ignore the text box value if it's just showing the search criteria string { Search(""); gIgnoreClick = true; // this needs to be on a timer otherwise we end up messing up the focus while the Search("") is still happening if (gQuickSearchFocusEl) // set in onSearchInputMouseDown setTimeout("restoreSearchFocusAfterClear();", 0); }}function restoreSearchFocusAfterClear(){ if (gQuickSearchFocusEl) gQuickSearchFocusEl.focus();}// called from commandglue.js in cases where the view is being changed and QS// needs to be cleared.function ClearQSIfNecessary(){ if (!gSearchInput || gSearchInput.showingSearchCriteria) return; gSearchInput.setSearchCriteriaText();}function Search(str){ viewDebug("in Search str = " + str + "gSearchInput.showingSearchCriteria = " + gSearchInput.showingSearchCriteria + "\n"); if (gSearchInput.showingSearchCriteria && str != "") return; if (str != gSearchInput.value) { gQSViewIsDirty = true; viewDebug("in Search(), setting gQSViewIsDirty true\n"); } gSearchInput.value = str; //on input does not get fired for some reason onSearchInput(true);}// helper methods for the quick search drop down menufunction changeQuickSearchMode(aMenuItem){ viewDebug("changing quick search mode\n"); // extract the label and set the search input to match it var oldSearchMode = gSearchInput.searchMode; gSearchInput.searchMode = aMenuItem.value; if (gSearchInput.value == "" || gSearchInput.showingSearchCriteria) { gSearchInput.showingSearchCriteria = true; if (gSearchInput.value) // gSearchInput.setSearchCriteriaText(); } // if the search box is empty, set showing search criteria to true so it shows up when focus moves out of the box if (!gSearchInput.value) gSearchInput.showingSearchCriteria = true; else if (gSearchInput.showingSearchCriteria) // if we are showing criteria text and the box isn't empty, change the criteria text gSearchInput.setSearchCriteriaText(); else if (oldSearchMode != gSearchInput.searchMode) // the search mode just changed so we need to redo the quick search onEnterInSearchBar();}function saveViewAsVirtualFolder(){ openNewVirtualFolderDialogWithArgs(gSearchInput.value, gSearchSession.searchTerms);}function InitQuickSearchPopup(){ // disable the create virtual folder menu item if the current radio // value is set to Find in message since you can't really create a VF from find // in message GetSearchInput(); if (!gSearchInput ||gSearchInput.value == "" || gSearchInput.showingSearchCriteria) document.getElementById('quickSearchSaveAsVirtualFolder').setAttribute('disabled', 'true'); else document.getElementById('quickSearchSaveAsVirtualFolder').removeAttribute('disabled');}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -