diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs index 3a962d4..9b6f955 100755 --- a/ShortcutUtil/Program.cs +++ b/ShortcutUtil/Program.cs @@ -41,7 +41,7 @@ return; } - Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1])); Application.EnableVisualStyles(); diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs index 3a962d4..9b6f955 100755 --- a/ShortcutUtil/Program.cs +++ b/ShortcutUtil/Program.cs @@ -41,7 +41,7 @@ return; } - Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1])); Application.EnableVisualStyles(); diff --git a/ShortcutUtil/SearchForm.Designer.cs b/ShortcutUtil/SearchForm.Designer.cs new file mode 100755 index 0000000..93f58bf --- /dev/null +++ b/ShortcutUtil/SearchForm.Designer.cs @@ -0,0 +1,111 @@ +namespace ShortcutUtil +{ + partial class SearchForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.searchLabel = new System.Windows.Forms.Label(); + this.optionsLabel = new System.Windows.Forms.Label(); + this.optionsList = new System.Windows.Forms.ListBox(); + this.selectButton = new System.Windows.Forms.Button(); + this.searchBox = new ShortcutUtil.WatermarkTextBox(); + this.SuspendLayout(); + // + // searchLabel + // + this.searchLabel.AutoSize = true; + this.searchLabel.Location = new System.Drawing.Point(13, 13); + this.searchLabel.Name = "searchLabel"; + this.searchLabel.Size = new System.Drawing.Size(94, 20); + this.searchLabel.TabIndex = 0; + this.searchLabel.Text = "Search text:"; + // + // optionsLabel + // + this.optionsLabel.AutoSize = true; + this.optionsLabel.Location = new System.Drawing.Point(13, 80); + this.optionsLabel.Name = "optionsLabel"; + this.optionsLabel.Size = new System.Drawing.Size(68, 20); + this.optionsLabel.TabIndex = 2; + this.optionsLabel.Text = "Options:"; + // + // optionsList + // + this.optionsList.FormattingEnabled = true; + this.optionsList.ItemHeight = 20; + this.optionsList.Location = new System.Drawing.Point(17, 104); + this.optionsList.Name = "optionsList"; + this.optionsList.Size = new System.Drawing.Size(771, 304); + this.optionsList.TabIndex = 3; + // + // selectButton + // + this.selectButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.selectButton.Location = new System.Drawing.Point(661, 414); + this.selectButton.Name = "selectButton"; + this.selectButton.Size = new System.Drawing.Size(127, 41); + this.selectButton.TabIndex = 4; + this.selectButton.Text = "Select"; + this.selectButton.UseVisualStyleBackColor = true; + // + // searchBox + // + this.searchBox.Location = new System.Drawing.Point(17, 37); + this.searchBox.Name = "searchBox"; + this.searchBox.Size = new System.Drawing.Size(771, 26); + this.searchBox.TabIndex = 1; + this.searchBox.WaterMarkColor = System.Drawing.Color.Gray; + this.searchBox.WaterMarkText = "Match text here"; + this.searchBox.TextChanged += new System.EventHandler(this.searchBox_TextChanged); + // + // SearchForm + // + this.AcceptButton = this.selectButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 463); + this.Controls.Add(this.selectButton); + this.Controls.Add(this.optionsList); + this.Controls.Add(this.optionsLabel); + this.Controls.Add(this.searchBox); + this.Controls.Add(this.searchLabel); + this.Name = "SearchForm"; + this.Text = "Search"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label searchLabel; + private System.Windows.Forms.Label optionsLabel; + private System.Windows.Forms.ListBox optionsList; + private System.Windows.Forms.Button selectButton; + private WatermarkTextBox searchBox; + } +} \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs index 3a962d4..9b6f955 100755 --- a/ShortcutUtil/Program.cs +++ b/ShortcutUtil/Program.cs @@ -41,7 +41,7 @@ return; } - Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1])); Application.EnableVisualStyles(); diff --git a/ShortcutUtil/SearchForm.Designer.cs b/ShortcutUtil/SearchForm.Designer.cs new file mode 100755 index 0000000..93f58bf --- /dev/null +++ b/ShortcutUtil/SearchForm.Designer.cs @@ -0,0 +1,111 @@ +namespace ShortcutUtil +{ + partial class SearchForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.searchLabel = new System.Windows.Forms.Label(); + this.optionsLabel = new System.Windows.Forms.Label(); + this.optionsList = new System.Windows.Forms.ListBox(); + this.selectButton = new System.Windows.Forms.Button(); + this.searchBox = new ShortcutUtil.WatermarkTextBox(); + this.SuspendLayout(); + // + // searchLabel + // + this.searchLabel.AutoSize = true; + this.searchLabel.Location = new System.Drawing.Point(13, 13); + this.searchLabel.Name = "searchLabel"; + this.searchLabel.Size = new System.Drawing.Size(94, 20); + this.searchLabel.TabIndex = 0; + this.searchLabel.Text = "Search text:"; + // + // optionsLabel + // + this.optionsLabel.AutoSize = true; + this.optionsLabel.Location = new System.Drawing.Point(13, 80); + this.optionsLabel.Name = "optionsLabel"; + this.optionsLabel.Size = new System.Drawing.Size(68, 20); + this.optionsLabel.TabIndex = 2; + this.optionsLabel.Text = "Options:"; + // + // optionsList + // + this.optionsList.FormattingEnabled = true; + this.optionsList.ItemHeight = 20; + this.optionsList.Location = new System.Drawing.Point(17, 104); + this.optionsList.Name = "optionsList"; + this.optionsList.Size = new System.Drawing.Size(771, 304); + this.optionsList.TabIndex = 3; + // + // selectButton + // + this.selectButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.selectButton.Location = new System.Drawing.Point(661, 414); + this.selectButton.Name = "selectButton"; + this.selectButton.Size = new System.Drawing.Size(127, 41); + this.selectButton.TabIndex = 4; + this.selectButton.Text = "Select"; + this.selectButton.UseVisualStyleBackColor = true; + // + // searchBox + // + this.searchBox.Location = new System.Drawing.Point(17, 37); + this.searchBox.Name = "searchBox"; + this.searchBox.Size = new System.Drawing.Size(771, 26); + this.searchBox.TabIndex = 1; + this.searchBox.WaterMarkColor = System.Drawing.Color.Gray; + this.searchBox.WaterMarkText = "Match text here"; + this.searchBox.TextChanged += new System.EventHandler(this.searchBox_TextChanged); + // + // SearchForm + // + this.AcceptButton = this.selectButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 463); + this.Controls.Add(this.selectButton); + this.Controls.Add(this.optionsList); + this.Controls.Add(this.optionsLabel); + this.Controls.Add(this.searchBox); + this.Controls.Add(this.searchLabel); + this.Name = "SearchForm"; + this.Text = "Search"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label searchLabel; + private System.Windows.Forms.Label optionsLabel; + private System.Windows.Forms.ListBox optionsList; + private System.Windows.Forms.Button selectButton; + private WatermarkTextBox searchBox; + } +} \ No newline at end of file diff --git a/ShortcutUtil/SearchForm.cs b/ShortcutUtil/SearchForm.cs new file mode 100755 index 0000000..3253ac5 --- /dev/null +++ b/ShortcutUtil/SearchForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class SearchForm : Form + { + public SearchForm() + { + InitializeComponent(); + } + + private List allOptions = new List(); + private List> displayOptions = new List>(); + + public T GetSelection(string title, string optionsName, List> options) where T : class + { + allOptions = options.Select(s => s.Item2).ToList(); + + Text = title; + optionsLabel.Text = optionsName; + + if (searchBox.Text != "") + { + searchBox.Text = ""; + } + else + { + UpdateDisplay(); + } + + if (ShowDialog() == DialogResult.OK && optionsList.SelectedIndex >= 0 && optionsList.SelectedIndex < displayOptions.Count) + { + return options[displayOptions[optionsList.SelectedIndex].Item2].Item1; + } + + return null; + } + + private void UpdateDisplay() + { + string search = searchBox.Text.Trim().ToLower(); + displayOptions = allOptions.Select((s, index) => new Tuple(s, index)).Where(s => s.Item1.ToLower().Contains(search)).ToList(); + + optionsList.Items.Clear(); + optionsList.Items.AddRange(displayOptions.Select(o => o.Item1).ToArray()); + } + + private void searchBox_TextChanged(object sender, EventArgs e) + { + UpdateDisplay(); + } + } +} diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs index 3a962d4..9b6f955 100755 --- a/ShortcutUtil/Program.cs +++ b/ShortcutUtil/Program.cs @@ -41,7 +41,7 @@ return; } - Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1])); Application.EnableVisualStyles(); diff --git a/ShortcutUtil/SearchForm.Designer.cs b/ShortcutUtil/SearchForm.Designer.cs new file mode 100755 index 0000000..93f58bf --- /dev/null +++ b/ShortcutUtil/SearchForm.Designer.cs @@ -0,0 +1,111 @@ +namespace ShortcutUtil +{ + partial class SearchForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.searchLabel = new System.Windows.Forms.Label(); + this.optionsLabel = new System.Windows.Forms.Label(); + this.optionsList = new System.Windows.Forms.ListBox(); + this.selectButton = new System.Windows.Forms.Button(); + this.searchBox = new ShortcutUtil.WatermarkTextBox(); + this.SuspendLayout(); + // + // searchLabel + // + this.searchLabel.AutoSize = true; + this.searchLabel.Location = new System.Drawing.Point(13, 13); + this.searchLabel.Name = "searchLabel"; + this.searchLabel.Size = new System.Drawing.Size(94, 20); + this.searchLabel.TabIndex = 0; + this.searchLabel.Text = "Search text:"; + // + // optionsLabel + // + this.optionsLabel.AutoSize = true; + this.optionsLabel.Location = new System.Drawing.Point(13, 80); + this.optionsLabel.Name = "optionsLabel"; + this.optionsLabel.Size = new System.Drawing.Size(68, 20); + this.optionsLabel.TabIndex = 2; + this.optionsLabel.Text = "Options:"; + // + // optionsList + // + this.optionsList.FormattingEnabled = true; + this.optionsList.ItemHeight = 20; + this.optionsList.Location = new System.Drawing.Point(17, 104); + this.optionsList.Name = "optionsList"; + this.optionsList.Size = new System.Drawing.Size(771, 304); + this.optionsList.TabIndex = 3; + // + // selectButton + // + this.selectButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.selectButton.Location = new System.Drawing.Point(661, 414); + this.selectButton.Name = "selectButton"; + this.selectButton.Size = new System.Drawing.Size(127, 41); + this.selectButton.TabIndex = 4; + this.selectButton.Text = "Select"; + this.selectButton.UseVisualStyleBackColor = true; + // + // searchBox + // + this.searchBox.Location = new System.Drawing.Point(17, 37); + this.searchBox.Name = "searchBox"; + this.searchBox.Size = new System.Drawing.Size(771, 26); + this.searchBox.TabIndex = 1; + this.searchBox.WaterMarkColor = System.Drawing.Color.Gray; + this.searchBox.WaterMarkText = "Match text here"; + this.searchBox.TextChanged += new System.EventHandler(this.searchBox_TextChanged); + // + // SearchForm + // + this.AcceptButton = this.selectButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 463); + this.Controls.Add(this.selectButton); + this.Controls.Add(this.optionsList); + this.Controls.Add(this.optionsLabel); + this.Controls.Add(this.searchBox); + this.Controls.Add(this.searchLabel); + this.Name = "SearchForm"; + this.Text = "Search"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label searchLabel; + private System.Windows.Forms.Label optionsLabel; + private System.Windows.Forms.ListBox optionsList; + private System.Windows.Forms.Button selectButton; + private WatermarkTextBox searchBox; + } +} \ No newline at end of file diff --git a/ShortcutUtil/SearchForm.cs b/ShortcutUtil/SearchForm.cs new file mode 100755 index 0000000..3253ac5 --- /dev/null +++ b/ShortcutUtil/SearchForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class SearchForm : Form + { + public SearchForm() + { + InitializeComponent(); + } + + private List allOptions = new List(); + private List> displayOptions = new List>(); + + public T GetSelection(string title, string optionsName, List> options) where T : class + { + allOptions = options.Select(s => s.Item2).ToList(); + + Text = title; + optionsLabel.Text = optionsName; + + if (searchBox.Text != "") + { + searchBox.Text = ""; + } + else + { + UpdateDisplay(); + } + + if (ShowDialog() == DialogResult.OK && optionsList.SelectedIndex >= 0 && optionsList.SelectedIndex < displayOptions.Count) + { + return options[displayOptions[optionsList.SelectedIndex].Item2].Item1; + } + + return null; + } + + private void UpdateDisplay() + { + string search = searchBox.Text.Trim().ToLower(); + displayOptions = allOptions.Select((s, index) => new Tuple(s, index)).Where(s => s.Item1.ToLower().Contains(search)).ToList(); + + optionsList.Items.Clear(); + optionsList.Items.AddRange(displayOptions.Select(o => o.Item1).ToArray()); + } + + private void searchBox_TextChanged(object sender, EventArgs e) + { + UpdateDisplay(); + } + } +} diff --git a/ShortcutUtil/SearchForm.resx b/ShortcutUtil/SearchForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/SearchForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs index 3a962d4..9b6f955 100755 --- a/ShortcutUtil/Program.cs +++ b/ShortcutUtil/Program.cs @@ -41,7 +41,7 @@ return; } - Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1])); Application.EnableVisualStyles(); diff --git a/ShortcutUtil/SearchForm.Designer.cs b/ShortcutUtil/SearchForm.Designer.cs new file mode 100755 index 0000000..93f58bf --- /dev/null +++ b/ShortcutUtil/SearchForm.Designer.cs @@ -0,0 +1,111 @@ +namespace ShortcutUtil +{ + partial class SearchForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.searchLabel = new System.Windows.Forms.Label(); + this.optionsLabel = new System.Windows.Forms.Label(); + this.optionsList = new System.Windows.Forms.ListBox(); + this.selectButton = new System.Windows.Forms.Button(); + this.searchBox = new ShortcutUtil.WatermarkTextBox(); + this.SuspendLayout(); + // + // searchLabel + // + this.searchLabel.AutoSize = true; + this.searchLabel.Location = new System.Drawing.Point(13, 13); + this.searchLabel.Name = "searchLabel"; + this.searchLabel.Size = new System.Drawing.Size(94, 20); + this.searchLabel.TabIndex = 0; + this.searchLabel.Text = "Search text:"; + // + // optionsLabel + // + this.optionsLabel.AutoSize = true; + this.optionsLabel.Location = new System.Drawing.Point(13, 80); + this.optionsLabel.Name = "optionsLabel"; + this.optionsLabel.Size = new System.Drawing.Size(68, 20); + this.optionsLabel.TabIndex = 2; + this.optionsLabel.Text = "Options:"; + // + // optionsList + // + this.optionsList.FormattingEnabled = true; + this.optionsList.ItemHeight = 20; + this.optionsList.Location = new System.Drawing.Point(17, 104); + this.optionsList.Name = "optionsList"; + this.optionsList.Size = new System.Drawing.Size(771, 304); + this.optionsList.TabIndex = 3; + // + // selectButton + // + this.selectButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.selectButton.Location = new System.Drawing.Point(661, 414); + this.selectButton.Name = "selectButton"; + this.selectButton.Size = new System.Drawing.Size(127, 41); + this.selectButton.TabIndex = 4; + this.selectButton.Text = "Select"; + this.selectButton.UseVisualStyleBackColor = true; + // + // searchBox + // + this.searchBox.Location = new System.Drawing.Point(17, 37); + this.searchBox.Name = "searchBox"; + this.searchBox.Size = new System.Drawing.Size(771, 26); + this.searchBox.TabIndex = 1; + this.searchBox.WaterMarkColor = System.Drawing.Color.Gray; + this.searchBox.WaterMarkText = "Match text here"; + this.searchBox.TextChanged += new System.EventHandler(this.searchBox_TextChanged); + // + // SearchForm + // + this.AcceptButton = this.selectButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 463); + this.Controls.Add(this.selectButton); + this.Controls.Add(this.optionsList); + this.Controls.Add(this.optionsLabel); + this.Controls.Add(this.searchBox); + this.Controls.Add(this.searchLabel); + this.Name = "SearchForm"; + this.Text = "Search"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label searchLabel; + private System.Windows.Forms.Label optionsLabel; + private System.Windows.Forms.ListBox optionsList; + private System.Windows.Forms.Button selectButton; + private WatermarkTextBox searchBox; + } +} \ No newline at end of file diff --git a/ShortcutUtil/SearchForm.cs b/ShortcutUtil/SearchForm.cs new file mode 100755 index 0000000..3253ac5 --- /dev/null +++ b/ShortcutUtil/SearchForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class SearchForm : Form + { + public SearchForm() + { + InitializeComponent(); + } + + private List allOptions = new List(); + private List> displayOptions = new List>(); + + public T GetSelection(string title, string optionsName, List> options) where T : class + { + allOptions = options.Select(s => s.Item2).ToList(); + + Text = title; + optionsLabel.Text = optionsName; + + if (searchBox.Text != "") + { + searchBox.Text = ""; + } + else + { + UpdateDisplay(); + } + + if (ShowDialog() == DialogResult.OK && optionsList.SelectedIndex >= 0 && optionsList.SelectedIndex < displayOptions.Count) + { + return options[displayOptions[optionsList.SelectedIndex].Item2].Item1; + } + + return null; + } + + private void UpdateDisplay() + { + string search = searchBox.Text.Trim().ToLower(); + displayOptions = allOptions.Select((s, index) => new Tuple(s, index)).Where(s => s.Item1.ToLower().Contains(search)).ToList(); + + optionsList.Items.Clear(); + optionsList.Items.AddRange(displayOptions.Select(o => o.Item1).ToArray()); + } + + private void searchBox_TextChanged(object sender, EventArgs e) + { + UpdateDisplay(); + } + } +} diff --git a/ShortcutUtil/SearchForm.resx b/ShortcutUtil/SearchForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/SearchForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/ShortcutUtil.csproj b/ShortcutUtil/ShortcutUtil.csproj index a9c0bce..87a451f 100755 --- a/ShortcutUtil/ShortcutUtil.csproj +++ b/ShortcutUtil/ShortcutUtil.csproj @@ -51,6 +51,10 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + False + ..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll + ..\packages\System.Text.Encodings.Web.4.7.1\lib\net461\System.Text.Encodings.Web.dll @@ -72,6 +76,9 @@ + + ..\..\..\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd + @@ -86,6 +93,15 @@ + + Form + + + SearchForm.cs + + + Component + MainForm.cs @@ -98,6 +114,9 @@ True Resources.resx + + SearchForm.cs + SettingsSingleFileGenerator @@ -112,5 +131,8 @@ + + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs index dd43a65..f6af196 100755 --- a/EntryList.cs +++ b/EntryList.cs @@ -9,7 +9,7 @@ namespace Entries { public class Entry - { + { public string Target { get; set; } public string Icon { get; set; } public int IconIndex { get; set; } @@ -19,6 +19,7 @@ public class EntryList { + public string FilePath = null; public List Entries; public static EntryList FromString(string contents) @@ -34,7 +35,10 @@ { contents = new StreamReader(input).ReadToEnd(); } - return FromString(contents); + EntryList entryList = FromString(contents); + if (entryList != null) entryList.FilePath = Path.GetFullPath(path); + + return entryList; } public override string ToString() diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs index fbb1aee..5dbf023 100755 --- a/ShortcutUtil/MainForm.Designer.cs +++ b/ShortcutUtil/MainForm.Designer.cs @@ -28,49 +28,95 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); + this.defaultShortcutLabel = new System.Windows.Forms.Label(); this.entryListBox = new System.Windows.Forms.ListBox(); this.createButton = new System.Windows.Forms.Button(); + this.appUserModelIdLabel = new System.Windows.Forms.Label(); + this.appUserModelIdBox = new ShortcutUtil.WatermarkTextBox(); + this.appButton = new System.Windows.Forms.Button(); + this.hwndButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 + // defaultShortcutLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(169, 20); - this.label1.TabIndex = 0; - this.label1.Text = "Select default shortcut"; + this.defaultShortcutLabel.AutoSize = true; + this.defaultShortcutLabel.Location = new System.Drawing.Point(14, 75); + this.defaultShortcutLabel.Name = "defaultShortcutLabel"; + this.defaultShortcutLabel.Size = new System.Drawing.Size(169, 20); + this.defaultShortcutLabel.TabIndex = 0; + this.defaultShortcutLabel.Text = "Select default shortcut"; // // entryListBox // this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this.entryListBox.FormattingEnabled = true; - this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Location = new System.Drawing.Point(16, 98); this.entryListBox.Name = "entryListBox"; - this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.Size = new System.Drawing.Size(770, 355); this.entryListBox.TabIndex = 1; this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); // // createButton // - this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Location = new System.Drawing.Point(644, 458); this.createButton.Name = "createButton"; this.createButton.Size = new System.Drawing.Size(144, 40); this.createButton.TabIndex = 2; this.createButton.Text = "Create Shortcut"; this.createButton.UseVisualStyleBackColor = true; // + // appUserModelIdLabel + // + this.appUserModelIdLabel.AutoSize = true; + this.appUserModelIdLabel.Location = new System.Drawing.Point(14, 12); + this.appUserModelIdLabel.Name = "appUserModelIdLabel"; + this.appUserModelIdLabel.Size = new System.Drawing.Size(213, 20); + this.appUserModelIdLabel.TabIndex = 3; + this.appUserModelIdLabel.Text = "Shortcut App User Model ID:"; + // + // appUserModelIdBox + // + this.appUserModelIdBox.Location = new System.Drawing.Point(16, 35); + this.appUserModelIdBox.Name = "appUserModelIdBox"; + this.appUserModelIdBox.Size = new System.Drawing.Size(608, 26); + this.appUserModelIdBox.TabIndex = 4; + this.appUserModelIdBox.WaterMarkColor = System.Drawing.Color.Gray; + this.appUserModelIdBox.WaterMarkText = "Enter a manual ID, or select on from a UWP App or open Window"; + // + // appButton + // + this.appButton.Location = new System.Drawing.Point(633, 35); + this.appButton.Name = "appButton"; + this.appButton.Size = new System.Drawing.Size(74, 31); + this.appButton.TabIndex = 5; + this.appButton.Text = "APP"; + this.appButton.UseVisualStyleBackColor = true; + this.appButton.Click += new System.EventHandler(this.appButton_Click); + // + // hwndButton + // + this.hwndButton.Location = new System.Drawing.Point(712, 35); + this.hwndButton.MinimumSize = new System.Drawing.Size(76, 26); + this.hwndButton.Name = "hwndButton"; + this.hwndButton.Size = new System.Drawing.Size(76, 31); + this.hwndButton.TabIndex = 6; + this.hwndButton.Text = "HWND"; + this.hwndButton.UseVisualStyleBackColor = true; + // // MainForm // this.AcceptButton = this.createButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 444); + this.ClientSize = new System.Drawing.Size(800, 508); + this.Controls.Add(this.hwndButton); + this.Controls.Add(this.appButton); + this.Controls.Add(this.appUserModelIdBox); + this.Controls.Add(this.appUserModelIdLabel); this.Controls.Add(this.createButton); this.Controls.Add(this.entryListBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.defaultShortcutLabel); this.Name = "MainForm"; this.Text = "Form1"; this.Shown += new System.EventHandler(this.MainForm_Shown); @@ -82,9 +128,13 @@ #endregion - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label defaultShortcutLabel; private System.Windows.Forms.ListBox entryListBox; private System.Windows.Forms.Button createButton; + private System.Windows.Forms.Label appUserModelIdLabel; + private System.Windows.Forms.Button appButton; + private System.Windows.Forms.Button hwndButton; + private WatermarkTextBox appUserModelIdBox; } } diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs index cb5990a..680ed45 100755 --- a/ShortcutUtil/MainForm.cs +++ b/ShortcutUtil/MainForm.cs @@ -9,6 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ShortcutUtil { @@ -28,13 +31,20 @@ { InitializeComponent(); - defaultFont = label1.Font; + Text = entryList.FilePath == null ? "New shortcut file" : entryList.FilePath; + + defaultFont = defaultShortcutLabel.Font; nameFont = new Font(defaultFont, FontStyle.Bold); - fontBrush = new SolidBrush(label1.ForeColor); + fontBrush = new SolidBrush(defaultShortcutLabel.ForeColor); this.entryList = entryList; entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + + if (this.entryList.Entries.Count > 0) + { + entryListBox.SelectedIndex = 0; + } } private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); @@ -128,5 +138,33 @@ shown = true; } + + private SearchForm search = new SearchForm(); + private async void appButton_Click(object sender, EventArgs e) + { + appButton.Enabled = false; + + PackageManager pm = new PackageManager(); + + List> options = new List>(); + + foreach (Package p in pm.FindPackagesForUser(string.Empty)) + { + var apps = await p.GetAppListEntriesAsync().AsTask(); + foreach (AppListEntry app in apps) + { + options.Add(new Tuple(app.AppUserModelId, app.DisplayInfo.DisplayName + ": " + app.AppUserModelId)); + } + } + + string selectedAppUserModelId = search.GetSelection("Select UWP App", "Available Apps:", options); + + if (selectedAppUserModelId != null) + { + appUserModelIdBox.Text = selectedAppUserModelId; + } + + appButton.Enabled = true; + } } } diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs index 3a962d4..9b6f955 100755 --- a/ShortcutUtil/Program.cs +++ b/ShortcutUtil/Program.cs @@ -41,7 +41,7 @@ return; } - Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1])); Application.EnableVisualStyles(); diff --git a/ShortcutUtil/SearchForm.Designer.cs b/ShortcutUtil/SearchForm.Designer.cs new file mode 100755 index 0000000..93f58bf --- /dev/null +++ b/ShortcutUtil/SearchForm.Designer.cs @@ -0,0 +1,111 @@ +namespace ShortcutUtil +{ + partial class SearchForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.searchLabel = new System.Windows.Forms.Label(); + this.optionsLabel = new System.Windows.Forms.Label(); + this.optionsList = new System.Windows.Forms.ListBox(); + this.selectButton = new System.Windows.Forms.Button(); + this.searchBox = new ShortcutUtil.WatermarkTextBox(); + this.SuspendLayout(); + // + // searchLabel + // + this.searchLabel.AutoSize = true; + this.searchLabel.Location = new System.Drawing.Point(13, 13); + this.searchLabel.Name = "searchLabel"; + this.searchLabel.Size = new System.Drawing.Size(94, 20); + this.searchLabel.TabIndex = 0; + this.searchLabel.Text = "Search text:"; + // + // optionsLabel + // + this.optionsLabel.AutoSize = true; + this.optionsLabel.Location = new System.Drawing.Point(13, 80); + this.optionsLabel.Name = "optionsLabel"; + this.optionsLabel.Size = new System.Drawing.Size(68, 20); + this.optionsLabel.TabIndex = 2; + this.optionsLabel.Text = "Options:"; + // + // optionsList + // + this.optionsList.FormattingEnabled = true; + this.optionsList.ItemHeight = 20; + this.optionsList.Location = new System.Drawing.Point(17, 104); + this.optionsList.Name = "optionsList"; + this.optionsList.Size = new System.Drawing.Size(771, 304); + this.optionsList.TabIndex = 3; + // + // selectButton + // + this.selectButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.selectButton.Location = new System.Drawing.Point(661, 414); + this.selectButton.Name = "selectButton"; + this.selectButton.Size = new System.Drawing.Size(127, 41); + this.selectButton.TabIndex = 4; + this.selectButton.Text = "Select"; + this.selectButton.UseVisualStyleBackColor = true; + // + // searchBox + // + this.searchBox.Location = new System.Drawing.Point(17, 37); + this.searchBox.Name = "searchBox"; + this.searchBox.Size = new System.Drawing.Size(771, 26); + this.searchBox.TabIndex = 1; + this.searchBox.WaterMarkColor = System.Drawing.Color.Gray; + this.searchBox.WaterMarkText = "Match text here"; + this.searchBox.TextChanged += new System.EventHandler(this.searchBox_TextChanged); + // + // SearchForm + // + this.AcceptButton = this.selectButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 463); + this.Controls.Add(this.selectButton); + this.Controls.Add(this.optionsList); + this.Controls.Add(this.optionsLabel); + this.Controls.Add(this.searchBox); + this.Controls.Add(this.searchLabel); + this.Name = "SearchForm"; + this.Text = "Search"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label searchLabel; + private System.Windows.Forms.Label optionsLabel; + private System.Windows.Forms.ListBox optionsList; + private System.Windows.Forms.Button selectButton; + private WatermarkTextBox searchBox; + } +} \ No newline at end of file diff --git a/ShortcutUtil/SearchForm.cs b/ShortcutUtil/SearchForm.cs new file mode 100755 index 0000000..3253ac5 --- /dev/null +++ b/ShortcutUtil/SearchForm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class SearchForm : Form + { + public SearchForm() + { + InitializeComponent(); + } + + private List allOptions = new List(); + private List> displayOptions = new List>(); + + public T GetSelection(string title, string optionsName, List> options) where T : class + { + allOptions = options.Select(s => s.Item2).ToList(); + + Text = title; + optionsLabel.Text = optionsName; + + if (searchBox.Text != "") + { + searchBox.Text = ""; + } + else + { + UpdateDisplay(); + } + + if (ShowDialog() == DialogResult.OK && optionsList.SelectedIndex >= 0 && optionsList.SelectedIndex < displayOptions.Count) + { + return options[displayOptions[optionsList.SelectedIndex].Item2].Item1; + } + + return null; + } + + private void UpdateDisplay() + { + string search = searchBox.Text.Trim().ToLower(); + displayOptions = allOptions.Select((s, index) => new Tuple(s, index)).Where(s => s.Item1.ToLower().Contains(search)).ToList(); + + optionsList.Items.Clear(); + optionsList.Items.AddRange(displayOptions.Select(o => o.Item1).ToArray()); + } + + private void searchBox_TextChanged(object sender, EventArgs e) + { + UpdateDisplay(); + } + } +} diff --git a/ShortcutUtil/SearchForm.resx b/ShortcutUtil/SearchForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/SearchForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/ShortcutUtil.csproj b/ShortcutUtil/ShortcutUtil.csproj index a9c0bce..87a451f 100755 --- a/ShortcutUtil/ShortcutUtil.csproj +++ b/ShortcutUtil/ShortcutUtil.csproj @@ -51,6 +51,10 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + False + ..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll + ..\packages\System.Text.Encodings.Web.4.7.1\lib\net461\System.Text.Encodings.Web.dll @@ -72,6 +76,9 @@ + + ..\..\..\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd + @@ -86,6 +93,15 @@ + + Form + + + SearchForm.cs + + + Component + MainForm.cs @@ -98,6 +114,9 @@ True Resources.resx + + SearchForm.cs + SettingsSingleFileGenerator @@ -112,5 +131,8 @@ + + + \ No newline at end of file diff --git a/ShortcutUtil/WatermarkTextBox.cs b/ShortcutUtil/WatermarkTextBox.cs new file mode 100755 index 0000000..fd4ada8 --- /dev/null +++ b/ShortcutUtil/WatermarkTextBox.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + // https://www.codeproject.com/Articles/27849/WaterMark-TextBox-For-Desktop-Applications-Using-C + + class WatermarkTextBox : TextBox + { + private Font mOldFont = null; + private Boolean mWaterMarkTextEnabled = false; + + #region Attributes + private Color _waterMarkColor = Color.Gray; + public Color WaterMarkColor + { + get { return _waterMarkColor; } + set + { + _waterMarkColor = value; Invalidate();/*thanks to Bernhard Elbl + for Invalidate()*/ + } + } + + private string _waterMarkText = "Water Mark"; + public string WaterMarkText + { + get { return _waterMarkText; } + set { _waterMarkText = value; Invalidate(); } + } + #endregion + + //Default constructor + public WatermarkTextBox() + { + JoinEvents(true); + } + + //Override OnCreateControl ... thanks to "lpgray .. codeproject guy" + protected override void OnCreateControl() + { + base.OnCreateControl(); + WaterMarkToggle(null, null); + } + + //Override OnPaint + protected override void OnPaint(PaintEventArgs args) + { + // Use the same font that was defined in base class + System.Drawing.Font drawFont = new System.Drawing.Font(Font.FontFamily, + Font.Size, Font.Style, Font.Unit); + //Create new brush with gray color or + SolidBrush drawBrush = new SolidBrush(WaterMarkColor);//use Water mark color + //Draw Text or WaterMark + args.Graphics.DrawString((mWaterMarkTextEnabled ? WaterMarkText : Text), + drawFont, drawBrush, new PointF(0.0F, 0.0F)); + base.OnPaint(args); + } + + private void JoinEvents(Boolean join) + { + if (join) + { + this.TextChanged += new System.EventHandler(this.WaterMarkToggle); + this.LostFocus += new System.EventHandler(this.WaterMarkToggle); + this.FontChanged += new System.EventHandler(this.WaterMark_FontChanged); + //No one of the above events will start immeddiatlly + //TextBox control still in constructing, so, + //Font object (for example) couldn't be catched from within + //WaterMark_Toggle + //So, call WaterMark_Toggel through OnCreateControl after TextBox + //is totally created + //No doupt, it will be only one time call + + //Old solution uses Timer.Tick event to check Create property + } + } + + private void WaterMarkToggle(object sender, EventArgs args) + { + if (this.Text.Length <= 0) + EnableWaterMark(); + else + DisableWaterMark(); + } + + private void EnableWaterMark() + { + //Save current font until returning the UserPaint style to false (NOTE: + //It is a try and error advice) + mOldFont = new System.Drawing.Font(Font.FontFamily, Font.Size, Font.Style, + Font.Unit); + //Enable OnPaint event handler + this.SetStyle(ControlStyles.UserPaint, true); + this.mWaterMarkTextEnabled = true; + //Triger OnPaint immediatly + Refresh(); + } + + private void DisableWaterMark() + { + //Disbale OnPaint event handler + this.mWaterMarkTextEnabled = false; + this.SetStyle(ControlStyles.UserPaint, false); + //Return back oldFont if existed + if (mOldFont != null) + this.Font = new System.Drawing.Font(mOldFont.FontFamily, mOldFont.Size, + mOldFont.Style, mOldFont.Unit); + } + + private void WaterMark_FontChanged(object sender, EventArgs args) + { + if (mWaterMarkTextEnabled) + { + mOldFont = new System.Drawing.Font(Font.FontFamily, Font.Size, Font.Style, + Font.Unit); + Refresh(); + } + } + } +}