[nostalgia/studio] Get Undo/Redo working
This commit is contained in:
parent
72ce8ea4d9
commit
c92ecdf499
@ -42,10 +42,6 @@ bool Editor::unsavedChanges() const noexcept {
|
|||||||
return m_unsavedChanges;
|
return m_unsavedChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
UndoStack *Editor::undoStack() {
|
|
||||||
return &m_cmdStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Editor::setExportable(bool exportable) {
|
void Editor::setExportable(bool exportable) {
|
||||||
m_exportable = exportable;
|
m_exportable = exportable;
|
||||||
exportableChanged.emit(exportable);
|
exportableChanged.emit(exportable);
|
||||||
|
@ -32,6 +32,7 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual ox::String itemName() const = 0;
|
virtual ox::String itemName() const = 0;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
virtual ox::String itemDisplayName() const;
|
virtual ox::String itemDisplayName() const;
|
||||||
|
|
||||||
virtual void cut();
|
virtual void cut();
|
||||||
@ -42,6 +43,14 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
|
|||||||
|
|
||||||
virtual void exportFile();
|
virtual void exportFile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the undo stack holding changes to the item being edited.
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual UndoStack *undoStack() noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,12 +67,6 @@ class NOSTALGIASTUDIO_EXPORT Editor: public Widget {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool unsavedChanges() const noexcept;
|
bool unsavedChanges() const noexcept;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the undo stack holding changes to the item being edited.
|
|
||||||
*/
|
|
||||||
[[nodiscard]]
|
|
||||||
UndoStack *undoStack();
|
|
||||||
|
|
||||||
void setExportable(bool);
|
void setExportable(bool);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
@ -22,8 +22,8 @@ void UndoStack::redo() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UndoStack::undo() noexcept {
|
void UndoStack::undo() noexcept {
|
||||||
if (m_stackIdx < ox::MaxValue<decltype(m_stackIdx)>) {
|
if (m_stackIdx) {
|
||||||
m_stack[m_stackIdx--]->undo();
|
m_stack[--m_stackIdx]->undo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,23 @@ void StudioUI::drawMenu() noexcept {
|
|||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
if (ImGui::BeginMenu("Edit")) {
|
||||||
|
auto undoStack = m_acitveEditor ? m_acitveEditor->undoStack() : nullptr;
|
||||||
|
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack)) {
|
||||||
|
m_acitveEditor->undoStack()->undo();
|
||||||
|
}
|
||||||
|
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack)) {
|
||||||
|
m_acitveEditor->undoStack()->redo();
|
||||||
|
}
|
||||||
|
ImGui::Separator();
|
||||||
|
if (ImGui::MenuItem("Copy", "Ctrl+N")) {
|
||||||
|
}
|
||||||
|
if (ImGui::MenuItem("Cut", "Ctrl+X")) {
|
||||||
|
}
|
||||||
|
if (ImGui::MenuItem("Paste", "Ctrl+V")) {
|
||||||
|
}
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
if (ImGui::BeginMenu("View", false)) {
|
if (ImGui::BeginMenu("View", false)) {
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
@ -147,6 +164,7 @@ void StudioUI::drawTabs() noexcept {
|
|||||||
auto const &e = *it;
|
auto const &e = *it;
|
||||||
bool open = true;
|
bool open = true;
|
||||||
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open)) {
|
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open)) {
|
||||||
|
m_acitveEditor = e.get();
|
||||||
e->draw(m_ctx);
|
e->draw(m_ctx);
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class StudioUI: public ox::SignalHandler {
|
|||||||
ox::HashMap<ox::String, studio::EditorMaker::Func> m_editorMakers;
|
ox::HashMap<ox::String, studio::EditorMaker::Func> m_editorMakers;
|
||||||
ProjectExplorer *m_projectExplorer = nullptr;
|
ProjectExplorer *m_projectExplorer = nullptr;
|
||||||
ox::Vector<ox::String> m_openFiles;
|
ox::Vector<ox::String> m_openFiles;
|
||||||
|
studio::Editor *m_acitveEditor = nullptr;
|
||||||
bool m_saveEnabled = false;
|
bool m_saveEnabled = false;
|
||||||
bool m_aboutEnabled = false;
|
bool m_aboutEnabled = false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user