protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { bool loaded = ActiveProfile != null; if (loaded) { if (ActiveProfile.IsStarted) { ConfigManager.LogManager.LogInfo("Stopping profile on exit."); ActiveProfile.Stop(); } ConfigManager.LogManager.LogInfo("Unloading profile on exit."); ActiveProfile = null; } ConfigManager.LogManager.LogInfo("Saving control center window position."); // Persist window placement details to application settings WINDOWPLACEMENT wp = new WINDOWPLACEMENT(); IntPtr hwnd = new WindowInteropHelper(this).Handle; NativeMethods.GetWindowPlacement(hwnd, out wp); //Properties.PreferencesFile.Default.ControlCenterPlacement = wp; PreferencesFile.SaveSetting("ControlCenter", "WindowLocation", wp.normalPosition); if (loaded && _profileIndex >= 0 && _profileIndex < _profiles.Count) { PreferencesFile.SaveSetting("ControlCenter", "LastProfile", _profiles[_profileIndex]); } Properties.Settings.Default.Save(); base.OnClosing(e); }
private void RunProfile_Executed(object sender, ExecutedRoutedEventArgs e) { string profileToLoad = e.Parameter as string; if (profileToLoad == null || !File.Exists(profileToLoad)) { NativeMethods.BringWindowToTop(_helper.Handle); } else { if (ActiveProfile != null) { if (ActiveProfile.IsStarted) { ActiveProfile.Stop(); } ActiveProfile = null; } // try to load the profile, setting SelectedProfileName in the process SettingsLoadTime = DateTime.Now; (ConfigManager.SettingsManager as ISettingsManager2)?.SynchronizeSettings(null); LoadProfile(profileToLoad); if (ActiveProfile != null) { // we need to fix up the selection index or Next/Prev buttons will not work correctly // because LoadProfile sets SelectedProfileName but assumes the prev/next has already been set // by user interaction. however, we selected this profile without user interaction LoadProfileList(profileToLoad); } StartProfile(); } }
private void StopProfile() { if (ActiveProfile != null && ActiveProfile.IsStarted) { ActiveProfile.Stop(); } }
private void RunProfile_Executed(object sender, ExecutedRoutedEventArgs e) { _deletingProfile = false; string profileToLoad = e.Parameter as string; if (profileToLoad == null || !File.Exists(profileToLoad)) { NativeMethods.BringWindowToTop(_helper.Handle); } else { if (ActiveProfile != null) { if (ActiveProfile.IsStarted) { ActiveProfile.Stop(); } ActiveProfile = null; } LoadProfile(profileToLoad); StartProfile(); } }