From 1588cd6a0ba4515692cc346bbb8eca31b8a362cc Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 7 Mar 2021 14:50:52 +1300 Subject: [PATCH] Added Save to Desktop Profile Button Added a button to save a profile shortcut to the Windows desktop. This will enable people to quickly change to another display configuration if they want to using a desktop display. This will work even if they are unable to get admin rights to install the background popup menu. --- .../UIForms/DisplayProfileForm.Designer.cs | 33 +++++++- DisplayMagician/UIForms/DisplayProfileForm.cs | 60 +++++++++++++- .../UIForms/DisplayProfileForm.resx | 3 + .../DisplayMagicianShared.csproj | 11 +++ DisplayMagicianShared/ProfileItem.cs | 82 ++++++++++++++++--- 5 files changed, 175 insertions(+), 14 deletions(-) diff --git a/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs b/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs index 9b5b098..0e3b84d 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs @@ -55,6 +55,8 @@ namespace DisplayMagician.UIForms this.tt_selected = new System.Windows.Forms.ToolTip(this.components); this.lbl_save_profile = new System.Windows.Forms.Label(); this.dv_profile = new DisplayMagicianShared.UserControls.DisplayView(); + this.btn_save = new System.Windows.Forms.Button(); + this.dialog_save = new System.Windows.Forms.SaveFileDialog(); this.menu_profiles.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pb_down_arrow)).BeginInit(); this.SuspendLayout(); @@ -68,7 +70,7 @@ namespace DisplayMagician.UIForms this.btn_apply.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btn_apply.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_apply.ForeColor = System.Drawing.Color.White; - this.btn_apply.Location = new System.Drawing.Point(359, 750); + this.btn_apply.Location = new System.Drawing.Point(245, 752); this.btn_apply.Name = "btn_apply"; this.btn_apply.Size = new System.Drawing.Size(120, 40); this.btn_apply.TabIndex = 2; @@ -100,7 +102,7 @@ namespace DisplayMagician.UIForms this.btn_delete.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btn_delete.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_delete.ForeColor = System.Drawing.Color.White; - this.btn_delete.Location = new System.Drawing.Point(498, 750); + this.btn_delete.Location = new System.Drawing.Point(384, 752); this.btn_delete.Name = "btn_delete"; this.btn_delete.Size = new System.Drawing.Size(120, 40); this.btn_delete.TabIndex = 4; @@ -298,6 +300,30 @@ namespace DisplayMagician.UIForms this.dv_profile.Size = new System.Drawing.Size(976, 517); this.dv_profile.TabIndex = 4; // + // btn_save + // + this.btn_save.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.btn_save.BackColor = System.Drawing.Color.Black; + this.btn_save.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_save.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_save.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_save.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_save.ForeColor = System.Drawing.Color.White; + this.btn_save.Location = new System.Drawing.Point(521, 752); + this.btn_save.Name = "btn_save"; + this.btn_save.Size = new System.Drawing.Size(211, 40); + this.btn_save.TabIndex = 34; + this.btn_save.Text = "&Save to Desktop"; + this.btn_save.UseVisualStyleBackColor = false; + this.btn_save.Click += new System.EventHandler(this.Save_Click); + // + // dialog_save + // + this.dialog_save.DefaultExt = "lnk"; + this.dialog_save.DereferenceLinks = false; + this.dialog_save.Filter = global::DisplayMagician.Resources.Language.Shortcuts_Filter; + this.dialog_save.RestoreDirectory = true; + // // DisplayProfileForm // this.AcceptButton = this.btn_apply; @@ -307,6 +333,7 @@ namespace DisplayMagician.UIForms this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.CancelButton = this.btn_back; this.ClientSize = new System.Drawing.Size(976, 812); + this.Controls.Add(this.btn_save); this.Controls.Add(this.lbl_save_profile); this.Controls.Add(this.label1); this.Controls.Add(this.lbl_profile_shown_subtitle); @@ -360,6 +387,8 @@ namespace DisplayMagician.UIForms private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolTip tt_selected; private System.Windows.Forms.Label lbl_save_profile; + private System.Windows.Forms.Button btn_save; + private System.Windows.Forms.SaveFileDialog dialog_save; } } diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 3e11bb7..eb8e443 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -38,7 +38,7 @@ namespace DisplayMagician.UIForms private void Apply_Click(object sender, EventArgs e) { - if (!(_selectedProfile is ProfileItem)) + if (_selectedProfile == null) return; if (!_selectedProfile.IsPossible) @@ -65,7 +65,7 @@ namespace DisplayMagician.UIForms private void Delete_Click(object sender, EventArgs e) { - if (!(_selectedProfile is ProfileItem)) + if (_selectedProfile == null) return; if (MessageBox.Show($"Are you sure you want to delete the '{_selectedProfile.Name}' Display Profile?", $"Delete '{_selectedProfile.Name}' Display Profile?", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) @@ -110,6 +110,62 @@ namespace DisplayMagician.UIForms } + private void Save_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.None; + + // Only do something if there is a shortcut selected + if (_selectedProfile != null) + { + + // if shortcut is not valid then ask if the user + // really wants to save it to desktop + if (!_selectedProfile.IsPossible) + { + // We ask the user of they still want to save the desktop shortcut + if (MessageBox.Show($"The '{_selectedProfile.Name}' Desktop Profile isn't possible to use right now so a desktop shortcut wouldn't work until your Displays are changed to match the profile. Has your hardware or screen layout changed from when the Display Profile was made? Do you still want to save the desktop shortcut?", $"Still save the '{_selectedProfile.Name}' Display Profile?", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) + return; + } + + try + { + // Set the profile save folder to the Desktop as that's where people will want it most likely + dialog_save.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + // Try to set up some sensible suggestions for the profile name + dialog_save.FileName = _selectedProfile.Name; + + // Show the Save Profile window + if (dialog_save.ShowDialog(this) == DialogResult.OK) + { + if (_selectedProfile.CreateShortcut(dialog_save.FileName)) + { + MessageBox.Show( + String.Format(Language.Shortcut_placed_successfully, dialog_save.FileName), + Language.Shortcut, + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show( + Language.Failed_to_create_the_shortcut_Unexpected_exception_occurred, + Language.Shortcut, + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); + } + + dialog_save.FileName = string.Empty; + DialogResult = DialogResult.OK; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, Language.Shortcut, MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + } + + private void RefreshDisplayProfileUI() { diff --git a/DisplayMagician/UIForms/DisplayProfileForm.resx b/DisplayMagician/UIForms/DisplayProfileForm.resx index 838c7b0..d48d675 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.resx +++ b/DisplayMagician/UIForms/DisplayProfileForm.resx @@ -162,6 +162,9 @@ 248, 17 + + 358, 17 + iVBORw0KGgoAAAANSUhEUgAABHAAAALQCAIAAAB32BBZAAABgmlDQ1BzUkdCIElFQzYxOTY2LTIuMQAA diff --git a/DisplayMagicianShared/DisplayMagicianShared.csproj b/DisplayMagicianShared/DisplayMagicianShared.csproj index b86c43b..6d23c3c 100644 --- a/DisplayMagicianShared/DisplayMagicianShared.csproj +++ b/DisplayMagicianShared/DisplayMagicianShared.csproj @@ -134,6 +134,17 @@ + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + True + +