diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 95 |
1 files changed, 2 insertions, 93 deletions
diff --git a/src/main.cpp b/src/main.cpp index c06fa2b..ee73d7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,99 +178,8 @@ static int _ts_create_menu(int window_w, int window_h) { ImGui::PopStyleColor(); _ts_create_popups(); - - // File exporting. - if (ifd::FileDialog::Instance().IsDone("FileSaveAsDialog", window_w, window_h)) { - if (ifd::FileDialog::Instance().HasResult()) { - std::string res = ifd::FileDialog::Instance().GetResult().u8string(); - last_export_result = 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(); - } - - // File importing. - if (ifd::FileDialog::Instance().IsDone("FileOpenDialog", window_w, window_h)) { - if (ifd::FileDialog::Instance().HasResult()) { - std::string res = ifd::FileDialog::Instance().GetResult().u8string(); - 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); - - current_search_result = ts_import_result(save_path); - } - ifd::FileDialog::Instance().Close(); - } - - - if (last_import_result != EXPORT_NONE) { - ImGui::OpenPopup("Import Failed"); - ImGuiIO& io = ImGui::GetIO(); - ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f,0.5f)); - } - - // import error popup - if (ImGui::BeginPopupModal("Import Failed", (bool*)&last_import_result, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove)) { - ImGui::SetWindowSize({300, 0}); - - switch (last_import_result) - { - case IMPORT_INVALID_DATA: ImGui::Text("File has invalid format"); break; - case IMPORT_INVALID_VERSION: ImGui::Text("File has unknown version"); break; - case IMPORT_FILE_ERROR: ImGui::Text("Failed to open file"); break; - default: - break; - } - - ImGui::Dummy({0, 20}); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); - if (ImGui::Button("Close")) { - last_import_result = IMPORT_NONE; - ImGui::CloseCurrentPopup(); - } - ImGui::PopStyleVar(); - - ImGui::EndPopup(); - } - - if (last_export_result != EXPORT_NONE) { - ImGui::OpenPopup("Export Failed"); - ImGuiIO& io = ImGui::GetIO(); - ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f,0.5f)); - } - - // export error popup - if (ImGui::BeginPopupModal("Export Failed", (bool*)&last_export_result, ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove)) { - ImGui::SetWindowSize({300, 0}); - - switch (last_export_result) - { - case EXPORT_NO_RESULT: ImGui::Text("No results to export"); break; - case EXPORT_SEARCH_ACTIVE: ImGui::Text("Can't export while save is active"); break; - case EXPORT_SAVE_PENDING: ImGui::Text("Export is pending"); break; - - default: - break; - } - - ImGui::Dummy({0, 20}); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); - if (ImGui::Button("Close")) { - last_export_result = EXPORT_NONE; - ImGui::CloseCurrentPopup(); - } - ImGui::PopStyleVar(); - - ImGui::EndPopup(); - } + ts_create_import_popup(window_w, window_h); + ts_create_export_popup(window_w, window_h); return menu_bar_h + 15; } |
