From b32211a457bf8a89ef4a0e36a5261ede434c66c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 12 Mar 2009 23:01:45 +0000 Subject: [PATCH] * r28871 turned around the sort logic for undefined attributes. * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29486 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/tracker/WidgetAttributeText.cpp | 79 +++++++++++++----------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/src/kits/tracker/WidgetAttributeText.cpp b/src/kits/tracker/WidgetAttributeText.cpp index bfa6993d72..c1e8a9b48a 100644 --- a/src/kits/tracker/WidgetAttributeText.cpp +++ b/src/kits/tracker/WidgetAttributeText.cpp @@ -135,7 +135,8 @@ WidgetAttributeText::NewWidgetText(const Model *model, } -WidgetAttributeText::WidgetAttributeText(const Model *model, const BColumn *column) +WidgetAttributeText::WidgetAttributeText(const Model *model, + const BColumn *column) : fModel(const_cast(model)), fColumn(column), @@ -389,17 +390,19 @@ TruncTimeBase(BString *result, int64 value, const View *view, float width) BString timeFormat; for (int32 index = 0; ; index++) { - if (TimeFormat(timeFormat, index, separator, order, clockIs24hr) != B_OK) + if (TimeFormat(timeFormat, index, separator, order, clockIs24hr) + != B_OK) break; strftime(buffer, 256, timeFormat.String(), &timeData); resultWidth = view->StringWidth(buffer); if (resultWidth <= width) break; } - if (resultWidth > width) + if (resultWidth > width) { // even the shortest format string didn't do it, insert ellipsis - resultWidth = TruncStringBase(result, buffer, (ssize_t)strlen(buffer), view, width); - else + resultWidth = TruncStringBase(result, buffer, (ssize_t)strlen(buffer), + view, width); + } else *result = buffer; return resultWidth; @@ -407,8 +410,8 @@ TruncTimeBase(BString *result, int64 value, const View *view, float width) float -WidgetAttributeText::TruncTime(BString *result, int64 value, const BPoseView *view, - float width) +WidgetAttributeText::TruncTime(BString *result, int64 value, + const BPoseView *view, float width) { return TruncTimeBase(result, value, view, width); } @@ -484,9 +487,10 @@ WidgetAttributeText::AttrAsString(const Model *model, BString *result, } else tmp = "-"; - if (width > 0) - TruncStringBase(result, tmp.String(), tmp.Length(), view, width); - else + if (width > 0) { + TruncStringBase(result, tmp.String(), tmp.Length(), view, + width); + } else *result = tmp.String(); return B_OK; @@ -513,7 +517,8 @@ WidgetAttributeText::AttrAsString(const Model *model, BString *result, bool WidgetAttributeText::IsEditable() const { - return fColumn->Editable() && !BVolume(fModel->StatBuf()->st_dev).IsReadOnly(); + return fColumn->Editable() + && !BVolume(fModel->StatBuf()->st_dev).IsReadOnly(); } @@ -567,8 +572,8 @@ StringAttributeText::FitValue(BString *result, const BPoseView *view) ReadValue(&fFullValueText); fOldWidth = fColumn->Width(); - fTruncatedWidth = TruncString(result, fFullValueText.String(), fFullValueText.Length(), - view, fOldWidth); + fTruncatedWidth = TruncString(result, fFullValueText.String(), + fFullValueText.Length(), view, fOldWidth); fDirty = false; } @@ -583,8 +588,8 @@ StringAttributeText::PreferredWidth(const BPoseView *pose) const int StringAttributeText::Compare(WidgetAttributeText &attr, BPoseView *view) { - StringAttributeText *compareTo = - dynamic_cast(&attr); + StringAttributeText *compareTo + = dynamic_cast(&attr); ASSERT(compareTo); if (fValueDirty) @@ -666,8 +671,8 @@ ScalarAttributeText::PreferredWidth(const BPoseView *pose) const int ScalarAttributeText::Compare(WidgetAttributeText &attr, BPoseView *) { - ScalarAttributeText *compareTo = - dynamic_cast(&attr); + ScalarAttributeText *compareTo + = dynamic_cast(&attr); ASSERT(compareTo); // make sure we're not comparing apples and oranges @@ -922,7 +927,8 @@ NameAttributeText::SetSortFolderNamesFirst(bool enabled) #ifdef OWNER_GROUP_ATTRIBUTES -OwnerAttributeText::OwnerAttributeText(const Model *model, const BColumn *column) +OwnerAttributeText::OwnerAttributeText(const Model *model, + const BColumn *column) : StringAttributeText(model, column) { } @@ -947,7 +953,8 @@ OwnerAttributeText::ReadValue(BString *result) } -GroupAttributeText::GroupAttributeText(const Model *model, const BColumn *column) +GroupAttributeText::GroupAttributeText(const Model *model, + const BColumn *column) : StringAttributeText(model, column) { } @@ -1457,8 +1464,8 @@ GenericAttributeText::ValueAsText(const BPoseView *view) int GenericAttributeText::Compare(WidgetAttributeText &attr, BPoseView *) { - GenericAttributeText *compareTo = - dynamic_cast(&attr); + GenericAttributeText *compareTo + = dynamic_cast(&attr); ASSERT(compareTo); if (fValueDirty) @@ -1467,25 +1474,25 @@ GenericAttributeText::Compare(WidgetAttributeText &attr, BPoseView *) compareTo->ReadValue(&compareTo->fFullValueText); // Sort undefined values last, regardless of the other value: - if (fValueIsDefined == false || compareTo->fValueIsDefined == false) { - return fValueIsDefined < compareTo->fValueIsDefined ? - 1 : (fValueIsDefined == compareTo->fValueIsDefined ? 0 : -1); - } + if (!fValueIsDefined) + return compareTo->fValueIsDefined ? -1 : 0; + if (!compareTo->fValueIsDefined) + return 1; switch (fColumn->AttrType()) { case B_STRING_TYPE: return fFullValueText.ICompare(compareTo->fFullValueText); case B_CHAR_TYPE: - { - char vStr[2] = { static_cast(fValue.uint8t), 0 }; - char cStr[2] = { static_cast(compareTo->fValue.uint8t), 0}; - - BString valueStr(vStr); - BString compareToStr(cStr); - - return valueStr.ICompare(compareToStr); - } + { + char vStr[2] = { static_cast(fValue.uint8t), 0 }; + char cStr[2] = { static_cast(compareTo->fValue.uint8t), 0}; + + BString valueStr(vStr); + BString compareToStr(cStr); + + return valueStr.ICompare(compareToStr); + } case B_FLOAT_TYPE: return fValue.floatt >= compareTo->fValue.floatt ? @@ -1772,8 +1779,8 @@ OpenWithRelationAttributeText::FitValue(BString *result, const BPoseView *view) ReadValue(); ASSERT(view == fPoseView); - const OpenWithPoseView *launchWithView = - dynamic_cast(view); + const OpenWithPoseView *launchWithView + = dynamic_cast(view); if (launchWithView) launchWithView->OpenWithRelationDescription(fModel, &fRelationText);