Exemple #1
0
        private void _OnNotificationsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (ServiceProvider.ViewManager == null || ServiceProvider.ViewManager.Notifications == null)
            {
                return;
            }

            _currentNotifications.Clear();
            var notificationTaskList = new List <JumpItem>();

            foreach (Notification notification in from n in ServiceProvider.ViewManager.Notifications orderby n.Created ascending select n)
            {
                _currentNotifications.Add(notification);

                string argument = null;

                // Get the default URL from the notification.
                var htc = new HyperlinkTextContent {
                    Text = notification.Title
                };
                Uri notifyUri = htc.DefaultUri;
                if (notifyUri != null)
                {
                    argument = "-uri:" + notifyUri.OriginalString;
                }

                string title = _GetFirstLine(notification.TitleText);

                if (title != null)
                {
                    notificationTaskList.Add(new JumpTask
                    {
                        Arguments      = argument,
                        CustomCategory = notification is FriendRequestNotification ? "Friend Requests" : "Notifications",
                        // Shell silently fails to accept multi-line JumpTasks so we need to trim the strings ourselves.
                        Description = _GetFirstLine(notification.DescriptionText),
                        Title       = title,
                    });
                }
            }

            JumpList jumpList = JumpList.GetJumpList(Application.Current);

            Assert.IsNotNull(jumpList);
            jumpList.JumpItems.RemoveAll(item => item.CustomCategory == "Notifications");
            jumpList.JumpItems.RemoveAll(item => item.CustomCategory == "Friend Requests");
            jumpList.JumpItems.AddRange(notificationTaskList);

            try
            {
                jumpList.JumpItemsRemovedByUser += _OnJumpItemsRemovedByUser;
                jumpList.Apply();
            }
            finally
            {
                jumpList.JumpItemsRemovedByUser -= _OnJumpItemsRemovedByUser;
            }
        }
        public void Clear_EventsRaisedWithCorrectArgumentsAndItemAdded()
        {
            var subject = new NotifyingList <int>();

            subject.Clearing += ((sender, e) => Assert.That(e.IsCancelled, Is.False));

            subject.Cleared += (sender, args) => { };

            subject.Clear();
            Assert.That(subject.Count, Is.EqualTo(0));
        }
        public void Clear_CanCancelClearance()
        {
            bool clearedRaised = false;

            var subject = new NotifyingList <int>();

            subject.Clearing += ((sender, e) => e.Cancel());

            subject.Cleared += (sender, args) => clearedRaised = true;

            subject.Clear();
            Assert.That(clearedRaised, Is.False);
        }
        public void Clear_EventsRaised()
        {
            bool clearingRaised = false, clearedRaised = false;

            var subject = new NotifyingList <int>();

            subject.Clearing += (sender, args) => clearingRaised = true;
            subject.Cleared  += (sender, args) => clearedRaised = true;

            subject.Clear();
            Assert.That(clearingRaised, Is.True);
            Assert.That(clearedRaised, Is.True);
        }
Exemple #5
0
        public NotificationsControl()
        {
            InitializeComponent();

            _currentNotifications = new NotifyingList <Notification>();
            _currentNotifications.ItemPropertyChanged += (sender, e) => this.Dispatcher.BeginInvoke((NotifyCollectionChangedEventHandler)_OnNotificationsChanged, this, null);

            CommandBindings.Add(new CommandBinding(CloseCommand, new ExecutedRoutedEventHandler((sender, e) => IsDisplayed = false)));

            Loaded   += (sender, e) => ServiceProvider.ViewManager.Notifications.CollectionChanged += _OnNotificationsChanged;
            Unloaded += (sender, e) =>
            {
                ServiceProvider.ViewManager.Notifications.CollectionChanged -= _OnNotificationsChanged;
                _currentNotifications.Clear();
            };
        }
Exemple #6
0
        void Hierarchy_SelectedItemChanged(object sender, HierarchyNode e)
        {
            InternalList.Clear();

            foreach (var it in Shell.Commands)
            {
                InternalList.Add(it);
            }
            foreach (var it in e.Commands)
            {
                InternalList.Add(it);
            }

            ApplyFilter();

            e.Commands.ItemAdded   += (ias, iaa) => InternalList.Add(iaa.Item);
            e.Commands.ItemRemoved += (ias, iaa) => InternalList.Remove(iaa.Item);
        }