From f1cc4cf8cb5fb0d2f566a79e671077f0beca86c1 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 22 Jul 2025 07:38:54 -0400 Subject: [PATCH] Tracker: Truncate name better in icon mode, don't draw outside. The max width of the file name was getting set by the width of the name column, even in icon mode. Use an arbitrary max width of 30em for the name field in icon (and mini-icon) mode instead. Set fValueIsDefined on name and other attributes. Do not attempt to truncate name if !fValueIsDefined, this means that the value is "-" to show that it is undefined. We assume this should fit and there is no way to truncate the value. If the value is later defined it is marked fDirty to truncate it to the available space. Fixes #19431 Change-Id: I4cb7953bc746039600ee578b4fa6b786c802bdf8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9516 Tested-by: Commit checker robot Reviewed-by: John Scipione --- src/kits/tracker/TextWidget.cpp | 5 ++++ src/kits/tracker/WidgetAttributeText.cpp | 36 ++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/kits/tracker/TextWidget.cpp b/src/kits/tracker/TextWidget.cpp index 4af28fd791..d22d31e0a5 100644 --- a/src/kits/tracker/TextWidget.cpp +++ b/src/kits/tracker/TextWidget.cpp @@ -639,6 +639,9 @@ BTextWidget::Draw(BRect eraseRect, BRect textRect, BPoseView* view, BView* drawV textRect.OffsetBy(offset); + BRegion textRegion(textRect); + drawView->ConstrainClippingRegion(&textRegion); + // We are only concerned with setting the correct text color. // For active views the selection is drawn as inverse text @@ -784,4 +787,6 @@ BTextWidget::Draw(BRect eraseRect, BRect textRect, BPoseView* view, BView* drawV if (direct && clipboardMode != kMoveSelectionTo) drawView->SetDrawingMode(B_OP_OVER); } + + drawView->ConstrainClippingRegion(NULL); } diff --git a/src/kits/tracker/WidgetAttributeText.cpp b/src/kits/tracker/WidgetAttributeText.cpp index 3b34c3e69c..a6c194f167 100644 --- a/src/kits/tracker/WidgetAttributeText.cpp +++ b/src/kits/tracker/WidgetAttributeText.cpp @@ -300,10 +300,9 @@ WidgetAttributeText::~WidgetAttributeText() const char* WidgetAttributeText::FittingText(const BPoseView* view) { - if (fDirty || fColumn->Width() != fOldWidth || CheckSettingsChanged() - || !fValueIsDefined) { + bool widthChanged = view->ViewMode() == kListMode ? fColumn->Width() != fOldWidth : false; + if (fDirty || widthChanged || CheckSettingsChanged()) CheckViewChanged(view); - } ASSERT(!fDirty); return fText.String(); @@ -649,8 +648,11 @@ PathAttributeText::ReadValue(BString* outString) if (entry.InitCheck() == B_OK && entry.GetPath(&path) == B_OK) { *outString = path.Path(); TruncateLeaf(outString); - } else + fValueIsDefined = true; + } else { *outString = "-"; + fValueIsDefined = false; + } fValueDirty = false; } @@ -674,10 +676,13 @@ OriginalPathAttributeText::ReadValue(BString* outString) BPath path; // get the original path - if (entry.InitCheck() == B_OK && FSGetOriginalPath(&entry, &path) == B_OK) + if (entry.InitCheck() == B_OK && FSGetOriginalPath(&entry, &path) == B_OK) { *outString = path.Path(); - else + fValueIsDefined = true; + } else { *outString = "-"; + fValueIsDefined = false; + } fValueDirty = false; } @@ -709,6 +714,7 @@ KindAttributeText::ReadValue(BString* outString) *outString = fModel->MimeType(); fValueDirty = false; + fValueIsDefined = true; } @@ -746,6 +752,7 @@ NameAttributeText::ReadValue(BString* outString) *outString = fModel->Name(); fValueDirty = false; + fValueIsDefined = true; } @@ -755,7 +762,11 @@ NameAttributeText::FitValue(BString* outString, const BPoseView* view) if (fValueDirty) ReadValue(&fFullValueText); - fOldWidth = fColumn->Width(); + if (view->ViewMode() != kListMode) + fOldWidth = view->StringWidth("M") * 30; + else + fOldWidth = fColumn->Width(); + fTruncatedWidth = TruncString(outString, fFullValueText.String(), fFullValueText.Length(), view, fOldWidth, B_TRUNCATE_MIDDLE); fDirty = false; @@ -839,6 +850,7 @@ RealNameAttributeText::ReadValue(BString* outString) *outString = fModel->EntryRef()->name; fValueDirty = false; + fValueIsDefined = true; } @@ -897,9 +909,11 @@ OwnerAttributeText::ReadValue(BString* outString) user << "root"; } else user << nodeOwner; + *outString = user.String(); fValueDirty = false; + fValueIsDefined = true; } @@ -924,9 +938,11 @@ GroupAttributeText::ReadValue(BString* outString) group << "0"; } else group << nodeGroup; + *outString = group.String(); fValueDirty = false; + fValueIsDefined = true; } #endif // OWNER_GROUP_ATTRIBUTES @@ -971,6 +987,7 @@ ModeAttributeText::ReadValue(BString* outString) *outString = buffer; fValueDirty = false; + fValueIsDefined = true; } @@ -1142,8 +1159,7 @@ GenericAttributeText::CheckAttributeChanged() // fDirty could already be true, in that case we mustn't set it to // false, even if the attribute text hasn't changed - bool changed = fValue.int64t != tmpValue.int64t - || tmpString != fFullValueText; + bool changed = fValue.int64t != tmpValue.int64t || tmpString != fFullValueText; if (changed) fDirty = true; @@ -2063,9 +2079,11 @@ VersionAttributeText::ReadValue(BString* outString) && info.GetVersionInfo(&version, fAppVersion ? B_APP_VERSION_KIND : B_SYSTEM_VERSION_KIND) == B_OK) { *outString = version.short_info; + fValueIsDefined = true; return; } } *outString = "-"; + fValueIsDefined = false; }