Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/ChangeNestingLevelMenuItem.cs @ 15250

Last change on this file since 15250 was 15003, checked in by pfleck, 8 years ago

#2788

  • Added a dialog for changing the maximum nesting level (Views menu item).
  • For systems that have the creators update installed and a high nesting level, a warning will be displayed with the option to lower the maximum nesting level.
File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using Microsoft.Win32;
27
28namespace HeuristicLab.Optimizer.MenuItems {
29  internal class ChangeNestingLevelMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {
30
31    #region Creators Update Nesting
32    const string VersionSubKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
33    private const int VersionWin10CreatorsUpdate = 460798;
34    private const int RecommendedMaxNestingLevel = 25;
35
36    static ChangeNestingLevelMenuItem() {
37      var settings = HeuristicLab.Core.Views.Properties.Settings.Default;
38      try {
39        // detect installed .net/OS version https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net_d
40        using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(VersionSubKey)) {
41          if (ndpKey == null || ndpKey.GetValue("Release") == null) return;
42          int version = (int)ndpKey.GetValue("Release");
43          if (version == VersionWin10CreatorsUpdate && settings.MaximumNestedControls > RecommendedMaxNestingLevel) {
44            var message = string.Format("A high nesting level of controls can cause Windows 10 Creators Update to crash with a blue screen. "
45                                          + "Do you want to set the maximum nesting level from {0} to {1} to minimize the risk of a crash?",
46                settings.MaximumNestedControls, RecommendedMaxNestingLevel);
47            if (MessageBox.Show(message, "Reduce Maximum Nesting Level?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
48              settings.MaximumNestedControls = 25;
49              settings.Save();
50            }
51          }
52        }
53      } catch (PlatformNotSupportedException) {
54        // thrown on mono
55      }
56    }
57    #endregion
58
59    public override string Name {
60      get { return "Change &Nesting Level..."; }
61    }
62    public override IEnumerable<string> Structure {
63      get { return new[] { "&View" }; }
64    }
65    public override int Position {
66      get { return 4000; }
67    }
68    public override string ToolTipText {
69      get { return "Change the maximum nesting level of controls."; }
70    }
71    public override void Execute() {
72      using (var dialog = new ChangeNestingLevelDialog()) {
73        var mainForm = MainFormManager.MainForm as IWin32Window;
74        if (mainForm != null)
75          dialog.ShowDialog(mainForm);
76        else
77          dialog.ShowDialog();
78      }
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.