diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index b368957..f6618a1 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -206,18 +206,42 @@ namespace EliteBGS { } } - private void AddCombatZone_Click(object sender, RoutedEventArgs e) { - if (entries.SelectedItem == null) { - return; - } - + /// + /// Gets the currently selected objective, even if a log entry in said objective + /// is selected instead. If nothing is selected, returns null. + /// + /// + private Objective GetSelectedObjective() { var obj = entries.SelectedItem; - if (obj.GetType() != typeof(Objective)) { - return; + if (obj == null) { + return null; } - Objective objective = obj as Objective; + if (obj.GetType() == typeof(Objective)) { + return obj as Objective; + } + + // Some form of entry perhaps? + if (obj.GetType().IsSubclassOf(typeof(LogEntry))) { + LogEntry entry = obj as LogEntry; + Objective objective = entries.Items + .OfType() + .First(x => x.LogEntries.Contains(entry)) + ; + + return objective; + } + + return null; + } + + private void AddCombatZone_Click(object sender, RoutedEventArgs e) { + Objective objective = GetSelectedObjective(); + + if (objective == null) { + return; + } CombatZoneDialog dialog = new CombatZoneDialog() { Owner = this };