dequeu (original) (raw)
...
void MyEditor::Window_Open(Win::Event& e)
{
btUndo.Enabled = false;
btRedo.Enabled = false;
}
void MyEditor::btUndo_Click(Win::Event& e)
{
if (undo.empty() == true) return;
//_____________________________ Step 1: Store current state
redo.push_front(tbxInput.Text);
//_____________________________ Step 2. Remove if full
if (redo.size()>=MAX_UNDO) redo.pop_back();
//_____________________________ Step 3. Perform the change
tbxInput.Text = undo.front();
undo.pop_front();
//_____________________________ Update buttons
btRedo.Enabled = (redo.empty() == false);
btUndo.Enabled = (undo.empty() == false);
}
void MyEditor::btRedo_Click(Win::Event& e)
{
if (redo.empty() == true) return;
//_____________________________ Step 1: Store current state
undo.push_front(tbxInput.Text);
//_____________________________ Step 2. Remove if full
if (undo.size()>=MAX_UNDO) undo.pop_back();
//_____________________________ Step 3. Perform the change
tbxInput.Text = redo.front();
redo.pop_front();
//_____________________________ Update buttons
btRedo.Enabled = (redo.empty() == false);
btUndo.Enabled = (undo.empty() == false);
}
void MyEditor::tbxInput_Change(Win::Event& e)
{
undo.push_front(tbxInput.Text);
btUndo.Enabled = true;
if (undo.size()>=MAX_UNDO) undo.pop_back();
redo.clear();
btRedo.Enabled = false;
}