From 5cea5a4d3aa712c21fbdfd9283c8ce9981086a67 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 12 Feb 2016 19:36:08 +0100 Subject: WAGE: Implement Cut and Clear actions --- engines/wage/gui-console.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ engines/wage/gui.cpp | 8 ++++++++ engines/wage/gui.h | 2 ++ engines/wage/menu.cpp | 4 ++-- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 9b02608989..92e61f9617 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -348,6 +348,49 @@ void Gui::actionUndo() { _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); } +void Gui::actionClear() { + int startPos = _selectionStartX; + int endPos = _selectionEndX; + + if (startPos > endPos) + SWAP(startPos, endPos); + + Common::String beg(_lines[_selectionStartY].c_str(), &_lines[_selectionStartY].c_str()[startPos]); + Common::String end(&_lines[_selectionStartY].c_str()[endPos]); + + _undobuffer = _engine->_inputText; + _engine->_inputText = beg + end; + drawInput(); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); + + _selectionStartY = -1; + _selectionEndY = -1; +} + +void Gui::actionCut() { + int startPos = _selectionStartX; + int endPos = _selectionEndX; + + if (startPos > endPos) + SWAP(startPos, endPos); + + Common::String beg(_lines[_selectionStartY].c_str(), &_lines[_selectionStartY].c_str()[startPos]); + Common::String mid(&_lines[_selectionStartY].c_str()[startPos], &_lines[_selectionStartY].c_str()[endPos]); + Common::String end(&_lines[_selectionStartY].c_str()[endPos]); + + _undobuffer = _engine->_inputText; + _engine->_inputText = beg + end; + _clipboard = mid; + drawInput(); + + _menu->enableCommand(kMenuEdit, kMenuActionUndo, true); + _menu->enableCommand(kMenuEdit, kMenuActionPaste, true); + + _selectionStartY = -1; + _selectionEndY = -1; +} + void Gui::disableUndo() { _menu->enableCommand(kMenuEdit, kMenuActionUndo, false); } diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 309617e8ff..819f5881c4 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -485,6 +485,14 @@ Designed *Gui::mouseUp(int x, int y) { _menu->enableCommand(kMenuEdit, kMenuActionCopy, false); } else { _menu->enableCommand(kMenuEdit, kMenuActionCopy, true); + + bool cutAllowed = false; + + if (_selectionStartY == _selectionEndY && _selectionStartY == _lines.size() - 1) + cutAllowed = true; + + _menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed); + _menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed); } } diff --git a/engines/wage/gui.h b/engines/wage/gui.h index 652e0ff1e4..f679faa5cd 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -107,6 +107,8 @@ public: void actionCopy(); void actionPaste(); void actionUndo(); + void actionClear(); + void actionCut(); void disableUndo(); private: diff --git a/engines/wage/menu.cpp b/engines/wage/menu.cpp index aeb5792b44..a65d4dd36a 100644 --- a/engines/wage/menu.cpp +++ b/engines/wage/menu.cpp @@ -519,7 +519,7 @@ void Menu::executeCommand(MenuSubItem *subitem) { _gui->actionUndo(); break; case kMenuActionCut: - warning("STUB: Unhandled shortcut"); + _gui->actionCut(); break; case kMenuActionCopy: _gui->actionCopy(); @@ -528,7 +528,7 @@ void Menu::executeCommand(MenuSubItem *subitem) { _gui->actionPaste(); break; case kMenuActionClear: - warning("STUB: Unhandled shortcut"); + _gui->actionClear(); break; case kMenuActionCommand: -- cgit v1.2.3