void listItem_Delete(object sender, RoutedEventArgs e, int soundID) { SOUND soundToRemove = (from s in soundData.SOUNDs where s.soundID == soundID select s).First(); soundData.SOUNDs.Remove(soundToRemove); soundData.SaveChanges(); RefreshSoundList(); RefreshKeyBindList(); RefreshOnScreenButtons(); }
private void listBoxQueuedSounds_Drop(object sender, System.Windows.DragEventArgs e) { if (e.Data.GetFormats().Count() > 0) { int searchID = (int)e.Data.GetData(typeof(int)); SOUND soundToAdd = (from s in soundData.SOUNDs where s.soundID == searchID select s).First(); soundManager.AddToMediaList(soundToAdd.name, soundToAdd.filePath); RefreshMediaQueueList(); } }
public void AddSound(string filePath, bool doBackup, bool isInitialLoad, int soundID = -1) { if (File.Exists(filePath) && soundManager.ValidateFile(filePath)) { int startAt = filePath.LastIndexOf("\\") + 1; int addedSoundID = soundID; string soundName = filePath.Substring(startAt, filePath.Length - startAt); if (!isInitialLoad) { SOUND newSound = new SOUND(); newSound.filePath = filePath; newSound.isBackup = doBackup; newSound.name = soundName; soundData.SOUNDs.Add(newSound); soundData.SaveChanges(); addedSoundID = (from s in soundData.SOUNDs orderby s.soundID descending select s.soundID).First(); } ListBoxItem newItem = new ListBoxItem(); newItem.Content = soundName; newItem.DataContext = addedSoundID; newItem.MouseDoubleClick += (sender, e) => listItem_MouseDoubleClick(sender, e, filePath); newItem.PreviewMouseMove += listBoxItemSound_PreviewMouseMoveEvent; System.Windows.Controls.ContextMenu listMenu = new System.Windows.Controls.ContextMenu(); System.Windows.Controls.MenuItem delete = new System.Windows.Controls.MenuItem(); delete.Header = "Delete"; delete.IsCheckable = false; delete.Click += (sender, e) => listItem_Delete(sender, e, addedSoundID); listMenu.Items.Add(delete); newItem.ContextMenu = listMenu; listBoxSounds.Items.Add(newItem); } }