Beispiel #1
0
        /// <summary>
        /// Searches the specified key word.
        /// </summary>
        /// <param name="keyWord">The key word.</param>
        /// <param name="token"></param>
        /// <param name="maxCount">The max count.</param>
        /// <param name="searchBoxInfo"></param>
        /// <returns></returns>
        public List <SearchResult> Search(string keyWord, SearchBoxInfo searchBoxInfo, CancellationToken token, int maxCount)
        {
            EverythingNativeApi.Everything_SetSearchW(keyWord);
            if (_maxCount != maxCount)
            {
                EverythingNativeApi.Everything_SetMax(maxCount);
                _maxCount = maxCount;
            }

            token.ThrowIfCancellationRequested();

            if (!EverythingNativeApi.Everything_QueryW(true))
            {
                GetLastError();
            }

            token.ThrowIfCancellationRequested();

            var buffer = new StringBuilder(BufferSize);
            var everythingGetNumResults = EverythingNativeApi.Everything_GetNumResults();
            var resultList = new List <SearchResult>(everythingGetNumResults);

            for (int idx = 0; idx < everythingGetNumResults; ++idx)
            {
                EverythingNativeApi.Everything_GetResultFullPathNameW(idx, buffer, BufferSize);

                var fullPath = buffer.ToString();
                var result   = new SearchResult
                {
                    FullPath = fullPath,
                    ShowPath = _textWidthManager.GetSubStringForWidth(fullPath, searchBoxInfo),
                    Type     = EverythingNativeApi.Everything_IsFolderResult(idx)
                        ? ResultType.Folder
                        : ResultType.File
                };

                result.ImageSource = IconManager.GetImageSource(result.FullPath, result.Type);

                resultList.Add(result);

                token.ThrowIfCancellationRequested();
            }
            return(resultList.OrderBy(item => item.Type).ToList());
        }
        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (!e.WidthChanged)
            {
                return;
            }
            if (ResultListBox.ItemsSource == null)
            {
                return;
            }
            var textWidthManager = new TextWidthManager();

            foreach (SearchResult item in ResultListBox.ItemsSource)
            {
                var searchBoxInfo = new SearchBoxInfo
                {
                    Width    = e.NewSize.Width,
                    FontSize = ResultListBox.FontSize,
                    FontName = ResultListBox.FontFamily.ToString()
                };
                item.ShowPath = textWidthManager.GetSubStringForWidth(item.FullPath, searchBoxInfo);
            }
        }