aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Main/ShiftOS/Desktop.cs
blob: 9bfcb0fb0156a526664085931e91e67adf2f7427 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Linq;
using System.Windows.Forms;
using ShiftOS.Engine.Misc;
using ShiftOS.Engine.WindowManager;
using ShiftOS.Main.Properties;
using ShiftOS.Main.ShiftOS.Apps;

namespace ShiftOS.Main.ShiftOS
{
	public partial class Desktop : Form
	{
		public Desktop()
		{
			InitializeComponent();

			timer1.Start();

			Closed += (sender, args) => { Application.Exit(); };

			#region Disgusting taskbar code

			ShiftWm.Windows.CollectionChanged += (sender, args) =>
			{
				args.NewItems?.OfType<ShiftWindow>()
				    .ToList()
				    .ForEach(
					    window =>
					    {
						    taskbar.Invoke(
							    new Action(
								    () =>
								    {
									    taskbar.Items.Add(
										    new ToolStripButton
										    {
											    Text = window.Title.Text,
											    Image = window.Icon.ToBitmap(),
											    Tag = window.Id
										    });
								    }));
					    });

				args.OldItems?.OfType<ShiftWindow>()
				    .ToList()
				    .ForEach(
					    window =>
					    {
						    taskbar.Invoke(
							    new Action(
								    () =>
								    {
									    var tbRemovalList = taskbar.Items.OfType<ToolStripItem>().Where(i => (uint) i.Tag == window.Id);

									    tbRemovalList.ToList().ForEach(p => taskbar.Items.Remove(p));
								    }));
					    });
			};

			#endregion
		}

		void timer1_Tick(object sender, EventArgs e) =>
			taskbarClock.Text = $"{DateTime.Now:t}";

		void terminalToolStripMenuItem_Click(object sender, EventArgs e)
		{
			var trm = new Terminal();

			ShiftWm.Init(trm, "Terminal", null);
		}

		void textPadToolStripMenuItem_Click(object sender, EventArgs e)
		{
			var tp = new TextPad();
			ShiftWm.Init(tp, "TextPad", Resources.iconTextPad.ToIcon());
		}
	}
}