diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index a55f6b7..ca2e933 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -32,6 +32,12 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem7 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripMenuItem8 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); @@ -39,6 +45,7 @@ this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); ((System.ComponentModel.ISupportInitialize)(this.imageBox3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.imageBox2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.imageBox1)).BeginInit(); @@ -49,19 +56,19 @@ // this.imageBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.imageBox3.Image = ((System.Drawing.Image)(resources.GetObject("imageBox3.Image"))); - this.imageBox3.Location = new System.Drawing.Point(384, 18); + this.imageBox3.Location = new System.Drawing.Point(-71, 18); // // imageBox2 // this.imageBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.imageBox2.Image = ((System.Drawing.Image)(resources.GetObject("imageBox2.Image"))); - this.imageBox2.Location = new System.Drawing.Point(356, 18); + this.imageBox2.Location = new System.Drawing.Point(-99, 18); // // imageBox1 // this.imageBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.imageBox1.Image = ((System.Drawing.Image)(resources.GetObject("imageBox1.Image"))); - this.imageBox1.Location = new System.Drawing.Point(328, 18); + this.imageBox1.Location = new System.Drawing.Point(-127, 18); // // contextMenuStrip1 // @@ -71,22 +78,66 @@ this.toolStripSeparator1, this.exitToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(181, 98); + this.contextMenuStrip1.Size = new System.Drawing.Size(100, 76); this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening); // // toolStripMenuItem4 // this.toolStripMenuItem4.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem5, + this.toolStripMenuItem7, + this.toolStripSeparator2, + this.toolStripMenuItem8, + this.toolStripSeparator3, + this.toolStripMenuItem6, this.toolStripMenuItem2}); this.toolStripMenuItem4.Name = "toolStripMenuItem4"; - this.toolStripMenuItem4.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem4.Size = new System.Drawing.Size(99, 22); this.toolStripMenuItem4.Text = "&File"; // + // toolStripMenuItem5 + // + this.toolStripMenuItem5.Name = "toolStripMenuItem5"; + this.toolStripMenuItem5.Size = new System.Drawing.Size(123, 22); + this.toolStripMenuItem5.Text = "&New"; + this.toolStripMenuItem5.Click += new System.EventHandler(this.toolStripMenuItem5_Click); + // + // toolStripMenuItem7 + // + this.toolStripMenuItem7.Name = "toolStripMenuItem7"; + this.toolStripMenuItem7.Size = new System.Drawing.Size(123, 22); + this.toolStripMenuItem7.Text = "&Open"; + this.toolStripMenuItem7.Click += new System.EventHandler(this.toolStripMenuItem7_Click); + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(120, 6); + // + // toolStripMenuItem8 + // + this.toolStripMenuItem8.Name = "toolStripMenuItem8"; + this.toolStripMenuItem8.Size = new System.Drawing.Size(123, 22); + this.toolStripMenuItem8.Text = "&Close"; + this.toolStripMenuItem8.Click += new System.EventHandler(this.toolStripMenuItem8_Click); + // + // toolStripSeparator3 + // + this.toolStripSeparator3.Name = "toolStripSeparator3"; + this.toolStripSeparator3.Size = new System.Drawing.Size(120, 6); + // + // toolStripMenuItem6 + // + this.toolStripMenuItem6.Name = "toolStripMenuItem6"; + this.toolStripMenuItem6.Size = new System.Drawing.Size(123, 22); + this.toolStripMenuItem6.Text = "&Save"; + this.toolStripMenuItem6.Click += new System.EventHandler(this.toolStripMenuItem6_Click); + // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; this.toolStripMenuItem2.Size = new System.Drawing.Size(123, 22); - this.toolStripMenuItem2.Text = "&Save As..."; + this.toolStripMenuItem2.Text = "Save &As..."; this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click); // // toolStripMenuItem3 @@ -94,7 +145,7 @@ this.toolStripMenuItem3.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1}); this.toolStripMenuItem3.Name = "toolStripMenuItem3"; - this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 22); + this.toolStripMenuItem3.Size = new System.Drawing.Size(99, 22); this.toolStripMenuItem3.Text = "&View"; // // toolStripMenuItem1 @@ -107,12 +158,12 @@ // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(96, 6); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(99, 22); this.exitToolStripMenuItem.Text = "E&xit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -127,7 +178,7 @@ this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 58); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; this.flowLayoutPanel1.Padding = new System.Windows.Forms.Padding(0, 0, 10, 0); - this.flowLayoutPanel1.Size = new System.Drawing.Size(1075, 341); + this.flowLayoutPanel1.Size = new System.Drawing.Size(620, 341); this.flowLayoutPanel1.TabIndex = 27; this.flowLayoutPanel1.WrapContents = false; // @@ -136,13 +187,19 @@ this.saveFileDialog1.Filter = "Session files|*.jsonfig"; this.saveFileDialog1.Title = "Choose file to save the session"; // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.Filter = "Session files|*.jsonfig"; + this.openFileDialog1.Title = "Choose session file"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(254)))), ((int)(((byte)(254))))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.ClientSize = new System.Drawing.Size(1088, 400); + this.ClientSize = new System.Drawing.Size(633, 400); this.Controls.Add(this.flowLayoutPanel1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "MainForm"; @@ -170,6 +227,13 @@ private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; private System.Windows.Forms.SaveFileDialog saveFileDialog1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem5; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem6; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem7; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem8; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; } } diff --git a/MainForm.cs b/MainForm.cs index 16bab41..55745c2 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -15,7 +15,8 @@ namespace AppLauncher { protected int collapsedWidth = 40; protected int expandedWidth = 800; - protected bool isBusy = false; + + protected string sessionFilename = null; public MainForm() : base() { @@ -24,13 +25,6 @@ namespace AppLauncher //this.Visible = false; } - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - - //this.Visible = false; - } - protected override void OnShown(EventArgs e) { this.Visible = false; @@ -40,7 +34,7 @@ namespace AppLauncher string jsonfigFilename = Path.ChangeExtension(Application.ExecutablePath, "jsonfig"); if (File.Exists(jsonfigFilename)) { - loadSession(jsonfigFilename); + loadFile(jsonfigFilename); } this.Location = this.DefaultLocation; @@ -63,61 +57,159 @@ namespace AppLauncher } } + /// + /// New + /// + /// + /// + private void toolStripMenuItem5_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(); + + sessionFilename = null; + } + } + else if (dr == DialogResult.No) + { + newSession(); + + sessionFilename = null; + } + else if (dr == DialogResult.Cancel) + { + return; + } + } + } + + /// + /// Open + /// + /// + /// + private void toolStripMenuItem7_Click(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(sessionFilename)) + { + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + 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) + { + loadFile(openFileDialog1.FileName); + } + } + } + else if (dr == DialogResult.No) + { + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + loadFile(openFileDialog1.FileName); + } + } + else if (dr == DialogResult.Cancel) + { + return; + } + } + } + + /// + /// Close + /// + /// + /// + private void toolStripMenuItem8_Click(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(sessionFilename)) + { + flowLayoutPanel1.Controls.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) + { + flowLayoutPanel1.Controls.Clear(); + + sessionFilename = null; + } + } + else if (dr == DialogResult.No) + { + flowLayoutPanel1.Controls.Clear(); + + sessionFilename = null; + } + else if (dr == DialogResult.Cancel) + { + return; + } + } + } + + /// + /// Save + /// + /// + /// + private void toolStripMenuItem6_Click(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(sessionFilename)) + { + saveAsFile(); + } + else + { + saveFile(sessionFilename, true); + } + } + /// /// Save As /// /// /// - private void toolStripMenuItem2_Click(object sender, EventArgs e) - { - if (isBusy) - { - return; - } - - if (flowLayoutPanel1.Controls.Count <= 0) - { - return; - } - - if (saveFileDialog1.ShowDialog() != DialogResult.OK) - { - return; - } - - isBusy = true; - - List rs = new List(); - for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++) - { - if (flowLayoutPanel1.Controls[i].GetType() != typeof(TTilePanelLayout)) - { - continue; - } - - TTilePanelLayout container = flowLayoutPanel1.Controls[i] as TTilePanelLayout; - rs.Add(container.Model); - } - - try - { - File.WriteAllText(saveFileDialog1.FileName, JsonConvert.SerializeObject(rs)); - MessageBox.Show("Session saved!", "Save session", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - catch (Exception exc) - { - MessageBox.Show(exc.Message, "Save session"); - } - - isBusy = false; - } + private void toolStripMenuItem2_Click(object sender, EventArgs e) => saveAsFile(); + /// + /// Always On Top + /// + /// + /// private void toolStripMenuItem1_Click(object sender, EventArgs e) => this.TopMost = !this.TopMost; - private void exitToolStripMenuItem_Click(object sender, EventArgs e) - { - this.Close(); - } + /// + /// Exit + /// + /// + /// + private void exitToolStripMenuItem_Click(object sender, EventArgs e) => this.Close(); protected async Task collapseWindow(int width, int increment = 6) { @@ -149,9 +241,37 @@ namespace AppLauncher }); } - protected void loadSession(string filename) + protected void loadFile(string filename) { - string sourceCode = File.ReadAllText(filename); + 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; @@ -174,18 +294,105 @@ namespace AppLauncher flowLayoutPanel1.Controls.Add(panel); } - //flowLayoutPanel1.Width = maxWidth + SystemInformation.VerticalScrollBarWidth + 20; - //flowLayoutPanel1.Width = maxWidth + SystemInformation.VerticalScrollBarWidth + 20; - - //this.Width = flowLayoutPanel1.Width + (flowLayoutPanel1.Left * 2); - //this.Width = flowLayoutPanel1.Width + flowLayoutPanel1.Left; this.Width = maxWidth + SystemInformation.VerticalScrollBarWidth + 20 + flowLayoutPanel1.Left; } + protected void newSession() + { + int maxWidth = 0; + flowLayoutPanel1.Controls.Clear(); + + TTilePanelLayout panel = new TTilePanelLayout(new TileGroupModel() + { + Title = "New Group", + IsExpanded = true, + GridSize = new Size(8, 1) + }); + + maxWidth = Math.Max(maxWidth, panel.Width); + + flowLayoutPanel1.Controls.Add(panel); + + this.Width = maxWidth + SystemInformation.VerticalScrollBarWidth + 20 + flowLayoutPanel1.Left; + } + + protected bool saveFile(string filename, bool showNotices = true) + { + if (isBusy) + { + return false; + } + + if (string.IsNullOrWhiteSpace(filename)) + { + return false; + } + + if (flowLayoutPanel1.Controls.Count <= 0) + { + return true; + } + + isBusy = true; + + List rs = new List(); + for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++) + { + if (flowLayoutPanel1.Controls[i].GetType() != typeof(TTilePanelLayout)) + { + continue; + } + + TTilePanelLayout container = flowLayoutPanel1.Controls[i] as TTilePanelLayout; + rs.Add(container.Model); + } + + try + { + File.WriteAllText(filename, JsonConvert.SerializeObject(rs)); + + 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; + } + private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e) { toolStripMenuItem1.Checked = this.TopMost; - + toolStripMenuItem6.Enabled = !string.IsNullOrWhiteSpace(sessionFilename); } } diff --git a/MainForm.resx b/MainForm.resx index 4b6ba9e..98f90b3 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -153,6 +153,9 @@ 172, 17 + + 308, 17 + AAABAAQAMDAAAAEAIACoJQAARgAAACAgAAABACAAqBAAAO4lAAAYGAAAAQAgAIgJAACWNgAAEBAAAAEA diff --git a/Resources/app_icon_24.png b/Resources/app_icon_24.png index 2d9b51f..ad67f18 100644 Binary files a/Resources/app_icon_24.png and b/Resources/app_icon_24.png differ diff --git a/Resources/raw/app_icon_24.png b/Resources/raw/app_icon_24.png new file mode 100644 index 0000000..2d9b51f Binary files /dev/null and b/Resources/raw/app_icon_24.png differ diff --git a/Windows/Forms/AForm.cs b/Windows/Forms/AForm.cs index cc6dfc9..3cbd64e 100644 --- a/Windows/Forms/AForm.cs +++ b/Windows/Forms/AForm.cs @@ -13,12 +13,15 @@ namespace AppLauncher.Windows.Forms protected readonly int titleBarHeight = 56; private bool isDragging = false; + private Point startPosition = new Point(); + + protected bool isBusy = false; + protected internal RyzStudio.Windows.Forms.TImageBox imageBox3; protected internal RyzStudio.Windows.Forms.TImageBox imageBox2; protected internal RyzStudio.Windows.Forms.TImageBox imageBox1; private NotifyIcon notifyIcon1; private IContainer components; - private Point startPosition = new Point(); public AForm() : base() { diff --git a/Windows/Forms/Tile/AddListTileForm.cs b/Windows/Forms/Tile/AddListTileForm.cs index 113b751..6b5fe15 100644 --- a/Windows/Forms/Tile/AddListTileForm.cs +++ b/Windows/Forms/Tile/AddListTileForm.cs @@ -267,6 +267,12 @@ namespace AppLauncher.Windows.Forms // do nothing } } + + + if (string.IsNullOrWhiteSpace(model.Title)) + { + model.Title = Path.GetFileNameWithoutExtension(fileList[0]); + } } listBox1.ListBox.Items.Add(model); diff --git a/Windows/Forms/Tile/EditListTileForm.cs b/Windows/Forms/Tile/EditListTileForm.cs index c1eff00..d901c45 100644 --- a/Windows/Forms/Tile/EditListTileForm.cs +++ b/Windows/Forms/Tile/EditListTileForm.cs @@ -288,6 +288,11 @@ namespace AppLauncher.Windows.Forms // do nothing } } + + if (string.IsNullOrWhiteSpace(model.Title)) + { + model.Title = Path.GetFileNameWithoutExtension(fileList[0]); + } } listBox1.ListBox.Items.Add(model); diff --git a/Windows/Forms/Tile/TTilePanelLayout.cs b/Windows/Forms/Tile/TTilePanelLayout.cs index 842321d..a161391 100644 --- a/Windows/Forms/Tile/TTilePanelLayout.cs +++ b/Windows/Forms/Tile/TTilePanelLayout.cs @@ -89,6 +89,11 @@ namespace AppLauncher.Windows.Forms // do nothing } } + + if (string.IsNullOrWhiteSpace(model.Title)) + { + model.Title = Path.GetFileNameWithoutExtension(fileList[0]); + } } this.AddTile(model);