Beispiel #1
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            // Only close the window, when the user has access to the "Exit" of the menu.
            if (!menuStrip1.Enabled)
            {
                e.Cancel = true;
                return;
            }

            if (Conflicts != null)
            {
                if (Conflicts.Any())
                {
                    // Ask if they want to resolve conflicts
                    string confDescrip = Conflicts
                                         .Select(kvp => kvp.Value)
                                         .Aggregate((a, b) => $"{a}, {b}");
                    if (!YesNoDialog($"There are conflicts. Really quit?\r\n\r\n{confDescrip}"))
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                else
                {
                    // The Conflicts dictionary is empty even when there are unmet dependencies.
                    if (!YesNoDialog("There are unmet dependencies. Really quit?"))
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }
            else if (ChangeSet?.Any() ?? false)
            {
                // Ask if they want to discard the change set
                string changeDescrip = ChangeSet
                                       .GroupBy(ch => ch.ChangeType, ch => ch.Mod.Name)
                                       .Select(grp => $"{grp.Key}: "
                                               + grp.Aggregate((a, b) => $"{a}, {b}"))
                                       .Aggregate((a, b) => $"{a}\r\n{b}");
                if (!YesNoDialog($"You have unapplied changes. Really quit?\r\n\r\n{changeDescrip}"))
                {
                    e.Cancel = true;
                    return;
                }
            }

            // Copy window location to app settings
            configuration.WindowLoc = Location;

            // Copy window size to app settings if not maximized
            configuration.WindowSize = WindowState == FormWindowState.Normal ? Size : RestoreBounds.Size;

            //copy window maximized state to app settings
            configuration.IsWindowMaximised = WindowState == FormWindowState.Maximized;

            // Copy panel position to app settings
            configuration.PanelPosition = splitContainer1.SplitterDistance;

            // Copy metadata panel split height to app settings
            configuration.ModInfoPosition = ModInfoTabControl.ModMetaSplitPosition;

            // Save the active filter
            configuration.ActiveFilter = (int)mainModList.ModFilter;

            // Save settings.
            configuration.Save();
            base.OnFormClosing(e);
        }