This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/MainForm.cs

236 lines
6.6 KiB
C#
Raw Normal View History

2020-04-11 17:43:20 +00:00
using AppLauncher.Models;
using AppLauncher.Windows.Forms;
using Newtonsoft.Json;
2020-03-28 02:54:08 +00:00
using System;
2020-03-27 23:16:34 +00:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
2020-03-30 10:48:24 +00:00
using System.Diagnostics;
2020-03-27 23:16:34 +00:00
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
2020-04-11 17:43:20 +00:00
using System.IO;
2020-03-27 23:16:34 +00:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppLauncher
{
2020-03-28 02:54:08 +00:00
public partial class MainForm : AForm
2020-03-27 23:16:34 +00:00
{
2020-04-12 00:12:21 +00:00
protected int collapsedWidth = 40;
protected int expandedWidth = 800;
2020-03-27 23:16:34 +00:00
2020-03-28 02:54:08 +00:00
public MainForm() : base()
2020-03-27 23:16:34 +00:00
{
InitializeComponent();
}
2020-05-02 16:17:10 +00:00
//protected override void OnLoad(EventArgs e)
//{
// base.OnLoad(e);
//}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
string jsonfigFilename = Path.ChangeExtension(Application.ExecutablePath, "jsonfig");
if (File.Exists(jsonfigFilename))
{
loadSession(jsonfigFilename);
}
}
2020-04-05 00:32:49 +00:00
private async void button1_Click(object sender, EventArgs e)
2020-03-29 14:28:38 +00:00
{
2020-04-12 00:12:21 +00:00
//if (this.Width > collapsedWidth)
//{
// await collapseWindow(collapsedWidth, 6);
//}
//else
//{
// await expandWindow(expandedWidth, 8);
//}
2020-03-29 14:28:38 +00:00
}
2020-03-30 10:48:24 +00:00
private void button2_Click(object sender, EventArgs e)
{
2020-04-11 17:43:20 +00:00
//List<TileGroupModel> groupList = new List<TileGroupModel>();
//TileGroupModel group1 = new TileGroupModel()
//{
// Title = "Featured",
// IsExpanded = true,
// Items = new List<TileModel>(),
// GridSize = new Size(8, 2)
//};
//group1.Items.Add(new TileModel()
//{
// Title = "CubicExplorer",
// Icon = null,
// Position = new Point(0, 0),
// ProcessFilename = @"C:\B\Portable Files\CubicExplorer\v0.95.1\CubicExplorer.exe",
// ProcessWorkingDirectory = @"N:\D"
//});
//group1.Items.Add(new TileModel()
//{
// Title = "VeraCrypt",
// Icon = null,
// Position = new Point(1, 0),
// ProcessFilename = @"C:\B\Portable Files\VeraCrypt\VeraCrypt-x64.exe",
// ProcessWorkingDirectory = @"L:\"
//});
//groupList.Add(group1);
//File.WriteAllText(Application.StartupPath.TrimEnd('\\') + "\\test1.jsonfig", JsonConvert.SerializeObject(groupList));
2020-04-05 00:32:49 +00:00
//ProcessStartInfo process = new ProcessStartInfo();
//process.FileName = @"C:\B\Portable Files (pure)\Build and Deploy Utility\v0.2.0.046 alpha\badutil.exe";
//process.Arguments = "";
//process.WindowStyle = ProcessWindowStyle.Normal;
//process.Verb = "runas";
//Process.Start(process);
//richTextBox1.Text += tilePanelContainer1.GridSize.ToString() + Environment.NewLine;
2020-04-11 17:43:20 +00:00
//tilePanelContainer1.Controls.Add(tilePanel1);
//tilePanel1.Location = new Point(0, 0);
2020-04-05 00:32:49 +00:00
2020-04-11 17:43:20 +00:00
//tilePanelContainer1.Controls.Add(tilePanel2);
//tilePanel2.Location = new Point(0, 0);
2020-04-05 00:32:49 +00:00
2020-03-30 10:48:24 +00:00
}
2020-04-12 00:12:21 +00:00
public async Task ToggleSize()
{
if (this.Width > collapsedWidth)
{
flowLayoutPanel1.Visible = false;
titlePanel1.LabelVisible = false;
await collapseWindow(collapsedWidth, 6);
}
else
{
await expandWindow(expandedWidth, 8);
flowLayoutPanel1.Visible = true;
titlePanel1.LabelVisible = true;
}
}
protected async Task collapseWindow(int width, int increment = 6)
2020-04-05 00:32:49 +00:00
{
await Task.Run(() =>
{
while (this.Width > width)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Width -= increment;
}));
}
else
{
this.Width -= increment;
}
Application.DoEvents();
}
});
}
2020-03-27 23:16:34 +00:00
2020-04-05 00:32:49 +00:00
protected async Task expandWindow(int width, int increment = 8)
{
await Task.Run(() =>
{
while (this.Width < width)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Width += increment;
2020-04-12 00:12:21 +00:00
//this.Invalidate();
2020-04-05 00:32:49 +00:00
}));
}
else
{
this.Width += increment;
2020-04-12 00:12:21 +00:00
//this.Invalidate();
2020-04-05 00:32:49 +00:00
}
2020-03-27 23:16:34 +00:00
2020-04-05 00:32:49 +00:00
Application.DoEvents();
}
});
}
2020-03-27 23:16:34 +00:00
2020-04-12 00:12:21 +00:00
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
this.TopMost = !this.TopMost;
toolStripMenuItem1.Checked = this.TopMost;
}
2020-04-11 17:43:20 +00:00
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
2020-03-27 23:16:34 +00:00
2020-05-02 16:17:10 +00:00
protected async void loadSession(string filename)
2020-04-11 17:43:20 +00:00
{
string sourceCode = File.ReadAllText(filename);
if (string.IsNullOrWhiteSpace(sourceCode))
{
return;
}
List<TileGroupModel> rs = JsonConvert.DeserializeObject<List<TileGroupModel>>(sourceCode);
if (rs == null)
{
return;
}
flowLayoutPanel1.Controls.Clear();
2020-03-27 23:16:34 +00:00
2020-04-11 17:43:20 +00:00
foreach (TileGroupModel item in rs)
{
TileContainer panel = new TileContainer(item);
flowLayoutPanel1.Controls.Add(panel);
2020-05-02 16:17:10 +00:00
if (item.IsExpanded)
{
//await panel.Expand();
}
2020-04-11 17:43:20 +00:00
}
}
2020-03-27 23:16:34 +00:00
2020-04-11 17:43:20 +00:00
private void button3_Click(object sender, EventArgs e)
{
2020-05-02 16:17:10 +00:00
// loadSession(Application.StartupPath.TrimEnd('\\') + "\\test1.jsonfig");
2020-03-27 23:16:34 +00:00
2020-04-11 17:43:20 +00:00
}
2020-04-12 00:12:21 +00:00
2020-04-27 12:17:13 +00:00
private void button1_Click_1(object sender, EventArgs e)
{
EditTileForm addTileForm = new EditTileForm();
addTileForm.ShowDialog();
}
2020-03-27 23:16:34 +00:00
}
}