diff options
| author | Bastien Bouclet | 2018-04-21 16:01:58 +0200 | 
|---|---|---|
| committer | Adrian Frühwirth | 2018-05-07 22:42:00 +0200 | 
| commit | bdc0db97d5fbb5ea6ef71aea466e38b13d1fb40c (patch) | |
| tree | 0f2e57c0f9a5dd31a80fc77dcc3631b41d43602b /gui | |
| parent | b210254dc02848690241802e2817f5935d1b7b38 (diff) | |
| download | scummvm-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')
| -rw-r--r-- | gui/console.cpp | 53 | ||||
| -rw-r--r-- | gui/console.h | 3 | 
2 files changed, 37 insertions, 19 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;  	}  } diff --git a/gui/console.h b/gui/console.h index d311ad5636..2445005afc 100644 --- a/gui/console.h +++ b/gui/console.h @@ -174,11 +174,12 @@ protected:  	void print(const char *str);  	void updateScrollBuffer();  	void scrollToCurrent(); +	Common::String getUserInput();  	void defaultKeyDownHandler(Common::KeyState &state);  	// Line editing -	void specialKeys(int keycode); +	void specialKeys(Common::KeyCode keycode);  	void nextLine();  	void killChar();  	void killLine();  | 
