Added ability to copy Shortcut and all settings

This should help if a user has a really complicated shortcut and they want to make a copy to have two of them with slightly different tweaks.
This commit is contained in:
Terry MacDonald 2021-11-14 13:48:01 +13:00
parent 9083ec7b34
commit 058060ed60
6 changed files with 191 additions and 20 deletions

View File

@ -353,6 +353,34 @@ namespace DisplayMagician
return sc;
}
public static List<ShortcutBitmap> ShortcutBitmapClone(List<ShortcutBitmap> shortcutBitmaps)
{
// Clones the List<ShortcutBitmap>
List<ShortcutBitmap> scListToReturn = new List<ShortcutBitmap>();
foreach (ShortcutBitmap sc in shortcutBitmaps)
{
scListToReturn.Add(ImageUtils.ShortcutBitmapClone(sc));
}
return scListToReturn;
}
public static ShortcutBitmap ShortcutBitmapClone(ShortcutBitmap shortcutBitmap)
{
// Clones the ShortcutBitmap
ShortcutBitmap scToReturn = new ShortcutBitmap();
scToReturn.UUID = Guid.NewGuid().ToString("D");
scToReturn.Image = (Bitmap)shortcutBitmap.Image.Clone();
scToReturn.Name = shortcutBitmap.Name;
scToReturn.Order = shortcutBitmap.Order;
scToReturn.Size = shortcutBitmap.Size;
scToReturn.Source = shortcutBitmap.Source;
return scToReturn;
}
public static bool ImagesAreEqual(Bitmap imageA, Bitmap imageB)
{
byte[] image1Bytes;

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information
[assembly: AssemblyVersion("2.1.0.215")]
[assembly: AssemblyFileVersion("2.1.0.215")]
[assembly: AssemblyVersion("2.1.0.228")]
[assembly: AssemblyFileVersion("2.1.0.228")]
[assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)]

View File

@ -990,8 +990,7 @@ namespace DisplayMagician
// Copy all the shortcut data over to the other Shortcut
shortcut.Name = Name;
shortcut.ProfileToUse = ProfileToUse;
shortcut.ProfileUUID = ProfileUUID;
shortcut.AutoName = false; // Force the autoname to be off, as it's a copy.
shortcut.DisplayPermanence = DisplayPermanence;
shortcut.AudioPermanence = AudioPermanence;
shortcut.CapturePermanence = CapturePermanence;
@ -1008,16 +1007,9 @@ namespace DisplayMagician
shortcut.StartTimeout = StartTimeout;
shortcut.GameArguments = GameArguments;
shortcut.GameArgumentsRequired = GameArgumentsRequired;
shortcut.OriginalIconPath = OriginalIconPath;
shortcut.OriginalLargeBitmap = OriginalLargeBitmap;
shortcut.ShortcutBitmap = ShortcutBitmap;
shortcut.SavedShortcutIconCacheFilename = SavedShortcutIconCacheFilename;
shortcut.SelectedImage = SelectedImage;
shortcut.AvailableImages = AvailableImages;
shortcut.OriginalIconPath = OriginalIconPath;
shortcut.IsValid = IsValid;
shortcut.Errors.AddRange(Errors);
shortcut.StartPrograms = StartPrograms;
shortcut.StopPrograms = StopPrograms;
shortcut.ChangeAudioDevice = ChangeAudioDevice;
shortcut.AudioDevice = AudioDevice;
shortcut.SetAudioVolume = SetAudioVolume;
@ -1026,10 +1018,53 @@ namespace DisplayMagician
shortcut.CaptureDevice = CaptureDevice;
shortcut.SetCaptureVolume = SetCaptureVolume;
shortcut.CaptureVolume = CaptureVolume;
shortcut.Hotkey = Hotkey;
// shortcut.Hotkey = Hotkey; // We cannot duplicate the Hotkey as it breaks things
// Duplicate the Images
shortcut.OriginalLargeBitmap = (Bitmap)OriginalLargeBitmap.Clone();
shortcut.ShortcutBitmap = (Bitmap)ShortcutBitmap.Clone();
//shortcut.SavedShortcutIconCacheFilename = SavedShortcutIconCacheFilename; // We want a new shortcut icon!
shortcut.SelectedImage = ImageUtils.ShortcutBitmapClone(SelectedImage);
shortcut.AvailableImages = ImageUtils.ShortcutBitmapClone(AvailableImages);
// Duplicate the start programs
shortcut.StartPrograms = new List<StartProgram>();
foreach (StartProgram sp in StartPrograms)
{
StartProgram copiedStartProgram = new StartProgram();
copiedStartProgram.Arguments = sp.Arguments;
copiedStartProgram.CloseOnFinish = sp.CloseOnFinish;
copiedStartProgram.Disabled = sp.Disabled;
copiedStartProgram.DontStartIfAlreadyRunning = sp.DontStartIfAlreadyRunning;
copiedStartProgram.Executable = sp.Executable;
copiedStartProgram.ExecutableArgumentsRequired = sp.ExecutableArgumentsRequired;
copiedStartProgram.Priority = sp.Priority;
copiedStartProgram.ProcessPriority = sp.ProcessPriority;
shortcut.StartPrograms.Add(copiedStartProgram);
}
// Duplicate the stop programs
shortcut.StopPrograms = new List<StopProgram>();
foreach (StopProgram sp in StopPrograms)
{
StopProgram copiedStopProgram = new StopProgram();
copiedStopProgram.Arguments = sp.Arguments;
copiedStopProgram.Disabled = sp.Disabled;
copiedStopProgram.DontStartIfAlreadyRunning = sp.DontStartIfAlreadyRunning;
copiedStopProgram.Executable = sp.Executable;
copiedStopProgram.ExecutableArgumentsRequired = sp.ExecutableArgumentsRequired;
copiedStopProgram.Priority = sp.Priority;
copiedStopProgram.ProcessPriority = sp.ProcessPriority;
shortcut.StopPrograms.Add(copiedStopProgram);
}
// Do the profiles last as AutoName will error if done earlier
shortcut.ProfileToUse = ProfileToUse;
shortcut.ProfileUUID = ProfileUUID;
// Save the shortcut incon to the icon cache
shortcut.ReplaceShortcutIconInCache();
shortcut.SaveShortcutIconToCache();
shortcut.RefreshValidity();
return true;

View File

@ -356,6 +356,45 @@ namespace DisplayMagician
return true;
}
public static bool CopyShortcut(ShortcutItem shortcut, out ShortcutItem copiedShortcut)
{
logger.Trace($"ShortcutRepository/CopyShortcut: Checking whether {shortcut.Name} exists in our shortcut repository");
copiedShortcut = new ShortcutItem();
if (!(shortcut is ShortcutItem))
return false;
if (shortcut.CopyTo(copiedShortcut,false))
{
// Copy worked!
// We add (Copy) to the end of the shortcut name
copiedShortcut.Name = copiedShortcut.Name + " (Copy)";
// Add the shortcut to the list of shortcuts
_allShortcuts.Add(copiedShortcut);
//Doublecheck it's been added
if (ContainsShortcut(copiedShortcut))
{
// Select the copied shortcut
// Save the shortcuts JSON as it's different
SaveShortcuts();
IsValidRefresh();
return true;
}
else
return false;
}
else
{
// Copy failed
return false;
}
}
private static bool LoadShortcuts()
{

View File

@ -45,10 +45,12 @@
this.tsmi_edit = new System.Windows.Forms.ToolStripMenuItem();
this.tsmi_run = new System.Windows.Forms.ToolStripMenuItem();
this.tsmi_save_to_desktop = new System.Windows.Forms.ToolStripMenuItem();
this.tsmi_copy = new System.Windows.Forms.ToolStripMenuItem();
this.tsmi_delete = new System.Windows.Forms.ToolStripMenuItem();
this.lbl_mask = new System.Windows.Forms.Label();
this.btn_help = new System.Windows.Forms.Button();
this.btn_donate = new System.Windows.Forms.Button();
this.btn_copy = new System.Windows.Forms.Button();
this.cms_shortcuts.SuspendLayout();
this.SuspendLayout();
//
@ -82,7 +84,7 @@
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(462, 643);
this.btn_delete.Location = new System.Drawing.Point(377, 643);
this.btn_delete.Name = "btn_delete";
this.btn_delete.Size = new System.Drawing.Size(120, 40);
this.btn_delete.TabIndex = 26;
@ -115,7 +117,7 @@
this.btn_run.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_run.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_run.ForeColor = System.Drawing.Color.White;
this.btn_run.Location = new System.Drawing.Point(588, 643);
this.btn_run.Location = new System.Drawing.Point(629, 643);
this.btn_run.Name = "btn_run";
this.btn_run.Size = new System.Drawing.Size(120, 40);
this.btn_run.TabIndex = 25;
@ -132,7 +134,7 @@
this.btn_edit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_edit.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_edit.ForeColor = System.Drawing.Color.White;
this.btn_edit.Location = new System.Drawing.Point(336, 643);
this.btn_edit.Location = new System.Drawing.Point(251, 643);
this.btn_edit.Name = "btn_edit";
this.btn_edit.Size = new System.Drawing.Size(120, 40);
this.btn_edit.TabIndex = 28;
@ -149,7 +151,7 @@
this.btn_new.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_new.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_new.ForeColor = System.Drawing.Color.White;
this.btn_new.Location = new System.Drawing.Point(210, 643);
this.btn_new.Location = new System.Drawing.Point(125, 643);
this.btn_new.Name = "btn_new";
this.btn_new.Size = new System.Drawing.Size(120, 40);
this.btn_new.TabIndex = 29;
@ -166,7 +168,7 @@
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(714, 643);
this.btn_save.Location = new System.Drawing.Point(755, 643);
this.btn_save.Name = "btn_save";
this.btn_save.Size = new System.Drawing.Size(211, 40);
this.btn_save.TabIndex = 30;
@ -214,9 +216,10 @@
this.tsmi_edit,
this.tsmi_run,
this.tsmi_save_to_desktop,
this.tsmi_copy,
this.tsmi_delete});
this.cms_shortcuts.Name = "cms_shortcuts";
this.cms_shortcuts.Size = new System.Drawing.Size(216, 92);
this.cms_shortcuts.Size = new System.Drawing.Size(216, 136);
//
// tsmi_edit
//
@ -241,6 +244,13 @@
this.tsmi_save_to_desktop.Text = "Save Shortcut to Desktop...";
this.tsmi_save_to_desktop.Click += new System.EventHandler(this.tsmi_save_to_desktop_Click);
//
// tsmi_copy
//
this.tsmi_copy.Name = "tsmi_copy";
this.tsmi_copy.Size = new System.Drawing.Size(215, 22);
this.tsmi_copy.Text = "Copy Shortcut...";
this.tsmi_copy.Click += new System.EventHandler(this.tsmi_copy_Click);
//
// tsmi_delete
//
this.tsmi_delete.Name = "tsmi_delete";
@ -296,6 +306,23 @@
this.btn_donate.UseVisualStyleBackColor = true;
this.btn_donate.Click += new System.EventHandler(this.btn_donate_Click);
//
// btn_copy
//
this.btn_copy.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.btn_copy.BackColor = System.Drawing.Color.Black;
this.btn_copy.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed;
this.btn_copy.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown;
this.btn_copy.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_copy.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_copy.ForeColor = System.Drawing.Color.White;
this.btn_copy.Location = new System.Drawing.Point(503, 643);
this.btn_copy.Name = "btn_copy";
this.btn_copy.Size = new System.Drawing.Size(120, 40);
this.btn_copy.TabIndex = 36;
this.btn_copy.Text = "&Copy";
this.btn_copy.UseVisualStyleBackColor = false;
this.btn_copy.Click += new System.EventHandler(this.btn_copy_Click);
//
// ShortcutLibraryForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -303,6 +330,7 @@
this.BackColor = System.Drawing.Color.Black;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(1134, 716);
this.Controls.Add(this.btn_copy);
this.Controls.Add(this.btn_donate);
this.Controls.Add(this.btn_help);
this.Controls.Add(this.lbl_mask);
@ -353,5 +381,7 @@
private System.Windows.Forms.Label lbl_mask;
private System.Windows.Forms.Button btn_help;
private System.Windows.Forms.Button btn_donate;
private System.Windows.Forms.Button btn_copy;
private System.Windows.Forms.ToolStripMenuItem tsmi_copy;
}
}

View File

@ -497,6 +497,11 @@ namespace DisplayMagician.UIForms
btn_delete.PerformClick();
}
private void tsmi_copy_Click(object sender, EventArgs e)
{
btn_copy.PerformClick();
}
private void ShortcutLibraryForm_KeyPress(object sender, KeyPressEventArgs e)
{
if (lbl_mask.Visible == true)
@ -520,5 +525,39 @@ namespace DisplayMagician.UIForms
string targetURL = @"https://github.com/sponsors/terrymacdonald";
System.Diagnostics.Process.Start(targetURL);
}
private void btn_copy_Click(object sender, EventArgs e)
{
if (_selectedShortcut == null)
{
if (ShortcutRepository.ShortcutCount > 0)
{
MessageBox.Show(
@"You need to select a Game Shortcut in order to copy it. Please select a Game Shortcut then try again, or right-click on the Game Shortcut and select 'Copy Shortcut'.",
@"Select Game Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else
{
MessageBox.Show(
@"You need to create a Game Shortcut in order to copy it. Please create a Game Shortcut by clicking the New button.",
@"Create Game Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else
{
ShortcutItem copiedShortcut;
// Copy the shortcut
ShortcutRepository.CopyShortcut(_selectedShortcut, out copiedShortcut);
// Select the new copied shortcut
_selectedShortcut = copiedShortcut;
// Invalidate the list of shortcuts so it gets redrawn again with the copy included!
ilv_saved_shortcuts.Invalidate();
// Refresh the UI
RefreshShortcutLibraryUI();
}
}
}
}