зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1707462 - expose Windows' localized file display names through XPCOM, r=mhowell
Differential Revision: https://phabricator.services.mozilla.com/D143480
This commit is contained in:
Родитель
c3d3119342
Коммит
a3f9a3f4e2
|
@ -94,6 +94,10 @@ FileDescriptorFile::GetNativeLeafName(nsACString& aLeafName) {
|
|||
return mFile->GetNativeLeafName(aLeafName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP FileDescriptorFile::GetDisplayName(nsAString& aLeafName) {
|
||||
return mFile->GetDisplayName(aLeafName);
|
||||
}
|
||||
|
||||
nsresult FileDescriptorFile::GetTarget(nsAString& aRetVal) {
|
||||
return mFile->GetTarget(aRetVal);
|
||||
}
|
||||
|
|
|
@ -116,6 +116,18 @@ interface nsIFile : nsISupports
|
|||
attribute AString leafName;
|
||||
[noscript] attribute ACString nativeLeafName;
|
||||
|
||||
/**
|
||||
* The leaf name as displayed in OS-provided file pickers and similar UI.
|
||||
* On Windows and macOS, 'real' leaf names of some directories can be
|
||||
* in English, but the OS will show a different, translated name to users
|
||||
* using a different locale. So folders like "Downloads", "Desktop" and
|
||||
* "Documents" might not normally appear to users with that (English) name,
|
||||
* but with an OS-localized translation. This API will return such a
|
||||
* translation if it exists, or the leafName if it doesn't.
|
||||
* On Linux, this will always be the same as `leafName`.
|
||||
*/
|
||||
readonly attribute AString displayName;
|
||||
|
||||
/**
|
||||
* copyTo[Native]
|
||||
*
|
||||
|
|
|
@ -666,6 +666,11 @@ nsLocalFile::SetNativeLeafName(const nsACString& aLeafName) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetDisplayName(nsAString& aLeafName) {
|
||||
return GetLeafName(aLeafName);
|
||||
}
|
||||
|
||||
nsCString nsLocalFile::NativePath() { return mPath; }
|
||||
|
||||
nsresult nsIFile::GetNativePath(nsACString& aResult) {
|
||||
|
|
|
@ -1615,6 +1615,25 @@ nsLocalFile::SetLeafName(const nsAString& aLeafName) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetDisplayName(nsAString& aLeafName) {
|
||||
aLeafName.Truncate();
|
||||
|
||||
if (mWorkingPath.IsEmpty()) {
|
||||
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
||||
}
|
||||
SHFILEINFOW sfi = {};
|
||||
DWORD_PTR result = ::SHGetFileInfoW(mWorkingPath.get(), 0, &sfi, sizeof(sfi),
|
||||
SHGFI_DISPLAYNAME);
|
||||
// If we found a display name, return that:
|
||||
if (result) {
|
||||
aLeafName.Assign(sfi.szDisplayName);
|
||||
return NS_OK;
|
||||
}
|
||||
// Nope - fall back to the regular leaf name.
|
||||
return GetLeafName(aLeafName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocalFile::GetPath(nsAString& aResult) {
|
||||
MOZ_ASSERT_IF(
|
||||
|
|
Загрузка…
Ссылка в новой задаче