From c3a430aa1828e2c161023076cc260eeda740ae7f Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 6 Mar 2024 21:22:48 +0100 Subject: show red border on input when path is invalid --- src/main.cpp | 4 ++++ src/main_windows.cpp | 10 ++++++++++ src/platform.h | 1 + 3 files changed, 15 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 56be834..317a56e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -267,7 +267,11 @@ void ts_create_gui(int window_w, int window_h) { { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::PushItemWidth(-1); + + bool dir_exists = ts_platform_dir_exists(path_buffer); + if (!dir_exists) ImGui::PushStyleColor(ImGuiCol_Border, ImGui::Spectrum::Color(0xCC2222)); ImGui::InputTextWithHint("path-ti", "Path", path_buffer, MAX_INPUT_LENGTH); + if (!dir_exists) ImGui::PopStyleColor(); ImGui::PopItemWidth(); ImGui::SetItemTooltip("Absolute path to directory to search"); diff --git a/src/main_windows.cpp b/src/main_windows.cpp index c574b2f..7c6fba2 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -52,6 +52,16 @@ static const char* _ts_platform_get_config_file_path(char* buffer) { return 0; } +bool ts_platform_dir_exists(utf8_int8_t* dir) +{ + DWORD ftyp = GetFileAttributesA(dir); + if (ftyp == INVALID_FILE_ATTRIBUTES) + return false; + if (ftyp & FILE_ATTRIBUTE_DIRECTORY) + return true; + return false; +} + uint64_t ts_platform_get_time(uint64_t compare) { LARGE_INTEGER stamp; diff --git a/src/platform.h b/src/platform.h index e9d7ba5..7fdc15a 100644 --- a/src/platform.h +++ b/src/platform.h @@ -31,6 +31,7 @@ typedef enum t_ts_file_open_error extern bool program_running; +bool ts_platform_dir_exists(utf8_int8_t* dir); ts_file_content ts_platform_read_file(char *path, const char *mode); void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_dir = nullptr); void ts_platform_list_files(ts_search_result* result); -- cgit v1.2.3-70-g09d2