コード例 #1
0
        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;
        }
コード例 #2
0
        public int CompareTo(object other)
        {
            ClipViewModel otherVM = other as ClipViewModel;

            if (otherVM == null)
            {
                return(1);
            }

            return(Clip.CompareTo(otherVM.Clip));
        }