add support for searching twice.... clear the scope term list between every search - #33101 r=bienvenu

This commit is contained in:
alecf%netscape.com 2000-06-21 02:17:14 +00:00
Родитель 4538064bbe
Коммит e87ff45414
7 изменённых файлов: 51 добавлений и 24 удалений

Просмотреть файл

@ -39,11 +39,9 @@ interface nsIMsgSearchNotify : nsISupports
* out-of-bound way to connect a set of search terms to a datasource
*/
/**
* searchSession - the current search session that's running
* for this listener
/*
* called when a new search begins
*/
attribute nsIMsgSearchSession searchSession;
void onNewSearch();
};

Просмотреть файл

@ -70,6 +70,8 @@ interface nsIMsgSearchSession : nsISupports {
void addScopeTerm(in nsMsgSearchScopeValue attrib,
in nsIMsgFolder folder);
void clearScopes();
/* special cases for LDAP since LDAP isn't really a folderInfo */
[noscript] void AddLdapScope(in nsMsgDIRServer server);
/* void AddAllLdapScopes(XP_List* dirServerList); */

Просмотреть файл

@ -34,7 +34,6 @@ function searchOnLoad()
{
initializeSearchWidgets();
initializeSearchWindowWidgets();
setSearchScope(0);
setupDatasource();
onMore(null);
@ -55,13 +54,17 @@ function onChooseFolder(event) {
gCurrentFolder =
RDF.GetResource(event.target.id).QueryInterface(nsIMsgFolder);
setSearchScope(GetScopeForFolder(gCurrentFolder));
}
function onSearch(event)
{
gSearchSession.clearScopes();
// tell the search session what the new scope is
gSearchSession.addScopeTerm(GetScopeForFolder(gCurrentFolder),
gCurrentFolder)
gCurrentFolder);
saveSearchTerms(gSearchSession.searchTerms, gSearchSession);

Просмотреть файл

@ -74,9 +74,11 @@ function onLess(event)
// set scope on all visible searhattribute tags
function setSearchScope(scope) {
dump("Setting search scope to " + scope + "\n");
gSearchScope = scope;
var searchTermElements = gSearchTermContainer.childNodes;
if (!searchTermElements) return;
dump("..on " + searchTermElements.length + " elements.\n");
for (var i=0; i<searchTermElements.length; i++) {
searchTermElements[i].searchattribute.searchScope = scope;
}
@ -217,6 +219,11 @@ function getBooleanAnd()
return false;
}
// save the search terms from the UI back to the actual search terms
// searchTerms: nsISupportsArray of terms
// termOwner: object which can contain and create the terms
// (will be unnecessary if we just make terms creatable
// via XPCOM)
function saveSearchTerms(searchTerms, termOwner)
{
var searchTermElements =

Просмотреть файл

@ -100,19 +100,11 @@ nsMsgSearchDataSource::OnSearchHit(nsIMsgDBHdr* aMsgHdr, nsIMsgFolder *folder)
return NS_OK;
}
// for now also acts as a way of resetting the search datasource
NS_IMETHODIMP
nsMsgSearchDataSource::SetSearchSession(nsIMsgSearchSession* aSession)
nsMsgSearchDataSource::OnNewSearch()
{
mSearchSession = aSession;
return NS_OK;
}
NS_IMETHODIMP
nsMsgSearchDataSource::GetSearchSession(nsIMsgSearchSession** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
(*aResult) = mSearchSession;
NS_IF_ADDREF(*aResult);
mSearchResults->Clear();
return NS_OK;
}

Просмотреть файл

@ -63,10 +63,11 @@ NS_IMETHODIMP
nsMsgSearchSession::AddSearchTerm(nsMsgSearchAttribValue attrib,
nsMsgSearchOpValue op,
nsIMsgSearchValue * value,
PRBool BooleanAND,
PRBool BooleanANDp,
const char *arbitraryHeader)
{
nsMsgSearchTerm *pTerm = new nsMsgSearchTerm (attrib, op, value, nsMsgSearchBooleanOp::BooleanAND, arbitraryHeader);
nsMsgSearchTerm *pTerm = new nsMsgSearchTerm (attrib, op, value,
BooleanANDp ? nsMsgSearchBooleanOp::BooleanAND : nsMsgSearchBooleanOp::BooleanOR, arbitraryHeader);
if (nsnull == pTerm)
return NS_ERROR_OUT_OF_MEMORY;
m_termList->AppendElement (pTerm);
@ -153,6 +154,7 @@ nsMsgSearchSession::GetNthSearchScope(PRInt32 which,
{
// argh, does this do an addref?
nsMsgSearchScopeTerm *scopeTerm = m_scopeList.ElementAt(which);
if (!scopeTerm) return NS_ERROR_INVALID_ARG;
*scopeId = scopeTerm->m_attribute;
*folder = scopeTerm->m_folder;
NS_IF_ADDREF(*folder);
@ -191,7 +193,8 @@ nsMsgSearchSession::AddScopeTerm(nsMsgSearchScopeValue attrib,
#endif
}
if ((attrib == nsMsgSearchScope::Newsgroup || attrib == nsMsgSearchScope::OfflineNewsgroup) /* && folder->IsNews() */)
if ((attrib == nsMsgSearchScope::Newsgroup ||
attrib == nsMsgSearchScope::OfflineNewsgroup) /* && folder->IsNews() */)
{
#if 0
// Even unsubscribed newsgroups have a folderInfo, so filter them
@ -254,6 +257,12 @@ nsMsgSearchSession::AddScopeTerm(nsMsgSearchScopeValue attrib,
return err;
}
NS_IMETHODIMP nsMsgSearchSession::ClearScopes()
{
DestroyScopeList();
return NS_OK;
}
/* [noscript] void AddLdapScope (in nsMsgDIRServer server); */
NS_IMETHODIMP nsMsgSearchSession::AddLdapScope(nsMsgDIRServer * server)
{
@ -291,6 +300,17 @@ nsMsgSearchSession::AddAllScopes(nsMsgSearchScopeValue attrib)
NS_IMETHODIMP nsMsgSearchSession::Search(nsIMsgWindow *aWindow)
{
nsresult err = Initialize ();
if (m_listenerList) {
PRUint32 count;
m_listenerList->Count(&count);
for (PRUint32 i=0; i<count;i++) {
nsCOMPtr<nsIMsgSearchNotify> listener;
m_listenerList->QueryElementAt(i, NS_GET_IID(nsIMsgSearchNotify),
(void **)getter_AddRefs(listener));
if (listener)
listener->OnNewSearch();
}
}
m_window = aWindow;
if (NS_SUCCEEDED(err))
err = BeginSearching ();
@ -586,11 +606,14 @@ void nsMsgSearchSession::DestroyResultList ()
void nsMsgSearchSession::DestroyScopeList()
{
nsMsgSearchScopeTerm *scope = NULL;
for (int i = 0; i < m_scopeList.Count(); i++)
PRInt32 count = m_scopeList.Count();
for (PRInt32 i = count-1; i >= 0; i--)
{
scope = m_scopeList.ElementAt(i);
// NS_ASSERTION (scope->IsValid(), "invalid search scope");
delete scope;
m_scopeList.RemoveElementAt(i);
}
}
@ -625,7 +648,7 @@ nsresult nsMsgSearchSession::TimeSliceSerial (PRBool *aDone)
nsMsgSearchScopeTerm *scope = GetRunningScope();
if (scope)
{
nsresult err = scope->TimeSlice (aDone);
scope->TimeSlice (aDone);
if (*aDone)
{
m_idxRunningScope++;

Просмотреть файл

@ -1352,7 +1352,9 @@ nsresult nsMsgSearchScopeTerm::TimeSlice (PRBool *aDone)
nsresult nsMsgSearchScopeTerm::InitializeAdapter (nsISupportsArray *termList)
{
NS_ASSERTION (m_adapter == nsnull, "already initialized");
if (m_adapter)
return NS_OK;
nsresult err = NS_OK;
// mscott: i have added m_searchServer into this switch to take into account the user's preference