public void Set_EventsRaisedWithCorrectArgumentsAndItemSet() { int index = 0, newValue = 3, previousValue = 1; var subject = new NotifyingList <int>(); subject.Setting += (sender, e) => { Assert.That(e.Index, Is.EqualTo(index)); Assert.That(e.Value, Is.EqualTo(previousValue)); Assert.That(e.NewValue, Is.EqualTo(newValue)); Assert.That(e.IsCancelled, Is.False); }; subject.Set += (sender, e) => { Assert.That(e.Index, Is.EqualTo(index)); Assert.That(e.OldValue, Is.EqualTo(previousValue)); Assert.That(e.Value, Is.EqualTo(newValue)); }; subject.Add(previousValue); subject[index] = newValue; Assert.That(subject.Count, Is.EqualTo(1)); Assert.That(subject[index], Is.EqualTo(newValue)); }
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; } }
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); }
/// <summary> /// Creates a texture from file. If it already exists, /// returns the existing texture ID. /// /// Additionally, the internal texture will be loaded with the /// provided display quality, which defines how the texture will be /// rescaled internally. /// </summary> /// <param name="filename"></param> /// <param name="displayQuality"></param> /// <returns></returns> public int CreateTexture(string filename, float displayQuality) { if (Otter.Interface.Graphics.Instance == null) { return(-1); } TextureInfo textureInfo = null; object lockObj = new System.Object(); lock (lockObj) { string texturePath = filename; // Convert to a relative path if necessary if (System.IO.Path.IsPathRooted(filename)) { texturePath = Utils.GetRelativePath(GUIProject.CurrentProject.ProjectDirectory, texturePath); } // See if this texture has already been recorded int maxID = 0; foreach (TextureInfo info in mTextures) { if (info.Filename == texturePath) { textureInfo = info; break; } if (info.ID > maxID) { maxID = info.ID; } } // If the texture has not been recorded, do so now. if (textureInfo == null) { // Open succeeded, now record the info. textureInfo = new TextureInfo(); textureInfo.ID = maxID + 1; textureInfo.Filename = texturePath; mTextures.Add(textureInfo); } } textureInfo.DisplayQuality = displayQuality; textureInfo.Load(); return(textureInfo.ID); }
public void Add_CanCancelAddition() { bool insertedRaised = false; var subject = new NotifyingList <int>(); subject.Inserting += ((sender, e) => e.Cancel()); subject.Inserted += (sender, args) => insertedRaised = true; subject.Add(3); Assert.That(insertedRaised, Is.False); }
public void Add_EventsRaised() { bool insertingRaised = false, insertedRaised = false; var subject = new NotifyingList <int>(); subject.Inserting += (sender, args) => insertingRaised = true; subject.Inserted += (sender, args) => insertedRaised = true; subject.Add(3); Assert.That(insertingRaised, Is.True); Assert.That(insertedRaised, Is.True); }
public CommanderTool(Main main) : base(main) { Text = "Act"; Panel = new TableLayoutPanel(); Panel.Dock = DockStyle.Fill; Panel.BackColor = Color.White; Panel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; Controls.Add(Panel); InputBox = new TextBox(); InputBox.Dock = DockStyle.Top; InputBox.Font = Main.Consolas975; InputBox.TextChanged += (tcs, tca) => { ApplyFilter(); }; Panel.Controls.Add(InputBox); InternalList = new NotifyingList <Command>(); InternalList.ItemAdded += (ias, iaa) => BindCommandToListView(iaa.Item); InternalList.ItemRemoved += (ias, iaa) => UnbindCommandToListView(iaa.Item); main.Commands.ItemAdded += (ias, iaa) => InternalList.Add(iaa.Item); main.Commands.ItemRemoved += (ias, iaa) => InternalList.Remove(iaa.Item); foreach (var it in main.Commands) { InternalList.Add(it); } main.HierarchyChanged += (s, a) => { main.Hierarchy.SelectedNodeChanged += Hierarchy_SelectedItemChanged; }; }
public void Set_EventsRaised() { bool settingRaised = false, setRaised = false; var subject = new NotifyingList <int>(); subject.Setting += (sender, args) => settingRaised = true; subject.Set += (sender, args) => setRaised = true; subject.Add(1); subject[0] = 3; Assert.That(settingRaised, Is.True); Assert.That(setRaised, Is.True); }
public void Add_EventsRaisedWithCorrectArgumentsAndItemAdded() { int index = 0, item = 3; var subject = new NotifyingList <int>(); subject.Inserting += (sender, e) => { Assert.That(e.Index, Is.EqualTo(index)); Assert.That(e.Value, Is.EqualTo(item)); Assert.That(e.IsCancelled, Is.False); }; subject.Inserted += (sender, e) => { Assert.That(e.Index, Is.EqualTo(index)); Assert.That(e.Value, Is.EqualTo(item)); }; subject.Add(item); Assert.That(subject.Count, Is.EqualTo(1)); Assert.That(subject[index], Is.EqualTo(item)); }