summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.cpp1
-rw-r--r--src/config.h4
-rw-r--r--src/main.cpp17
-rw-r--r--src/platform.h1
-rw-r--r--src/unix/main_unix.cpp7
-rw-r--r--src/windows/main_windows.cpp12
6 files changed, 39 insertions, 3 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 1dd0284..04ad58e 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -6,6 +6,7 @@
#include <string.h>
#include <cstring>
+utf8_int8_t save_path[MAX_INPUT_LENGTH];
utf8_int8_t path_buffer[MAX_INPUT_LENGTH];
utf8_int8_t filter_buffer[MAX_INPUT_LENGTH];
utf8_int8_t query_buffer[MAX_INPUT_LENGTH];
diff --git a/src/config.h b/src/config.h
index d57c7c7..2e64755 100644
--- a/src/config.h
+++ b/src/config.h
@@ -17,6 +17,10 @@
#include "../imgui/imgui.h"
#include "../utf8.h"
+// Current session only.
+extern utf8_int8_t save_path[MAX_INPUT_LENGTH];
+
+// Stored in config.
extern utf8_int8_t path_buffer[MAX_INPUT_LENGTH];
extern utf8_int8_t filter_buffer[MAX_INPUT_LENGTH];
extern utf8_int8_t query_buffer[MAX_INPUT_LENGTH];
diff --git a/src/main.cpp b/src/main.cpp
index bcbc4df..e1bb34f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -141,6 +141,12 @@ static int _ts_create_menu(int window_w, int window_h) {
if (ImGui::BeginMenu("File"))
{
//ImGui::MenuItem("Open", "CTRL+O");
+ if (ImGui::MenuItem("Save")) {
+ if (strlen(save_path) == 0)
+ ifd::FileDialog::Instance().Save("FileSaveAsDialog", "Save results to file", "File (*.csv;*.json;*.xml){.csv,.json,.xml}");
+ else
+ ts_export_result(current_search_result, (const utf8_int8_t *)save_path);
+ }
if (ImGui::MenuItem("Save As")) {
ifd::FileDialog::Instance().Save("FileSaveAsDialog", "Save results to file", "File (*.csv;*.json;*.xml){.csv,.json,.xml}");
}
@@ -174,6 +180,12 @@ static int _ts_create_menu(int window_w, int window_h) {
if (ifd::FileDialog::Instance().HasResult()) {
std::string res = ifd::FileDialog::Instance().GetResult().u8string();
ts_export_result(current_search_result, (const utf8_int8_t *)res.c_str());
+ utf8ncpy(save_path, (const utf8_int8_t *)res.c_str(), sizeof(save_path));
+
+ // Set titlebar name.
+ utf8_int8_t new_name[MAX_INPUT_LENGTH];
+ snprintf(new_name, MAX_INPUT_LENGTH, "Text-Search > %s", res.c_str());
+ ts_platform_set_window_title(new_name);
}
ifd::FileDialog::Instance().Close();
}
@@ -182,7 +194,10 @@ static int _ts_create_menu(int window_w, int window_h) {
}
void ts_init() {
- // idk
+ memset(save_path, 0, sizeof(save_path));
+ memset(path_buffer, 0, sizeof(path_buffer));
+ memset(filter_buffer, 0, sizeof(filter_buffer));
+ memset(query_buffer, 0, sizeof(query_buffer));
}
int _tb_query_input_cb(ImGuiInputTextCallbackData* data) {
diff --git a/src/platform.h b/src/platform.h
index 8d5583c..3f41e4f 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -37,5 +37,6 @@ void ts_platform_list_files_block(ts_search_result* result, wchar_t* start_di
uint64_t ts_platform_get_time(uint64_t compare = 0); // if compare is not 0, return difference between timestamp and now, in milliseconds.
void ts_platform_open_file_as(utf8_int8_t* str);
void ts_platform_open_file_in_folder(utf8_int8_t* file);
+void ts_platform_set_window_title(utf8_int8_t* str);
#endif \ No newline at end of file
diff --git a/src/unix/main_unix.cpp b/src/unix/main_unix.cpp
index f25111d..9dd9e62 100644
--- a/src/unix/main_unix.cpp
+++ b/src/unix/main_unix.cpp
@@ -65,6 +65,8 @@ int main(int, char**)
if (!glfwInit())
return 1;
+ ts_init();
+
// Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2)
// GL ES 2.0 + GLSL 100
@@ -112,7 +114,6 @@ int main(int, char**)
ImGui::Spectrum::StyleColorsSpectrum();
ImGui::Spectrum::LoadFont(18.0f);
- ts_init();
ts_load_images();
ts_load_config();
@@ -163,6 +164,10 @@ bool ts_platform_dir_exists(utf8_int8_t* path) {
}
}
+void ts_platform_set_window_title(utf8_int8_t* str) {
+ // TODO
+}
+
ts_file_content ts_platform_read_file(char *path, const char *mode) {
ts_file_content result;
result.content = 0;
diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp
index af64fc6..f7f2901 100644
--- a/src/windows/main_windows.cpp
+++ b/src/windows/main_windows.cpp
@@ -41,6 +41,7 @@ static int g_Width;
static int g_Height;
LARGE_INTEGER Frequency;
bool program_running = true;
+HWND window_handle;
bool CreateDeviceWGL(HWND hWnd, WGL_WindowData* data);
void CleanupDeviceWGL(HWND hWnd, WGL_WindowData* data);
@@ -97,15 +98,25 @@ static void _ts_platform_draw_frame() {
::SwapBuffers(g_MainWindow.hDC);
}
+void ts_platform_set_window_title(utf8_int8_t* str) {
+ // convert utf8 to wchar path.
+ wchar_t wchar_buffer[MAX_INPUT_LENGTH];
+ MultiByteToWideChar(CP_UTF8, 0, str, -1, (wchar_t*)wchar_buffer, MAX_INPUT_LENGTH);
+
+ SetWindowTextW(window_handle, wchar_buffer);
+}
+
int main(int, char**)
{
CoInitializeEx(0, COINIT_MULTITHREADED|COINIT_DISABLE_OLE1DDE);
+ ts_init();
// Create application window
//ImGui_ImplWin32_EnableDpiAwareness();
WNDCLASSEXW wc = { sizeof(wc), CS_OWNDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr };
::RegisterClassExW(&wc);
HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Text-Search", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr);
+ window_handle = hwnd;
// Initialize OpenGL
if (!CreateDeviceWGL(hwnd, &g_MainWindow))
@@ -143,7 +154,6 @@ int main(int, char**)
QueryPerformanceFrequency(&Frequency);
- ts_init();
ts_load_images();
ts_load_config();