public bool AddClip(Clipboard.Clip clip) { // Check if a clip with the same content exists in the last clips. var equalClips = Clips.Take(10).Where(vm => vm.Clip.Content == clip.Content); if (equalClips.Count() > 0) { // If a clip with the same content already exists, just update the creation time. // TODO: Possibly refresh list view to push clip to top. equalClips.First().Clip.Created = DateTime.Now; return false; } var viewModel = new ClipViewModel(clip); viewModel.PropertyChanged += OnClipViewModelPropChanged; if (Clips.Count >= ClipLimit && ClipLimit > 0) { // If the limit is reached, throw out the oldest one. // Make sure it is not pinned. var first = Clips.Where((c) => !c.Pinned).First(); Clips.Remove(first); } Clips.Add(viewModel); return true; }
public MockClipList() { AddClip(new Clipboard.Clip("AlternationCount=\"{Binding Items.Count, RelativeSource={RelativeSource Self}}\"")); var pinnedClip = new Clipboard.Clip("rgba(255, 2, 50, .3)"); var clipVM = new ClipViewModel(pinnedClip); clipVM.Pinned = true; Clips.Add(clipVM); AddClip(new Clipboard.Clip("#0bb")); }
public ClipViewModel(Clipboard.Clip clip) { this.Clip = clip; ResetRichTitle(); }