Redo filtering to use new RegExp classes.
ImageFunctionsView's filtering field now allows shell-style glob matches rather than just simple direct string matches. Implements remaining part of #7955.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
#include <RegExp.h>
|
||||||
|
|
||||||
#include "table/TableColumns.h"
|
#include "table/TableColumns.h"
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ public:
|
|||||||
fComponentName(componentName),
|
fComponentName(componentName),
|
||||||
fSourceFile(sourceFile),
|
fSourceFile(sourceFile),
|
||||||
fFunction(function),
|
fFunction(function),
|
||||||
fFilterMatchIndex(-1)
|
fFilterMatch()
|
||||||
{
|
{
|
||||||
if (fSourceFile != NULL)
|
if (fSourceFile != NULL)
|
||||||
fSourceFile->AcquireReference();
|
fSourceFile->AcquireReference();
|
||||||
@@ -137,14 +138,14 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 FilterMatchIndex() const
|
const RegExp::MatchResult& FilterMatch() const
|
||||||
{
|
{
|
||||||
return fFilterMatchIndex;
|
return fFilterMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFilterMatchIndex(int32 index)
|
void SetFilterMatch(const RegExp::MatchResult& match)
|
||||||
{
|
{
|
||||||
fFilterMatchIndex = index;
|
fFilterMatch = match;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -171,7 +172,7 @@ private:
|
|||||||
LocatableFile* fSourceFile;
|
LocatableFile* fSourceFile;
|
||||||
FunctionInstance* fFunction;
|
FunctionInstance* fFunction;
|
||||||
ChildPathComponentList fChildPathComponents;
|
ChildPathComponentList fChildPathComponents;
|
||||||
int32 fFilterMatchIndex;
|
RegExp::MatchResult fFilterMatch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -186,15 +187,13 @@ public:
|
|||||||
:
|
:
|
||||||
StringTableColumn(modelIndex, title, width, minWidth, maxWidth,
|
StringTableColumn(modelIndex, title, width, minWidth, maxWidth,
|
||||||
truncate, align),
|
truncate, align),
|
||||||
fFilter(),
|
fHasFilter(false)
|
||||||
fFilterWidth(0.0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFilter(const BString& filter)
|
void SetHasFilter(bool hasFilter)
|
||||||
{
|
{
|
||||||
fFilter = filter;
|
fHasFilter = hasFilter;
|
||||||
fFilterWidth = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void DrawValue(const BVariant& value, BRect rect,
|
virtual void DrawValue(const BVariant& value, BRect rect,
|
||||||
@@ -202,10 +201,7 @@ public:
|
|||||||
{
|
{
|
||||||
StringTableColumn::DrawValue(value, rect, targetView);
|
StringTableColumn::DrawValue(value, rect, targetView);
|
||||||
|
|
||||||
if (!fFilter.IsEmpty()) {
|
if (fHasFilter) {
|
||||||
if (fFilterWidth == 0.0)
|
|
||||||
fFilterWidth = targetView->StringWidth(fFilter);
|
|
||||||
|
|
||||||
// TODO: handle this case as well
|
// TODO: handle this case as well
|
||||||
if (fField.HasClippedString())
|
if (fField.HasClippedString())
|
||||||
return;
|
return;
|
||||||
@@ -213,15 +209,18 @@ public:
|
|||||||
const SourcePathComponentNode* node
|
const SourcePathComponentNode* node
|
||||||
= (const SourcePathComponentNode*)value.ToPointer();
|
= (const SourcePathComponentNode*)value.ToPointer();
|
||||||
|
|
||||||
int32 matchIndex = node->FilterMatchIndex();
|
const RegExp::MatchResult& match = node->FilterMatch();
|
||||||
if (matchIndex < 0)
|
if (!match.HasMatched())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
targetView->PushState();
|
targetView->PushState();
|
||||||
BRect fillRect(rect);
|
BRect fillRect(rect);
|
||||||
fillRect.left += kTextMargin + targetView->StringWidth(
|
fillRect.left += kTextMargin + targetView->StringWidth(
|
||||||
fField.String(), matchIndex);
|
fField.String(), match.StartOffset());
|
||||||
fillRect.right = fillRect.left + fFilterWidth;
|
float filterWidth = targetView->StringWidth(fField.String()
|
||||||
|
+ match.StartOffset(), match.EndOffset()
|
||||||
|
- match.StartOffset());
|
||||||
|
fillRect.right = fillRect.left + filterWidth;
|
||||||
targetView->SetLowColor(255, 255, 0, 255);
|
targetView->SetLowColor(255, 255, 0, 255);
|
||||||
targetView->SetDrawingMode(B_OP_MIN);
|
targetView->SetDrawingMode(B_OP_MIN);
|
||||||
targetView->FillRect(fillRect, B_SOLID_LOW);
|
targetView->FillRect(fillRect, B_SOLID_LOW);
|
||||||
@@ -241,8 +240,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fFilter;
|
bool fHasFilter;
|
||||||
float fFilterWidth;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -293,7 +291,8 @@ public:
|
|||||||
|
|
||||||
LocatableFile* currentFile = NULL;
|
LocatableFile* currentFile = NULL;
|
||||||
BStringList pathComponents;
|
BStringList pathComponents;
|
||||||
bool applyFilter = !fCurrentFilter.IsEmpty();
|
bool applyFilter = !fFilterString.IsEmpty()
|
||||||
|
&& fCurrentFilter.IsValid();
|
||||||
int32 functionCount = fImageDebugInfo->CountFunctions();
|
int32 functionCount = fImageDebugInfo->CountFunctions();
|
||||||
for (int32 i = 0; i < functionCount; i++) {
|
for (int32 i = 0; i < functionCount; i++) {
|
||||||
FunctionInstance* instance = fImageDebugInfo->FunctionAt(i);
|
FunctionInstance* instance = fImageDebugInfo->FunctionAt(i);
|
||||||
@@ -313,16 +312,16 @@ public:
|
|||||||
if (sourceFile != NULL)
|
if (sourceFile != NULL)
|
||||||
sourceFile->GetPath(sourcePath);
|
sourceFile->GetPath(sourcePath);
|
||||||
|
|
||||||
int32 pathMatchIndex = -1;
|
RegExp::MatchResult pathMatch;
|
||||||
int32 functionMatchIndex = -1;
|
RegExp::MatchResult functionMatch;
|
||||||
if (applyFilter && !_FilterFunction(instance, sourcePath,
|
if (applyFilter && !_FilterFunction(instance, sourcePath,
|
||||||
pathMatchIndex, functionMatchIndex)) {
|
pathMatch, functionMatch)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceFile == NULL) {
|
if (sourceFile == NULL) {
|
||||||
if (!_AddFunctionNode(sourcelessNode, instance, NULL,
|
if (!_AddFunctionNode(sourcelessNode, instance, NULL,
|
||||||
functionMatchIndex)) {
|
functionMatch)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -342,7 +341,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_AddFunctionByPath(pathComponents, instance, currentFile,
|
if (!_AddFunctionByPath(pathComponents, instance, currentFile,
|
||||||
pathMatchIndex, functionMatchIndex)) {
|
pathMatch, functionMatch)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,10 +468,13 @@ public:
|
|||||||
|
|
||||||
void SetFilter(const char* filter)
|
void SetFilter(const char* filter)
|
||||||
{
|
{
|
||||||
fCurrentFilter = filter;
|
fFilterString = filter;
|
||||||
|
if (fFilterString.IsEmpty()
|
||||||
|
|| fCurrentFilter.SetPattern(filter, RegExp::PATTERN_TYPE_WILDCARD,
|
||||||
|
false)) {
|
||||||
SetImageDebugInfo(fImageDebugInfo);
|
SetImageDebugInfo(fImageDebugInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _GetSourcePathComponents(LocatableFile* currentFile,
|
bool _GetSourcePathComponents(LocatableFile* currentFile,
|
||||||
@@ -504,8 +506,8 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _AddFunctionByPath(const BStringList& pathComponents,
|
bool _AddFunctionByPath(const BStringList& pathComponents,
|
||||||
FunctionInstance* function, LocatableFile* file, int32 pathMatchIndex,
|
FunctionInstance* function, LocatableFile* file,
|
||||||
int32 functionMatchIndex)
|
RegExp::MatchResult& pathMatch, RegExp::MatchResult& functionMatch)
|
||||||
{
|
{
|
||||||
SourcePathComponentNode* parentNode = NULL;
|
SourcePathComponentNode* parentNode = NULL;
|
||||||
SourcePathComponentNode* currentNode = NULL;
|
SourcePathComponentNode* currentNode = NULL;
|
||||||
@@ -525,7 +527,7 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (pathComponents.CountStrings() == 1)
|
if (pathComponents.CountStrings() == 1)
|
||||||
currentNode->SetFilterMatchIndex(pathMatchIndex);
|
currentNode->SetFilterMatch(pathMatch);
|
||||||
|
|
||||||
BReference<SourcePathComponentNode> nodeReference(currentNode,
|
BReference<SourcePathComponentNode> nodeReference(currentNode,
|
||||||
true);
|
true);
|
||||||
@@ -545,11 +547,12 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return _AddFunctionNode(currentNode, function, file,
|
return _AddFunctionNode(currentNode, function, file,
|
||||||
functionMatchIndex);
|
functionMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _AddFunctionNode(SourcePathComponentNode* parent,
|
bool _AddFunctionNode(SourcePathComponentNode* parent,
|
||||||
FunctionInstance* function, LocatableFile* file, int32 matchIndex)
|
FunctionInstance* function, LocatableFile* file,
|
||||||
|
RegExp::MatchResult& match)
|
||||||
{
|
{
|
||||||
SourcePathComponentNode* functionNode = new(std::nothrow)
|
SourcePathComponentNode* functionNode = new(std::nothrow)
|
||||||
SourcePathComponentNode(parent, function->PrettyName(), file,
|
SourcePathComponentNode(parent, function->PrettyName(), file,
|
||||||
@@ -558,7 +561,7 @@ private:
|
|||||||
if (functionNode == NULL)
|
if (functionNode == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
functionNode->SetFilterMatchIndex(matchIndex);
|
functionNode->SetFilterMatch(match);
|
||||||
|
|
||||||
BReference<SourcePathComponentNode> nodeReference(functionNode, true);
|
BReference<SourcePathComponentNode> nodeReference(functionNode, true);
|
||||||
if (!parent->AddChild(functionNode))
|
if (!parent->AddChild(functionNode))
|
||||||
@@ -568,12 +571,12 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _FilterFunction(FunctionInstance* instance, const BString& sourcePath,
|
bool _FilterFunction(FunctionInstance* instance, const BString& sourcePath,
|
||||||
int32& pathMatchIndex, int32& functionMatchIndex)
|
RegExp::MatchResult& pathMatch, RegExp::MatchResult& functionMatch)
|
||||||
{
|
{
|
||||||
functionMatchIndex = instance->PrettyName().IFindFirst(fCurrentFilter);
|
functionMatch = fCurrentFilter.Match(instance->PrettyName());
|
||||||
pathMatchIndex = sourcePath.IFindFirst(fCurrentFilter);
|
pathMatch = fCurrentFilter.Match(sourcePath.String());
|
||||||
|
|
||||||
return functionMatchIndex >= 0 || pathMatchIndex >= 0;
|
return functionMatch.HasMatched() || pathMatch.HasMatched();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -584,7 +587,8 @@ private:
|
|||||||
ImageDebugInfo* fImageDebugInfo;
|
ImageDebugInfo* fImageDebugInfo;
|
||||||
ChildPathComponentList fChildPathComponents;
|
ChildPathComponentList fChildPathComponents;
|
||||||
SourcePathComponentNode* fSourcelessNode;
|
SourcePathComponentNode* fSourcelessNode;
|
||||||
BString fCurrentFilter;
|
BString fFilterString;
|
||||||
|
RegExp fCurrentFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -713,7 +717,8 @@ ImageFunctionsView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
if (system_time() - fLastFilterKeypress >= kKeypressTimeout) {
|
if (system_time() - fLastFilterKeypress >= kKeypressTimeout) {
|
||||||
fFunctionsTableModel->SetFilter(fFilterField->Text());
|
fFunctionsTableModel->SetFilter(fFilterField->Text());
|
||||||
fHighlightingColumn->SetFilter(fFilterField->Text());
|
fHighlightingColumn->SetHasFilter(
|
||||||
|
fFilterField->TextView()->TextLength() > 0);
|
||||||
_ExpandFilteredNodes();
|
_ExpandFilteredNodes();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user