aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI/UI_MainWindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/UI/UI_MainWindow.cpp')
-rw-r--r--core/src/UI/UI_MainWindow.cpp67
1 files changed, 35 insertions, 32 deletions
diff --git a/core/src/UI/UI_MainWindow.cpp b/core/src/UI/UI_MainWindow.cpp
index de300e2..15c28ff 100644
--- a/core/src/UI/UI_MainWindow.cpp
+++ b/core/src/UI/UI_MainWindow.cpp
@@ -5,28 +5,38 @@
#include "UI/Localization.hpp"
#include "UI/States.hpp"
-#include <portable-file-dialogs.h>
-
#include <IconsFontAwesome.h>
#include <imgui.h>
-#include <imgui_internal.h>
#include <imgui_stdlib.h>
+#include <portable-file-dialogs.h>
#include <filesystem>
+#include <memory>
namespace fs = std::filesystem;
namespace {
void LoadProjectAt(const std::filesystem::path& path) {
auto& uis = UIState::GetInstance();
- auto& gs = GlobalStates::GetInstance();
-
auto project = Project::Load(path);
- auto uptr = std::unique_ptr<Project>(new Project(std::move(project)));
- uis.SetCurrentProject(std::move(uptr));
+ uis.SetCurrentProject(std::make_unique<Project>(std::move(project)));
}
void ProjectTab_Normal() {
- // TODO
+ auto ls = LocaleStrings::Instance.get();
+ auto& gs = GlobalStates::GetInstance();
+ auto& uis = UIState::GetInstance();
+
+ if (ImGui::Button(ls->CloseActiveProject.Get())) {
+ uis.CloseCurrentProject();
+ return;
+ }
+ ImGui::SameLine();
+ if (ImGui::Button(ls->OpenActiveProjectInFileSystem.Get())) {
+ // TODO
+ }
+
+ ImGui::Text("%s%s", ls->ActiveProjectName.Get(), uis.CurrentProject->GetName().c_str());
+ ImGui::Text("%s%s", ls->ActiveProjectPath.Get(), uis.CurrentProject->GetPathString().c_str());
}
void ProjectTab_NoProject() {
@@ -42,6 +52,7 @@ void ProjectTab_NoProject() {
auto TrySelectPath = [&](fs::path newPath) {
if (fs::exists(newPath)) {
dirNameIsValid = true;
+ dirName = newPath.string();
dirPath = std::move(newPath);
} else {
dirNameIsValid = false;
@@ -49,15 +60,14 @@ void ProjectTab_NoProject() {
};
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->NewProjectTitle.Get());
+ ImGui::SetNextWindowCentered();
+ ImGui::SetNextWindowSizeRelScreen(0.5f, 0.5f);
+ ImGui::OpenPopup(ls->NewProjectDialogTitle.Get());
}
// Make it so that the modal dialog has a close button
bool newProjectDialogDummyTrue = true;
- if (ImGui::BeginPopupModal(ls->NewProjectTitle.Get(), &newProjectDialogDummyTrue)) {
+ if (ImGui::BeginPopupModal(ls->NewProjectDialogTitle.Get(), &newProjectDialogDummyTrue)) {
ImGui::InputTextWithHint("##ProjectName", ls->NewProjectNameHint.Get(), &projectName);
if (ImGui::InputTextWithHint("##ProjectPath", ls->NewProjectPathHint.Get(), &dirName)) {
@@ -76,30 +86,26 @@ void ProjectTab_NoProject() {
ImGui::ErrorIcon();
ImGui::SameLine();
- ImGui::Text(ls->NewProjectEmptyNameError.Get());
+ ImGui::Text("%s", ls->NewProjectEmptyNameError.Get());
}
if (!dirNameIsValid) {
ImGui::ErrorIcon();
ImGui::SameLine();
- ImGui::Text(ls->NewProjectInvalidPathError.Get());
+ ImGui::Text("%s", ls->NewProjectInvalidPathError.Get());
}
ImGui::Spacing();
bool formValid = dirNameIsValid && !projectName.empty();
- if (!formValid) {
- ImGui::PushItemFlag(ImGuiItemFlags_Disabled, false);
- ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f * ImGui::GetStyle().Alpha);
- }
- if (ImGui::Button(ls->ConfirmNewProject.Get())) {
+ if (!formValid) ImGui::PushDisabled();
+ if (ImGui::Button(ls->DialogConfirm.Get())) {
ImGui::CloseCurrentPopup();
auto project = Project::Create(std::move(projectName), dirPath);
- auto uptr = std::unique_ptr<Project>(new Project(std::move(project)));
- uis.SetCurrentProject(std::move(uptr));
+ uis.SetCurrentProject(std::make_unique<Project>(std::move(project)));
// Dialog just got closed, reset states
projectName = "";
@@ -107,13 +113,10 @@ void ProjectTab_NoProject() {
dirPath = fs::path{};
dirNameIsValid = false;
}
- if (!formValid) {
- ImGui::PopItemFlag();
- ImGui::PopStyleVar();
- }
+ if (!formValid) ImGui::PopDisabled();
ImGui::SameLine();
- if (ImGui::Button(ls->CancelNewProject.Get())) {
+ if (ImGui::Button(ls->DialogCancel.Get())) {
ImGui::CloseCurrentPopup();
}
@@ -129,7 +132,7 @@ void ProjectTab_NoProject() {
}
ImGui::Separator();
- ImGui::Text(ls->RecentProjects.Get());
+ ImGui::Text("%s", ls->RecentProjects.Get());
ImGui::SameLine();
if (ImGui::Button(ls->ClearRecentProjects.Get())) {
gs.ClearRecentProjects();
@@ -137,18 +140,18 @@ void ProjectTab_NoProject() {
auto& recentProjects = gs.GetRecentProjects();
if (recentProjects.empty()) {
- ImGui::Text(ls->NoRecentProjectsMessage.Get());
+ ImGui::Text("%s", ls->NoRecentProjectsMessage.Get());
}
for (auto it = recentProjects.begin(); it != recentProjects.end(); ++it) {
auto& [path, recent] = *it;
- ImGui::Text(recent.c_str());
+ ImGui::Text("%s", recent.c_str());
ImGui::SameLine();
if (ImGui::Button(ICON_FA_EDIT)) {
LoadProjectAt(path);
}
if (ImGui::IsItemHovered()) {
- ImGui::SetTooltip(ls->OpenRecentProjectTooltip.Get());
+ ImGui::SetTooltip("%s", ls->OpenRecentProjectTooltip.Get());
}
ImGui::SameLine();
@@ -156,7 +159,7 @@ void ProjectTab_NoProject() {
gs.RemoveRecentProject(std::distance(recentProjects.begin(), it));
}
if (ImGui::IsItemHovered()) {
- ImGui::SetTooltip(ls->DeleteRecentProjectTooltip.Get());
+ ImGui::SetTooltip("%s", ls->DeleteRecentProjectTooltip.Get());
}
}
}