hrev51529 adds 1 changeset to branch 'master'
old head: 83e8a2654cac7e9419e4222a653d32b0614e4dd3
new head: 653c76760241871dd426c21a99aea4109ed0278e
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=653c76760241+%5E83e8a2654cac
----------------------------------------------------------------------------
653c76760241: 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".
[ Philippe Houdoin <philippe.houdoin@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev51529
Commit: 653c76760241871dd426c21a99aea4109ed0278e
URL: http://cgit.haiku-os.org/haiku/commit/?id=653c76760241
Author: Philippe Houdoin <philippe.houdoin@xxxxxxxxx>
Date: Tue Nov 7 09:28:20 2017 UTC
Ticket: https://dev.haiku-os.org/ticket/13289
----------------------------------------------------------------------------
5 files changed, 48 insertions(+), 23 deletions(-)
src/apps/text_search/GrepWindow.cpp | 27 +++++++++++++++++----------
src/apps/text_search/GrepWindow.h | 1 -
src/apps/text_search/Grepper.cpp | 32 ++++++++++++++++++++------------
src/apps/text_search/Model.cpp | 8 ++++++++
src/apps/text_search/Model.h | 3 +++
----------------------------------------------------------------------------
diff --git a/src/apps/text_search/GrepWindow.cpp
b/src/apps/text_search/GrepWindow.cpp
index 4b17ce9..97683b0 100644
--- a/src/apps/text_search/GrepWindow.cpp
+++ b/src/apps/text_search/GrepWindow.cpp
@@ -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)
- done = _OpenInPe(entry->ref, lineNum);
-
- if (!done)
- be_roster->Launch(&entry->ref);
+ if (fModel->fInvokePe && _OpenInPe(entry->ref, lineNum))
+ return;
+
+ // 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);
}
}
}
diff --git a/src/apps/text_search/GrepWindow.h
b/src/apps/text_search/GrepWindow.h
index 651db09..3602415 100644
--- a/src/apps/text_search/GrepWindow.h
+++ b/src/apps/text_search/GrepWindow.h
@@ -122,7 +122,6 @@ private:
bigtime_t fLastNodeMonitorEvent;
ChangesIterator* fChangesIterator;
BMessageRunner* fChangesPulse;
- float fSearchBoxWidth;
BFilePanel* fFilePanel;
diff --git a/src/apps/text_search/Grepper.cpp b/src/apps/text_search/Grepper.cpp
index b69349d..d0a7b82 100644
--- a/src/apps/text_search/Grepper.cpp
+++ b/src/apps/text_search/Grepper.cpp
@@ -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));
diff --git a/src/apps/text_search/Model.cpp b/src/apps/text_search/Model.cpp
index b2cde14..4caaf5a 100644
--- a/src/apps/text_search/Model.cpp
+++ b/src/apps/text_search/Model.cpp
@@ -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();
diff --git a/src/apps/text_search/Model.h b/src/apps/text_search/Model.h
index fb52962..9edc823 100644
--- a/src/apps/text_search/Model.h
+++ b/src/apps/text_search/Model.h
@@ -105,6 +105,9 @@ public:
// Current directory of the filepanel
BString fFilePanelPath;
+ // Show lines ?
+ bool fShowLines;
+
// Grep string encoding ?
uint32 fEncoding;