public void SetSettings(CommandForWindowsGUISettings newSettings, bool save) { // change the current settings CommandForWindowsGUISettings oldSettings = this.Settings; this.Settings = newSettings; OnSettingsChanged(newSettings, oldSettings); // save the settings if necessary if (save) { string settingsFilePath = this.SettingsFilePath; if (string.IsNullOrEmpty(settingsFilePath) == false) { Action saveTask = () => { try { SaveSettingsToFile(newSettings, settingsFilePath); } catch (Exception exception) { LogError($"Fail to save settings: {exception.Message}"); } }; // launch save task Task.Run(saveTask); } } }
public void DoInitialSetup() { CommandForWindowsGUISettings settings = CloneSettings(this.Settings); if (base.DoInitialSetup(settings)) { // settings are set up // Note that the new settings have been saved in base.DoInitialSetup() SetSettings(settings, save: false); } return; }
protected override int DoInitialSetupImpl(CommandSettings settings) { // argument checks CommandForWindowsGUISettings actualSettings = settings as CommandForWindowsGUISettings; if (actualSettings == null) { throw new ArgumentException($"It must be an instance of {nameof(CommandForWindowsGUISettings)} class.", nameof(settings)); } // create context SetupContextForWindows setupContext = new SetupContextForWindows(actualSettings, this); bool needSetup = (settings.InitialSetupLevel == 0) || setupContext.NeedSetup; // Note that it returns the latest level if no need to setup, it sets 'InitialSetupLevel' settings up-to-date return(needSetup? this.app.ShowSetupWindow(setupContext): SetupContext.LatestInitialSetupLevel); }
internal void ShowSettingsWindow() { // state checks if ((this.UIState & UIStateFlags.SettingsEnabled) == 0) { // currently not enabled // maybe a queued event is dispatched belatedly return; } // show the settings window SettingsWindow window = this.settingsWindow; if (window != null) { window.Activate(); } else { // state checks Debug.Assert((this.UIState & UIStateFlags.SettingsEnabled) != 0); // open the settings window as dialog Command command = this.Command; CommandForWindowsGUISettings settings = Command.CloneSettings(command.Settings); settings.LogLevel = Logger.LogLevel; // LogLevel might be changed by LogLevel menu window = new SettingsWindow(settings, command.HasSettingsFile, command.IsProxyRunning); window.Owner = this; this.settingsWindow = window; try { UpdateUIState(); if (window.ShowDialog() ?? false) { command.SetSettings(window.CommandSettings, window.SaveAsDefault); UpdateLogLevelUI(window.CommandSettings.LogLevel); } } finally { this.settingsWindow = null; UpdateUIState(); } } }
internal SettingsWindow(CommandForWindowsGUISettings commandSettings, bool enableSaveAsDefault, bool runningProxy) { // argument checks if (commandSettings == null) { throw new ArgumentNullException(nameof(commandSettings)); } // initialize members this.CommandSettings = commandSettings; this.SaveAsDefault = false; this.enableSaveAsDefault = enableSaveAsDefault; this.runningProxy = runningProxy; // initialize components InitializeComponent(); // Tuple(control, tab index on which the control resides) this.validatableControls = new Tuple <Control, int>[] { new Tuple <Control, int>(this.retryTextBox, 0), new Tuple <Control, int>(this.resumeTryCountTextBox, 3), new Tuple <Control, int>(this.resumeDelayTextBox, 3), new Tuple <Control, int>(this.resumeIntervalTextBox, 3) }; this.Icon = App.Current.OnIcon; this.DataContext = this; // Proxy Tab // Actual Proxy SystemSettingsSwitcherForWindowsSettings systemSettingsSwitcherSettings = commandSettings.SystemSettingsSwitcher; this.actualProxy.SystemSettingsSwitcherSettings = systemSettingsSwitcherSettings; // SystemSettingSwither // this.enableSystemSettingSwitherCheckBox.IsChecked is bound to this.EnableSystemSettingSwitch this.systemSettingsSwitcher.SystemSettingsSwitcherSettings = systemSettingsSwitcherSettings; // Misc // this.retryTextBox.Text is bound to this.RetryCount // Listener Tab ProxySettings proxySettings = commandSettings.Proxy; ItemCollection items = this.listenerListView.Items; items.Add(proxySettings.MainListener); if (proxySettings.AdditionalListeners != null) { foreach (ListenerSettings listenerSetting in proxySettings.AdditionalListeners) { items.Add(listenerSetting); } } // Credential Tab if (commandSettings.Credentials != null) { items = this.credentialListView.Items; foreach (CredentialSettings credentialSettings in commandSettings.Credentials) { items.Add(credentialSettings); } } // Misc Tab // this.logLevelComboBox.SelectedItem is bound to this.LogLevel // update UI state if (runningProxy) { // modify the title this.Title = Properties.Resources.SettingsWindow_Title_ReadOnly; // disable input controls // Note that buttons are disabled through GetUIState(). Control[] inputControls = new Control[] { this.actualProxy, this.systemSettingsSwitcher, this.retryTextBox, this.logLevelComboBox, this.resumeTryCountTextBox, this.resumeDelayTextBox, this.resumeIntervalTextBox }; Array.ForEach(inputControls, c => { c.IsEnabled = false; }); } UpdateUIState(); return; }