summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp26
-rw-r--r--src/main_windows.cpp6
-rw-r--r--src/search.cpp6
-rw-r--r--src/search.h1
4 files changed, 26 insertions, 13 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4046004..4a26ceb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,7 @@
#include "../imgui/imgui.h"
#include "../imgui/imgui_spectrum.h"
#include "../imgui/imgui_impl_opengl3_loader.h"
+#include "../imgui/imspinner.h"
#include "../utf8.h"
#include "definitions.h"
#include "search.h"
@@ -9,11 +10,9 @@
#include <stdio.h>
-#define SEARCH_BUFFER_SIZE 2048
-
-utf8_int8_t path_buffer[SEARCH_BUFFER_SIZE];
-utf8_int8_t filter_buffer[SEARCH_BUFFER_SIZE];
-utf8_int8_t query_buffer[SEARCH_BUFFER_SIZE];
+utf8_int8_t path_buffer[MAX_INPUT_LENGTH];
+utf8_int8_t filter_buffer[MAX_INPUT_LENGTH];
+utf8_int8_t query_buffer[MAX_INPUT_LENGTH];
bool open_settings_window = false;
bool open_about_window = false;
@@ -123,6 +122,15 @@ void ts_init() {
snprintf(query_buffer, MAX_INPUT_LENGTH, "%s", "test");
}
+int _tb_query_input_cb(ImGuiInputTextCallbackData* data) {
+ if (data->EventFlag == ImGuiInputTextFlags_CallbackEdit) {
+ utf8ncpy(query_buffer, data->Buf, MAX_INPUT_LENGTH);
+ ts_start_search(path_buffer, filter_buffer, query_buffer);
+ }
+
+ return 0;
+}
+
void ts_create_gui(int window_w, int window_h) {
static float f = 0.0f;
static int counter = 0;
@@ -161,7 +169,7 @@ void ts_create_gui(int window_w, int window_h) {
ImGui::PopItemWidth();
ImGui::PushItemWidth(-1);
- ImGui::InputTextWithHint("query", "Query", query_buffer, 4000);
+ ImGui::InputTextWithHint("query", "Query", query_buffer, 4000, ImGuiInputTextFlags_CallbackEdit, _tb_query_input_cb);
ImGui::PopItemWidth();
ImGui::PopStyleVar();
}
@@ -176,11 +184,9 @@ void ts_create_gui(int window_w, int window_h) {
ImGui::PopItemWidth();
ImGui::PopStyleVar();
- ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
- if (ImGui::Button("Search")) {
- ts_start_search(path_buffer, filter_buffer, query_buffer);
+ if (current_search_result && !current_search_result->search_completed) {
+ ImSpinner::SpinnerIncScaleDots("Spinner", 10.0f, 2.0f, ImColor(70,70,70), 5.0f);
}
- ImGui::PopStyleVar();
}
ImGui::EndChild();
diff --git a/src/main_windows.cpp b/src/main_windows.cpp
index 5b98eed..d0db43e 100644
--- a/src/main_windows.cpp
+++ b/src/main_windows.cpp
@@ -300,6 +300,12 @@ static void *_list_files_thread(void *args)
ts_search_result *info = (ts_search_result *)args;
ts_platform_list_files_block(info, nullptr);
info->done_finding_files = true;
+
+ while (!info->search_completed) {
+ if (info->completed_match_threads == info->max_ts_thread_count) {
+ info->search_completed = true;
+ }
+ }
return 0;
}
diff --git a/src/search.cpp b/src/search.cpp
index 9a55105..5e4e934 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -87,8 +87,9 @@ ts_search_result *ts_create_empty_search_result()
new_result_buffer->mutex = ts_mutex_create();
new_result_buffer->done_finding_files = false;
new_result_buffer->file_list_read_cursor = 0;
- new_result_buffer->max_ts_thread_count = 4;
+ new_result_buffer->max_ts_thread_count = 1;
new_result_buffer->match_count = 0;
+ new_result_buffer->search_completed = false;
new_result_buffer->file_count = 0;
new_result_buffer->cancel_search = false;
new_result_buffer->max_file_size = megabytes(1000);
@@ -342,8 +343,7 @@ void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query)
snprintf(new_result->search_text, MAX_INPUT_LENGTH, "%s", query);
ts_platform_list_files(new_result);
- // new_result->max_ts_thread_count
- for (int i = 0; i < 1; i++)
+ for (int i = 0; i < new_result->max_ts_thread_count; i++)
{
ts_thread thr = ts_thread_start(_ts_search_thread, new_result);
ts_thread_detach(&thr);
diff --git a/src/search.h b/src/search.h
index 3518b33..73eb17a 100644
--- a/src/search.h
+++ b/src/search.h
@@ -30,6 +30,7 @@ typedef struct t_ts_search_result
int done_finding_files;
int file_list_read_cursor;
bool cancel_search;
+ bool search_completed;
// search query
utf8_int8_t *directory_to_search;