diff options
Diffstat (limited to 'core/src/UI/UI_MainWindow.cpp')
-rw-r--r-- | core/src/UI/UI_MainWindow.cpp | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/core/src/UI/UI_MainWindow.cpp b/core/src/UI/UI_MainWindow.cpp index 9b20550..de300e2 100644 --- a/core/src/UI/UI_MainWindow.cpp +++ b/core/src/UI/UI_MainWindow.cpp @@ -5,6 +5,8 @@ #include "UI/Localization.hpp" #include "UI/States.hpp" +#include <portable-file-dialogs.h> + #include <IconsFontAwesome.h> #include <imgui.h> #include <imgui_internal.h> @@ -18,9 +20,9 @@ void LoadProjectAt(const std::filesystem::path& path) { auto& uis = UIState::GetInstance(); auto& gs = GlobalStates::GetInstance(); - if (uis.CurrentProject) { - uis.CloseCurrentProject(); - } + auto project = Project::Load(path); + auto uptr = std::unique_ptr<Project>(new Project(std::move(project))); + uis.SetCurrentProject(std::move(uptr)); } void ProjectTab_Normal() { @@ -36,45 +38,52 @@ void ProjectTab_NoProject() { static std::string dirName; static fs::path dirPath; static bool dirNameIsValid = false; + + auto TrySelectPath = [&](fs::path newPath) { + if (fs::exists(newPath)) { + dirNameIsValid = true; + dirPath = std::move(newPath); + } else { + dirNameIsValid = false; + } + }; + if (ImGui::Button(ls->NewProject.Get())) { auto vs = ImGui::GetMainViewport()->Size; // Viewport Size ImGui::SetNextWindowSize({ vs.x * 0.5f, vs.y * 0.5f }); ImGui::SetNextWindowPos({ vs.x / 2, vs.y / 2 }, ImGuiCond_Always, { 0.5f, 0.5f }); // Center window initially - ImGui::OpenPopup(ls->TitleNewProject.Get()); + ImGui::OpenPopup(ls->NewProjectTitle.Get()); } // Make it so that the modal dialog has a close button bool newProjectDialogDummyTrue = true; - if (ImGui::BeginPopupModal(ls->TitleNewProject.Get(), &newProjectDialogDummyTrue)) { - ImGui::InputTextWithHint("##ProjectName", ls->HintNewProjectName.Get(), &projectName); + if (ImGui::BeginPopupModal(ls->NewProjectTitle.Get(), &newProjectDialogDummyTrue)) { + ImGui::InputTextWithHint("##ProjectName", ls->NewProjectNameHint.Get(), &projectName); - if (ImGui::InputTextWithHint("##ProjectPath", ls->HintNewProjectPath.Get(), &dirName)) { + if (ImGui::InputTextWithHint("##ProjectPath", ls->NewProjectPathHint.Get(), &dirName)) { // Changed, validate value - fs::path newPath(dirName); - if (fs::exists(newPath)) { - dirNameIsValid = true; - dirPath = std::move(newPath); - } else { - dirNameIsValid = false; - } + TrySelectPath(fs::path(dirName)); } ImGui::SameLine(); if (ImGui::Button("...")) { - // TODO file dialog + auto selection = pfd::select_folder(ls->NewProjectPathDialogTitle.Get()).result(); + if (!selection.empty()) { + TrySelectPath(fs::path(selection)); + } } if (projectName.empty()) { ImGui::ErrorIcon(); ImGui::SameLine(); - ImGui::Text(ls->ErrorNewProjectEmptyName.Get()); + ImGui::Text(ls->NewProjectEmptyNameError.Get()); } if (!dirNameIsValid) { ImGui::ErrorIcon(); ImGui::SameLine(); - ImGui::Text(ls->ErrorNewProjectInvalidPath.Get()); + ImGui::Text(ls->NewProjectInvalidPathError.Get()); } ImGui::Spacing(); @@ -85,7 +94,7 @@ void ProjectTab_NoProject() { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, false); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f * ImGui::GetStyle().Alpha); } - if (ImGui::Button(ls->ActionNewProjectConfirm.Get())) { + if (ImGui::Button(ls->ConfirmNewProject.Get())) { ImGui::CloseCurrentPopup(); auto project = Project::Create(std::move(projectName), dirPath); @@ -104,7 +113,7 @@ void ProjectTab_NoProject() { } ImGui::SameLine(); - if (ImGui::Button(ls->ActionNewProjectCancel.Get())) { + if (ImGui::Button(ls->CancelNewProject.Get())) { ImGui::CloseCurrentPopup(); } @@ -112,19 +121,23 @@ void ProjectTab_NoProject() { } if (ImGui::Button(ls->OpenProject.Get())) { - // TODO + auto selection = pfd::open_file(ls->OpenProjectDialogTitle.Get()).result(); + if (!selection.empty()) { + fs::path path(selection[0]); + LoadProjectAt(path); + } } ImGui::Separator(); ImGui::Text(ls->RecentProjects.Get()); ImGui::SameLine(); - if (ImGui::Button(ls->ActionClearRecentProjects.Get())) { + if (ImGui::Button(ls->ClearRecentProjects.Get())) { gs.ClearRecentProjects(); } auto& recentProjects = gs.GetRecentProjects(); if (recentProjects.empty()) { - ImGui::Text(ls->MessageNoRecentProjects.Get()); + ImGui::Text(ls->NoRecentProjectsMessage.Get()); } for (auto it = recentProjects.begin(); it != recentProjects.end(); ++it) { auto& [path, recent] = *it; @@ -135,7 +148,7 @@ void ProjectTab_NoProject() { LoadProjectAt(path); } if (ImGui::IsItemHovered()) { - ImGui::SetTooltip(ls->TooltipOpenRecentProject.Get()); + ImGui::SetTooltip(ls->OpenRecentProjectTooltip.Get()); } ImGui::SameLine(); @@ -143,7 +156,7 @@ void ProjectTab_NoProject() { gs.RemoveRecentProject(std::distance(recentProjects.begin(), it)); } if (ImGui::IsItemHovered()) { - ImGui::SetTooltip(ls->TooltipDeleteRecentProject.Get()); + ImGui::SetTooltip(ls->DeleteRecentProjectTooltip.Get()); } } } @@ -163,7 +176,7 @@ void UI::MainWindow() { ImGui::EndTabItem(); } - if (ImGui::BeginTabItem(ls->TabProject.Get(), nullptr, ImGuiTabItemFlags_SetSelected)) { + if (ImGui::BeginTabItem(ls->TabProject.Get(), nullptr)) { if (uis.CurrentProject) { ProjectTab_Normal(); } else { |