Browse Source
Tried to fix ExternalException when accessing the clipboard. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@426 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
18 changed files with 242 additions and 79 deletions
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Daniel Grunwald |
||||
* Date: 24.08.2005 |
||||
* Time: 11:38 |
||||
*/ |
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <summary>
|
||||
/// Helper class to access the clipboard without worrying about ExternalExceptions
|
||||
/// </summary>
|
||||
public static class ClipboardWrapper |
||||
{ |
||||
public static bool ContainsText { |
||||
get { |
||||
try { |
||||
return Clipboard.ContainsText(); |
||||
} catch (ExternalException) { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static string GetText() |
||||
{ |
||||
// retry 2 times should be enough for read access
|
||||
try { |
||||
return Clipboard.GetText(); |
||||
} catch (ExternalException) { |
||||
return Clipboard.GetText(); |
||||
} |
||||
} |
||||
|
||||
public static void SetText(string text) |
||||
{ |
||||
DataObject data = new DataObject(); |
||||
data.SetData(DataFormats.UnicodeText, true, text); |
||||
SetDataObject(data); |
||||
} |
||||
|
||||
public static IDataObject GetDataObject() |
||||
{ |
||||
// retry 2 times should be enough for read access
|
||||
try { |
||||
return Clipboard.GetDataObject(); |
||||
} catch (ExternalException) { |
||||
return Clipboard.GetDataObject(); |
||||
} |
||||
} |
||||
|
||||
public static void SetDataObject(object data) |
||||
{ |
||||
Clipboard.SetDataObject(data, true, 50, 50); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue