mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
And fixup launcher too
This commit is contained in:
parent
40532a439f
commit
8ae11b80a1
@ -72,9 +72,11 @@ namespace Launcher.Gui.Screens {
|
|||||||
RedrawLastInput();
|
RedrawLastInput();
|
||||||
OnRemovedChar();
|
OnRemovedChar();
|
||||||
} else if (e.Key == Key.C && ControlDown) {
|
} else if (e.Key == Key.C && ControlDown) {
|
||||||
curInput.Chars.CopyToClipboard();
|
if (String.IsNullOrEmpty(curInput.Text)) return;
|
||||||
|
game.Window.SetClipboardText(curInput.Text);
|
||||||
} else if (e.Key == Key.V && ControlDown) {
|
} else if (e.Key == Key.V && ControlDown) {
|
||||||
if (curInput.Chars.CopyFromClipboard()) RedrawLastInput();
|
string text = game.Window.GetClipboardText();
|
||||||
|
if (curInput.Chars.CopyFromClipboard(text)) RedrawLastInput();
|
||||||
} else if (e.Key == Key.Escape) {
|
} else if (e.Key == Key.Escape) {
|
||||||
if (curInput.Chars.Clear()) RedrawLastInput();
|
if (curInput.Chars.Clear()) RedrawLastInput();
|
||||||
} else if (e.Key == Key.Left) {
|
} else if (e.Key == Key.Left) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
|
||||||
using ClassicalSharp;
|
using ClassicalSharp;
|
||||||
|
|
||||||
namespace Launcher.Gui.Widgets {
|
namespace Launcher.Gui.Widgets {
|
||||||
@ -100,17 +99,12 @@ namespace Launcher.Gui.Widgets {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Copies the contents of the currently entered text to the system clipboard. </summary>
|
|
||||||
public void CopyToClipboard() {
|
|
||||||
if (String.IsNullOrEmpty(input.Text)) return;
|
|
||||||
Clipboard.SetText(input.Text);
|
|
||||||
}
|
|
||||||
static char[] trimChars = new char[] {'\r', '\n', '\v', '\f', ' ', '\t', '\0'};
|
static char[] trimChars = new char[] {'\r', '\n', '\v', '\f', ' ', '\t', '\0'};
|
||||||
|
|
||||||
/// <summary> Sets the currently entered text to the contents of the system clipboard. </summary>
|
/// <summary> Sets the currently entered text to the contents of the system clipboard. </summary>
|
||||||
/// <returns> true if a redraw is necessary, false otherwise. </returns>
|
/// <returns> true if a redraw is necessary, false otherwise. </returns>
|
||||||
public bool CopyFromClipboard() {
|
public bool CopyFromClipboard(string text) {
|
||||||
string text = Clipboard.GetText().Trim(trimChars);
|
text = text.Trim(trimChars);
|
||||||
if (String.IsNullOrEmpty(text)) return false;
|
if (String.IsNullOrEmpty(text)) return false;
|
||||||
if (input.Text.Length >= MaxChars) return false;
|
if (input.Text.Length >= MaxChars) return false;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ namespace OpenTK.Platform.X11 {
|
|||||||
IntPtr net_wm_icon;
|
IntPtr net_wm_icon;
|
||||||
IntPtr net_frame_extents;
|
IntPtr net_frame_extents;
|
||||||
|
|
||||||
IntPtr clipboard, xa_targets, xa_utf8_string, xa_atom, data_sel;
|
IntPtr xa_clipboard, xa_targets, xa_utf8_string, xa_atom, xa_data_sel;
|
||||||
string clipboard_paste_text, clipboard_copy_text;
|
string clipboard_paste_text, clipboard_copy_text;
|
||||||
|
|
||||||
static readonly IntPtr xa_cardinal = (IntPtr)6;
|
static readonly IntPtr xa_cardinal = (IntPtr)6;
|
||||||
@ -193,11 +193,11 @@ namespace OpenTK.Platform.X11 {
|
|||||||
net_wm_icon = API.XInternAtom(window.Display, "_NEW_WM_ICON", false);
|
net_wm_icon = API.XInternAtom(window.Display, "_NEW_WM_ICON", false);
|
||||||
net_frame_extents = API.XInternAtom(window.Display, "_NET_FRAME_EXTENTS", false);
|
net_frame_extents = API.XInternAtom(window.Display, "_NET_FRAME_EXTENTS", false);
|
||||||
|
|
||||||
clipboard = API.XInternAtom(window.Display, "CLIPBOARD", false);
|
xa_clipboard = API.XInternAtom(window.Display, "CLIPBOARD", false);
|
||||||
xa_targets = API.XInternAtom(window.Display, "TARGETS", false);
|
xa_targets = API.XInternAtom(window.Display, "TARGETS", false);
|
||||||
xa_utf8_string = API.XInternAtom(window.Display, "UTF8_STRING", false);
|
xa_utf8_string = API.XInternAtom(window.Display, "UTF8_STRING", false);
|
||||||
xa_atom = API.XInternAtom(window.Display, "ATOM", false);
|
xa_atom = API.XInternAtom(window.Display, "ATOM", false);
|
||||||
data_sel = API.XInternAtom(window.Display, "CS_SEL_DATA", false);
|
xa_data_sel = API.XInternAtom(window.Display, "CS_SEL_DATA", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWindowMinMax(short min_width, short min_height, short max_width, short max_height) {
|
void SetWindowMinMax(short min_width, short min_height, short max_width, short max_height) {
|
||||||
@ -433,14 +433,14 @@ namespace OpenTK.Platform.X11 {
|
|||||||
case XEventName.SelectionNotify:
|
case XEventName.SelectionNotify:
|
||||||
clipboard_paste_text = "";
|
clipboard_paste_text = "";
|
||||||
|
|
||||||
if (e.SelectionEvent.selection == clipboard && e.SelectionEvent.target == xa_utf8_string && e.SelectionEvent.property == data_sel) {
|
if (e.SelectionEvent.selection == xa_clipboard && e.SelectionEvent.target == xa_utf8_string && e.SelectionEvent.property == xa_data_sel) {
|
||||||
IntPtr prop_type, num_items, bytes_after, data = IntPtr.Zero;
|
IntPtr prop_type, num_items, bytes_after, data = IntPtr.Zero;
|
||||||
int prop_format;
|
int prop_format;
|
||||||
|
|
||||||
API.XGetWindowProperty (window.Display, window.WinHandle, data_sel, IntPtr.Zero, new IntPtr (1024), false, IntPtr.Zero,
|
API.XGetWindowProperty (window.Display, window.WinHandle, xa_data_sel, IntPtr.Zero, new IntPtr (1024), false, IntPtr.Zero,
|
||||||
out prop_type, out prop_format, out num_items, out bytes_after, ref data);
|
out prop_type, out prop_format, out num_items, out bytes_after, ref data);
|
||||||
|
|
||||||
API.XDeleteProperty (window.Display, window.WinHandle, data_sel);
|
API.XDeleteProperty (window.Display, window.WinHandle, xa_data_sel);
|
||||||
if (num_items == IntPtr.Zero) break;
|
if (num_items == IntPtr.Zero) break;
|
||||||
|
|
||||||
if (prop_type == xa_utf8_string) {
|
if (prop_type == xa_utf8_string) {
|
||||||
@ -465,7 +465,7 @@ namespace OpenTK.Platform.X11 {
|
|||||||
reply.SelectionEvent.property = IntPtr.Zero;
|
reply.SelectionEvent.property = IntPtr.Zero;
|
||||||
reply.SelectionEvent.time = e.SelectionRequestEvent.time;
|
reply.SelectionEvent.time = e.SelectionRequestEvent.time;
|
||||||
|
|
||||||
if (e.SelectionRequestEvent.selection == clipboard && e.SelectionRequestEvent.target == xa_utf8_string && clipboard_copy_text != null) {
|
if (e.SelectionRequestEvent.selection == xa_clipboard && e.SelectionRequestEvent.target == xa_utf8_string && clipboard_copy_text != null) {
|
||||||
reply.SelectionEvent.property = GetSelectionProperty(ref e);
|
reply.SelectionEvent.property = GetSelectionProperty(ref e);
|
||||||
|
|
||||||
byte[] utf8_data = Encoding.UTF8.GetBytes (clipboard_copy_text);
|
byte[] utf8_data = Encoding.UTF8.GetBytes (clipboard_copy_text);
|
||||||
@ -473,7 +473,7 @@ namespace OpenTK.Platform.X11 {
|
|||||||
API.XChangeProperty(window.Display, reply.SelectionEvent.requestor, reply.SelectionEvent.property, xa_utf8_string, 8,
|
API.XChangeProperty(window.Display, reply.SelectionEvent.requestor, reply.SelectionEvent.property, xa_utf8_string, 8,
|
||||||
PropertyMode.Replace, (IntPtr)utf8_ptr, utf8_data.Length);
|
PropertyMode.Replace, (IntPtr)utf8_ptr, utf8_data.Length);
|
||||||
}
|
}
|
||||||
} else if (e.SelectionRequestEvent.selection == clipboard && e.SelectionRequestEvent.target == xa_targets) {
|
} else if (e.SelectionRequestEvent.selection == xa_clipboard && e.SelectionRequestEvent.target == xa_targets) {
|
||||||
reply.SelectionEvent.property = GetSelectionProperty(ref e);
|
reply.SelectionEvent.property = GetSelectionProperty(ref e);
|
||||||
|
|
||||||
IntPtr[] data = new IntPtr[] { xa_utf8_string, xa_targets };
|
IntPtr[] data = new IntPtr[] { xa_utf8_string, xa_targets };
|
||||||
@ -500,13 +500,10 @@ namespace OpenTK.Platform.X11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string GetClipboardText() {
|
public string GetClipboardText() {
|
||||||
IntPtr owner = API.XGetSelectionOwner(window.Display, clipboard);
|
IntPtr owner = API.XGetSelectionOwner(window.Display, xa_clipboard);
|
||||||
if (owner == IntPtr.Zero) return ""; // no window owner
|
if (owner == IntPtr.Zero) return ""; // no window owner
|
||||||
|
|
||||||
Console.WriteLine (window.WinHandle + ", " + window.WindowHandle);
|
API.XConvertSelection(window.Display, xa_clipboard, xa_utf8_string, xa_data_sel, window.WinHandle, IntPtr.Zero);
|
||||||
int result = API.XConvertSelection (window.Display, clipboard, xa_utf8_string, data_sel, window.WinHandle, IntPtr.Zero);
|
|
||||||
Console.WriteLine (owner.ToInt64 () + ", " + result);
|
|
||||||
|
|
||||||
clipboard_paste_text = null;
|
clipboard_paste_text = null;
|
||||||
|
|
||||||
// wait up to 1 second for SelectionNotify event to arrive
|
// wait up to 1 second for SelectionNotify event to arrive
|
||||||
@ -520,7 +517,7 @@ namespace OpenTK.Platform.X11 {
|
|||||||
|
|
||||||
public void SetClipboardText(string value) {
|
public void SetClipboardText(string value) {
|
||||||
clipboard_copy_text = value;
|
clipboard_copy_text = value;
|
||||||
API.XSetSelectionOwner(window.Display, clipboard, window.WinHandle, IntPtr.Zero);
|
API.XSetSelectionOwner(window.Display, xa_clipboard, window.WinHandle, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle Bounds {
|
public Rectangle Bounds {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user