aboutsummaryrefslogtreecommitdiff
path: root/gui/console.cpp
diff options
context:
space:
mode:
authorBastien Bouclet2018-04-21 16:01:58 +0200
committerAdrian Frühwirth2018-05-07 22:42:00 +0200
commitbdc0db97d5fbb5ea6ef71aea466e38b13d1fb40c (patch)
tree0f2e57c0f9a5dd31a80fc77dcc3631b41d43602b /gui/console.cpp
parentb210254dc02848690241802e2817f5935d1b7b38 (diff)
downloadscummvm-rg350-bdc0db97d5fbb5ea6ef71aea466e38b13d1fb40c.tar.gz
scummvm-rg350-bdc0db97d5fbb5ea6ef71aea466e38b13d1fb40c.tar.bz2
scummvm-rg350-bdc0db97d5fbb5ea6ef71aea466e38b13d1fb40c.zip
GUI: Add copy and paste support to the graphical console
Diffstat (limited to 'gui/console.cpp')
-rw-r--r--gui/console.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/gui/console.cpp b/gui/console.cpp
index 553b3c56d4..5e9def8740 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -243,9 +243,19 @@ void ConsoleDialog::handleMouseWheel(int x, int y, int direction) {
_scrollBar->handleMouseWheel(x, y, direction);
}
-void ConsoleDialog::handleKeyDown(Common::KeyState state) {
- int i;
+Common::String ConsoleDialog::getUserInput() {
+ assert(_promptEndPos >= _promptStartPos);
+ int len = _promptEndPos - _promptStartPos;
+
+ // Copy the user input to str
+ Common::String str;
+ for (int i = 0; i < len; i++)
+ str.insertChar(buffer(_promptStartPos + i), i);
+ return str;
+}
+
+void ConsoleDialog::handleKeyDown(Common::KeyState state) {
if (_slideMode != kNoSlideMode)
return;
@@ -257,26 +267,16 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
nextLine();
- assert(_promptEndPos >= _promptStartPos);
- int len = _promptEndPos - _promptStartPos;
bool keepRunning = true;
-
- if (len > 0) {
-
- Common::String str;
-
- // Copy the user input to str
- for (i = 0; i < len; i++)
- str.insertChar(buffer(_promptStartPos + i), i);
-
+ Common::String userInput = getUserInput();
+ if (!userInput.empty()) {
// Add the input to the history
- addToHistory(str);
+ addToHistory(userInput);
// Pass it to the input callback, if any
if (_callbackProc)
- keepRunning = (*_callbackProc)(this, str.c_str(), _callbackRefCon);
-
+ keepRunning = (*_callbackProc)(this, userInput.c_str(), _callbackRefCon);
}
print(PROMPT);
@@ -311,7 +311,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
char *str = new char[len + 1];
// Copy the user input to str
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
str[i] = buffer(_promptStartPos + i);
str[len] = '\0';
@@ -504,7 +504,7 @@ void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
}
}
-void ConsoleDialog::specialKeys(int keycode) {
+void ConsoleDialog::specialKeys(Common::KeyCode keycode) {
switch (keycode) {
case Common::KEYCODE_a:
_currentPos = _promptStartPos;
@@ -528,6 +528,23 @@ void ConsoleDialog::specialKeys(int keycode) {
killLastWord();
g_gui.scheduleTopDialogRedraw();
break;
+ case Common::KEYCODE_v:
+ if (g_system->hasFeature(OSystem::kFeatureClipboardSupport) && g_system->hasTextInClipboard()) {
+ Common::String text = g_system->getTextFromClipboard();
+ insertIntoPrompt(text.c_str());
+ scrollToCurrent();
+ drawLine(pos2line(_currentPos));
+ }
+ break;
+ case Common::KEYCODE_c:
+ if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
+ Common::String userInput = getUserInput();
+ if (!userInput.empty())
+ g_system->setTextInClipboard(userInput);
+ }
+ break;
+ default:
+ break;
}
}