Compare commits

...

2 Commits

Author SHA1 Message Date
25a7873ea2 [nostalgia,studio] Fix crash that occurred when navigating to file that is not already open
All checks were successful
Build / build (push) Successful in 1m32s
2025-02-20 23:57:02 -06:00
d0a32e247e [ox/std] Add Vector::remove
All checks were successful
Build / build (push) Successful in 1m42s
2025-02-20 23:34:36 -06:00
5 changed files with 33 additions and 10 deletions

View File

@ -311,6 +311,8 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
*/
constexpr Error unordered_erase(std::size_t pos) noexcept(useNoexcept);
constexpr Error remove(T const &val);
constexpr void reserve(std::size_t cap) noexcept(useNoexcept);
constexpr void shrink_to_fit() noexcept(useNoexcept);
@ -659,6 +661,17 @@ constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(std::size
return ox::Error(0);
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr ox::Error Vector<T, SmallVectorSize, Allocator>::remove(T const &val) {
for (size_t i{}; auto const &v : *this) {
if (v == val) {
return erase(i).error;
}
++i;
}
return ox::Error{1, "element not found"};
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr void Vector<T, SmallVectorSize, Allocator>::reserve(std::size_t cap) noexcept(useNoexcept) {
if (cap <= m_cap) {

View File

@ -566,8 +566,10 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
m_view.setPalIdx(i);
}
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) {
auto const rqst = ox::sfmt<ox::BasicString<100>>("{};{}", i, m_model.palettePage());
oxLogError(studio::navigateTo(m_sctx, m_model.palPath(), rqst));
studio::navigateTo(
m_sctx,
m_model.palPath(),
ox::sfmt("{};{}", i, m_model.palettePage()));
}
// Column: color RGB
ImGui::TableNextColumn();

View File

@ -18,8 +18,8 @@
namespace studio {
ox::Error navigateTo(StudioContext &ctx, ox::StringViewCR filePath, ox::StringViewCR args) noexcept {
return ctx.ui.navigateTo(filePath, args);
void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
ctx.ui.navigateTo(std::move(filePath), std::move(navArgs));
}
namespace ig {
@ -111,10 +111,8 @@ void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept
}
}
ox::Error StudioUI::navigateTo(ox::StringViewCR path, ox::StringViewCR navArgs) noexcept {
OX_RETURN_ERROR(openFile(path));
m_activeEditor->navigateTo(navArgs);
return {};
void StudioUI::navigateTo(ox::StringParam path, ox::StringParam navArgs) noexcept {
m_navAction.emplace(std::move(path), std::move(navArgs));
}
void StudioUI::draw() noexcept {
@ -287,6 +285,11 @@ void StudioUI::drawTabs() noexcept {
}
m_closeActiveTab = false;
}
if (m_navAction) {
oxLogError(openFile(m_navAction->path));
m_activeEditor->navigateTo(m_navAction->args);
m_navAction.reset();
}
}
void StudioUI::loadEditorMaker(EditorMaker const&editorMaker) noexcept {

View File

@ -62,13 +62,18 @@ class StudioUI: public ox::SignalHandler {
&m_renameFile,
};
bool m_showProjectExplorer = true;
struct NavAction {
ox::String path;
ox::String args;
};
ox::Optional<NavAction> m_navAction;
public:
explicit StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept;
void handleKeyEvent(turbine::Key, bool down) noexcept;
ox::Error navigateTo(ox::StringViewCR path, ox::StringViewCR navArgs = {}) noexcept;
void navigateTo(ox::StringParam path, ox::StringParam navArgs) noexcept;
[[nodiscard]]
constexpr Project *project() noexcept {

View File

@ -27,6 +27,6 @@ inline keel::Context &keelCtx(StudioContext &ctx) noexcept {
return keelCtx(ctx.tctx);
}
ox::Error navigateTo(StudioContext &ctx, ox::StringViewCR filePath, ox::StringViewCR args) noexcept;
void navigateTo(StudioContext &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept;
}