diff options
author | rtk0c <[email protected]> | 2021-03-29 19:14:07 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-03-29 19:14:07 -0700 |
commit | e75e26da92424528e190a2111acfcc49c657e894 (patch) | |
tree | c9b6f0e2f98e8fef28feff3136e950b1f0e0f357 /core/src/UI | |
parent | 70cc233165b5efa3a3888af34f7afce095fe6947 (diff) |
Replace Dialog.hpp with portable-file-dialogs, more work on projects
Diffstat (limited to 'core/src/UI')
-rw-r--r-- | core/src/UI/Localization.hpp | 24 | ||||
-rw-r--r-- | core/src/UI/UI_MainWindow.cpp | 63 |
2 files changed, 51 insertions, 36 deletions
diff --git a/core/src/UI/Localization.hpp b/core/src/UI/Localization.hpp index 7b401ef..e604165 100644 --- a/core/src/UI/Localization.hpp +++ b/core/src/UI/Localization.hpp @@ -19,19 +19,21 @@ public: BasicTranslation TabExport{ "MainWindow.Tab.Exports"sv }; BasicTranslation NewProject{ "Project.New"sv }; - BasicTranslation TitleNewProject{ "Project.New.DialogTitle"sv }; - BasicTranslation ActionNewProjectConfirm{ "Project.New.Confirm"sv }; - BasicTranslation ActionNewProjectCancel{ "Project.New.Cancel"sv }; - BasicTranslation HintNewProjectName{ "Project.New.Name"sv }; - BasicTranslation HintNewProjectPath{ "Project.New.Path"sv }; - BasicTranslation ErrorNewProjectEmptyName{ "Project.New.EmptyName"sv }; - BasicTranslation ErrorNewProjectInvalidPath{ "Project.New.InvalidPath"sv }; + BasicTranslation NewProjectTitle{ "Project.New.DialogTitle"sv }; + BasicTranslation ConfirmNewProject{ "Project.New.Confirm"sv }; + BasicTranslation CancelNewProject{ "Project.New.Cancel"sv }; + BasicTranslation NewProjectNameHint{ "Project.New.Name"sv }; + BasicTranslation NewProjectPathHint{ "Project.New.Path"sv }; + BasicTranslation NewProjectPathDialogTitle{ "Project.New.Path.DialogTitle"sv }; + BasicTranslation NewProjectEmptyNameError{ "Project.New.EmptyName"sv }; + BasicTranslation NewProjectInvalidPathError{ "Project.New.InvalidPath"sv }; BasicTranslation OpenProject{ "Project.Open"sv }; + BasicTranslation OpenProjectDialogTitle{ "Project.Open.DialogTitle"sv }; BasicTranslation RecentProjects{ "Project.Recents"sv }; - BasicTranslation ActionClearRecentProjects{ "Project.Recents.Clear"sv }; - BasicTranslation MessageNoRecentProjects{ "Project.Recents.NonePresent"sv }; - BasicTranslation TooltipOpenRecentProject{ "Project.Recents.Open.Tooltip"sv }; - BasicTranslation TooltipDeleteRecentProject{ "Project.Recents.Delete.Tooltip"sv }; + BasicTranslation ClearRecentProjects{ "Project.Recents.Clear"sv }; + BasicTranslation NoRecentProjectsMessage{ "Project.Recents.NonePresent"sv }; + BasicTranslation OpenRecentProjectTooltip{ "Project.Recents.Open.Tooltip"sv }; + BasicTranslation DeleteRecentProjectTooltip{ "Project.Recents.Delete.Tooltip"sv }; }; 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 { |