[studio] Add FilePickerPopup
This commit is contained in:
38
src/olympic/studio/modlib/include/studio/filepickerpopup.hpp
Normal file
38
src/olympic/studio/modlib/include/studio/filepickerpopup.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "popup.hpp"
|
||||
#include "filetreemodel.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
class FilePickerPopup {
|
||||
|
||||
private:
|
||||
ox::String m_name;
|
||||
FileExplorer m_explorer;
|
||||
ox::Vector<ox::String> const m_fileExts;
|
||||
bool m_open{};
|
||||
|
||||
public:
|
||||
explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::StringParam fileExt) noexcept;
|
||||
|
||||
explicit FilePickerPopup(ox::StringParam name, keel::Context &kctx, ox::Vector<ox::String> fileExts) noexcept;
|
||||
|
||||
void refresh() noexcept;
|
||||
|
||||
void open() noexcept;
|
||||
|
||||
void close() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
ox::Optional<ox::String> draw(StudioContext &ctx) noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
constexpr void safeDelete(class FileTreeModel *m) noexcept;
|
||||
constexpr void safeDelete(class FileTreeModel const *m) noexcept;
|
||||
|
||||
class FileExplorer: public ox::SignalHandler {
|
||||
|
||||
@@ -32,8 +32,6 @@ class FileExplorer: public ox::SignalHandler {
|
||||
m_kctx{kctx},
|
||||
m_fileDraggable{fileDraggable} {}
|
||||
|
||||
virtual ~FileExplorer() = default;
|
||||
|
||||
void draw(StudioContext &ctx, ImVec2 const &sz) const noexcept;
|
||||
|
||||
void setModel(ox::UPtr<FileTreeModel> &&model, bool selectRoot = false) noexcept;
|
||||
@@ -45,6 +43,8 @@ class FileExplorer: public ox::SignalHandler {
|
||||
|
||||
virtual void fileOpened(ox::StringViewCR path) const noexcept;
|
||||
|
||||
virtual void fileDeleted(ox::StringViewCR path) const noexcept;
|
||||
|
||||
void drawFileContextMenu(ox::CStringViewCR path) const noexcept;
|
||||
|
||||
void drawDirContextMenu(ox::CStringViewCR path) const noexcept;
|
||||
@@ -116,7 +116,7 @@ class FileTreeModel {
|
||||
|
||||
};
|
||||
|
||||
constexpr void safeDelete(FileTreeModel *m) noexcept {
|
||||
constexpr void safeDelete(FileTreeModel const *m) noexcept {
|
||||
delete m;
|
||||
}
|
||||
|
||||
|
@@ -155,6 +155,23 @@ TextInput<ox::IString<MaxChars>> InputText(
|
||||
return out;
|
||||
}
|
||||
|
||||
template<size_t MaxChars = 50>
|
||||
TextInput<ox::IString<MaxChars>> InputTextWithHint(
|
||||
ox::CStringViewCR label,
|
||||
ox::CStringViewCR hint,
|
||||
ox::StringViewCR currentText,
|
||||
ImGuiInputTextFlags const flags = 0,
|
||||
ImGuiInputTextCallback const callback = nullptr,
|
||||
void *user_data = nullptr) noexcept {
|
||||
TextInput<ox::IString<MaxChars>> out = {.text = currentText};
|
||||
out.changed = ImGui::InputTextWithHint(
|
||||
label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template<size_t StrCap>
|
||||
bool InputText(
|
||||
ox::CStringViewCR label,
|
||||
|
Reference in New Issue
Block a user