Files
ox/src/nostalgia/studio/filedialogmanager.cpp
T

44 lines
1.2 KiB
C++

/*
* Copyright 2016 - 2021 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <imgui.h>
#include <nostalgia/core/gfx.hpp>
#include "filedialogmanager.hpp"
namespace nostalgia {
studio::TaskState FileDialogManager::update(core::Context *ctx) noexcept {
switch (m_state) {
case UpdateProjectPathState::EnableSystemCursor: {
// switch to system cursor in this update and open file dialog in the next
// the cursor state has to be set before the ImGui frame starts
auto &io = ImGui::GetIO();
io.MouseDrawCursor = false;
m_state = UpdateProjectPathState::RunFileDialog;
break;
}
case UpdateProjectPathState::RunFileDialog: {
// switch to system cursor
auto [path, err] = studio::chooseDirectory();
// Mac file dialog doesn't restore focus to main window when closed...
core::focusWindow(ctx);
if (!err) {
err = pathChosen.emitCheckError(path);
oxAssert(err, "Path chosen response failed");
}
auto &io = ImGui::GetIO();
io.MouseDrawCursor = true;
m_state = UpdateProjectPathState::None;
return nostalgia::studio::TaskState::Done;
}
case UpdateProjectPathState::None:
break;
}
return nostalgia::studio::TaskState::Running;
}
}