[studio,nostalgia/studio] Make executing UndoCommands report errors
All checks were successful
Build / build (push) Successful in 2m31s
All checks were successful
Build / build (push) Successful in 2m31s
This commit is contained in:
@ -197,10 +197,10 @@ void StudioUI::drawMenu() noexcept {
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack && undoStack->canUndo())) {
|
||||
undoStack->undo();
|
||||
oxLogError(undoStack->undo());
|
||||
}
|
||||
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack && undoStack->canRedo())) {
|
||||
undoStack->redo();
|
||||
oxLogError(undoStack->redo());
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Copy", "Ctrl+C", false, m_activeEditor && m_activeEditor->copyEnabled())) {
|
||||
@ -315,14 +315,14 @@ void StudioUI::toggleProjectExplorer() noexcept {
|
||||
void StudioUI::redo() noexcept {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (undoStack && undoStack->canRedo()) {
|
||||
m_activeEditor->undoStack()->redo();
|
||||
oxLogError(m_activeEditor->undoStack()->redo());
|
||||
}
|
||||
}
|
||||
|
||||
void StudioUI::undo() noexcept {
|
||||
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
|
||||
if (undoStack && undoStack->canUndo()) {
|
||||
m_activeEditor->undoStack()->undo();
|
||||
oxLogError(m_activeEditor->undoStack()->undo());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,16 +131,14 @@ class Editor: public studio::BaseEditor {
|
||||
[[nodiscard]]
|
||||
UndoStack *undoStack() noexcept final;
|
||||
|
||||
void pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
ox::Error pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
|
||||
template<typename UC, typename ...Args>
|
||||
bool pushCommand(Args&&... args) noexcept {
|
||||
ox::Error pushCommand(Args&&... args) noexcept {
|
||||
try {
|
||||
m_undoStack.push(ox::make_unique<UC>(ox::forward<Args>(args)...));
|
||||
return true;
|
||||
return m_undoStack.push(ox::make_unique<UC>(ox::forward<Args>(args)...));
|
||||
} catch (ox::Exception const&ex) {
|
||||
oxLogError(ex.toError());
|
||||
return false;
|
||||
return ex.toError();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,11 @@ class UndoStack {
|
||||
std::size_t m_stackIdx = 0;
|
||||
|
||||
public:
|
||||
void push(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
ox::Error push(ox::UPtr<UndoCommand> &&cmd) noexcept;
|
||||
|
||||
void redo() noexcept;
|
||||
ox::Error redo() noexcept;
|
||||
|
||||
void undo() noexcept;
|
||||
ox::Error undo() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool canRedo() const noexcept {
|
||||
|
@ -127,8 +127,8 @@ ox::CStringView Editor::itemDisplayName() const noexcept {
|
||||
return m_itemName;
|
||||
}
|
||||
|
||||
void Editor::pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
m_undoStack.push(std::move(cmd));
|
||||
ox::Error Editor::pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
return m_undoStack.push(std::move(cmd));
|
||||
}
|
||||
|
||||
UndoStack *Editor::undoStack() noexcept {
|
||||
|
@ -6,42 +6,39 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
ox::Error UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
for (auto const i = m_stackIdx; i < m_stack.size();) {
|
||||
std::ignore = m_stack.erase(i);
|
||||
}
|
||||
if (cmd->redo()) {
|
||||
return;
|
||||
}
|
||||
oxReturnError(cmd->redo());
|
||||
redoTriggered.emit(cmd.get());
|
||||
changeTriggered.emit(cmd.get());
|
||||
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) {
|
||||
m_stack.emplace_back(std::move(cmd));
|
||||
++m_stackIdx;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void UndoStack::redo() noexcept {
|
||||
ox::Error UndoStack::redo() noexcept {
|
||||
if (m_stackIdx < m_stack.size()) {
|
||||
auto &c = m_stack[m_stackIdx];
|
||||
if (c->redo()) {
|
||||
return;
|
||||
}
|
||||
oxReturnError(c->redo());
|
||||
++m_stackIdx;
|
||||
redoTriggered.emit(c.get());
|
||||
changeTriggered.emit(c.get());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void UndoStack::undo() noexcept {
|
||||
ox::Error UndoStack::undo() noexcept {
|
||||
if (m_stackIdx) {
|
||||
auto &c = m_stack[--m_stackIdx];
|
||||
if (c->undo()) {
|
||||
return;
|
||||
}
|
||||
oxReturnError(c->undo());
|
||||
undoTriggered.emit(c.get());
|
||||
changeTriggered.emit(c.get());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user