Make ctrl+x cut to clipboard
This commit is contained in:
@@ -61,6 +61,7 @@ namespace OpenRA
|
|||||||
Bitmap TakeScreenshot();
|
Bitmap TakeScreenshot();
|
||||||
void PumpInput(IInputHandler inputHandler);
|
void PumpInput(IInputHandler inputHandler);
|
||||||
string GetClipboardText();
|
string GetClipboardText();
|
||||||
|
bool SetClipboardText(string text);
|
||||||
void DrawPrimitives(PrimitiveType type, int firstVertex, int numVertices);
|
void DrawPrimitives(PrimitiveType type, int firstVertex, int numVertices);
|
||||||
|
|
||||||
void SetLineWidth(float width);
|
void SetLineWidth(float width);
|
||||||
|
|||||||
@@ -267,5 +267,10 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
return Device.GetClipboardText();
|
return Device.GetClipboardText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SetClipboardText(string text)
|
||||||
|
{
|
||||||
|
return Device.SetClipboardText(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,15 +123,15 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Func<int> getPrevWhitespaceIndex = () =>
|
Func<int> getPrevWhitespaceIndex = () =>
|
||||||
Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
||||||
|
|
||||||
Func<int> getNextWhitespaceIndex = () => {
|
Func<int> getNextWhitespaceIndex = () =>
|
||||||
|
{
|
||||||
var substr = Text.Substring(CursorPosition);
|
var substr = Text.Substring(CursorPosition);
|
||||||
var substrTrimmed = substr.TrimStart();
|
var substrTrimmed = substr.TrimStart();
|
||||||
var trimmedSpaces = substr.Length - substrTrimmed.Length;
|
var trimmedSpaces = substr.Length - substrTrimmed.Length;
|
||||||
var nextWhitespace = substrTrimmed.IndexOf(' ');
|
var nextWhitespace = substrTrimmed.IndexOf(' ');
|
||||||
if (nextWhitespace == -1)
|
if (nextWhitespace == -1)
|
||||||
return Text.Length;
|
return Text.Length;
|
||||||
else
|
return CursorPosition + trimmedSpaces + nextWhitespace;
|
||||||
return CursorPosition + trimmedSpaces + nextWhitespace;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var isOSX = Platform.CurrentPlatform == PlatformType.OSX;
|
var isOSX = Platform.CurrentPlatform == PlatformType.OSX;
|
||||||
@@ -161,21 +161,24 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
case Keycode.LEFT:
|
case Keycode.LEFT:
|
||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if (CursorPosition > 0)
|
if (CursorPosition > 0)
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
{
|
||||||
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
CursorPosition = getPrevWhitespaceIndex();
|
CursorPosition = getPrevWhitespaceIndex();
|
||||||
else
|
else
|
||||||
CursorPosition--;
|
CursorPosition--;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.RIGHT:
|
case Keycode.RIGHT:
|
||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if (CursorPosition <= Text.Length - 1)
|
if (CursorPosition <= Text.Length - 1)
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
{
|
||||||
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
CursorPosition = getNextWhitespaceIndex();
|
CursorPosition = getNextWhitespaceIndex();
|
||||||
else
|
else
|
||||||
CursorPosition++;
|
CursorPosition++;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -214,10 +217,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
case Keycode.X:
|
case Keycode.X:
|
||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if (((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if (((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))) &&
|
||||||
(isOSX && e.Modifiers.HasModifier(Modifiers.Meta))) &&
|
!string.IsNullOrEmpty(Text))
|
||||||
(!string.IsNullOrEmpty(Text)))
|
|
||||||
{
|
{
|
||||||
|
Game.Renderer.SetClipboardText(Text);
|
||||||
Text = Text.Remove(0);
|
Text = Text.Remove(0);
|
||||||
CursorPosition = 0;
|
CursorPosition = 0;
|
||||||
OnTextEdited();
|
OnTextEdited();
|
||||||
@@ -230,8 +233,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if (CursorPosition < Text.Length)
|
if (CursorPosition < Text.Length)
|
||||||
{
|
{
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
Text = Text.Substring(0, CursorPosition) + Text.Substring(getNextWhitespaceIndex());
|
Text = Text.Substring(0, CursorPosition) + Text.Substring(getNextWhitespaceIndex());
|
||||||
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||||
Text = Text.Remove(CursorPosition);
|
Text = Text.Remove(CursorPosition);
|
||||||
@@ -248,8 +250,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if (CursorPosition > 0)
|
if (CursorPosition > 0)
|
||||||
{
|
{
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
|
||||||
{
|
{
|
||||||
var prev_whitespace = getPrevWhitespaceIndex();
|
var prev_whitespace = getPrevWhitespaceIndex();
|
||||||
Text = Text.Substring(0, prev_whitespace) + Text.Substring(CursorPosition);
|
Text = Text.Substring(0, prev_whitespace) + Text.Substring(CursorPosition);
|
||||||
@@ -273,8 +274,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
case Keycode.V:
|
case Keycode.V:
|
||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Meta)))
|
||||||
(isOSX && e.Modifiers.HasModifier(Modifiers.Meta)))
|
|
||||||
{
|
{
|
||||||
var clipboardText = Game.Renderer.GetClipboardText();
|
var clipboardText = Game.Renderer.GetClipboardText();
|
||||||
|
|
||||||
|
|||||||
@@ -382,6 +382,12 @@ namespace OpenRA.Platforms.Default
|
|||||||
return input.GetClipboardText();
|
return input.GetClipboardText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SetClipboardText(string text)
|
||||||
|
{
|
||||||
|
VerifyThreadAffinity();
|
||||||
|
return input.SetClipboardText(text);
|
||||||
|
}
|
||||||
|
|
||||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size)
|
public IVertexBuffer<Vertex> CreateVertexBuffer(int size)
|
||||||
{
|
{
|
||||||
VerifyThreadAffinity();
|
VerifyThreadAffinity();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
MouseButton lastButtonBits = (MouseButton)0;
|
MouseButton lastButtonBits = (MouseButton)0;
|
||||||
|
|
||||||
public string GetClipboardText() { return SDL.SDL_GetClipboardText(); }
|
public string GetClipboardText() { return SDL.SDL_GetClipboardText(); }
|
||||||
|
public bool SetClipboardText(string text) { return SDL.SDL_SetClipboardText(text) == 0; }
|
||||||
|
|
||||||
static MouseButton MakeButton(byte b)
|
static MouseButton MakeButton(byte b)
|
||||||
{
|
{
|
||||||
@@ -177,4 +178,4 @@ namespace OpenRA.Platforms.Default
|
|||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ namespace OpenRA.Platforms.Null
|
|||||||
public Bitmap TakeScreenshot() { return new Bitmap(1, 1); }
|
public Bitmap TakeScreenshot() { return new Bitmap(1, 1); }
|
||||||
|
|
||||||
public string GetClipboardText() { return ""; }
|
public string GetClipboardText() { return ""; }
|
||||||
|
public bool SetClipboardText(string text) { return false; }
|
||||||
public void PumpInput(IInputHandler ih)
|
public void PumpInput(IInputHandler ih)
|
||||||
{
|
{
|
||||||
Game.HasInputFocus = false;
|
Game.HasInputFocus = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user