[nostalgia] Add PaletteEditor

This commit is contained in:
2022-04-02 16:38:38 -05:00
parent 99987ee423
commit 71e0f181ea
14 changed files with 251 additions and 334 deletions

View File

@@ -8,7 +8,7 @@
namespace nostalgia::studio {
ox::String Editor::itemDisplayName() const {
const ox::String &Editor::itemDisplayName() const {
return itemName();
}

View File

@@ -30,10 +30,10 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
* Returns the name of item being edited.
*/
[[nodiscard]]
virtual ox::String itemName() const = 0;
virtual const ox::String &itemName() const = 0;
[[nodiscard]]
virtual ox::String itemDisplayName() const;
virtual const ox::String &itemDisplayName() const;
virtual void cut();

View File

@@ -14,7 +14,7 @@
namespace nostalgia::studio {
struct EditorMaker {
using Func = std::function<class Editor*(ox::String)>;
using Func = std::function<ox::Result<class Editor*>(const ox::String&)>;
ox::Vector<ox::String> fileTypes;
Func make;
};
@@ -27,4 +27,4 @@ class Module {
};
}
}

View File

@@ -110,8 +110,8 @@ ox::Error Project::writeObj(const ox::String &path, auto *obj) const noexcept {
// replace garbage last character with new line
typeOut.back().value = '\n';
// write to FS
static constexpr auto descPath = "/.nostalgia/type_descriptors/";
const auto typePath = ox::sfmt("{}{}", descPath, type->typeName);
static constexpr auto descPath = "/.nostalgia/type_descriptors";
const auto typePath = ox::sfmt("{}/{}", descPath, type->typeName);
oxReturnError(mkdir(descPath));
oxReturnError(writeBuff(typePath, typeOut));
fileUpdated.emit(path);
@@ -136,7 +136,7 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
case ProjectEvent::FileRecognized:
{
oxRequire(files, listFiles());
for (auto f : files) {
for (const auto &f : files) {
slot(f);
}
connect(this, &Project::fileRecognized, tgt, slot);

View File

@@ -182,7 +182,7 @@ void StudioUI::drawTabBar() noexcept {
void StudioUI::drawTabs() noexcept {
for (auto it = m_editors.begin(); it != m_editors.end();) {
auto const &e = *it;
bool open = true;
auto open = true;
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open)) {
m_acitveEditor = e.get();
e->draw(m_ctx);
@@ -289,14 +289,13 @@ ox::Error StudioUI::openFile(const ox::String &path) noexcept {
if (!m_editorMakers.contains(ext)) {
return OxError(1, "There is no editor for this file extension");
}
try {
auto editor = m_editorMakers[ext](path);
editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor);
} catch (const ox::Exception &ex) {
oxErrorf("Could not open Editor: {} ({}:{})", ex.msg, ex.file, ex.line);
return ex.toError();
auto [editor, err] = m_editorMakers[ext](path);
if (err) {
oxErrorf("Could not open Editor: {} ({}:{})", err.msg, err.file, err.line);
return err;
}
editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor);
m_openFiles.emplace_back(path);
// save to config
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {