-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add button to copy c# code to clipboard
- Loading branch information
1 parent
a759e7c
commit 5ba5504
Showing
8 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System.Reflection; | ||
|
||
[assembly: AssemblyVersion("1.2.1.0")] | ||
[assembly: AssemblyFileVersion("1.2.1.0")] | ||
[assembly: AssemblyVersion("1.2.1.1")] | ||
[assembly: AssemblyFileVersion("1.2.1.1")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace pseudocode_ide | ||
{ | ||
// from https://stackoverflow.com/questions/899350/how-do-i-copy-the-contents-of-a-string-to-the-clipboard-in-c | ||
|
||
public class SetClipboardHelper : StaHelper | ||
{ | ||
readonly string _format; | ||
readonly object _data; | ||
|
||
public SetClipboardHelper(string format, object data) | ||
{ | ||
_format = format; | ||
_data = data; | ||
} | ||
|
||
protected override void Work() | ||
{ | ||
var obj = new System.Windows.Forms.DataObject( | ||
_format, | ||
_data | ||
); | ||
|
||
Clipboard.SetDataObject(obj, true); | ||
} | ||
} | ||
|
||
public abstract class StaHelper | ||
{ | ||
readonly ManualResetEvent _complete = new ManualResetEvent(false); | ||
|
||
public void Go() | ||
{ | ||
var thread = new Thread(new ThreadStart(DoWork)) | ||
{ | ||
IsBackground = true, | ||
}; | ||
thread.SetApartmentState(ApartmentState.STA); | ||
thread.Start(); | ||
} | ||
|
||
// Thread entry method | ||
private void DoWork() | ||
{ | ||
try | ||
{ | ||
_complete.Reset(); | ||
Work(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (DontRetryWorkOnFailed) | ||
throw; | ||
else | ||
{ | ||
try | ||
{ | ||
Thread.Sleep(1000); | ||
Work(); | ||
} | ||
catch | ||
{ | ||
// ex from first exception | ||
Debug.WriteLine(ex); | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
_complete.Set(); | ||
} | ||
} | ||
|
||
public bool DontRetryWorkOnFailed { get; set; } | ||
|
||
// Implemented in base class to do actual work. | ||
protected abstract void Work(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters