[nostalgia] Split studio::Editor into Editor and BaseEditor
This commit is contained in:
parent
56964e197a
commit
edf4571ff7
@ -13,7 +13,7 @@ ox::Vector<studio::EditorMaker> Module::editors(core::Context *ctx) noexcept {
|
||||
return {
|
||||
{
|
||||
{"ng"},
|
||||
[ctx](const ox::String &path) -> ox::Result<studio::Editor*> {
|
||||
[ctx](const ox::String &path) -> ox::Result<studio::BaseEditor*> {
|
||||
try {
|
||||
return new TileSheetEditorImGui(ctx, path);
|
||||
} catch (const ox::Exception &ex) {
|
||||
@ -23,7 +23,7 @@ ox::Vector<studio::EditorMaker> Module::editors(core::Context *ctx) noexcept {
|
||||
},
|
||||
{
|
||||
{"npal"},
|
||||
[ctx](const ox::String &path) -> ox::Result<studio::Editor*> {
|
||||
[ctx](const ox::String &path) -> ox::Result<studio::BaseEditor*> {
|
||||
return PaletteEditorImGui::make(ctx, path);
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,10 @@ ox::Result<PaletteEditorImGui*> PaletteEditorImGui::make(Context *ctx, const ox:
|
||||
out->m_itemName = out->m_itemPath.substr(lastSlash + 1);
|
||||
oxRequire(pal, core::readObj<Palette>(out->m_ctx, out->m_itemPath));
|
||||
out->m_pal = *pal.get();
|
||||
out->undoStack()->changeTriggered.connect(out.get(), &PaletteEditorImGui::markUnsavedChanges);
|
||||
return out.release();
|
||||
}
|
||||
|
||||
const ox::String &PaletteEditorImGui::itemName() const {
|
||||
const ox::String &PaletteEditorImGui::itemName() const noexcept {
|
||||
return m_itemPath;
|
||||
}
|
||||
|
||||
@ -33,10 +32,6 @@ const ox::String &PaletteEditorImGui::itemDisplayName() const noexcept {
|
||||
return m_itemName;
|
||||
}
|
||||
|
||||
studio::UndoStack *PaletteEditorImGui::undoStack() noexcept {
|
||||
return &m_undoStack;
|
||||
}
|
||||
|
||||
void PaletteEditorImGui::draw(core::Context*) noexcept {
|
||||
static constexpr auto flags = ImGuiTableFlags_RowBg;
|
||||
const auto paneSize = ImGui::GetContentRegionAvail();
|
||||
@ -50,20 +45,20 @@ void PaletteEditorImGui::draw(core::Context*) noexcept {
|
||||
{
|
||||
const auto sz = ImVec2(70, 24);
|
||||
if (ImGui::Button("Add", sz)) {
|
||||
m_undoStack.push(new AddColorCommand(&m_pal, 0, m_pal.colors.size()));
|
||||
undoStack()->push(new AddColorCommand(&m_pal, 0, m_pal.colors.size()));
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size());
|
||||
{
|
||||
if (ImGui::Button("Remove", sz)) {
|
||||
m_undoStack.push(new RemoveColorCommand(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], m_selectedRow));
|
||||
undoStack()->push(new RemoveColorCommand(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], m_selectedRow));
|
||||
m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(m_selectedRow <= 0);
|
||||
{
|
||||
if (ImGui::Button("Move Up", sz)) {
|
||||
m_undoStack.push(new MoveColorCommand(&m_pal, m_selectedRow, -1));
|
||||
undoStack()->push(new MoveColorCommand(&m_pal, m_selectedRow, -1));
|
||||
--m_selectedRow;
|
||||
}
|
||||
}
|
||||
@ -72,7 +67,7 @@ void PaletteEditorImGui::draw(core::Context*) noexcept {
|
||||
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size() - 1);
|
||||
{
|
||||
if (ImGui::Button("Move Down", sz)) {
|
||||
m_undoStack.push(new MoveColorCommand(&m_pal, m_selectedRow, 1));
|
||||
undoStack()->push(new MoveColorCommand(&m_pal, m_selectedRow, 1));
|
||||
++m_selectedRow;
|
||||
}
|
||||
}
|
||||
@ -132,7 +127,7 @@ void PaletteEditorImGui::draw(core::Context*) noexcept {
|
||||
ImGui::InputInt("Blue", &b, 1, 5);
|
||||
const auto newColor = color16(r, g, b, a);
|
||||
if (c != newColor) {
|
||||
m_undoStack.push(new UpdateColorCommand(&m_pal, m_selectedRow, c, newColor));
|
||||
undoStack()->push(new UpdateColorCommand(&m_pal, m_selectedRow, c, newColor));
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
@ -148,9 +143,4 @@ ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
ox::Error PaletteEditorImGui::markUnsavedChanges(int) noexcept {
|
||||
setUnsavedChanges(true);
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
ox::String m_itemPath;
|
||||
Palette m_pal;
|
||||
std::size_t m_selectedRow = 0;
|
||||
studio::UndoStack m_undoStack;
|
||||
|
||||
PaletteEditorImGui() noexcept = default;
|
||||
|
||||
@ -27,19 +26,14 @@ class PaletteEditorImGui: public studio::Editor {
|
||||
/**
|
||||
* Returns the name of item being edited.
|
||||
*/
|
||||
const ox::String &itemName() const override;
|
||||
const ox::String &itemName() const noexcept final;
|
||||
|
||||
const ox::String &itemDisplayName() const noexcept override;
|
||||
const ox::String &itemDisplayName() const noexcept final;
|
||||
|
||||
void draw(core::Context*) noexcept override;
|
||||
void draw(core::Context*) noexcept final;
|
||||
|
||||
protected:
|
||||
studio::UndoStack *undoStack() noexcept final;
|
||||
|
||||
ox::Error saveItem() noexcept override;
|
||||
|
||||
private:
|
||||
ox::Error markUnsavedChanges(int) noexcept;
|
||||
ox::Error saveItem() noexcept final;
|
||||
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,7 @@ enum class Tool {
|
||||
Select,
|
||||
};
|
||||
|
||||
class TileSheetEditorImGui: public studio::Editor {
|
||||
class TileSheetEditorImGui: public studio::BaseEditor {
|
||||
|
||||
private:
|
||||
class SubSheetEditor {
|
||||
|
@ -8,27 +8,27 @@
|
||||
|
||||
namespace nostalgia::studio {
|
||||
|
||||
const ox::String &Editor::itemDisplayName() const {
|
||||
const ox::String &BaseEditor::itemDisplayName() const noexcept {
|
||||
return itemName();
|
||||
}
|
||||
|
||||
void Editor::cut() {
|
||||
void BaseEditor::cut() {
|
||||
}
|
||||
|
||||
void Editor::copy() {
|
||||
void BaseEditor::copy() {
|
||||
}
|
||||
|
||||
void Editor::paste() {
|
||||
void BaseEditor::paste() {
|
||||
}
|
||||
|
||||
void Editor::exportFile() {
|
||||
void BaseEditor::exportFile() {
|
||||
}
|
||||
|
||||
void Editor::close() {
|
||||
void BaseEditor::close() {
|
||||
this->closed.emit(itemName());
|
||||
}
|
||||
|
||||
void Editor::save() noexcept {
|
||||
void BaseEditor::save() noexcept {
|
||||
const auto err = saveItem();
|
||||
if (!err) {
|
||||
setUnsavedChanges(false);
|
||||
@ -37,52 +37,61 @@ void Editor::save() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::setUnsavedChanges(bool uc) {
|
||||
void BaseEditor::setUnsavedChanges(bool uc) {
|
||||
m_unsavedChanges = uc;
|
||||
unsavedChangesChanged.emit(uc);
|
||||
}
|
||||
|
||||
bool Editor::unsavedChanges() const noexcept {
|
||||
bool BaseEditor::unsavedChanges() const noexcept {
|
||||
return m_unsavedChanges;
|
||||
}
|
||||
|
||||
void Editor::setExportable(bool exportable) {
|
||||
void BaseEditor::setExportable(bool exportable) {
|
||||
m_exportable = exportable;
|
||||
exportableChanged.emit(exportable);
|
||||
}
|
||||
|
||||
bool Editor::exportable() const {
|
||||
bool BaseEditor::exportable() const {
|
||||
return m_exportable;
|
||||
}
|
||||
|
||||
void Editor::setCutEnabled(bool v) {
|
||||
void BaseEditor::setCutEnabled(bool v) {
|
||||
m_cutEnabled = v;
|
||||
cutEnabledChanged.emit(v);
|
||||
}
|
||||
|
||||
bool Editor::cutEnabled() const {
|
||||
bool BaseEditor::cutEnabled() const {
|
||||
return m_cutEnabled;
|
||||
}
|
||||
|
||||
void Editor::setCopyEnabled(bool v) {
|
||||
void BaseEditor::setCopyEnabled(bool v) {
|
||||
m_copyEnabled = v;
|
||||
copyEnabledChanged.emit(v);
|
||||
}
|
||||
|
||||
bool Editor::copyEnabled() const {
|
||||
bool BaseEditor::copyEnabled() const {
|
||||
return m_copyEnabled;
|
||||
}
|
||||
|
||||
void Editor::setPasteEnabled(bool v) {
|
||||
void BaseEditor::setPasteEnabled(bool v) {
|
||||
m_pasteEnabled = v;
|
||||
pasteEnabledChanged.emit(v);
|
||||
}
|
||||
|
||||
bool Editor::pasteEnabled() const {
|
||||
bool BaseEditor::pasteEnabled() const {
|
||||
return m_pasteEnabled;
|
||||
}
|
||||
|
||||
ox::Error Editor::saveItem() noexcept {
|
||||
ox::Error BaseEditor::saveItem() noexcept {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Editor::Editor() noexcept {
|
||||
m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges);
|
||||
}
|
||||
|
||||
ox::Error Editor::markUnsavedChanges(int) noexcept {
|
||||
setUnsavedChanges(true);
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class StudioUI;
|
||||
|
||||
namespace nostalgia::studio {
|
||||
|
||||
class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
|
||||
class NOSTALGIASTUDIO_EXPORT BaseEditor: public Widget {
|
||||
|
||||
friend StudioUI;
|
||||
|
||||
@ -29,16 +29,16 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
|
||||
bool m_pasteEnabled = false;
|
||||
|
||||
public:
|
||||
~Editor() override = default;
|
||||
~BaseEditor() override = default;
|
||||
|
||||
/**
|
||||
* Returns the name of item being edited.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
virtual const ox::String &itemName() const = 0;
|
||||
virtual const ox::String &itemName() const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const ox::String &itemDisplayName() const;
|
||||
virtual const ox::String &itemDisplayName() const noexcept;
|
||||
|
||||
virtual void cut();
|
||||
|
||||
@ -109,4 +109,20 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
|
||||
|
||||
};
|
||||
|
||||
class Editor: public studio::BaseEditor {
|
||||
private:
|
||||
studio::UndoStack m_undoStack;
|
||||
|
||||
public:
|
||||
Editor() noexcept;
|
||||
|
||||
UndoStack *undoStack() noexcept final {
|
||||
return &m_undoStack;
|
||||
}
|
||||
|
||||
private:
|
||||
ox::Error markUnsavedChanges(int) noexcept;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace nostalgia::studio {
|
||||
|
||||
struct EditorMaker {
|
||||
using Func = std::function<ox::Result<class Editor*>(const ox::String&)>;
|
||||
using Func = std::function<ox::Result<class BaseEditor*>(const ox::String&)>;
|
||||
ox::Vector<ox::String> fileTypes;
|
||||
Func make;
|
||||
};
|
||||
|
@ -24,13 +24,13 @@ class StudioUI: public ox::SignalHandler {
|
||||
ox::UniquePtr<studio::Project> m_project;
|
||||
studio::TaskRunner m_taskRunner;
|
||||
core::Context *m_ctx = nullptr;
|
||||
ox::Vector<ox::UniquePtr<studio::Editor>> m_editors;
|
||||
ox::Vector<ox::UniquePtr<studio::BaseEditor>> m_editors;
|
||||
ox::Vector<ox::UniquePtr<studio::Widget>> m_widgets;
|
||||
ox::HashMap<ox::String, studio::EditorMaker::Func> m_editorMakers;
|
||||
ProjectExplorer *m_projectExplorer = nullptr;
|
||||
ox::Vector<ox::String> m_openFiles;
|
||||
studio::Editor *m_activeEditor = nullptr;
|
||||
studio::Editor *m_activeEditorUpdatePending = nullptr;
|
||||
studio::BaseEditor *m_activeEditor = nullptr;
|
||||
studio::BaseEditor *m_activeEditorUpdatePending = nullptr;
|
||||
bool m_saveEnabled = false;
|
||||
bool m_aboutEnabled = false;
|
||||
bool m_showProjectExplorer = true;
|
||||
|
Loading…
Reference in New Issue
Block a user