diff --git a/mozilla/toolkit/components/filepicker/content/filepicker.js b/mozilla/toolkit/components/filepicker/content/filepicker.js
index 0c85cf6eadf..69486fe150c 100644
--- a/mozilla/toolkit/components/filepicker/content/filepicker.js
+++ b/mozilla/toolkit/components/filepicker/content/filepicker.js
@@ -753,6 +753,7 @@ function gotoDirectory(directory) {
textInput.value = "";
}
textInput.focus();
+ textInput.setAttribute("autocompletesearchparam", directory.path);
sfile = directory;
}
diff --git a/mozilla/toolkit/components/filepicker/content/filepicker.xul b/mozilla/toolkit/components/filepicker/content/filepicker.xul
index f60f2ab6153..5228ccea75c 100644
--- a/mozilla/toolkit/components/filepicker/content/filepicker.xul
+++ b/mozilla/toolkit/components/filepicker/content/filepicker.xul
@@ -101,6 +101,7 @@
diff --git a/mozilla/xpfe/components/autocomplete/resources/content/autocomplete.xml b/mozilla/xpfe/components/autocomplete/resources/content/autocomplete.xml
index e41052c65cf..aeafbd3ef09 100644
--- a/mozilla/xpfe/components/autocomplete/resources/content/autocomplete.xml
+++ b/mozilla/xpfe/components/autocomplete/resources/content/autocomplete.xml
@@ -52,7 +52,8 @@
this.ifSetAttribute("disableKeyNavigation", true);
// initialize the search sessions
- this.searchSessions = this.getAttribute("searchSessions");
+ this.initSearchSessions();
+ this.initAutoCompleteSearch();
// hack to work around lack of bottom-up constructor calling
if ("initialize" in this.resultsPopup)
@@ -82,35 +83,46 @@
onget="return this.getAttribute('focused') == 'true';"/>
-
-
- for (var i in list) {
+
+
-
+ ]]>
+
+
+
+
+
0
@@ -282,10 +294,10 @@
- null
- null
- null
- null
+ ({})
+ ({})
+ ({})
+ ({})
null
0
false
@@ -300,14 +312,81 @@
null
false
+
+
= this.lastItems.length)
+ return null;
+ if (!this.lastItems[aIndex]) {
+ this.lastItems[aIndex] = {
+ value: this.lastResult.getValueAt(aIndex),
+ comment: this.lastResult.getCommentAt(aIndex),
+ className: this.lastResult.getStyleAt(aIndex),
+ param: null
+ }
+ }
+ return this.lastItems[aIndex];
}
};
listener;
@@ -414,13 +493,15 @@
+
diff --git a/mozilla/xpfe/components/filepicker/res/content/filepicker.js b/mozilla/xpfe/components/filepicker/res/content/filepicker.js
index 2d920143836..f90762b1224 100644
--- a/mozilla/xpfe/components/filepicker/res/content/filepicker.js
+++ b/mozilla/xpfe/components/filepicker/res/content/filepicker.js
@@ -311,7 +311,7 @@ function selectOnOK()
[file.path]);
promptService = Components.classes[NS_PROMPTSERVICE_CONTRACTID].getService(Components.interfaces.nsIPromptService);
- var rv = promptService.confirm(window, title, message);
+ var rv = promptService.confirm(window, confirmTitle, message);
if (rv) {
ret = nsIFilePicker.returnReplace;
retvals.directory = file.parent.path;
@@ -725,11 +725,11 @@ function gotoDirectory(directory) {
window.setCursor("auto");
- treeView.QueryInterface(nsITreeView).selection.clearSelection();
if (filePickerMode == nsIFilePicker.modeGetFolder) {
textInput.value = "";
}
textInput.focus();
+ textInput.setAttribute("autocompletesearchparam", directory.path);
sfile = directory;
}
diff --git a/mozilla/xpfe/components/filepicker/res/content/filepicker.xul b/mozilla/xpfe/components/filepicker/res/content/filepicker.xul
index c6db02c131e..594de42fb87 100644
--- a/mozilla/xpfe/components/filepicker/res/content/filepicker.xul
+++ b/mozilla/xpfe/components/filepicker/res/content/filepicker.xul
@@ -102,6 +102,7 @@
diff --git a/mozilla/xpfe/components/filepicker/src/Makefile.in b/mozilla/xpfe/components/filepicker/src/Makefile.in
index 1586905cbdd..480cbbf6ef1 100644
--- a/mozilla/xpfe/components/filepicker/src/Makefile.in
+++ b/mozilla/xpfe/components/filepicker/src/Makefile.in
@@ -60,6 +60,7 @@ REQUIRES = \
dom \
string \
locale \
+ autocomplete \
$(NULL)
CPPSRCS = \
diff --git a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp
index ce7bde4e684..a48a6b2a452 100644
--- a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp
+++ b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp
@@ -42,7 +42,7 @@
#include "nsITreeSelection.h"
#include "nsITreeColumns.h"
#include "nsITreeBoxObject.h"
-#include "nsIFile.h"
+#include "nsILocalFile.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
@@ -53,11 +53,163 @@
#include "nsDateTimeFormatCID.h"
#include "nsQuickSort.h"
#include "nsIAtom.h"
+#include "nsIAutoCompleteResult.h"
+#include "nsIAutoCompleteSearch.h"
#include "nsISimpleEnumerator.h"
+#include "nsAutoPtr.h"
#include "nsIMutableArray.h"
#include "nsWildCard.h"
+#define NS_FILECOMPLETE_CID { 0xcb60980e, 0x18a5, 0x4a77, \
+ { 0x91, 0x10, 0x81, 0x46, 0x61, 0x4c, 0xa7, 0xf0 } }
+#define NS_FILECOMPLETE_CONTRACTID "@mozilla.org/autocomplete/search;1?name=file"
+
+class nsFileResult : public nsIAutoCompleteResult
+{
+public:
+ // aSearchString is the text typed into the autocomplete widget
+ // aSearchParam is the picker's currently displayed directory
+ nsFileResult(const nsAString& aSearchString, const nsAString& aSearchParam);
+
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIAUTOCOMPLETERESULT
+
+ nsStringArray mValues;
+ nsAutoString mSearchString;
+ PRInt32 mSlashPos;
+ PRUint16 mSearchResult;
+};
+
+NS_IMPL_ISUPPORTS1(nsFileResult, nsIAutoCompleteResult)
+
+nsFileResult::nsFileResult(const nsAString& aSearchString,
+ const nsAString& aSearchParam):
+ mSearchString(aSearchString),
+ mSlashPos(mSearchString.RFindChar('/'))
+{
+ if (aSearchString.IsEmpty())
+ mSearchResult = RESULT_IGNORED;
+ else {
+ mSearchResult = RESULT_FAILURE;
+ nsCOMPtr directory;
+ nsDependentSubstring parent(Substring(mSearchString, 0, mSlashPos + 1));
+ if (mSlashPos != kNotFound)
+ NS_NewLocalFile(parent, PR_TRUE, getter_AddRefs(directory));
+ if (!directory) {
+ if (NS_FAILED(NS_NewLocalFile(aSearchParam, PR_TRUE, getter_AddRefs(directory))))
+ return;
+ if (mSlashPos > 0)
+ directory->AppendRelativePath(Substring(mSearchString, 0, mSlashPos));
+ }
+ nsCOMPtr dirEntries;
+ if (NS_FAILED(directory->GetDirectoryEntries(getter_AddRefs(dirEntries))))
+ return;
+ mSearchResult = RESULT_NOMATCH;
+ PRBool hasMore = PR_FALSE;
+ nsDependentSubstring prefix(Substring(mSearchString, mSlashPos + 1));
+ while (NS_SUCCEEDED(dirEntries->HasMoreElements(&hasMore)) && hasMore) {
+ nsCOMPtr nextItem;
+ dirEntries->GetNext(getter_AddRefs(nextItem));
+ nsCOMPtr nextFile(do_QueryInterface(nextItem));
+ nsAutoString fileName;
+ nextFile->GetLeafName(fileName);
+ if (StringBeginsWith(fileName, prefix)) {
+ fileName.Insert(parent, 0);
+ mValues.AppendString(fileName);
+ if (mSearchResult == RESULT_NOMATCH && fileName.Equals(mSearchString))
+ mSearchResult = RESULT_IGNORED;
+ else
+ mSearchResult = RESULT_SUCCESS;
+ }
+ }
+ mValues.Sort();
+ }
+}
+
+NS_IMETHODIMP nsFileResult::GetSearchString(nsAString & aSearchString)
+{
+ aSearchString.Assign(mSearchString);
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetSearchResult(PRUint16 *aSearchResult)
+{
+ NS_ENSURE_ARG_POINTER(aSearchResult);
+ *aSearchResult = mSearchResult;
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetDefaultIndex(PRInt32 *aDefaultIndex)
+{
+ NS_ENSURE_ARG_POINTER(aDefaultIndex);
+ *aDefaultIndex = -1;
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetErrorDescription(nsAString & aErrorDescription)
+{
+ aErrorDescription.Truncate();
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetMatchCount(PRUint32 *aMatchCount)
+{
+ NS_ENSURE_ARG_POINTER(aMatchCount);
+ *aMatchCount = mValues.Count();
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetValueAt(PRInt32 index, nsAString & aValue)
+{
+ mValues.StringAt(index, aValue);
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetCommentAt(PRInt32 index, nsAString & aComment)
+{
+ aComment.Truncate();
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::GetStyleAt(PRInt32 index, nsAString & aStyle)
+{
+ aStyle.Truncate();
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsFileResult::RemoveValueAt(PRInt32 rowIndex, PRBool removeFromDb)
+{
+ return NS_OK;
+}
+
+class nsFileComplete : public nsIAutoCompleteSearch
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIAUTOCOMPLETESEARCH
+};
+
+NS_IMPL_ISUPPORTS1(nsFileComplete, nsIAutoCompleteSearch)
+
+NS_IMETHODIMP
+nsFileComplete::StartSearch(const nsAString& aSearchString,
+ const nsAString& aSearchParam,
+ nsIAutoCompleteResult *aPreviousResult,
+ nsIAutoCompleteObserver *aListener)
+{
+ NS_ENSURE_ARG_POINTER(aListener);
+ nsRefPtr result = new nsFileResult(aSearchString, aSearchParam);
+ NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
+ return aListener->OnSearchResult(this, result);
+}
+
+NS_IMETHODIMP
+nsFileComplete::StopSearch()
+{
+ return NS_OK;
+}
+
#define NS_FILEVIEW_CID { 0xa5570462, 0x1dd1, 0x11b2, \
{ 0x9d, 0x19, 0xdf, 0x30, 0xa2, 0x7f, 0xbd, 0xc4 } }
@@ -104,10 +256,13 @@ protected:
};
// Factory constructor
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileComplete)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFileView, Init)
static const nsModuleComponentInfo components[] =
{
+ { "nsFileComplete", NS_FILECOMPLETE_CID,
+ NS_FILECOMPLETE_CONTRACTID, nsFileCompleteConstructor },
{ "nsFileView", NS_FILEVIEW_CID,
NS_FILEVIEW_CONTRACTID, nsFileViewConstructor }
};
@@ -190,6 +345,11 @@ nsFileView::SetShowOnlyDirectories(PRBool aOnlyDirs)
} else {
// Run the filter again to get the file list back
FilterFiles();
+
+ SortArray(mFilteredFiles);
+ if (mReverseSort)
+ ReverseArray(mFilteredFiles);
+
if (mTree)
mTree->RowCountChanged(dirCount, mTotalRows - dirCount);
}