summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp15
-rw-r--r--src/main_windows.cpp8
-rw-r--r--src/search.cpp6
-rw-r--r--src/search.h2
4 files changed, 27 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 687bbab..3566695 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -117,8 +117,8 @@ static int _ts_create_menu() {
}
void ts_init() {
- snprintf(path_buffer, MAX_INPUT_LENGTH, "%s", "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\allegro5\\build\\tests");
- snprintf(filter_buffer, MAX_INPUT_LENGTH, "%s", "*.h");
+ snprintf(path_buffer, MAX_INPUT_LENGTH, "%s", "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\allegro5");
+ snprintf(filter_buffer, MAX_INPUT_LENGTH, "%s", "*.c,.h,.cpp");
snprintf(query_buffer, MAX_INPUT_LENGTH, "%s", "test");
}
@@ -169,7 +169,9 @@ void ts_create_gui(int window_w, int window_h) {
ImGui::PopItemWidth();
ImGui::PushItemWidth(-1);
- ImGui::InputTextWithHint("query", "Query", query_buffer, 4000, ImGuiInputTextFlags_CallbackEdit, _tb_query_input_cb);
+ if (ImGui::InputTextWithHint("query", "Query", query_buffer, 4000, ImGuiInputTextFlags_CallbackEdit|ImGuiInputTextFlags_EnterReturnsTrue, _tb_query_input_cb)) {
+ ts_start_search(path_buffer, filter_buffer, query_buffer);
+ }
ImGui::PopItemWidth();
ImGui::PopStyleVar();
}
@@ -187,6 +189,13 @@ void ts_create_gui(int window_w, int window_h) {
if (current_search_result && !current_search_result->search_completed) {
ImSpinner::SpinnerIncScaleDots("Spinner", 10.0f, 2.0f, ImColor(70,70,70), 5.0f);
}
+ else {
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
+ if (ImGui::Button("Search")) {
+ ts_start_search(path_buffer, filter_buffer, query_buffer);
+ }
+ ImGui::PopStyleVar();
+ }
}
ImGui::EndChild();
diff --git a/src/main_windows.cpp b/src/main_windows.cpp
index d985416..cbc7265 100644
--- a/src/main_windows.cpp
+++ b/src/main_windows.cpp
@@ -312,6 +312,14 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir)
(file_info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ||
(file_info.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE))
{
+ char *matched_filter = 0;
+ utf8_int8_t uni_name[MAX_INPUT_LENGTH];
+ WideCharToMultiByte(CP_UTF8,0,name,-1,(LPSTR)uni_name,MAX_INPUT_LENGTH, NULL, NULL);
+ if (ts_filter_matches(&result->filters, uni_name, &matched_filter) == -1) {
+ continue;
+ }
+ (void)matched_filter;
+
wchar_t complete_file_path[MAX_INPUT_LENGTH];
wcscpy(complete_file_path, search_dir);
wcscat(complete_file_path, L"\\");
diff --git a/src/search.cpp b/src/search.cpp
index 76d7b92..e90e433 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -71,7 +71,10 @@ int ts_filter_matches(ts_array *filters, char *string, char **matched_filter)
for (int i = 0; i < filters->length; i++)
{
char *filter = (char *)ts_array_at(filters, i);
- if (ts_string_match(filter, string))
+
+ char wildcard_filter[MAX_INPUT_LENGTH];
+ snprintf(wildcard_filter, MAX_INPUT_LENGTH, "*%s", filter);
+ if (ts_string_match(wildcard_filter, string))
{
*matched_filter = filter;
return strlen(filter);
@@ -357,6 +360,7 @@ void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query)
ts_search_result *new_result = ts_create_empty_search_result();
snprintf(new_result->directory_to_search, MAX_INPUT_LENGTH, "%s", path);
snprintf(new_result->search_text, MAX_INPUT_LENGTH, "%s", query);
+ new_result->filters = ts_get_filters(filter);
_ts_list_files(new_result);
for (int i = 0; i < new_result->max_ts_thread_count; i++)
diff --git a/src/search.h b/src/search.h
index b8cfb24..f8ddc6c 100644
--- a/src/search.h
+++ b/src/search.h
@@ -21,6 +21,7 @@ typedef struct t_ts_search_result
// data
ts_array files;
ts_array matches;
+ ts_array filters;
int match_count;
int file_count;
@@ -34,6 +35,7 @@ typedef struct t_ts_search_result
// search query
utf8_int8_t *directory_to_search;
+ utf8_int8_t *file_filter;
utf8_int8_t *search_text;
int max_ts_thread_count;
int max_file_size;