2001-11-01 10:54:40 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** 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.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2006-03-30 11:57:05 +04:00
|
|
|
* Netscape Communications Corporation.
|
2001-11-01 10:54:40 +03:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-09-29 10:04:02 +04:00
|
|
|
* Brian Ryner <bryner@brianryner.com>
|
2001-11-01 10:54:40 +03:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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 ***** */
|
|
|
|
|
|
|
|
#include "nsIFileView.h"
|
2002-03-29 05:46:01 +03:00
|
|
|
#include "nsITreeView.h"
|
2010-06-13 04:50:56 +04:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2002-03-29 05:46:01 +03:00
|
|
|
#include "nsITreeSelection.h"
|
2004-04-17 09:53:38 +04:00
|
|
|
#include "nsITreeColumns.h"
|
2002-03-29 05:46:01 +03:00
|
|
|
#include "nsITreeBoxObject.h"
|
2006-04-13 03:00:52 +04:00
|
|
|
#include "nsILocalFile.h"
|
2001-11-01 10:54:40 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2001-11-01 10:54:40 +03:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "nsIDateTimeFormat.h"
|
|
|
|
#include "nsDateTimeFormatCID.h"
|
|
|
|
#include "nsQuickSort.h"
|
2002-07-25 22:31:10 +04:00
|
|
|
#include "nsIAtom.h"
|
2006-04-13 03:00:52 +04:00
|
|
|
#include "nsIAutoCompleteResult.h"
|
|
|
|
#include "nsIAutoCompleteSearch.h"
|
2003-03-16 12:20:40 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2006-04-13 03:00:52 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2006-04-12 19:43:32 +04:00
|
|
|
#include "nsIMutableArray.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
#include "nsWildCard.h"
|
|
|
|
|
2009-06-24 21:12:33 +04:00
|
|
|
class nsIDOMDataTransfer;
|
|
|
|
|
2006-04-13 03:00:52 +04:00
|
|
|
#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
|
|
|
|
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString> mValues;
|
2006-04-13 03:00:52 +04:00
|
|
|
nsAutoString mSearchString;
|
|
|
|
PRUint16 mSearchResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsFileResult, nsIAutoCompleteResult)
|
|
|
|
|
|
|
|
nsFileResult::nsFileResult(const nsAString& aSearchString,
|
|
|
|
const nsAString& aSearchParam):
|
2006-09-11 17:10:06 +04:00
|
|
|
mSearchString(aSearchString)
|
2006-04-13 03:00:52 +04:00
|
|
|
{
|
|
|
|
if (aSearchString.IsEmpty())
|
|
|
|
mSearchResult = RESULT_IGNORED;
|
|
|
|
else {
|
2006-09-11 17:10:06 +04:00
|
|
|
PRInt32 slashPos = mSearchString.RFindChar('/');
|
2006-04-13 03:00:52 +04:00
|
|
|
mSearchResult = RESULT_FAILURE;
|
|
|
|
nsCOMPtr<nsILocalFile> directory;
|
2006-09-11 17:10:06 +04:00
|
|
|
nsDependentSubstring parent(Substring(mSearchString, 0, slashPos + 1));
|
|
|
|
if (!parent.IsEmpty() && parent.First() == '/')
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewLocalFile(parent, true, getter_AddRefs(directory));
|
2006-04-13 03:00:52 +04:00
|
|
|
if (!directory) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (NS_FAILED(NS_NewLocalFile(aSearchParam, true, getter_AddRefs(directory))))
|
2006-04-13 03:00:52 +04:00
|
|
|
return;
|
2006-09-11 17:10:06 +04:00
|
|
|
if (slashPos > 0)
|
|
|
|
directory->AppendRelativePath(Substring(mSearchString, 0, slashPos));
|
2006-04-13 03:00:52 +04:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> dirEntries;
|
|
|
|
if (NS_FAILED(directory->GetDirectoryEntries(getter_AddRefs(dirEntries))))
|
|
|
|
return;
|
|
|
|
mSearchResult = RESULT_NOMATCH;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore = false;
|
2006-09-11 17:10:06 +04:00
|
|
|
nsDependentSubstring prefix(Substring(mSearchString, slashPos + 1));
|
2006-04-13 03:00:52 +04:00
|
|
|
while (NS_SUCCEEDED(dirEntries->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> nextItem;
|
|
|
|
dirEntries->GetNext(getter_AddRefs(nextItem));
|
|
|
|
nsCOMPtr<nsILocalFile> nextFile(do_QueryInterface(nextItem));
|
|
|
|
nsAutoString fileName;
|
|
|
|
nextFile->GetLeafName(fileName);
|
|
|
|
if (StringBeginsWith(fileName, prefix)) {
|
|
|
|
fileName.Insert(parent, 0);
|
2009-01-18 23:14:14 +03:00
|
|
|
mValues.AppendElement(fileName);
|
2006-04-13 03:00:52 +04:00
|
|
|
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);
|
2009-01-18 23:14:14 +03:00
|
|
|
*aMatchCount = mValues.Length();
|
2006-04-13 03:00:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsFileResult::GetValueAt(PRInt32 index, nsAString & aValue)
|
|
|
|
{
|
2009-01-18 23:14:14 +03:00
|
|
|
aValue = mValues[index];
|
2006-04-13 03:00:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:19:20 +04:00
|
|
|
NS_IMETHODIMP nsFileResult::GetLabelAt(PRInt32 index, nsAString & aValue)
|
|
|
|
{
|
|
|
|
return GetValueAt(index, aValue);
|
|
|
|
}
|
|
|
|
|
2006-04-13 03:00:52 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-07-21 01:55:18 +04:00
|
|
|
NS_IMETHODIMP nsFileResult::GetImageAt(PRInt32 index, nsAString & aImage)
|
|
|
|
{
|
|
|
|
aImage.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsFileResult::RemoveValueAt(PRInt32 rowIndex, bool removeFromDb)
|
2006-04-13 03:00:52 +04:00
|
|
|
{
|
|
|
|
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<nsFileResult> 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;
|
|
|
|
}
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
#define NS_FILEVIEW_CID { 0xa5570462, 0x1dd1, 0x11b2, \
|
|
|
|
{ 0x9d, 0x19, 0xdf, 0x30, 0xa2, 0x7f, 0xbd, 0xc4 } }
|
|
|
|
|
|
|
|
class nsFileView : public nsIFileView,
|
2002-03-29 05:46:01 +03:00
|
|
|
public nsITreeView
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsFileView();
|
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFILEVIEW
|
2002-03-29 05:46:01 +03:00
|
|
|
NS_DECL_NSITREEVIEW
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsFileView();
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
void FilterFiles();
|
2001-11-01 10:54:40 +03:00
|
|
|
void ReverseArray(nsISupportsArray* aArray);
|
|
|
|
void SortArray(nsISupportsArray* aArray);
|
|
|
|
void SortInternal();
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> mFileList;
|
|
|
|
nsCOMPtr<nsISupportsArray> mDirList;
|
|
|
|
nsCOMPtr<nsISupportsArray> mFilteredFiles;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> mDirectoryPath;
|
2002-03-29 05:46:01 +03:00
|
|
|
nsCOMPtr<nsITreeBoxObject> mTree;
|
|
|
|
nsCOMPtr<nsITreeSelection> mSelection;
|
2001-11-01 10:54:40 +03:00
|
|
|
nsCOMPtr<nsIAtom> mDirectoryAtom;
|
|
|
|
nsCOMPtr<nsIAtom> mFileAtom;
|
|
|
|
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
|
|
|
|
|
|
|
|
PRInt16 mSortType;
|
|
|
|
PRInt32 mTotalRows;
|
|
|
|
|
2009-02-25 18:25:10 +03:00
|
|
|
nsTArray<PRUnichar*> mCurrentFilters;
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mShowHiddenFiles;
|
|
|
|
bool mDirectoryFilter;
|
|
|
|
bool mReverseSort;
|
2001-11-01 10:54:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Factory constructor
|
2006-04-13 03:00:52 +04:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileComplete)
|
2001-11-01 10:54:40 +03:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFileView, Init)
|
2010-06-13 04:50:56 +04:00
|
|
|
NS_DEFINE_NAMED_CID(NS_FILECOMPLETE_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_FILEVIEW_CID);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2010-06-13 04:50:56 +04:00
|
|
|
static const mozilla::Module::CIDEntry kFileViewCIDs[] = {
|
|
|
|
{ &kNS_FILECOMPLETE_CID, false, NULL, nsFileCompleteConstructor },
|
|
|
|
{ &kNS_FILEVIEW_CID, false, NULL, nsFileViewConstructor },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::ContractIDEntry kFileViewContracts[] = {
|
|
|
|
{ NS_FILECOMPLETE_CONTRACTID, &kNS_FILECOMPLETE_CID },
|
|
|
|
{ NS_FILEVIEW_CONTRACTID, &kNS_FILEVIEW_CID },
|
|
|
|
{ NULL }
|
2001-11-01 10:54:40 +03:00
|
|
|
};
|
|
|
|
|
2010-06-13 04:50:56 +04:00
|
|
|
static const mozilla::Module kFileViewModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kFileViewCIDs,
|
|
|
|
kFileViewContracts
|
|
|
|
};
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2010-06-13 04:50:56 +04:00
|
|
|
NSMODULE_DEFN(nsFileViewModule) = &kFileViewModule;
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
nsFileView::nsFileView() :
|
|
|
|
mSortType(-1),
|
|
|
|
mTotalRows(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mShowHiddenFiles(false),
|
|
|
|
mDirectoryFilter(false),
|
|
|
|
mReverseSort(false)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFileView::~nsFileView()
|
|
|
|
{
|
2009-02-25 18:25:10 +03:00
|
|
|
PRUint32 count = mCurrentFilters.Length();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i)
|
2008-02-10 07:21:17 +03:00
|
|
|
NS_Free(mCurrentFilters[i]);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFileView::Init()
|
|
|
|
{
|
2003-07-24 08:53:13 +04:00
|
|
|
mDirectoryAtom = do_GetAtom("directory");
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mDirectoryAtom)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2003-07-24 08:53:13 +04:00
|
|
|
mFileAtom = do_GetAtom("file");
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mFileAtom)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
NS_NewISupportsArray(getter_AddRefs(mFileList));
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mFileList)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
NS_NewISupportsArray(getter_AddRefs(mDirList));
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mDirList)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
NS_NewISupportsArray(getter_AddRefs(mFilteredFiles));
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mFilteredFiles)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2006-06-04 03:35:59 +04:00
|
|
|
mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID);
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mDateFormatter)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports implementation
|
|
|
|
|
2003-09-08 04:31:50 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(nsFileView, nsITreeView, nsIFileView)
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
// nsIFileView implementation
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::SetShowHiddenFiles(bool aShowHidden)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2001-11-01 23:21:22 +03:00
|
|
|
if (aShowHidden != mShowHiddenFiles) {
|
|
|
|
mShowHiddenFiles = aShowHidden;
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2001-11-01 23:21:22 +03:00
|
|
|
// This could be better optimized, but since the hidden
|
|
|
|
// file functionality is not currently used, this will be fine.
|
|
|
|
SetDirectory(mDirectoryPath);
|
|
|
|
}
|
2001-11-01 23:28:20 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::GetShowHiddenFiles(bool* aShowHidden)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
*aShowHidden = mShowHiddenFiles;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::SetShowOnlyDirectories(bool aOnlyDirs)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
if (aOnlyDirs == mDirectoryFilter)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mDirectoryFilter = aOnlyDirs;
|
|
|
|
PRUint32 dirCount;
|
|
|
|
mDirList->Count(&dirCount);
|
|
|
|
if (mDirectoryFilter) {
|
|
|
|
PRInt32 rowDiff = mTotalRows - dirCount;
|
|
|
|
|
|
|
|
mFilteredFiles->Clear();
|
|
|
|
mTotalRows = dirCount;
|
2002-03-29 05:46:01 +03:00
|
|
|
if (mTree)
|
|
|
|
mTree->RowCountChanged(mTotalRows, -rowDiff);
|
2001-11-01 10:54:40 +03:00
|
|
|
} else {
|
|
|
|
// Run the filter again to get the file list back
|
2003-10-21 16:00:49 +04:00
|
|
|
FilterFiles();
|
2006-04-13 03:00:52 +04:00
|
|
|
|
|
|
|
SortArray(mFilteredFiles);
|
|
|
|
if (mReverseSort)
|
|
|
|
ReverseArray(mFilteredFiles);
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
if (mTree)
|
|
|
|
mTree->RowCountChanged(dirCount, mTotalRows - dirCount);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::GetShowOnlyDirectories(bool* aOnlyDirs)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
*aOnlyDirs = mDirectoryFilter;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::GetSortType(PRInt16* aSortType)
|
|
|
|
{
|
|
|
|
*aSortType = mSortType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::GetReverseSort(bool* aReverseSort)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
*aReverseSort = mReverseSort;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::Sort(PRInt16 aSortType, bool aReverseSort)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
if (aSortType == mSortType) {
|
2009-06-11 21:47:35 +04:00
|
|
|
if (aReverseSort == mReverseSort)
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
2009-06-11 21:47:35 +04:00
|
|
|
|
|
|
|
mReverseSort = aReverseSort;
|
|
|
|
ReverseArray(mDirList);
|
|
|
|
ReverseArray(mFilteredFiles);
|
2001-11-01 10:54:40 +03:00
|
|
|
} else {
|
|
|
|
mSortType = aSortType;
|
|
|
|
mReverseSort = aReverseSort;
|
|
|
|
SortInternal();
|
|
|
|
}
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
if (mTree)
|
|
|
|
mTree->Invalidate();
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::SetDirectory(nsIFile* aDirectory)
|
|
|
|
{
|
2009-06-11 21:47:35 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aDirectory);
|
|
|
|
|
2001-11-28 02:02:07 +03:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> dirEntries;
|
|
|
|
aDirectory->GetDirectoryEntries(getter_AddRefs(dirEntries));
|
|
|
|
|
|
|
|
if (!dirEntries) {
|
|
|
|
// Couldn't read in the directory, this can happen if the user does not
|
|
|
|
// have permission to list it.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
mDirectoryPath = aDirectory;
|
|
|
|
mFileList->Clear();
|
|
|
|
mDirList->Clear();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
while (NS_SUCCEEDED(dirEntries->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> nextItem;
|
|
|
|
dirEntries->GetNext(getter_AddRefs(nextItem));
|
|
|
|
nsCOMPtr<nsIFile> theFile = do_QueryInterface(nextItem);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDirectory = false;
|
2009-06-11 21:47:35 +04:00
|
|
|
if (theFile) {
|
|
|
|
theFile->IsDirectory(&isDirectory);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2009-06-11 21:47:35 +04:00
|
|
|
if (isDirectory) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHidden;
|
2009-06-11 21:47:35 +04:00
|
|
|
theFile->IsHidden(&isHidden);
|
|
|
|
if (mShowHiddenFiles || !isHidden) {
|
|
|
|
mDirList->AppendElement(theFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFileList->AppendElement(theFile);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
if (mTree) {
|
|
|
|
mTree->BeginUpdateBatch();
|
|
|
|
mTree->RowCountChanged(0, -mTotalRows);
|
|
|
|
}
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
FilterFiles();
|
|
|
|
SortInternal();
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
if (mTree) {
|
2003-10-21 16:00:49 +04:00
|
|
|
mTree->EndUpdateBatch();
|
2002-03-29 05:46:01 +03:00
|
|
|
mTree->ScrollToRow(0);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-02-10 07:21:17 +03:00
|
|
|
nsFileView::SetFilter(const nsAString& aFilterString)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2009-02-25 18:25:10 +03:00
|
|
|
PRUint32 filterCount = mCurrentFilters.Length();
|
|
|
|
for (PRUint32 i = 0; i < filterCount; ++i)
|
2008-02-10 07:21:17 +03:00
|
|
|
NS_Free(mCurrentFilters[i]);
|
2001-11-01 10:54:40 +03:00
|
|
|
mCurrentFilters.Clear();
|
2008-02-10 07:21:17 +03:00
|
|
|
|
|
|
|
nsAString::const_iterator start, iter, end;
|
|
|
|
aFilterString.BeginReading(iter);
|
|
|
|
aFilterString.EndReading(end);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
while (true) {
|
2008-02-10 07:21:17 +03:00
|
|
|
// skip over delimiters
|
|
|
|
while (iter != end && (*iter == ';' || *iter == ' '))
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
if (iter == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
start = iter; // start of a filter
|
|
|
|
|
|
|
|
// we know this is neither ';' nor ' ', skip to next char
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
// find next delimiter or end of string
|
|
|
|
while (iter != end && (*iter != ';' && *iter != ' '))
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
PRUnichar* filter = ToNewUnicode(Substring(start, iter));
|
|
|
|
if (!filter)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (!mCurrentFilters.AppendElement(filter)) {
|
|
|
|
NS_Free(filter);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
2008-02-10 07:21:17 +03:00
|
|
|
if (iter == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
++iter; // we know this is either ';' or ' ', skip to next char
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
if (mTree) {
|
|
|
|
mTree->BeginUpdateBatch();
|
|
|
|
PRUint32 count;
|
|
|
|
mDirList->Count(&count);
|
|
|
|
mTree->RowCountChanged(count, count - mTotalRows);
|
|
|
|
}
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
mFilteredFiles->Clear();
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
FilterFiles();
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
SortArray(mFilteredFiles);
|
|
|
|
if (mReverseSort)
|
|
|
|
ReverseArray(mFilteredFiles);
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
if (mTree)
|
|
|
|
mTree->EndUpdateBatch();
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-03-16 12:20:40 +03:00
|
|
|
nsFileView::GetSelectedFiles(nsIArray** aFiles)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2003-03-16 12:20:40 +03:00
|
|
|
*aFiles = nsnull;
|
2009-06-11 21:47:35 +04:00
|
|
|
if (!mSelection)
|
|
|
|
return NS_OK;
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2003-03-16 12:20:40 +03:00
|
|
|
PRInt32 numRanges;
|
|
|
|
mSelection->GetRangeCount(&numRanges);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2003-03-16 12:20:40 +03:00
|
|
|
PRUint32 dirCount;
|
|
|
|
mDirList->Count(&dirCount);
|
|
|
|
|
2006-04-12 19:43:32 +04:00
|
|
|
nsCOMPtr<nsIMutableArray> fileArray =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(fileArray);
|
2003-03-16 12:20:40 +03:00
|
|
|
|
|
|
|
for (PRInt32 range = 0; range < numRanges; ++range) {
|
|
|
|
PRInt32 rangeBegin, rangeEnd;
|
|
|
|
mSelection->GetRangeAt(range, &rangeBegin, &rangeEnd);
|
|
|
|
|
|
|
|
for (PRInt32 itemIndex = rangeBegin; itemIndex <= rangeEnd; ++itemIndex) {
|
|
|
|
nsCOMPtr<nsIFile> curFile;
|
|
|
|
|
|
|
|
if (itemIndex < (PRInt32) dirCount)
|
|
|
|
curFile = do_QueryElementAt(mDirList, itemIndex);
|
|
|
|
else {
|
|
|
|
if (itemIndex < mTotalRows)
|
|
|
|
curFile = do_QueryElementAt(mFilteredFiles, itemIndex - dirCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curFile)
|
2011-10-17 18:59:28 +04:00
|
|
|
fileArray->AppendElement(curFile, false);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-12 19:43:32 +04:00
|
|
|
NS_ADDREF(*aFiles = fileArray);
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
// nsITreeView implementation
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::GetRowCount(PRInt32* aRowCount)
|
|
|
|
{
|
|
|
|
*aRowCount = mTotalRows;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-29 05:46:01 +03:00
|
|
|
nsFileView::GetSelection(nsITreeSelection** aSelection)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
*aSelection = mSelection;
|
|
|
|
NS_IF_ADDREF(*aSelection);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-29 05:46:01 +03:00
|
|
|
nsFileView::SetSelection(nsITreeSelection* aSelection)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
mSelection = aSelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::GetRowProperties(PRInt32 aIndex,
|
|
|
|
nsISupportsArray* aProperties)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::GetCellProperties(PRInt32 aRow, nsITreeColumn* aCol,
|
2001-11-01 10:54:40 +03:00
|
|
|
nsISupportsArray* aProperties)
|
|
|
|
{
|
|
|
|
PRUint32 dirCount;
|
|
|
|
mDirList->Count(&dirCount);
|
|
|
|
|
|
|
|
if (aRow < (PRInt32) dirCount)
|
|
|
|
aProperties->AppendElement(mDirectoryAtom);
|
2001-11-01 23:21:22 +03:00
|
|
|
else if (aRow < mTotalRows)
|
2001-11-01 10:54:40 +03:00
|
|
|
aProperties->AppendElement(mFileAtom);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::GetColumnProperties(nsITreeColumn* aCol,
|
2001-11-01 10:54:40 +03:00
|
|
|
nsISupportsArray* aProperties)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::IsContainer(PRInt32 aIndex, bool* aIsContainer)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsContainer = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::IsContainerOpen(PRInt32 aIndex, bool* aIsOpen)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsOpen = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::IsContainerEmpty(PRInt32 aIndex, bool* aIsEmpty)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsEmpty = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::IsSeparator(PRInt32 aIndex, bool* aIsSeparator)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsSeparator = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileView::IsSorted(bool* aIsSorted)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
*aIsSorted = (mSortType >= 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-06-24 21:12:33 +04:00
|
|
|
nsFileView::CanDrop(PRInt32 aIndex, PRInt32 aOrientation,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIDOMDataTransfer* dataTransfer, bool* aCanDrop)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aCanDrop = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-06-24 21:12:33 +04:00
|
|
|
nsFileView::Drop(PRInt32 aRow, PRInt32 aOrientation, nsIDOMDataTransfer* dataTransfer)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::GetParentIndex(PRInt32 aRowIndex, PRInt32* aParentIndex)
|
|
|
|
{
|
|
|
|
*aParentIndex = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::HasNextSibling(PRInt32 aRowIndex, PRInt32 aAfterIndex,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aHasSibling)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
*aHasSibling = (aAfterIndex < (mTotalRows - 1));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::GetLevel(PRInt32 aIndex, PRInt32* aLevel)
|
|
|
|
{
|
|
|
|
*aLevel = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::GetImageSrc(PRInt32 aRow, nsITreeColumn* aCol,
|
2002-03-29 05:46:01 +03:00
|
|
|
nsAString& aImageSrc)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::GetProgressMode(PRInt32 aRow, nsITreeColumn* aCol,
|
2002-03-29 05:46:01 +03:00
|
|
|
PRInt32* aProgressMode)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::GetCellValue(PRInt32 aRow, nsITreeColumn* aCol,
|
2002-03-29 05:46:01 +03:00
|
|
|
nsAString& aCellValue)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol,
|
2001-12-30 01:05:16 +03:00
|
|
|
nsAString& aCellText)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
PRUint32 dirCount, fileCount;
|
|
|
|
mDirList->Count(&dirCount);
|
|
|
|
mFilteredFiles->Count(&fileCount);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDirectory;
|
2001-11-01 10:54:40 +03:00
|
|
|
nsCOMPtr<nsIFile> curFile;
|
|
|
|
|
|
|
|
if (aRow < (PRInt32) dirCount) {
|
2011-10-17 18:59:28 +04:00
|
|
|
isDirectory = true;
|
2001-11-01 10:54:40 +03:00
|
|
|
curFile = do_QueryElementAt(mDirList, aRow);
|
2001-11-01 23:21:22 +03:00
|
|
|
} else if (aRow < mTotalRows) {
|
2011-10-17 18:59:28 +04:00
|
|
|
isDirectory = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
curFile = do_QueryElementAt(mFilteredFiles, aRow - dirCount);
|
|
|
|
} else {
|
|
|
|
// invalid row
|
2001-12-30 01:05:16 +03:00
|
|
|
aCellText.SetCapacity(0);
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-17 09:53:38 +04:00
|
|
|
const PRUnichar* colID;
|
|
|
|
aCol->GetIdConst(&colID);
|
|
|
|
if (NS_LITERAL_STRING("FilenameColumn").Equals(colID)) {
|
2002-05-08 03:07:19 +04:00
|
|
|
curFile->GetLeafName(aCellText);
|
2004-04-17 09:53:38 +04:00
|
|
|
} else if (NS_LITERAL_STRING("LastModifiedColumn").Equals(colID)) {
|
2001-11-02 01:35:59 +03:00
|
|
|
PRInt64 lastModTime;
|
2001-11-26 11:05:05 +03:00
|
|
|
curFile->GetLastModifiedTime(&lastModTime);
|
2001-12-30 01:05:16 +03:00
|
|
|
// XXX FormatPRTime could take an nsAString&
|
|
|
|
nsAutoString temp;
|
2001-11-01 10:54:40 +03:00
|
|
|
mDateFormatter->FormatPRTime(nsnull, kDateFormatShort, kTimeFormatSeconds,
|
2001-12-30 01:05:16 +03:00
|
|
|
lastModTime * 1000, temp);
|
|
|
|
aCellText = temp;
|
2001-11-01 23:21:22 +03:00
|
|
|
} else {
|
|
|
|
// file size
|
2001-11-01 10:54:40 +03:00
|
|
|
if (isDirectory)
|
2001-12-30 01:05:16 +03:00
|
|
|
aCellText.SetCapacity(0);
|
2001-11-01 10:54:40 +03:00
|
|
|
else {
|
|
|
|
PRInt64 fileSize;
|
|
|
|
curFile->GetFileSize(&fileSize);
|
2004-09-17 15:12:14 +04:00
|
|
|
CopyUTF8toUTF16(nsPrintfCString("%lld", fileSize), aCellText);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
2001-11-01 23:21:22 +03:00
|
|
|
}
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-29 05:46:01 +03:00
|
|
|
nsFileView::SetTree(nsITreeBoxObject* aTree)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
mTree = aTree;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::ToggleOpenState(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::CycleHeader(nsITreeColumn* aCol)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::SelectionChanged()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::CycleCell(PRInt32 aRow, nsITreeColumn* aCol)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::IsEditable(PRInt32 aRow, nsITreeColumn* aCol,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aIsEditable)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsEditable = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-07 00:05:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::IsSelectable(PRInt32 aRow, nsITreeColumn* aCol,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aIsSelectable)
|
2006-06-07 00:05:13 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsSelectable = false;
|
2006-06-07 00:05:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-01 10:54:40 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-17 09:53:38 +04:00
|
|
|
nsFileView::SetCellValue(PRInt32 aRow, nsITreeColumn* aCol,
|
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::SetCellText(PRInt32 aRow, nsITreeColumn* aCol,
|
|
|
|
const nsAString& aValue)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::PerformAction(const PRUnichar* aAction)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::PerformActionOnRow(const PRUnichar* aAction, PRInt32 aRow)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileView::PerformActionOnCell(const PRUnichar* aAction, PRInt32 aRow,
|
2004-04-17 09:53:38 +04:00
|
|
|
nsITreeColumn* aCol)
|
2001-11-01 10:54:40 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods
|
|
|
|
|
2003-10-21 16:00:49 +04:00
|
|
|
void
|
2001-11-01 10:54:40 +03:00
|
|
|
nsFileView::FilterFiles()
|
|
|
|
{
|
2003-10-21 16:00:49 +04:00
|
|
|
PRUint32 count = 0;
|
|
|
|
mDirList->Count(&count);
|
|
|
|
mTotalRows = count;
|
2001-11-01 10:54:40 +03:00
|
|
|
mFileList->Count(&count);
|
|
|
|
mFilteredFiles->Clear();
|
2009-02-25 18:25:10 +03:00
|
|
|
PRUint32 filterCount = mCurrentFilters.Length();
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2001-11-01 23:21:22 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2001-11-01 10:54:40 +03:00
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
2001-11-01 23:21:22 +03:00
|
|
|
file = do_QueryElementAt(mFileList, i);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHidden = false;
|
2001-11-01 10:54:40 +03:00
|
|
|
if (!mShowHiddenFiles)
|
2001-11-01 23:21:22 +03:00
|
|
|
file->IsHidden(&isHidden);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2002-05-08 03:07:19 +04:00
|
|
|
nsAutoString ucsLeafName;
|
|
|
|
if(NS_FAILED(file->GetLeafName(ucsLeafName))) {
|
2002-04-27 09:33:09 +04:00
|
|
|
// need to check return value for GetLeafName()
|
2002-04-09 05:54:09 +04:00
|
|
|
continue;
|
|
|
|
}
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
if (!isHidden) {
|
2009-02-25 18:25:10 +03:00
|
|
|
for (PRUint32 j = 0; j < filterCount; ++j) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool matched = false;
|
2009-02-25 18:25:10 +03:00
|
|
|
if (!nsCRT::strcmp(mCurrentFilters.ElementAt(j),
|
2002-07-07 11:21:45 +04:00
|
|
|
NS_LITERAL_STRING("..apps").get()))
|
|
|
|
{
|
|
|
|
file->IsExecutable(&matched);
|
|
|
|
} else
|
|
|
|
matched = (NS_WildCardMatch(ucsLeafName.get(),
|
2009-02-25 18:25:10 +03:00
|
|
|
mCurrentFilters.ElementAt(j),
|
2011-10-17 18:59:28 +04:00
|
|
|
true) == MATCH);
|
2002-07-07 11:21:45 +04:00
|
|
|
|
|
|
|
if (matched) {
|
2001-11-01 23:21:22 +03:00
|
|
|
mFilteredFiles->AppendElement(file);
|
2003-10-21 16:00:49 +04:00
|
|
|
++mTotalRows;
|
2001-11-01 10:54:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFileView::ReverseArray(nsISupportsArray* aArray)
|
|
|
|
{
|
|
|
|
PRUint32 count;
|
|
|
|
aArray->Count(&count);
|
|
|
|
for (PRUint32 i = 0; i < count/2; ++i) {
|
|
|
|
nsCOMPtr<nsISupports> element = dont_AddRef(aArray->ElementAt(i));
|
|
|
|
nsCOMPtr<nsISupports> element2 = dont_AddRef(aArray->ElementAt(count-i-1));
|
|
|
|
aArray->ReplaceElementAt(element2, i);
|
|
|
|
aArray->ReplaceElementAt(element, count-i-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static int
|
2001-11-01 10:54:40 +03:00
|
|
|
SortNameCallback(const void* aElement1, const void* aElement2, void* aContext)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIFile* file1 = *static_cast<nsIFile* const *>(aElement1);
|
|
|
|
nsIFile* file2 = *static_cast<nsIFile* const *>(aElement2);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2002-05-08 03:07:19 +04:00
|
|
|
nsAutoString leafName1, leafName2;
|
2002-04-27 09:33:09 +04:00
|
|
|
file1->GetLeafName(leafName1);
|
|
|
|
file2->GetLeafName(leafName2);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
return Compare(leafName1, leafName2);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static int
|
2001-11-01 10:54:40 +03:00
|
|
|
SortSizeCallback(const void* aElement1, const void* aElement2, void* aContext)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIFile* file1 = *static_cast<nsIFile* const *>(aElement1);
|
|
|
|
nsIFile* file2 = *static_cast<nsIFile* const *>(aElement2);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
PRInt64 size1, size2;
|
|
|
|
file1->GetFileSize(&size1);
|
|
|
|
file2->GetFileSize(&size2);
|
|
|
|
|
|
|
|
if (LL_EQ(size1, size2))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (LL_CMP(size1, <, size2) ? -1 : 1);
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static int
|
2001-11-01 10:54:40 +03:00
|
|
|
SortDateCallback(const void* aElement1, const void* aElement2, void* aContext)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIFile* file1 = *static_cast<nsIFile* const *>(aElement1);
|
|
|
|
nsIFile* file2 = *static_cast<nsIFile* const *>(aElement2);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2001-11-02 01:35:59 +03:00
|
|
|
PRInt64 time1, time2;
|
2001-11-26 11:05:05 +03:00
|
|
|
file1->GetLastModifiedTime(&time1);
|
|
|
|
file2->GetLastModifiedTime(&time2);
|
2001-11-01 10:54:40 +03:00
|
|
|
|
2001-11-02 01:35:59 +03:00
|
|
|
if (LL_EQ(time1, time2))
|
2001-11-01 10:54:40 +03:00
|
|
|
return 0;
|
|
|
|
|
2001-11-02 01:35:59 +03:00
|
|
|
return (LL_CMP(time1, <, time2) ? -1 : 1);
|
2001-11-01 10:54:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFileView::SortArray(nsISupportsArray* aArray)
|
|
|
|
{
|
|
|
|
// We assume the array to be in filesystem order, which
|
|
|
|
// for our purposes, is completely unordered.
|
|
|
|
|
|
|
|
int (*compareFunc)(const void*, const void*, void*);
|
|
|
|
|
|
|
|
switch (mSortType) {
|
|
|
|
case sortName:
|
|
|
|
compareFunc = SortNameCallback;
|
|
|
|
break;
|
|
|
|
case sortSize:
|
|
|
|
compareFunc = SortSizeCallback;
|
|
|
|
break;
|
|
|
|
case sortDate:
|
|
|
|
compareFunc = SortDateCallback;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
aArray->Count(&count);
|
|
|
|
|
|
|
|
// each item will have an additional refcount while
|
|
|
|
// the array is alive.
|
|
|
|
nsIFile** array = new nsIFile*[count];
|
|
|
|
PRUint32 i;
|
2001-11-01 23:21:22 +03:00
|
|
|
for (i = 0; i < count; ++i)
|
2001-11-01 23:28:20 +03:00
|
|
|
aArray->QueryElementAt(i, NS_GET_IID(nsIFile), (void**)&(array[i]));
|
2001-11-01 10:54:40 +03:00
|
|
|
|
|
|
|
NS_QuickSort(array, count, sizeof(nsIFile*), compareFunc, nsnull);
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
aArray->ReplaceElementAt(array[i], i);
|
|
|
|
NS_RELEASE(array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] array;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFileView::SortInternal()
|
|
|
|
{
|
|
|
|
SortArray(mDirList);
|
|
|
|
SortArray(mFilteredFiles);
|
|
|
|
|
|
|
|
if (mReverseSort) {
|
|
|
|
ReverseArray(mDirList);
|
|
|
|
ReverseArray(mFilteredFiles);
|
|
|
|
}
|
|
|
|
}
|