/// <summary> /// Handles the duplicate logic between updating History/Favourites in gui /// </summary> /// <param name="dropDown">The dropdown object from the ToolStripMenuItem that uses this collection</param> /// <param name="e">The event args, to determine gui update behaviour</param> private void Update_History_Favourites_Menu(ToolStripDropDown dropDown, EntryRecordChanged e) { switch (e.AddRemUpd) { case ARU.Added: ToolStripMenuItem nextItem = new ToolStripMenuItem(e.EntryKey); nextItem.Click += MenuItem_Click; nextItem.Name = e.EntryKey; nextItem.Tag = e.Path; dropDown.Items.Add(nextItem); break; case ARU.Removed: dropDown.Items.RemoveByKey(e.EntryKey); break; case ARU.Updated: Console.WriteLine("Edited: {0}", e.EntryKey); dropDown.Items.RemoveByKey(e.EntryKey); ToolStripMenuItem updatedItem = new ToolStripMenuItem(e.EntryKey); updatedItem.Name = e.EntryKey; updatedItem.Click += MenuItem_Click; dropDown.Items.Add(updatedItem); break; case ARU.Cleared: ToolStripMenuItem editItem = (ToolStripMenuItem)dropDown.Items[0]; dropDown.Items.Clear(); dropDown.Items.Add(editItem); break; } }
/// <summary> /// Event called whenever a change to the list occurs /// </summary> /// <param name="title"></param> /// <param name="state"></param> /// <param name="WriteFile"></param> void OnEntryChanged(string title, ARU state, bool WriteFile) { EntryRecordChanged updatedEntry = new EntryRecordChanged(); updatedEntry.AddRemUpd = state; updatedEntry.EntryKey = title; updatedEntry.WriteFile = WriteFile; updatedEntry.Path = Filename; EventHandler <EntryRecordChanged> handler = EntryChanged; // handler has null deligate so no need to check if null handler(this, updatedEntry); if (WriteFile) { SerializeCollection(); } }
public void Test_EventExpectedParams_EntryRecord() { object sentFrom = null; EntryRecordChanged args = null; bool eventTriggered = false; EntryRecord h = new EntryRecord("Test", CompareBy.AlphabetTitle, false); h.EntryChanged += delegate(object sender, EntryRecordChanged e) { eventTriggered = true; sentFrom = sender; args = e; }; EntryElement e = new EntryElement("http://www.duckduckgo.com", "DuckDuckGo", CompareBy.AlphabetTitle); Assert.AreEqual(eventTriggered, false, "The event should not have triggered"); Assert.AreSame(sentFrom, null, "The event should be null"); Assert.AreSame(args, null, "The event should be null"); h.AddEntry(e, false); Assert.AreEqual(eventTriggered, true, "The event should have triggered"); Assert.AreSame(sentFrom, h, "h should be the sender object"); Assert.AreSame(args.EntryKey, e.Title, "Entry Key should be the title"); Assert.AreEqual(args.AddRemUpd, ARU.Added, "AddRemUpd should be Added"); Assert.AreEqual(args.Path, "Test", "Path should match path used when instantiating h"); Assert.AreEqual(args.WriteFile, false, "WriteFile should be false"); }
/// <summary> /// When history changed event gets thrown, this method updates the history collection in the gui /// </summary> /// <param name="e">EntryRecordChanged event parameter, indicates what kind of event got thrown & updates the list accordingly</param> private void History_Changed(object sender, EntryRecordChanged e) { ToolStripDropDown histDropdown = OpenHistory.DropDown; Update_History_Favourites_Menu(histDropdown, e); }
/// <summary> /// When favourites changed event gets thrown, this method updates the favourites collection in the gui /// </summary> /// <param name="e">EntryRecordChanged event parameter, indicates what kind of event got thrown & updates the list accordingly</param> private void Favourites_Changed(object sender, EntryRecordChanged e) { ToolStripDropDown favDropdown = OpenFavourites.DropDown; Update_History_Favourites_Menu(favDropdown, e); }