Tracker: style fixes to WidgetAttributeText

This commit is contained in:
John Scipione 2014-06-20 19:26:06 -04:00
parent 69e5768d45
commit 92199e801c
2 changed files with 284 additions and 255 deletions

View File

@ -240,40 +240,54 @@ WidgetAttributeText::NewWidgetText(const Model* model,
if (strcmp(attrName, kAttrPath) == 0)
return new PathAttributeText(model, column);
if (strcmp(attrName, kAttrMIMEType) == 0)
return new KindAttributeText(model, column);
if (strcmp(attrName, kAttrStatName) == 0)
return new NameAttributeText(model, column);
if (strcmp(attrName, kAttrRealName) == 0)
return new RealNameAttributeText(model, column);
if (strcmp(attrName, kAttrStatSize) == 0)
return new SizeAttributeText(model, column);
if (strcmp(attrName, kAttrStatModified) == 0)
return new ModificationTimeAttributeText(model, column);
if (strcmp(attrName, kAttrStatCreated) == 0)
return new CreationTimeAttributeText(model, column);
#ifdef OWNER_GROUP_ATTRIBUTES
if (strcmp(attrName, kAttrStatOwner) == 0)
return new OwnerAttributeText(model, column);
if (strcmp(attrName, kAttrStatGroup) == 0)
return new GroupAttributeText(model, column);
#endif
if (strcmp(attrName, kAttrStatMode) == 0)
return new ModeAttributeText(model, column);
if (strcmp(attrName, kAttrOpenWithRelation) == 0)
return new OpenWithRelationAttributeText(model, column, view);
if (strcmp(attrName, kAttrAppVersion) == 0)
return new AppShortVersionAttributeText(model, column);
if (strcmp(attrName, kAttrSystemVersion) == 0)
return new SystemShortVersionAttributeText(model, column);
if (strcmp(attrName, kAttrOriginalPath) == 0)
return new OriginalPathAttributeText(model, column);
if (column->DisplayAs() != NULL) {
if (!strncmp(column->DisplayAs(), "checkbox", 8))
return new CheckboxAttributeText(model, column);
if (!strncmp(column->DisplayAs(), "duration", 8))
return new DurationAttributeText(model, column);
if (!strncmp(column->DisplayAs(), "rating", 6))
return new RatingAttributeText(model, column);
}
@ -304,8 +318,9 @@ const char*
WidgetAttributeText::FittingText(const BPoseView* view)
{
if (fDirty || fColumn->Width() != fOldWidth || CheckSettingsChanged()
|| !fValueIsDefined )
|| !fValueIsDefined) {
CheckViewChanged(view);
}
ASSERT(!fDirty);
return fText.String();
@ -469,7 +484,7 @@ WidgetAttributeText::SetDirty(bool value)
}
// #pragma mark -
// #pragma mark - StringAttributeText
StringAttributeText::StringAttributeText(const Model* model,
@ -570,7 +585,7 @@ StringAttributeText::CommitEditedText(BTextView* textView)
}
// #pragma mark -
// #pragma mark - ScalarAttributeText
ScalarAttributeText::ScalarAttributeText(const Model* model,
@ -599,7 +614,8 @@ ScalarAttributeText::CheckAttributeChanged()
return false;
fValue = newValue;
fDirty = true; // have to redo fitted string
fDirty = true;
// have to redo fitted string
return true;
}
@ -629,7 +645,7 @@ ScalarAttributeText::Compare(WidgetAttributeText& attr, BPoseView*)
}
// #pragma mark -
// #pragma mark - PathAttributeText
PathAttributeText::PathAttributeText(const Model* model, const BColumn* column)
@ -651,11 +667,12 @@ PathAttributeText::ReadValue(BString* result)
TruncateLeaf(result);
} else
*result = "-";
fValueDirty = false;
}
// #pragma mark -
// #pragma mark - OriginalPathAttributeText
OriginalPathAttributeText::OriginalPathAttributeText(const Model* model,
@ -677,15 +694,15 @@ OriginalPathAttributeText::ReadValue(BString* result)
*result = path.Path();
else
*result = "-";
fValueDirty = false;
}
// #pragma mark -
// #pragma mark - KindAttributeText
KindAttributeText::KindAttributeText(const Model* model,
const BColumn* column)
KindAttributeText::KindAttributeText(const Model* model, const BColumn* column)
:
StringAttributeText(model, column)
{
@ -701,16 +718,17 @@ KindAttributeText::ReadValue(BString* result)
// get the mime type
if (mime.SetType(fModel->MimeType()) != B_OK)
*result = B_TRANSLATE("Unknown");
else if (mime.GetShortDescription(desc) == B_OK) {
// get the short mime type description
else if (mime.GetShortDescription(desc) == B_OK)
*result = desc;
else
} else
*result = fModel->MimeType();
fValueDirty = false;
}
// #pragma mark -
// #pragma mark - NameAttributeText
NameAttributeText::NameAttributeText(const Model* model,
@ -791,9 +809,7 @@ NameAttributeText::CommitEditedTextFlavor(BTextView* textView)
B_TRANSLATE("Replace other file"),
B_TRANSLATE("OK"),
NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetShortcut(0, 'r');
if (alert->Go())
return false;
@ -847,7 +863,7 @@ NameAttributeText::IsEditable() const
}
// #pragma mark -
// #pragma mark - RealNameAttributeText
RealNameAttributeText::RealNameAttributeText(const Model* model,
@ -981,8 +997,6 @@ RealNameAttributeText::SetSortFolderNamesFirst(bool enabled)
#ifdef OWNER_GROUP_ATTRIBUTES
OwnerAttributeText::OwnerAttributeText(const Model* model,
const BColumn* column)
:
@ -1035,11 +1049,12 @@ GroupAttributeText::ReadValue(BString* result)
fValueDirty = false;
}
#endif // OWNER_GROUP_ATTRIBUTES
// #pragma mark - ModeAttributeText
ModeAttributeText::ModeAttributeText(const Model* model,
const BColumn* column)
:
@ -1080,7 +1095,7 @@ ModeAttributeText::ReadValue(BString* result)
}
// #pragma mark -
// #pragma mark - SizeAttributeText
SizeAttributeText::SizeAttributeText(const Model* model,
@ -1137,7 +1152,7 @@ SizeAttributeText::PreferredWidth(const BPoseView* pose) const
}
// #pragma mark - time related
// #pragma mark - TimeAttributeText
TimeAttributeText::TimeAttributeText(const Model* model,
@ -1176,6 +1191,9 @@ TimeAttributeText::CheckSettingsChanged(void)
}
// #pragma mark - CreationTimeAttributeText
CreationTimeAttributeText::CreationTimeAttributeText(const Model* model,
const BColumn* column)
:
@ -1193,6 +1211,9 @@ CreationTimeAttributeText::ReadValue()
}
// #pragma mark - ModificationTimeAttributeText
ModificationTimeAttributeText::ModificationTimeAttributeText(
const Model* model, const BColumn* column)
:
@ -1210,7 +1231,7 @@ ModificationTimeAttributeText::ReadValue()
}
// #pragma mark -
// #pragma mark - GenericAttributeText
GenericAttributeText::GenericAttributeText(const Model* model,
@ -1326,11 +1347,13 @@ GenericAttributeText::ReadValue(BString* result)
default:
TRESPASS();
break;
}
} else {
// handle the standard data types
switch (info.size) {
case sizeof(char): // Takes care of bool too.
case sizeof(char):
// Takes care of bool too.
fValueIsDefined = true;
fValue.int8t = tmp.int8t;
break;
@ -1340,18 +1363,21 @@ GenericAttributeText::ReadValue(BString* result)
fValue.int16t = tmp.int16t;
break;
case sizeof(int32): // Takes care of time_t too.
case sizeof(int32):
// Takes care of time_t too.
fValueIsDefined = true;
fValue.int32t = tmp.int32t;
break;
case sizeof(int64): // Takes care of off_t too.
case sizeof(int64):
// Takes care of off_t too.
fValueIsDefined = true;
fValue.int64t = tmp.int64t;
break;
default:
TRESPASS();
break;
}
}
}
@ -1528,9 +1554,10 @@ GenericAttributeText::Compare(WidgetAttributeText& attr, BPoseView*)
if (compareTo->fValueDirty)
compareTo->ReadValue(&compareTo->fFullValueText);
// Sort undefined values last, regardless of the other value:
// sort undefined values last, regardless of the other value
if (!fValueIsDefined)
return compareTo->fValueIsDefined ? 1 : 0;
if (!compareTo->fValueIsDefined)
return -1;
@ -1598,6 +1625,7 @@ GenericAttributeText::Compare(WidgetAttributeText& attr, BPoseView*)
return fValue.uint64t >= compareTo->fValue.uint64t ?
(fValue.uint64t == compareTo->fValue.uint64t ? 0 : 1) : -1;
}
return 0;
}
@ -1794,7 +1822,6 @@ GenericAttributeText::CommitEditedTextFlavor(BTextView* textView)
default:
TRESPASS();
}
size = fModel->WriteAttr(columnName, type, 0, &tmp, scalarSize);
@ -1819,7 +1846,7 @@ GenericAttributeText::CommitEditedTextFlavor(BTextView* textView)
}
// #pragma mark - display as: duration
// #pragma mark - DurationAttributeText (display as: duration)
DurationAttributeText::DurationAttributeText(const Model* model,
@ -1901,7 +1928,7 @@ DurationAttributeText::FitValue(BString* result, const BPoseView* view)
}
// #pragma mark - display as: checkbox
// #pragma mark - CheckboxAttributeText (display as: checkbox)
CheckboxAttributeText::CheckboxAttributeText(const Model* model,
@ -1981,7 +2008,7 @@ CheckboxAttributeText::FitValue(BString* result, const BPoseView* view)
}
// #pragma mark - display as: rating
// #pragma mark - RatingAttributeText (display as: rating)
RatingAttributeText::RatingAttributeText(const Model* model,
@ -2052,7 +2079,7 @@ RatingAttributeText::FitValue(BString* result, const BPoseView* view)
}
// #pragma mark -
// #pragma mark - OpenWithRelationAttributeText
OpenWithRelationAttributeText::OpenWithRelationAttributeText(const Model* model,
@ -2110,6 +2137,9 @@ OpenWithRelationAttributeText::FitValue(BString* result, const BPoseView* view)
}
// #pragma mark - VersionAttributeText
VersionAttributeText::VersionAttributeText(const Model* model,
const BColumn* column, bool app)
:

View File

@ -31,8 +31,8 @@ of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#ifndef __TEXT_WIDGET_ATTRIBUTE__
#define __TEXT_WIDGET_ATTRIBUTE__
#ifndef _TEXT_WIDGET_ATTRIBUTE_H
#define _TEXT_WIDGET_ATTRIBUTE_H
#include <String.h>
@ -56,7 +56,7 @@ class WidgetAttributeText {
// corresponding text, fitted into a specified width using a given
// view
// It is being asked for the string value by the TextWidget object
public:
public:
WidgetAttributeText(const Model*, const BColumn*);
virtual ~WidgetAttributeText();
@ -106,7 +106,7 @@ class WidgetAttributeText {
void SetDirty(bool);
protected:
protected:
// generic fitting routines used by the different attributes
static float TruncString(BString* result, const char* src,
int32 length, const BPoseView*, float width,
@ -143,7 +143,7 @@ WidgetAttributeText::TargetModel() const
class StringAttributeText : public WidgetAttributeText {
public:
public:
StringAttributeText(const Model*, const BColumn*);
virtual const char* ValueAsText(const BPoseView* view);
@ -156,7 +156,7 @@ class StringAttributeText : public WidgetAttributeText {
virtual bool CommitEditedText(BTextView*);
protected:
protected:
virtual bool CommitEditedTextFlavor(BTextView*) { return false; }
virtual void FitValue(BString* result, const BPoseView*);
@ -171,8 +171,9 @@ class StringAttributeText : public WidgetAttributeText {
class ScalarAttributeText : public WidgetAttributeText {
public:
public:
ScalarAttributeText(const Model*, const BColumn*);
int64 Value();
virtual bool CheckAttributeChanged();
@ -180,7 +181,7 @@ class ScalarAttributeText : public WidgetAttributeText {
virtual bool CommitEditedText(BTextView*) { return false; }
// return true if attribute actually changed
protected:
protected:
virtual int64 ReadValue() = 0;
virtual int Compare(WidgetAttributeText&, BPoseView* view);
int64 fValue;
@ -211,14 +212,12 @@ union GenericValueStruct {
//! Used for displaying mime extra attributes. Supports different formats.
class GenericAttributeText : public StringAttributeText {
public:
GenericAttributeText(const Model* model,
const BColumn* column);
GenericAttributeText(const Model* model, const BColumn* column);
virtual bool CheckAttributeChanged();
virtual float PreferredWidth(const BPoseView* view) const;
virtual int Compare(WidgetAttributeText& other,
BPoseView* view);
virtual int Compare(WidgetAttributeText& other, BPoseView* view);
virtual void SetUpEditing(BTextView* view);
virtual bool CommitEditedText(BTextView* view);
@ -228,8 +227,7 @@ public:
protected:
virtual bool CommitEditedTextFlavor(BTextView* view);
virtual void FitValue(BString* result,
const BPoseView* view);
virtual void FitValue(BString* result, const BPoseView* view);
virtual void ReadValue(BString* result);
protected:
@ -242,26 +240,22 @@ protected:
//! Used for the display-as type "duration"
class DurationAttributeText : public GenericAttributeText {
public:
DurationAttributeText(const Model* model,
const BColumn* column);
DurationAttributeText(const Model* model, const BColumn* column);
private:
virtual void FitValue(BString* result,
const BPoseView* view);
virtual void FitValue(BString* result, const BPoseView* view);
};
//! Used for the display-as type "checkbox"
class CheckboxAttributeText : public GenericAttributeText {
public:
CheckboxAttributeText(const Model* model,
const BColumn* column);
CheckboxAttributeText(const Model* model, const BColumn* column);
virtual void SetUpEditing(BTextView* view);
private:
virtual void FitValue(BString* result,
const BPoseView* view);
virtual void FitValue(BString* result, const BPoseView* view);
private:
BString fOnChar;
@ -272,14 +266,12 @@ private:
//! Used for the display-as type "rating"
class RatingAttributeText : public GenericAttributeText {
public:
RatingAttributeText(const Model* model,
const BColumn* column);
RatingAttributeText(const Model* model, const BColumn* column);
virtual void SetUpEditing(BTextView* view);
private:
virtual void FitValue(BString* result,
const BPoseView* view);
virtual void FitValue(BString* result, const BPoseView* view);
private:
int32 fCount;
@ -288,9 +280,10 @@ private:
class TimeAttributeText : public ScalarAttributeText {
public:
public:
TimeAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual float PreferredWidth(const BPoseView*) const;
virtual void FitValue(BString* result, const BPoseView*);
virtual bool CheckSettingsChanged();
@ -303,38 +296,42 @@ class TimeAttributeText : public ScalarAttributeText {
class PathAttributeText : public StringAttributeText {
public:
public:
PathAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void ReadValue(BString* result);
};
class OriginalPathAttributeText : public StringAttributeText {
public:
public:
OriginalPathAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void ReadValue(BString* result);
};
class KindAttributeText : public StringAttributeText {
public:
public:
KindAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void ReadValue(BString* result);
};
class NameAttributeText : public StringAttributeText {
public:
public:
NameAttributeText(const Model*, const BColumn*);
virtual void SetUpEditing(BTextView*);
virtual void FitValue(BString* result, const BPoseView*);
virtual bool IsEditable() const;
static void SetSortFolderNamesFirst(bool);
protected:
protected:
virtual bool CommitEditedTextFlavor(BTextView*);
virtual int Compare(WidgetAttributeText&, BPoseView* view);
virtual void ReadValue(BString* result);
@ -345,8 +342,8 @@ class NameAttributeText : public StringAttributeText {
class RealNameAttributeText : public StringAttributeText {
public:
RealNameAttributeText(const Model*,
const BColumn*);
RealNameAttributeText(const Model*, const BColumn*);
virtual void SetUpEditing(BTextView*);
virtual void FitValue(BString* result, const BPoseView*);
@ -362,32 +359,30 @@ protected:
#ifdef OWNER_GROUP_ATTRIBUTES
class OwnerAttributeText : public StringAttributeText {
public:
public:
OwnerAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void ReadValue(BString* result);
};
class GroupAttributeText : public StringAttributeText {
public:
public:
GroupAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void ReadValue(BString* result);
};
#endif // OWNER_GROUP_ATTRIBUTES
class ModeAttributeText : public StringAttributeText {
public:
public:
ModeAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void ReadValue(BString* result);
};
@ -396,10 +391,10 @@ const int64 kUnknownSize = -1;
class SizeAttributeText : public ScalarAttributeText {
public:
public:
SizeAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual void FitValue(BString* result, const BPoseView*);
virtual int64 ReadValue();
virtual float PreferredWidth(const BPoseView*) const;
@ -407,28 +402,29 @@ class SizeAttributeText : public ScalarAttributeText {
class CreationTimeAttributeText : public TimeAttributeText {
public:
public:
CreationTimeAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual int64 ReadValue();
};
class ModificationTimeAttributeText : public TimeAttributeText {
public:
public:
ModificationTimeAttributeText(const Model*, const BColumn*);
protected:
protected:
virtual int64 ReadValue();
};
class OpenWithRelationAttributeText : public ScalarAttributeText {
public:
public:
OpenWithRelationAttributeText(const Model*, const BColumn*,
const BPoseView*);
protected:
protected:
virtual void FitValue(BString* result, const BPoseView*);
virtual int64 ReadValue();
virtual float PreferredWidth(const BPoseView*) const;
@ -439,32 +435,34 @@ class OpenWithRelationAttributeText : public ScalarAttributeText {
class VersionAttributeText : public StringAttributeText {
public:
public:
VersionAttributeText(const Model*, const BColumn*, bool appVersion);
protected:
protected:
virtual void ReadValue(BString* result);
private:
private:
bool fAppVersion;
};
class AppShortVersionAttributeText : public VersionAttributeText {
public:
public:
AppShortVersionAttributeText(const Model* model,
const BColumn* column)
: VersionAttributeText(model, column, true)
:
VersionAttributeText(model, column, true)
{
}
};
class SystemShortVersionAttributeText : public VersionAttributeText {
public:
public:
SystemShortVersionAttributeText(const Model* model,
const BColumn* column)
: VersionAttributeText(model, column, false)
:
VersionAttributeText(model, column, false)
{
}
};
@ -477,4 +475,5 @@ extern status_t TimeFormat(BString &string, int32 index,
using namespace BPrivate;
#endif // __TEXT_WIDGET_ATTRIBUTE__
#endif // _TEXT_WIDGET_ATTRIBUTE_H