diff --git a/FileSessionManager.cs b/FileSessionManager.cs new file mode 100644 index 0000000..8a373ba --- /dev/null +++ b/FileSessionManager.cs @@ -0,0 +1,209 @@ +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FizzyLauncher +{ + public class FileSessionManager + { + public delegate void OnNewSessionEvent(FileSessionManager sender); + public delegate Task OnSaveSessionEvent(FileSessionManager sender, string filename, bool showNotices = true); + public delegate Task OnLoadSessionEvent(FileSessionManager sender, string filename); + public delegate Task OnClearSessionEvent(FileSessionManager sender); + + + public string SessionFilename { get; set; } = null; + + public string NewSessionPromptTitle { get; set; } = "New session"; + public string OpenSessionPromptTitle { get; set; } = "Open session"; + public string CloseSessionPromptTitle { get; set; } = "Close session"; + public string SaveExistingSession { get; set; } = "Save existing session?"; + + public OpenFileDialog OpenFileDialog { get; set; } = null; + public SaveFileDialog SaveFileDialog { get; set; } = null; + + public OnNewSessionEvent OnNewSession { get; set; } = null; + public OnSaveSessionEvent OnSaveSession { get; set; } = null; + public OnLoadSessionEvent OnLoadSession { get; set; } = null; + public OnClearSessionEvent OnClearSession { get; set; } = null; + + + public async Task NewSession() + { + if (string.IsNullOrWhiteSpace(this.SessionFilename)) + { + this.SessionFilename = null; + + PerformNewSession(); + } + else + { + var result = MessageBox.Show(this.SaveExistingSession, this.NewSessionPromptTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + var result2 = await PerformSaveSession(this.SessionFilename, false); + if (result2) + { + this.SessionFilename = null; + + PerformNewSession(); + } + } + else if (result == DialogResult.No) + { + this.SessionFilename = null; + + PerformNewSession(); + } + else if (result == DialogResult.Cancel) + { + return; + } + } + } + + public async Task OpenSession(string filename) + { + this.SessionFilename = filename; + + if (string.IsNullOrWhiteSpace(this.SessionFilename)) + { + await this.OpenSession(); + } + else + { + await PerformLoadSession(this.SessionFilename); + } + } + + public async Task OpenSession() + { + if (string.IsNullOrWhiteSpace(this.SessionFilename)) + { + if (this.OpenFileDialog.ShowDialog() == DialogResult.OK) + { + this.SessionFilename = this.OpenFileDialog.FileName; + + await PerformLoadSession(this.SessionFilename); + } + } + else + { + var result = MessageBox.Show(this.SaveExistingSession, this.OpenSessionPromptTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + if (await PerformSaveSession(this.SessionFilename, false)) + { + if (this.OpenFileDialog.ShowDialog() == DialogResult.OK) + { + this.SessionFilename = this.OpenFileDialog.FileName; + + await PerformLoadSession(this.SessionFilename); + } + } + } + else if (result == DialogResult.No) + { + if (this.OpenFileDialog.ShowDialog() == DialogResult.OK) + { + this.SessionFilename = this.OpenFileDialog.FileName; + + await PerformLoadSession(this.SessionFilename); + } + } + else if (result == DialogResult.Cancel) + { + return; + } + } + } + + public async Task SaveSession() + { + if (string.IsNullOrWhiteSpace(this.SessionFilename)) + { + await this.SaveAsSession(); + } + else + { + await PerformSaveSession(this.SessionFilename, true); + } + } + + public async Task SaveAsSession() + { + if (this.SaveFileDialog.ShowDialog() == DialogResult.OK) + { + bool result = await PerformSaveSession(this.SaveFileDialog.FileName); + if (result) + { + this.SessionFilename = this.SaveFileDialog.FileName; + } + + return result; + } + + return false; + } + + public async Task CloseSession() + { + if (string.IsNullOrWhiteSpace(this.SessionFilename)) + { + this.SessionFilename = null; + + await PerformClearSession(); + } + else + { + var result = MessageBox.Show(this.SaveExistingSession, this.CloseSessionPromptTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + bool result2 = await PerformSaveSession(this.SessionFilename, false); + if (result2) + { + this.SessionFilename = null; + + await PerformClearSession(); + } + } + else if (result == DialogResult.No) + { + this.SessionFilename = null; + + await PerformClearSession(); + } + else if (result == DialogResult.Cancel) + { + return; + } + } + } + + + private void PerformNewSession() => this.OnNewSession?.Invoke(this); + + private async Task PerformSaveSession(string filename, bool showNotices = true) + { + if (this.OnSaveSession == null) + { + return false; + } + + return await this.OnSaveSession?.Invoke(this, filename, showNotices); + } + + private async Task PerformLoadSession(string filename) + { + if (this.OnLoadSession == null) + { + return false; + } + + return await this.OnLoadSession?.Invoke(this, filename); + } + + private async Task PerformClearSession() => this.OnClearSession?.Invoke(this); + + + } +} diff --git a/FizzyLauncher.csproj b/FizzyLauncher.csproj index 1a8e3e7..c15b847 100644 --- a/FizzyLauncher.csproj +++ b/FizzyLauncher.csproj @@ -2,7 +2,7 @@ WinExe - net6.0-windows + net8.0-windows8.0 true true favicon.ico @@ -45,10 +45,24 @@ + + + + + + + + + + + + + + @@ -59,12 +73,8 @@ - - References\Ryz3core.dll - - - References\Ryz3ui.dll - + + diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 2ae6153..0bcc517 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -30,296 +30,385 @@ namespace FizzyLauncher /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); - this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); - this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); - this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); - this.contextMenuStrip2 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem13 = new System.Windows.Forms.ToolStripSeparator(); - this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem14 = new System.Windows.Forms.ToolStripSeparator(); - this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem15 = new System.Windows.Forms.ToolStripSeparator(); - this.exitToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.addGroupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.showBigIconsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.enableAnimationsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.alwaysOnTopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.helpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.viewHelpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem16 = new System.Windows.Forms.ToolStripSeparator(); - this.aboutToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.tileContainer1 = new FizzyLauncher.Windows.Forms.TileContainer(); - this.contextMenuStrip2.SuspendLayout(); - this.menuStrip1.SuspendLayout(); - this.SuspendLayout(); + saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); + openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + notifyIcon1 = new System.Windows.Forms.NotifyIcon(components); + contextMenuStrip2 = new System.Windows.Forms.ContextMenuStrip(components); + exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + menuStrip1 = new System.Windows.Forms.MenuStrip(); + fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem13 = new System.Windows.Forms.ToolStripSeparator(); + closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem14 = new System.Windows.Forms.ToolStripSeparator(); + saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem15 = new System.Windows.Forms.ToolStripSeparator(); + exitToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + addGroupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + showBigIconsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + alwaysOnTopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + helpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + viewHelpToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem16 = new System.Windows.Forms.ToolStripSeparator(); + aboutToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + tileContainerMenu1 = new System.Windows.Forms.ContextMenuStrip(components); + addGroupToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); + editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); + addRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + removeRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); + topToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + upToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + downToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + bottomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); + removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + contextMenuStrip2.SuspendLayout(); + menuStrip1.SuspendLayout(); + tileContainerMenu1.SuspendLayout(); + SuspendLayout(); // // saveFileDialog1 // - this.saveFileDialog1.Filter = "Session files|*.jsonfig"; - this.saveFileDialog1.Title = "Choose file to save the session"; + saveFileDialog1.Filter = "Session files|*.jsonfig"; + saveFileDialog1.Title = "Choose file to save the session"; // // openFileDialog1 // - this.openFileDialog1.Filter = "Session files|*.jsonfig"; - this.openFileDialog1.Title = "Choose session file"; + openFileDialog1.Filter = "Session files|*.jsonfig"; + openFileDialog1.Title = "Choose session file"; // // notifyIcon1 // - this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip2; - this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon"))); - this.notifyIcon1.Text = "notifyIcon1"; - this.notifyIcon1.Visible = true; - this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick); + notifyIcon1.ContextMenuStrip = contextMenuStrip2; + notifyIcon1.Icon = (System.Drawing.Icon)resources.GetObject("notifyIcon1.Icon"); + notifyIcon1.Text = "notifyIcon1"; + notifyIcon1.Visible = true; + notifyIcon1.MouseClick += notifyIcon1_MouseClick; // // contextMenuStrip2 // - this.contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.exitToolStripMenuItem1}); - this.contextMenuStrip2.Name = "contextMenuStrip2"; - this.contextMenuStrip2.Size = new System.Drawing.Size(94, 26); + contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { exitToolStripMenuItem1 }); + contextMenuStrip2.Name = "contextMenuStrip2"; + contextMenuStrip2.Size = new System.Drawing.Size(94, 26); // // exitToolStripMenuItem1 // - this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1"; - this.exitToolStripMenuItem1.Size = new System.Drawing.Size(93, 22); - this.exitToolStripMenuItem1.Text = "E&xit"; - this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem1_Click); + exitToolStripMenuItem1.Name = "exitToolStripMenuItem1"; + exitToolStripMenuItem1.Size = new System.Drawing.Size(93, 22); + exitToolStripMenuItem1.Text = "E&xit"; + exitToolStripMenuItem1.Click += exitToolStripMenuItem1_Click; // // menuStrip1 // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.fileToolStripMenuItem, - this.toolStripMenuItem1, - this.viewToolStripMenuItem, - this.toolsToolStripMenuItem, - this.helpToolStripMenuItem1}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(633, 24); - this.menuStrip1.TabIndex = 2; - this.menuStrip1.MenuActivate += new System.EventHandler(this.menuStrip1_MenuActivate); + menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { fileToolStripMenuItem, toolStripMenuItem1, viewToolStripMenuItem, toolsToolStripMenuItem, helpToolStripMenuItem1 }); + menuStrip1.Location = new System.Drawing.Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new System.Drawing.Size(873, 24); + menuStrip1.TabIndex = 2; + menuStrip1.MenuActivate += menuStrip1_MenuActivate; // // fileToolStripMenuItem // - this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.newToolStripMenuItem, - this.openToolStripMenuItem, - this.toolStripMenuItem13, - this.closeToolStripMenuItem, - this.toolStripMenuItem14, - this.saveToolStripMenuItem, - this.saveAsToolStripMenuItem, - this.toolStripMenuItem15, - this.exitToolStripMenuItem2}); - this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); - this.fileToolStripMenuItem.Text = "&File"; + fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { newToolStripMenuItem, openToolStripMenuItem, toolStripMenuItem13, closeToolStripMenuItem, toolStripMenuItem14, saveToolStripMenuItem, saveAsToolStripMenuItem, toolStripMenuItem15, exitToolStripMenuItem2 }); + fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + fileToolStripMenuItem.Text = "&File"; // // newToolStripMenuItem // - this.newToolStripMenuItem.Image = AppResource.file; - this.newToolStripMenuItem.Name = "newToolStripMenuItem"; - this.newToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); - this.newToolStripMenuItem.Size = new System.Drawing.Size(146, 22); - this.newToolStripMenuItem.Text = "&New"; - this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); + newToolStripMenuItem.Image = AppResource.file; + newToolStripMenuItem.Name = "newToolStripMenuItem"; + newToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N; + newToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + newToolStripMenuItem.Text = "&New"; + newToolStripMenuItem.Click += newToolStripMenuItem_Click; // // openToolStripMenuItem // - this.openToolStripMenuItem.Image = AppResource.folder; - this.openToolStripMenuItem.Name = "openToolStripMenuItem"; - this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); - this.openToolStripMenuItem.Size = new System.Drawing.Size(146, 22); - this.openToolStripMenuItem.Text = "&Open"; - this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); + openToolStripMenuItem.Image = AppResource.folder; + openToolStripMenuItem.Name = "openToolStripMenuItem"; + openToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O; + openToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + openToolStripMenuItem.Text = "&Open"; + openToolStripMenuItem.Click += openToolStripMenuItem_Click; // // toolStripMenuItem13 // - this.toolStripMenuItem13.Name = "toolStripMenuItem13"; - this.toolStripMenuItem13.Size = new System.Drawing.Size(143, 6); + toolStripMenuItem13.Name = "toolStripMenuItem13"; + toolStripMenuItem13.Size = new System.Drawing.Size(143, 6); // // closeToolStripMenuItem // - this.closeToolStripMenuItem.Name = "closeToolStripMenuItem"; - this.closeToolStripMenuItem.Size = new System.Drawing.Size(146, 22); - this.closeToolStripMenuItem.Text = "&Close"; - this.closeToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click); + closeToolStripMenuItem.Name = "closeToolStripMenuItem"; + closeToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + closeToolStripMenuItem.Text = "&Close"; + closeToolStripMenuItem.Click += closeToolStripMenuItem_Click; // // toolStripMenuItem14 // - this.toolStripMenuItem14.Name = "toolStripMenuItem14"; - this.toolStripMenuItem14.Size = new System.Drawing.Size(143, 6); + toolStripMenuItem14.Name = "toolStripMenuItem14"; + toolStripMenuItem14.Size = new System.Drawing.Size(143, 6); // // saveToolStripMenuItem // - this.saveToolStripMenuItem.Image = AppResource.disk2; - this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.saveToolStripMenuItem.Size = new System.Drawing.Size(146, 22); - this.saveToolStripMenuItem.Text = "&Save"; - this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); + saveToolStripMenuItem.Image = AppResource.disk2; + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S; + saveToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + saveToolStripMenuItem.Text = "&Save"; + saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; // // saveAsToolStripMenuItem // - this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; - this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(146, 22); - this.saveAsToolStripMenuItem.Text = "Save &As..."; - this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); + saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; + saveAsToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + saveAsToolStripMenuItem.Text = "Save &As..."; + saveAsToolStripMenuItem.Click += saveAsToolStripMenuItem_Click; // // toolStripMenuItem15 // - this.toolStripMenuItem15.Name = "toolStripMenuItem15"; - this.toolStripMenuItem15.Size = new System.Drawing.Size(143, 6); + toolStripMenuItem15.Name = "toolStripMenuItem15"; + toolStripMenuItem15.Size = new System.Drawing.Size(143, 6); // // exitToolStripMenuItem2 // - this.exitToolStripMenuItem2.Name = "exitToolStripMenuItem2"; - this.exitToolStripMenuItem2.Size = new System.Drawing.Size(146, 22); - this.exitToolStripMenuItem2.Text = "E&xit"; - this.exitToolStripMenuItem2.Click += new System.EventHandler(this.exitToolStripMenuItem2_Click); + exitToolStripMenuItem2.Name = "exitToolStripMenuItem2"; + exitToolStripMenuItem2.Size = new System.Drawing.Size(146, 22); + exitToolStripMenuItem2.Text = "E&xit"; + exitToolStripMenuItem2.Click += exitToolStripMenuItem2_Click; // // toolStripMenuItem1 // - this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.addGroupToolStripMenuItem}); - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(39, 20); - this.toolStripMenuItem1.Text = "&Edit"; + toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { addGroupToolStripMenuItem }); + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new System.Drawing.Size(39, 20); + toolStripMenuItem1.Text = "&Edit"; // // addGroupToolStripMenuItem // - this.addGroupToolStripMenuItem.Name = "addGroupToolStripMenuItem"; - this.addGroupToolStripMenuItem.Size = new System.Drawing.Size(132, 22); - this.addGroupToolStripMenuItem.Text = "&Add Group"; - this.addGroupToolStripMenuItem.Click += new System.EventHandler(this.addGroupToolStripMenuItem_Click); + addGroupToolStripMenuItem.Name = "addGroupToolStripMenuItem"; + addGroupToolStripMenuItem.Size = new System.Drawing.Size(132, 22); + addGroupToolStripMenuItem.Text = "&Add Group"; + addGroupToolStripMenuItem.Click += addGroupToolStripMenuItem_Click; // // viewToolStripMenuItem // - this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.showBigIconsToolStripMenuItem, - this.enableAnimationsToolStripMenuItem, - this.alwaysOnTopToolStripMenuItem}); - this.viewToolStripMenuItem.Name = "viewToolStripMenuItem"; - this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20); - this.viewToolStripMenuItem.Text = "&View"; + viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { showBigIconsToolStripMenuItem, alwaysOnTopToolStripMenuItem }); + viewToolStripMenuItem.Name = "viewToolStripMenuItem"; + viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20); + viewToolStripMenuItem.Text = "&View"; // // showBigIconsToolStripMenuItem // - this.showBigIconsToolStripMenuItem.Name = "showBigIconsToolStripMenuItem"; - this.showBigIconsToolStripMenuItem.Size = new System.Drawing.Size(173, 22); - this.showBigIconsToolStripMenuItem.Text = "Show &Big Icons"; - this.showBigIconsToolStripMenuItem.Click += new System.EventHandler(this.showBigIconsToolStripMenuItem_Click); - // - // enableAnimationsToolStripMenuItem - // - this.enableAnimationsToolStripMenuItem.Name = "enableAnimationsToolStripMenuItem"; - this.enableAnimationsToolStripMenuItem.Size = new System.Drawing.Size(173, 22); - this.enableAnimationsToolStripMenuItem.Text = "Enable &Animations"; - this.enableAnimationsToolStripMenuItem.Click += new System.EventHandler(this.enableAnimationsToolStripMenuItem_Click); + showBigIconsToolStripMenuItem.Name = "showBigIconsToolStripMenuItem"; + showBigIconsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + showBigIconsToolStripMenuItem.Text = "Show &Big Icons"; + showBigIconsToolStripMenuItem.Click += showBigIconsToolStripMenuItem_Click; // // alwaysOnTopToolStripMenuItem // - this.alwaysOnTopToolStripMenuItem.Name = "alwaysOnTopToolStripMenuItem"; - this.alwaysOnTopToolStripMenuItem.Size = new System.Drawing.Size(173, 22); - this.alwaysOnTopToolStripMenuItem.Text = "Always On &Top"; - this.alwaysOnTopToolStripMenuItem.Click += new System.EventHandler(this.alwaysOnTopToolStripMenuItem_Click); + alwaysOnTopToolStripMenuItem.Name = "alwaysOnTopToolStripMenuItem"; + alwaysOnTopToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + alwaysOnTopToolStripMenuItem.Text = "Always On &Top"; + alwaysOnTopToolStripMenuItem.Click += alwaysOnTopToolStripMenuItem_Click; // // toolsToolStripMenuItem // - this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.optionsToolStripMenuItem}); - this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; - this.toolsToolStripMenuItem.Size = new System.Drawing.Size(46, 20); - this.toolsToolStripMenuItem.Text = "&Tools"; + toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { optionsToolStripMenuItem }); + toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; + toolsToolStripMenuItem.Size = new System.Drawing.Size(46, 20); + toolsToolStripMenuItem.Text = "&Tools"; // // optionsToolStripMenuItem // - this.optionsToolStripMenuItem.Image = AppResource.cog2; - this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; - this.optionsToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F12))); - this.optionsToolStripMenuItem.Size = new System.Drawing.Size(168, 22); - this.optionsToolStripMenuItem.Text = "&Options"; - this.optionsToolStripMenuItem.Click += new System.EventHandler(this.optionsToolStripMenuItem_Click); + optionsToolStripMenuItem.Image = AppResource.cog2; + optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; + optionsToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F12; + optionsToolStripMenuItem.Size = new System.Drawing.Size(168, 22); + optionsToolStripMenuItem.Text = "&Options"; + optionsToolStripMenuItem.Click += optionsToolStripMenuItem_Click; // // helpToolStripMenuItem1 // - this.helpToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.viewHelpToolStripMenuItem1, - this.toolStripMenuItem16, - this.aboutToolStripMenuItem1}); - this.helpToolStripMenuItem1.Name = "helpToolStripMenuItem1"; - this.helpToolStripMenuItem1.Size = new System.Drawing.Size(44, 20); - this.helpToolStripMenuItem1.Text = "&Help"; + helpToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { viewHelpToolStripMenuItem1, toolStripMenuItem16, aboutToolStripMenuItem1 }); + helpToolStripMenuItem1.Name = "helpToolStripMenuItem1"; + helpToolStripMenuItem1.Size = new System.Drawing.Size(44, 20); + helpToolStripMenuItem1.Text = "&Help"; // // viewHelpToolStripMenuItem1 // - this.viewHelpToolStripMenuItem1.Image = AppResource.help2; - this.viewHelpToolStripMenuItem1.Name = "viewHelpToolStripMenuItem1"; - this.viewHelpToolStripMenuItem1.ShortcutKeys = System.Windows.Forms.Keys.F1; - this.viewHelpToolStripMenuItem1.Size = new System.Drawing.Size(146, 22); - this.viewHelpToolStripMenuItem1.Text = "&View Help"; - this.viewHelpToolStripMenuItem1.Click += new System.EventHandler(this.viewHelpToolStripMenuItem1_Click); + viewHelpToolStripMenuItem1.Image = AppResource.help2; + viewHelpToolStripMenuItem1.Name = "viewHelpToolStripMenuItem1"; + viewHelpToolStripMenuItem1.ShortcutKeys = System.Windows.Forms.Keys.F1; + viewHelpToolStripMenuItem1.Size = new System.Drawing.Size(146, 22); + viewHelpToolStripMenuItem1.Text = "&View Help"; + viewHelpToolStripMenuItem1.Click += viewHelpToolStripMenuItem1_Click; // // toolStripMenuItem16 // - this.toolStripMenuItem16.Name = "toolStripMenuItem16"; - this.toolStripMenuItem16.Size = new System.Drawing.Size(143, 6); + toolStripMenuItem16.Name = "toolStripMenuItem16"; + toolStripMenuItem16.Size = new System.Drawing.Size(143, 6); // // aboutToolStripMenuItem1 // - this.aboutToolStripMenuItem1.Name = "aboutToolStripMenuItem1"; - this.aboutToolStripMenuItem1.Size = new System.Drawing.Size(146, 22); - this.aboutToolStripMenuItem1.Text = "&About"; - this.aboutToolStripMenuItem1.Click += new System.EventHandler(this.aboutToolStripMenuItem1_Click); + aboutToolStripMenuItem1.Name = "aboutToolStripMenuItem1"; + aboutToolStripMenuItem1.Size = new System.Drawing.Size(146, 22); + aboutToolStripMenuItem1.Text = "&About"; + aboutToolStripMenuItem1.Click += aboutToolStripMenuItem1_Click; // - // tileContainer1 + // tileContainerMenu1 // - this.tileContainer1.AutoScroll = true; - this.tileContainer1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tileContainer1.BackColor = System.Drawing.Color.Transparent; - this.tileContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tileContainer1.Location = new System.Drawing.Point(0, 24); - this.tileContainer1.Margin = new System.Windows.Forms.Padding(0); - this.tileContainer1.Name = "tileContainer1"; - this.tileContainer1.Padding = new System.Windows.Forms.Padding(10, 10, 10, 20); - this.tileContainer1.Size = new System.Drawing.Size(633, 376); - this.tileContainer1.TabIndex = 3; + tileContainerMenu1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { addGroupToolStripMenuItem1, toolStripMenuItem4, editToolStripMenuItem, toolStripSeparator1, toolStripMenuItem2, toolStripSeparator2, toolStripMenuItem3, toolStripSeparator3, removeToolStripMenuItem }); + tileContainerMenu1.Name = "tileContainerMenu1"; + tileContainerMenu1.Size = new System.Drawing.Size(133, 154); + // + // addGroupToolStripMenuItem1 + // + addGroupToolStripMenuItem1.Name = "addGroupToolStripMenuItem1"; + addGroupToolStripMenuItem1.Size = new System.Drawing.Size(132, 22); + addGroupToolStripMenuItem1.Text = "&Add Tile"; + addGroupToolStripMenuItem1.Click += addGroupToolStripMenuItem1_Click; + // + // toolStripMenuItem4 + // + toolStripMenuItem4.Name = "toolStripMenuItem4"; + toolStripMenuItem4.Size = new System.Drawing.Size(132, 22); + toolStripMenuItem4.Text = "Add &Group"; + toolStripMenuItem4.Click += toolStripMenuItem4_Click; + // + // editToolStripMenuItem + // + editToolStripMenuItem.Name = "editToolStripMenuItem"; + editToolStripMenuItem.Size = new System.Drawing.Size(132, 22); + editToolStripMenuItem.Text = "&Edit"; + editToolStripMenuItem.Click += editToolStripMenuItem_Click; + // + // toolStripSeparator1 + // + toolStripSeparator1.Name = "toolStripSeparator1"; + toolStripSeparator1.Size = new System.Drawing.Size(129, 6); + // + // toolStripMenuItem2 + // + toolStripMenuItem2.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { addRowToolStripMenuItem, removeRowToolStripMenuItem }); + toolStripMenuItem2.Name = "toolStripMenuItem2"; + toolStripMenuItem2.Size = new System.Drawing.Size(132, 22); + toolStripMenuItem2.Text = "Ro&w"; + // + // addRowToolStripMenuItem + // + addRowToolStripMenuItem.Name = "addRowToolStripMenuItem"; + addRowToolStripMenuItem.Size = new System.Drawing.Size(143, 22); + addRowToolStripMenuItem.Text = "A&dd Row"; + addRowToolStripMenuItem.Click += addRowToolStripMenuItem_Click; + // + // removeRowToolStripMenuItem + // + removeRowToolStripMenuItem.Name = "removeRowToolStripMenuItem"; + removeRowToolStripMenuItem.Size = new System.Drawing.Size(143, 22); + removeRowToolStripMenuItem.Text = "Remo&ve Row"; + removeRowToolStripMenuItem.Click += removeRowToolStripMenuItem_Click; + // + // toolStripSeparator2 + // + toolStripSeparator2.Name = "toolStripSeparator2"; + toolStripSeparator2.Size = new System.Drawing.Size(129, 6); + // + // toolStripMenuItem3 + // + toolStripMenuItem3.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { topToolStripMenuItem, upToolStripMenuItem, downToolStripMenuItem, bottomToolStripMenuItem }); + toolStripMenuItem3.Name = "toolStripMenuItem3"; + toolStripMenuItem3.Size = new System.Drawing.Size(132, 22); + toolStripMenuItem3.Text = "&Move"; + // + // topToolStripMenuItem + // + topToolStripMenuItem.Name = "topToolStripMenuItem"; + topToolStripMenuItem.Size = new System.Drawing.Size(114, 22); + topToolStripMenuItem.Text = "&Top"; + topToolStripMenuItem.Click += topToolStripMenuItem_Click; + // + // upToolStripMenuItem + // + upToolStripMenuItem.Name = "upToolStripMenuItem"; + upToolStripMenuItem.Size = new System.Drawing.Size(114, 22); + upToolStripMenuItem.Text = "&Up"; + upToolStripMenuItem.Click += upToolStripMenuItem_Click; + // + // downToolStripMenuItem + // + downToolStripMenuItem.Name = "downToolStripMenuItem"; + downToolStripMenuItem.Size = new System.Drawing.Size(114, 22); + downToolStripMenuItem.Text = "&Down"; + downToolStripMenuItem.Click += downToolStripMenuItem_Click; + // + // bottomToolStripMenuItem + // + bottomToolStripMenuItem.Name = "bottomToolStripMenuItem"; + bottomToolStripMenuItem.Size = new System.Drawing.Size(114, 22); + bottomToolStripMenuItem.Text = "&Bottom"; + bottomToolStripMenuItem.Click += bottomToolStripMenuItem_Click; + // + // toolStripSeparator3 + // + toolStripSeparator3.Name = "toolStripSeparator3"; + toolStripSeparator3.Size = new System.Drawing.Size(129, 6); + // + // removeToolStripMenuItem + // + removeToolStripMenuItem.Name = "removeToolStripMenuItem"; + removeToolStripMenuItem.Size = new System.Drawing.Size(132, 22); + removeToolStripMenuItem.Text = "&Remove"; + removeToolStripMenuItem.Click += removeToolStripMenuItem_Click; + // + // flowLayoutPanel1 + // + flowLayoutPanel1.AutoScroll = true; + flowLayoutPanel1.BackColor = System.Drawing.Color.FromArgb(255, 192, 255); + flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + flowLayoutPanel1.Location = new System.Drawing.Point(12, 27); + flowLayoutPanel1.Name = "flowLayoutPanel1"; + flowLayoutPanel1.Size = new System.Drawing.Size(461, 426); + flowLayoutPanel1.TabIndex = 8; + flowLayoutPanel1.WrapContents = false; // // MainForm // - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250))))); - this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.ClientSize = new System.Drawing.Size(633, 400); - this.Controls.Add(this.tileContainer1); - this.Controls.Add(this.menuStrip1); - this.DoubleBuffered = true; - this.ForeColor = System.Drawing.SystemColors.ControlText; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MainMenuStrip = this.menuStrip1; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(420, 280); - this.Name = "MainForm"; - this.Text = "Fizzy Launcher"; - this.contextMenuStrip2.ResumeLayout(false); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + BackColor = System.Drawing.Color.FromArgb(250, 250, 250); + BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; + ClientSize = new System.Drawing.Size(873, 505); + Controls.Add(flowLayoutPanel1); + Controls.Add(menuStrip1); + DoubleBuffered = true; + ForeColor = System.Drawing.SystemColors.ControlText; + Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon"); + MainMenuStrip = menuStrip1; + MaximizeBox = false; + MinimizeBox = false; + MinimumSize = new System.Drawing.Size(420, 280); + Name = "MainForm"; + Text = "Fizzy Launcher"; + contextMenuStrip2.ResumeLayout(false); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + tileContainerMenu1.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -333,7 +422,6 @@ namespace FizzyLauncher private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem toolsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem1; - private TileContainer tileContainer1; private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem13; @@ -344,7 +432,6 @@ namespace FizzyLauncher private System.Windows.Forms.ToolStripSeparator toolStripMenuItem15; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem2; private System.Windows.Forms.ToolStripMenuItem showBigIconsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem enableAnimationsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem alwaysOnTopToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem viewHelpToolStripMenuItem1; @@ -352,6 +439,23 @@ namespace FizzyLauncher private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem addGroupToolStripMenuItem; + private System.Windows.Forms.ContextMenuStrip tileContainerMenu1; + private System.Windows.Forms.ToolStripMenuItem addGroupToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4; + private System.Windows.Forms.ToolStripMenuItem addRowToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem removeRowToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem topToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem upToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem downToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem bottomToolStripMenuItem; } } diff --git a/MainForm.cs b/MainForm.cs index e5dcc0a..fb107da 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,78 +1,216 @@ -using FizzyLauncher.Models; -using RyzStudio.Drawing; -using RyzStudio.Text.Json; -using RyzStudio.Windows.Forms; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Runtime.InteropServices; -using System.Text.Json; using System.Threading.Tasks; using System.Windows.Forms; +using FizzyLauncher.Models; +using FizzyLauncher.Windows.Forms; +using RyzStudio.Windows.Forms; +using RyzStudio.Windows.ThemedForms.ButtonTextBox; +using RyzStudio.Windows.TileForms; namespace FizzyLauncher { public partial class MainForm : Form { - [DllImport("user32.dll")] - protected static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); - - [DllImport("user32.dll")] - protected static extern bool UnregisterHotKey(IntPtr hWnd, int id); - - //protected const int MOD_ALT = 0x1; - //protected const int MOD_CONTROL = 0x2; - //protected const int MOD_SHIFT = 0x4; - //protected const int MOD_WIN = 0x8; - protected const int WM_HOTKEY = 0x312; - protected const int WM_QUERYENDSESSION = 0x0011; - - protected OptionsForm optionsForm = null; + //protected OptionsForm optionsForm = null; protected string sessionFilename = null; protected bool isBusy = false; protected bool requestExit = false; + private readonly FileSessionManager _fileSessionManager; - public MainForm() : base() + public MainForm() { InitializeComponent(); - tileContainer1.OnColumnSizeChanged += tileContainer1_OnSizeChanged; - notifyIcon1.Text = Application.ProductName; + _fileSessionManager = new FileSessionManager(); + _fileSessionManager.SessionFilename = sessionFilename; + _fileSessionManager.OpenFileDialog = openFileDialog1; + _fileSessionManager.SaveFileDialog = saveFileDialog1; + _fileSessionManager.OnNewSession += fileSessionManager_OnNewSession; + _fileSessionManager.OnLoadSession += fileSessionManager_OnLoadSession; + _fileSessionManager.OnSaveSession += fileSessionManager_OnSaveSession; + _fileSessionManager.OnClearSession += fileSessionManager_OnClearSession; + + //tileContainer1.OnColumnSizeChanged += tileContainer1_OnSizeChanged; + notifyIcon1.Text = System.Windows.Forms.Application.ProductName; this.AutoScaleMode = AutoScaleMode.None; this.StartPosition = FormStartPosition.WindowsDefaultBounds; this.Visible = false; } - protected override void OnLoad(EventArgs e) + + #region File session manager + + private void fileSessionManager_OnNewSession(FileSessionManager sender) { - base.OnLoad(e); + var form = new NewForm(); + if (form.ShowDialog() == DialogResult.OK) + { + var result = form.Result; - this.AutoScaleMode = AutoScaleMode.None; + UIControl.Clear(flowLayoutPanel1); - UIControl.SetVisible(this, false); - UIControl.SetSize(this, this.MinimumSize); + for (var i = 0; i < result.GroupCount; i++) + { + AddNewTileGroup(); + } + } + + sessionFilename = sender.SessionFilename; + UIControl.SetText(this, System.Windows.Forms.Application.ProductName); } + private async Task fileSessionManager_OnLoadSession(FileSessionManager sender, string filename) + { + return await Task.Run(async () => + { + this.CurrentSession = RyzStudio.Text.Json.JsonSerialiser.DeserialiseFile(filename); + if (this.CurrentSession == null) + { + MessageBox.Show("Unable to read session", "Load session"); + + return false; + } + + if (this.CurrentSession == null) + { + this.CurrentSession = new LauncherSession(); + } + + UIControl.SetText(this, Path.GetFileNameWithoutExtension(sessionFilename) + " - " + System.Windows.Forms.Application.ProductName); + + // Reposition + resize + if (!this.CurrentSession.StartPosition.IsEmpty) + { + UIControl.SetLocation(this, this.CurrentSession.StartPosition); + } + + if (this.CurrentSession.Height > 0) + { + UIControl.SetClientHeight(this, this.CurrentSession.Height); + } + + InvalidateOptions(); + + // Load tiles + await LoadTileGroups(this.CurrentSession.Groups); + + sessionFilename = sender.SessionFilename; + + UIControl.SetVisible(this, true); + UIControl.SetFocus(this); + + return true; + }); + } + + private async Task fileSessionManager_OnSaveSession(FileSessionManager sender, string filename, bool showNotices) + { + if (string.IsNullOrWhiteSpace(filename)) + { + return false; + } + + if (!flowLayoutPanel1.Controls.OfType().Any()) + { + return true; + } + + return await Task.Run(() => + { + if (isBusy) + { + return false; + } + + isBusy = true; + + // update session + if (this.CurrentSession == null) + { + this.CurrentSession = new LauncherSession(); + } + + this.CurrentSession.StartPosition = this.Location; + this.CurrentSession.Height = this.Height; + //this.CurrentSession.AlwaysOnTop = this.TopMost; + + this.CurrentSession.Groups = new List(); + foreach (var container in flowLayoutPanel1.Controls.OfType()) + { + this.CurrentSession.Groups.Add(container.Tag as TileGroupModel); + } + + var result = RyzStudio.Text.Json.JsonSerialiser.SerialiseFile(filename, this.CurrentSession); + if (result.IsSuccess) + { + if (showNotices) + { + MessageBox.Show("Session saved!", "Save session", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + else + { + MessageBox.Show(result.Message, "Save session"); + + isBusy = false; + + return false; + } + + sessionFilename = sender.SessionFilename; + UIControl.SetText(this, Path.GetFileNameWithoutExtension(sessionFilename) + " - " + System.Windows.Forms.Application.ProductName); + + isBusy = false; + + return true; + }); + } + + private async Task fileSessionManager_OnClearSession(FileSessionManager sender) + { + await Task.Run(() => + { + UIControl.Clear(flowLayoutPanel1); + + sessionFilename = sender.SessionFilename; + + UIControl.SetText(this, System.Windows.Forms.Application.ProductName); + }); + } + + #endregion + + + //protected override void OnLoad(EventArgs e) + //{ + // base.OnLoad(e); + + // //UIControl.SetSize(this, this.MinimumSize); + //} + protected async override void OnShown(EventArgs e) { base.OnShown(e); - UIControl.SetVisible(this, false); + var args = RyzStudio.Windows.Forms.Application.GetCommandLine(); - string[] commandLineArgs = Environment.GetCommandLineArgs(); - - string jsonfigFilename = null; - if (string.IsNullOrWhiteSpace(jsonfigFilename)) jsonfigFilename = parseOpenFile_FromCMD(commandLineArgs); - if (string.IsNullOrWhiteSpace(jsonfigFilename)) jsonfigFilename = Path.ChangeExtension(Application.ExecutablePath, "jsonfig"); + string jsonfigFilename = args.Where(x => (x.Key.Equals("o") || x.Key.Equals("open"))).Select(x => x.Value).FirstOrDefault(); + if (string.IsNullOrWhiteSpace(jsonfigFilename)) + { + jsonfigFilename = Path.ChangeExtension(System.Windows.Forms.Application.ExecutablePath, "jsonfig"); + } if (!string.IsNullOrWhiteSpace(jsonfigFilename) && File.Exists(jsonfigFilename)) { - await loadFile(jsonfigFilename); + await _fileSessionManager.OpenSession(jsonfigFilename); + + sessionFilename = _fileSessionManager.SessionFilename; } else { @@ -82,11 +220,14 @@ namespace FizzyLauncher } } - protected override void OnClosing(CancelEventArgs e) + protected async override void OnClosing(CancelEventArgs e) { base.OnClosing(e); - if (this.CurrentSession == null) this.CurrentSession = new LauncherSession(); + if (this.CurrentSession == null) + { + this.CurrentSession = new LauncherSession(); + } if (this.CurrentSession.HideOnClose && !requestExit) { @@ -97,46 +238,48 @@ namespace FizzyLauncher requestExit = false; - if (string.IsNullOrWhiteSpace(sessionFilename)) - { - // do nothing - } - else - { - if (this.CurrentSession.AutoSave == LauncherSession.AutoSaveOption.Prompt) - { - DialogResult dr = MessageBox.Show("Save existing session?", "Exit", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (dr == DialogResult.Yes) - { - bool rv = saveFile(sessionFilename, false); - if (!rv) - { - e.Cancel = true; - } - } - else if (dr == DialogResult.No) - { - // do nothing - } - else if (dr == DialogResult.Cancel) - { - e.Cancel = true; - } - } - else if (this.CurrentSession.AutoSave == LauncherSession.AutoSaveOption.Yes) - { - saveFile(sessionFilename, false); - } - } + await _fileSessionManager.CloseSession(); - if (this.CurrentSession.HotKey != null) + sessionFilename = _fileSessionManager.SessionFilename; + + //if (string.IsNullOrWhiteSpace(sessionFilename)) + //{ + // // do nothing + //} + //else + //{ + + //if (this.CurrentSession.AutoSave == LauncherSession.AutoSaveOption.Prompt) + //{ + //DialogResult dr = MessageBox.Show("Save existing session?", "Exit", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + //if (dr == DialogResult.Yes) + //{ + // bool rv = saveFile(sessionFilename, false); + // if (!rv) + // { + // e.Cancel = true; + // } + //} + //else if (dr == DialogResult.No) + //{ + // // do nothing + //} + //else if (dr == DialogResult.Cancel) + //{ + // e.Cancel = true; + //} + //} + //else if (this.CurrentSession.AutoSave == LauncherSession.AutoSaveOption.Yes) + //{ + // saveFile(sessionFilename, false); + //} + //} + + if ((this.CurrentSession?.ShowToggleHotkey ?? new ThKeyCodeTextBox.Results()).Key != Keys.None) { - if (this.CurrentSession.HotKey.KeyCode != Keys.None) - { #if !DEBUG - UnregisterHotKey((IntPtr)Handle, 1); + RyzStudio.Runtime.InteropServices.User32.UnregisterHotKey((IntPtr)Handle, 1); #endif - } } } @@ -145,21 +288,21 @@ namespace FizzyLauncher { switch (m.Msg) { - case WM_HOTKEY: + case RyzStudio.Runtime.InteropServices.User32.WM_HOTKEY: if (m.WParam.ToInt32() == 1) { this.Visible = !this.Visible; } break; - case WM_QUERYENDSESSION: + case RyzStudio.Runtime.InteropServices.User32.WM_QUERYENDSESSION: requestExit = true; //this.Close(); - Application.Exit(); + System.Windows.Forms.Application.Exit(); break; - default: break; - + default: + break; } base.WndProc(ref m); @@ -169,315 +312,255 @@ namespace FizzyLauncher public LauncherSession CurrentSession { get; set; } = null; - public void Clear(int columnCount) + public void Clear() { - tileContainer1.Clear(); - tileContainer1.Add(columnCount); + UIControl.Clear(flowLayoutPanel1); sessionFilename = null; } - protected async Task collapseWindow(int width, int increment = 6) + //protected async Task collapseWindow(int width, int increment = 6) + //{ + // await Task.Run(() => + // { + // while (this.Width > width) + // { + // UIControl.SetWidth(this, (this.Width - increment)); + + // System.Windows.Forms.Application.DoEvents(); + // } + + // UIControl.SetWidth(this, width); + // }); + //} + + //protected async Task expandWindow(int width, int increment = 8) + //{ + // await Task.Run(() => + // { + // while (this.Width < width) + // { + // UIControl.SetWidth(this, (this.Width + increment)); + + // System.Windows.Forms.Application.DoEvents(); + // } + + // UIControl.SetWidth(this, width); + // }); + //} + +// protected void invalidateHotKey() +// { +//#if !DEBUG +// UIControl.Invoke(this, (x) => +// { +// RyzStudio.Runtime.InteropServices.User32.UnregisterHotKey((IntPtr)Handle, 1); +// }); + +// if ((this.CurrentSession?.ShowToggleHotkey ?? new ThKeyCodeTextBox.Results()).Key != Keys.None) +// { +// UIControl.Invoke(this, (x) => +// { +// RyzStudio.Runtime.InteropServices.User32.RegisterHotKey((IntPtr)Handle, 1, this.CurrentSession.HotKey.ModifierCode, this.CurrentSession.HotKey.Key); +// }); +// } +//#endif +// } + + //protected void newSession() + //{ + // var form = new NewForm(); + // if (form.ShowDialog() == DialogResult.OK) + // { + // var result = form.Result; + + // flowLayoutPanel1.Controls.Clear(); + + // for (var i = 0; i < result.GroupCount; i++) + // { + // AddNewTileGroup(); + // } + // } + //} + + //protected async Task loadFile(string filename) + //{ + // //await Task.Run(async () => + // //{ + // if (isBusy) + // { + // return; + // } + + // this.CurrentSession = RyzStudio.Text.Json.JsonSerialiser.DeserialiseFile(filename); + // if (this.CurrentSession == null) + // { + // MessageBox.Show("Unable to read session", "Load session"); + // return; + // } + + // if (this.CurrentSession == null) + // { + // this.CurrentSession = new LauncherSession(); + // } + + // InvalidateOptions(); + + // // load tiles + // //tileContainer1.Load(this.CurrentSession.Groups); + // await LoadTileGroups(this.CurrentSession.Groups); + + // // reposition + // //if (!this.CurrentSession.StartPosition.IsEmpty) + // //{ + // //UIControl.SetLocation(this, this.CurrentSession.StartPosition); + // //} + + // // + // //UIControl.SetTopMost(this, this.CurrentSession.AlwaysOnTop); + // UIControl.SetVisible(this, true); + // //UIControl.SetChecked(showBigIconsToolStripMenuItem, this.CurrentSession.EnableBigIconInFolder); + // //UIControl.SetClientHeight(this, this.CurrentSession.DefaultHeight); + + // UIControl.SetFocus(this); + + // // hotkey + // //invalidateHotKey(); + + // //}); + //} + + //protected bool saveFile(string filename, bool showNotices = true) + //{ + // if (isBusy) + // { + // return false; + // } + + // if (string.IsNullOrWhiteSpace(filename)) + // { + // return false; + // } + + // //if (tileContainer1.GroupCount <= 0) + // //{ + // // return true; + // //} + + // isBusy = true; + + // // update session + // if (this.CurrentSession == null) + // { + // this.CurrentSession = new LauncherSession(); + // } + + // this.CurrentSession.Height = this.Height; + // //this.CurrentSession.AlwaysOnTop = this.TopMost; + // this.CurrentSession.StartPosition = this.Location; + // //this.CurrentSession.Groups = flowLayoutPanel1.Controls.OfType()?.ToList() ?? new List(); + + // var result = RyzStudio.Text.Json.JsonSerialiser.SerialiseFile(filename, this.CurrentSession); + // if (result.IsSuccess) + // { + // if (showNotices) + // { + // MessageBox.Show("Session saved!", "Save session", MessageBoxButtons.OK, MessageBoxIcon.Information); + // } + // } + // else + // { + // MessageBox.Show(result.Message, "Save session"); + + // return false; + // } + + // isBusy = false; + + // return true; + //} + + //protected bool saveAsFile() + //{ + // if (isBusy) + // { + // return false; + // } + + // if (saveFileDialog1.ShowDialog() == DialogResult.OK) + // { + // bool rv = saveFile(saveFileDialog1.FileName); + // if (rv) + // { + // sessionFilename = saveFileDialog1.FileName; + // } + + // return rv; + // } + + // return false; + //} + + private void InvalidateOptions() { - await Task.Run(() => - { - while (this.Width > width) - { - UIControl.SetWidth(this, (this.Width - increment)); + /// todo: big icons - Application.DoEvents(); - } - - UIControl.SetWidth(this, width); - }); - } - - protected async Task expandWindow(int width, int increment = 8) - { - await Task.Run(() => - { - while (this.Width < width) - { - UIControl.SetWidth(this, (this.Width + increment)); - - Application.DoEvents(); - } - - UIControl.SetWidth(this, width); - }); - } - - protected void invalidateHotKey() - { #if !DEBUG - if (this.InvokeRequired) + UIControl.Invoke(this, (x) => { - this.Invoke(new MethodInvoker(() => + RyzStudio.Runtime.InteropServices.User32.UnregisterHotKey((IntPtr)Handle, 1); + }); + + if ((this.CurrentSession?.ShowToggleHotkey ?? new ThKeyCodeTextBox.Results()).Key != Keys.None) + { + UIControl.Invoke(this, (x) => { - UnregisterHotKey((IntPtr)Handle, 1); - })); - } - else - { - UnregisterHotKey((IntPtr)Handle, 1); + RyzStudio.Runtime.InteropServices.User32.RegisterHotKey((IntPtr)Handle, 1, this.CurrentSession.HotKey.ModifierCode, this.CurrentSession.HotKey.Key); + }); } #endif - if (this.CurrentSession.HotKey != null) - { - if (this.CurrentSession.HotKey.KeyCode != Keys.None) - { -#if !DEBUG - if (this.InvokeRequired) - { - this.Invoke(new MethodInvoker(() => - { - RegisterHotKey((IntPtr)Handle, 1, this.CurrentSession.HotKey.ModifierCode, this.CurrentSession.HotKey.Key); - })); - } - else - { - RegisterHotKey((IntPtr)Handle, 1, this.CurrentSession.HotKey.ModifierCode, this.CurrentSession.HotKey.Key); - } -#endif - } - } + UIControl.SetTopMost(this, this.CurrentSession.AlwaysOnTop); + } - protected string parseOpenFile_FromCMD(string[] args) - { - if (args.Length <= 1) - { - return null; - } - int i = 1; - while (true) - { - if (i > (args.Length - 1)) - { - break; - } - - switch (args[i].Trim().ToLower()) - { - case "-o": - case "-open": - if ((i + 1) > (args.Length - 1)) break; - - string openFilename = args[(i + 1)]; - if (string.IsNullOrWhiteSpace(openFilename)) break; - if (!File.Exists(openFilename)) break; - - return openFilename; - - //i++; - //break; - } - - i++; - } - - return null; - } - - protected void newSession() - { - NewForm form = new NewForm(this); - form.ShowDialog(); - } - - protected async Task loadFile(string filename) - { - await Task.Run(() => - { - if (isBusy) - { - return; - } - - if (string.IsNullOrWhiteSpace(filename)) - { - return; - } - - if (!File.Exists(filename)) - { - return; - } - - string sourceCode = null; - - try - { - sessionFilename = filename; - - sourceCode = File.ReadAllText(sessionFilename); - } - catch (Exception exc) - { - MessageBox.Show(exc.Message, "Load session"); - return; - } - - if (string.IsNullOrWhiteSpace(sourceCode)) - { - return; - } - - // load options - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonPointConverter()); - options.Converters.Add(new JsonSizeConverter()); - options.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping; - - try - { - this.CurrentSession = JsonSerializer.Deserialize(sourceCode, options); - } - catch (Exception) - { - MessageBox.Show("Unable to read session", "Load session"); - return; - } - - if (this.CurrentSession == null) - { - this.CurrentSession = new LauncherSession(); - } - - // load tiles - tileContainer1.Load(this.CurrentSession.Groups); - - // reposition - if (!this.CurrentSession.StartPosition.IsEmpty) UIControl.SetLocation(this, this.CurrentSession.StartPosition); - - // - UIControl.SetTopMost(this, this.CurrentSession.AlwaysOnTop); - UIControl.SetVisible(this, true); - UIControl.SetChecked(enableAnimationsToolStripMenuItem, this.CurrentSession.EnableAnimation); - UIControl.SetChecked(showBigIconsToolStripMenuItem, this.CurrentSession.EnableBigIconInFolder); - UIControl.SetClientHeight(this, this.CurrentSession.DefaultHeight); - - UIControl.SetFocus(this); - - // hotkey - invalidateHotKey(); - - }); - } - - protected bool saveFile(string filename, bool showNotices = true) - { - if (isBusy) - { - return false; - } - - if (string.IsNullOrWhiteSpace(filename)) - { - return false; - } - - if (tileContainer1.GroupCount <= 0) - { - return true; - } - - isBusy = true; - - // update session - if (this.CurrentSession == null) - { - this.CurrentSession = new LauncherSession(); - } - - this.CurrentSession.DefaultHeight = this.Height; - this.CurrentSession.AlwaysOnTop = this.TopMost; - this.CurrentSession.StartPosition = this.Location; - this.CurrentSession.Groups = tileContainer1.GroupModels?.ToList() ?? new List(); - - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonPointConverter()); - options.Converters.Add(new JsonSizeConverter()); - options.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping; - - try - { - File.WriteAllText(filename, JsonSerializer.Serialize(this.CurrentSession, options)); - - if (showNotices) - { - MessageBox.Show("Session saved!", "Save session", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - catch (Exception exc) - { - MessageBox.Show(exc.Message, "Save session"); - - return false; - } - - isBusy = false; - - return true; - } - - protected bool saveAsFile() - { - if (isBusy) - { - return false; - } - - if (saveFileDialog1.ShowDialog() == DialogResult.OK) - { - bool rv = saveFile(saveFileDialog1.FileName); - if (rv) - { - sessionFilename = saveFileDialog1.FileName; - } - - return rv; - } - - return false; - } - -#region main menu + #region main menu /// /// New /// /// /// - private void newToolStripMenuItem_Click(object sender, EventArgs e) + private async void newToolStripMenuItem_Click(object sender, EventArgs e) { - if (string.IsNullOrWhiteSpace(sessionFilename)) - { - newSession(); - } - else - { - DialogResult dr = MessageBox.Show("Save existing session?", "New session", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (dr == DialogResult.Yes) - { - bool rv = saveFile(sessionFilename, false); - if (rv) - { - newSession(); - } - } - else if (dr == DialogResult.No) - { - newSession(); - } - else if (dr == DialogResult.Cancel) - { - return; - } - } + await _fileSessionManager.NewSession(); + + //if (string.IsNullOrWhiteSpace(sessionFilename)) + //{ + // newSession(); + //} + //else + //{ + // var result = MessageBox.Show("Save existing session?", "New session", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + // if (result == DialogResult.Yes) + // { + // bool rv = saveFile(sessionFilename, false); + // if (rv) + // { + // newSession(); + // } + // } + // else if (result == DialogResult.No) + // { + // newSession(); + // } + // else if (result == DialogResult.Cancel) + // { + // return; + // } + //} } /// @@ -487,39 +570,42 @@ namespace FizzyLauncher /// private async void openToolStripMenuItem_Click(object sender, EventArgs e) { - if (string.IsNullOrWhiteSpace(sessionFilename)) - { - if (openFileDialog1.ShowDialog() == DialogResult.OK) - { - await loadFile(openFileDialog1.FileName); - } - } - else - { - DialogResult dr = MessageBox.Show("Save existing session?", "Open session", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (dr == DialogResult.Yes) - { - bool rv = saveFile(sessionFilename, false); - if (rv) - { - if (openFileDialog1.ShowDialog() == DialogResult.OK) - { - await loadFile(openFileDialog1.FileName); - } - } - } - else if (dr == DialogResult.No) - { - if (openFileDialog1.ShowDialog() == DialogResult.OK) - { - await loadFile(openFileDialog1.FileName); - } - } - else if (dr == DialogResult.Cancel) - { - return; - } - } + await _fileSessionManager.OpenSession(); + + + //if (string.IsNullOrWhiteSpace(sessionFilename)) + //{ + // if (openFileDialog1.ShowDialog() == DialogResult.OK) + // { + // await loadFile(openFileDialog1.FileName); + // } + //} + //else + //{ + // var result = MessageBox.Show("Save existing session?", "Open session", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + // if (result == DialogResult.Yes) + // { + // bool rv = saveFile(sessionFilename, false); + // if (rv) + // { + // if (openFileDialog1.ShowDialog() == DialogResult.OK) + // { + // await loadFile(openFileDialog1.FileName); + // } + // } + // } + // else if (result == DialogResult.No) + // { + // if (openFileDialog1.ShowDialog() == DialogResult.OK) + // { + // await loadFile(openFileDialog1.FileName); + // } + // } + // else if (result == DialogResult.Cancel) + // { + // return; + // } + //} } /// @@ -527,36 +613,42 @@ namespace FizzyLauncher /// /// /// - private void closeToolStripMenuItem_Click(object sender, EventArgs e) + private async void closeToolStripMenuItem_Click(object sender, EventArgs e) { - if (string.IsNullOrWhiteSpace(sessionFilename)) - { - tileContainer1.Clear(); - } - else - { - DialogResult dr = MessageBox.Show("Save existing session?", "Close session", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (dr == DialogResult.Yes) - { - bool rv = saveFile(sessionFilename, false); - if (rv) - { - tileContainer1.Clear(); + await _fileSessionManager.CloseSession(); - sessionFilename = null; - } - } - else if (dr == DialogResult.No) - { - tileContainer1.Clear(); + //if (string.IsNullOrWhiteSpace(sessionFilename)) + //{ + // //flowLayoutPanel1.Controls.Clear(); - sessionFilename = null; - } - else if (dr == DialogResult.Cancel) - { - return; - } - } + // this.Clear(); + //} + //else + //{ + // var result = MessageBox.Show("Save existing session?", "Close session", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + // if (result == DialogResult.Yes) + // { + // bool rv = saveFile(sessionFilename, false); + // if (rv) + // { + // this.Clear(); + // //flowLayoutPanel1.Controls.Clear(); + + // //sessionFilename = null; + // } + // } + // else if (result == DialogResult.No) + // { + // this.Clear(); + // //flowLayoutPanel1.Controls.Clear(); + + // //sessionFilename = null; + // } + // else if (result == DialogResult.Cancel) + // { + // return; + // } + //} } /// @@ -564,16 +656,18 @@ namespace FizzyLauncher /// /// /// - private void saveToolStripMenuItem_Click(object sender, EventArgs e) + private async void saveToolStripMenuItem_Click(object sender, EventArgs e) { - if (string.IsNullOrWhiteSpace(sessionFilename)) - { - saveAsFile(); - } - else - { - saveFile(sessionFilename, true); - } + await _fileSessionManager.SaveSession(); + + //if (string.IsNullOrWhiteSpace(sessionFilename)) + //{ + // saveAsFile(); + //} + //else + //{ + // saveFile(sessionFilename, true); + //} } /// @@ -581,9 +675,11 @@ namespace FizzyLauncher /// /// /// - private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) + private async void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { - saveAsFile(); + await _fileSessionManager.SaveAsSession(); + + //saveAsFile(); } /// @@ -606,7 +702,7 @@ namespace FizzyLauncher /// private void addGroupToolStripMenuItem_Click(object sender, EventArgs e) { - tileContainer1.Add(); + AddNewTileGroup(); } @@ -622,26 +718,7 @@ namespace FizzyLauncher return; } - this.CurrentSession.EnableBigIconInFolder = !this.CurrentSession.EnableBigIconInFolder; - - showBigIconsToolStripMenuItem.Checked = this.CurrentSession.EnableBigIconInFolder; - } - - /// - /// Enable animations - /// - /// - /// - private void enableAnimationsToolStripMenuItem_Click(object sender, EventArgs e) - { - if (this.CurrentSession == null) - { - return; - } - - this.CurrentSession.EnableAnimation = !this.CurrentSession.EnableAnimation; - - enableAnimationsToolStripMenuItem.Checked = this.CurrentSession.EnableAnimation; + this.CurrentSession.ShowBigIcons = !this.CurrentSession.ShowBigIcons; } /// @@ -651,7 +728,14 @@ namespace FizzyLauncher /// private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e) { - this.TopMost = !this.TopMost; + if (this.CurrentSession == null) + { + return; + } + + this.CurrentSession.AlwaysOnTop = !this.CurrentSession.AlwaysOnTop; + + this.TopMost = this.CurrentSession.AlwaysOnTop; } @@ -662,10 +746,13 @@ namespace FizzyLauncher /// private void optionsToolStripMenuItem_Click(object sender, EventArgs e) { - if (optionsForm == null) optionsForm = new OptionsForm(this); - optionsForm.ShowDialog(); + var form = new OptionsForm(this.CurrentSession); + if (form.ShowDialog() == DialogResult.OK) + { + this.CurrentSession = form.Result; - invalidateHotKey(); + InvalidateOptions(); + } } @@ -676,18 +763,7 @@ namespace FizzyLauncher /// private void viewHelpToolStripMenuItem1_Click(object sender, EventArgs e) { - try - { - System.Diagnostics.Process.Start(new ProcessStartInfo() - { - FileName = AppResource.AppHelpURL, - UseShellExecute = true - }); - } - catch - { - // do nothing - } + RyzStudio.Diagnostics.Process.Execute(AppResource.AppHelpURL); } /// @@ -697,19 +773,21 @@ namespace FizzyLauncher /// private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) { - MessageBox.Show(Application.ProductName + " v" + Application.ProductVersion, "About", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(System.Windows.Forms.Application.ProductName + " v" + System.Windows.Forms.Application.ProductVersion, "About", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void menuStrip1_MenuActivate(object sender, EventArgs e) { - alwaysOnTopToolStripMenuItem.Checked = this.TopMost; saveAsToolStripMenuItem.Enabled = !string.IsNullOrWhiteSpace(sessionFilename); + + showBigIconsToolStripMenuItem.Checked = this.CurrentSession.ShowBigIcons; + alwaysOnTopToolStripMenuItem.Checked = this.CurrentSession.AlwaysOnTop; } -#endregion + #endregion -#region notification icon + #region notification icon private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { @@ -726,14 +804,264 @@ namespace FizzyLauncher this.Close(); } -#endregion + #endregion - private void tileContainer1_OnSizeChanged(object sender, EventArgs e) + //private void tileContainer1_OnSizeChanged(object sender, EventArgs e) + //{ + // //int newWidth = this.Padding.Horizontal + SystemInformation.VerticalScrollBarWidth + tileContainer1.CalcWidth; + + // //UIControl.SetClientWidth(this, newWidth); + //} + + + + private void AddNewTileGroup() { - int newWidth = this.Padding.Horizontal + SystemInformation.VerticalScrollBarWidth + tileContainer1.CalcWidth; + var group = new TileGroupModel(); + group.Title = "New Group"; + group.IsExpanded = true; + group.GridSize = new System.Drawing.Size(8, 1); - UIControl.SetClientWidth(this, newWidth); + var container = new RyzStudio.Windows.TileForms.TileContainer(); + container.Title = group.Title; + container.IsOpen = group.IsExpanded; + container.TitleContextMenuStrip = tileContainerMenu1; + container.AutoSizeHeight = true; + container.Tag = group; + + container.AutoResize(group.GridSize.Width, group.GridSize.Height); + + UIControl.Add(flowLayoutPanel1, container); } + private async Task LoadTileGroups(List groupList) + { + await Task.Run(() => + { + UIControl.Clear(flowLayoutPanel1); + + // Load groups + foreach (var item in groupList ?? new List()) + { + var panel = new RyzStudio.Windows.TileForms.TileContainer(); + panel.Title = item.Title; + panel.IsOpen = item.IsExpanded; + panel.TitleContextMenuStrip = tileContainerMenu1; + panel.AutoSizeHeight = true; + panel.Tag = item; + + panel.AutoResize(item.GridSize.Width, item.GridSize.Height); + + UIControl.Add(flowLayoutPanel1, panel); + + // Load tiles + foreach (var item2 in item.Items ?? new List()) + { + var tile = new FizzyLauncher.Windows.Forms.TilePanel(); + tile.LoadInfo(item2); + + panel.Add(tile, item2.Position.X, item2.Position.Y); + } + } + + //InvalidateColumnSize(); + }); + } + + #region Tile container + + /// + /// Add Tile + /// + /// + /// + private void addGroupToolStripMenuItem1_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripMenuItem)sender); + if (container == null) + { + return; + } + + var form = new EditTileForm(); + if (form.ShowDialog() == DialogResult.OK) + { + var result = form.Result; + var newCoord = container.GetNextCoord(); + + var newTile = new FizzyLauncher.Windows.Forms.TilePanel(); + newTile.LoadInfo(result); + + container.Add(newTile, newCoord.X, newCoord.Y); + }; + } + + /// + /// Add Tile Group + /// + /// + /// + private void toolStripMenuItem4_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripMenuItem)sender); + if (container == null) + { + return; + } + + var form = new EditTileFolderForm(); + if (form.ShowDialog() == DialogResult.OK) + { + var result = form.Result; + var newCoord = container.GetNextCoord(); + + var newTile = new FizzyLauncher.Windows.Forms.TilePanel(); + newTile.LoadInfo(result); + + container.Add(newTile, newCoord.X, newCoord.Y); + }; + } + + /// + /// Edit + /// + /// + /// + private void editToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripMenuItem)sender); + if (container == null) + { + return; + } + + var model = UIControl.GetTag(container); + + var form = new EditGroupForm(model); + if (form.ShowDialog() == DialogResult.OK) + { + var result = form.Result; + + container.Title = result.Title; + container.Tag = result; + + container.Invalidate(); + }; + } + + /// + /// Row - Add Row + /// + /// + /// + private void addRowToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripDropDownItem)sender); + if (container == null) + { + return; + } + + container.AddRow(); + } + + /// + /// Row - Remove Row + /// + /// + /// + private void removeRowToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripDropDownItem)sender); + if (container == null) + { + return; + } + + container.RemoveRow(); + } + + /// + /// Move Top + /// + /// + /// + private void topToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripDropDownItem)sender); + if (container == null) + { + return; + } + + UIControl.MoveTop(flowLayoutPanel1, container); + } + + /// + /// Move Up + /// + /// + /// + private void upToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripDropDownItem)sender); + if (container == null) + { + return; + } + + UIControl.MoveUp(flowLayoutPanel1, container); + } + + /// + /// Move Down + /// + /// + /// + private void downToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripDropDownItem)sender); + if (container == null) + { + return; + } + + UIControl.MoveDown(flowLayoutPanel1, container); + } + + /// + /// Move Bottom + /// + /// + /// + private void bottomToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripDropDownItem)sender); + if (container == null) + { + return; + } + + UIControl.MoveBottom(flowLayoutPanel1, container); + } + + /// + /// Remove + /// + /// + /// + private void removeToolStripMenuItem_Click(object sender, EventArgs e) + { + var container = UIControl.GetOwner((ToolStripMenuItem)sender); + if (container == null) + { + return; + } + + flowLayoutPanel1.Controls.Remove(container); + } + + #endregion + } } \ No newline at end of file diff --git a/MainForm.resx b/MainForm.resx index 04386e6..7dd25cd 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -1,4 +1,64 @@ - + + + @@ -370,6 +430,9 @@ 716, 17 + + 831, 17 + AAABAAQAMDAAAAEAIACoJQAARgAAACAgAAABACAAqBAAAO4lAAAYGAAAAQAgAIgJAACWNgAAEBAAAAEA diff --git a/Models/LauncherSession.cs b/Models/LauncherSession.cs index 784b2d8..0647ac5 100644 --- a/Models/LauncherSession.cs +++ b/Models/LauncherSession.cs @@ -1,42 +1,65 @@ using System.Collections.Generic; using System.Drawing; +using RyzStudio.Windows.ThemedForms.ButtonTextBox; namespace FizzyLauncher.Models { public class LauncherSession { - public class HotKeyOptions - { - public bool IsCtrl { get; set; } = false; - public bool IsAlt { get; set; } = false; - public bool IsShift { get; set; } = false; - public int Key { get; set; } = (int)System.Windows.Forms.Keys.None; + public int TilesPerRow { get; set; } = 8; - public int ModifierCode => ((this.IsAlt ? 1 : 0) + (this.IsCtrl ? 2 : 0) + (this.IsShift ? 4 : 0)); + public bool ShowBigIcons { get; set; } = true; - public System.Windows.Forms.Keys KeyCode => (System.Windows.Forms.Keys)this.Key; - } + public ThKeyCodeTextBox.Results ShowToggleHotkey { get; set; } = null; - public enum AutoSaveOption - { - Prompt = 0, - Yes, - No - } + public bool HideOnClose { get; set; } = true; - public int DefaultHeight { get; set; } = 280; - public HotKeyOptions HotKey { get; set; } = null; + public bool HideOnExecute { get; set; } = true; public bool AlwaysOnTop { get; set; } = false; - public bool EnableAnimation { get; set; } = false; - public bool EnableBigIconInFolder { get; set; } = false; - public bool HideOnClose { get; set; } = false; - public bool HideOnClick { get; set; } = false; - public AutoSaveOption AutoSave { get; set; } = AutoSaveOption.Prompt; + + + //public class HotKeyOptions + //{ + // public bool IsCtrl { get; set; } = false; + // public bool IsAlt { get; set; } = false; + // public bool IsShift { get; set; } = false; + // public int Key { get; set; } = (int)System.Windows.Forms.Keys.None; + + // public int ModifierCode => ((this.IsAlt ? 1 : 0) + (this.IsCtrl ? 2 : 0) + (this.IsShift ? 4 : 0)); + + // public System.Windows.Forms.Keys KeyCode => (System.Windows.Forms.Keys)this.Key; + //} + + //public enum AutoSaveOption + //{ + // Prompt = 0, + // Yes, + // No + //} + + //public int DefaultHeight { get; set; } = 280; + + //public ThKeyCodeTextBox.Results HotKey { get; set; } = null; + + //public bool AlwaysOnTop { get; set; } = false; + //public bool EnableAnimation { get; set; } = false; + //public bool EnableBigIconInFolder { get; set; } = false; + + //public bool HideOnClose { get; set; } = false; + //public bool HideOnClick { get; set; } = false; + //public AutoSaveOption AutoSave { get; set; } = AutoSaveOption.Prompt; + public List Groups { get; set; } = new List(); public Point StartPosition { get; set; } = Point.Empty; + public int Height { get; set; } = 280; + + + //public int ColumnCount { get; set; } = 8; + + } } \ No newline at end of file diff --git a/Models/NewFormModel.cs b/Models/NewFormModel.cs new file mode 100644 index 0000000..52233d1 --- /dev/null +++ b/Models/NewFormModel.cs @@ -0,0 +1,10 @@ +namespace FizzyLauncher.Models +{ + public class NewFormModel + { + public int ColumnCount { get; set; } = 8; + + public int GroupCount { get; set; } = 1; + + } +} \ No newline at end of file diff --git a/NewForm.cs b/NewForm.cs index d6691ab..86dbe3f 100644 --- a/NewForm.cs +++ b/NewForm.cs @@ -1,124 +1,168 @@ -using RyzStudio.Windows.ThemedForms; -using System; +using System.Windows.Forms; +using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; +using RyzStudio.Windows.ThemedForms; namespace FizzyLauncher { - public class NewForm : TDialogForm + public class NewForm : TDialog { private System.Windows.Forms.Label label1; - private TButton button1; - private TNumericBox numericBox1; + private ThButton button1; + private ThNumericBox numericBox1; + private ThNumericBox numericBox2; + private Label label2; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1; - public NewForm(MainForm parent) : base() + public NewForm() { InitializeComponent(); - parentForm = parent; + this.OkButton = button1; numericBox1.Minimum = 4; numericBox1.Maximum = 24; - numericBox1.Value = 6; + numericBox1.Value = 8; + numericBox2.Minimum = 1; + numericBox2.Maximum = 8; + numericBox2.Value = 1; } private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); - this.button1 = new RyzStudio.Windows.ThemedForms.TButton(); - this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); - this.numericBox1 = new RyzStudio.Windows.ThemedForms.TNumericBox(); - this.SuspendLayout(); + label1 = new Label(); + button1 = new ThButton(); + tHorizontalSeparator1 = new THorizontalSeparator(); + numericBox1 = new ThNumericBox(); + numericBox2 = new ThNumericBox(); + label2 = new Label(); + SuspendLayout(); // // label1 // - this.label1.AutoSize = true; - this.label1.BackColor = System.Drawing.Color.Transparent; - this.label1.ForeColor = System.Drawing.SystemColors.ControlText; - this.label1.Location = new System.Drawing.Point(10, 21); - this.label1.Margin = new System.Windows.Forms.Padding(0); - this.label1.Name = "label1"; - this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label1.Size = new System.Drawing.Size(137, 34); - this.label1.TabIndex = 153; - this.label1.Text = "Number of Tiles Per Row"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label1.AutoSize = true; + label1.BackColor = System.Drawing.Color.Transparent; + label1.ForeColor = System.Drawing.SystemColors.ControlText; + label1.Location = new System.Drawing.Point(10, 21); + label1.Margin = new Padding(0); + label1.Name = "label1"; + label1.Padding = new Padding(0, 9, 0, 10); + label1.Size = new System.Drawing.Size(76, 34); + label1.TabIndex = 153; + label1.Text = "Tiles Per Row"; + label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // button1 // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.BackColor = System.Drawing.Color.Transparent; - this.button1.IdleImage = null; - this.button1.ActiveImage = null; - this.button1.LabelText = "&Save"; - this.button1.Location = new System.Drawing.Point(241, 109); - this.button1.Margin = new System.Windows.Forms.Padding(10); - this.button1.Name = "button1"; - this.button1.HoverImage = null; - this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); - this.button1.Size = new System.Drawing.Size(128, 32); - this.button1.TabIndex = 173; - this.button1.Click += new System.EventHandler(this.button1_Click); + button1.AcceptButton = null; + button1.ActiveImage = null; + button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + button1.BackColor = System.Drawing.Color.Transparent; + button1.EnableMenuOnClick = false; + button1.EnableReactiveVisual = true; + button1.HoverImage = null; + button1.IdleImage = null; + button1.LabelText = "&Save"; + button1.Location = new System.Drawing.Point(241, 369); + button1.Margin = new Padding(10, 10, 10, 0); + button1.Name = "button1"; + button1.Padding = new Padding(4, 4, 3, 3); + button1.Size = new System.Drawing.Size(128, 32); + button1.TabIndex = 173; + button1.TabStop = false; // // tHorizontalSeparator1 // - this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; - this.tHorizontalSeparator1.Location = new System.Drawing.Point(10, 77); - this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); - this.tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); - this.tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); - this.tHorizontalSeparator1.Name = "tHorizontalSeparator1"; - this.tHorizontalSeparator1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); - this.tHorizontalSeparator1.Size = new System.Drawing.Size(364, 22); - this.tHorizontalSeparator1.TabIndex = 188; + tHorizontalSeparator1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); + tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; + tHorizontalSeparator1.Location = new System.Drawing.Point(10, 337); + tHorizontalSeparator1.Margin = new Padding(0, 10, 0, 0); + tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); + tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); + tHorizontalSeparator1.Name = "tHorizontalSeparator1"; + tHorizontalSeparator1.Size = new System.Drawing.Size(364, 22); + tHorizontalSeparator1.TabIndex = 188; + tHorizontalSeparator1.TabStop = false; // // numericBox1 // - this.numericBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.numericBox1.BackColor = System.Drawing.Color.Transparent; - this.numericBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.numericBox1.Location = new System.Drawing.Point(285, 20); - this.numericBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.numericBox1.Name = "numericBox1"; - this.numericBox1.Padding = new System.Windows.Forms.Padding(8, 8, 7, 7); - this.numericBox1.Size = new System.Drawing.Size(84, 34); - this.numericBox1.AcceptButton = null; - this.numericBox1.TabIndex = 189; - this.numericBox1.Value = 0; + numericBox1.AcceptButton = null; + numericBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; + numericBox1.BackColor = System.Drawing.Color.Transparent; + numericBox1.EnableReactiveVisual = true; + numericBox1.Font = new System.Drawing.Font("Segoe UI", 9F); + numericBox1.Location = new System.Drawing.Point(285, 20); + numericBox1.Margin = new Padding(10, 10, 10, 0); + numericBox1.Maximum = 100; + numericBox1.Minimum = 1; + numericBox1.Name = "numericBox1"; + numericBox1.Padding = new Padding(4, 4, 3, 3); + numericBox1.Size = new System.Drawing.Size(84, 32); + numericBox1.TabIndex = 189; + numericBox1.TabStop = false; + numericBox1.Value = 1; + // + // numericBox2 + // + numericBox2.AcceptButton = null; + numericBox2.Anchor = AnchorStyles.Top | AnchorStyles.Right; + numericBox2.BackColor = System.Drawing.Color.Transparent; + numericBox2.EnableReactiveVisual = true; + numericBox2.Font = new System.Drawing.Font("Segoe UI", 9F); + numericBox2.Location = new System.Drawing.Point(285, 62); + numericBox2.Margin = new Padding(10, 10, 10, 0); + numericBox2.Maximum = 100; + numericBox2.Minimum = 1; + numericBox2.Name = "numericBox2"; + numericBox2.Padding = new Padding(4, 4, 3, 3); + numericBox2.Size = new System.Drawing.Size(84, 32); + numericBox2.TabIndex = 191; + numericBox2.TabStop = false; + numericBox2.Value = 1; + // + // label2 + // + label2.AutoSize = true; + label2.BackColor = System.Drawing.Color.Transparent; + label2.ForeColor = System.Drawing.SystemColors.ControlText; + label2.Location = new System.Drawing.Point(10, 63); + label2.Margin = new Padding(0); + label2.Name = "label2"; + label2.Padding = new Padding(0, 9, 0, 10); + label2.Size = new System.Drawing.Size(106, 34); + label2.TabIndex = 190; + label2.Text = "Number of Groups"; + label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // NewForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(384, 161); - this.Controls.Add(this.numericBox1); - this.Controls.Add(this.tHorizontalSeparator1); - this.Controls.Add(this.button1); - this.Controls.Add(this.label1); - this.MinimumSize = new System.Drawing.Size(400, 200); - this.Name = "NewForm"; - this.Text = "New"; - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(384, 421); + Controls.Add(numericBox2); + Controls.Add(label2); + Controls.Add(numericBox1); + Controls.Add(tHorizontalSeparator1); + Controls.Add(button1); + Controls.Add(label1); + MinimumSize = new System.Drawing.Size(400, 200); + Name = "NewForm"; + Text = "New"; + ResumeLayout(false); + PerformLayout(); } - public MainForm parentForm { get; set; } = null; - - - private void button1_Click(object sender, EventArgs e) + public NewFormModel Result { - if (parentForm != null) + get => new NewFormModel() { - parentForm.Clear(numericBox1.Value); - } - - this.Close(); + ColumnCount = numericBox1.Value, + GroupCount = numericBox2.Value + }; } } diff --git a/NewForm.resx b/NewForm.resx index f298a7b..af32865 100644 --- a/NewForm.resx +++ b/NewForm.resx @@ -1,4 +1,64 @@ - + + + diff --git a/OptionsForm.cs b/OptionsForm.cs index 8e845e5..29e10c4 100644 --- a/OptionsForm.cs +++ b/OptionsForm.cs @@ -1,279 +1,434 @@ -using FizzyLauncher.Models; +using System; +using System.Linq; +using System.Windows.Forms; +using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; using RyzStudio.Windows.ThemedForms; using RyzStudio.Windows.ThemedForms.ButtonTextBox; using RyzStudio.Windows.ThemedForms.PickerBox; -using System; namespace FizzyLauncher { - public class OptionsForm : TDialogForm + public class OptionsForm : TDialog { private System.Windows.Forms.Label label1; - private TButton button1; - private TYesNoPickerBox pickerBox2; + private ThButton button1; + private ThYesNoPickerBox yesNoPickerBox2; private System.Windows.Forms.Label label6; - private TYesNoPickerBox pickerBox3; + private ThYesNoPickerBox yesNoPickerBox3; private System.Windows.Forms.Label label7; - private System.Windows.Forms.Label label8; - private TPickerBox pickerBox1; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1; - private TKeyCodeTextBox textBox1; + private ThKeyCodeTextBox textBox1; + private ThNumericBox numericBox1; + private Label label4; + private FlowLayoutPanel flowLayoutPanel1; + private TTogglePanel tTogglePanel1; + private TTogglePanel tTogglePanel2; + private ThYesNoPickerBox yesNoPickerBox1; + private Label label2; + private ThYesNoPickerBox yesNoPickerBox4; + private Label label3; + + private LauncherSession _appSession = null; - public OptionsForm(MainForm parent) : base() + public OptionsForm(LauncherSession appSession) { InitializeComponent(); - parentForm = parent; + this.OkButton = button1; - pickerBox1.ComboBox.Items.Clear(); - foreach (string item in Enum.GetNames(typeof(LauncherSession.AutoSaveOption))) + numericBox1.Minimum = 4; + numericBox1.Maximum = 24; + + _appSession = appSession; + + if (_appSession != null) { - pickerBox1.ComboBox.Items.Add(item); + numericBox1.Value = _appSession.TilesPerRow; + yesNoPickerBox1.Value = _appSession.ShowBigIcons; + textBox1.UpdateKeyCode(_appSession?.ShowToggleHotkey ?? new ThKeyCodeTextBox.Results()); + yesNoPickerBox2.Value = _appSession.HideOnClose; + yesNoPickerBox3.Value = _appSession.HideOnExecute; + yesNoPickerBox4.Value = _appSession.AlwaysOnTop; } - - if (pickerBox1.ComboBox.Items.Count > 0) pickerBox1.ComboBox.SelectedIndex = 0; - } private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OptionsForm)); - TKeyCodeTextBox.Results results1 = new TKeyCodeTextBox.Results(); - this.label1 = new System.Windows.Forms.Label(); - this.button1 = new TButton(); - this.pickerBox2 = new TYesNoPickerBox(); - this.label6 = new System.Windows.Forms.Label(); - this.pickerBox3 = new TYesNoPickerBox(); - this.label7 = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); - this.pickerBox1 = new TPickerBox(); - this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); - this.textBox1 = new TKeyCodeTextBox(); - this.SuspendLayout(); - // + ThKeyCodeTextBox.Results results2 = new ThKeyCodeTextBox.Results(); + label1 = new Label(); + button1 = new ThButton(); + yesNoPickerBox2 = new ThYesNoPickerBox(); + label6 = new Label(); + yesNoPickerBox3 = new ThYesNoPickerBox(); + label7 = new Label(); + tHorizontalSeparator1 = new THorizontalSeparator(); + textBox1 = new ThKeyCodeTextBox(); + numericBox1 = new ThNumericBox(); + label4 = new Label(); + flowLayoutPanel1 = new FlowLayoutPanel(); + tTogglePanel1 = new TTogglePanel(); + yesNoPickerBox1 = new ThYesNoPickerBox(); + label2 = new Label(); + tTogglePanel2 = new TTogglePanel(); + yesNoPickerBox4 = new ThYesNoPickerBox(); + label3 = new Label(); + flowLayoutPanel1.SuspendLayout(); + tTogglePanel1.SuspendLayout(); + tTogglePanel2.SuspendLayout(); + SuspendLayout(); + // // label1 - // - this.label1.AutoSize = true; - this.label1.BackColor = System.Drawing.Color.Transparent; - this.label1.ForeColor = System.Drawing.SystemColors.ControlText; - this.label1.Location = new System.Drawing.Point(10, 21); - this.label1.Margin = new System.Windows.Forms.Padding(0); - this.label1.Name = "label1"; - this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label1.Size = new System.Drawing.Size(107, 34); - this.label1.TabIndex = 153; - this.label1.Text = "Show/Hide Hotkey"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // + // + label1.AutoSize = true; + label1.BackColor = System.Drawing.Color.Transparent; + label1.ForeColor = System.Drawing.SystemColors.ControlText; + label1.Location = new System.Drawing.Point(1, 22); + label1.Margin = new Padding(0); + label1.Name = "label1"; + label1.Padding = new Padding(0, 8, 0, 0); + label1.Size = new System.Drawing.Size(115, 23); + label1.TabIndex = 153; + label1.Text = "Show Toggle Hotkey"; + label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // button1 - // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.BackColor = System.Drawing.Color.Transparent; - this.button1.IdleImage = null; - this.button1.ActiveImage = null; - this.button1.LabelText = "&Save"; - this.button1.Location = new System.Drawing.Point(241, 469); - this.button1.Margin = new System.Windows.Forms.Padding(10); - this.button1.Name = "button1"; - this.button1.HoverImage = null; - this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); - this.button1.Size = new System.Drawing.Size(128, 32); - this.button1.TabIndex = 173; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // pickerBox2 - // - this.pickerBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pickerBox2.BackColor = System.Drawing.Color.Transparent; - this.pickerBox2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.pickerBox2.Location = new System.Drawing.Point(285, 103); - this.pickerBox2.Margin = new System.Windows.Forms.Padding(10, 4, 10, 4); - this.pickerBox2.Name = "pickerBox2"; - this.pickerBox2.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); - this.pickerBox2.Size = new System.Drawing.Size(84, 34); - this.pickerBox2.AcceptButton = null; - this.pickerBox2.TabIndex = 183; - this.pickerBox2.Value = true; - // + // + button1.AcceptButton = null; + button1.ActiveImage = null; + button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + button1.BackColor = System.Drawing.Color.Transparent; + button1.EnableMenuOnClick = false; + button1.EnableReactiveVisual = true; + button1.HoverImage = null; + button1.IdleImage = null; + button1.LabelText = "&Save"; + button1.Location = new System.Drawing.Point(301, 469); + button1.Margin = new Padding(10, 10, 10, 0); + button1.Name = "button1"; + button1.Padding = new Padding(4, 4, 3, 3); + button1.Size = new System.Drawing.Size(128, 32); + button1.TabIndex = 173; + button1.TabStop = false; + // + // yesNoPickerBox2 + // + yesNoPickerBox2.AcceptButton = null; + yesNoPickerBox2.Anchor = AnchorStyles.Top | AnchorStyles.Right; + yesNoPickerBox2.BackColor = System.Drawing.Color.Transparent; + yesNoPickerBox2.EnableReactiveVisual = true; + yesNoPickerBox2.Font = new System.Drawing.Font("Segoe UI", 9F); + yesNoPickerBox2.Location = new System.Drawing.Point(307, 63); + yesNoPickerBox2.Margin = new Padding(10, 10, 10, 0); + yesNoPickerBox2.Name = "yesNoPickerBox2"; + yesNoPickerBox2.Padding = new Padding(4, 4, 3, 3); + yesNoPickerBox2.SelectedIndex = 1; + yesNoPickerBox2.Size = new System.Drawing.Size(84, 34); + yesNoPickerBox2.TabIndex = 183; + yesNoPickerBox2.TabStop = false; + yesNoPickerBox2.Value = true; + // // label6 - // - this.label6.AutoSize = true; - this.label6.BackColor = System.Drawing.Color.Transparent; - this.label6.ForeColor = System.Drawing.SystemColors.ControlText; - this.label6.Location = new System.Drawing.Point(10, 103); - this.label6.Margin = new System.Windows.Forms.Padding(0); - this.label6.Name = "label6"; - this.label6.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label6.Size = new System.Drawing.Size(83, 34); - this.label6.TabIndex = 182; - this.label6.Text = "Hide On Close"; - this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // pickerBox3 - // - this.pickerBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pickerBox3.BackColor = System.Drawing.Color.Transparent; - this.pickerBox3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.pickerBox3.Location = new System.Drawing.Point(285, 144); - this.pickerBox3.Margin = new System.Windows.Forms.Padding(10, 4, 10, 4); - this.pickerBox3.Name = "pickerBox3"; - this.pickerBox3.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); - this.pickerBox3.Size = new System.Drawing.Size(84, 34); - this.pickerBox3.AcceptButton = null; - this.pickerBox3.TabIndex = 185; - this.pickerBox3.Value = true; - // + // + label6.AutoSize = true; + label6.BackColor = System.Drawing.Color.Transparent; + label6.ForeColor = System.Drawing.SystemColors.ControlText; + label6.Location = new System.Drawing.Point(1, 63); + label6.Margin = new Padding(0); + label6.Name = "label6"; + label6.Padding = new Padding(0, 8, 0, 0); + label6.Size = new System.Drawing.Size(83, 23); + label6.TabIndex = 182; + label6.Text = "Hide On Close"; + label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // yesNoPickerBox3 + // + yesNoPickerBox3.AcceptButton = null; + yesNoPickerBox3.Anchor = AnchorStyles.Top | AnchorStyles.Right; + yesNoPickerBox3.BackColor = System.Drawing.Color.Transparent; + yesNoPickerBox3.EnableReactiveVisual = true; + yesNoPickerBox3.Font = new System.Drawing.Font("Segoe UI", 9F); + yesNoPickerBox3.Location = new System.Drawing.Point(307, 107); + yesNoPickerBox3.Margin = new Padding(10, 10, 10, 0); + yesNoPickerBox3.Name = "yesNoPickerBox3"; + yesNoPickerBox3.Padding = new Padding(4, 4, 3, 3); + yesNoPickerBox3.SelectedIndex = 1; + yesNoPickerBox3.Size = new System.Drawing.Size(84, 34); + yesNoPickerBox3.TabIndex = 185; + yesNoPickerBox3.TabStop = false; + yesNoPickerBox3.Value = true; + // // label7 - // - this.label7.AutoSize = true; - this.label7.BackColor = System.Drawing.Color.Transparent; - this.label7.ForeColor = System.Drawing.SystemColors.ControlText; - this.label7.Location = new System.Drawing.Point(10, 144); - this.label7.Margin = new System.Windows.Forms.Padding(0); - this.label7.Name = "label7"; - this.label7.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label7.Size = new System.Drawing.Size(95, 34); - this.label7.TabIndex = 184; - this.label7.Text = "Hide On Execute"; - this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.BackColor = System.Drawing.Color.Transparent; - this.label8.ForeColor = System.Drawing.SystemColors.ControlText; - this.label8.Location = new System.Drawing.Point(10, 62); - this.label8.Margin = new System.Windows.Forms.Padding(0); - this.label8.Name = "label8"; - this.label8.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label8.Size = new System.Drawing.Size(60, 34); - this.label8.TabIndex = 186; - this.label8.Text = "Auto Save"; - this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // pickerBox1 - // - this.pickerBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pickerBox1.BackColor = System.Drawing.Color.Transparent; - this.pickerBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.pickerBox1.Location = new System.Drawing.Point(285, 62); - this.pickerBox1.Margin = new System.Windows.Forms.Padding(10, 4, 10, 4); - this.pickerBox1.Name = "pickerBox1"; - this.pickerBox1.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); - this.pickerBox1.Size = new System.Drawing.Size(84, 34); - this.pickerBox1.AcceptButton = null; - this.pickerBox1.TabIndex = 187; - // + // + label7.AutoSize = true; + label7.BackColor = System.Drawing.Color.Transparent; + label7.ForeColor = System.Drawing.SystemColors.ControlText; + label7.Location = new System.Drawing.Point(1, 107); + label7.Margin = new Padding(0); + label7.Name = "label7"; + label7.Padding = new Padding(0, 8, 0, 0); + label7.Size = new System.Drawing.Size(95, 23); + label7.TabIndex = 184; + label7.Text = "Hide On Execute"; + label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // tHorizontalSeparator1 - // - this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; - this.tHorizontalSeparator1.Location = new System.Drawing.Point(10, 437); - this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); - this.tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); - this.tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); - this.tHorizontalSeparator1.Name = "tHorizontalSeparator1"; - this.tHorizontalSeparator1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); - this.tHorizontalSeparator1.Size = new System.Drawing.Size(364, 22); - this.tHorizontalSeparator1.TabIndex = 188; - // + // + tHorizontalSeparator1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); + tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; + tHorizontalSeparator1.Location = new System.Drawing.Point(10, 437); + tHorizontalSeparator1.Margin = new Padding(0, 10, 0, 0); + tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); + tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); + tHorizontalSeparator1.Name = "tHorizontalSeparator1"; + tHorizontalSeparator1.Size = new System.Drawing.Size(424, 22); + tHorizontalSeparator1.TabIndex = 188; + tHorizontalSeparator1.TabStop = false; + // // textBox1 - // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.BackColor = System.Drawing.Color.Transparent; - this.textBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox1.HighlightImage = ((System.Drawing.Image)(resources.GetObject("textBox1.HighlightImage"))); - results1.IsAlt = false; - results1.IsCtrl = false; - results1.IsShift = false; - results1.Key = System.Windows.Forms.Keys.None; - this.textBox1.KeyCodeResults = results1; - this.textBox1.Location = new System.Drawing.Point(192, 20); - this.textBox1.Margin = new System.Windows.Forms.Padding(10, 3, 3, 3); - this.textBox1.Name = "textBox1"; - this.textBox1.NormalImage = ((System.Drawing.Image)(resources.GetObject("textBox1.NormalImage"))); - this.textBox1.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox1.Size = new System.Drawing.Size(177, 35); - this.textBox1.AcceptButton = null; - this.textBox1.TabIndex = 189; - this.textBox1.UseSystemPasswordChar = false; - // + // + textBox1.AcceptButton = null; + textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBox1.BackColor = System.Drawing.Color.Transparent; + textBox1.EnableReactiveVisual = true; + textBox1.Font = new System.Drawing.Font("Segoe UI", 9F); + textBox1.HighlightImage = (System.Drawing.Image)resources.GetObject("textBox1.HighlightImage"); + results2.IsAlt = false; + results2.IsCtrl = false; + results2.IsShift = false; + results2.Key = Keys.None; + textBox1.KeyCodeResults = results2; + textBox1.Location = new System.Drawing.Point(192, 21); + textBox1.Margin = new Padding(10, 10, 10, 0); + textBox1.Name = "textBox1"; + textBox1.NormalImage = (System.Drawing.Image)resources.GetObject("textBox1.NormalImage"); + textBox1.Padding = new Padding(4, 4, 3, 3); + textBox1.Size = new System.Drawing.Size(199, 32); + textBox1.TabIndex = 189; + textBox1.TabStop = false; + textBox1.UseSystemPasswordChar = false; + // + // numericBox1 + // + numericBox1.AcceptButton = null; + numericBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; + numericBox1.BackColor = System.Drawing.Color.Transparent; + numericBox1.EnableReactiveVisual = true; + numericBox1.Font = new System.Drawing.Font("Segoe UI", 9F); + numericBox1.Location = new System.Drawing.Point(252, 22); + numericBox1.Margin = new Padding(10, 10, 10, 0); + numericBox1.Maximum = 100; + numericBox1.Minimum = 1; + numericBox1.Name = "numericBox1"; + numericBox1.Padding = new Padding(4, 4, 3, 3); + numericBox1.Size = new System.Drawing.Size(139, 32); + numericBox1.TabIndex = 192; + numericBox1.TabStop = false; + numericBox1.Value = 1; + // + // label4 + // + label4.AutoSize = true; + label4.BackColor = System.Drawing.Color.Transparent; + label4.ForeColor = System.Drawing.SystemColors.ControlText; + label4.Location = new System.Drawing.Point(1, 22); + label4.Margin = new Padding(0); + label4.Name = "label4"; + label4.Padding = new Padding(0, 8, 0, 0); + label4.Size = new System.Drawing.Size(76, 23); + label4.TabIndex = 193; + label4.Text = "Tiles Per Row"; + label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // flowLayoutPanel1 + // + flowLayoutPanel1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + flowLayoutPanel1.AutoScroll = true; + flowLayoutPanel1.BackColor = System.Drawing.Color.Transparent; + flowLayoutPanel1.Controls.Add(tTogglePanel1); + flowLayoutPanel1.Controls.Add(tTogglePanel2); + flowLayoutPanel1.FlowDirection = FlowDirection.TopDown; + flowLayoutPanel1.Location = new System.Drawing.Point(10, 12); + flowLayoutPanel1.Name = "flowLayoutPanel1"; + flowLayoutPanel1.Size = new System.Drawing.Size(424, 412); + flowLayoutPanel1.TabIndex = 194; + flowLayoutPanel1.WrapContents = false; + flowLayoutPanel1.Resize += flowLayoutPanel1_Resize; + // + // tTogglePanel1 + // + tTogglePanel1.AutoScrollMargin = new System.Drawing.Size(0, 0); + tTogglePanel1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + tTogglePanel1.Controls.Add(yesNoPickerBox1); + tTogglePanel1.Controls.Add(label2); + tTogglePanel1.Controls.Add(label4); + tTogglePanel1.Controls.Add(numericBox1); + tTogglePanel1.ForeColor = System.Drawing.Color.FromArgb(99, 105, 119); + tTogglePanel1.IsOpen = true; + tTogglePanel1.Location = new System.Drawing.Point(0, 0); + tTogglePanel1.Margin = new Padding(0); + tTogglePanel1.Name = "tTogglePanel1"; + tTogglePanel1.Padding = new Padding(0, 22, 0, 0); + tTogglePanel1.Size = new System.Drawing.Size(401, 119); + tTogglePanel1.TabIndex = 0; + tTogglePanel1.Title = "Appearance"; + tTogglePanel1.TitleContextMenuStrip = null; + tTogglePanel1.TitleCursor = Cursors.Default; + tTogglePanel1.TitlePadding = new Padding(4, 4, 0, 2); + // + // yesNoPickerBox1 + // + yesNoPickerBox1.AcceptButton = null; + yesNoPickerBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; + yesNoPickerBox1.BackColor = System.Drawing.Color.Transparent; + yesNoPickerBox1.EnableReactiveVisual = true; + yesNoPickerBox1.Font = new System.Drawing.Font("Segoe UI", 9F); + yesNoPickerBox1.Location = new System.Drawing.Point(307, 64); + yesNoPickerBox1.Margin = new Padding(10, 10, 10, 0); + yesNoPickerBox1.Name = "yesNoPickerBox1"; + yesNoPickerBox1.Padding = new Padding(4, 4, 3, 3); + yesNoPickerBox1.SelectedIndex = 1; + yesNoPickerBox1.Size = new System.Drawing.Size(84, 34); + yesNoPickerBox1.TabIndex = 195; + yesNoPickerBox1.TabStop = false; + yesNoPickerBox1.Value = true; + // + // label2 + // + label2.AutoSize = true; + label2.BackColor = System.Drawing.Color.Transparent; + label2.ForeColor = System.Drawing.SystemColors.ControlText; + label2.Location = new System.Drawing.Point(1, 64); + label2.Margin = new Padding(0); + label2.Name = "label2"; + label2.Padding = new Padding(0, 8, 0, 0); + label2.Size = new System.Drawing.Size(87, 23); + label2.TabIndex = 194; + label2.Text = "Show Big Icons"; + label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // tTogglePanel2 + // + tTogglePanel2.AutoScrollMargin = new System.Drawing.Size(0, 0); + tTogglePanel2.AutoScrollMinSize = new System.Drawing.Size(0, 0); + tTogglePanel2.Controls.Add(yesNoPickerBox4); + tTogglePanel2.Controls.Add(label3); + tTogglePanel2.Controls.Add(label1); + tTogglePanel2.Controls.Add(textBox1); + tTogglePanel2.Controls.Add(yesNoPickerBox2); + tTogglePanel2.Controls.Add(yesNoPickerBox3); + tTogglePanel2.Controls.Add(label6); + tTogglePanel2.Controls.Add(label7); + tTogglePanel2.ForeColor = System.Drawing.Color.FromArgb(99, 105, 119); + tTogglePanel2.IsOpen = true; + tTogglePanel2.Location = new System.Drawing.Point(0, 119); + tTogglePanel2.Margin = new Padding(0); + tTogglePanel2.Name = "tTogglePanel2"; + tTogglePanel2.Padding = new Padding(0, 22, 0, 0); + tTogglePanel2.Size = new System.Drawing.Size(401, 206); + tTogglePanel2.TabIndex = 1; + tTogglePanel2.Title = "Behaviour"; + tTogglePanel2.TitleContextMenuStrip = null; + tTogglePanel2.TitleCursor = Cursors.Default; + tTogglePanel2.TitlePadding = new Padding(4, 4, 0, 2); + // + // yesNoPickerBox4 + // + yesNoPickerBox4.AcceptButton = null; + yesNoPickerBox4.Anchor = AnchorStyles.Top | AnchorStyles.Right; + yesNoPickerBox4.BackColor = System.Drawing.Color.Transparent; + yesNoPickerBox4.EnableReactiveVisual = true; + yesNoPickerBox4.Font = new System.Drawing.Font("Segoe UI", 9F); + yesNoPickerBox4.Location = new System.Drawing.Point(307, 151); + yesNoPickerBox4.Margin = new Padding(10, 10, 10, 0); + yesNoPickerBox4.Name = "yesNoPickerBox4"; + yesNoPickerBox4.Padding = new Padding(4, 4, 3, 3); + yesNoPickerBox4.SelectedIndex = 1; + yesNoPickerBox4.Size = new System.Drawing.Size(84, 34); + yesNoPickerBox4.TabIndex = 191; + yesNoPickerBox4.TabStop = false; + yesNoPickerBox4.Value = true; + // + // label3 + // + label3.AutoSize = true; + label3.BackColor = System.Drawing.Color.Transparent; + label3.ForeColor = System.Drawing.SystemColors.ControlText; + label3.Location = new System.Drawing.Point(1, 151); + label3.Margin = new Padding(0); + label3.Name = "label3"; + label3.Padding = new Padding(0, 8, 0, 0); + label3.Size = new System.Drawing.Size(85, 23); + label3.TabIndex = 190; + label3.Text = "Always On Top"; + label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // OptionsForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(384, 521); - this.Controls.Add(this.textBox1); - this.Controls.Add(this.tHorizontalSeparator1); - this.Controls.Add(this.pickerBox1); - this.Controls.Add(this.label8); - this.Controls.Add(this.pickerBox3); - this.Controls.Add(this.label7); - this.Controls.Add(this.pickerBox2); - this.Controls.Add(this.label6); - this.Controls.Add(this.button1); - this.Controls.Add(this.label1); - this.MinimumSize = new System.Drawing.Size(400, 560); - this.Name = "OptionsForm"; - this.Text = "Options"; - this.ResumeLayout(false); - this.PerformLayout(); - + // + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(444, 521); + Controls.Add(flowLayoutPanel1); + Controls.Add(tHorizontalSeparator1); + Controls.Add(button1); + MinimumSize = new System.Drawing.Size(460, 560); + Name = "OptionsForm"; + Text = "Options"; + flowLayoutPanel1.ResumeLayout(false); + tTogglePanel1.ResumeLayout(false); + tTogglePanel1.PerformLayout(); + tTogglePanel2.ResumeLayout(false); + tTogglePanel2.PerformLayout(); + ResumeLayout(false); } - protected override void OnShown(EventArgs e) + protected override void OnLoad(EventArgs e) { - base.OnShown(e); + base.OnLoad(e); - if (parentForm == null) - { - return; - } - - if (parentForm.CurrentSession == null) - { - return; - } - - // hotkey - if (parentForm.CurrentSession.HotKey != null) - { - textBox1.UpdateKeyCode(parentForm.CurrentSession.HotKey.IsCtrl, parentForm.CurrentSession.HotKey.IsAlt, parentForm.CurrentSession.HotKey.IsShift, parentForm.CurrentSession.HotKey.KeyCode); - } - - pickerBox1.ComboBox.SelectedIndex = (int)parentForm.CurrentSession.AutoSave; - pickerBox2.Value = parentForm.CurrentSession.HideOnClose; - pickerBox3.Value = parentForm.CurrentSession.HideOnClick; + flowLayoutPanel1_Resize(null, e); } + //protected override void OnShown(EventArgs e) + //{ + // base.OnShown(e); - public MainForm parentForm { get; set; } = null; + // flowLayoutPanel1_Resize(null, e); + //} - - private void button1_Click(object sender, EventArgs e) + private void flowLayoutPanel1_Resize(object sender, EventArgs e) { - if (parentForm != null) + var width = flowLayoutPanel1.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth; + + foreach (var item in flowLayoutPanel1.Controls.OfType()) { - if (parentForm.CurrentSession == null) parentForm.CurrentSession = new LauncherSession(); - if (parentForm.CurrentSession.HotKey == null) parentForm.CurrentSession.HotKey = new LauncherSession.HotKeyOptions(); - - parentForm.CurrentSession.HotKey.IsCtrl = textBox1.KeyCodeResults.IsCtrl; - parentForm.CurrentSession.HotKey.IsAlt = textBox1.KeyCodeResults.IsAlt; - parentForm.CurrentSession.HotKey.IsShift = textBox1.KeyCodeResults.IsShift; - parentForm.CurrentSession.HotKey.Key = textBox1.KeyCodeResults.KeyCode; - - parentForm.CurrentSession.AutoSave = (LauncherSession.AutoSaveOption)pickerBox1.ComboBox.SelectedIndex; - parentForm.CurrentSession.HideOnClose = pickerBox2.Value; - parentForm.CurrentSession.HideOnClick = pickerBox3.Value; - + item.Width = width; } + } - this.Close(); + public LauncherSession Result + { + get + { + if (_appSession == null) + { + _appSession = new LauncherSession(); + } + + _appSession.TilesPerRow = numericBox1.Value; + _appSession.ShowBigIcons = yesNoPickerBox1.Value; + _appSession.ShowToggleHotkey = textBox1.KeyCodeResults; + _appSession.HideOnClose = yesNoPickerBox2.Value; + _appSession.HideOnExecute = yesNoPickerBox3.Value; + _appSession.AlwaysOnTop = yesNoPickerBox4.Value; + + return _appSession; + } } } diff --git a/OptionsForm.resx b/OptionsForm.resx index c8f691f..0386da6 100644 --- a/OptionsForm.resx +++ b/OptionsForm.resx @@ -1,4 +1,64 @@ - + + + @@ -60,21 +120,22 @@ - iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAYAAAAmlE46AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAClSURBVDhP7dI/ - DgFBGIbxSVTKjcRx3MLqXYCOjkocQcMF3MAZOIKaE5AthOexf2QnbJQKb/JLJvO9XzLFhCgtbHDBveB5 - DWcfM8ANC0wKnr1LUUsbHXSxxBlJxDtnduy6E04on/Utd0IPOxwxxBT9iHfO7Nh155kV9vmxMXbsVvkv - vvIji4f82Bg7tcUxrpih/NyxOeyMUMVPu0WGd39TzuzQDeEB5/ZKvTSyulEAAAAASUVORK5CYII= + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wQAADsEBuJFr7QAAAN5JREFUOE/tUzsKwkAUXLCyFMHjeIvdB4Gk8ALamU4rsbLaTWz0AOYGOYMewTqe + QLEQnZc8WRMSsBYHhrzPzJBin2pC60PPGLs3xl3Bp5DrHe9E1g2tHUH8QMjKmGReketyZkRWh9abfhTZ + YRimI4jWRPYSBMngkzzjHWtYyx6xK4X0Anz/7rcsxM4BdoxBTuTOqCdEaUyU6DrTuNqxxuXsEXsFDLfg + UdpOsIa10nr8A34p4CRtJ1jTGoC3PsPiBi78ETXplqzBwU3F5sHHgWWGJ3rHt+3tg+Uu84ek1AsYYd8q + EsfwCwAAAABJRU5ErkJggg== - iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAYAAAAmlE46AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAADTSURBVDhP7ZI7 - CsJQEEUfWFmK4HLchdpnA9ppp5W4BBtdQNyBC0ilRf6VdVyBwUL03JdXxC/YWThwmDcz94YJjKmH7/uN - OI7XaZqekiS5Cr1hpZmTPQemAeILeU4eC/dWr+9kVQRB0MzzvB2GYQfBAsExiqJWHfU0k0ZaeQyNAuxa - X1CYLMu6/MOW4kD2YAK9B9TznGYrj12XVZY0drb4ENJI68q/sR4/YoS9K9+GNHdGLmIEJV+cku1xP4Jh - Ri7JQ2erDp3mBs7w6jaFZht74MaYGwmLbkeRGexGAAAAAElFTkSuQmCC + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wQAADsEBuJFr7QAAANFJREFUOE/tkzEKAjEURANWliJ4HG+h9l5AO7fTSjyCxWpCIBB2b+AZ9AjW6wlc + LGSdWb9Elw1YiwOP/Pw/E1Ikqqksyzpa670x5goqgfWOM7HFhfAE5jvWNdYFkZq9sdg+laZp13vfBwOY + NjBfnHO9d9jjjB56mZG4UhgW4HXdbykkXl97iMYBnFFPrbUJGDVIOKOHXmYk/hSaW3CUbVT00CvboP8B + v3TASbZR0RM7YA5KsAT1J2phBUq8wpnEgvg5MMwxvGFte/uVzPLwkZR6AInAKK6aICfTAAAAAElFTkSu + QmCC \ No newline at end of file diff --git a/Windows/Forms/EditGroupForm.cs b/Windows/Forms/EditGroupForm.cs index 2b0314c..be037ed 100644 --- a/Windows/Forms/EditGroupForm.cs +++ b/Windows/Forms/EditGroupForm.cs @@ -1,43 +1,49 @@ -using FizzyLauncher.Models; +using System.Windows.Forms; +using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; using RyzStudio.Windows.ThemedForms; -using System; namespace FizzyLauncher.Windows.Forms { - public class EditGroupForm : TDialogForm + public class EditGroupForm : TDialog { - public static void ShowDialog(TilePanelLayout control) - { - EditGroupForm form = new EditGroupForm(); - form.TilePanelLayout = control; - form.ShowDialog(); - } - - private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; - private TButton button1; - private TPickerBox pickerBox1; + private ThButton button1; + private ThPickerBox pickerBox1; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator2; - private TTextBox textBox1; + private ThTextBox textBox1; - public EditGroupForm() : base() + public EditGroupForm(TileGroupModel model = null) { InitializeComponent(); + this.StartPosition = FormStartPosition.WindowsDefaultLocation; + this.Text = ((model == null) ? "Add Group" : "Edit Group"); + this.OkButton = button1; + pickerBox1.ComboBox.Items.Clear(); pickerBox1.ComboBox.Items.AddRange(new string[] { "No", "Yes" }); - if (pickerBox1.ComboBox.Items.Count > 0) pickerBox1.ComboBox.SelectedIndex = 0; + if (pickerBox1.ComboBox.Items.Count > 0) + { + pickerBox1.ComboBox.SelectedIndex = 0; + } + + if (model != null) + { + textBox1.Text = model.Title?.Trim() ?? string.Empty; + pickerBox1.ComboBox.SelectedIndex = (model.IsExclusive ? 1 : 0); + } } private void InitializeComponent() { - this.textBox1 = new RyzStudio.Windows.ThemedForms.TTextBox(); + this.textBox1 = new ThTextBox(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); - this.button1 = new RyzStudio.Windows.ThemedForms.TButton(); - this.pickerBox1 = new RyzStudio.Windows.ThemedForms.TPickerBox(); + this.button1 = new ThButton(); + this.pickerBox1 = new ThPickerBox(); this.horizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); this.SuspendLayout(); // @@ -97,7 +103,6 @@ namespace FizzyLauncher.Windows.Forms this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); this.button1.Size = new System.Drawing.Size(128, 32); this.button1.TabIndex = 173; - this.button1.Click += new System.EventHandler(this.button1_Click); // // pickerBox1 // @@ -145,31 +150,15 @@ namespace FizzyLauncher.Windows.Forms } - protected override void OnShown(EventArgs e) - { - base.OnShown(e); - if (this.TilePanelLayout != null) + public TileGroupModel Result + { + get => new TileGroupModel() { - textBox1.Text = this.TilePanelLayout.Model.Title; - pickerBox1.ComboBox.SelectedIndex = (this.TilePanelLayout.Model.IsExclusive ? 1 : 0); - } - } - - - public TilePanelLayout TilePanelLayout { get; set; } = null; - - - private void button1_Click(object sender, EventArgs e) - { - TileGroupModel model = this.TilePanelLayout.Model; - model.Title = textBox1.Text?.Trim(); - model.IsExclusive = (pickerBox1.ComboBox.SelectedIndex == 1); - - this.TilePanelLayout.UpdateModel(model); - - this.Close(); + Title = textBox1.Text?.Trim() ?? string.Empty, + IsExclusive = (pickerBox1.ComboBox.SelectedIndex == 1) + }; } } -} +} \ No newline at end of file diff --git a/Windows/Forms/EditTileFolderForm.cs b/Windows/Forms/EditTileFolderForm.cs index 2bb45d7..42b97e1 100644 --- a/Windows/Forms/EditTileFolderForm.cs +++ b/Windows/Forms/EditTileFolderForm.cs @@ -1,309 +1,232 @@ -using FizzyLauncher.Models; -using RyzStudio.Windows.ThemedForms; -using System; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; +using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; +using RyzStudio.Windows.ThemedForms; namespace FizzyLauncher.Windows.Forms { - public class EditTileFolderForm : TDialogForm + public class EditTileFolderForm : TDialog { - public static void ShowAddDialog(TilePanelLayout control, Point coord) - { - EditTileFolderForm form = new EditTileFolderForm(DialogModeType.Add); - form.TilePanelLayout = control; - form.AimCoord = coord; - form.ShowDialog(); - } - - public static void ShowEditDialog(TilePanel control) - { - EditTileFolderForm form = new EditTileFolderForm(DialogModeType.Edit); - form.TilePanel = control; - form.ShowDialog(); - } - - private System.Windows.Forms.Label label1; - private TButton button1; + private ThButton button1; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator2; - private TTextBox textBox1; - private TListBox listBox1; + private ThTextBox textBox1; + private ThListBox listBox1; private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1; private System.Windows.Forms.Label label2; - public enum DialogModeType - { - Add = 0, - Edit - } - - - protected DialogModeType dialogMode = DialogModeType.Add; - - - public EditTileFolderForm(DialogModeType dialogMode) : base() + public EditTileFolderForm(TileModel model = null) { InitializeComponent(); - this.DialogMode = dialogMode; + this.StartPosition = FormStartPosition.WindowsDefaultLocation; + this.OkButton = button1; + + if (model != null) + { + this.Text = "Edit Folder"; + + textBox1.Text = model?.Title ?? string.Empty; + + foreach (TileModel item in model.Items ?? new System.Collections.Generic.List()) + { + if (item.IsGroup) + { + continue; + } + + listBox1.ListBox.Items.Add(item); + } + } + else + { + this.Text = "Add Folder"; + } } private void InitializeComponent() { - this.textBox1 = new RyzStudio.Windows.ThemedForms.TTextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.button1 = new RyzStudio.Windows.ThemedForms.TButton(); - this.horizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); - this.listBox1 = new RyzStudio.Windows.ThemedForms.TListBox(); - this.label2 = new System.Windows.Forms.Label(); - this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); - this.SuspendLayout(); + textBox1 = new ThTextBox(); + label1 = new Label(); + button1 = new ThButton(); + horizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + listBox1 = new ThListBox(); + label2 = new Label(); + tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + SuspendLayout(); // // textBox1 // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.BackColor = System.Drawing.Color.Transparent; - this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox1.Location = new System.Drawing.Point(192, 20); - this.textBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.textBox1.Name = "textBox1"; - this.textBox1.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox1.Size = new System.Drawing.Size(177, 35); - this.textBox1.AcceptButton = null; - this.textBox1.TabIndex = 152; - this.textBox1.UseSystemPasswordChar = false; + textBox1.AcceptButton = null; + textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBox1.BackColor = Color.Transparent; + textBox1.EnableReactiveVisual = true; + textBox1.Font = new Font("Microsoft Sans Serif", 8.25F); + textBox1.Location = new Point(109, 20); + textBox1.Margin = new Padding(10, 10, 10, 0); + textBox1.Name = "textBox1"; + textBox1.Padding = new Padding(4, 4, 3, 3); + textBox1.ReadOnly = false; + textBox1.Size = new Size(260, 35); + textBox1.TabIndex = 152; + textBox1.TabStop = false; + textBox1.UseSystemPasswordChar = false; // // label1 // - this.label1.AutoSize = true; - this.label1.BackColor = System.Drawing.Color.Transparent; - this.label1.ForeColor = System.Drawing.SystemColors.ControlText; - this.label1.Location = new System.Drawing.Point(10, 21); - this.label1.Margin = new System.Windows.Forms.Padding(0); - this.label1.Name = "label1"; - this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label1.Size = new System.Drawing.Size(29, 34); - this.label1.TabIndex = 153; - this.label1.Text = "Title"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label1.AutoSize = true; + label1.BackColor = Color.Transparent; + label1.ForeColor = SystemColors.ControlText; + label1.Location = new Point(10, 21); + label1.Margin = new Padding(0); + label1.Name = "label1"; + label1.Padding = new Padding(0, 9, 0, 10); + label1.Size = new Size(29, 34); + label1.TabIndex = 153; + label1.Text = "Title"; + label1.TextAlign = ContentAlignment.MiddleLeft; // // button1 // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.BackColor = System.Drawing.Color.Transparent; - this.button1.IdleImage = null; - this.button1.ActiveImage = null; - this.button1.LabelText = "&Save"; - this.button1.Location = new System.Drawing.Point(241, 469); - this.button1.Margin = new System.Windows.Forms.Padding(10); - this.button1.Name = "button1"; - this.button1.HoverImage = null; - this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); - this.button1.Size = new System.Drawing.Size(128, 32); - this.button1.TabIndex = 173; - this.button1.Click += new System.EventHandler(this.button1_Click); + button1.AcceptButton = null; + button1.ActiveImage = null; + button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + button1.BackColor = Color.Transparent; + button1.EnableMenuOnClick = false; + button1.EnableReactiveVisual = true; + button1.HoverImage = null; + button1.IdleImage = null; + button1.LabelText = "&Save"; + button1.Location = new Point(241, 469); + button1.Margin = new Padding(10, 10, 10, 0); + button1.Name = "button1"; + button1.Padding = new Padding(4, 4, 3, 3); + button1.Size = new Size(128, 32); + button1.TabIndex = 173; + button1.TabStop = false; // // horizontalSeparator2 // - this.horizontalSeparator2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.horizontalSeparator2.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.horizontalSeparator2.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.horizontalSeparator2.BackColor = System.Drawing.Color.Transparent; - this.horizontalSeparator2.Location = new System.Drawing.Point(10, 61); - this.horizontalSeparator2.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); - this.horizontalSeparator2.MaximumSize = new System.Drawing.Size(4920, 2); - this.horizontalSeparator2.MinimumSize = new System.Drawing.Size(0, 22); - this.horizontalSeparator2.Name = "horizontalSeparator2"; - this.horizontalSeparator2.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); - this.horizontalSeparator2.Size = new System.Drawing.Size(364, 22); - this.horizontalSeparator2.TabIndex = 177; + horizontalSeparator2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + horizontalSeparator2.AutoScrollMargin = new Size(0, 0); + horizontalSeparator2.AutoScrollMinSize = new Size(0, 0); + horizontalSeparator2.BackColor = Color.Transparent; + horizontalSeparator2.Location = new Point(10, 61); + horizontalSeparator2.Margin = new Padding(0, 10, 0, 0); + horizontalSeparator2.MaximumSize = new Size(4920, 2); + horizontalSeparator2.MinimumSize = new Size(0, 22); + horizontalSeparator2.Name = "horizontalSeparator2"; + horizontalSeparator2.Size = new Size(364, 22); + horizontalSeparator2.TabIndex = 177; + horizontalSeparator2.TabStop = false; // // listBox1 // - this.listBox1.AllowDrop = true; - this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.listBox1.BackColor = System.Drawing.Color.Transparent; - this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.listBox1.Location = new System.Drawing.Point(109, 87); - this.listBox1.Margin = new System.Windows.Forms.Padding(10, 4, 10, 4); - this.listBox1.Name = "listBox1"; - this.listBox1.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); - this.listBox1.Size = new System.Drawing.Size(260, 346); - this.listBox1.AcceptButton = null; - this.listBox1.TabIndex = 180; - this.listBox1.OnAdd += new System.EventHandler(this.listBox1_OnAdd); - this.listBox1.OnEdit += new System.EventHandler(this.listBox1_OnEdit); - this.listBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listBox1_DragDrop); - this.listBox1.DragOver += new System.Windows.Forms.DragEventHandler(this.listBox1_DragOver); + listBox1.AcceptButton = null; + listBox1.AllowDrop = true; + listBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + listBox1.BackColor = Color.Transparent; + listBox1.EnableReactiveVisual = true; + listBox1.Font = new Font("Microsoft Sans Serif", 8.25F); + listBox1.Location = new Point(109, 87); + listBox1.Margin = new Padding(10, 10, 10, 0); + listBox1.Name = "listBox1"; + listBox1.Padding = new Padding(4, 4, 3, 3); + listBox1.Size = new Size(260, 346); + listBox1.TabIndex = 180; + listBox1.OnAdd += listBox1_OnAdd; + listBox1.OnEdit += listBox1_OnEdit; + listBox1.DragDrop += listBox1_DragDrop; + listBox1.DragOver += listBox1_DragOver; // // label2 // - this.label2.AutoSize = true; - this.label2.BackColor = System.Drawing.Color.Transparent; - this.label2.ForeColor = System.Drawing.SystemColors.ControlText; - this.label2.Location = new System.Drawing.Point(8, 87); - this.label2.Name = "label2"; - this.label2.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label2.Size = new System.Drawing.Size(25, 34); - this.label2.TabIndex = 181; - this.label2.Text = "List"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label2.AutoSize = true; + label2.BackColor = Color.Transparent; + label2.ForeColor = SystemColors.ControlText; + label2.Location = new Point(8, 87); + label2.Name = "label2"; + label2.Padding = new Padding(0, 9, 0, 10); + label2.Size = new Size(30, 34); + label2.TabIndex = 181; + label2.Text = "Tiles"; + label2.TextAlign = ContentAlignment.MiddleLeft; // // tHorizontalSeparator1 // - this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent; - this.tHorizontalSeparator1.Location = new System.Drawing.Point(10, 437); - this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); - this.tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); - this.tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); - this.tHorizontalSeparator1.Name = "tHorizontalSeparator1"; - this.tHorizontalSeparator1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); - this.tHorizontalSeparator1.Size = new System.Drawing.Size(364, 22); - this.tHorizontalSeparator1.TabIndex = 182; + tHorizontalSeparator1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + tHorizontalSeparator1.AutoScrollMargin = new Size(0, 0); + tHorizontalSeparator1.AutoScrollMinSize = new Size(0, 0); + tHorizontalSeparator1.BackColor = Color.Transparent; + tHorizontalSeparator1.Location = new Point(10, 437); + tHorizontalSeparator1.Margin = new Padding(0, 10, 0, 0); + tHorizontalSeparator1.MaximumSize = new Size(4920, 2); + tHorizontalSeparator1.MinimumSize = new Size(0, 22); + tHorizontalSeparator1.Name = "tHorizontalSeparator1"; + tHorizontalSeparator1.Size = new Size(364, 22); + tHorizontalSeparator1.TabIndex = 182; + tHorizontalSeparator1.TabStop = false; // // EditTileFolderForm // - this.ClientSize = new System.Drawing.Size(384, 521); - this.Controls.Add(this.tHorizontalSeparator1); - this.Controls.Add(this.label2); - this.Controls.Add(this.listBox1); - this.Controls.Add(this.horizontalSeparator2); - this.Controls.Add(this.button1); - this.Controls.Add(this.label1); - this.Controls.Add(this.textBox1); - this.MinimumSize = new System.Drawing.Size(400, 560); - this.Name = "EditTileFolderForm"; - this.Text = "Add List Tile"; - this.ResumeLayout(false); - this.PerformLayout(); - + ClientSize = new Size(384, 521); + Controls.Add(tHorizontalSeparator1); + Controls.Add(label2); + Controls.Add(listBox1); + Controls.Add(horizontalSeparator2); + Controls.Add(button1); + Controls.Add(label1); + Controls.Add(textBox1); + MinimumSize = new Size(400, 560); + Name = "EditTileFolderForm"; + Text = "Add List Tile"; + ResumeLayout(false); + PerformLayout(); } - protected override void OnShown(EventArgs e) + + public TileModel Result { - base.OnShown(e); - - if (this.DialogMode == DialogModeType.Edit) + get { - listBox1.ListBox.Items.Clear(); - - if (this.TilePanel == null) return; - if (this.TilePanel.ModelInfo == null) return; - - textBox1.Text = this.TilePanel.ModelInfo.Title; - - if (this.TilePanel.ModelInfo.Items != null) + var result = new TileModel() { - foreach (TileModel item in this.TilePanel.ModelInfo.Items) + Title = textBox1.Text?.Trim() ?? string.Empty, + IsGroup = true, + Items = new List() + }; + + foreach (TileModel item in listBox1.ListBox.Items.OfType()) + { + if (item.IsGroup) { - if (item.IsGroup) - { - continue; - } - - listBox1.ListBox.Items.Add(item); + continue; } + + result.Items.Add(item); } + + return result; } } - public TilePanelLayout TilePanelLayout { get; set; } = null; - - public TilePanel TilePanel { get; set; } = null; - - public Point AimCoord { get; set; } = new Point(-1, -1); - - public DialogModeType DialogMode + private void listBox1_OnAdd(object sender, EventArgs e) { - get => dialogMode; - set + var form = new EditTileForm(); + if (form.ShowDialog() == DialogResult.OK) { - dialogMode = value; - - switch (dialogMode) - { - case DialogModeType.Add: - this.Text = "Add Folder"; - textBox1.Text = "New Folder"; - break; - case DialogModeType.Edit: - this.Text = "Edit Folder"; - break; - default: break; - } - } - } - - - private void button1_Click(object sender, EventArgs e) - { - TileModel model = new TileModel() - { - Title = textBox1.Text?.Trim(), - IsGroup = true + listBox1.ListBox.Items.Add(form.Result); }; - - switch (this.DialogMode) - { - case DialogModeType.Add: - if (!this.AimCoord.Equals(new Point(-1, -1))) - { - model.Position = this.AimCoord; - } - - model.Items = new System.Collections.Generic.List(); - - foreach (TileModel item in listBox1.ListBox.Items.OfType()) - { - if (item.IsGroup) - { - continue; - } - - model.Items.Add(item); - } - - this.TilePanelLayout.AddTile(model); - - break; - case DialogModeType.Edit: - model.Items = new System.Collections.Generic.List(); - - foreach (TileModel item in listBox1.ListBox.Items.OfType()) - { - if (item.IsGroup) - { - continue; - } - - model.Items.Add(item); - } - - this.TilePanel.LoadInfo(model); - - break; - default: break; - } - - this.Close(); } - private void listBox1_OnAdd(object sender, EventArgs e) => EditTileForm.ShowAddDialog(listBox1); - private void listBox1_OnEdit(object sender, EventArgs e) { if (listBox1.ListBox.Items.Count <= 0) @@ -311,7 +234,8 @@ namespace FizzyLauncher.Windows.Forms return; } - if (listBox1.ListBox.SelectedIndex < 0) + var n = listBox1.ListBox.SelectedIndex; + if (n < 0) { return; } @@ -321,7 +245,12 @@ namespace FizzyLauncher.Windows.Forms return; } - EditTileForm.ShowEditDialog(listBox1); + var form = new EditTileForm((TileModel)listBox1.ListBox.SelectedItem); + if (form.ShowDialog() == DialogResult.OK) + { + listBox1.ListBox.Items.RemoveAt(n); + listBox1.ListBox.Items.Insert(n, form.Result); + }; } private void listBox1_DragOver(object sender, System.Windows.Forms.DragEventArgs e) @@ -338,7 +267,7 @@ namespace FizzyLauncher.Windows.Forms private void listBox1_DragDrop(object sender, DragEventArgs e) { - string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; + var fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; if (fileList == null) { return; @@ -354,7 +283,7 @@ namespace FizzyLauncher.Windows.Forms return; } - TileModel model = new TileModel() + var model = new TileModel() { ProcessFilename = fileList[0], Title = Path.GetFileName(fileList[0]) diff --git a/Windows/Forms/EditTileFolderForm.resx b/Windows/Forms/EditTileFolderForm.resx index f298a7b..af32865 100644 --- a/Windows/Forms/EditTileFolderForm.resx +++ b/Windows/Forms/EditTileFolderForm.resx @@ -1,4 +1,64 @@ - + + + diff --git a/Windows/Forms/EditTileForm.cs b/Windows/Forms/EditTileForm.cs index 0ef5e5f..9991eb0 100644 --- a/Windows/Forms/EditTileForm.cs +++ b/Windows/Forms/EditTileForm.cs @@ -1,482 +1,364 @@ -using FizzyLauncher.Models; +using System.Drawing; +using System.Windows.Forms; +using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; using RyzStudio.Windows.ThemedForms; using RyzStudio.Windows.ThemedForms.ButtonTextBox; -using System; -using System.Drawing; namespace FizzyLauncher.Windows.Forms { - public class EditTileForm : TDialogForm + public class EditTileForm : TDialog { - public static void ShowAddDialog(TilePanelLayout control, Point coord) - { - EditTileForm form = new EditTileForm(DialogModeType.Add); - form.TilePanelLayout = control; - form.AimCoord = coord; - form.ShowDialog(); - } - - public static void ShowAddDialog(TListBox control) - { - EditTileForm form = new EditTileForm(DialogModeType.Add); - form.ListBox = control; - form.ShowDialog(); - } - - public static void ShowEditDialog(TilePanel control) - { - EditTileForm form = new EditTileForm(DialogModeType.Edit); - form.TilePanel = control; - form.ShowDialog(); - } - - public static void ShowEditDialog(TListBox control) - { - EditTileForm form = new EditTileForm(DialogModeType.Edit); - form.ListBox = control; - form.ShowDialog(); - } - - private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; - private TOpenFileTextBox textBox2; - private TTextBox textBox3; - private TFolderTextBox textBox4; - private TButton button1; - private TPickerBox pickerBox1; - private TPickerBox pickerBox2; + private ThPathDialogTextBox textBox2; + private ThTextBox textBox3; + private ThPathDialogTextBox textBox4; + private ThButton button1; + private ThPickerBox pickerBox1; + private ThPickerBox pickerBox2; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator1; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator2; - private TTextBox textBox1; + private ThTextBox textBox1; - public enum DialogModeType - { - Add = 0, - Edit - } - - - protected DialogModeType dialogMode = DialogModeType.Add; - - - public EditTileForm(DialogModeType dialogMode) : base() + public EditTileForm(TileModel model = null) { InitializeComponent(); - this.DialogMode = dialogMode; + this.StartPosition = FormStartPosition.WindowsDefaultLocation; + this.OkButton = button1; pickerBox1.ComboBox.Items.Clear(); pickerBox1.ComboBox.Items.AddRange(new string[] { "Normal", "Hidden", "Minimized", "Maximized" }); - if (pickerBox1.ComboBox.Items.Count > 0) pickerBox1.ComboBox.SelectedIndex = 0; + if (pickerBox1.ComboBox.Items.Count > 0) + { + pickerBox1.ComboBox.SelectedIndex = 0; + } pickerBox2.ComboBox.Items.Clear(); pickerBox2.ComboBox.Items.AddRange(new string[] { "No", "Yes" }); - if (pickerBox2.ComboBox.Items.Count > 0) pickerBox2.ComboBox.SelectedIndex = 0; + if (pickerBox2.ComboBox.Items.Count > 0) + { + pickerBox2.ComboBox.SelectedIndex = 0; + } + + if (model != null) + { + this.Text = "Edit Tile"; + + textBox1.Text = model?.Title ?? string.Empty; + textBox2.Text = model?.ProcessFilename ?? string.Empty; + textBox3.Text = model?.ProcessArgument ?? string.Empty; + textBox4.Text = model?.ProcessWorkingDirectory ?? string.Empty; + pickerBox1.ComboBox.SelectedIndex = (int)model.ProcessWindowStyle; + pickerBox2.ComboBox.SelectedIndex = (model.ProcessAsAdmin ? 1 : 0); + } + else + { + this.Text = "Add Tile"; + } } private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditTileForm)); - this.textBox1 = new TTextBox(); - this.label6 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - this.textBox2 = new TOpenFileTextBox(); - this.textBox3 = new TTextBox(); - this.textBox4 = new TFolderTextBox(); - this.button1 = new TButton(); - this.pickerBox1 = new TPickerBox(); - this.pickerBox2 = new TPickerBox(); - this.horizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); - this.horizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); - this.SuspendLayout(); + textBox1 = new ThTextBox(); + label6 = new Label(); + label7 = new Label(); + label4 = new Label(); + label3 = new Label(); + label2 = new Label(); + label1 = new Label(); + textBox2 = new ThPathDialogTextBox(); + textBox3 = new ThTextBox(); + textBox4 = new ThPathDialogTextBox(); + button1 = new ThButton(); + pickerBox1 = new ThPickerBox(); + pickerBox2 = new ThPickerBox(); + horizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + horizontalSeparator2 = new RyzStudio.Windows.Forms.THorizontalSeparator(); + SuspendLayout(); // // textBox1 // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.BackColor = System.Drawing.Color.Transparent; - this.textBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox1.Location = new System.Drawing.Point(192, 20); - this.textBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.textBox1.Name = "textBox1"; - this.textBox1.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox1.Size = new System.Drawing.Size(177, 35); - this.textBox1.AcceptButton = null; - this.textBox1.TabIndex = 152; - this.textBox1.UseSystemPasswordChar = false; + textBox1.AcceptButton = null; + textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBox1.BackColor = Color.Transparent; + textBox1.EnableReactiveVisual = true; + textBox1.Font = new Font("Segoe UI", 9F); + textBox1.Location = new Point(126, 20); + textBox1.Margin = new Padding(10, 10, 10, 0); + textBox1.Name = "textBox1"; + textBox1.Padding = new Padding(4, 4, 3, 3); + textBox1.ReadOnly = false; + textBox1.Size = new Size(243, 35); + textBox1.TabIndex = 152; + textBox1.TabStop = false; + textBox1.UseSystemPasswordChar = false; // // label6 // - this.label6.AutoSize = true; - this.label6.BackColor = System.Drawing.Color.Transparent; - this.label6.ForeColor = System.Drawing.SystemColors.ControlText; - this.label6.Location = new System.Drawing.Point(10, 250); - this.label6.Name = "label6"; - this.label6.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label6.Size = new System.Drawing.Size(83, 34); - this.label6.TabIndex = 163; - this.label6.Text = "Run As Admin"; - this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label6.AutoSize = true; + label6.BackColor = Color.Transparent; + label6.ForeColor = SystemColors.ControlText; + label6.Location = new Point(10, 250); + label6.Name = "label6"; + label6.Padding = new Padding(0, 9, 0, 10); + label6.Size = new Size(83, 34); + label6.TabIndex = 163; + label6.Text = "Run As Admin"; + label6.TextAlign = ContentAlignment.MiddleLeft; // // label7 // - this.label7.AutoSize = true; - this.label7.BackColor = System.Drawing.Color.Transparent; - this.label7.ForeColor = System.Drawing.SystemColors.ControlText; - this.label7.Location = new System.Drawing.Point(10, 209); - this.label7.Name = "label7"; - this.label7.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label7.Size = new System.Drawing.Size(79, 34); - this.label7.TabIndex = 161; - this.label7.Text = "Window Style"; - this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label7.AutoSize = true; + label7.BackColor = Color.Transparent; + label7.ForeColor = SystemColors.ControlText; + label7.Location = new Point(10, 209); + label7.Name = "label7"; + label7.Padding = new Padding(0, 9, 0, 10); + label7.Size = new Size(79, 34); + label7.TabIndex = 161; + label7.Text = "Window Style"; + label7.TextAlign = ContentAlignment.MiddleLeft; // // label4 // - this.label4.AutoSize = true; - this.label4.BackColor = System.Drawing.Color.Transparent; - this.label4.ForeColor = System.Drawing.SystemColors.ControlText; - this.label4.Location = new System.Drawing.Point(10, 144); - this.label4.Name = "label4"; - this.label4.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label4.Size = new System.Drawing.Size(103, 34); - this.label4.TabIndex = 159; - this.label4.Text = "Working Directory"; - this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label4.AutoSize = true; + label4.BackColor = Color.Transparent; + label4.ForeColor = SystemColors.ControlText; + label4.Location = new Point(10, 144); + label4.Name = "label4"; + label4.Padding = new Padding(0, 9, 0, 10); + label4.Size = new Size(103, 34); + label4.TabIndex = 159; + label4.Text = "Working Directory"; + label4.TextAlign = ContentAlignment.MiddleLeft; // // label3 // - this.label3.AutoSize = true; - this.label3.BackColor = System.Drawing.Color.Transparent; - this.label3.ForeColor = System.Drawing.SystemColors.ControlText; - this.label3.Location = new System.Drawing.Point(10, 103); - this.label3.Name = "label3"; - this.label3.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label3.Size = new System.Drawing.Size(61, 34); - this.label3.TabIndex = 157; - this.label3.Text = "Argument"; - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label3.AutoSize = true; + label3.BackColor = Color.Transparent; + label3.ForeColor = SystemColors.ControlText; + label3.Location = new Point(10, 103); + label3.Name = "label3"; + label3.Padding = new Padding(0, 9, 0, 10); + label3.Size = new Size(61, 34); + label3.TabIndex = 157; + label3.Text = "Argument"; + label3.TextAlign = ContentAlignment.MiddleLeft; // // label2 // - this.label2.AutoSize = true; - this.label2.BackColor = System.Drawing.Color.Transparent; - this.label2.ForeColor = System.Drawing.SystemColors.ControlText; - this.label2.Location = new System.Drawing.Point(10, 62); - this.label2.Name = "label2"; - this.label2.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label2.Size = new System.Drawing.Size(55, 34); - this.label2.TabIndex = 155; - this.label2.Text = "Filename"; - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label2.AutoSize = true; + label2.BackColor = Color.Transparent; + label2.ForeColor = SystemColors.ControlText; + label2.Location = new Point(10, 62); + label2.Name = "label2"; + label2.Padding = new Padding(0, 9, 0, 10); + label2.Size = new Size(55, 34); + label2.TabIndex = 155; + label2.Text = "Filename"; + label2.TextAlign = ContentAlignment.MiddleLeft; // // label1 // - this.label1.AutoSize = true; - this.label1.BackColor = System.Drawing.Color.Transparent; - this.label1.ForeColor = System.Drawing.SystemColors.ControlText; - this.label1.Location = new System.Drawing.Point(10, 21); - this.label1.Margin = new System.Windows.Forms.Padding(0); - this.label1.Name = "label1"; - this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10); - this.label1.Size = new System.Drawing.Size(29, 34); - this.label1.TabIndex = 153; - this.label1.Text = "Title"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + label1.AutoSize = true; + label1.BackColor = Color.Transparent; + label1.ForeColor = SystemColors.ControlText; + label1.Location = new Point(10, 21); + label1.Margin = new Padding(0); + label1.Name = "label1"; + label1.Padding = new Padding(0, 9, 0, 10); + label1.Size = new Size(29, 34); + label1.TabIndex = 153; + label1.Text = "Title"; + label1.TextAlign = ContentAlignment.MiddleLeft; // // textBox2 // - this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox2.BackColor = System.Drawing.Color.Transparent; - this.textBox2.FileDialog = null; - this.textBox2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox2.HighlightImage = ((System.Drawing.Image)(resources.GetObject("textBox2.HighlightImage"))); - this.textBox2.Location = new System.Drawing.Point(192, 61); - this.textBox2.Margin = new System.Windows.Forms.Padding(10, 3, 3, 3); - this.textBox2.Name = "textBox2"; - this.textBox2.NormalImage = ((System.Drawing.Image)(resources.GetObject("textBox2.NormalImage"))); - this.textBox2.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox2.Size = new System.Drawing.Size(177, 35); - this.textBox2.AcceptButton = null; - this.textBox2.TabIndex = 170; - this.textBox2.UseSystemPasswordChar = false; + textBox2.AcceptButton = null; + textBox2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBox2.BackColor = Color.Transparent; + textBox2.DialogMode = ThPathDialogTextBox.DialogType.OpenFile; + textBox2.EnableReactiveVisual = true; + textBox2.FolderBrowserDialog = null; + textBox2.Font = new Font("Segoe UI", 9F); + textBox2.HighlightImage = null; + textBox2.Location = new Point(126, 61); + textBox2.Margin = new Padding(10, 10, 10, 0); + textBox2.Name = "textBox2"; + textBox2.NormalImage = null; + textBox2.OpenFileDialog = null; + textBox2.Padding = new Padding(4, 4, 3, 3); + textBox2.SaveFileDialog = null; + textBox2.Size = new Size(243, 32); + textBox2.TabIndex = 170; + textBox2.TabStop = false; + textBox2.UseSystemPasswordChar = false; // // textBox3 // - this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox3.BackColor = System.Drawing.Color.Transparent; - this.textBox3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox3.Location = new System.Drawing.Point(192, 102); - this.textBox3.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.textBox3.Name = "textBox3"; - this.textBox3.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox3.Size = new System.Drawing.Size(177, 35); - this.textBox3.AcceptButton = null; - this.textBox3.TabIndex = 171; - this.textBox3.UseSystemPasswordChar = false; + textBox3.AcceptButton = null; + textBox3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBox3.BackColor = Color.Transparent; + textBox3.EnableReactiveVisual = true; + textBox3.Font = new Font("Segoe UI", 9F); + textBox3.Location = new Point(147, 102); + textBox3.Margin = new Padding(10, 10, 10, 0); + textBox3.Name = "textBox3"; + textBox3.Padding = new Padding(4, 4, 3, 3); + textBox3.ReadOnly = false; + textBox3.Size = new Size(222, 35); + textBox3.TabIndex = 171; + textBox3.TabStop = false; + textBox3.UseSystemPasswordChar = false; // // textBox4 // - this.textBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.textBox4.BackColor = System.Drawing.Color.Transparent; - this.textBox4.FolderDialog = null; - this.textBox4.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox4.HighlightImage = ((System.Drawing.Image)(resources.GetObject("textBox4.HighlightImage"))); - this.textBox4.Location = new System.Drawing.Point(192, 143); - this.textBox4.Margin = new System.Windows.Forms.Padding(10, 3, 3, 3); - this.textBox4.Name = "textBox4"; - this.textBox4.NormalImage = ((System.Drawing.Image)(resources.GetObject("textBox4.NormalImage"))); - this.textBox4.Padding = new System.Windows.Forms.Padding(10, 10, 9, 9); - this.textBox4.Size = new System.Drawing.Size(177, 35); - this.textBox4.AcceptButton = null; - this.textBox4.TabIndex = 172; - this.textBox4.UseSystemPasswordChar = false; + textBox4.AcceptButton = null; + textBox4.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBox4.BackColor = Color.Transparent; + textBox4.DialogMode = ThPathDialogTextBox.DialogType.FolderBrowser; + textBox4.EnableReactiveVisual = true; + textBox4.FolderBrowserDialog = null; + textBox4.Font = new Font("Segoe UI", 9F); + textBox4.HighlightImage = null; + textBox4.Location = new Point(147, 143); + textBox4.Margin = new Padding(10, 10, 10, 0); + textBox4.Name = "textBox4"; + textBox4.NormalImage = null; + textBox4.OpenFileDialog = null; + textBox4.Padding = new Padding(4, 4, 3, 3); + textBox4.SaveFileDialog = null; + textBox4.Size = new Size(222, 32); + textBox4.TabIndex = 172; + textBox4.TabStop = false; + textBox4.UseSystemPasswordChar = false; // // button1 // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button1.BackColor = System.Drawing.Color.Transparent; - this.button1.IdleImage = null; - this.button1.ActiveImage = null; - this.button1.LabelText = "&Save"; - this.button1.Location = new System.Drawing.Point(241, 469); - this.button1.Margin = new System.Windows.Forms.Padding(10); - this.button1.Name = "button1"; - this.button1.HoverImage = null; - this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3); - this.button1.Size = new System.Drawing.Size(128, 32); - this.button1.TabIndex = 173; - this.button1.Click += new System.EventHandler(this.button1_Click); + button1.AcceptButton = null; + button1.ActiveImage = null; + button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + button1.BackColor = Color.Transparent; + button1.EnableMenuOnClick = false; + button1.EnableReactiveVisual = true; + button1.HoverImage = null; + button1.IdleImage = null; + button1.LabelText = "&Save"; + button1.Location = new Point(241, 469); + button1.Margin = new Padding(10, 10, 10, 0); + button1.Name = "button1"; + button1.Padding = new Padding(4, 4, 3, 3); + button1.Size = new Size(128, 32); + button1.TabIndex = 173; + button1.TabStop = false; // // pickerBox1 // - this.pickerBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pickerBox1.BackColor = System.Drawing.Color.Transparent; - this.pickerBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.pickerBox1.Location = new System.Drawing.Point(241, 209); - this.pickerBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.pickerBox1.Name = "pickerBox1"; - this.pickerBox1.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); - this.pickerBox1.Size = new System.Drawing.Size(128, 34); - this.pickerBox1.AcceptButton = null; - this.pickerBox1.TabIndex = 174; + pickerBox1.AcceptButton = null; + pickerBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; + pickerBox1.BackColor = Color.Transparent; + pickerBox1.EnableReactiveVisual = true; + pickerBox1.Font = new Font("Segoe UI", 9F); + pickerBox1.Location = new Point(241, 209); + pickerBox1.Margin = new Padding(10, 10, 10, 0); + pickerBox1.Name = "pickerBox1"; + pickerBox1.Padding = new Padding(4, 4, 3, 3); + pickerBox1.SelectedIndex = -1; + pickerBox1.Size = new Size(128, 34); + pickerBox1.TabIndex = 174; + pickerBox1.TabStop = false; // // pickerBox2 // - this.pickerBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.pickerBox2.BackColor = System.Drawing.Color.Transparent; - this.pickerBox2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.pickerBox2.Location = new System.Drawing.Point(285, 250); - this.pickerBox2.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6); - this.pickerBox2.Name = "pickerBox2"; - this.pickerBox2.Padding = new System.Windows.Forms.Padding(10, 6, 7, 5); - this.pickerBox2.Size = new System.Drawing.Size(84, 34); - this.pickerBox2.AcceptButton = null; - this.pickerBox2.TabIndex = 175; + pickerBox2.AcceptButton = null; + pickerBox2.Anchor = AnchorStyles.Top | AnchorStyles.Right; + pickerBox2.BackColor = Color.Transparent; + pickerBox2.EnableReactiveVisual = true; + pickerBox2.Font = new Font("Segoe UI", 9F); + pickerBox2.Location = new Point(285, 250); + pickerBox2.Margin = new Padding(10, 10, 10, 0); + pickerBox2.Name = "pickerBox2"; + pickerBox2.Padding = new Padding(4, 4, 3, 3); + pickerBox2.SelectedIndex = -1; + pickerBox2.Size = new Size(84, 34); + pickerBox2.TabIndex = 175; + pickerBox2.TabStop = false; // // horizontalSeparator1 // - this.horizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.horizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.horizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.horizontalSeparator1.BackColor = System.Drawing.Color.Transparent; - this.horizontalSeparator1.Location = new System.Drawing.Point(10, 181); - this.horizontalSeparator1.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); - this.horizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2); - this.horizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22); - this.horizontalSeparator1.Name = "horizontalSeparator1"; - this.horizontalSeparator1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); - this.horizontalSeparator1.Size = new System.Drawing.Size(364, 22); - this.horizontalSeparator1.TabIndex = 176; + horizontalSeparator1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + horizontalSeparator1.AutoScrollMargin = new Size(0, 0); + horizontalSeparator1.AutoScrollMinSize = new Size(0, 0); + horizontalSeparator1.BackColor = Color.Transparent; + horizontalSeparator1.Location = new Point(10, 181); + horizontalSeparator1.Margin = new Padding(0, 10, 0, 0); + horizontalSeparator1.MaximumSize = new Size(4920, 2); + horizontalSeparator1.MinimumSize = new Size(0, 22); + horizontalSeparator1.Name = "horizontalSeparator1"; + horizontalSeparator1.Size = new Size(364, 22); + horizontalSeparator1.TabIndex = 176; + horizontalSeparator1.TabStop = false; // // horizontalSeparator2 // - this.horizontalSeparator2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.horizontalSeparator2.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.horizontalSeparator2.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.horizontalSeparator2.BackColor = System.Drawing.Color.Transparent; - this.horizontalSeparator2.Location = new System.Drawing.Point(10, 437); - this.horizontalSeparator2.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0); - this.horizontalSeparator2.MaximumSize = new System.Drawing.Size(4920, 2); - this.horizontalSeparator2.MinimumSize = new System.Drawing.Size(0, 22); - this.horizontalSeparator2.Name = "horizontalSeparator2"; - this.horizontalSeparator2.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10); - this.horizontalSeparator2.Size = new System.Drawing.Size(364, 22); - this.horizontalSeparator2.TabIndex = 177; + horizontalSeparator2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + horizontalSeparator2.AutoScrollMargin = new Size(0, 0); + horizontalSeparator2.AutoScrollMinSize = new Size(0, 0); + horizontalSeparator2.BackColor = Color.Transparent; + horizontalSeparator2.Location = new Point(10, 437); + horizontalSeparator2.Margin = new Padding(0, 10, 0, 0); + horizontalSeparator2.MaximumSize = new Size(4920, 2); + horizontalSeparator2.MinimumSize = new Size(0, 22); + horizontalSeparator2.Name = "horizontalSeparator2"; + horizontalSeparator2.Size = new Size(364, 22); + horizontalSeparator2.TabIndex = 177; + horizontalSeparator2.TabStop = false; // // EditTileForm // - this.ClientSize = new System.Drawing.Size(384, 521); - this.Controls.Add(this.horizontalSeparator2); - this.Controls.Add(this.horizontalSeparator1); - this.Controls.Add(this.pickerBox2); - this.Controls.Add(this.pickerBox1); - this.Controls.Add(this.button1); - this.Controls.Add(this.textBox4); - this.Controls.Add(this.textBox3); - this.Controls.Add(this.textBox2); - this.Controls.Add(this.label6); - this.Controls.Add(this.label7); - this.Controls.Add(this.label4); - this.Controls.Add(this.label3); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Controls.Add(this.textBox1); - this.MinimumSize = new System.Drawing.Size(400, 560); - this.Name = "EditTileForm"; - this.Text = "Add Tile"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - protected override void OnShown(EventArgs e) - { - base.OnShown(e); - - if (this.DialogMode == DialogModeType.Edit) - { - if (this.TilePanel != null) - { - updateModel(this.TilePanel.ModelInfo); - } - else if (this.ListBox != null) - { - if (this.ListBox.ListBox.SelectedItem != null) - { - TileModel model = (this.ListBox.ListBox.SelectedItem as TileModel); - if (model != null) - { - updateModel(model); - } - } - } - } + ClientSize = new Size(384, 521); + Controls.Add(horizontalSeparator2); + Controls.Add(horizontalSeparator1); + Controls.Add(pickerBox2); + Controls.Add(pickerBox1); + Controls.Add(button1); + Controls.Add(textBox4); + Controls.Add(textBox3); + Controls.Add(textBox2); + Controls.Add(label6); + Controls.Add(label7); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(textBox1); + MinimumSize = new Size(400, 560); + Name = "EditTileForm"; + Text = "Add Tile"; + ResumeLayout(false); + PerformLayout(); } - public TilePanelLayout TilePanelLayout { get; set; } = null; - - public TilePanel TilePanel { get; set; } = null; - - public TListBox ListBox { get; set; } = null; - - public Point AimCoord { get; set; } = new Point(-1, -1); - - public DialogModeType DialogMode + public TileModel Result { - get => dialogMode; - set + get => new TileModel() { - dialogMode = value; - - switch (dialogMode) - { - case DialogModeType.Add: - this.Text = "Add Tile"; - break; - case DialogModeType.Edit: - this.Text = "Edit Tile"; - break; - default: break; - } - } - } - - - private void button1_Click(object sender, EventArgs e) - { - TileModel model = buildModel(); - - switch (this.DialogMode) - { - case DialogModeType.Add: - if (this.TilePanelLayout != null) - { - this.TilePanelLayout.AddTile(model); - } - else if (this.ListBox != null) - { - int n = this.ListBox.ListBox.Items.Add(model); - this.ListBox.ListBox.SelectedIndex = n; - } - - break; - case DialogModeType.Edit: - if (this.TilePanel != null) - { - this.TilePanel.LoadInfo(model); - } - else if (this.ListBox != null) - { - int n = this.ListBox.ListBox.SelectedIndex; - if (n >= 0) - { - this.ListBox.ListBox.Items.RemoveAt(n); - this.ListBox.ListBox.Items.Insert(n, model); - this.ListBox.ListBox.SelectedIndex = n; - } - } - - break; - default: break; - } - - this.Close(); - } - - protected TileModel buildModel() - { - TileModel rs = new TileModel() - { - Title = textBox1.Text?.Trim(), - ProcessFilename = textBox2.Text?.Trim(), - ProcessArgument = textBox3.Text?.Trim(), + Title = textBox1.Text?.Trim() ?? string.Empty, + ProcessFilename = textBox2.Text?.Trim() ?? string.Empty, + ProcessArgument = textBox3.Text?.Trim() ?? string.Empty, ProcessWorkingDirectory = textBox4.Text?.Trim(), ProcessWindowStyle = (System.Diagnostics.ProcessWindowStyle)pickerBox1.ComboBox.SelectedIndex, ProcessAsAdmin = (pickerBox2.ComboBox.SelectedIndex == 1) }; - - if (this.DialogMode == DialogModeType.Add) - { - if (!this.AimCoord.Equals(new Point(-1, -1))) - { - rs.Position = this.AimCoord; - } - } - - return rs; - } - - protected void updateModel(TileModel model) - { - if (model == null) - { - return; - } - - textBox1.Text = model.Title; - textBox2.Text = model.ProcessFilename; - textBox3.Text = model.ProcessArgument; - textBox4.Text = model.ProcessWorkingDirectory; - pickerBox1.ComboBox.SelectedIndex = (int)model.ProcessWindowStyle; - pickerBox2.ComboBox.SelectedIndex = (model.ProcessAsAdmin ? 1 : 0); } } -} +} \ No newline at end of file diff --git a/Windows/Forms/EditTileForm.resx b/Windows/Forms/EditTileForm.resx index 0220ec4..af32865 100644 --- a/Windows/Forms/EditTileForm.resx +++ b/Windows/Forms/EditTileForm.resx @@ -1,4 +1,64 @@ - + + + @@ -57,41 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAAK9JREFUOE/t0zsKwkAURuGp1BWJK3EhIrgAV+EOLLWwtRQLwQdiIbbiIkwynj+O - IVwnyhR2XvjyInNIkXHee8f0cEQBPbDOaKEarSvXhsAJO4wirlB4jipiA3phoIvIrLFChhnKiA3o8Ckw - RR93LNBODVwwwRL62kNKYIxNzQ1FSsDOEHk08HrYJMw/8KtA06/cCef6KJDZgDbTFrHNZO3x9idqOyui - m2+07bvPgHcPXOhtG3D6cUIAAAAASUVORK5CYII= - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAAMZJREFUOE/tk7sNwjAQQF3BRohJGAQhMQBTsAElFLSUiAKJTxIXhBZlCILNuyRG - iXEQKeg46fmsO/slhU9Za5XWehiXYcD6JElygZ6qhdwTioVDGo4wDXDjsohXdYkvMDTHVa8R9Hb0tpCz - XzqJL5Df/CRYRFE0Yn8nr9M07XcSwBXmXN6QDfncRTCjt6+Rgfla4Adfn3D+ERS4Yht/wY8FxVN2xTac - gLP5qyYLAhmmA4SGyeeEoPkSq3EWydsoB4gRDEqBVU/p15ajstHKCgAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wAAADsABataJCQAAAJtJREFUOE/t0zEKwkAQheEpvILHSLySlTeJ6AnEzpPYi0ERPIKWKtZKNv9LNS5x - E6xS+OCDJew8tsgYmeCECsGZo1dKXLBwtnghQ2fe0JDPGHecsW6xwgwjNM8tdIgyxQ0qij2gORV9LejK - Bk8dfi3QjGY/C0IISS7/gkEVtP3KfbKEZm0PLZM++IVK0d0rdrAcR8TrnKK7BzPLa7Wb+WX/Nb8PAAAA - AElFTkSuQmCC - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wAAADsABataJCQAAALZJREFUOE/tkzEKwjAYRjt4BY9hvZKTN1HsCYqbJzGzKBGb9gY6qjgrxvdJK7ZS - Gpwc/ODBnzTvg0AT5Xk+hB3cwVc456ZRSIqi2MAeafbGEq5Zlg3KY+1Bvkkql89Ya/vsnUCZN8FJYWyM - 6ekKnsWkdF9hb8S3I6ioyRnkpa0FXcFbwOXrAjlyawXe+06q/At+qoDh41cOCU4iV8OaQY8pUVEgOnuA - VcSzjRm2UHvOHeisdc7FDwDnJKIbLgP9AAAAAElFTkSuQmCC - - \ No newline at end of file diff --git a/Windows/Forms/TileContainer.cs b/Windows/Forms/TileContainer.cs index a692bb0..d402138 100644 --- a/Windows/Forms/TileContainer.cs +++ b/Windows/Forms/TileContainer.cs @@ -1,10 +1,10 @@ -using FizzyLauncher.Models; -using RyzStudio.Windows.Forms; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; +using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; namespace FizzyLauncher.Windows.Forms { diff --git a/Windows/Forms/TilePanel.Designer.cs b/Windows/Forms/TilePanel.Designer.cs index b771cd9..509bc8f 100644 --- a/Windows/Forms/TilePanel.Designer.cs +++ b/Windows/Forms/TilePanel.Designer.cs @@ -61,16 +61,9 @@ // TilePanel // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234))))); - this.Margin = new System.Windows.Forms.Padding(4, 3, 0, 0); - this.MaximumSize = new System.Drawing.Size(82, 81); - this.MinimumSize = new System.Drawing.Size(82, 81); this.Name = "TilePanel"; - this.Size = new System.Drawing.Size(82, 81); this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); - } #endregion diff --git a/Windows/Forms/TilePanel.cs b/Windows/Forms/TilePanel.cs index 57a65cb..1d2cfb4 100644 --- a/Windows/Forms/TilePanel.cs +++ b/Windows/Forms/TilePanel.cs @@ -4,130 +4,43 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Windows.Forms; +using System.Xml.Linq; using FizzyLauncher.Models; +using RyzStudio.Windows.Forms; namespace FizzyLauncher.Windows.Forms { - public partial class TilePanel : RyzStudio.Windows.Forms.TC1UserControl + public partial class TilePanel : RyzStudio.Windows.TileForms.Tile { - protected bool isDragging = false; - protected Point startPosition = new Point(); - - protected int imageLeft = 0; - protected int imageTop = 11; - protected int labelMargin = 3; - protected int labelTop = 47; - protected Rectangle labelRectangle = new Rectangle(); - - protected string title = ""; - protected Image icon = null; - protected ContextMenuStrip groupContextMenu = null; protected TileModel modelInfo = new TileModel(); - public TilePanel() : base() + public TilePanel() { InitializeComponent(); this.AllowDrop = true; - this.AutoSize = false; - this.BackColor = Color.FromArgb(250, 250, 250); this.ContextMenuStrip = contextMenuStrip1; - this.DoubleBuffered = true; - this.Font = new Font(this.Font.FontFamily, 8.25F); - this.ForeColor = Color.FromArgb(99, 105, 119); - this.Size = new Size(70, 70); - this.MaximumSize = this.MinimumSize = this.Size; - } - - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - - this.AllowDrop = true; - this.AutoSize = false; - this.BackColor = Color.FromArgb(250, 250, 250); - this.ContextMenuStrip = contextMenuStrip1; - this.DoubleBuffered = true; this.Font = new Font(this.Font.FontFamily, 8.25F); this.Size = new Size(70, 70); - this.MaximumSize = this.MinimumSize = this.Size; - } - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - - Graphics g = e.Graphics; - - - if (this.Image != null) - { - g.DrawImage(this.Image, new Point(imageLeft, imageTop)); - } - - if (!string.IsNullOrWhiteSpace(this.Title)) - { - TextRenderer.DrawText(e.Graphics, this.Title, this.Font, labelRectangle, this.ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPadding | TextFormatFlags.EndEllipsis); - } - - g.DrawRectangle(new Pen(Color.FromArgb(204, 206, 218), 1), new Rectangle(this.DisplayRectangle.X, this.DisplayRectangle.Y, (this.DisplayRectangle.Width - 1), (this.DisplayRectangle.Height - 1))); - - } - - [Category("Tile"), Browsable(true)] - public Image Image - { - get => icon; - protected set - { - icon = value; - - if (icon == null) - { - imageLeft = 0; - } - else - { - imageLeft = (this.Width - icon.Width) / 2; - } - } - } - - [Category("Tile"), Browsable(true)] - public string Title - { - get => title; - protected set - { - title = value; - - labelRectangle = new Rectangle(labelMargin, labelTop, (this.Width - (labelMargin * 2)), (this.Height - labelTop - 1)); - - this.Invalidate(); - } + this.EnableMovable = true; } [Browsable(false)] public TileModel ModelInfo => modelInfo; - public TilePanelLayout PanelContainer + public RyzStudio.Windows.TileForms.TileContainer TileContainer { get => UIControl.GetParentsUntil(this); } + + protected MainForm MainForm { get => UIControl.GetParentsUntil(this); } + + + protected override void OnDragOver(DragEventArgs e) { - get - { - if (this.Parent == null) - { - return null; - } + base.OnDragDrop(e); - if (this.Parent.GetType() != typeof(TilePanelLayout)) - { - return null; - } - - return (TilePanelLayout)this.Parent; - } + e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? DragDropEffects.Link : DragDropEffects.None; } protected override void OnDragDrop(DragEventArgs e) @@ -138,67 +51,34 @@ namespace FizzyLauncher.Windows.Forms { this.DropFileList(fileList); - invalidateGroupMenu(this.ModelInfo); + InvalidateGroupMenu(this.ModelInfo); } else { - if (this.PanelContainer != null) - { - this.PanelContainer.DropFileList(fileList); - } - } - } - - protected override void OnDragOver(DragEventArgs e) - { - base.OnDragDrop(e); - - e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? DragDropEffects.Link : DragDropEffects.None; - } - - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - - isDragging = false; - } - - protected override void OnMouseDown(MouseEventArgs e) - { - base.OnMouseDown(e); - - TilePanelLayout container = this.PanelContainer; - if (container == null) - { - return; - } - - this.BringToFront(); - - if (((e.Button == MouseButtons.Left) && (Control.ModifierKeys == Keys.Control)) || (e.Button == MouseButtons.Right)) - { - isDragging = true; - startPosition = e.Location; + //if (this.PanelContainer != null) + //{ + // this.PanelContainer.LoadShortcuts(fileList); + //} } } protected override void OnMouseClick(MouseEventArgs e) { - base.OnMouseClick(e); + if (Control.ModifierKeys == Keys.Control) + { + return; + } - if (Control.ModifierKeys == Keys.Control) return; - if (this.ModelInfo == null) return; + if (this.ModelInfo == null) + { + return; + } if (e.Button == MouseButtons.Left) { if (this.ModelInfo.IsGroup) { - if (groupContextMenu != null) - { - invalidateGroupMenuSize(); - - groupContextMenu.Show(this, e.Location); - } + this.LeftContextMenuStrip?.Show(this, e.Location); } else { @@ -211,33 +91,57 @@ namespace FizzyLauncher.Windows.Forms { base.OnMouseDoubleClick(e); - if (Control.ModifierKeys == Keys.Control) return; + if (Control.ModifierKeys == Keys.Control) + { + return; + } if (e.Button == MouseButtons.Left) { - execute(this.ModelInfo); + Execute(this.ModelInfo); } } - protected override void OnMouseMove(MouseEventArgs e) + +#region Context Menu + + /// + /// Edit + /// + /// + /// + private void editToolStripMenuItem_Click(object sender, EventArgs e) { - base.OnMouseMove(e); - - if (isDragging) + if (this.ModelInfo.IsGroup) { - TilePanelLayout layoutPanel = this.PanelContainer; - if (layoutPanel == null) + var form = new EditTileFolderForm(this.ModelInfo); + if (form.ShowDialog() == DialogResult.OK) { - return; - } - - int x = (this.Location.X + (e.Location.X - startPosition.X)); - int y = (this.Location.Y + (e.Location.Y - startPosition.Y)); - - layoutPanel.MoveTile(this, x, y); + this.LoadInfo(form.Result); + }; + } + else + { + var form = new EditTileForm(this.ModelInfo); + if (form.ShowDialog() == DialogResult.OK) + { + this.LoadInfo(form.Result); + }; } } + /// + /// Remove + /// + /// + /// + private void removeToolStripMenuItem_Click(object sender, EventArgs e) + { + this.TileContainer?.Controls?.Remove(this); + } + +#endregion + public void DropFileList(string[] fileList) { @@ -294,46 +198,24 @@ namespace FizzyLauncher.Windows.Forms { this.modelInfo = model; - this.Image = null; + this.LargeIcon = null; this.Title = model.Title; if (this.modelInfo.IsGroup) { - this.Image = AppResource.folder_32; + this.LargeIcon = AppResource.folder_32; - invalidateGroupMenu(this.modelInfo); + InvalidateGroupMenu(this.modelInfo); } else { - this.Image = getIcon(model); + this.LargeIcon = RyzStudio.IO.File.GetIcon(model.CleanProcessFilename); } toolTip1.SetToolTip(this, this.Title); } - private void editToolStripMenuItem_Click(object sender, EventArgs e) - { - if (this.ModelInfo.IsGroup) - { - EditTileFolderForm.ShowEditDialog(this); - } - else - { - EditTileForm.ShowEditDialog(this); - } - } - - private void removeToolStripMenuItem_Click(object sender, EventArgs e) - { - if (this.PanelContainer == null) - { - return; - } - - this.PanelContainer.Remove(this); - } - - protected void execute(TileModel model) + protected void Execute(TileModel model) { if (model == null) { @@ -345,159 +227,42 @@ namespace FizzyLauncher.Windows.Forms return; } - if (string.IsNullOrWhiteSpace(model.CleanProcessFilename)) + if (this.MainForm != null) { - return; - } - - if (!File.Exists(model.CleanProcessFilename)) - { - return; - } - - ProcessStartInfo p = new ProcessStartInfo(); - p.FileName = model.CleanProcessFilename; - p.WindowStyle = model.ProcessWindowStyle; - p.UseShellExecute = true; - - if (!string.IsNullOrWhiteSpace(model.CleanProcessArgument)) - { - p.Arguments = model.CleanProcessArgument; - } - - if (!string.IsNullOrWhiteSpace(model.CleanProcessWorkingDirectory)) - { - p.WorkingDirectory = model.CleanProcessWorkingDirectory; - } - - if (model.ProcessAsAdmin) - { - p.Verb = "runas"; - } - - MainForm parentForm = findMainForm(); - if (parentForm != null) - { - if (parentForm.CurrentSession != null) + if (this.MainForm.CurrentSession?.HideOnExecute ?? true) { - if (parentForm.CurrentSession.HideOnClick) - { - parentForm.Visible = false; - } + this.MainForm.Visible = false; } } - try - { - Process.Start(p); - } - catch (Exception exc) - { - MessageBox.Show(exc.Message); - } + RyzStudio.Diagnostics.Process.Execute(model.CleanProcessFilename, model.CleanProcessWorkingDirectory, model.CleanProcessArgument, model.ProcessWindowStyle, model.ProcessAsAdmin); } - protected Image getIcon(TileModel model) + protected void InvalidateGroupMenu(TileModel model) { - if (!File.Exists(model.CleanProcessFilename)) + //var iconSize = ((this.PanelContainer?.MainForm?.CurrentSession?.EnableBigIconInFolder ?? true) ? 24 : 16); + var iconSize = 24; + + if (this.LeftContextMenuStrip == null) { - return null; + this.LeftContextMenuStrip = new ContextMenuStrip(); } - try - { - return Icon.ExtractAssociatedIcon(model.CleanProcessFilename)?.ToBitmap(); - } - catch - { - // do nothing - } + this.LeftContextMenuStrip.ImageScalingSize = new Size(iconSize, iconSize); + this.LeftContextMenuStrip.Items.Clear(); - return null; - } - - protected void invalidateGroupMenu(TileModel model) - { - if (groupContextMenu == null) + foreach (TileModel item in model?.Items ?? new System.Collections.Generic.List()) { - groupContextMenu = new ContextMenuStrip(); - } - - groupContextMenu.Items.Clear(); - - if (model.Items == null) - { - return; - } - - foreach (TileModel item in model.Items) - { - ToolStripItem toolItem = groupContextMenu.Items.Add(item.Title); - toolItem.Image = getIcon(item); + ToolStripItem toolItem = this.LeftContextMenuStrip.Items.Add(item.Title); + toolItem.Image = RyzStudio.IO.File.GetIcon(item.CleanProcessFilename); toolItem.Tag = item; - toolItem.Click += toolItem_Click; - } - } - - protected void invalidateGroupMenuSize() - { - if (this.PanelContainer != null) - { - if (this.PanelContainer.MainForm != null) + toolItem.Click += (object sender, EventArgs e) => { - if (this.PanelContainer.MainForm.CurrentSession != null) - { - if (this.PanelContainer.MainForm.CurrentSession.EnableBigIconInFolder) - { - groupContextMenu.ImageScalingSize = new Size(24, 24); - return; - } - } - } + var result = UIControl.GetTag((Control)sender); + + Execute(result); + }; } - - groupContextMenu.ImageScalingSize = new Size(16, 16); - } - - protected MainForm findMainForm() - { - Control item = this; - - while (true) - { - item = item.Parent; - if (item == null) - { - return null; - } - - if (item.GetType() == typeof(MainForm)) - { - return (item as MainForm); - } - } - } - - private void toolItem_Click(object sender, EventArgs e) - { - if (sender.GetType() != typeof(ToolStripMenuItem)) - { - return; - } - - ToolStripMenuItem item = (sender as ToolStripMenuItem); - if (item.Tag == null) - { - return; - } - - if (item.Tag.GetType() != typeof(TileModel)) - { - return; - } - - TileModel model = (item.Tag as TileModel); - execute(model); } } diff --git a/Windows/Forms/TilePanelLayout.Designer.cs b/Windows/Forms/TilePanelLayout.Designer.cs index 41d2ee5..31d2727 100644 --- a/Windows/Forms/TilePanelLayout.Designer.cs +++ b/Windows/Forms/TilePanelLayout.Designer.cs @@ -45,7 +45,6 @@ this.bottomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); - this.label1 = new System.Windows.Forms.Label(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem7 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem(); @@ -174,21 +173,6 @@ this.toolStripMenuItem3.Text = "&Remove"; this.toolStripMenuItem3.Click += new System.EventHandler(this.removeGroupMenuItem3_Click); // - // label1 - // - this.label1.AutoSize = true; - this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(99)))), ((int)(((byte)(105)))), ((int)(((byte)(119))))); - this.label1.Image = global::FizzyLauncher.AppResource.toggle_left_ea_16; - this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.label1.Location = new System.Drawing.Point(265, 83); - this.label1.Margin = new System.Windows.Forms.Padding(0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(0, 15); - this.label1.TabIndex = 2; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.label1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.label1_MouseClick); - this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.label1_MouseClick); - // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; @@ -222,7 +206,6 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Transparent; - this.Controls.Add(this.label1); this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "TilePanelLayout"; this.Size = new System.Drawing.Size(432, 173); @@ -248,7 +231,6 @@ private System.Windows.Forms.ToolStripMenuItem bottomToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; - private System.Windows.Forms.Label label1; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem6; private System.Windows.Forms.ToolStripMenuItem removeRowToolStripMenuItem1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; diff --git a/Windows/Forms/TilePanelLayout.cs b/Windows/Forms/TilePanelLayout.cs index a2b8c9a..cb826c7 100644 --- a/Windows/Forms/TilePanelLayout.cs +++ b/Windows/Forms/TilePanelLayout.cs @@ -4,125 +4,35 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; -using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using FizzyLauncher.Models; using RyzStudio.Windows.Forms; namespace FizzyLauncher.Windows.Forms { - public partial class TilePanelLayout : RyzStudio.Windows.Forms.TC1UserControl + public partial class TilePanelLayout : TileGridPanelLayout { - public static int CalcWidth(int tileCount) => (tileCount * tileSize) + ((tileCount - 1) * margin); - - - public class Item - { - public TilePanel Tile { get; set; } - public Point Coord { get; set; } = new Point(0, 0); - } - - - protected const int tileSize = 70; - protected const int margin = 3; - protected const int labelHeight = 20; - protected const int collapseIncrement = 6; - protected const int expandIncrement = 8; - protected TileGroupModel groupModel = null; - protected List items = new List(); - - protected int collapseHeight = 0; - protected int expandedHeight = 0; - - protected bool isAnimating = false; - protected bool isChecked = true; - protected Point lastMousePosition = new Point(); - protected Point gridSize = new Point(); public TilePanelLayout(TileGroupModel model) : base() { InitializeComponent(); - this.AllowDrop = true; - this.BackColor = Color.Transparent; + this.TitleContextMenuStrip = contextMenuStrip2; + this.ContainerContextMenuStrip = contextMenuStrip1; this.LoadModel(model); - - label1.Location = new Point(0, 4); - label1.Margin = new Padding(0); - label1.Padding = new Padding(0); } protected override void OnDragDrop(DragEventArgs e) { string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[]; - this.DropFileList(fileList); + this.LoadShortcuts(fileList); } - protected override void OnDragOver(DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) - { - e.Effect = DragDropEffects.Link; - } - else - { - e.Effect = DragDropEffects.None; - } - } - - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - - this.Margin = new Padding(0); - this.Padding = new Padding(0, 0, 0, 10); - } - - protected override async void OnResize(EventArgs e) - { - base.OnResize(e); - - await this.InvalidateContainer(); - } - - protected override void OnMouseClick(MouseEventArgs e) - { - base.OnMouseClick(e); - - lastMousePosition = e.Location; - - bool isLabel = ((e.Location.X >= 0) && (e.Location.X <= this.Width) && (e.Location.Y >= 0) && (e.Location.Y <= 20)); - - if (e.Button == MouseButtons.Left) - { - // do nothing - } - else if (e.Button == MouseButtons.Right) - { - if (isLabel) - { - contextMenuStrip2.Show(this, e.Location); - } - else - { - contextMenuStrip1.Show(this, e.Location); - } - } - } - - protected override void OnMouseDoubleClick(MouseEventArgs e) => base.OnMouseClick(e); - - public Point GridSize - { - get => gridSize; - } - - public bool EnableAnimation + public new bool EnableAnimation { get { @@ -137,15 +47,14 @@ namespace FizzyLauncher.Windows.Forms return false; } - return mainForm.CurrentSession.EnableAnimation; + base.EnableAnimation = mainForm.CurrentSession.EnableAnimation; + + return base.EnableAnimation; } + set => base.EnableAnimation = value; } - public int CollapseHeight => labelHeight + collapseHeight; - - public int ExpandedHeight => expandedHeight + this.Padding.Bottom; - - public void DropFileList(string[] fileList) + public void LoadShortcuts(string[] fileList) { if (fileList == null) { @@ -204,7 +113,7 @@ namespace FizzyLauncher.Windows.Forms { Title = groupModel.Title, GridSize = new Size(this.GridSize.X, this.GridSize.Y), - IsExpanded = isChecked, + IsExpanded = this.IsExpanded, IsExclusive = groupModel.IsExclusive, Items = this.Tiles }; @@ -213,82 +122,39 @@ namespace FizzyLauncher.Windows.Forms } } - public FlowLayoutPanel FlowLayoutPanel - { - get - { - Control parentControl = this.Parent; - while (true) - { - if (parentControl == null) - { - return null; - } - if (parentControl.GetType() == typeof(FlowLayoutPanel)) - { - return parentControl as FlowLayoutPanel; - } - - parentControl = parentControl.Parent; - } - } - } - - public MainForm MainForm - { - get - { - Control parentControl = this.FlowLayoutPanel; - while (true) - { - if (parentControl == null) - { - return null; - } - - if (parentControl.GetType() == typeof(MainForm)) - { - return parentControl as MainForm; - } - - parentControl = parentControl.Parent; - } - } - } + public MainForm MainForm { get => UIControl.GetParentsUntil(this.Parent); } public List Tiles { get { - List rs = new List(); - foreach (Item item in items) + List result = new List(); + foreach (GridTileItem item in this.GridTileItems.Where(x => x.Tile.GetType() == typeof(TilePanel))) { - TileModel model = item.Tile.ModelInfo; + TileModel model = (item.Tile as TilePanel).ModelInfo; model.Position = item.Coord; - rs.Add(model); + result.Add(model); } - return rs; + return result; } } - public int TileSize => (tileSize + margin); - public void AddTile(TileModel tile) { Point gridSize = this.GridSize; - if (items.Count >= (gridSize.X * gridSize.Y)) + if (GridTileItems.Count >= (gridSize.X * gridSize.Y)) { this.SetGridSize(gridSize.X, (gridSize.Y + 1)); } Point? newCoord = tile.Position; - if ((newCoord == null) || hasTile(tile.Position)) + if ((newCoord == null) || HasTile(tile.Position)) { - newCoord = findLastFreeCoord(); + newCoord = FindLastFreeCoord(); } if (newCoord == null) @@ -300,9 +166,9 @@ namespace FizzyLauncher.Windows.Forms TilePanel panel = new TilePanel(); panel.LoadInfo(tile); - panel.Location = convertCoordToLocation(tile.Position); + panel.Location = ConvertCoordToLocation(tile.Position); - items.Add(new Item() + GridTileItems.Add(new GridTileItem() { Tile = panel, Coord = tile.Position @@ -311,92 +177,6 @@ namespace FizzyLauncher.Windows.Forms this.Controls.Add(panel); } - public void Clear() - { - this.Controls.Clear(); - } - - public async Task Collapse() - { - await Task.Run(() => - { - if (isAnimating) return; - - isAnimating = true; - isChecked = false; - - if (this.EnableAnimation) - { - while (this.Height > this.CollapseHeight) - { - UIControl.SetHeight(this, (this.Height - collapseIncrement)); - - Thread.Sleep(10); - } - } - - UIControl.SetHeight(this, this.CollapseHeight); - - isAnimating = false; - - this.Invalidate(this.DisplayRectangle, false); - }); - } - - public async Task Expand() - { - await Task.Run(() => - { - if (isAnimating) return; - - isAnimating = true; - isChecked = true; - - if (this.EnableAnimation) - { - while (this.Height < this.ExpandedHeight) - { - UIControl.SetHeight(this, (this.Height + expandIncrement)); - Thread.Sleep(10); - } - } - - UIControl.SetHeight(this, this.ExpandedHeight); - - isAnimating = false; - - this.Invalidate(this.DisplayRectangle, false); - }); - } - - public Point GetTilePosition(int posX, int posY) - { - int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); - int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize)); - - if (x < 0) x = 0; - if (y < 0) y = 0; - - return new Point((x * this.TileSize), ((y * this.TileSize) + labelHeight)); - } - - public async Task InvalidateContainer() - { - if (isAnimating) - { - return; - } - - if (isChecked) - { - await this.Expand(); - } - else - { - await this.Collapse(); - } - } - public void AddGroup() { if (this.FlowLayoutPanel == null) @@ -411,34 +191,37 @@ namespace FizzyLauncher.Windows.Forms })); } - public void AddRow() => this.SetGridSize(gridSize.X, (gridSize.Y + 1)); + public void AddRow() => this.SetGridSize(this.GridSize.X, (this.GridSize.Y + 1)); - public void EditGroup() => EditGroupForm.ShowDialog(this); + public void EditGroup() + { + //EditGroupForm.ShowDialog(this); + } - public void LoadModel(TileGroupModel model) + public async void LoadModel(TileGroupModel model) { groupModel = model; - isChecked = groupModel.IsExpanded; + this.Title = groupModel?.Title ?? string.Empty; + this.IsExpanded = groupModel.IsExpanded; - label1.Text = " " + groupModel?.Title; - label1.Image = (isChecked ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); + //label1.Image = (isExpanded ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); this.SetGridSize(groupModel.GridSize.Width, groupModel.GridSize.Height); this.LoadTiles(model.Items); this.SetGridSize(groupModel.GridSize.Width, groupModel.GridSize.Height); - this.Invalidate(); + await this.Invalidate(); } - public void UpdateModel(TileGroupModel model) + public async void UpdateModel(TileGroupModel model) { groupModel = model; - isChecked = groupModel.IsExpanded; - label1.Text = " " + groupModel?.Title; + this.Title = groupModel?.Title ?? string.Empty; + this.IsExpanded = groupModel.IsExpanded; - this.Invalidate(); + await this.Invalidate(); } public void LoadTiles(List tiles) @@ -456,7 +239,7 @@ namespace FizzyLauncher.Windows.Forms foreach (TileModel item in tiles) { // resolve final grid position - Point? confirmedPosition = resolveCoord(item.Position); + Point? confirmedPosition = ResolveCoord(item.Position); if (confirmedPosition == null) { continue; @@ -465,9 +248,9 @@ namespace FizzyLauncher.Windows.Forms // place control TilePanel panel = new TilePanel(); panel.LoadInfo(item); - panel.Location = convertCoordToLocation(confirmedPosition.Value); + panel.Location = ConvertCoordToLocation(confirmedPosition.Value); - items.Add(new Item() + GridTileItems.Add(new GridTileItem() { Tile = panel, Coord = confirmedPosition.Value @@ -477,308 +260,26 @@ namespace FizzyLauncher.Windows.Forms } } - public void MoveTile(TilePanel panel, int posX, int posY) + private void SetGridSize(int width, int height) { - Item item = items.Where(x => x.Tile.Equals(panel)).FirstOrDefault(); - if (item == null) - { - return; - } - - Point newPosition = convertLocationToCoord_Nearest(posX, posY); - if (!isTileInBounds(newPosition)) - { - return; - } - - if (hasTile(newPosition)) - { - Item swapItem = items.Where(x => x.Coord.Equals(newPosition)).FirstOrDefault(); - if (swapItem != null) - { - swapItem.Coord = item.Coord; - swapItem.Tile.Location = convertCoordToLocation(item.Coord); - } - - item.Coord = newPosition; - panel.Location = convertCoordToLocation(newPosition); - } - else - { - item.Coord = newPosition; - panel.Location = convertCoordToLocation(newPosition); - } - } - - public void MoveTop() - { - if (this.FlowLayoutPanel == null) - { - return; - } - - this.FlowLayoutPanel.Controls.SetChildIndex(this, 0); - } - - public void MoveUp() - { - if (this.FlowLayoutPanel == null) - { - return; - } - - int pos = this.FlowLayoutPanel.Controls.GetChildIndex(this); - if (pos <= 0) - { - return; - } - - this.FlowLayoutPanel.Controls.SetChildIndex(this, (pos - 1)); - } - - public void MoveDown() - { - if (this.FlowLayoutPanel == null) - { - return; - } - - int pos = this.FlowLayoutPanel.Controls.GetChildIndex(this); - if (pos >= (this.FlowLayoutPanel.Controls.Count - 1)) - { - return; - } - - this.FlowLayoutPanel.Controls.SetChildIndex(this, (pos + 1)); - } - - public void MoveBottom() - { - if (this.FlowLayoutPanel == null) - { - return; - } - - this.FlowLayoutPanel.Controls.SetChildIndex(this, (this.FlowLayoutPanel.Controls.Count - 1)); - } - - public void Remove() - { - if (this.FlowLayoutPanel == null) - { - return; - } - - this.FlowLayoutPanel.Controls.Remove(this); - } - - public void Remove(TilePanel panel) - { - Item m = items.Where(x => x.Tile.Equals(panel)).FirstOrDefault(); - if (m != null) - { - items.Remove(m); - } - - this.Controls.Remove(panel); - } - - public void SetGridSize(int width, int height) - { - gridSize = new Point(width, height); + this.GridSize = new Point(width, height); groupModel.GridSize = new Size(groupModel.GridSize.Width, height); - - expandedHeight = (this.TileSize * height) + labelHeight; - - int w = CalcWidth(gridSize.X); - - this.Size = new Size(w, (isChecked ? this.ExpandedHeight : this.CollapseHeight)); } - protected Point convertCoordToLocation(Point position) => new Point((position.X * this.TileSize), ((position.Y * this.TileSize) + labelHeight)); - - protected Point convertLocationToCoord(int posX, int posY) + protected override async void label1_MouseClick(object sender, MouseEventArgs e) { - int x = (int)Math.Ceiling(decimal.Divide(posX, this.TileSize)); - int y = (int)Math.Ceiling(decimal.Divide((posY - labelHeight), this.TileSize)); + base.label1_MouseClick(sender, e); - x--; - y--; - - if (x < 0) x = 0; - if (y < 0) y = 0; - - return new Point(x, y); - } - - protected Point convertLocationToCoord_Nearest(int posX, int posY) - { - int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); - int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize)); - - if (x < 0) x = 0; - if (y < 0) y = 0; - - return new Point(x, y); - } - - protected Point? findFirstFreeCoord() - { - Point gridSize = this.GridSize; - - for (int y = 0; y < gridSize.Y; y++) + if (isAnimating) { - for (int x = 0; x < gridSize.X; x++) - { - if (hasTile(new Point(x, y))) - { - continue; - } - - return new Point(x, y); - } + return; } - return null; - } - - protected Point? findLastFreeCoord() - { - Point gridSize = this.GridSize; - - // none available - if (items.Count >= (gridSize.X * gridSize.Y)) - { - return null; - } - - if (items.Count <= 0) - { - return findFirstFreeCoord(); - } - - // only one available - if (items.Count >= ((gridSize.X * gridSize.Y) - 1)) - { - return findFirstFreeCoord(); - } - - Point? rv = null; - - for (int y = (gridSize.Y - 1); y >= 0; y--) - { - for (int x = (gridSize.X - 1); x >= 0; x--) - { - if (hasTile(new Point(x, y))) - { - if (rv.HasValue) - { - return rv; - } - } - else - { - rv = new Point(x, y); - } - } - } - - return null; - } - - protected bool hasTile(Point position) - { - if (items == null) - { - return false; - } - - if (items.Count <= 0) - { - return false; - } - - return (items.Count(x => x.Coord.Equals(position)) > 0); - } - - protected bool isTileInBounds(Point position) - { - Point gridSize = this.GridSize; - - if (position.X >= gridSize.X) - { - return false; - } - - if (position.Y >= gridSize.Y) - { - return false; - } - - return true; - } - - protected Point? resolveCoord(Point coord) - { - if (!isTileInBounds(coord)) - { - return null; - } - - if (!hasTile(coord)) - { - return coord; - } - - return resolveNextCoord(coord); - } - - protected Point? resolveNextCoord(Point coord) - { - Point gridSize = this.GridSize; - Point newCoord = coord; - - while (true) - { - newCoord.X++; - - if (newCoord.X >= gridSize.X) - { - newCoord.Y++; - newCoord.X = 0; - } - - if (!isTileInBounds(newCoord)) - { - return null; - } - - if (hasTile(newCoord)) - { - continue; - } - - return newCoord; - } - } - - private async void label1_MouseClick(object sender, MouseEventArgs e) - { - if (isAnimating) return; - if (e.Button == MouseButtons.Left) { - isChecked = !isChecked; - - label1.Image = (isChecked ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); - - this.Invalidate(); - - await this.InvalidateContainer(); - // exclusivity - if (isChecked) + if (this.IsExpanded) { if (this.Model.IsExclusive) { @@ -796,12 +297,6 @@ namespace FizzyLauncher.Windows.Forms } } } - - label1.Image = (isChecked ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); - } - else if (e.Button == MouseButtons.Right) - { - contextMenuStrip2.Show(this, e.Location); } } @@ -814,9 +309,9 @@ namespace FizzyLauncher.Windows.Forms /// private void addTileMenuItem_Click(object sender, EventArgs e) { - Point coord = convertLocationToCoord(lastMousePosition.X, lastMousePosition.Y); + Point coord = ConvertLocationToCoord(lastMousePosition.X, lastMousePosition.Y); - EditTileForm.ShowAddDialog(this, coord); + //EditTileForm.ShowAddDialog(this, coord); } /// @@ -826,9 +321,9 @@ namespace FizzyLauncher.Windows.Forms /// private void addListTileMenuItem_Click(object sender, EventArgs e) { - Point coord = convertLocationToCoord(lastMousePosition.X, lastMousePosition.Y); + Point coord = ConvertLocationToCoord(lastMousePosition.X, lastMousePosition.Y); - EditTileFolderForm.ShowAddDialog(this, coord); + //EditTileFolderForm.ShowAddDialog(this, coord); } #endregion @@ -872,18 +367,18 @@ namespace FizzyLauncher.Windows.Forms /// private void removeRowToolStripMenuItem_Click_1(object sender, EventArgs e) { - if (gridSize.Y <= 1) + if (this.GridSize.Y <= 1) { return; } - bool rs = items.Exists(x => x.Coord.Y.Equals(gridSize.Y - 1)); + bool rs = GridTileItems.Exists(x => x.Coord.Y.Equals(this.GridSize.Y - 1)); if (rs) { return; } - this.SetGridSize(gridSize.X, (gridSize.Y - 1)); + this.SetGridSize(this.GridSize.X, (this.GridSize.Y - 1)); } /// @@ -938,5 +433,6 @@ namespace FizzyLauncher.Windows.Forms #endregion + } } diff --git a/Windows/GridTableLayout.Designer.cs b/Windows/GridTableLayout.Designer.cs new file mode 100644 index 0000000..7accad9 --- /dev/null +++ b/Windows/GridTableLayout.Designer.cs @@ -0,0 +1,37 @@ +namespace FizzyLauncher.Windows +{ + partial class GridTableLayout + { + /// + /// 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 Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/Windows/GridTableLayout.cs b/Windows/GridTableLayout.cs new file mode 100644 index 0000000..09dd3d1 --- /dev/null +++ b/Windows/GridTableLayout.cs @@ -0,0 +1,20 @@ +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 FizzyLauncher.Windows +{ + public partial class GridTableLayout : RyzStudio.Windows.Forms.T1UserControl + { + public GridTableLayout() + { + InitializeComponent(); + } + } +} diff --git a/Windows/GridTableLayout.resx b/Windows/GridTableLayout.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Windows/GridTableLayout.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/Windows/TileGridPanel.Designer.cs b/Windows/TileGridPanel.Designer.cs new file mode 100644 index 0000000..02e2d8b --- /dev/null +++ b/Windows/TileGridPanel.Designer.cs @@ -0,0 +1,37 @@ +namespace RyzStudio.Windows.Forms +{ + partial class TileGridPanel + { + /// + /// 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 Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/Windows/TileGridPanel.cs b/Windows/TileGridPanel.cs new file mode 100644 index 0000000..61524e8 --- /dev/null +++ b/Windows/TileGridPanel.cs @@ -0,0 +1,72 @@ +namespace RyzStudio.Windows.Forms +{ + public partial class TileGridPanel : RyzStudio.Windows.Forms.T1UserControl + { + public TileGridPanel() : base() + { + InitializeComponent(); + + this.EnableMovable = true; + } + + //protected override void OnDragOver(DragEventArgs e) + //{ + // base.OnDragDrop(e); + + // e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? DragDropEffects.Link : DragDropEffects.None; + //} + + //protected override void OnMouseUp(MouseEventArgs e) + //{ + // base.OnMouseUp(e); + + // isDragging = false; + //} + + //protected override void OnMouseDown(MouseEventArgs e) + //{ + // base.OnMouseDown(e); + + // //var parentLayout = this.TileGridLayout; + // //if (parentLayout == null) + // //{ + // // return; + // //} + + // this.BringToFront(); + + // if (((e.Button == MouseButtons.Left) && (Control.ModifierKeys == Keys.Control)) || (e.Button == MouseButtons.Right)) + // { + // isDragging = true; + // startPosition = e.Location; + // } + //} + + //protected override void OnMouseMove(MouseEventArgs e) + //{ + // base.OnMouseMove(e); + + // if (isDragging) + // { + // //var parentLayout = this.TileGridLayout; + // //if (parentLayout == null) + // //{ + // // return; + // //} + + // int x = (this.Location.X + (e.Location.X - startPosition.X)); + // int y = (this.Location.Y + (e.Location.Y - startPosition.Y)); + + // //parentLayout.MoveTile(this, x, y); + + // this.Location = new Point(x, y); + + // } + //} + + + //public TileGridPanelLayout TileGridLayout { get => UIControl.GetParentsUntil>(this); } + + + } +} \ No newline at end of file diff --git a/Windows/TileGridPanel.resx b/Windows/TileGridPanel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Windows/TileGridPanel.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/Windows/TileGridPanelLayout.Designer.cs b/Windows/TileGridPanelLayout.Designer.cs new file mode 100644 index 0000000..42a0c3a --- /dev/null +++ b/Windows/TileGridPanelLayout.Designer.cs @@ -0,0 +1,67 @@ +using System.Drawing; +using System.Windows.Forms; + +namespace RyzStudio.Windows.Forms +{ + partial class TileGridPanelLayout + { + /// + /// 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 Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new System.Windows.Forms.Label(); + SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(99)))), ((int)(((byte)(105)))), ((int)(((byte)(119))))); + this.label1.Image = global::FizzyLauncher.AppResource.toggle_left_ea_16; + this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.label1.Location = new System.Drawing.Point(0, 4); + this.label1.Margin = new System.Windows.Forms.Padding(0); + this.label1.Padding = new System.Windows.Forms.Padding(0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(0, 15); + this.label1.TabIndex = 2; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.label1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.label1_MouseClick); + this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.label1_MouseClick); + // + // GridLayout2 + // + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + Controls.Add(label1); + Name = "GridLayout2"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.Label label1; + } +} diff --git a/Windows/TileGridPanelLayout.cs b/Windows/TileGridPanelLayout.cs new file mode 100644 index 0000000..28f3430 --- /dev/null +++ b/Windows/TileGridPanelLayout.cs @@ -0,0 +1,581 @@ +using System; +using System.CodeDom; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using FizzyLauncher; +using FizzyLauncher.Windows.Forms; + +namespace RyzStudio.Windows.Forms +{ + public partial class TileGridPanelLayout : RyzStudio.Windows.Forms.TUserControl where T : Control + { + public static int CalcWidth(int tileCount) + => (tileCount * tileSize) + ((tileCount - 1) * margin); + + + public class GridTileItem + { + public T Tile { get; set; } + public Point Coord { get; set; } = new Point(0, 0); + } + + + protected const int tileSize = 70; + protected const int margin = 3; + protected const int labelHeight = 20; + protected const int collapseIncrement = 6; + protected const int expandIncrement = 8; + + protected int collapseHeight = 0; + protected int expandedHeight = 0; + + protected bool isAnimating = false; + protected bool isExpanded = true; + protected Point lastMousePosition = new Point(); + protected Point gridSize = new Point(0, 0); + + + public TileGridPanelLayout() : base() + { + InitializeComponent(); + + this.AllowDrop = true; + this.BackColor = Color.Transparent; + this.Margin = new Padding(0); + this.Padding = new Padding(0, 0, 0, 10); + + } + + protected override void OnControlAdded(ControlEventArgs e) + { + base.OnControlAdded(e); + + e.Control.MouseMove += (sender, e) => + { + this.MoveTile(sender as T, e.X, e.Y); + }; + } + + private void tilePanel_Move(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + + protected override void OnDragOver(DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + e.Effect = DragDropEffects.Link; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + protected override void OnMouseClick(MouseEventArgs e) + { + base.OnMouseClick(e); + + lastMousePosition = e.Location; + + bool isLabel = ((e.Location.X >= 0) && (e.Location.X <= this.Width) && (e.Location.Y >= 0) && (e.Location.Y <= 20)); + + if (e.Button == MouseButtons.Left) + { + // do nothing + } + else if (e.Button == MouseButtons.Right) + { + if (isLabel) + { + this.TitleContextMenuStrip?.Show(this, e.Location); + } + else + { + this.ContainerContextMenuStrip?.Show(this, e.Location); + } + } + } + + protected override void OnMouseDoubleClick(MouseEventArgs e) + => base.OnMouseClick(e); + + protected override async void OnResize(EventArgs e) + { + base.OnResize(e); + + await this.Invalidate(); + } + + protected virtual async void label1_MouseClick(object sender, MouseEventArgs e) + { + if (isAnimating) + { + return; + } + + if (e.Button == MouseButtons.Left) + { + this.IsExpanded = !this.IsExpanded; + + //label1.Image = (this.IsExpanded ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); + + await this.Invalidate(); + + // exclusivity + //if (this.IsExpanded) + //{ + //if (this.Model.IsExclusive) + //{ + // if (this.FlowLayoutPanel != null) + // { + // foreach (TilePanelLayout item in this.FlowLayoutPanel.Controls.OfType()) + // { + // if (item.Equals(this)) + // { + // continue; + // } + + // await item.Collapse(); + // } + // } + //} + //} + + //label1.Image = (this.IsExpanded ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); + } + else if (e.Button == MouseButtons.Right) + { + this.TitleContextMenuStrip?.Show(this, e.Location); + } + } + + #region encapsulation + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new Padding Margin { get => base.Margin; set => base.Margin = new Padding(0); } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new Padding Padding { get => base.Padding; set => base.Padding = new Padding(0, 0, 0, 10); } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new ContextMenuStrip ContextMenuStrip { get; set; } = null; + + #endregion + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public Point GridSize + { + get => gridSize; + protected set + { + gridSize = value; + expandedHeight = (this.TileSize * value.Y) + labelHeight; + + int newWidth = CalcWidth(gridSize.X); + + this.Size = new Size(newWidth, (this.IsExpanded ? this.ExpandedHeight : this.CollapseHeight)); + } + } + + [Category("Appearance")] + public ContextMenuStrip TitleContextMenuStrip { get; set; } = null; + + [Category("Appearance")] + public ContextMenuStrip ContainerContextMenuStrip { get; set; } = null; + + [Category("Appearance")] + public bool EnableAnimation { get; set; } = false; + + [Category("Appearance")] + public string Title { get => label1.Text?.Trim(); set => label1.Text = " " + value; } + + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public List GridTileItems { get; protected set; } = new List(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public FlowLayoutPanel FlowLayoutPanel { get => UIControl.GetParentsUntil(this.Parent); } + + protected int CollapseHeight + => labelHeight + collapseHeight; + + protected int ExpandedHeight + => expandedHeight + this.Padding.Bottom; + + protected int TileSize => (tileSize + margin); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsExpanded + { + get => isExpanded; + protected set + { + isExpanded = value; + + //label1.Image = (isExpanded ? UIResource1.toggle_right_16 : UIResource1.toggle_left_16); + label1.Image = (isExpanded ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16); + } + } + + + public void Clear() + { + this.Controls.Clear(); + } + + public async Task Collapse() + { + await Task.Run(() => + { + if (isAnimating) return; + + isAnimating = true; + this.IsExpanded = false; + + if (this.EnableAnimation) + { + while (this.Height > this.CollapseHeight) + { + UIControl.SetHeight(this, (this.Height - collapseIncrement)); + + Thread.Sleep(10); + } + } + + UIControl.SetHeight(this, this.CollapseHeight); + + isAnimating = false; + + this.Invalidate(this.DisplayRectangle, false); + }); + } + + public async Task Expand() + { + await Task.Run(() => + { + if (isAnimating) return; + + isAnimating = true; + this.IsExpanded = true; + + if (this.EnableAnimation) + { + while (this.Height < this.ExpandedHeight) + { + UIControl.SetHeight(this, (this.Height + expandIncrement)); + Thread.Sleep(10); + } + } + + UIControl.SetHeight(this, this.ExpandedHeight); + + isAnimating = false; + + this.Invalidate(this.DisplayRectangle, false); + }); + } + + public new async Task Invalidate() + { + base.Invalidate(); + + if (isAnimating) + { + return; + } + + if (this.IsExpanded) + { + await this.Expand(); + } + else + { + await this.Collapse(); + } + } + + public void MoveTop() + { + if (this.FlowLayoutPanel != null) + { + this.FlowLayoutPanel.Controls.SetChildIndex(this, 0); + } + } + + public void MoveUp() + { + if (this.FlowLayoutPanel != null) + { + int pos = this.FlowLayoutPanel.Controls.GetChildIndex(this); + if (pos <= 0) + { + return; + } + + this.FlowLayoutPanel.Controls.SetChildIndex(this, (pos - 1)); + } + } + + public void MoveDown() + { + if (this.FlowLayoutPanel != null) + { + int pos = this.FlowLayoutPanel.Controls.GetChildIndex(this); + if (pos >= (this.FlowLayoutPanel.Controls.Count - 1)) + { + return; + } + + this.FlowLayoutPanel.Controls.SetChildIndex(this, (pos + 1)); + } + } + + public void MoveBottom() + { + if (this.FlowLayoutPanel != null) + { + this.FlowLayoutPanel.Controls.SetChildIndex(this, (this.FlowLayoutPanel.Controls.Count - 1)); + } + } + + public void MoveTile(T panel, int posX, int posY) + { + GridTileItem item = this.GridTileItems.Where(x => x.Tile.Equals(panel)).FirstOrDefault(); + if (item == null) + { + return; + } + + //Point newPosition = ConvertLocationToNearestCoord(posX, posY); + //Point newPosition = ConvertLocationToCoord(posX, posY); + Point newPosition = ConvertLocationToCoord(panel.Location.X, panel.Location.Y); + if (!IsCoordInBounds(newPosition)) + { + return; + } + + if (HasTile(newPosition)) + { + GridTileItem swapItem = this.GridTileItems.Where(x => x.Coord.Equals(newPosition)).FirstOrDefault(); + if (swapItem != null) + { + swapItem.Coord = item.Coord; + swapItem.Tile.Location = ConvertCoordToLocation(item.Coord); + } + + item.Coord = newPosition; + panel.Location = ConvertCoordToLocation(newPosition); + } + else + { + item.Coord = newPosition; + panel.Location = ConvertCoordToLocation(newPosition); + } + } + + public void Remove() + { + if (this.FlowLayoutPanel != null) + { + this.FlowLayoutPanel.Controls.Remove(this); + } + } + + public void Remove(T panel) + { + GridTileItem m = this.GridTileItems.Where(x => x.Tile.Equals(panel)).FirstOrDefault(); + if (m != null) + { + this.GridTileItems.Remove(m); + } + + this.Controls.Remove(panel); + } + + //protected Point CalcCoordFromPosition(int posX, int posY) + //{ + // int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); + // int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize)); + + // if (x < 0) x = 0; + // if (y < 0) y = 0; + + // return new Point((x * this.TileSize), ((y * this.TileSize) + labelHeight)); + //} + + protected Point ConvertCoordToLocation(Point position) + => new Point((position.X * this.TileSize), ((position.Y * this.TileSize) + labelHeight)); + + protected Point ConvertLocationToCoord(int posX, int posY) + { + int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); + int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize)); + + //int x = (int)Math.Ceiling(decimal.Divide(posX, this.TileSize)); + //int y = (int)Math.Ceiling(decimal.Divide((posY - labelHeight), this.TileSize)); + + //x--; + //y--; + + if (x < 0) x = 0; + if (y < 0) y = 0; + + return new Point(x, y); + } + + //protected Point ConvertLocationToNearestCoord(int posX, int posY) + //{ + // int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); + // int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize)); + + // if (x < 0) x = 0; + // if (y < 0) y = 0; + + // return new Point(x, y); + //} + + protected bool HasTile(Point position) + { + if (GridTileItems == null) + { + return false; + } + + if (GridTileItems.Count <= 0) + { + return false; + } + + return GridTileItems.Any(x => x.Coord.Equals(position)); + } + + protected bool IsCoordInBounds(Point position) + { + if (position.X >= this.GridSize.X) + { + return false; + } + + if (position.Y >= this.GridSize.Y) + { + return false; + } + + return true; + } + + protected Point? FindFirstFreeCoord() + { + for (int y = 0; y < this.GridSize.Y; y++) + { + for (int x = 0; x < this.GridSize.X; x++) + { + if (HasTile(new Point(x, y))) + { + continue; + } + + return new Point(x, y); + } + } + + return null; + } + + protected Point? FindLastFreeCoord() + { + Point gridSize = this.GridSize; + + // none available + if (GridTileItems.Count >= (gridSize.X * gridSize.Y)) + { + return null; + } + + if (GridTileItems.Count <= 0) + { + return FindFirstFreeCoord(); + } + + // only one available + if (GridTileItems.Count >= ((gridSize.X * gridSize.Y) - 1)) + { + return FindFirstFreeCoord(); + } + + Point? rv = null; + + for (int y = (gridSize.Y - 1); y >= 0; y--) + { + for (int x = (gridSize.X - 1); x >= 0; x--) + { + if (HasTile(new Point(x, y))) + { + if (rv.HasValue) + { + return rv; + } + } + else + { + rv = new Point(x, y); + } + } + } + + return null; + } + + protected Point? FindNextFreeCoord(Point coord) + { + Point newCoord = coord; + + while (true) + { + newCoord.X++; + + if (newCoord.X >= this.GridSize.X) + { + newCoord.Y++; + newCoord.X = 0; + } + + if (!IsCoordInBounds(newCoord)) + { + return null; + } + + if (HasTile(newCoord)) + { + continue; + } + + return newCoord; + } + } + + protected Point? ResolveCoord(Point coord) + { + if (!IsCoordInBounds(coord)) + { + return null; + } + + if (!HasTile(coord)) + { + return coord; + } + + return FindNextFreeCoord(coord); + } + + } +} diff --git a/Windows/TileGridPanelLayout.resx b/Windows/TileGridPanelLayout.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/Windows/TileGridPanelLayout.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/build.bat b/build.bat index d90b1f3..71bd782 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,5 @@ rmdir /s /q "bin\Release\" +dotnet restore skye.sln dotnet publish skye.sln -r win-x64 -c Release /p:PublishSingleFile=true /p:SelfContained=false /p:PublishReadyToRunfalse=true /p:PublishDir="bin\Release\64\" ##rmdir /s /q "bin\Release\86\" diff --git a/skye.sln b/skye.sln index 94d918f..95187b0 100644 --- a/skye.sln +++ b/skye.sln @@ -5,6 +5,12 @@ VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FizzyLauncher", "FizzyLauncher.csproj", "{4833FB27-0817-4720-A54B-180369B0C374}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RyzStudio", "..\ryzstudio8\core\RyzStudio.csproj", "{C790A76B-C968-476E-AD96-C8DA6147C0B4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RyzStudio.Windows.Forms", "..\ryzstudio8\windows.forms\RyzStudio.Windows.Forms.csproj", "{C828C8E9-F46C-444E-8C0F-A2C7887B1117}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RyzStudio.Data.Sqlite", "..\ryzstudio8\data.sqlite\RyzStudio.Data.Sqlite.csproj", "{96E88371-0C86-4574-A507-FF19092C840B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +21,18 @@ Global {4833FB27-0817-4720-A54B-180369B0C374}.Debug|Any CPU.Build.0 = Debug|Any CPU {4833FB27-0817-4720-A54B-180369B0C374}.Release|Any CPU.ActiveCfg = Release|Any CPU {4833FB27-0817-4720-A54B-180369B0C374}.Release|Any CPU.Build.0 = Release|Any CPU + {C790A76B-C968-476E-AD96-C8DA6147C0B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C790A76B-C968-476E-AD96-C8DA6147C0B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C790A76B-C968-476E-AD96-C8DA6147C0B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C790A76B-C968-476E-AD96-C8DA6147C0B4}.Release|Any CPU.Build.0 = Release|Any CPU + {C828C8E9-F46C-444E-8C0F-A2C7887B1117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C828C8E9-F46C-444E-8C0F-A2C7887B1117}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C828C8E9-F46C-444E-8C0F-A2C7887B1117}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C828C8E9-F46C-444E-8C0F-A2C7887B1117}.Release|Any CPU.Build.0 = Release|Any CPU + {96E88371-0C86-4574-A507-FF19092C840B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96E88371-0C86-4574-A507-FF19092C840B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96E88371-0C86-4574-A507-FF19092C840B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96E88371-0C86-4574-A507-FF19092C840B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE