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:
@@ -355,17 +355,17 @@ BCountView::IsTypingAhead() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BCountView::AddFilterString(const char *string)
|
BCountView::AddFilterCharacter(const char *character)
|
||||||
{
|
{
|
||||||
fFilterString += string;
|
fFilterString.AppendChars(character, 1);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BCountView::RemoveFilterString()
|
BCountView::RemoveFilterCharacter()
|
||||||
{
|
{
|
||||||
fFilterString.Truncate(fFilterString.Length() - 1);
|
fFilterString.TruncateChars(fFilterString.CountChars() - 1);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ public:
|
|||||||
const char *TypeAhead() const;
|
const char *TypeAhead() const;
|
||||||
bool IsTypingAhead() const;
|
bool IsTypingAhead() const;
|
||||||
|
|
||||||
void AddFilterString(const char *string);
|
void AddFilterCharacter(const char *character);
|
||||||
void RemoveFilterString();
|
void RemoveFilterCharacter();
|
||||||
void CancelFilter();
|
void CancelFilter();
|
||||||
const char *Filter() const;
|
const char *Filter() const;
|
||||||
bool IsFiltering() const;
|
bool IsFiltering() const;
|
||||||
|
|||||||
@@ -6162,9 +6162,9 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
lastString->Truncate(lastString->Length() - 1);
|
lastString->TruncateChars(lastString->CountChars() - 1);
|
||||||
|
|
||||||
fCountView->RemoveFilterString();
|
fCountView->RemoveFilterCharacter();
|
||||||
FilterChanged();
|
FilterChanged();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -6173,7 +6173,7 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// remove last char from the typeahead buffer
|
// remove last char from the typeahead buffer
|
||||||
sMatchString.Truncate(sMatchString.Length() - 1);
|
sMatchString.TruncateChars(sMatchString.CountChars() - 1);
|
||||||
|
|
||||||
fLastKeyTime = system_time();
|
fLastKeyTime = system_time();
|
||||||
|
|
||||||
@@ -6191,10 +6191,7 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
// handle typeahead selection
|
// handle typeahead selection / filtering
|
||||||
|
|
||||||
// create a null-terminated version of typed char
|
|
||||||
char searchChar[4] = { key, 0 };
|
|
||||||
|
|
||||||
if (TrackerSettings().TypeAheadFiltering()) {
|
if (TrackerSettings().TypeAheadFiltering()) {
|
||||||
if (key == ' ' && modifiers() & B_SHIFT_KEY) {
|
if (key == ' ' && modifiers() & B_SHIFT_KEY) {
|
||||||
@@ -6202,12 +6199,12 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
fFilterStrings.AddItem(new BString());
|
fFilterStrings.AddItem(new BString());
|
||||||
fCountView->AddFilterString("|");
|
fCountView->AddFilterCharacter("|");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fFilterStrings.LastItem()->Append(searchChar);
|
fFilterStrings.LastItem()->AppendChars(bytes, 1);
|
||||||
fCountView->AddFilterString(searchChar);
|
fCountView->AddFilterCharacter(bytes);
|
||||||
FilterChanged();
|
FilterChanged();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -6231,9 +6228,9 @@ BPoseView::KeyDown(const char *bytes, int32 count)
|
|||||||
|
|
||||||
// add char to existing matchString or start new match string
|
// add char to existing matchString or start new match string
|
||||||
if (eventTime - fLastKeyTime < (doubleClickSpeed * 2))
|
if (eventTime - fLastKeyTime < (doubleClickSpeed * 2))
|
||||||
sMatchString.Append(searchChar);
|
sMatchString.AppendChars(bytes, 1);
|
||||||
else
|
else
|
||||||
sMatchString.SetTo(searchChar);
|
sMatchString.SetToChars(bytes, 1);
|
||||||
|
|
||||||
fLastKeyTime = eventTime;
|
fLastKeyTime = eventTime;
|
||||||
|
|
||||||
@@ -6290,7 +6287,6 @@ BPoseView::FindBestMatch(int32 *index)
|
|||||||
BPose *poseToSelect = NULL;
|
BPose *poseToSelect = NULL;
|
||||||
float bestScore = -1;
|
float bestScore = -1;
|
||||||
int32 count = fPoseList->CountItems();
|
int32 count = fPoseList->CountItems();
|
||||||
size_t matchLength = sMatchString.Length();
|
|
||||||
|
|
||||||
// loop through all poses to find match
|
// loop through all poses to find match
|
||||||
for (int32 j = 0; j < CountColumns(); j++) {
|
for (int32 j = 0; j < CountColumns(); j++) {
|
||||||
@@ -6308,12 +6304,11 @@ BPoseView::FindBestMatch(int32 *index)
|
|||||||
text = widget->Text(this);
|
text = widget->Text(this);
|
||||||
|
|
||||||
if (text != NULL) {
|
if (text != NULL) {
|
||||||
score = ComputeTypeAheadScore(text, sMatchString.String(),
|
score = ComputeTypeAheadScore(text, sMatchString.String());
|
||||||
matchLength);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
score = ComputeTypeAheadScore(pose->TargetModel()->Name(),
|
score = ComputeTypeAheadScore(pose->TargetModel()->Name(),
|
||||||
sMatchString.String(), matchLength);
|
sMatchString.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (score > bestScore) {
|
if (score > bestScore) {
|
||||||
@@ -9668,7 +9663,7 @@ BPoseView::FilterChanged()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
int32 stringCount = fFilterStrings.CountItems();
|
int32 stringCount = fFilterStrings.CountItems();
|
||||||
int32 length = fFilterStrings.LastItem()->Length();
|
int32 length = fFilterStrings.LastItem()->CountChars();
|
||||||
|
|
||||||
if (!fFiltering && length > 0)
|
if (!fFiltering && length > 0)
|
||||||
StartFiltering();
|
StartFiltering();
|
||||||
|
|||||||
@@ -1585,8 +1585,7 @@ BootedInSafeMode()
|
|||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
ComputeTypeAheadScore(const char *text, const char *match, size_t matchLength,
|
ComputeTypeAheadScore(const char *text, const char *match, bool wordMode)
|
||||||
bool wordMode)
|
|
||||||
{
|
{
|
||||||
// highest score: exact match
|
// highest score: exact match
|
||||||
const char* found = strcasestr(text, 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;
|
extern const float kExactMatchScore;
|
||||||
float ComputeTypeAheadScore(const char *text, const char *match,
|
float ComputeTypeAheadScore(const char *text, const char *match,
|
||||||
size_t matchLength, bool wordMode = false);
|
bool wordMode = false);
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user