* 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
This commit is contained in:
Axel Dörfler
2009-03-12 23:01:45 +00:00
parent 2c5ecffabf
commit b32211a457
+41 -34
View File
@@ -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 *>(model)), fModel(const_cast<Model *>(model)),
fColumn(column), fColumn(column),
@@ -389,17 +390,19 @@ TruncTimeBase(BString *result, int64 value, const View *view, float width)
BString timeFormat; BString timeFormat;
for (int32 index = 0; ; index++) { for (int32 index = 0; ; index++) {
if (TimeFormat(timeFormat, index, separator, order, clockIs24hr) != B_OK) if (TimeFormat(timeFormat, index, separator, order, clockIs24hr)
!= B_OK)
break; break;
strftime(buffer, 256, timeFormat.String(), &timeData); strftime(buffer, 256, timeFormat.String(), &timeData);
resultWidth = view->StringWidth(buffer); resultWidth = view->StringWidth(buffer);
if (resultWidth <= width) if (resultWidth <= width)
break; break;
} }
if (resultWidth > width) if (resultWidth > width) {
// even the shortest format string didn't do it, insert ellipsis // even the shortest format string didn't do it, insert ellipsis
resultWidth = TruncStringBase(result, buffer, (ssize_t)strlen(buffer), view, width); resultWidth = TruncStringBase(result, buffer, (ssize_t)strlen(buffer),
else view, width);
} else
*result = buffer; *result = buffer;
return resultWidth; return resultWidth;
@@ -407,8 +410,8 @@ TruncTimeBase(BString *result, int64 value, const View *view, float width)
float float
WidgetAttributeText::TruncTime(BString *result, int64 value, const BPoseView *view, WidgetAttributeText::TruncTime(BString *result, int64 value,
float width) const BPoseView *view, float width)
{ {
return TruncTimeBase(result, value, view, width); return TruncTimeBase(result, value, view, width);
} }
@@ -484,9 +487,10 @@ WidgetAttributeText::AttrAsString(const Model *model, BString *result,
} else } else
tmp = "-"; tmp = "-";
if (width > 0) if (width > 0) {
TruncStringBase(result, tmp.String(), tmp.Length(), view, width); TruncStringBase(result, tmp.String(), tmp.Length(), view,
else width);
} else
*result = tmp.String(); *result = tmp.String();
return B_OK; return B_OK;
@@ -513,7 +517,8 @@ WidgetAttributeText::AttrAsString(const Model *model, BString *result,
bool bool
WidgetAttributeText::IsEditable() const 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); ReadValue(&fFullValueText);
fOldWidth = fColumn->Width(); fOldWidth = fColumn->Width();
fTruncatedWidth = TruncString(result, fFullValueText.String(), fFullValueText.Length(), fTruncatedWidth = TruncString(result, fFullValueText.String(),
view, fOldWidth); fFullValueText.Length(), view, fOldWidth);
fDirty = false; fDirty = false;
} }
@@ -583,8 +588,8 @@ StringAttributeText::PreferredWidth(const BPoseView *pose) const
int int
StringAttributeText::Compare(WidgetAttributeText &attr, BPoseView *view) StringAttributeText::Compare(WidgetAttributeText &attr, BPoseView *view)
{ {
StringAttributeText *compareTo = StringAttributeText *compareTo
dynamic_cast<StringAttributeText *>(&attr); = dynamic_cast<StringAttributeText *>(&attr);
ASSERT(compareTo); ASSERT(compareTo);
if (fValueDirty) if (fValueDirty)
@@ -666,8 +671,8 @@ ScalarAttributeText::PreferredWidth(const BPoseView *pose) const
int int
ScalarAttributeText::Compare(WidgetAttributeText &attr, BPoseView *) ScalarAttributeText::Compare(WidgetAttributeText &attr, BPoseView *)
{ {
ScalarAttributeText *compareTo = ScalarAttributeText *compareTo
dynamic_cast<ScalarAttributeText *>(&attr); = dynamic_cast<ScalarAttributeText *>(&attr);
ASSERT(compareTo); ASSERT(compareTo);
// make sure we're not comparing apples and oranges // make sure we're not comparing apples and oranges
@@ -922,7 +927,8 @@ NameAttributeText::SetSortFolderNamesFirst(bool enabled)
#ifdef OWNER_GROUP_ATTRIBUTES #ifdef OWNER_GROUP_ATTRIBUTES
OwnerAttributeText::OwnerAttributeText(const Model *model, const BColumn *column) OwnerAttributeText::OwnerAttributeText(const Model *model,
const BColumn *column)
: StringAttributeText(model, 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) : StringAttributeText(model, column)
{ {
} }
@@ -1457,8 +1464,8 @@ GenericAttributeText::ValueAsText(const BPoseView *view)
int int
GenericAttributeText::Compare(WidgetAttributeText &attr, BPoseView *) GenericAttributeText::Compare(WidgetAttributeText &attr, BPoseView *)
{ {
GenericAttributeText *compareTo = GenericAttributeText *compareTo
dynamic_cast<GenericAttributeText *>(&attr); = dynamic_cast<GenericAttributeText *>(&attr);
ASSERT(compareTo); ASSERT(compareTo);
if (fValueDirty) if (fValueDirty)
@@ -1467,25 +1474,25 @@ GenericAttributeText::Compare(WidgetAttributeText &attr, BPoseView *)
compareTo->ReadValue(&compareTo->fFullValueText); compareTo->ReadValue(&compareTo->fFullValueText);
// Sort undefined values last, regardless of the other value: // Sort undefined values last, regardless of the other value:
if (fValueIsDefined == false || compareTo->fValueIsDefined == false) { if (!fValueIsDefined)
return fValueIsDefined < compareTo->fValueIsDefined ? return compareTo->fValueIsDefined ? -1 : 0;
1 : (fValueIsDefined == compareTo->fValueIsDefined ? 0 : -1); if (!compareTo->fValueIsDefined)
} return 1;
switch (fColumn->AttrType()) { switch (fColumn->AttrType()) {
case B_STRING_TYPE: case B_STRING_TYPE:
return fFullValueText.ICompare(compareTo->fFullValueText); return fFullValueText.ICompare(compareTo->fFullValueText);
case B_CHAR_TYPE: case B_CHAR_TYPE:
{ {
char vStr[2] = { static_cast<char>(fValue.uint8t), 0 }; char vStr[2] = { static_cast<char>(fValue.uint8t), 0 };
char cStr[2] = { static_cast<char>(compareTo->fValue.uint8t), 0}; char cStr[2] = { static_cast<char>(compareTo->fValue.uint8t), 0};
BString valueStr(vStr); BString valueStr(vStr);
BString compareToStr(cStr); BString compareToStr(cStr);
return valueStr.ICompare(compareToStr); return valueStr.ICompare(compareToStr);
} }
case B_FLOAT_TYPE: case B_FLOAT_TYPE:
return fValue.floatt >= compareTo->fValue.floatt ? return fValue.floatt >= compareTo->fValue.floatt ?
@@ -1772,8 +1779,8 @@ OpenWithRelationAttributeText::FitValue(BString *result, const BPoseView *view)
ReadValue(); ReadValue();
ASSERT(view == fPoseView); ASSERT(view == fPoseView);
const OpenWithPoseView *launchWithView = const OpenWithPoseView *launchWithView
dynamic_cast<const OpenWithPoseView *>(view); = dynamic_cast<const OpenWithPoseView *>(view);
if (launchWithView) if (launchWithView)
launchWithView->OpenWithRelationDescription(fModel, &fRelationText); launchWithView->OpenWithRelationDescription(fModel, &fRelationText);