mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
GUI桌面环境
This commit is contained in:
82
Gui/Apps/Tasks.cs
Normal file
82
Gui/Apps/Tasks.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using CMLeonOS;
|
||||
using CMLeonOS.Gui.UILib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CMLeonOS.Gui.Apps
|
||||
{
|
||||
internal class Tasks : Process
|
||||
{
|
||||
internal Tasks() : base("Tasks", ProcessType.Application) { }
|
||||
|
||||
AppWindow window;
|
||||
|
||||
Table table;
|
||||
|
||||
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
|
||||
|
||||
int lastSecond = DateTime.Now.Second;
|
||||
|
||||
private void PopulateTable()
|
||||
{
|
||||
table.Cells.Clear();
|
||||
foreach (Process process in ProcessManager.Processes)
|
||||
{
|
||||
table.Cells.Add(new TableCell(process.Name));
|
||||
}
|
||||
table.Render();
|
||||
}
|
||||
|
||||
private void EndTaskClicked(int x, int y)
|
||||
{
|
||||
if (table.SelectedCellIndex != -1 && table.SelectedCellIndex < ProcessManager.Processes.Count)
|
||||
{
|
||||
if (UserSystem.CurrentLoggedInUser == null || !UserSystem.CurrentLoggedInUser.Admin)
|
||||
{
|
||||
MessageBox messageBox = new MessageBox(this, Name, "You must be an admin to end tasks.");
|
||||
messageBox.Show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessManager.Processes[table.SelectedCellIndex].TryStop();
|
||||
ProcessManager.Sweep();
|
||||
table.SelectedCellIndex = -1;
|
||||
PopulateTable();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
window = new AppWindow(this, 256, 256, 384, 256);
|
||||
wm.AddWindow(window);
|
||||
window.Title = "Tasks";
|
||||
window.Icon = AppManager.GetAppMetadata("Tasks").Icon;
|
||||
window.Closing = TryStop;
|
||||
|
||||
window.Clear(Color.Gray);
|
||||
|
||||
table = new Table(window, 12, 12, window.Width - 24, window.Height - 24 - 20 - 12);
|
||||
PopulateTable();
|
||||
wm.AddWindow(table);
|
||||
|
||||
Button endTask = new Button(window, window.Width - 100 - 12, window.Height - 20 - 12, 100, 20);
|
||||
endTask.Text = "End Task";
|
||||
endTask.OnClick = EndTaskClicked;
|
||||
wm.AddWindow(endTask);
|
||||
|
||||
wm.Update(window);
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
if (lastSecond != now.Second)
|
||||
{
|
||||
PopulateTable();
|
||||
lastSecond = now.Second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user