TextSearch: several small improvements
* Wakeup periodically search thread, cancelling should be more responsive now... * Show Lines setting is now saved too * Fix a bug, current file is display again while searching. * Always pass line number, if any, to invoked app. Works with StyledEdit as with Pe. Partially fix #13289. Another change will add "open with" context menu and remove "Open with Pe".
This commit is contained in:
parent
83e8a2654c
commit
653c767602
@ -128,7 +128,6 @@ GrepWindow::GrepWindow(BMessage* message)
|
||||
_LoadPrefs();
|
||||
_TileIfMultipleWindows();
|
||||
|
||||
fSearchBoxWidth = fSearchText->Bounds().Width();
|
||||
Show();
|
||||
}
|
||||
|
||||
@ -611,6 +610,8 @@ GrepWindow::_LoadPrefs()
|
||||
fTextOnly->SetMarked(fModel->fTextOnly);
|
||||
fInvokePe->SetMarked(fModel->fInvokePe);
|
||||
|
||||
fShowLinesCheckbox->SetValue(fModel->fShowLines);
|
||||
|
||||
switch (fModel->fEncoding) {
|
||||
case 0:
|
||||
fUTF8->SetMarked(true);
|
||||
@ -960,7 +961,7 @@ GrepWindow::_OnReportFileName(BMessage* message)
|
||||
if (fModel->fState != STATE_UPDATE) {
|
||||
BString name = message->FindString("filename");
|
||||
fSearchText->TruncateString(&name, B_TRUNCATE_MIDDLE,
|
||||
fSearchBoxWidth - 10);
|
||||
fSearchText->Bounds().Width() - 10);
|
||||
|
||||
fSearchText->SetText(name);
|
||||
}
|
||||
@ -1121,11 +1122,13 @@ GrepWindow::_OnCheckboxShowLines()
|
||||
// I think it's the least bad of what's possible on BeOS R5,
|
||||
// but perhaps someone comes along with a patch of magic.
|
||||
|
||||
fModel->fShowLines = (fShowLinesCheckbox->Value() == 1);
|
||||
|
||||
int32 numItems = fSearchResults->FullListCountItems();
|
||||
for (int32 x = 0; x < numItems; ++x) {
|
||||
BListItem* listItem = fSearchResults->FullListItemAt(x);
|
||||
if (listItem->OutlineLevel() == 0) {
|
||||
if (fShowLinesCheckbox->Value() == 1) {
|
||||
if (fModel->fShowLines) {
|
||||
if (!fSearchResults->IsExpanded(x))
|
||||
fSearchResults->Expand(listItem);
|
||||
} else {
|
||||
@ -1173,13 +1176,17 @@ GrepWindow::_OnInvokeItem()
|
||||
|
||||
ResultItem* entry = dynamic_cast<ResultItem*>(item);
|
||||
if (entry != NULL) {
|
||||
bool done = false;
|
||||
if (fModel->fInvokePe && _OpenInPe(entry->ref, lineNum))
|
||||
return;
|
||||
|
||||
if (fModel->fInvokePe)
|
||||
done = _OpenInPe(entry->ref, lineNum);
|
||||
|
||||
if (!done)
|
||||
be_roster->Launch(&entry->ref);
|
||||
// ask tracker to open it for us
|
||||
BMessenger target(TRACKER_SIGNATURE);
|
||||
BMessage message(B_REFS_RECEIVED);
|
||||
message.AddRef("refs", &entry->ref);
|
||||
if (lineNum > -1) {
|
||||
message.AddInt32("be:line", lineNum);
|
||||
}
|
||||
target.SendMessage(&message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,6 @@ private:
|
||||
bigtime_t fLastNodeMonitorEvent;
|
||||
ChangesIterator* fChangesIterator;
|
||||
BMessageRunner* fChangesPulse;
|
||||
float fSearchBoxWidth;
|
||||
|
||||
|
||||
BFilePanel* fFilePanel;
|
||||
|
@ -11,16 +11,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <OS.h>
|
||||
#include <image.h>
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <Directory.h>
|
||||
#include <image.h>
|
||||
#include <List.h>
|
||||
#include <Locale.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <OS.h>
|
||||
#include <Path.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
@ -301,12 +301,6 @@ Grepper::_RunnerThread()
|
||||
}
|
||||
set_thread_priority(xargsThread, B_LOW_PRIORITY);
|
||||
|
||||
thread_id writerThread = spawn_thread(_SpawnWriterThread,
|
||||
"Grep writer", B_LOW_PRIORITY, this);
|
||||
// let's go!
|
||||
resume_thread(xargsThread);
|
||||
resume_thread(writerThread);
|
||||
|
||||
// Listen on xargs's stdout and stderr via select()
|
||||
printf("Running: ");
|
||||
for (int i = 0; i < argc; i++) {
|
||||
@ -322,6 +316,7 @@ Grepper::_RunnerThread()
|
||||
}
|
||||
|
||||
fd_set readSet;
|
||||
struct timeval timeout = { 0, 100000 };
|
||||
char line[B_PATH_NAME_LENGTH * 2];
|
||||
|
||||
FILE* output = fdopen(out, "r");
|
||||
@ -331,6 +326,13 @@ Grepper::_RunnerThread()
|
||||
currentFileName[0] = '\0';
|
||||
bool canReadOutput, canReadErrors;
|
||||
canReadOutput = canReadErrors = true;
|
||||
|
||||
thread_id writerThread = spawn_thread(_SpawnWriterThread,
|
||||
"Grep writer", B_LOW_PRIORITY, this);
|
||||
// let's go!
|
||||
resume_thread(xargsThread);
|
||||
resume_thread(writerThread);
|
||||
|
||||
while (!fMustQuit && (canReadOutput || canReadErrors)) {
|
||||
FD_ZERO(&readSet);
|
||||
if (canReadOutput) {
|
||||
@ -340,9 +342,15 @@ Grepper::_RunnerThread()
|
||||
FD_SET(err, &readSet);
|
||||
}
|
||||
|
||||
int result = select(maxfd + 1, &readSet, NULL, NULL, NULL);
|
||||
int result = select(maxfd + 1, &readSet, NULL, NULL, &timeout);
|
||||
if (result == -1 && errno == EINTR)
|
||||
continue;
|
||||
if (result == 0) {
|
||||
// timeout, but meanwhile fMustQuit was changed maybe...
|
||||
continue;
|
||||
}
|
||||
if (result < 0) {
|
||||
printf("select(): %d (%s)\n", result, strerror(errno));
|
||||
perror("select():");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -372,7 +380,7 @@ Grepper::_RunnerThread()
|
||||
}
|
||||
|
||||
char* text = &line[strlen(fileName)+1];
|
||||
printf("[%s] %s", fileName, text);
|
||||
// printf("[%s] %s", fileName, text);
|
||||
if (fEncoding > 0) {
|
||||
char* tempdup = strdup_to_utf8(fEncoding, text,
|
||||
strlen(text));
|
||||
|
@ -45,6 +45,7 @@ Model::Model()
|
||||
|
||||
fFilePanelPath(""),
|
||||
|
||||
fShowLines(true),
|
||||
fEncoding(0)
|
||||
{
|
||||
BPath path;
|
||||
@ -110,6 +111,10 @@ Model::LoadPrefs()
|
||||
|
||||
file.ReadAttr("WindowFrame", B_RECT_TYPE, 0, &fFrame, sizeof(BRect));
|
||||
|
||||
if (file.ReadAttr("ShowLines", B_INT32_TYPE, 0, &value,
|
||||
sizeof(int32)) > 0)
|
||||
fShowLines = (value != 0);
|
||||
|
||||
if (file.ReadAttr("Encoding", B_INT32_TYPE, 0, &value, sizeof(int32)) > 0)
|
||||
fEncoding = value;
|
||||
|
||||
@ -161,6 +166,9 @@ Model::SavePrefs()
|
||||
file.WriteAttr("FilePanelPath", B_STRING_TYPE, 0, fFilePanelPath.String(),
|
||||
fFilePanelPath.Length() + 1);
|
||||
|
||||
value = fShowLines ? 1 : 0;
|
||||
file.WriteAttr("ShowLines", B_INT32_TYPE, 0, &value, sizeof(int32));
|
||||
|
||||
file.WriteAttr("Encoding", B_INT32_TYPE, 0, &fEncoding, sizeof(int32));
|
||||
|
||||
file.Sync();
|
||||
|
@ -105,6 +105,9 @@ public:
|
||||
// Current directory of the filepanel
|
||||
BString fFilePanelPath;
|
||||
|
||||
// Show lines ?
|
||||
bool fShowLines;
|
||||
|
||||
// Grep string encoding ?
|
||||
uint32 fEncoding;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user