public static SettingValues Load()
        {
            SettingValues settings;

            if (!File.Exists(SettingsFileName))
            {
                settings = new SettingValues();
            }
            else
            {
                // Getting could not load VirtualDesktopGridSwitcher.XmlSerializers.dll?
                // Enable "Just My Code" in debug options
                XmlSerializer serializer = new XmlSerializer(typeof(SettingValues));
                FileStream    fs         = new FileStream(SettingsFileName, FileMode.Open);
                settings = (SettingValues)serializer.Deserialize(fs);
                fs.Close();

                LoadOldSettings(settings);
            }

            settings.SetListDefaults();

            settings.ApplyVersionUpdates();

            return(settings);
        }
        public SettingsDialog(SettingValues settings)
        {
            this.settings = settings;

            InitializeComponent();

            LoadValues();
        }
        private static void LoadOldSettings(SettingValues settings)
        {
            // Backward compatibility
            XDocument xdoc = XDocument.Load(SettingsFileName);

            var switchCtrl = xdoc.Element("SettingValues").Element("CtrlModifierSwitch");

            if (switchCtrl != null)
            {
                settings.SwitchModifiers.Ctrl = (bool)switchCtrl;
            }
            var switchWin = xdoc.Element("SettingValues").Element("WinModifierSwitch");

            if (switchWin != null)
            {
                settings.SwitchModifiers.Win = (bool)switchWin;
            }
            var switchAlt = xdoc.Element("SettingValues").Element("AltModifierSwitch");

            if (switchAlt != null)
            {
                settings.SwitchModifiers.Alt = (bool)switchAlt;
            }
            var switchShift = xdoc.Element("SettingValues").Element("ShiftModifierSwitch");

            if (switchShift != null)
            {
                settings.SwitchModifiers.Shift = (bool)switchShift;
            }

            var moveCtrl = xdoc.Element("SettingValues").Element("CtrlModifierMove");

            if (moveCtrl != null)
            {
                settings.MoveModifiers.Ctrl = (bool)moveCtrl;
            }
            var moveWin = xdoc.Element("SettingValues").Element("WinModifierMove");

            if (moveWin != null)
            {
                settings.MoveModifiers.Win = (bool)moveWin;
            }
            var moveAlt = xdoc.Element("SettingValues").Element("AltModifierMove");

            if (moveAlt != null)
            {
                settings.MoveModifiers.Alt = (bool)moveAlt;
            }
            var moveShift = xdoc.Element("SettingValues").Element("ShiftModifierMove");

            if (moveShift != null)
            {
                settings.MoveModifiers.Shift = (bool)moveShift;
            }
        }
        public SettingsDialog(SettingValues settings)
        {
            this.settings = settings;

            InitializeComponent();

            List <Keys> stickyKeyValues = Enum.GetValues(typeof(Keys)).Cast <Keys>().Where(v => v > 0).ToList();

            comboBoxKeySticky.DataSource = stickyKeyValues;

            List <Keys> alwaysOnTopKeyValues = Enum.GetValues(typeof(Keys)).Cast <Keys>().Where(v => v > 0).ToList();

            comboBoxAlwaysOnTopKey.DataSource = alwaysOnTopKeyValues;

            LoadValues();
        }
        public static SettingValues Load()
        {
            SettingValues settings;

            if (!File.Exists(SettingsFileName))
            {
                settings = new SettingValues();
            }
            else
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SettingValues));
                FileStream    fs         = new FileStream(SettingsFileName, FileMode.Open);
                settings = (SettingValues)serializer.Deserialize(fs);
                fs.Close();

                LoadOldSettings(settings);
            }

            settings.SetListDefaults();
            return(settings);
        }
        public SettingsDialog(SettingValues settings)
        {
            InitializeComponent();

            this.settings      = settings;
            this.desktopCombos =
                new ComboBox[] {
                comboBox1,
                comboBox2,
                comboBox3,
                comboBox4,
                comboBox5,
                comboBox6,
                comboBox7,
                comboBox8,
                comboBox9,
                comboBox10,
                comboBox11,
                comboBox12
            };

            PopulateComboBoxKeyValues(comboBoxLeft);
            PopulateComboBoxKeyValues(comboBoxRight);
            PopulateComboBoxKeyValues(comboBoxUp);
            PopulateComboBoxKeyValues(comboBoxDown);

            foreach (ComboBox desktopCombo in desktopCombos)
            {
                PopulateComboBoxKeyValues(desktopCombo);
            }

            PopulateComboBoxKeyValues(comboBoxKeySticky);
            PopulateComboBoxKeyValues(comboBoxAlwaysOnTopKey);

            LoadValues();
        }
        private static void LoadOldSettings(SettingValues settings)
        {
            // Backward compatibility
            XDocument xdoc = XDocument.Load(SettingsFileName);

            var switchCtrl = xdoc.Element("SettingValues").Element("CtrlModifierSwitch");

            if (switchCtrl != null)
            {
                settings.SwitchDirModifiers.Ctrl = (bool)switchCtrl;
            }
            var switchWin = xdoc.Element("SettingValues").Element("WinModifierSwitch");

            if (switchWin != null)
            {
                settings.SwitchDirModifiers.Win = (bool)switchWin;
            }
            var switchAlt = xdoc.Element("SettingValues").Element("AltModifierSwitch");

            if (switchAlt != null)
            {
                settings.SwitchDirModifiers.Alt = (bool)switchAlt;
            }
            var switchShift = xdoc.Element("SettingValues").Element("ShiftModifierSwitch");

            if (switchShift != null)
            {
                settings.SwitchDirModifiers.Shift = (bool)switchShift;
            }

            var moveCtrl = xdoc.Element("SettingValues").Element("CtrlModifierMove");

            if (moveCtrl != null)
            {
                settings.MoveDirModifiers.Ctrl = (bool)moveCtrl;
            }
            var moveWin = xdoc.Element("SettingValues").Element("WinModifierMove");

            if (moveWin != null)
            {
                settings.MoveDirModifiers.Win = (bool)moveWin;
            }
            var moveAlt = xdoc.Element("SettingValues").Element("AltModifierMove");

            if (moveAlt != null)
            {
                settings.MoveDirModifiers.Alt = (bool)moveAlt;
            }
            var moveShift = xdoc.Element("SettingValues").Element("ShiftModifierMove");

            if (moveShift != null)
            {
                settings.MoveDirModifiers.Shift = (bool)moveShift;
            }

            var fKeysForNumbers = xdoc.Element("SettingValues").Element("FKeysForNumbers");

            if (fKeysForNumbers != null)
            {
                settings.FKeysEnabled = (bool)fKeysForNumbers;
            }

            // Version 3

            var switchModCtrl = xdoc.Element("SettingValues").Element("SwitchModifiers")?.Element("Ctrl");

            if (switchModCtrl != null)
            {
                settings.SwitchDirModifiers.Ctrl = (bool)switchModCtrl;
                settings.SwitchPosModifiers.Ctrl = (bool)switchModCtrl;
            }
            var switchModWin = xdoc.Element("SettingValues").Element("SwitchModifiers")?.Element("Win");

            if (switchModWin != null)
            {
                settings.SwitchDirModifiers.Win = (bool)switchModWin;
                settings.SwitchPosModifiers.Win = (bool)switchModWin;
            }
            var switchModAlt = xdoc.Element("SettingValues").Element("SwitchModifiers")?.Element("Alt");

            if (switchModAlt != null)
            {
                settings.SwitchDirModifiers.Alt = (bool)switchModAlt;
                settings.SwitchPosModifiers.Alt = (bool)switchModAlt;
            }
            var switchModShift = xdoc.Element("SettingValues").Element("SwitchModifiers")?.Element("Shift");

            if (switchModShift != null)
            {
                settings.SwitchDirModifiers.Shift = (bool)switchModShift;
                settings.SwitchPosModifiers.Shift = (bool)switchModShift;
            }
            var switchEnabled = xdoc.Element("SettingValues").Element("SwitchEnabled");

            if (switchEnabled != null)
            {
                settings.SwitchDirEnabled = (bool)switchEnabled;
                settings.SwitchPosEnabled = (bool)switchEnabled;
            }

            var moveModCtrl = xdoc.Element("SettingValues").Element("MoveModifiers")?.Element("Ctrl");

            if (moveModCtrl != null)
            {
                settings.MoveDirModifiers.Ctrl = (bool)moveModCtrl;
                settings.MovePosModifiers.Ctrl = (bool)moveModCtrl;
            }
            var moveModWin = xdoc.Element("SettingValues").Element("MoveModifiers")?.Element("Win");

            if (moveModWin != null)
            {
                settings.MoveDirModifiers.Win = (bool)moveModWin;
                settings.MovePosModifiers.Win = (bool)moveModWin;
            }
            var moveModAlt = xdoc.Element("SettingValues").Element("MoveModifiers")?.Element("Alt");

            if (moveModAlt != null)
            {
                settings.MoveDirModifiers.Alt = (bool)moveModAlt;
                settings.MovePosModifiers.Alt = (bool)moveModAlt;
            }
            var moveModShift = xdoc.Element("SettingValues").Element("MoveModifiers")?.Element("Shift");

            if (moveModShift != null)
            {
                settings.MoveDirModifiers.Shift = (bool)moveModShift;
                settings.MovePosModifiers.Shift = (bool)moveModShift;
            }
            var moveEnabled = xdoc.Element("SettingValues").Element("MoveEnabled");

            if (moveEnabled != null)
            {
                settings.MoveDirEnabled = (bool)moveEnabled;
                settings.MovePosEnabled = (bool)moveEnabled;
            }

            var dirKeysEnabled = xdoc.Element("SettingValues").Element("DirectionKeysEnabled");

            if (dirKeysEnabled != null && !(bool)dirKeysEnabled)
            {
                settings.SwitchDirEnabled = false;
                settings.MoveDirEnabled   = false;
            }
        }
 private static void LoadOldSettings(SettingValues settings)
 {
     // Backward compatibility
     XDocument xdoc = XDocument.Load(SettingsFileName);
 }