TextSearch: add a simple file filter.
It relies on grep's "--include <glob>" option. GUI layout code courtesy of Humdinger (thanks!). Change-Id: I825abdaafaecdb750f2d27e510b310d20d3b461c Reviewed-on: https://review.haiku-os.org/c/haiku/+/9285 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]> Reviewed-by: humdinger humdinger <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
2de2e7aec3
commit
30e1b0862f
@@ -109,6 +109,7 @@ GrepWindow::GrepWindow(BMessage* message)
|
|||||||
|
|
||||||
fGrepper(NULL),
|
fGrepper(NULL),
|
||||||
fOldPattern(""),
|
fOldPattern(""),
|
||||||
|
fIncludeFilesGlob(""),
|
||||||
fModel(new (nothrow) Model()),
|
fModel(new (nothrow) Model()),
|
||||||
fLastNodeMonitorEvent(system_time()),
|
fLastNodeMonitorEvent(system_time()),
|
||||||
fChangesIterator(NULL),
|
fChangesIterator(NULL),
|
||||||
@@ -235,6 +236,10 @@ void GrepWindow::MessageReceived(BMessage* message)
|
|||||||
_OnSearchText();
|
_OnSearchText();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_SEARCH_GLOB_FILTER:
|
||||||
|
_OnGlobFilterChange();
|
||||||
|
break;
|
||||||
|
|
||||||
case MSG_SELECT_HISTORY:
|
case MSG_SELECT_HISTORY:
|
||||||
_OnHistoryItem(message);
|
_OnHistoryItem(message);
|
||||||
break;
|
break;
|
||||||
@@ -547,6 +552,14 @@ GrepWindow::_CreateViews()
|
|||||||
fSearchText->TextView()->SetMaxBytes(1000);
|
fSearchText->TextView()->SetMaxBytes(1000);
|
||||||
fSearchText->SetModificationMessage(new BMessage(MSG_SEARCH_TEXT));
|
fSearchText->SetModificationMessage(new BMessage(MSG_SEARCH_TEXT));
|
||||||
|
|
||||||
|
fGlobText = new BTextControl(
|
||||||
|
"GlobText", B_TRANSLATE("File filter:"), NULL, NULL,
|
||||||
|
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE);
|
||||||
|
|
||||||
|
fGlobText->TextView()->SetMaxBytes(20);
|
||||||
|
fGlobText->SetModificationMessage(new BMessage(MSG_SEARCH_GLOB_FILTER));
|
||||||
|
fGlobText->SetToolTip(B_TRANSLATE("Only search files matching the given pattern, e.g. \"*.h\"."));
|
||||||
|
|
||||||
fButton = new BButton(
|
fButton = new BButton(
|
||||||
"Button", B_TRANSLATE("Search"),
|
"Button", B_TRANSLATE("Search"),
|
||||||
new BMessage(MSG_START_CANCEL));
|
new BMessage(MSG_START_CANCEL));
|
||||||
@@ -573,13 +586,16 @@ GrepWindow::_LayoutViews()
|
|||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||||
.SetInsets(0, 0, -1, -1)
|
.SetInsets(0, 0, -1, -1)
|
||||||
.Add(fMenuBar)
|
.Add(fMenuBar)
|
||||||
.AddGrid(B_USE_HALF_ITEM_INSETS)
|
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
|
||||||
.SetInsets(B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING,
|
.SetInsets(B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING,
|
||||||
B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING)
|
B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING)
|
||||||
.Add(fSearchText, 0, 0, 3)
|
.Add(fSearchText)
|
||||||
.Add(fShowLinesCheckbox, 0, 1)
|
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
|
||||||
.Add(BSpaceLayoutItem::CreateGlue(), 1, 1)
|
.Add(fGlobText, 1.0)
|
||||||
.Add(fButton, 2, 1)
|
.Add(fShowLinesCheckbox)
|
||||||
|
.AddGlue(0.5)
|
||||||
|
.Add(fButton)
|
||||||
|
.End()
|
||||||
.End()
|
.End()
|
||||||
.AddGroup(B_VERTICAL, 0)
|
.AddGroup(B_VERTICAL, 0)
|
||||||
.SetInsets(-2, 0, -1, -1)
|
.SetInsets(-2, 0, -1, -1)
|
||||||
@@ -737,6 +753,7 @@ GrepWindow::_OnStartCancel()
|
|||||||
// displaying the names of the files we are grepping.
|
// displaying the names of the files we are grepping.
|
||||||
|
|
||||||
fSearchText->SetModificationMessage(NULL);
|
fSearchText->SetModificationMessage(NULL);
|
||||||
|
fGlobText->SetModificationMessage(NULL);
|
||||||
|
|
||||||
fFileMenu->SetEnabled(false);
|
fFileMenu->SetEnabled(false);
|
||||||
fActionMenu->SetEnabled(false);
|
fActionMenu->SetEnabled(false);
|
||||||
@@ -745,6 +762,7 @@ GrepWindow::_OnStartCancel()
|
|||||||
fEncodingMenu->SetEnabled(false);
|
fEncodingMenu->SetEnabled(false);
|
||||||
|
|
||||||
fSearchText->SetEnabled(false);
|
fSearchText->SetEnabled(false);
|
||||||
|
fGlobText->SetEnabled(false);
|
||||||
|
|
||||||
fButton->MakeFocus(true);
|
fButton->MakeFocus(true);
|
||||||
fButton->SetLabel(B_TRANSLATE("Cancel"));
|
fButton->SetLabel(B_TRANSLATE("Cancel"));
|
||||||
@@ -762,7 +780,7 @@ GrepWindow::_OnStartCancel()
|
|||||||
_SetWindowTitle();
|
_SetWindowTitle();
|
||||||
|
|
||||||
FileIterator* iterator = new (nothrow) InitialIterator(fModel);
|
FileIterator* iterator = new (nothrow) InitialIterator(fModel);
|
||||||
fGrepper = new (nothrow) Grepper(fOldPattern.String(), fModel,
|
fGrepper = new (nothrow) Grepper(fOldPattern.String(), fIncludeFilesGlob.String(), fModel,
|
||||||
this, iterator);
|
this, iterator);
|
||||||
if (fGrepper != NULL && fGrepper->IsValid())
|
if (fGrepper != NULL && fGrepper->IsValid())
|
||||||
fGrepper->Start();
|
fGrepper->Start();
|
||||||
@@ -810,6 +828,8 @@ GrepWindow::_OnSearchFinished()
|
|||||||
fSearchText->SetText(fOldPattern.String());
|
fSearchText->SetText(fOldPattern.String());
|
||||||
fSearchText->TextView()->SelectAll();
|
fSearchText->TextView()->SelectAll();
|
||||||
fSearchText->SetModificationMessage(new BMessage(MSG_SEARCH_TEXT));
|
fSearchText->SetModificationMessage(new BMessage(MSG_SEARCH_TEXT));
|
||||||
|
fGlobText->SetEnabled(true);
|
||||||
|
fGlobText->SetModificationMessage(new BMessage(MSG_SEARCH_GLOB_FILTER));
|
||||||
|
|
||||||
PostMessage(MSG_START_NODE_MONITORING);
|
PostMessage(MSG_START_NODE_MONITORING);
|
||||||
}
|
}
|
||||||
@@ -968,7 +988,7 @@ GrepWindow::_OnNodeMonitorPulse()
|
|||||||
fChangesIterator->PrintToStream();
|
fChangesIterator->PrintToStream();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fGrepper = new (nothrow) Grepper(fOldPattern.String(), fModel,
|
fGrepper = new (nothrow) Grepper(fOldPattern.String(), fIncludeFilesGlob.String(), fModel,
|
||||||
this, fChangesIterator);
|
this, fChangesIterator);
|
||||||
if (fGrepper != NULL && fGrepper->IsValid()) {
|
if (fGrepper != NULL && fGrepper->IsValid()) {
|
||||||
fGrepper->Start();
|
fGrepper->Start();
|
||||||
@@ -1558,6 +1578,15 @@ GrepWindow::_OnSetTargetToParent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GrepWindow::_OnGlobFilterChange()
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
fIncludeFilesGlob = fGlobText->Text();
|
||||||
|
_StopNodeMonitoring();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ private:
|
|||||||
void _OnSelectAll(BMessage* message);
|
void _OnSelectAll(BMessage* message);
|
||||||
void _OnNewWindow();
|
void _OnNewWindow();
|
||||||
void _OnSetTargetToParent();
|
void _OnSetTargetToParent();
|
||||||
|
void _OnGlobFilterChange();
|
||||||
|
|
||||||
void _ModelChanged();
|
void _ModelChanged();
|
||||||
bool _OpenInEditor(const entry_ref& ref, int32 lineNum);
|
bool _OpenInEditor(const entry_ref& ref, int32 lineNum);
|
||||||
@@ -85,6 +86,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BTextControl* fSearchText;
|
BTextControl* fSearchText;
|
||||||
|
BTextControl* fGlobText;
|
||||||
GrepListView* fSearchResults;
|
GrepListView* fSearchResults;
|
||||||
|
|
||||||
BMenuBar* fMenuBar;
|
BMenuBar* fMenuBar;
|
||||||
@@ -121,6 +123,7 @@ private:
|
|||||||
|
|
||||||
Grepper* fGrepper;
|
Grepper* fGrepper;
|
||||||
BString fOldPattern;
|
BString fOldPattern;
|
||||||
|
BString fIncludeFilesGlob;
|
||||||
Model* fModel;
|
Model* fModel;
|
||||||
bigtime_t fLastNodeMonitorEvent;
|
bigtime_t fLastNodeMonitorEvent;
|
||||||
ChangesIterator* fChangesIterator;
|
ChangesIterator* fChangesIterator;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ strdup_from_utf8(uint32 encode, const char* src, int32 length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Grepper::Grepper(const char* pattern, const Model* model,
|
Grepper::Grepper(const char* pattern, const char* glob, const Model* model,
|
||||||
const BHandler* target, FileIterator* iterator)
|
const BHandler* target, FileIterator* iterator)
|
||||||
: fPattern(NULL),
|
: fPattern(NULL),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
@@ -107,6 +107,8 @@ Grepper::Grepper(const char* pattern, const Model* model,
|
|||||||
free(src);
|
free(src);
|
||||||
} else
|
} else
|
||||||
_SetPattern(pattern);
|
_SetPattern(pattern);
|
||||||
|
|
||||||
|
fGlob = strdup(glob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -114,6 +116,7 @@ Grepper::~Grepper()
|
|||||||
{
|
{
|
||||||
Cancel();
|
Cancel();
|
||||||
free(fPattern);
|
free(fPattern);
|
||||||
|
free(fGlob);
|
||||||
delete fIterator;
|
delete fIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,6 +274,13 @@ Grepper::_RunnerThread()
|
|||||||
argv[argc++] = "-i";
|
argv[argc++] = "-i";
|
||||||
if (! fRegularExpression)
|
if (! fRegularExpression)
|
||||||
argv[argc++] = "-F"; // no a regexp: force fixed string,
|
argv[argc++] = "-F"; // no a regexp: force fixed string,
|
||||||
|
|
||||||
|
// Limit included files to fGlob pattern, if one was given.
|
||||||
|
if (strlen(fGlob) > 0) {
|
||||||
|
argv[argc++] = "--include";
|
||||||
|
argv[argc++] = fGlob;
|
||||||
|
}
|
||||||
|
|
||||||
// Add double dash argument to tell grep
|
// Add double dash argument to tell grep
|
||||||
// it's the end of commands options
|
// it's the end of commands options
|
||||||
argv[argc++] = "--";
|
argv[argc++] = "--";
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Model;
|
|||||||
// Executes "grep" in a background thread.
|
// Executes "grep" in a background thread.
|
||||||
class Grepper {
|
class Grepper {
|
||||||
public:
|
public:
|
||||||
Grepper(const char* pattern, const Model* model,
|
Grepper(const char* pattern, const char* glob, const Model* model,
|
||||||
const BHandler* target,
|
const BHandler* target,
|
||||||
FileIterator* iterator);
|
FileIterator* iterator);
|
||||||
virtual ~Grepper();
|
virtual ~Grepper();
|
||||||
@@ -43,6 +43,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
// The (escaped) search pattern.
|
// The (escaped) search pattern.
|
||||||
char* fPattern;
|
char* fPattern;
|
||||||
|
char* fGlob;
|
||||||
|
|
||||||
// The settings from the model.
|
// The settings from the model.
|
||||||
BMessenger fTarget;
|
BMessenger fTarget;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ enum {
|
|||||||
MSG_INVOKE_EDITOR,
|
MSG_INVOKE_EDITOR,
|
||||||
MSG_CHECKBOX_SHOW_LINES,
|
MSG_CHECKBOX_SHOW_LINES,
|
||||||
MSG_SEARCH_TEXT,
|
MSG_SEARCH_TEXT,
|
||||||
|
MSG_SEARCH_GLOB_FILTER,
|
||||||
MSG_INVOKE_ITEM,
|
MSG_INVOKE_ITEM,
|
||||||
MSG_SELECT_HISTORY,
|
MSG_SELECT_HISTORY,
|
||||||
MSG_NODE_MONITOR_PULSE,
|
MSG_NODE_MONITOR_PULSE,
|
||||||
|
|||||||
Reference in New Issue
Block a user