Use the multibyte aware string functions for typeahead search and filtering so
that special characters can be used as well (umlauts for example). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35375 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5cd9308ef4
commit
b3e4ce5422
@ -355,17 +355,17 @@ BCountView::IsTypingAhead() const
|
||||
|
||||
|
||||
void
|
||||
BCountView::AddFilterString(const char *string)
|
||||
BCountView::AddFilterCharacter(const char *character)
|
||||
{
|
||||
fFilterString += string;
|
||||
fFilterString.AppendChars(character, 1);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BCountView::RemoveFilterString()
|
||||
BCountView::RemoveFilterCharacter()
|
||||
{
|
||||
fFilterString.Truncate(fFilterString.Length() - 1);
|
||||
fFilterString.TruncateChars(fFilterString.CountChars() - 1);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,8 @@ public:
|
||||
const char *TypeAhead() const;
|
||||
bool IsTypingAhead() const;
|
||||
|
||||
void AddFilterString(const char *string);
|
||||
void RemoveFilterString();
|
||||
void AddFilterCharacter(const char *character);
|
||||
void RemoveFilterCharacter();
|
||||
void CancelFilter();
|
||||
const char *Filter() const;
|
||||
bool IsFiltering() const;
|
||||
|
@ -6162,9 +6162,9 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
||||
else
|
||||
break;
|
||||
} else
|
||||
lastString->Truncate(lastString->Length() - 1);
|
||||
lastString->TruncateChars(lastString->CountChars() - 1);
|
||||
|
||||
fCountView->RemoveFilterString();
|
||||
fCountView->RemoveFilterCharacter();
|
||||
FilterChanged();
|
||||
break;
|
||||
}
|
||||
@ -6173,7 +6173,7 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
||||
break;
|
||||
|
||||
// remove last char from the typeahead buffer
|
||||
sMatchString.Truncate(sMatchString.Length() - 1);
|
||||
sMatchString.TruncateChars(sMatchString.CountChars() - 1);
|
||||
|
||||
fLastKeyTime = system_time();
|
||||
|
||||
@ -6191,10 +6191,7 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
||||
|
||||
default:
|
||||
{
|
||||
// handle typeahead selection
|
||||
|
||||
// create a null-terminated version of typed char
|
||||
char searchChar[4] = { key, 0 };
|
||||
// handle typeahead selection / filtering
|
||||
|
||||
if (TrackerSettings().TypeAheadFiltering()) {
|
||||
if (key == ' ' && modifiers() & B_SHIFT_KEY) {
|
||||
@ -6202,12 +6199,12 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
||||
break;
|
||||
|
||||
fFilterStrings.AddItem(new BString());
|
||||
fCountView->AddFilterString("|");
|
||||
fCountView->AddFilterCharacter("|");
|
||||
break;
|
||||
}
|
||||
|
||||
fFilterStrings.LastItem()->Append(searchChar);
|
||||
fCountView->AddFilterString(searchChar);
|
||||
fFilterStrings.LastItem()->AppendChars(bytes, 1);
|
||||
fCountView->AddFilterCharacter(bytes);
|
||||
FilterChanged();
|
||||
break;
|
||||
}
|
||||
@ -6231,9 +6228,9 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
||||
|
||||
// add char to existing matchString or start new match string
|
||||
if (eventTime - fLastKeyTime < (doubleClickSpeed * 2))
|
||||
sMatchString.Append(searchChar);
|
||||
sMatchString.AppendChars(bytes, 1);
|
||||
else
|
||||
sMatchString.SetTo(searchChar);
|
||||
sMatchString.SetToChars(bytes, 1);
|
||||
|
||||
fLastKeyTime = eventTime;
|
||||
|
||||
@ -6290,7 +6287,6 @@ BPoseView::FindBestMatch(int32 *index)
|
||||
BPose *poseToSelect = NULL;
|
||||
float bestScore = -1;
|
||||
int32 count = fPoseList->CountItems();
|
||||
size_t matchLength = sMatchString.Length();
|
||||
|
||||
// loop through all poses to find match
|
||||
for (int32 j = 0; j < CountColumns(); j++) {
|
||||
@ -6308,12 +6304,11 @@ BPoseView::FindBestMatch(int32 *index)
|
||||
text = widget->Text(this);
|
||||
|
||||
if (text != NULL) {
|
||||
score = ComputeTypeAheadScore(text, sMatchString.String(),
|
||||
matchLength);
|
||||
score = ComputeTypeAheadScore(text, sMatchString.String());
|
||||
}
|
||||
} else {
|
||||
score = ComputeTypeAheadScore(pose->TargetModel()->Name(),
|
||||
sMatchString.String(), matchLength);
|
||||
sMatchString.String());
|
||||
}
|
||||
|
||||
if (score > bestScore) {
|
||||
@ -9668,7 +9663,7 @@ BPoseView::FilterChanged()
|
||||
return;
|
||||
|
||||
int32 stringCount = fFilterStrings.CountItems();
|
||||
int32 length = fFilterStrings.LastItem()->Length();
|
||||
int32 length = fFilterStrings.LastItem()->CountChars();
|
||||
|
||||
if (!fFiltering && length > 0)
|
||||
StartFiltering();
|
||||
|
@ -1585,8 +1585,7 @@ BootedInSafeMode()
|
||||
|
||||
|
||||
float
|
||||
ComputeTypeAheadScore(const char *text, const char *match, size_t matchLength,
|
||||
bool wordMode)
|
||||
ComputeTypeAheadScore(const char *text, const char *match, bool wordMode)
|
||||
{
|
||||
// highest score: exact match
|
||||
const char* found = strcasestr(text, match);
|
||||
|
@ -759,7 +759,7 @@ inline uint64 SwapUInt64(uint64 value) { return B_SWAP_INT64(value); }
|
||||
|
||||
extern const float kExactMatchScore;
|
||||
float ComputeTypeAheadScore(const char *text, const char *match,
|
||||
size_t matchLength, bool wordMode = false);
|
||||
bool wordMode = false);
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user