diff --git a/FloatFolder/System/App.cs b/FloatFolder/System/App.cs index a34d213..6faec7b 100644 --- a/FloatFolder/System/App.cs +++ b/FloatFolder/System/App.cs @@ -9,14 +9,24 @@ namespace FloatFolder { - public class App - { - List shortcuts; - - public App() - { - shortcuts = new List(); - } + public class App + { + List shortcuts; + + public App() + { + shortcuts = new List(); + } + + static string EscapeLiteral(string value) + { + if (value == null) + { + return string.Empty; + } + + return value.Replace("\\", "\\\\").Replace("\"", "\\\""); + } public void AddShortcut(string name, string url) { @@ -50,11 +60,11 @@ public string GenerateApp() code.AppendLine("namespace SavanDev {"); code.AppendLine(Template.AppProgram).AppendLine(); - StringBuilder codeShortcut = new StringBuilder(); - foreach (var item in shortcuts) { - codeShortcut.AppendLine("Nombre.Add(\"" + item.name + "\");"); - codeShortcut.AppendLine("Url.Add(\"" + item.url.Replace("\\", "\\\\") + "\");"); - } + StringBuilder codeShortcut = new StringBuilder(); + foreach (var item in shortcuts) { + codeShortcut.AppendLine("Nombre.Add(\"" + EscapeLiteral(item.name) + "\");"); + codeShortcut.AppendLine("Url.Add(\"" + EscapeLiteral(item.url) + "\");"); + } string size; switch (shortcuts.Count) diff --git a/FloatFolder/System/Template.cs b/FloatFolder/System/Template.cs index 4f9b8be..f1b426c 100644 --- a/FloatFolder/System/Template.cs +++ b/FloatFolder/System/Template.cs @@ -7,13 +7,14 @@ namespace FloatFolder { static class Template { - public static readonly string AppNamespace = @"using System; - using System.Collections.Generic; - using System.Drawing; - using System.IO; - using System.Windows.Forms; - using System.Reflection; - using System.Runtime.InteropServices;"; + public static readonly string AppNamespace = @"using System; + using System.Collections.Generic; + using System.Drawing; + using System.Drawing.Drawing2D; + using System.IO; + using System.Windows.Forms; + using System.Reflection; + using System.Runtime.InteropServices;"; public static readonly string AppProgram = @"static class Program { @@ -30,8 +31,9 @@ public static string AppMain(string shortcuts, string size) return @"public class App : Form { System.ComponentModel.IContainer components; - ListView listView1; - ImageList imageList1; + ListView listView1; + ImageList imageList1; + Label titleLabel; protected override void Dispose(bool disposing) { @@ -46,51 +48,76 @@ void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.listView1 = new ListView(); - this.imageList1 = new ImageList(this.components); - this.SuspendLayout(); - // - // listView1 - // - this.listView1.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right))); - this.listView1.BackColor = SystemColors.Control; - this.listView1.BorderStyle = BorderStyle.None; - this.listView1.LargeImageList = this.imageList1; - this.listView1.Location = new Point(12, 12); - this.listView1.Size = new Size(" + size + @"); - this.listView1.TileSize = new Size(143, 32); - this.listView1.SelectedIndexChanged += this.listView1_SelectedIndexChanged; - // - // imageList1 - // - this.imageList1.ColorDepth = ColorDepth.Depth32Bit; - this.imageList1.ImageSize = new Size(32, 32); - this.imageList1.TransparentColor = Color.Transparent; - // - // Form1 - // - this.AutoScaleDimensions = new SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new Size(this.listView1.Width + 12, this.listView1.Height + 12); - this.ControlBox = false; - this.Controls.Add(this.listView1); - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.StartPosition = FormStartPosition.Manual; - this.Deactivate += this.Form1_Deactivate; - this.Load += this.Form1_Load; - this.ResumeLayout(false); - - } + this.imageList1 = new ImageList(this.components); + this.titleLabel = new Label(); + this.SuspendLayout(); + // + // listView1 + // + this.listView1.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right))); + this.listView1.BackColor = Color.FromArgb(250, 250, 250); + this.listView1.BorderStyle = BorderStyle.None; + this.listView1.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point); + this.listView1.ForeColor = Color.FromArgb(33, 33, 33); + this.listView1.FullRowSelect = true; + this.listView1.HideSelection = false; + this.listView1.LargeImageList = this.imageList1; + this.listView1.Location = new Point(24, 72); + this.listView1.Size = new Size(" + size + @"); + this.listView1.TileSize = new Size(Math.Max(48, this.listView1.Width - 24), 64); + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = View.Tile; + this.listView1.SelectedIndexChanged += this.listView1_SelectedIndexChanged; + // + // imageList1 + // + this.imageList1.ColorDepth = ColorDepth.Depth32Bit; + this.imageList1.ImageSize = new Size(48, 48); + this.imageList1.TransparentColor = Color.Transparent; + // + // titleLabel + // + this.titleLabel.AutoSize = false; + this.titleLabel.Font = new Font("Segoe UI", 12F, FontStyle.Bold, GraphicsUnit.Point); + this.titleLabel.ForeColor = Color.White; + this.titleLabel.Location = new Point(24, 24); + this.titleLabel.Size = new Size(this.listView1.Width, 32); + this.titleLabel.Text = "Accesos directos"; + this.titleLabel.TextAlign = ContentAlignment.MiddleLeft; + // + // Form1 + // + this.AutoScaleDimensions = new SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = Color.FromArgb(33, 33, 33); + this.ClientSize = new Size(this.listView1.Width + 48, this.listView1.Height + 96); + this.ControlBox = false; + this.Controls.Add(this.titleLabel); + this.Controls.Add(this.listView1); + this.DoubleBuffered = true; + this.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + this.FormBorderStyle = FormBorderStyle.None; + this.Opacity = 0.92D; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = FormStartPosition.Manual; + this.Text = string.Empty; + this.TopMost = true; + this.Deactivate += this.Form1_Deactivate; + this.Load += this.Form1_Load; + this.ResumeLayout(false); + + } // Normal code List Url = new List(); List Nombre = new List(); - public App() - { - InitializeComponent(); - - //Establecer posición del formulario + public App() + { + InitializeComponent(); + + //Establecer posición del formulario if(Cursor.Position.X + Size.Width > Screen.PrimaryScreen.WorkingArea.Width || Cursor.Position.Y + Size.Height > Screen.PrimaryScreen.WorkingArea.Height) Location = Cursor.Position - Size; else @@ -114,25 +141,50 @@ public static Bitmap getApplicationIcon(string source) return Icon.ExtractAssociatedIcon(source).ToBitmap(); } - void Form1_Load(object sender, EventArgs e) - { - foreach (var item in Url) - { - imageList1.Images.Add(getApplicationIcon(item)); - } - - for (int i = 0; i < Nombre.Count; i++) - { - listView1.Items.Add(Nombre[i]); - listView1.Items[i].ImageIndex = i; - } - } - - void listView1_SelectedIndexChanged(object sender, EventArgs e) - { - System.Diagnostics.Process.Start(Url[listView1.SelectedIndices[0]]); - Application.Exit(); - } + void Form1_Load(object sender, EventArgs e) + { + listView1.TileSize = new Size(Math.Max(48, listView1.ClientSize.Width - 24), 64); + + foreach (var item in Url) + { + imageList1.Images.Add(getApplicationIcon(item)); + } + + for (int i = 0; i < Nombre.Count; i++) + { + listView1.Items.Add(Nombre[i]); + listView1.Items[i].ImageIndex = i; + } + } + + protected override void OnCreateControl() + { + base.OnCreateControl(); + + int radius = 18; + + using (GraphicsPath path = new GraphicsPath()) + { + path.StartFigure(); + path.AddArc(0, 0, radius, radius, 180, 90); + path.AddArc(Width - radius, 0, radius, radius, 270, 90); + path.AddArc(Width - radius, Height - radius, radius, radius, 0, 90); + path.AddArc(0, Height - radius, radius, radius, 90, 90); + path.CloseFigure(); + Region = new Region(path); + } + } + + void listView1_SelectedIndexChanged(object sender, EventArgs e) + { + if (listView1.SelectedIndices.Count == 0) + { + return; + } + + System.Diagnostics.Process.Start(Url[listView1.SelectedIndices[0]]); + Application.Exit(); + } }"; } }