From 6c27eb4202e5de82ea7facc9eec442684e430544 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Fri, 18 Feb 2022 14:17:35 +0100 Subject: [PATCH] condense mirror state calls into a method --- .../AM2RLauncher/MainForm/MainForm.Events.cs | 52 ++++++------------- .../AM2RLauncher/MainForm/MainForm.Methods.cs | 13 +++++ .../MainForm/MainForm.StateMachine.cs | 13 +++++ .../AM2RLauncher/MainForm/MainForm.UI.cs | 3 +- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs index fb2b4e8..e6a571a 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs @@ -175,24 +175,24 @@ namespace AM2RLauncher { // If we're currently still downloading, ask first if user really wants to close and cancel the event if necessary case UpdateState.Downloading: - { - var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, - MessageBoxType.Warning, MessageBoxDefaultButton.No); + { + var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, + MessageBoxType.Warning, MessageBoxDefaultButton.No); - if (result == DialogResult.No) - e.Cancel = true; - else - isGitProcessGettingCancelled = true; - // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :) - break; - } + if (result == DialogResult.No) + e.Cancel = true; + else + isGitProcessGettingCancelled = true; + // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :) + break; + } // We can't close during installing, so we cancel the event. case UpdateState.Installing: - { - MessageBox.Show(this, Text.CloseOnInstallingText, Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning); - e.Cancel = true; - break; - } + { + MessageBox.Show(this, Text.CloseOnInstallingText, Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning); + e.Cancel = true; + break; + } } // This needs to be made invisible, otherwise a tray indicator will be visible (on linux?) that clicking crashes the application @@ -634,16 +634,10 @@ namespace AM2RLauncher log.Info("Use Custom Mirror option has been set to " + customMirrorCheck.Checked + "."); CrossPlatformOperations.WriteToConfig("CustomMirrorEnabled", (bool)customMirrorCheck.Checked); - bool enabled = (bool)customMirrorCheck.Checked; - customMirrorTextBox.Enabled = enabled; - mirrorDropDown.Enabled = !enabled; - // Not sure why the dropdown menu needs this hack, but the textBox does not. - if (OS.IsWindows) - mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; - mirrorLabel.TextColor = !enabled ? colGreen : colInactive; + EnableMirrorControlsAccordingly(); // Create warning dialog when enabling - if (enabled) + if ((bool)customMirrorCheck.Checked) { MessageBox.Show(this, Text.WarningWindowText, Text.WarningWindowTitle, MessageBoxType.Warning); currentMirror = customMirrorTextBox.Text; @@ -655,18 +649,6 @@ namespace AM2RLauncher } } - //TODO: why exactly do we need this? - /// Gets called when gets loaded. - /// Enables and changes colors for and accordingly. - private void CustomMirrorCheckLoadComplete(object sender, EventArgs e) - { - bool enabled = (bool)customMirrorCheck.Checked; - customMirrorTextBox.Enabled = enabled; - mirrorDropDown.Enabled = !enabled; - if (OS.IsWindows) - mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; - } - /// /// If the has lost focus, we set its text as the new . /// diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs index 87b6d63..88f5fa3 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs @@ -85,5 +85,18 @@ namespace AM2RLauncher fileDialog.Filters.Add(new FileFilter(Text.ZipArchiveText, ".zip")); return fileDialog; } + + /// Enables and changes colors for and accordingly. + private void EnableMirrorControlsAccordingly() + { + bool enabled = (bool)customMirrorCheck.Checked; + customMirrorTextBox.Enabled = enabled; + mirrorDropDown.Enabled = !enabled; + // Not sure why the dropdown menu needs this hack, but the textBox does not. + //TODO: eto issue? + if (OS.IsWindows) + mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; + mirrorLabel.TextColor = !enabled ? colGreen : colInactive; + } } } \ No newline at end of file diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs index b1ae1bb..273b1d3 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs @@ -366,5 +366,18 @@ namespace AM2RLauncher Profile.ArchiveProfile(profile); LoadProfilesAndAdjustLists(); } + + /// Enables and changes colors for and accordingly. + private void EnableMirrorControlsAccordingly() + { + bool enabled = (bool)customMirrorCheck.Checked; + customMirrorTextBox.Enabled = enabled; + mirrorDropDown.Enabled = !enabled; + // Not sure why the dropdown menu needs this hack, but the textBox does not. + //TODO: eto issue? + if (OS.IsWindows) + mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; + mirrorLabel.TextColor = !enabled ? colGreen : colInactive; + } } } \ No newline at end of file diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs index 9ec9529..65fd56f 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs @@ -634,6 +634,8 @@ namespace AM2RLauncher TextColor = colGreen }; + EnableMirrorControlsAccordingly(); + settingsLayout.BeginHorizontal(); settingsLayout.AddSpace(); settingsLayout.AddColumn(null, languageLabel, languageDropDown, autoUpdateAM2RCheck, autoUpdateLauncherCheck, hqMusicPCCheck, hqMusicAndroidCheck, profileDebugLogCheck, customEnvVarLabel, (Control)customEnvVarTextBox ?? new Label(), mirrorLabel, mirrorDropDown, customMirrorCheck, customMirrorTextBox, null); @@ -799,7 +801,6 @@ namespace AM2RLauncher hqMusicAndroidCheck.CheckedChanged += HqMusicAndroidCheckChanged; hqMusicPCCheck.CheckedChanged += HqMusicPCCheckChanged; customMirrorCheck.CheckedChanged += CustomMirrorCheckChanged; - customMirrorCheck.LoadComplete += CustomMirrorCheckLoadComplete; apkButton.Click += ApkButtonClickEvent; apkButton.LoadComplete += (sender, e) => UpdateApkState(); profileDropDown.LoadComplete += (sender, e) => UpdateProfileState();