* Extend the Model class with a method bool HasLocalizedName().
* Disallow renaming of entries with localized names for now - this is meant to be temporary - and so far only in Tracker's Info window. Renames do not result in a change, visually, as the localized name hides the real name, and results in a bad user experience. One could possibly allow renames of the localized name, writing it back to the catalog. I've experimented with using BCatalogAddOn::SetString() but haven't been able to make it stick yet. * Disallow renaming Trash in Tracker's Info window via Command-E. * Adjust the argument order of BLocaleRoster::GetLocalizedFileName(). * Add a BLocaleRoster::GetLocalizedFileName() variant to look up another app's name given its signature and unlocalized, canonical name. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41126 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -68,10 +68,14 @@ public:
|
|||||||
|
|
||||||
bool IsFilesystemTranslationPreferred() const;
|
bool IsFilesystemTranslationPreferred() const;
|
||||||
|
|
||||||
status_t GetLocalizedFileName(const entry_ref& ref,
|
status_t GetLocalizedFileName(BString& localizedFileName,
|
||||||
BString& localizedFileName,
|
const entry_ref& ref,
|
||||||
bool traverse = false);
|
bool traverse = false);
|
||||||
|
|
||||||
|
status_t GetLocalizedFileName(BString& localizedFileName,
|
||||||
|
const char* signature, const char* context,
|
||||||
|
const char* string);
|
||||||
|
|
||||||
static const char* kCatLangAttr;
|
static const char* kCatLangAttr;
|
||||||
static const char* kCatSigAttr;
|
static const char* kCatSigAttr;
|
||||||
static const char* kCatFingerprintAttr;
|
static const char* kCatFingerprintAttr;
|
||||||
@@ -82,6 +86,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
static BCatalog* _GetCatalog(BCatalog* catalog,
|
static BCatalog* _GetCatalog(BCatalog* catalog,
|
||||||
vint32* catalogInitStatus);
|
vint32* catalogInitStatus);
|
||||||
|
|
||||||
|
status_t _PrepareCatalogEntry(const entry_ref& ref,
|
||||||
|
BString& signature, BString& context,
|
||||||
|
BString& string, bool traverse);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -620,7 +620,7 @@ TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref)
|
|||||||
|
|
||||||
BString name;
|
BString name;
|
||||||
if (!gLocalizedNamePreferred
|
if (!gLocalizedNamePreferred
|
||||||
|| BLocaleRoster::Default()->GetLocalizedFileName(*ref, name) != B_OK)
|
|| BLocaleRoster::Default()->GetLocalizedFileName(name, *ref) != B_OK)
|
||||||
name = ref->name;
|
name = ref->name;
|
||||||
|
|
||||||
BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig),
|
BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig),
|
||||||
|
|||||||
+1
-1
@@ -94,7 +94,7 @@ perform_query(BVolume &volume, const char *predicate)
|
|||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|
||||||
if (entry.GetRef(&ref) != B_OK || BLocaleRoster::Default()
|
if (entry.GetRef(&ref) != B_OK || BLocaleRoster::Default()
|
||||||
->GetLocalizedFileName(ref, string) != B_OK)
|
->GetLocalizedFileName(string, ref) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (string.IFindFirst(predicate) < 0)
|
if (string.IFindFirst(predicate) < 0)
|
||||||
|
|||||||
@@ -381,11 +381,10 @@ BLocaleRoster::IsFilesystemTranslationPreferred() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Looks up a localized filename in a catalog, using attribute data
|
/*! \brief Looks up a localized filename from a catalog.
|
||||||
on the entry.
|
|
||||||
\param ref An entry_ref with an attribute holding data for catalog lookup.
|
|
||||||
\param localizedFileName A pre-allocated BString object for the result
|
\param localizedFileName A pre-allocated BString object for the result
|
||||||
of the lookup.
|
of the lookup.
|
||||||
|
\param ref An entry_ref with an attribute holding data for catalog lookup.
|
||||||
\param traverse A boolean to decide if symlinks are to be traversed.
|
\param traverse A boolean to decide if symlinks are to be traversed.
|
||||||
\return
|
\return
|
||||||
- \c B_OK: success
|
- \c B_OK: success
|
||||||
@@ -400,8 +399,56 @@ BLocaleRoster::IsFilesystemTranslationPreferred() const
|
|||||||
Lookup fails if a comment is present in the catalog entry.
|
Lookup fails if a comment is present in the catalog entry.
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
BLocaleRoster::GetLocalizedFileName(const entry_ref& ref,
|
BLocaleRoster::GetLocalizedFileName(BString& localizedFileName,
|
||||||
BString& localizedFileName, bool traverse)
|
const entry_ref& ref, bool traverse)
|
||||||
|
{
|
||||||
|
BString signature;
|
||||||
|
BString context;
|
||||||
|
BString string;
|
||||||
|
|
||||||
|
status_t status = _PrepareCatalogEntry(ref, signature, context, string,
|
||||||
|
traverse);
|
||||||
|
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
return GetLocalizedFileName(localizedFileName, signature, context, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Looks up a localized filename from a catalog.
|
||||||
|
\param localizedFileName A pre-allocated BString object for the result
|
||||||
|
of the lookup.
|
||||||
|
\param signature The "x-vnd..." part of an application signature.
|
||||||
|
\param context A catalog context. Likely B_TRANSLATE_SYSTEM_NAME_CONTEXT.
|
||||||
|
\param string A catalog string entry. Likely the unlocalized app name.
|
||||||
|
\return
|
||||||
|
- \c B_OK: success
|
||||||
|
- \c B_ENTRY_NOT_FOUND: failure. Catalog entry not found in catalog, etc
|
||||||
|
- other error codes: failure
|
||||||
|
|
||||||
|
Lookup is done for the top preferred language, only.
|
||||||
|
Lookup fails if a comment is present in the catalog entry.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
BLocaleRoster::GetLocalizedFileName(BString& localizedFileName,
|
||||||
|
const char* signature, const char* context, const char* string)
|
||||||
|
{
|
||||||
|
BCatalog catalog(signature);
|
||||||
|
|
||||||
|
const char* temp = catalog.GetString(string, context);
|
||||||
|
|
||||||
|
if (temp == NULL)
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
|
localizedFileName = temp;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BLocaleRoster::_PrepareCatalogEntry(const entry_ref& ref, BString& signature,
|
||||||
|
BString& context, BString& string, bool traverse)
|
||||||
{
|
{
|
||||||
BEntry entry(&ref, traverse);
|
BEntry entry(&ref, traverse);
|
||||||
if (!entry.Exists())
|
if (!entry.Exists())
|
||||||
@@ -412,44 +459,26 @@ BLocaleRoster::GetLocalizedFileName(const entry_ref& ref,
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
attr_info attr;
|
status = node.ReadAttrString("SYS:NAME", &signature);
|
||||||
status = node.GetAttrInfo("SYS:NAME", &attr);
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
char attribute[attr.size + 1];
|
int32 first = signature.FindFirst(':');
|
||||||
ssize_t bytes = node.ReadAttr("SYS:NAME", B_MIME_TYPE, 0, &attribute,
|
int32 last = signature.FindLast(':');
|
||||||
attr.size);
|
if (first == last)
|
||||||
|
|
||||||
if (bytes < 0)
|
|
||||||
return bytes;
|
|
||||||
|
|
||||||
if (bytes == 0 || bytes != attr.size)
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
attribute[bytes] = '\0';
|
context = signature;
|
||||||
|
string = signature;
|
||||||
|
|
||||||
char* signature = attribute;
|
signature.Truncate(first);
|
||||||
char* context = strchr(signature, ':');
|
context.Truncate(last);
|
||||||
if (context == NULL)
|
context.Remove(0, first + 1);
|
||||||
|
string.Remove(0, last + 1);
|
||||||
|
|
||||||
|
if (signature.Length() == 0 || context.Length() == 0
|
||||||
|
|| string.Length() == 0)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
context[0] = '\0';
|
|
||||||
context++;
|
|
||||||
|
|
||||||
char* string = strchr(context, ':');
|
|
||||||
if (string == NULL)
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
|
||||||
|
|
||||||
string[0] = '\0';
|
|
||||||
string++;
|
|
||||||
|
|
||||||
BCatalog catalog(signature);
|
|
||||||
|
|
||||||
const char* temp = catalog.GetString(string, context);
|
|
||||||
if (temp == NULL)
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
|
||||||
|
|
||||||
localizedFileName = temp;
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -782,7 +782,7 @@ TFilePanel::Init(const BMessage *)
|
|||||||
if (be_app->GetAppInfo(&info) == B_OK) {
|
if (be_app->GetAppInfo(&info) == B_OK) {
|
||||||
if (!gLocalizedNamePreferred
|
if (!gLocalizedNamePreferred
|
||||||
|| BLocaleRoster::Default()->GetLocalizedFileName(
|
|| BLocaleRoster::Default()->GetLocalizedFileName(
|
||||||
info.ref, title, false) != B_OK)
|
title, info.ref, false) != B_OK)
|
||||||
title = info.ref.name;
|
title = info.ref.name;
|
||||||
title << ": ";
|
title << ": ";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,7 +299,9 @@ BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *
|
|||||||
if (list)
|
if (list)
|
||||||
list->AddItem(this);
|
list->AddItem(this);
|
||||||
|
|
||||||
AddShortcut('E', 0, new BMessage(kEditItem));
|
if (!model->IsTrash() && !model->HasLocalizedName())
|
||||||
|
AddShortcut('E', 0, new BMessage(kEditItem));
|
||||||
|
|
||||||
AddShortcut('O', 0, new BMessage(kOpenSelection));
|
AddShortcut('O', 0, new BMessage(kOpenSelection));
|
||||||
AddShortcut('U', 0, new BMessage(kUnmountVolume));
|
AddShortcut('U', 0, new BMessage(kUnmountVolume));
|
||||||
AddShortcut('P', 0, new BMessage(kPermissionsSelected));
|
AddShortcut('P', 0, new BMessage(kPermissionsSelected));
|
||||||
@@ -1222,6 +1224,7 @@ AttributeView::MouseDown(BPoint point)
|
|||||||
} else if (fTitleRect.Contains(point)) {
|
} else if (fTitleRect.Contains(point)) {
|
||||||
// You can't change the name of the trash
|
// You can't change the name of the trash
|
||||||
if (!fModel->IsTrash()
|
if (!fModel->IsTrash()
|
||||||
|
&& !fModel->HasLocalizedName()
|
||||||
&& ConfirmChangeIfWellKnownDirectory(&entry,
|
&& ConfirmChangeIfWellKnownDirectory(&entry,
|
||||||
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
|
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
|
||||||
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'"), true)
|
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'"), true)
|
||||||
@@ -2037,9 +2040,11 @@ AttributeView::BuildContextMenu(BMenu *parent)
|
|||||||
new BMessage(kOpenSelection), 'O'));
|
new BMessage(kOpenSelection), 'O'));
|
||||||
|
|
||||||
if (!model.IsTrash()) {
|
if (!model.IsTrash()) {
|
||||||
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
if (!fModel->HasLocalizedName()) {
|
||||||
new BMessage(kEditItem), 'E'));
|
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
||||||
parent->AddSeparatorItem();
|
new BMessage(kEditItem), 'E'));
|
||||||
|
parent->AddSeparatorItem();
|
||||||
|
}
|
||||||
if (fModel->IsVolume()) {
|
if (fModel->IsVolume()) {
|
||||||
BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
|
BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
|
||||||
new BMessage(kUnmountVolume), 'U');
|
new BMessage(kUnmountVolume), 'U');
|
||||||
|
|||||||
@@ -568,7 +568,7 @@ void
|
|||||||
Model::CacheLocalizedName()
|
Model::CacheLocalizedName()
|
||||||
{
|
{
|
||||||
if (BLocaleRoster::Default()->GetLocalizedFileName(
|
if (BLocaleRoster::Default()->GetLocalizedFileName(
|
||||||
fEntryRef, fLocalizedName, true) == B_OK)
|
fLocalizedName, fEntryRef, true) == B_OK)
|
||||||
fHasLocalizedName = true;
|
fHasLocalizedName = true;
|
||||||
else
|
else
|
||||||
fHasLocalizedName = false;
|
fHasLocalizedName = false;
|
||||||
|
|||||||
@@ -204,6 +204,9 @@ class Model {
|
|||||||
|
|
||||||
bool Mimeset(bool force);
|
bool Mimeset(bool force);
|
||||||
// returns true if mime type changed
|
// returns true if mime type changed
|
||||||
|
|
||||||
|
bool HasLocalizedName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t OpenNodeCommon(bool writable);
|
status_t OpenNodeCommon(bool writable);
|
||||||
void SetupBaseType();
|
void SetupBaseType();
|
||||||
@@ -451,6 +454,13 @@ Model::IsSymLink() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
Model::HasLocalizedName() const
|
||||||
|
{
|
||||||
|
return fHasLocalizedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
ModelNodeLazyOpener::ModelNodeLazyOpener(Model *model, bool writable, bool openLater)
|
ModelNodeLazyOpener::ModelNodeLazyOpener(Model *model, bool writable, bool openLater)
|
||||||
: fModel(model),
|
: fModel(model),
|
||||||
|
|||||||
Reference in New Issue
Block a user