* 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:
parent
6ccba002a8
commit
ee6a2e5589
@ -68,10 +68,14 @@ public:
|
||||
|
||||
bool IsFilesystemTranslationPreferred() const;
|
||||
|
||||
status_t GetLocalizedFileName(const entry_ref& ref,
|
||||
BString& localizedFileName,
|
||||
status_t GetLocalizedFileName(BString& localizedFileName,
|
||||
const entry_ref& ref,
|
||||
bool traverse = false);
|
||||
|
||||
status_t GetLocalizedFileName(BString& localizedFileName,
|
||||
const char* signature, const char* context,
|
||||
const char* string);
|
||||
|
||||
static const char* kCatLangAttr;
|
||||
static const char* kCatSigAttr;
|
||||
static const char* kCatFingerprintAttr;
|
||||
@ -82,6 +86,10 @@ public:
|
||||
private:
|
||||
static BCatalog* _GetCatalog(BCatalog* catalog,
|
||||
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;
|
||||
if (!gLocalizedNamePreferred
|
||||
|| BLocaleRoster::Default()->GetLocalizedFileName(*ref, name) != B_OK)
|
||||
|| BLocaleRoster::Default()->GetLocalizedFileName(name, *ref) != B_OK)
|
||||
name = ref->name;
|
||||
|
||||
BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig),
|
||||
|
@ -94,7 +94,7 @@ perform_query(BVolume &volume, const char *predicate)
|
||||
entry_ref ref;
|
||||
|
||||
if (entry.GetRef(&ref) != B_OK || BLocaleRoster::Default()
|
||||
->GetLocalizedFileName(ref, string) != B_OK)
|
||||
->GetLocalizedFileName(string, ref) != B_OK)
|
||||
continue;
|
||||
|
||||
if (string.IFindFirst(predicate) < 0)
|
||||
|
@ -381,11 +381,10 @@ BLocaleRoster::IsFilesystemTranslationPreferred() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Looks up a localized filename in a catalog, using attribute data
|
||||
on the entry.
|
||||
\param ref An entry_ref with an attribute holding data for catalog lookup.
|
||||
/*! \brief Looks up a localized filename from a catalog.
|
||||
\param localizedFileName A pre-allocated BString object for the result
|
||||
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.
|
||||
\return
|
||||
- \c B_OK: success
|
||||
@ -400,8 +399,56 @@ BLocaleRoster::IsFilesystemTranslationPreferred() const
|
||||
Lookup fails if a comment is present in the catalog entry.
|
||||
*/
|
||||
status_t
|
||||
BLocaleRoster::GetLocalizedFileName(const entry_ref& ref,
|
||||
BString& localizedFileName, bool traverse)
|
||||
BLocaleRoster::GetLocalizedFileName(BString& localizedFileName,
|
||||
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);
|
||||
if (!entry.Exists())
|
||||
@ -412,44 +459,26 @@ BLocaleRoster::GetLocalizedFileName(const entry_ref& ref,
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
attr_info attr;
|
||||
status = node.GetAttrInfo("SYS:NAME", &attr);
|
||||
status = node.ReadAttrString("SYS:NAME", &signature);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
char attribute[attr.size + 1];
|
||||
ssize_t bytes = node.ReadAttr("SYS:NAME", B_MIME_TYPE, 0, &attribute,
|
||||
attr.size);
|
||||
|
||||
if (bytes < 0)
|
||||
return bytes;
|
||||
|
||||
if (bytes == 0 || bytes != attr.size)
|
||||
int32 first = signature.FindFirst(':');
|
||||
int32 last = signature.FindLast(':');
|
||||
if (first == last)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
|
||||
attribute[bytes] = '\0';
|
||||
context = signature;
|
||||
string = signature;
|
||||
|
||||
char* signature = attribute;
|
||||
char* context = strchr(signature, ':');
|
||||
if (context == NULL)
|
||||
signature.Truncate(first);
|
||||
context.Truncate(last);
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -782,7 +782,7 @@ TFilePanel::Init(const BMessage *)
|
||||
if (be_app->GetAppInfo(&info) == B_OK) {
|
||||
if (!gLocalizedNamePreferred
|
||||
|| BLocaleRoster::Default()->GetLocalizedFileName(
|
||||
info.ref, title, false) != B_OK)
|
||||
title, info.ref, false) != B_OK)
|
||||
title = info.ref.name;
|
||||
title << ": ";
|
||||
}
|
||||
|
@ -299,7 +299,9 @@ BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *
|
||||
if (list)
|
||||
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('U', 0, new BMessage(kUnmountVolume));
|
||||
AddShortcut('P', 0, new BMessage(kPermissionsSelected));
|
||||
@ -1222,6 +1224,7 @@ AttributeView::MouseDown(BPoint point)
|
||||
} else if (fTitleRect.Contains(point)) {
|
||||
// You can't change the name of the trash
|
||||
if (!fModel->IsTrash()
|
||||
&& !fModel->HasLocalizedName()
|
||||
&& ConfirmChangeIfWellKnownDirectory(&entry,
|
||||
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
|
||||
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'"), true)
|
||||
@ -2037,9 +2040,11 @@ AttributeView::BuildContextMenu(BMenu *parent)
|
||||
new BMessage(kOpenSelection), 'O'));
|
||||
|
||||
if (!model.IsTrash()) {
|
||||
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
||||
new BMessage(kEditItem), 'E'));
|
||||
parent->AddSeparatorItem();
|
||||
if (!fModel->HasLocalizedName()) {
|
||||
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
||||
new BMessage(kEditItem), 'E'));
|
||||
parent->AddSeparatorItem();
|
||||
}
|
||||
if (fModel->IsVolume()) {
|
||||
BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
|
||||
new BMessage(kUnmountVolume), 'U');
|
||||
|
@ -568,7 +568,7 @@ void
|
||||
Model::CacheLocalizedName()
|
||||
{
|
||||
if (BLocaleRoster::Default()->GetLocalizedFileName(
|
||||
fEntryRef, fLocalizedName, true) == B_OK)
|
||||
fLocalizedName, fEntryRef, true) == B_OK)
|
||||
fHasLocalizedName = true;
|
||||
else
|
||||
fHasLocalizedName = false;
|
||||
|
@ -204,6 +204,9 @@ class Model {
|
||||
|
||||
bool Mimeset(bool force);
|
||||
// returns true if mime type changed
|
||||
|
||||
bool HasLocalizedName() const;
|
||||
|
||||
private:
|
||||
status_t OpenNodeCommon(bool writable);
|
||||
void SetupBaseType();
|
||||
@ -451,6 +454,13 @@ Model::IsSymLink() const
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
Model::HasLocalizedName() const
|
||||
{
|
||||
return fHasLocalizedName;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
ModelNodeLazyOpener::ModelNodeLazyOpener(Model *model, bool writable, bool openLater)
|
||||
: fModel(model),
|
||||
|
Loading…
Reference in New Issue
Block a user