# HG changeset patch # User sheepluva # Date 1425773081 -3600 # Node ID c76ea22ea249cb6e7205f9d27ede318fd0b07dad # Parent a772d342066af35ab82a607e448e4f8d15cbed90 copy to/paste from system clipboard (via frontend) diff -r a772d342066a -r c76ea22ea249 QTfrontend/game.cpp --- a/QTfrontend/game.cpp Fri Mar 06 21:24:21 2015 +0100 +++ b/QTfrontend/game.cpp Sun Mar 08 01:04:41 2015 +0100 @@ -16,6 +16,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include + #include #include #include @@ -210,6 +213,18 @@ SendIPC("!"); break; } + case 'Y': + { + // copy string to clipboard + QApplication::clipboard()->setText(QString::fromUtf8(msg.mid(2))); + break; + } + case 'P': + { + // paste clipboard to game + SendIPC(QString("P").toAscii() + QApplication::clipboard()->text().toUtf8().left(254).replace('\n', ' ')); + break; + } case 'C': { switch (gameType) diff -r a772d342066a -r c76ea22ea249 hedgewars/uChat.pas --- a/hedgewars/uChat.pas Fri Mar 06 21:24:21 2015 +0100 +++ b/hedgewars/uChat.pas Sun Mar 08 01:04:41 2015 +0100 @@ -249,6 +249,8 @@ inc(visibleCount) end; +procedure CheckPasteBuffer(); forward; + procedure DrawChat; var i, t, left, top, cnt: LongInt; selRect: TSDL_Rect; @@ -265,6 +267,8 @@ // draw chat input line first and under all other lines if (GameState = gsChat) and (InputStr.Tex <> nil) then begin + CheckPasteBuffer(); + if firstDraw then begin UpdateCursorCoords(); @@ -662,11 +666,9 @@ end; end; -var clipboardBuffer: shortstring; - procedure CopyToClipboard(var newContent: shortstring); begin - clipboardBuffer:= newContent; + SendIPC(_S'Y' + copy(newContent, 1, 253) + #0); end; procedure CopySelectionToClipboard(); @@ -710,8 +712,16 @@ procedure PasteFromClipboard(); begin - DeleteSelected(); - InsertIntoInputStr(clipboardBuffer); + SendIPC(_S'P'); +end; + +procedure CheckPasteBuffer(); +begin + if Length(ChatPasteBuffer) > 0 then + begin + InsertIntoInputStr(ChatPasteBuffer); + ChatPasteBuffer:= ''; + end; end; procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); @@ -724,6 +734,8 @@ LastKeyPressTick:= RealTicks; action:= true; + CheckPasteBuffer(); + selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0; ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0; skip:= none; @@ -1069,8 +1081,6 @@ LastKeyPressTick:= 0; ResetCursor(); - - clipboardBuffer:= ''; end; procedure freeModule; diff -r a772d342066a -r c76ea22ea249 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Fri Mar 06 21:24:21 2015 +0100 +++ b/hedgewars/uIO.pas Sun Mar 08 01:04:41 2015 +0100 @@ -138,6 +138,7 @@ case s[1] of '!': begin AddFileLog('Ping? Pong!'); isPonged:= true; end; '?': SendIPC(_S'!'); + 'P': ChatPasteBuffer:= copy(s, 2, Length(s) - 1); 'e': ParseCommand(copy(s, 2, Length(s) - 1), true); 'E': OutError(copy(s, 2, Length(s) - 1), true); 'W': OutError(copy(s, 2, Length(s) - 1), false); diff -r a772d342066a -r c76ea22ea249 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Fri Mar 06 21:24:21 2015 +0100 +++ b/hedgewars/uVariables.pas Sun Mar 08 01:04:41 2015 +0100 @@ -237,6 +237,8 @@ MaxTextureSize: LongInt; + ChatPasteBuffer: shortstring; + ///////////////////////////////////// //Buttons {$IFDEF USE_TOUCH_INTERFACE} @@ -2685,6 +2687,8 @@ cStereoDepth:= 0; cViewLimitsDebug:= false; AprilOne := false; + + ChatPasteBuffer:= ''; end; procedure freeModule;