FileViewToolStrip.cs :  » Network-Clients » iReaper » IReaper » CommonGui » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » iReaper 
iReaper » IReaper » CommonGui » FileViewToolStrip.cs
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using IReaper.CourseData;
using IReaper.FileData;
using IReaper.Command;
using System.Threading;

namespace IReaper.CommonGui{
    public partial class FileViewToolStrip : ToolStrip
    {
        public FileViewToolStrip()
        {
            InitializeComponent();

        }

        public FileViewToolStrip(IContainer container)
        {
            container.Add(this);

            InitializeComponent();

            CustomInit();
        }

        private void CustomInit()
        {
            Core.CoreData.PropertyChanged += new PropertyChangedEventHandler(CoreComponent_PropertyChanged);
            CourseFileData.RLChanged += new EventHandler(CourseFileData_LifetimeChanged);
            // Load strip image
            // Pause
            this.toolStripBPause.Image = global::IReaper.Properties.Resources.Stop;
            this.toolStripBPauseAll.Image = global::IReaper.Properties.Resources.StopAll;
            // Remove
            this.toolStripBRemove.Image = global::IReaper.Properties.Resources.Clear;
            this.toolStripBRemoveAll.Image = global::IReaper.Properties.Resources.ClearAll;
            // Run
            this.toolStripBStart.Image = global::IReaper.Properties.Resources.Run;
            this.toolStripBStartAll.Image = global::IReaper.Properties.Resources.RunAll;

            // Load button enable
            UpdateButton();
        }

        void CourseFileData_LifetimeChanged(object sender, EventArgs e)
        {
            UpdateButton();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CoreComponent_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            /* 
             * 
             */
            if (e.PropertyName == CoreDataType.CurrentSelectedFiles.ToString() || e.PropertyName == CoreDataType.CurrentViewedFiles.ToString())
            {
                UpdateButton();
            }
            
        }

        /// <summary>
        /// Update single file operation buttons stats
        /// </summary>
        private void UpdateButton()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new ThreadStart(UpdateButton));
                return;
            }
            IList<CourseFileData> files = Core.CoreData[CoreDataType.CurrentSelectedFiles] as IList<CourseFileData>;
            bool canStart, canPause, canRemove;
            this.CheckButtonStatus(files, out canPause, out canStart, out canRemove);

            files = Core.CoreData[CoreDataType.CurrentViewedFiles] as IList<CourseFileData>;
            bool canStartAll, canPauseAll, canRemoveAll;
            this.CheckButtonStatus(files, out canPauseAll, out canStartAll, out canRemoveAll);
            this.BeginInvoke(new System.Threading.ThreadStart(delegate()
            {
                this.toolStripBPause.Enabled = canPause;
                this.toolStripBStart.Enabled = canStart;
                this.toolStripBRemove.Enabled = canRemove;
                this.toolStripBPauseAll.Enabled = canPauseAll;
                this.toolStripBStartAll.Enabled = canStartAll;
                this.toolStripBRemoveAll.Enabled = canRemoveAll;
            }));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="canPause"></param>
        /// <param name="canStart"></param>
        /// <param name="canRemove"></param>
        private void CheckButtonStatus(IList<CourseFileData> data, out bool canPause, out bool canStart, out bool canRemove)
        {
            canPause = false;
            canStart = false;
            canRemove = false;
            if (data == null)
            {
                return;
            }
            for (int i = 0; i < data.Count; i++)
            {
                CourseFileData file = data[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;//
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PauseDownload(object sender, EventArgs e)
        {
            CourseFileDataCollection files = this.GetPredictedFiles(sender);
            CommandBase command = CommandManager.GetCommand(CommandFamily.Command_PauseDownload);
            command.ExecuteAsync(this, files);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartDownload(object sender, EventArgs e)
        {
            CourseFileDataCollection files = this.GetPredictedFiles(sender);
            CommandBase command = CommandManager.GetCommand(CommandFamily.Command_DownloadFile);
            command.ExecuteAsync(this, files);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoveDownload(object sender, EventArgs e)
        {
            CourseFileDataCollection files = this.GetPredictedFiles(sender);
            CommandBase command = CommandManager.GetCommand(CommandFamily.Command_RemoveFile);
            command.ExecuteAsync(this,files,RemoveFileTaskTypeEnum.Incompleted);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private CourseFileDataCollection GetPredictedFiles(object sender)
        {
            ToolStripItem item = sender as ToolStripItem;
            string tagMessage;
            CourseFileDataCollection files = null;
            if (item == null)
            {
                tagMessage = null;
            }
            else
            {
                tagMessage = item.Tag as string;
            }

            if (tagMessage == "All")
            {
                files = ((CourseFileDataCollection)Core.CoreData[CoreDataType.CurrentViewedFiles]);
            }
            else
            {
                files = ((CourseFileDataCollection)Core.CoreData[CoreDataType.CurrentSelectedFiles]);
            }
            return files;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.