From 79597b077fd10182beff6ce20bfa7fb07d05bdda Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 7 Mar 2021 14:24:58 +1300 Subject: [PATCH] Fixed profile selection for Shortcuts Fixed the logic for profile selection on shortcuts so that the profile is either selected or not based on its existence or whether the profile is valid to use now or whether the shortcut is new. --- DisplayMagician/ShortcutRepository.cs | 8 ++- .../UIForms/ShortcutForm.Designer.cs | 17 +++-- DisplayMagician/UIForms/ShortcutForm.cs | 71 ++++++------------- 3 files changed, 37 insertions(+), 59 deletions(-) diff --git a/DisplayMagician/ShortcutRepository.cs b/DisplayMagician/ShortcutRepository.cs index b1c0dde..4295723 100644 --- a/DisplayMagician/ShortcutRepository.cs +++ b/DisplayMagician/ShortcutRepository.cs @@ -608,7 +608,9 @@ namespace DisplayMagician // record the old audio device bool needToChangeAudio = false; CoreAudioDevice rollbackAudioDevice = _audioController.DefaultPlaybackDevice; - double rollbackAudioVolume = _audioController.DefaultPlaybackDevice.Volume; + double rollbackAudioVolume = 50; + if (rollbackAudioDevice != null) + rollbackAudioVolume = _audioController.DefaultPlaybackDevice.Volume; if (!rollbackAudioDevice.FullName.Equals(shortcutToUse.AudioDevice)) { logger.Debug($"ShortcutRepository/RunShortcut: We need to change to the {shortcutToUse.AudioDevice} audio device."); @@ -650,7 +652,9 @@ namespace DisplayMagician // record the old microphone device bool needToChangeCaptureDevice = false; CoreAudioDevice rollbackCaptureDevice = _audioController.DefaultCaptureDevice; - double rollbackCaptureVolume = _audioController.DefaultCaptureDevice.Volume; + double rollbackCaptureVolume = 50; + if (rollbackCaptureDevice != null) + rollbackCaptureVolume = _audioController.DefaultCaptureDevice.Volume; if (!rollbackCaptureDevice.FullName.Equals(shortcutToUse.CaptureDevice)) { logger.Debug($"ShortcutRepository/RunShortcut: We need to change to the {shortcutToUse.CaptureDevice} capture (microphone) device."); diff --git a/DisplayMagician/UIForms/ShortcutForm.Designer.cs b/DisplayMagician/UIForms/ShortcutForm.Designer.cs index a1713cb..c2e9d7b 100644 --- a/DisplayMagician/UIForms/ShortcutForm.Designer.cs +++ b/DisplayMagician/UIForms/ShortcutForm.Designer.cs @@ -260,10 +260,9 @@ namespace DisplayMagician.UIForms this.lbl_profile_shown_subtitle.ForeColor = System.Drawing.Color.White; this.lbl_profile_shown_subtitle.Location = new System.Drawing.Point(18, 49); this.lbl_profile_shown_subtitle.Name = "lbl_profile_shown_subtitle"; - this.lbl_profile_shown_subtitle.Size = new System.Drawing.Size(943, 20); + this.lbl_profile_shown_subtitle.Size = new System.Drawing.Size(397, 20); this.lbl_profile_shown_subtitle.TabIndex = 26; - this.lbl_profile_shown_subtitle.Text = "Please go back to the startup window, click on the \'Setup Display Profile\' button" + - ", save a new Display Profile and then come back here."; + this.lbl_profile_shown_subtitle.Text = "Please select a Display Profile to use with this Shortcut."; // // lbl_profile_shown // @@ -273,9 +272,9 @@ namespace DisplayMagician.UIForms this.lbl_profile_shown.ForeColor = System.Drawing.Color.White; this.lbl_profile_shown.Location = new System.Drawing.Point(18, 20); this.lbl_profile_shown.Name = "lbl_profile_shown"; - this.lbl_profile_shown.Size = new System.Drawing.Size(396, 29); + this.lbl_profile_shown.Size = new System.Drawing.Size(308, 29); this.lbl_profile_shown.TabIndex = 25; - this.lbl_profile_shown.Text = "No Saved Display Profiles Available"; + this.lbl_profile_shown.Text = "No Display Profile Selected"; // // ilv_saved_profiles // @@ -323,7 +322,7 @@ namespace DisplayMagician.UIForms this.tabp_audio.Location = new System.Drawing.Point(4, 32); this.tabp_audio.Name = "tabp_audio"; this.tabp_audio.Padding = new System.Windows.Forms.Padding(3); - this.tabp_audio.Size = new System.Drawing.Size(1082, 594); + this.tabp_audio.Size = new System.Drawing.Size(1082, 618); this.tabp_audio.TabIndex = 4; this.tabp_audio.Text = "2. Choose Audio"; // @@ -601,7 +600,7 @@ namespace DisplayMagician.UIForms this.tabp_before.Location = new System.Drawing.Point(4, 32); this.tabp_before.Name = "tabp_before"; this.tabp_before.Padding = new System.Windows.Forms.Padding(3); - this.tabp_before.Size = new System.Drawing.Size(1082, 594); + this.tabp_before.Size = new System.Drawing.Size(1082, 618); this.tabp_before.TabIndex = 1; this.tabp_before.Text = "3. Choose what happens before"; // @@ -971,7 +970,7 @@ namespace DisplayMagician.UIForms this.tabp_game.Location = new System.Drawing.Point(4, 32); this.tabp_game.Name = "tabp_game"; this.tabp_game.Padding = new System.Windows.Forms.Padding(3); - this.tabp_game.Size = new System.Drawing.Size(1082, 594); + this.tabp_game.Size = new System.Drawing.Size(1082, 618); this.tabp_game.TabIndex = 2; this.tabp_game.Text = "4. Choose Game to start"; // @@ -1340,7 +1339,7 @@ namespace DisplayMagician.UIForms this.tabp_after.Location = new System.Drawing.Point(4, 32); this.tabp_after.Name = "tabp_after"; this.tabp_after.Padding = new System.Windows.Forms.Padding(3); - this.tabp_after.Size = new System.Drawing.Size(1082, 594); + this.tabp_after.Size = new System.Drawing.Size(1082, 618); this.tabp_after.TabIndex = 3; this.tabp_after.Text = "5. Choose what happens afterwards"; // diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index c7529e9..91e634f 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -66,6 +66,9 @@ namespace DisplayMagician.UIForms ilv_saved_profiles.AllowDrag = false; ilv_saved_profiles.AllowDrop = false; ilv_saved_profiles.SetRenderer(new ProfileILVRenderer()); + + lbl_profile_shown.Text = "No Display Profiles available"; + lbl_profile_shown_subtitle.Text = "Please go back to the main window, click on 'Display Profiles', and save a new Display Profile. Then come back here."; } public ShortcutItem Shortcut @@ -818,34 +821,32 @@ namespace DisplayMagician.UIForms }); } - // We only get down here if the form has loaded a shortcut to edit - if (_shortcutToEdit is ShortcutItem && _shortcutToEdit.ProfileToUse is ProfileItem) + + if (_shortcutToEdit != null) { - foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles) + if (ProfileRepository.ContainsProfile(_shortcutToEdit.ProfileUUID)) { - if (_shortcutToEdit.ProfileToUse.Equals(loadedProfile)) + // We have loaded the profile used last time + // so we need to show the selected profile in the UI + chosenProfile = ProfileRepository.GetProfile(_shortcutToEdit.ProfileUUID); + foundChosenProfileInLoadedProfiles = true; + + // If the profile is the same, but the user has renamed the profile + // since the shortcut was last created, then we need to tell the user + if (!chosenProfile.IsPossible) { - // We have loaded the profile used last time - // so we need to show the selected profile in the UI - chosenProfile = loadedProfile; - foundChosenProfileInLoadedProfiles = true; - // If the profile is the same, but the user has renamed the profile - // since the shortcut was last created, then we need to tell the user - if (!loadedProfile.Name.Equals(_shortcutToEdit.ProfileToUse.Name)) - { - - MessageBox.Show( - @"The Display Profile used by this Shortcut still exists, but it's changed it's name. We've updated the shortcut's name to reflect this change.", - @"Display Profile name changed", - MessageBoxButtons.OK, - MessageBoxIcon.Exclamation); + MessageBox.Show( + $"The '{chosenProfile.Name}' Display Profile used by this Shortcut still exists, but it isn't possible to use it right now. You can either change the Display Profile this Shortcut uses, or you can change your Displays to make the Display Profile valid again.", + @"Display Profile isn't possible now", + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); - } - break; } } + + } if (!foundChosenProfileInLoadedProfiles && !String.IsNullOrWhiteSpace(_shortcutToEdit.ProfileUUID)) @@ -855,39 +856,13 @@ namespace DisplayMagician.UIForms @"Display Profile no longer exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - // If we get to the end of the loaded profiles and haven't // found a matching profile, then we need to show the current profile // that we're running now - if (!foundChosenProfileInLoadedProfiles && ProfileRepository.ProfileCount > 0) + else if (!foundChosenProfileInLoadedProfiles && ProfileRepository.ProfileCount > 0) { - foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles) - { - if (ProfileRepository.CurrentProfile.Equals(loadedProfile)) - { - // We have loaded the profile used last time - // so we need to show the selected profile in the UI - chosenProfile = loadedProfile; - foundChosenProfileInLoadedProfiles = true; - - // If the profile is the same, but the user has renamed the profile - // since the shortcut was last created, then we need to tell the user - if (!loadedProfile.Name.Equals(ProfileRepository.CurrentProfile.Name)) - { - - MessageBox.Show( - @"The Display Profile used by this Shortcut still exists, but it's changed it's name. We've updated the shortcut's name to reflect this change.", - @"Display Profile name changed", - MessageBoxButtons.OK, - MessageBoxIcon.Exclamation); - } - - } - - } - + chosenProfile = ProfileRepository.GetActiveProfile(); ; }