private void initAll() { appViewHandles = new List<AppViewHandle>(); string settingsFile = "settings.json"; if (File.Exists(settingsFile)) { var fs = File.Open(settingsFile, FileMode.Open); var sr = new StreamReader(fs); settings = Settings.FromJson(sr.ReadToEnd()); ghm = new GlobalHotkeyManager(); for (int i = 0; i < settings.appViews.Count; i++) { appViewHandles.Add(spawnProc(settings.appViews[i])); ghm.Register( settings.appViews[i].hotKeyModifier, settings.appViews[i].hotKey, this, GetDelegate(i)); var tsmiView = new ToolStripMenuItem(settings.appViews[i].name); var tsmiRebind = new ToolStripMenuItem("Rebind"); tsmiRebind.Enabled = false; tsmiView.DropDownItems.Add(tsmiRebind); var tsmiRelaunch = new ToolStripMenuItem("Relaunch"); tsmiRelaunch.Enabled = false; tsmiView.DropDownItems.Add(tsmiRelaunch); viewsToolStripMenuItem.DropDownItems.Add(tsmiView); } tAnimate.Interval = settings.animationDelay; } else { settings = new Settings(); if (MessageBox.Show("You have not configured any settings.\nDo you want to do that now?", "No settings file found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { settingsToolStripMenuItem_Click(null, null); } } }
private void FormSettings_Load(object sender, EventArgs e) { MenuAddKeyRange(Keys.A, Keys.Z, lettersToolStripMenuItem); MenuAddKeyRange(Keys.D0, Keys.D9, digitsToolStripMenuItem); MenuAddKeyRange(Keys.NumPad0, Keys.NumPad9, numPadToolStripMenuItem); MenuAddKeyRange(Keys.F1, Keys.F24, functionKeysToolStripMenuItem); MenuAddKeys(new List<Keys> { {Keys.BrowserBack}, {Keys.BrowserFavorites}, {Keys.BrowserForward}, {Keys.BrowserHome}, {Keys.BrowserRefresh}, {Keys.BrowserSearch}, {Keys.BrowserStop}, {Keys.MediaPlayPause}, {Keys.MediaNextTrack}, {Keys.MediaPreviousTrack}, {Keys.MediaStop}, {Keys.SelectMedia}, {Keys.VolumeUp}, {Keys.VolumeMute}, {Keys.VolumeDown} }, multimediaToolStripMenuItem); MenuAddKeys(new List<Keys> { {Keys.Back}, {Keys.Scroll}, {Keys.NumLock}, {Keys.PrintScreen}, {Keys.Pause}, {Keys.PageUp}, {Keys.PageDown}, {Keys.Home}, {Keys.End}, {Keys.Insert}, {Keys.Delete} }, specialToolStripMenuItem); MenuAddKeys(new List<Keys> { {Keys.Oem1}, {Keys.Oem2}, {Keys.Oem3}, {Keys.Oem4}, {Keys.Oem5}, {Keys.Oem6}, {Keys.Oem7}, {Keys.Oem8}, {Keys.Oem102} }, oEMToolStripMenuItem); bSetKeys.Text = (string)bSetKeys.Tag; string settingsFile = "settings.json"; if(File.Exists(settingsFile)){ try { var fs = File.Open(settingsFile, FileMode.OpenOrCreate); var sr = new StreamReader(fs); settings = Settings.FromJson(sr.ReadToEnd()); } catch (Exception x) { MessageBox.Show("Error when reading settings:\n " + x.Message); settings = new Settings(); } } else { settings = new Settings(); } //settings.AddTestData(); avNames = new BindingList<string>(); foreach (AppView av in settings.appViews) avNames.Add(av.name); lbAppViews.DataSource = avNames; lbAppViews.DisplayMember = "name"; tbAnimationSpeed.Value = (100 / settings.animationDelay); tbDownMovementSpeed.Value = settings.downMovementSpeed; tbUpMovementSpeed.Value = settings.upMovementSpeed; tbFadeInSpeed.Value = settings.fadeInSpeed * 5; tbFadeOutSpeed.Value = settings.fadeOutSpeed * 5; UpdateValues(); }