File indexing completed on 2024-04-28 15:39:41

0001 /* SPDX-FileCopyrightText: 2014 Jesper K. Pedersen <blackie@kde.org>
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "History.h"
0007 
0008 namespace RemoteControl
0009 {
0010 
0011 void History::push(std::unique_ptr<Action> action)
0012 {
0013     if (m_current)
0014         m_current->save();
0015     m_backward.push(std::move(m_current));
0016     m_forward = std::stack<std::unique_ptr<Action>>();
0017     m_current = std::move(action);
0018     m_current->run();
0019 }
0020 
0021 void History::goForward()
0022 {
0023     if (m_current)
0024         m_current->save();
0025     m_backward.push(std::move(m_current));
0026     m_current = std::move(m_forward.top());
0027     m_forward.pop();
0028     m_current->run();
0029 }
0030 
0031 void History::goBackward()
0032 {
0033     if (m_current)
0034         m_current->save();
0035     m_forward.push(std::move(m_current));
0036     m_current = std::move(m_backward.top());
0037     m_backward.pop();
0038     m_current->run();
0039 }
0040 
0041 bool History::canGoBack() const
0042 {
0043     return m_backward.size() > 1;
0044 }
0045 
0046 bool History::canGoForward() const
0047 {
0048     return !m_forward.empty();
0049 }
0050 
0051 void History::rerunTopItem()
0052 {
0053     m_current->run();
0054 }
0055 
0056 } // namespace RemoteControl