Browse Source

Add unit tests for CSharpOutputVisitor.

Tried to fix ExternalException when accessing the clipboard.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@426 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
9a246da449
  1. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs
  2. 6
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/DisplayDefinition.cs
  3. 65
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs
  4. 11
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  5. 6
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs
  6. 120
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  7. 9
      src/Libraries/NRefactory/Test/Parser/Statements/LocalVariableDeclarationTests.cs
  8. 8
      src/Main/Base/Project/Src/Commands/EditCommands.cs
  9. 2
      src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs
  10. 2
      src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopAboutPanels.cs
  11. 8
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs
  12. 4
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs
  13. 2
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/ProjectNode.cs
  14. 6
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/SolutionFolderNode.cs
  15. 4
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/SolutionItemNode.cs
  16. 1
      src/Main/Core/Project/ICSharpCode.Core.csproj
  17. 61
      src/Main/Core/Project/Src/Util/ClipboardWrapper.cs
  18. 4
      src/Main/StartUp/Project/Dialogs/ExceptionBox.cs

2
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs

@ -22,7 +22,7 @@ namespace ResourceEditor @@ -22,7 +22,7 @@ namespace ResourceEditor
ResourceEditorControl editor = (ResourceEditorControl)window.ViewContent.Control;
if(editor.ResourceList.SelectedItems.Count > 0) {
Clipboard.SetDataObject(editor.ResourceList.SelectedItems[0].Text, true);
ClipboardWrapper.SetText(editor.ResourceList.SelectedItems[0].Text);
}
}
}

6
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/DisplayDefinition.cs

@ -154,7 +154,7 @@ namespace ResourceEditor @@ -154,7 +154,7 @@ namespace ResourceEditor
resourceEditor.ResourceList.Items.Remove(item);
}
resourceEditor.ResourceList.OnChanged();
Clipboard.SetDataObject(tmphash);
ClipboardWrapper.SetDataObject(tmphash);
}
public void Copy()
@ -168,7 +168,7 @@ namespace ResourceEditor @@ -168,7 +168,7 @@ namespace ResourceEditor
object resourceValue = GetClonedResource(resourceEditor.ResourceList.Resources[item.Text].ResourceValue);
tmphash.Add(item.Text, resourceValue); // copy a clone to clipboard
}
Clipboard.SetDataObject(tmphash);
ClipboardWrapper.SetDataObject(tmphash);
}
public void Paste()
@ -177,7 +177,7 @@ namespace ResourceEditor @@ -177,7 +177,7 @@ namespace ResourceEditor
return;
}
IDataObject dob = Clipboard.GetDataObject();
IDataObject dob = ClipboardWrapper.GetDataObject();
if (dob.GetDataPresent(typeof(Hashtable).FullName)) {
Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable));

65
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs

@ -44,7 +44,11 @@ namespace ICSharpCode.TextEditor @@ -44,7 +44,11 @@ namespace ICSharpCode.TextEditor
public bool EnablePaste {
get {
return Clipboard.ContainsText();
try {
return Clipboard.ContainsText();
} catch (ExternalException) {
return false;
}
}
}
@ -76,24 +80,15 @@ namespace ICSharpCode.TextEditor @@ -76,24 +80,15 @@ namespace ICSharpCode.TextEditor
string str = textArea.SelectionManager.SelectedText;
if (str.Length > 0) {
// paste to clipboard
// BIG HACK: STRANGE EXTERNAL EXCEPTION BUG WORKAROUND
for (int i = 0; i < 5; ++i) {
try {
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.UnicodeText, true, str);
// Default has no highlighting, therefore we don't need RTF output
if (textArea.Document.HighlightingStrategy.Name != "Default") {
dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
}
OnCopyText(new CopyTextEventArgs(str));
Clipboard.SetDataObject(dataObject, true);
return true;
} catch (ExternalException) {
}
Thread.Sleep(100);
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.UnicodeText, true, str);
// Default has no highlighting, therefore we don't need RTF output
if (textArea.Document.HighlightingStrategy.Name != "Default") {
dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
}
OnCopyText(new CopyTextEventArgs(str));
Clipboard.SetDataObject(dataObject, true, 50, 50);
return true;
}
return false;
}
@ -117,22 +112,28 @@ namespace ICSharpCode.TextEditor @@ -117,22 +112,28 @@ namespace ICSharpCode.TextEditor
public void Paste(object sender, EventArgs e)
{
// Clipboard.GetDataObject may throw an exception...
try {
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.UnicodeText)) {
string text = (string)data.GetData(DataFormats.UnicodeText);
if (text.Length > 0) {
int redocounter = 0;
if (textArea.SelectionManager.HasSomethingSelected) {
Delete(sender, e);
redocounter++;
for (int i = 0;; i++) {
try {
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.UnicodeText)) {
string text = (string)data.GetData(DataFormats.UnicodeText);
if (text.Length > 0) {
int redocounter = 0;
if (textArea.SelectionManager.HasSomethingSelected) {
Delete(sender, e);
redocounter++;
}
textArea.InsertString(text);
if (redocounter > 0) {
textArea.Document.UndoStack.UndoLast(redocounter + 1); // redo the whole operation
}
}
textArea.InsertString(text);
if (redocounter > 0) {
textArea.Document.UndoStack.UndoLast(redocounter + 1); // redo the whole operation
} }
}
return;
} catch (ExternalException) {
// GetDataObject does not provide RetryTimes parameter
if (i > 5) throw;
}
} catch (ExternalException) {
}
}

11
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -154,7 +154,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -154,7 +154,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (this.prettyPrintOptions.SpacesWithinBrackets) {
outputFormatter.Space();
}
for (int j = 1; j < typeReference.RankSpecifier[i]; ++j) {
for (int j = 0; j < typeReference.RankSpecifier[i]; ++j) {
outputFormatter.PrintToken(Tokens.Comma);
}
if (this.prettyPrintOptions.SpacesWithinBrackets) {
@ -1827,6 +1827,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1827,6 +1827,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
}
break;
case BinaryOperatorType.NullCoalescing:
if (prettyPrintOptions.AroundRelationalOperatorParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.DoubleQuestion);
if (prettyPrintOptions.AroundRelationalOperatorParentheses) {
outputFormatter.Space();
}
break;
default:
errors.Error(-1, -1, String.Format("Unknown binary operator {0}", binaryOperatorExpression.Op));
return null;

6
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs

@ -119,6 +119,12 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -119,6 +119,12 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
/// <summary>
/// The rank of the array type.
/// For "object[]", this is { 0 }; for "object[,]", it is {1}.
/// For "object[,][,,][]", it is {1, 2, 0}.
/// For non-array types, this property is null or {}.
/// </summary>
public int[] RankSpecifier {
get {
return rankSpecifier;

120
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.IO;
using NUnit.Framework;
using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Parser.AST;
using ICSharpCode.NRefactory.PrettyPrinter;
namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
@ -16,24 +17,113 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -16,24 +17,113 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
[TestFixture]
public class CSharpOutputTest
{
void TestProgram(string program)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
outputVisitor.Visit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));
}
string StripWhitespace(string text)
{
return text.Trim().Replace("\t", "").Replace("\r", "").Replace("\n", " ").Replace(" ", " ");
}
void TestTypeMember(string program)
{
TestProgram("class A { " + program + " }");
}
void TestStatement(string statement)
{
TestTypeMember("void Method() { " + statement + " }");
}
void TestExpression(string expression)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(expression + ";"));
Expression e = parser.ParseExpression();
Assert.AreEqual("", parser.Errors.ErrorOutput);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
e.AcceptVisitor(outputVisitor, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text));
}
[Test]
public void Field()
{
TestTypeMember("int a;");
}
[Test]
public void Method()
{
TestTypeMember("void Method() { }");
}
[Test]
public void PartialModifier()
{
TestProgram("public partial class Foo { }");
}
[Test]
public void GenericClassDefinition()
{
TestProgram("public class Foo<T> where T : IDisposable, ICloneable { }");
}
[Test]
public void GenericClassDefinitionWithBaseType()
{
TestProgram("public class Foo<T> : BaseClass where T : IDisposable, ICloneable { }");
}
[Test]
public void CSharpOutputTest1()
public void GenericMethodDefinition()
{
// TODO:
// string program = "public class Test" + Environment.NewLine +
// "{" + Environment.NewLine +
// "\tvoid A()" + Environment.NewLine +
// "\t{" + Environment.NewLine +
// "\t\tstring test = 546.ToString();" + Environment.NewLine +
// "\t}" + Environment.NewLine +
// "}" + Environment.NewLine;
// IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(program));
// parser.Parse();
// CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
// outputVisitor.Visit(parser.CompilationUnit, null);
//
// Assert.AreEqual(program, outputVisitor.Text);
TestTypeMember("public void Foo<T>(T arg) where T : IDisposable, ICloneable { }");
}
[Test]
public void ArrayRank()
{
TestStatement("object[,,] a = new object[1, 2, 3];");
}
[Test]
public void ArrayInitializer()
{
TestStatement("object[] a = new object[] {1, 2, 3};");
}
[Test]
public void Assignment()
{
TestExpression("a = b");
}
[Test]
public void GenericMethodInvocation()
{
TestExpression("GenericMethod<T>(arg)");
}
[Test]
public void NullCoalescing()
{
TestExpression("a ?? b");
}
[Test]
public void SpecialIdentifierName()
{
TestExpression("@class");
}
}
}

9
src/Libraries/NRefactory/Test/Parser/Statements/LocalVariableDeclarationTests.cs

@ -58,8 +58,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -58,8 +58,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual("int", type.GenericTypes[0].Type);
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count);
Assert.IsFalse(type.GenericTypes[0].IsArrayType);
Assert.AreEqual(1, type.RankSpecifier.Length);
Assert.AreEqual(0, type.RankSpecifier[0]);
Assert.AreEqual(new int[] {0}, type.RankSpecifier);
}
[Test]
@ -73,8 +72,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -73,8 +72,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual("int", type.GenericTypes[0].Type);
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count);
Assert.IsFalse(type.IsArrayType);
Assert.AreEqual(1, type.GenericTypes[0].RankSpecifier.Length);
Assert.AreEqual(0, type.GenericTypes[0].RankSpecifier[0]);
Assert.AreEqual(new int[] {0}, type.GenericTypes[0].RankSpecifier);
}
[Test]
@ -240,8 +238,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -240,8 +238,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual("Integer", type.GenericTypes[0].Type);
Assert.AreEqual(0, type.GenericTypes[0].GenericTypes.Count);
Assert.IsFalse(type.GenericTypes[0].IsArrayType);
Assert.AreEqual(1, type.RankSpecifier.Length);
Assert.AreEqual(0, type.RankSpecifier[0]);
Assert.AreEqual(new int[] { 0 }, type.RankSpecifier);
}
[Test]

8
src/Main/Base/Project/Src/Commands/EditCommands.cs

@ -129,7 +129,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -129,7 +129,7 @@ namespace ICSharpCode.SharpDevelop.Commands
get { return comboBox.SelectionLength > 0; }
}
public bool EnablePaste {
get { return Clipboard.ContainsText(); }
get { return ClipboardWrapper.ContainsText; }
}
public bool EnableDelete {
get { return true; }
@ -137,9 +137,9 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -137,9 +137,9 @@ namespace ICSharpCode.SharpDevelop.Commands
public bool EnableSelectAll {
get { return comboBox.Text.Length > 0; }
}
public void Cut() { Clipboard.SetText(comboBox.SelectedText); comboBox.SelectedText = ""; }
public void Copy() { Clipboard.SetText(comboBox.SelectedText); }
public void Paste() { comboBox.SelectedText = Clipboard.GetText(); }
public void Cut() { ClipboardWrapper.SetText(comboBox.SelectedText); comboBox.SelectedText = ""; }
public void Copy() { ClipboardWrapper.SetText(comboBox.SelectedText); }
public void Paste() { comboBox.SelectedText = ClipboardWrapper.GetText(); }
public void Delete() { comboBox.SelectedText = ""; }
public void SelectAll() { comboBox.SelectAll(); }
}

2
src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs

@ -126,7 +126,7 @@ namespace ICSharpCode.SharpDevelop.Commands.TabStrip @@ -126,7 +126,7 @@ namespace ICSharpCode.SharpDevelop.Commands.TabStrip
{
IWorkbenchWindow window = Owner as IWorkbenchWindow;
if (window != null && window.ViewContent.FileName != null) {
Clipboard.SetDataObject(new DataObject(DataFormats.Text, window.ViewContent.FileName));
ClipboardWrapper.SetText(window.ViewContent.FileName);
}
}
}

2
src/Main/Base/Project/Src/Gui/Dialogs/SharpDevelopAboutPanels.cs

@ -140,7 +140,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -140,7 +140,7 @@ namespace ICSharpCode.SharpDevelop.Gui
versionInfo.Append(Environment.NewLine);
}
Clipboard.SetDataObject(new DataObject(System.Windows.Forms.DataFormats.Text, versionInfo.ToString()), true);
ClipboardWrapper.SetText(versionInfo.ToString());
}
// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER

8
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/DirectoryNode.cs

@ -405,7 +405,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -405,7 +405,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override bool EnablePaste {
get {
IDataObject dataObject = Clipboard.GetDataObject();
IDataObject dataObject = ClipboardWrapper.GetDataObject();
if (dataObject == null) {
return false;
}
@ -429,7 +429,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -429,7 +429,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Paste()
{
IDataObject dataObject = Clipboard.GetDataObject();
IDataObject dataObject = ClipboardWrapper.GetDataObject();
if (dataObject.GetDataPresent(DataFormats.FileDrop)) {
string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
@ -472,7 +472,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -472,7 +472,7 @@ namespace ICSharpCode.SharpDevelop.Project
}
public override void Copy()
{
Clipboard.SetDataObject(new DataObject(typeof(DirectoryNode).ToString(), new FileOperationClipboardObject(Directory, false)), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(DirectoryNode).ToString(), new FileOperationClipboardObject(Directory, false)));
}
public override bool EnableCut {
@ -484,7 +484,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -484,7 +484,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Cut()
{
DoPerformCut = true;
Clipboard.SetDataObject(new DataObject(typeof(DirectoryNode).ToString(), new FileOperationClipboardObject(Directory, true)), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(DirectoryNode).ToString(), new FileOperationClipboardObject(Directory, true)));
}
#endregion

4
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/FileNode.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -185,7 +185,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Copy()
{
Clipboard.SetDataObject(new DataObject(typeof(FileNode).ToString(), new FileOperationClipboardObject(FileName, false)), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(FileNode).ToString(), new FileOperationClipboardObject(FileName, false)));
}
public override bool EnableCut {
@ -197,7 +197,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -197,7 +197,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Cut()
{
DoPerformCut = true;
Clipboard.SetDataObject(new DataObject(typeof(FileNode).ToString(), new FileOperationClipboardObject(FileName, true)), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(FileNode).ToString(), new FileOperationClipboardObject(FileName, true)));
}

2
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/ProjectNode.cs

@ -119,7 +119,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -119,7 +119,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Cut()
{
DoPerformCut = true;
Clipboard.SetDataObject(new DataObject(typeof(ISolutionFolder).ToString(), project.IdGuid), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(ISolutionFolder).ToString(), project.IdGuid));
}
// Paste is inherited from DirectoryNode.

6
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/SolutionFolderNode.cs

@ -146,12 +146,12 @@ namespace ICSharpCode.SharpDevelop.Project @@ -146,12 +146,12 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Cut()
{
DoPerformCut = true;
Clipboard.SetDataObject(new DataObject(typeof(ISolutionFolder).ToString(), folder.IdGuid), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(ISolutionFolder).ToString(), folder.IdGuid));
}
public static bool DoEnablePaste(ISolutionFolderNode container)
{
IDataObject dataObject = Clipboard.GetDataObject();
IDataObject dataObject = ClipboardWrapper.GetDataObject();
if (dataObject == null) {
return false;
}
@ -166,7 +166,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -166,7 +166,7 @@ namespace ICSharpCode.SharpDevelop.Project
public static void DoPaste(ISolutionFolderNode folderNode)
{
ExtTreeNode folderTreeNode = (ExtTreeNode)folderNode;
IDataObject dataObject = Clipboard.GetDataObject();
IDataObject dataObject = ClipboardWrapper.GetDataObject();
if (dataObject.GetDataPresent(typeof(ISolutionFolder).ToString())) {
string guid = dataObject.GetData(typeof(ISolutionFolder).ToString()).ToString();

4
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/SolutionItemNode.cs

@ -101,7 +101,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -101,7 +101,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Copy()
{
DoPerformCut = true;
Clipboard.SetDataObject(new DataObject(typeof(SolutionItemNode).ToString(), new FileOperationClipboardObject(Path.Combine(Solution.Directory, item.Name), false)), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(SolutionItemNode).ToString(), new FileOperationClipboardObject(Path.Combine(Solution.Directory, item.Name), false)));
}
public override bool EnableCut {
@ -113,7 +113,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -113,7 +113,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override void Cut()
{
DoPerformCut = true;
Clipboard.SetDataObject(new DataObject(typeof(SolutionItemNode).ToString(), new FileOperationClipboardObject(Path.Combine(Solution.Directory, item.Name), true)), true);
ClipboardWrapper.SetDataObject(new DataObject(typeof(SolutionItemNode).ToString(), new FileOperationClipboardObject(Path.Combine(Solution.Directory, item.Name), true)));
}
#endregion

1
src/Main/Core/Project/ICSharpCode.Core.csproj

@ -136,6 +136,7 @@ @@ -136,6 +136,7 @@
<Compile Include="Src\AddInTree\AddIn\IBuildItemsModifier.cs" />
<Compile Include="Src\AddInTree\AddIn\DefaultDoozers\IncludeDoozer.cs" />
<Compile Include="Src\Services\LoggingService\LoggingService.cs" />
<Compile Include="Src\Util\ClipboardWrapper.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Src\Services\LoggingService" />

61
src/Main/Core/Project/Src/Util/ClipboardWrapper.cs

@ -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);
}
}
}

4
src/Main/StartUp/Project/Dialogs/ExceptionBox.cs

@ -72,9 +72,7 @@ namespace ICSharpCode.SharpDevelop @@ -72,9 +72,7 @@ namespace ICSharpCode.SharpDevelop
void CopyInfoToClipboard()
{
if (copyErrorCheckBox.Checked) {
try {
Clipboard.SetDataObject(new DataObject(System.Windows.Forms.DataFormats.Text, getClipboardString()), true);
} catch (Exception) {}
ClipboardWrapper.SetText(getClipboardString());
}
}

Loading…
Cancel
Save