private void ModItem_DoubleClick(object sender, RoutedEventArgs args) { IModListItem item = GetModListItemFromListViewItem(sender); if (item == null) { return; } TrySwapModListItemState(item); }
static public void Filter(object sender, FilterEventArgs args) { IModListItem mod = args.Item as IModListItem; if (mod == null) { throw new NotImplementedException(); } args.Accepted = mod.IsEnabled ? showEnabled : showDisabled; }
private void TrySwapModListItemState(IModListItem modListItem) { try { //modListItem.ToggleEnabled(); } catch (ModLockedException ex) { MessageBox.Show(ex.Message, "Mod Locked", MessageBoxButton.OK, MessageBoxImage.Exclamation); } RefreshModsList(); }
private IModListItem GetModListItemFromListViewItem(object listViewItem) { ListViewItem item = listViewItem as ListViewItem; if (item == null) { return(null); } IModListItem mod = modsList.ItemContainerGenerator.ItemFromContainer(item) as IModListItem; if (mod == null) { return(null); } mod = modListItemInternal[modListItemInternal.IndexOf(mod)]; return(mod); }
private ModListItemViewModel MakeViewModel(IModListItem modItem) { var mod = modItem as Mod; if (mod != null) { return(MakeModViewModel(mod)); } var preset = modItem as Preset; if (preset != null) { return(MakePresetViewModel(preset)); } throw new NotSupportedException("Unknown IModListItem {0}".With(modItem.GetType().Name)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { FrameworkElement element = container as FrameworkElement; if (element != null && item != null && item is IModListItem) { IModListItem listItem = item as IModListItem; if (listItem is Mod) { return(element.FindResource("modItemTemplate") as DataTemplate); } else if (listItem is Preset) { return(element.FindResource("presetItemTemplate") as DataTemplate); } } return(null); }
private void ShowModItemContextMenu(object item) { ListViewItem listViewItem = item as ListViewItem; IModListItem modListItem = GetModListItemFromListViewItem(item); if (modListItem == null) { return; } ContextMenu menu = new ContextMenu(); MenuItem enableDisableItem = new MenuItem(); enableDisableItem.Header = (modListItem.IsEnabled) ? "Disable" : "Enable"; enableDisableItem.Click += (o, e) => TrySwapModListItemState(modListItem); menu.Items.Add(enableDisableItem); if (modListItem is Mod) { menu.Items.Add(new Separator()); Mod mod = (Mod)modListItem; var deleteModItem = new MenuItem(); deleteModItem.Header = "Delete Mod"; deleteModItem.Click += (o, e) => ConfirmAndDeleteMod(mod); menu.Items.Add(deleteModItem); menu.Items.Add(new Separator()); MenuItem addToPresetItem = new MenuItem(); addToPresetItem.Header = "Add To Preset"; MenuItem newPresetItem = new MenuItem(); newPresetItem.Header = "New Preset..."; newPresetItem.Click += (o, e) => CreatePresetAndAddModTo(mod); addToPresetItem.Items.Add(newPresetItem); //bool separatorAdded = false; /*foreach (Preset preset in PresetManager.GetAllPresets()) * { * Preset currentPreset = preset; * if (!separatorAdded) * { * addToPresetItem.Items.Add(new Separator()); * separatorAdded = true; * } * MenuItem presetItem = new MenuItem(); * presetItem.Header = preset.Name; * presetItem.Click += (o, e) => AddModToPreset(mod, currentPreset); * addToPresetItem.Items.Add(presetItem); * }*/ menu.Items.Add(addToPresetItem); } if (modListItem is Preset) { Preset preset = modListItem as Preset; menu.Items.Add(new Separator()); MenuItem renamePresetItem = new MenuItem(); renamePresetItem.Header = "Rename..."; renamePresetItem.Click += (o, e) => RenamePreset(preset); menu.Items.Add(renamePresetItem); MenuItem disbandPresetItem = new MenuItem(); disbandPresetItem.Header = "Disband"; disbandPresetItem.Click += (o, e) => DisbandPreset(preset); menu.Items.Add(disbandPresetItem); } listViewItem.ContextMenu = menu; }
private ModListItemViewModel MakeViewModel(IModListItem modItem) { var mod = modItem as Mod; if (mod != null) return MakeModViewModel(mod); var preset = modItem as Preset; if (preset != null) return MakePresetViewModel(preset); throw new NotSupportedException("Unknown IModListItem {0}".With(modItem.GetType().Name)); }