Beispiel #1
0
        private void OpenTextFile(SearchResultItemModel searchResultItemModel)
        {
            var factor = ClientSize.Width < Screen.PrimaryScreen.Bounds.Width / 2 ? 1 : 0.5;

            using (var dlg = new TextFileReaderForm(searchResultItemModel))
            {
                dlg.Width = (int)(Width * factor);
                dlg.ShowDialog(this);
            }
        }
 public TextFileReaderForm(SearchResultItemModel searchResultItemModel)
 {
     InitializeComponent();
     Text             = searchResultItemModel.FileName;
     richTextBox.Text = File.ReadAllText(searchResultItemModel.FilePath);
     richTextBox.Find(searchResultItemModel.SearchText, searchResultItemModel.CharIndex, -1, RichTextBoxFinds.WholeWord);
     richTextBox.SelectionBackColor = Color.Yellow;
     richTextBox.SelectionColor     = Color.Black;
     richTextBox.SelectionStart     = searchResultItemModel.CharIndex;
     richTextBox.SelectionLength    = 0;
     richTextBox.ScrollToCaret();
 }
Beispiel #3
0
 public SearchResultItem(SearchResultItemModel searchResult)
 {
     this.searchResult = searchResult;
     InitializeComponent();
     titleLabel.Text         = searchResult.FileName;
     pathLabel.Text          = searchResult.FilePath;
     locationLabel.Text      = $"Line number {searchResult.LineNumber} \t Column {searchResult.ColumnNumber}";
     contextRichTextBox.Text = searchResult.Context;
     contextRichTextBox.Find(searchResult.SearchText, searchResult.WordIndexInContext, -1, RichTextBoxFinds.WholeWord);
     contextRichTextBox.SelectionBackColor = Color.Yellow;
     contextRichTextBox.SelectionColor     = Color.Black;
 }
        private async Task BuildResultListing()
        {
            var models            = new List <SearchResultItemModel>();
            var resultsInfoToShow = LinqExtensions.Skip(searchResults, (currentPage - 1) * ResultsPerPage).Take(ResultsPerPage).ToList();
            var fileIdToPathMap   = await Task.Run(() => folderManager.GetFilePathsFromIds(resultsInfoToShow.Select(x => x.FileId).ToArray()));

            foreach (var resultInfo in resultsInfoToShow)
            {
                if (fileIdToPathMap.TryGetValue(resultInfo.FileId, out string filePath) && File.Exists(filePath))
                {
                    var(context, wordIndexInContext) = await WordContext.GetContext(filePath, searchText, resultInfo.CharIndex);

                    var sr = new SearchResultItemModel
                    {
                        ColumnNumber       = resultInfo.ColumnNumber,
                        LineNumber         = resultInfo.LineNumber,
                        CharIndex          = resultInfo.CharIndex,
                        FileName           = Path.GetFileName(filePath),
                        SearchText         = searchText,
                        FilePath           = filePath,
                        Context            = context,
                        WordIndexInContext = wordIndexInContext
                    };
                    models.Add(sr);
                }
            }


            var factor = resultsPanel.ClientSize.Width < Screen.PrimaryScreen.Bounds.Width / 2 ? 1 : 0.75;

            resultsPanel.SuspendLayout();
            resultsPanel.Controls.Clear();
            foreach (var item in models)
            {
                var srItem = new SearchResultItem(item)
                {
                    Margin = new Padding(8, 0, 0, 8),
                    Width  = (int)(resultsPanel.ClientSize.Width * factor)
                };
                srItem.LinkFollowed += SrItem_LinkFollowed;
                resultsPanel.Controls.Add(srItem);
            }
            resultsPanel.ResumeLayout();
        }
 private void SrItem_LinkFollowed(SearchResultItem sender, SearchResultItemModel searchResult)
 {
     SearchItemClicked?.Invoke(this, searchResult);
 }