Ejemplo n.º 1
0
        private void ProjectTypePopulation(ProjectTypeCellEditor editor)
        {
            // retrieve current row
            int row = editor.EditingCellPos.Row;

            // retrieve current folder path
            string folder = tableModel.Rows[row].Cells[1].Text;

            bool hasCache = Detector.Current.HasExtCache(folder);
            if (!hasCache)
            {
                // create waiting item, to signal progress
                ProjecTypeItem wait = new ProjecTypeItem();
                wait.Text = "Scanning";
                wait.Description = "Wait please ...";
                wait.ImageIndex = -1;
                wait.Mark = true;
                wait.ForeColor = Color.Red;
                editor.Items.Clear();
                editor.Items.Add(wait);
            }

            // cancel previous worker if running
            if (detectorWorker!=null)
            {
                DetectorCancel();
            }

            // create a background worker thread that ReportsProgress & SupportsCancellation
            // hook up the appropriate events.
            DetectorData detectorData = new DetectorData(folder, editor);

            detectorWorker = new BackgroundWorker();
            detectorWorker.WorkerReportsProgress = true;
            detectorWorker.WorkerSupportsCancellation = true;
            detectorWorker.ProgressChanged += new ProgressChangedEventHandler(DetectorProgressChanged);
            detectorWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(DetectorWorkerCompleted);
            detectorWorker.DoWork += new DoWorkEventHandler(DetectorDoWork);
            Detector.Current.currentWorker = detectorWorker;
            detectorDatas.Add(detectorWorker, detectorData);
            if (!hasCache)
            {
                detectorWorker.RunWorkerAsync();
            }
            else
            {
                // we have cache, so do operation synchronously, to prevent UI blinking
                DetectorDoWork(detectorWorker, new DoWorkEventArgs(null));
                DetectorWorkerCompleted(detectorWorker, new RunWorkerCompletedEventArgs(null, null, false));
            }
        }
Ejemplo n.º 2
0
 public int ProjectTypeComparer(ProjecTypeItem a, ProjecTypeItem b)
 {
     return a.Text.ToString().CompareTo(b.Text.ToString());
 }
Ejemplo n.º 3
0
        private void DetectorDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                // The sender is the BackgroundWorker object we need it to
                // report progress and check for cancellation.
                BackgroundWorker worker = sender as BackgroundWorker;

                DetectorData detectorData = detectorDatas[sender];

                // build list of project types using scanners
                List<ProjecTypeItem> recommendedTypes = new List<ProjecTypeItem>();
                List<ProjecTypeItem> otherTypes = new List<ProjecTypeItem>();

                foreach (Scanner scanner in Detector.Current.scanners)
                {
                    bool isRecommended = scanner.Scan(detectorData.folder);

                    ProjecTypeItem item = new ProjecTypeItem();
                    item.Text = scanner.GetName();
                    item.Description = scanner.GetDescription();
                    item.ImageIndex = scanner.GetImageIndex();
                    item.Mark = true;
                    item.ForeColor = isRecommended ? Color.Black : Color.Gray;

                    if (isRecommended)
                        recommendedTypes.Add(item);
                    else
                        otherTypes.Add(item);
                }

                // enable separator lines
                if (recommendedTypes.Count > 0)
                    recommendedTypes[recommendedTypes.Count - 1].Separator = true;
                if (otherTypes.Count > 0)
                    otherTypes[otherTypes.Count - 1].Separator = true;

                // add lists into listbox
                detectorData.items.AddRange(recommendedTypes.ToArray());
                detectorData.items.AddRange(otherTypes.ToArray());

                ProjecTypeItem custom = new ProjecTypeItem();
                custom.Text = "Custom";
                custom.Description = "Custom settings";
                custom.ImageIndex = 0;
                custom.Mark = true;
                custom.ForeColor = Color.Blue;
                detectorData.items.Add(custom);
            }
            catch (CancelException)
            {
                e.Cancel = true;
            }
        }