private void OnClipboardUpdate(object sender, EventArgs args) //TODO: Either remove entries with the same data or don't add on paste { object data = null; ClipboardObjectType type = ClipboardObjectType.NoData; if (ClipboardHelper.ContainsText(OPEN_CLIPBOARD_TRIES)) { data = ClipboardHelper.GetText(OPEN_CLIPBOARD_TRIES); type = ClipboardObjectType.String; } else if (ClipboardHelper.ContainsImage(OPEN_CLIPBOARD_TRIES)) { data = ClipboardHelper.GetImage(OPEN_CLIPBOARD_TRIES); type = ClipboardObjectType.Image; } if (data == null) { return; } if (SavedClipboardObjects.Any(i => i.Data.Equals(data))) { return; } var sameObjects = ClipboardObjects.Where(i => i.Data.Equals(data)).ToList(); foreach (var sameObject in sameObjects) { ClipboardObjects.Remove(sameObject); } ClipboardObjectViewModel noDataItem = ClipboardObjects.FirstOrDefault(i => i.ClipboardObjectType == ClipboardObjectType.NoData); if (noDataItem != null) { ClipboardObjects.Remove(noDataItem); } ClipboardObjects.Insert(0, new ClipboardObjectViewModel(data, type)); if (ClipboardObjects.Count <= ((ClipboardManagerSettings)Settings).MaxEntries) { return; } ClipboardObjectViewModel lastObject = ClipboardObjects.LastOrDefault(); if (lastObject == null) { return; } ClipboardObjects.Remove(lastObject); }
public ClipboardObjectViewModel(object data, ClipboardObjectType type) { Data = data; ClipboardObjectType = type; if (type == ClipboardObjectType.NoData) { IsEnabled = false; } if (type == ClipboardObjectType.String) { IsPinnable = true; } }