using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using IReaper;
using IReaper.CourseData;
using IReaper.FileData;
namespace IReaper.CommonGui{
public static class ButtonStatuMonitor
{
static bool download, open, remove, canProperty,canExport;
static CoreDataType dataType = CoreDataType.CurrentSelectedCourses;
static Course course;
static IList<Course> privateCollection = new List<Course>();
/// <summary>
///
/// </summary>
public static Course CurrentCourse
{
set
{
course = value;
UpdateByCourse();
}
get { return course; }
}
/// <summary>
///
/// </summary>
public static CoreDataType DataType
{
get { return dataType; }
set
{
dataType = value;
UpdateByType();
}
}
/// <summary>
/// Remove
/// </summary>
public static bool CanRemove
{
get { return ButtonStatuMonitor.remove; }
}
/// <summary>
/// Opem
/// </summary>
public static bool CanOpen
{
get { return ButtonStatuMonitor.open; }
}
/// <summary>
/// Download
/// </summary>
public static bool CanDownload
{
get { return ButtonStatuMonitor.download; }
}
/// <summary>
/// Property
/// </summary>
public static bool CanProperty
{
get { return ButtonStatuMonitor.canProperty; }
}
/// <summary>
/// Export
/// </summary>
public static bool CanExport
{
get { return ButtonStatuMonitor.canExport; }
}
public static void Init()
{
Core.CoreData.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(CoreData_PropertyChanged);
UpdateByType();
}
private static void CoreData_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == dataType.ToString())
{
UpdateByType();
}
}
/// <summary>
///
/// </summary>
private static void UpdateByCourse()
{
privateCollection.Clear();
privateCollection.Add(course);
Update(privateCollection);
}
/// <summary>
///
/// </summary>
private static void UpdateByType()
{
IList<Course> courses = Core.CoreData[dataType] as IList<Course>;
Update(courses);
}
private static void Update(IList<Course> courses)
{
download = false;
open = false;
remove = false;
canProperty = false;
canExport = false;
if (courses == null)
{
return;
}
foreach (Course c in courses)
{
if (!download)
{
download |= Course.CanDownload(c);
}
if (!remove)
{
remove |= Course.CanRemove(c);
}
if (!canExport)
{
canExport |= Course.CanOpen(c);
}
}
if (courses.Count != 1)
{
open = false;
canProperty = false;
}
else
{
Course c = courses[0];
canProperty = true;
open = Course.CanOpen(c);
}
}
}
}
|