public TaskDialog(Task task = null) { InitializeComponent(); if (task != null) WindowUtils.ConnectTask(this, task); }
public TaskDialog(Task task = null) { XML gxml = new XML(null, "MultiMC.GTKGUI.TaskDialog.glade", "vboxTask", null); gxml.Autoconnect(this); this.Remove(this.VBox); this.Add(vboxTask); WidthRequest = 400; HeightRequest = 110; if (task != null) WindowUtils.ConnectTask(this, task); }
public static void ConnectTask(this ITaskDialog dlg, Task task) { task.ProgressChange += (o, args) => dlg.Invoke((o2, args2) => dlg.TaskProgress = args.Progress); task.StatusChange += (o, args) => dlg.Invoke((o2, args2) => dlg.TaskStatus = args.Status); task.Completed += (o, args) => dlg.Invoke((o2, args2) => dlg.Close()); dlg.TaskStatus = task.Status; dlg.TaskProgress = task.Progress; }
void TaskStatusChange(object sender, Task.TaskStatusEventArgs e) { Invoke((o, args) => { (taskProgBars[e.TaskID].Children[0] as ProgressBar). Text = e.Status; }); }
void TaskRemoved(Task task) { if (!taskProgBars.ContainsKey(task.TaskID)) return; ProgressBar pbar = taskProgBars[task.TaskID].Children[0] as ProgressBar; pbar.Fraction = 1; pbar.Hide(); mainVBox.Remove(taskProgBars[task.TaskID]); lock (this) { taskProgBars.Remove(task.TaskID); } }
void TaskProgressChange(object sender, Task.ProgressChangeEventArgs e) { Invoke((o, args) => { double pbarFraction = (float)e.Progress / 100f; if (pbarFraction > 1.0) pbarFraction = 1; (taskProgBars[e.TaskID].Children[0] as ProgressBar). Fraction = pbarFraction; }); }
void TaskAdded(Task task) { if (taskProgBars.ContainsKey(task.TaskID)) task.TaskID = GetAvailableTaskID(); HBox tHBox = new HBox(); ProgressBar tProgBar = new ProgressBar(); tProgBar.Text = task.Status; tProgBar.HeightRequest = 22; tHBox.PackStart(tProgBar, true, true, 0); task.StatusChange += TaskStatusChange; task.ProgressChange += TaskProgressChange; lock (this) { taskProgBars.Add(task.TaskID, tHBox); } progBarVBox.PackEnd(tHBox, false, true, 0); tHBox.ShowAll(); }
void TaskAdded(Task task) { if (InvokeRequired) { Invoke((o, args) => TaskAdded(task)); } else { if (!task.Running) { task.Started += (o, args) => { AddTaskStatusBar(task); }; } else AddTaskStatusBar(task); task.Completed += (o, args) => { Console.WriteLine("Task {0} completed.", task.TaskID); RemoveTaskStatusBar(task); }; } }
void RemoveTaskStatusBar(Task task) { if (InvokeRequired) { Invoke((o, args) => RemoveTaskStatusBar(task)); return; } if (toolStripContainer.BottomToolStripPanel.Controls.Contains(statusStrips[task.TaskID])) toolStripContainer.BottomToolStripPanel.Controls.Remove(statusStrips[task.TaskID]); }
void AddTaskStatusBar(Task task) { if (InvokeRequired) { Invoke((o, args) => AddTaskStatusBar(task)); return; } // Status strip StatusStrip taskStatusStrip = new StatusStrip(); statusStrips[task.TaskID] = taskStatusStrip; taskStatusStrip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; taskStatusStrip.AutoSize = true; taskStatusStrip.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow; taskStatusStrip.SizingGrip = false; // Status label ToolStripStatusLabel statusLabel = new ToolStripStatusLabel(task.Status); statusLabel.Name = "status"; statusLabel.AutoSize = true; task.StatusChange += (o, args) => UpdateStatusLabel(statusLabel, args.Status); statusLabel.Text = task.Status; statusLabel.Visible = true; taskStatusStrip.Items.Add(statusLabel); // Progress bar ToolStripProgressBar progBar = new ToolStripProgressBar("progress"); progBar.Alignment = ToolStripItemAlignment.Right; progBar.Size = new Size(100, 16); task.ProgressChange += (o, args) => UpdateProgBar(progBar, args.Progress); UpdateProgBar(progBar, task.Progress); progBar.Visible = true; taskStatusStrip.Items.Add(progBar); // Add the status bar toolStripContainer.BottomToolStripPanel.Controls.Add(taskStatusStrip); taskStatusStrip.Visible = true; }