Exemple #1
0
        private void FreshSelected(FrmEverythingInputInfo info)
        {
            if (_selecting)
            {
                return;
            }

            _selecting = true;
            string exp         = info.ExpInput;
            bool   containPath = info.ContainPath;


            Invoke(_actFreshDvRowCount, new object[] { 0 });

            if (string.IsNullOrWhiteSpace(exp))
            {
                _listSelected = new List <NamePath>();
                if (containPath)
                {
                    _listSelected.AddRange(_listPath);
                }
                _listSelected.AddRange(_listFile);
            }
            else
            {
                _listSelected = new List <NamePath>();

                if (info.UseRegex)
                {
                    Regex regex = new Regex(exp);
                    if (containPath)
                    {
                        _listSelected.AddRange(_listPath.Where(np => regex.IsMatch(np.Name)));
                    }
                    _listSelected.AddRange(_listFile.Where(np => regex.IsMatch(np.Name)));
                }
                else
                {
                    if (containPath)
                    {
                        _listSelected.AddRange(_listPath.Where(np => np.Name.ToUpper().Contains(exp.ToUpper())));
                    }
                    _listSelected.AddRange(_listFile.Where(np => np.Name.ToUpper().Contains(exp.ToUpper())));
                }
            }

            _selected  = true;
            _selecting = false;
            Invoke(_actFreshDvRowCount, new object[] { _listSelected.Count });
        }
Exemple #2
0
        public FrmEverything()
        {
            InitializeComponent();
            //Gets user inputs delegate.
            _funcGetInput = () =>
            {
                FrmEverythingInputInfo i = new FrmEverythingInputInfo();
                i.ContainPath = cbContainPath.Checked;
                i.ExpInput    = tbInput.Text;
                i.UseRegex    = cbRegex.Checked;
                return(i);
            };
            //FreshDvRowCount delegate.
            _actFreshDvRowCount = i =>
            {
                dgView.RowCount = i;
            };
            //Reading finished delegate.
            _actReading = list =>
            {
                _listPath = list.Where(np => np.Path.EndsWith(@"\")).ToList();
                _listFile = list.Where(np => !np.Path.EndsWith(@"\")).ToList();
                FrmEverythingInputInfo info = Invoke(_funcGetInput) as FrmEverythingInputInfo;
                FreshSelected(info);
                lblReadingStatus.Text = @"文件整理完成";
                _readed               = true;
                cbRegex.Enabled       = true;
                cbContainPath.Enabled = true;
            };
            //Exit delegate.
            _actExit = i =>
            {
                MessageBox.Show(@"未能读取文件信息!");
                Close();
            };
            //Read File msgs background.
            new Thread(() =>
            {
                List <NamePath> listNamePath;
                if (DriveHelper.GetNamePathList(out listNamePath))
                {
                    this.Invoke(_actReading, new object[] { listNamePath });
                }
                else
                {
                    this.Invoke(_actExit, new object[] { 0 });
                }
            }).Start();

            _timerSelect          = new System.Timers.Timer(500);
            _timerSelect.Elapsed += (sender, args) =>
            {
                if (!_readed)
                {
                    return;
                }
                if (_selected)
                {
                    return;
                }
                if ((DateTime.Now - _lastSearchInputTime).TotalSeconds < 0.8)
                {
                    return;
                }

                FrmEverythingInputInfo info = Invoke(_funcGetInput) as FrmEverythingInputInfo;
                FreshSelected(info);
            };
            _timerSelect.Start();
        }
Exemple #3
0
        private void cbContainPath_CheckedChanged(object sender, EventArgs e)
        {
            FrmEverythingInputInfo info = Invoke(_funcGetInput) as FrmEverythingInputInfo;

            FreshSelected(info);
        }