Selaa lähdekoodia

Merge remote-tracking branch 'upstream/develop' into v_1_8_0

Charlie Kindel 2 vuotta sitten
vanhempi
commit
811e6376d1

+ 1 - 1
Terminal.Gui/Core/Clipboard/Clipboard.cs

@@ -15,7 +15,7 @@ namespace Terminal.Gui {
 			get {
 				try {
 					if (IsSupported) {
-						return Application.Driver.Clipboard.GetClipboardData ();
+						return contents = ustring.Make (Application.Driver.Clipboard.GetClipboardData ());
 					} else {
 						return contents;
 					}

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -2722,7 +2722,7 @@ namespace Terminal.Gui {
 		/// <returns>The text formatter size more the <see cref="TextFormatter.HotKeySpecifier"/> length.</returns>
 		public Size GetBoundsTextFormatterSize ()
 		{
-			if (TextFormatter.Text == null)
+			if (ustring.IsNullOrEmpty (TextFormatter.Text))
 				return Bounds.Size;
 
 			return new Size (frame.Size.Width + GetHotKeySpecifierLength (),

+ 2 - 2
Terminal.Gui/Views/TextField.cs

@@ -666,7 +666,7 @@ namespace Terminal.Gui {
 
 			historyText.Redo ();
 
-			//if (Clipboard.Contents == null)
+			//if (ustring.IsNullOrEmpty (Clipboard.Contents))
 			//	return true;
 			//var clip = TextModel.ToRunes (Clipboard.Contents);
 			//if (clip == null)
@@ -1217,7 +1217,7 @@ namespace Terminal.Gui {
 		/// </summary>
 		public virtual void Paste ()
 		{
-			if (ReadOnly || Clipboard.Contents == null) {
+			if (ReadOnly || ustring.IsNullOrEmpty (Clipboard.Contents)) {
 				return;
 			}
 

+ 1 - 1
UnitTests/ApplicationTests.cs

@@ -1318,7 +1318,7 @@ namespace Terminal.Gui.Core {
 						if (myi == 0) {
 
 							// let the timeouts run for a bit
-							Thread.Sleep (5000);
+							Thread.Sleep (10000);
 
 							// then tell the application to quit
 							Application.MainLoop.Invoke (() => Application.RequestStop ());

+ 103 - 107
UnitTests/ClipboardTests.cs

@@ -53,23 +53,21 @@ namespace Terminal.Gui.Core {
 		[AutoInitShutdown]
 		public void TrySetClipboardData_Sets_The_OS_Clipboard ()
 		{
-			lock (Clipboard.Contents) {
-				var clipText = "Trying to set the OS clipboard.";
-				if (Clipboard.IsSupported) {
-					Assert.True (Clipboard.TrySetClipboardData (clipText));
-				} else {
-					Assert.False (Clipboard.TrySetClipboardData (clipText));
-				}
+			var clipText = "Trying to set the OS clipboard.";
+			if (Clipboard.IsSupported) {
+				Assert.True (Clipboard.TrySetClipboardData (clipText));
+			} else {
+				Assert.False (Clipboard.TrySetClipboardData (clipText));
+			}
 
-				Application.Iteration += () => Application.RequestStop ();
+			Application.Iteration += () => Application.RequestStop ();
 
-				Application.Run ();
+			Application.Run ();
 
-				if (Clipboard.IsSupported) {
-					Assert.Equal (clipText, Clipboard.Contents);
-				} else {
-					Assert.NotEqual (clipText, Clipboard.Contents);
-				}
+			if (Clipboard.IsSupported) {
+				Assert.Equal (clipText, Clipboard.Contents);
+			} else {
+				Assert.NotEqual (clipText, Clipboard.Contents);
 			}
 		}
 
@@ -81,112 +79,110 @@ namespace Terminal.Gui.Core {
 			var exit = false;
 			var getClipText = "";
 
-			lock (Clipboard.Contents) {
-				Application.Iteration += () => {
-					if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
-						// using (Process clipExe = new Process {
-						// 	StartInfo = new ProcessStartInfo {
-						// 		RedirectStandardInput = true,
-						// 		FileName = "clip"
-						// 	}
-						// }) {
-						// 	clipExe.Start ();
-						// 	clipExe.StandardInput.Write (clipText);
-						// 	clipExe.StandardInput.Close ();
-						// 	var result = clipExe.WaitForExit (500);
-						// 	if (result) {
-						// 		clipExe.WaitForExit ();
-						// 	}
-						// }
-
-						using (Process pwsh = new Process {
-							StartInfo = new ProcessStartInfo {
-								FileName = "powershell",
-								Arguments = $"-command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
-							}
-						}) {
-							pwsh.Start ();
-							pwsh.WaitForExit ();
+			Application.Iteration += () => {
+				if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
+					// using (Process clipExe = new Process {
+					// 	StartInfo = new ProcessStartInfo {
+					// 		RedirectStandardInput = true,
+					// 		FileName = "clip"
+					// 	}
+					// }) {
+					// 	clipExe.Start ();
+					// 	clipExe.StandardInput.Write (clipText);
+					// 	clipExe.StandardInput.Close ();
+					// 	var result = clipExe.WaitForExit (500);
+					// 	if (result) {
+					// 		clipExe.WaitForExit ();
+					// 	}
+					// }
+
+					using (Process pwsh = new Process {
+						StartInfo = new ProcessStartInfo {
+							FileName = "powershell",
+							Arguments = $"-command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
 						}
-						getClipText = Clipboard.Contents.ToString ();
+					}) {
+						pwsh.Start ();
+						pwsh.WaitForExit ();
+					}
+					getClipText = Clipboard.Contents.ToString ();
 
-					} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
-						using (Process copy = new Process {
-							StartInfo = new ProcessStartInfo {
-								RedirectStandardInput = true,
-								FileName = "pbcopy"
-							}
-						}) {
-							copy.Start ();
-							copy.StandardInput.Write (clipText);
-							copy.StandardInput.Close ();
-							copy.WaitForExit ();
+				} else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
+					using (Process copy = new Process {
+						StartInfo = new ProcessStartInfo {
+							RedirectStandardInput = true,
+							FileName = "pbcopy"
 						}
-						getClipText = Clipboard.Contents.ToString ();
+					}) {
+						copy.Start ();
+						copy.StandardInput.Write (clipText);
+						copy.StandardInput.Close ();
+						copy.WaitForExit ();
+					}
+					getClipText = Clipboard.Contents.ToString ();
 
-					} else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) {
-						if (Is_WSL_Platform ()) {
-							try {
-								using (Process bash = new Process {
-									StartInfo = new ProcessStartInfo {
-										FileName = "powershell.exe",
-										Arguments = $"-noprofile -command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
-									}
-								}) {
-									bash.Start ();
-									bash.WaitForExit ();
+				} else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) {
+					if (Is_WSL_Platform ()) {
+						try {
+							using (Process bash = new Process {
+								StartInfo = new ProcessStartInfo {
+									FileName = "powershell.exe",
+									Arguments = $"-noprofile -command \"Set-Clipboard -Value \\\"{clipText}\\\"\""
 								}
-
-								//using (Process clipExe = new Process {
-								//	StartInfo = new ProcessStartInfo {
-								//		RedirectStandardInput = true,
-								//		FileName = "clip.exe"
-								//	}
-								//}) {
-								//	clipExe.Start ();
-								//	clipExe.StandardInput.Write (clipText);
-								//	clipExe.StandardInput.Close ();
-								//	clipExe.WaitForExit ();
-								//	//var result = clipExe.WaitForExit (500);
-								//	//if (result) {
-								//	//	clipExe.WaitForExit ();
-								//	//}
-								//}
-							} catch {
-								exit = true;
-							}
-							if (!exit) {
-								getClipText = Clipboard.Contents.ToString ();
+							}) {
+								bash.Start ();
+								bash.WaitForExit ();
 							}
-							Application.RequestStop ();
-							return;
-						}
-						if (exit = xclipExists () == false) {
-							// xclip doesn't exist then exit.
-							Application.RequestStop ();
-							return;
-						}
 
-						using (Process bash = new Process {
-							StartInfo = new ProcessStartInfo {
-								FileName = "bash",
-								Arguments = $"-c \"xclip -sel clip -i\"",
-								RedirectStandardInput = true,
-							}
-						}) {
-							bash.Start ();
-							bash.StandardInput.Write (clipText);
-							bash.StandardInput.Close ();
-							bash.WaitForExit ();
+							//using (Process clipExe = new Process {
+							//	StartInfo = new ProcessStartInfo {
+							//		RedirectStandardInput = true,
+							//		FileName = "clip.exe"
+							//	}
+							//}) {
+							//	clipExe.Start ();
+							//	clipExe.StandardInput.Write (clipText);
+							//	clipExe.StandardInput.Close ();
+							//	clipExe.WaitForExit ();
+							//	//var result = clipExe.WaitForExit (500);
+							//	//if (result) {
+							//	//	clipExe.WaitForExit ();
+							//	//}
+							//}
+						} catch {
+							exit = true;
 						}
 						if (!exit) {
 							getClipText = Clipboard.Contents.ToString ();
 						}
+						Application.RequestStop ();
+						return;
+					}
+					if (exit = xclipExists () == false) {
+						// xclip doesn't exist then exit.
+						Application.RequestStop ();
+						return;
 					}
 
-					Application.RequestStop ();
-				};
-			}
+					using (Process bash = new Process {
+						StartInfo = new ProcessStartInfo {
+							FileName = "bash",
+							Arguments = $"-c \"xclip -sel clip -i\"",
+							RedirectStandardInput = true,
+						}
+					}) {
+						bash.Start ();
+						bash.StandardInput.Write (clipText);
+						bash.StandardInput.Close ();
+						bash.WaitForExit ();
+					}
+					if (!exit) {
+						getClipText = Clipboard.Contents.ToString ();
+					}
+				}
+
+				Application.RequestStop ();
+			};
 
 			Application.Run ();