From 6159a44ee849981a501a5b24a939d851b46e9e97 Mon Sep 17 00:00:00 2001 From: Gamedemons <72032280+Gamedemons@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:57:55 +0530 Subject: [PATCH] Added placeholder text to all TextBoxes, error check for empty outputLocation --- main/gui.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/main/gui.cpp b/main/gui.cpp index 9d2e673..0121ff7 100644 --- a/main/gui.cpp +++ b/main/gui.cpp @@ -276,7 +276,7 @@ void gui::Render(int iniTheme) noexcept static short int lGap = 35; static short int leftLayoutWidth = 350; - static char outputFileName[250] = "_filename"; + static char outputFileName[250] = ""; static std::vector outputFileExtensions = { ".txt", ".md" }; static std::vector realFileNames; static std::vector oldFileNames; // Old File Names @@ -472,7 +472,7 @@ void gui::Render(int iniTheme) noexcept // File Picker /*static char inputLocation[50000] = "Select Input File/Folder";*/ - static char inputLocation[50000] = "D:\\Z"; + static char inputLocation[50000] = ""; static char inputFiles[5000000] = ""; if (currentFilePickType == 0) { ImGui::SetCursorPos(ImVec2( @@ -480,7 +480,7 @@ void gui::Render(int iniTheme) noexcept lance::toShint( yPos + (lGap * 1.0) ) )); ImGui::PushItemWidth(315); - ImGui::InputText("##inputLocationLabel1", inputLocation, IM_ARRAYSIZE(inputLocation), ImGuiInputTextFlags_ReadOnly); + ImGui::InputTextWithHint("##inputLocationLabel1", "Select Input Directory", inputLocation, IM_ARRAYSIZE(inputLocation), ImGuiInputTextFlags_ReadOnly); ImGui::SameLine(); ImGui::SetCursorPos(ImVec2( lance::toShint( 335.0 ), @@ -513,7 +513,7 @@ void gui::Render(int iniTheme) noexcept lance::toShint( yPos + (lGap * 1.0) ) )); ImGui::PushItemWidth(315); - ImGui::InputText("##inputLocationLabel2", inputFiles, IM_ARRAYSIZE(inputFiles), ImGuiInputTextFlags_ReadOnly); + ImGui::InputTextWithHint("##inputLocationLabel2", "Select Input Files", inputFiles, IM_ARRAYSIZE(inputFiles), ImGuiInputTextFlags_ReadOnly); ImGui::SameLine(); ImGui::SetCursorPos(ImVec2( lance::toShint( 335.0 ), @@ -536,10 +536,10 @@ void gui::Render(int iniTheme) noexcept // Output Picker /*static char outputLocation[50000] = "Select Output Folder";*/ - static char outputLocation[50000] = "D:\\Z"; + static char outputLocation[50000] = ""; ImGui::SetCursorPos(ImVec2(xPos, yPos + (lGap * 2.0))); ImGui::PushItemWidth(315); - ImGui::InputText("##outputLocationLabel", outputLocation, IM_ARRAYSIZE(outputLocation), ImGuiInputTextFlags_ReadOnly); + ImGui::InputTextWithHint("##outputLocationLabel", "Select Output Directory", outputLocation, IM_ARRAYSIZE(outputLocation), ImGuiInputTextFlags_ReadOnly); ImGui::SameLine(); ImGui::SetCursorPos(ImVec2(335, yPos + (lGap * 2.0))); if (ImGui::Button("...##outputLocationButton", ImVec2(25, 25))) { @@ -738,6 +738,10 @@ void gui::Render(int iniTheme) noexcept filePath = lance::getFileNames(inputFiles + std::string("")); } + if (strlen(outputLocation) == 0) { + throw "Error : Invalid Output Path"; + } + std::string customFilePath = outputLocation + std::string("\\") + outputFileName; if (strlen(outputFileName) == 0) { std::filesystem::path c1(filePath.front()); @@ -819,7 +823,7 @@ void gui::Render(int iniTheme) noexcept ImGui::SetCursorPosX(menuPosX); ImGui::PushItemWidth(315); - ImGui::InputText("##outputFileName", outputFileName, IM_ARRAYSIZE(outputFileName)); + ImGui::InputTextWithHint("##outputFileName", "Enter Custom Filename", outputFileName, IM_ARRAYSIZE(outputFileName)); ImGui::SetCursorPos(ImVec2(menuPosX, menuPosY + tabGap)); ImGui::PushID("enable_markdown_format"); @@ -1275,6 +1279,22 @@ std::string lance::removeEmptySpaces(std::string str) { return str; } +static inline void ltrim(std::string& s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); +} +static inline void rtrim(std::string& s) { + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), s.end() + ); +} +static inline void trim(std::string& s) { + rtrim(s); + ltrim(s); +} + // Type Conversions short int lance::toShint(short int x)