using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using IReaper.Command;
namespace IReaper.FileData{
public partial class FileDataGridContextMenu : ContextMenuStrip
{
IList<CourseFileData> files;
public FileDataGridContextMenu()
{
InitializeComponent();
}
public FileDataGridContextMenu(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public IList<CourseFileData> Files
{
get { return files; }
set { files = value; }
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <param name="canPause"></param>
/// <param name="canStart"></param>
/// <param name="canRemove"></param>
private void CheckButtonStatus()
{
bool canPause = false;
bool canStart = false;
bool canRemove = false;
if (files != null)
{
for (int i = 0; i < this.files.Count; i++)
{
CourseFileData file = files[i];
if (file.RunState == RunningStatue.Running ||
file.RunState == RunningStatue.RunQueued ||
file.RunState == RunningStatue.RunRequest)
canPause |= true;
if (file.RunState == RunningStatue.Created ||
file.RunState == RunningStatue.Error ||
file.RunState == RunningStatue.Stopped)
canStart |= true;
}
canRemove = canStart;//
}
this.toolStripMenuItemRemove.Enabled = canRemove;
this.toolStripMenuItemStart.Enabled = canStart;
this.toolStripMenuItemStop.Enabled = canPause;
}
protected override void OnOpening(CancelEventArgs e)
{
this.CheckButtonStatus();
base.OnOpening(e);
}
private void Start(object sender, EventArgs e)
{
CommandBase command = CommandManager.GetCommand(CommandFamily.Command_DownloadFile);
command.ExecuteAsync(this.files, files);
}
private void Stop(object sender, EventArgs e)
{
CommandBase command = CommandManager.GetCommand(CommandFamily.Command_PauseDownload);
command.ExecuteAsync(this.files, files);
}
private void Remove(object sender, EventArgs e)
{
CommandBase command = CommandManager.GetCommand(CommandFamily.Command_RemoveFile);
command.ExecuteAsync(this.files, files,RemoveFileTaskTypeEnum.Incompleted);
}
}
}
|