Skip to content

Commit

Permalink
Added the property 'ObserveLastEntry' that enables/disables auto-pick…
Browse files Browse the repository at this point in the history
…ing of the last clipboard item once monitoring is enabled.
  • Loading branch information
Willy-Kimura committed Feb 23, 2019
1 parent 04833d9 commit 010f3b6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 38 deletions.
1 change: 1 addition & 0 deletions Assets/NuGet Package-2.0.7-brightgreen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/sharpclipboard-preview-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SharpClipboard
[![sc-nuget](/Assets/nuget-package-2.0.5-brightgreen.svg)](https://www.nuget.org/packages/SharpClipboard/) [![sc-donate](/Assets/Donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJ8D9CE8BWA3J&source=url)
[![sc-nuget](/Assets/nuget-package-2.0.7-brightgreen.svg)](https://www.nuget.org/packages/SharpClipboard/) [![sc-donate](/Assets/Donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJ8D9CE8BWA3J&source=url)

**SharpClipboard** is a clipboard-monitoring library for .NET that listens to the system's clipboard entries,
allowing developers to tap into the rich capabilities of determining the clipboard's contents at runtime.
Expand All @@ -12,7 +12,7 @@ Here's a screenshot and below a usage-preview of the library's features:
# Installation
To install via the NuGet Package Manager Console, type:

> `Install-Package SharpClipboard -Version 2.0.5`
> `Install-Package SharpClipboard -Version 2.0.7`
You can also [download](https://github.com/Willy-Kimura/SharpClipboard/releases/download/v2.0.5/SharpClipboard.dll) the assembly and add it to Visual Studio's Toolbox; plus not forgetting its [documentation](https://github.com/Willy-Kimura/SharpClipboard/releases/download/v2.0.5/SharpClipboard.xml).

Expand Down
2 changes: 2 additions & 0 deletions SharpCliboard.Tests/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions SharpClipboard/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.5.0")]
[assembly: AssemblyFileVersion("2.0.5.0")]
[assembly: AssemblyVersion("2.0.7.0")]
[assembly: AssemblyFileVersion("2.0.7.0")]
67 changes: 38 additions & 29 deletions SharpClipboard/SharpClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using System.Runtime.InteropServices;

using WK.Libraries.SharpClipboardNS.Views;
using System.Text;

namespace WK.Libraries.SharpClipboardNS
{
Expand Down Expand Up @@ -59,14 +58,10 @@ public SharpClipboard(IContainer container)
#endregion

#region Fields

private bool _monitorClipboard;
private bool _observeLastEntry;

private string _clipboardText;
private string _clipboardFile;
private List<string> _clipboardFiles = new List<string>();

private Image _clipboardImage;
private Timer _timer = new Timer();
private ClipboardHandle _handle = new ClipboardHandle();
private ObservableDataFormats _observableFormats = new ObservableDataFormats();
Expand Down Expand Up @@ -104,7 +99,7 @@ public enum ContentTypes
#endregion

#region Properties

#region Browsable

/// <summary>
Expand All @@ -125,6 +120,28 @@ public bool MonitorClipboard
}
}

/// <summary>
/// When set to true, the last cut/copied clipboard item will
/// not be auto-picked once monitoring is enabled. However when
/// set to false, the last cut/copied clipboard item will be
/// auto-picked once monitoring is enabled.
/// </summary>
[Category("#Clipboard: Behaviour")]
[Description("When set to true, the last cut/copied clipboard item will " +
"not be auto-picked once monitoring is enabled. However when " +
"set to false, the last cut/copied clipboard item will be " +
"auto-picked once monitoring is enabled.")]
public bool ObserveLastEntry
{
get { return _observeLastEntry; }
set {

_observeLastEntry = value;
ObserveLastEntryChanged?.Invoke(this, EventArgs.Empty);

}
}

/// <summary>
/// Gets or sets the data formats that will be observed
/// or monitored when cut/copy actions are triggered.
Expand Down Expand Up @@ -163,41 +180,25 @@ public ObservableDataFormats ObservableFormats
/// Gets the currently cut/copied clipboard text.
/// </summary>
[Browsable(false)]
public string ClipboardText
{
get { return _clipboardText; }
internal set { _clipboardText = value; }
}
public string ClipboardText { get; internal set; }

/// <summary>
/// Gets the currently cut/copied clipboard file-path.
/// </summary>
[Browsable(false)]
public string ClipboardFile
{
get { return _clipboardFile; }
internal set { _clipboardFile = value; }
}
public string ClipboardFile { get; internal set; }

/// <summary>
/// Gets the currently cut/copied clipboard file-paths.
/// </summary>
[Browsable(false)]
public List<string> ClipboardFiles
{
get { return _clipboardFiles; }
internal set { _clipboardFiles = value; }
}
public List<string> ClipboardFiles { get; internal set; } = new List<string>();

/// <summary>
/// Gets the currently cut/copied clipboard image.
/// </summary>
[Browsable(false)]
public Image ClipboardImage
{
get { return _clipboardImage; }
internal set { _clipboardImage = value; }
}
public Image ClipboardImage { get; internal set; }

#endregion

Expand All @@ -214,8 +215,9 @@ private void SetDefaults()
_timer.Enabled = true;
_timer.Interval = 1000;
_timer.Tick += OnLoad;

MonitorClipboard = true;
ObserveLastEntry = true;
}

[DllImport("user32.dll")]
Expand Down Expand Up @@ -295,6 +297,13 @@ internal void Invoke(object content, ContentTypes type, SourceApplication source
[Description("Occurs whenever the allowed observable formats have been changed.")]
public event EventHandler<EventArgs> ObservableFormatsChanged = null;

/// <summary>
/// Occurs whenever the 'ObserveLastEntry' property has been changed.
/// </summary>
[Category("#Clipboard: Events")]
[Description("Occurs whenever the allowed observable formats have been changed.")]
public event EventHandler<EventArgs> ObserveLastEntryChanged = null;

#endregion

#region Event Arguments
Expand Down
38 changes: 33 additions & 5 deletions SharpClipboard/Views/ClipboardHandle.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
/*
* The SharpClipboard Handle.
* ----------------------------------------
* ---------------------------------------+
* Please preserve this window.
* It acts as the message-processing
* handle with regards to the clipboard.
*
* The window however will not be visible
* to the users both via the Taskbar or
* the Task Manager so don't you worry :)
* ----------------------------------------
* ---------------------------------------+
*
*/


using System;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace WK.Libraries.SharpClipboardNS.Views
{
/// <summary>
/// This window acts as a handle to the clipboard-monitoring process and
/// thus will be launched in the background once the component has started
/// the monitoring service. However, it won't be visible to anyone even via
/// the Task Manager.
/// </summary>
public partial class ClipboardHandle : Form
{
#region Constructor
Expand All @@ -41,6 +47,8 @@ public ClipboardHandle()
const int WM_DRAWCLIPBOARD = 0x0308;
const int WM_CHANGECBCHAIN = 0x030D;

private bool _ready;

private string _processName = string.Empty;
private string _executableName = string.Empty;
private string _executablePath = string.Empty;
Expand All @@ -49,12 +57,31 @@ public ClipboardHandle()

#region Properties

/// <summary>
/// Checks if the handle is ready to monitor the system clipboard.
/// It is used to provide a final value for use whenever the property
/// 'ObserveLastEntry' is enabled.
/// </summary>
[Browsable(false)]
internal bool Ready
{
get {

if (SharpClipboardInstance.ObserveLastEntry)
_ready = true;

return _ready;

}
set { _ready = value; }
}

/// <summary>
/// Gets or sets an active <see cref="SharpClipboard"/> instance
/// for use when managing the current clipboard handle.
/// </summary>
[Browsable(false)]
public SharpClipboard SharpClipboardInstance { get; set; }
internal SharpClipboard SharpClipboardInstance { get; set; }

#endregion

Expand Down Expand Up @@ -111,7 +138,7 @@ protected override void WndProc(ref Message m)
case WM_DRAWCLIPBOARD:

// If clipboard-monitoring is enabled, proceed to listening.
if (SharpClipboardInstance.MonitorClipboard)
if (Ready && SharpClipboardInstance.MonitorClipboard)
{
IDataObject dataObj = Clipboard.GetDataObject();

Expand Down Expand Up @@ -271,6 +298,7 @@ private void OnLoad(object sender, EventArgs e)
{
// Start listening for clipboard changes.
_chainedWnd = SetClipboardViewer(this.Handle);
Ready = true;
}

private void OnFormClosing(object sender, FormClosingEventArgs e)
Expand Down

0 comments on commit 010f3b6

Please sign in to comment.