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); }
private void OnClipboardObjectPinStateChanged(object sender, bool isPinned) { if (isPinned) { ClipboardObjectViewModel clipboardObject = ClipboardObjects.FirstOrDefault(i => i.Equals(sender)); ClipboardObjects.Remove(clipboardObject); SavedClipboardObjects.Add(clipboardObject); SavePinnedItem(clipboardObject); } else { ClipboardObjectViewModel savedClipboardObject = SavedClipboardObjects.FirstOrDefault(i => i.Equals(sender)); int index = SavedClipboardObjects.IndexOf(savedClipboardObject); SavedClipboardObjects.Remove(savedClipboardObject); ClipboardObjects.Add(savedClipboardObject); DeletePinnedItem(index); } }
private void SavePinnedItem(ClipboardObjectViewModel clipboardObject) { RegistryHelper.Instance.SubKey(Name).Set($"{PINNED_ENTRY_KEY}{SavedClipboardObjects.IndexOf(clipboardObject)}", (string)clipboardObject.Data); }
private void PreviewKeyDown(KeyEventArgs args) { switch (args.Key) { case Key.Escape: { Close(); break; } case Key.Down: { if (!ClipboardManager.ClipboardObjects.Any(i => i.IsEnabled)) { break; } ClipboardObjectViewModel selectedItem = ClipboardManager.ClipboardObjects.FirstOrDefault(i => i.IsSelected); if (selectedItem == null) { ClipboardObjectViewModel firstItem = ClipboardManager.ClipboardObjects.FirstOrDefault(i => i.IsEnabled); if (firstItem == null) { break; } firstItem.IsSelected = true; } else { int indexOfSelectedItem = ClipboardManager.ClipboardObjects.IndexOf(selectedItem); if (indexOfSelectedItem + 2 <= ClipboardManager.ClipboardObjects.Count) { ClipboardObjectViewModel newSelectedItem = ClipboardManager.ClipboardObjects[indexOfSelectedItem + 1]; newSelectedItem.IsSelected = true; } } break; } case Key.Up: { if (!ClipboardManager.ClipboardObjects.Any(i => i.IsEnabled)) { break; } ClipboardObjectViewModel selectedItem = ClipboardManager.ClipboardObjects.FirstOrDefault(i => i.IsSelected); if (selectedItem == null) { break; } int indexOfSelectedItem = ClipboardManager.ClipboardObjects.IndexOf(selectedItem); if (indexOfSelectedItem > 0) { ClipboardObjectViewModel newSelectedItem = ClipboardManager.ClipboardObjects[indexOfSelectedItem - 1]; newSelectedItem.IsSelected = true; } break; } case Key.Enter: { ClipboardObjectViewModel selectedItem = ClipboardManager.ClipboardObjects.FirstOrDefault(i => i.IsSelected); selectedItem?.ClickedCommand.Execute(null); break; } } }