//double click internal void OpenResultShowPreview(object src, EventArgs args) { ResultItem resultLine = dictResultItems[(TreeViewItem)src]; FindSettings settings = dictSearchSettings[(TreeViewItem)src]; OpenDocShowPreview(resultLine, settings, true); }
//preview on MouseUp public void PreviewResultDoc(object src, EventArgs args) { ResultItem resultLine = dictResultItems[(TreeViewItem)src]; FindSettings settings = dictSearchSettings[(TreeViewItem)src]; RichTextBox tbPreview = dictTBPreview[settings]; tbPreview.Document.Blocks.Clear(); EnvDTE.Document document = GetDocumentByPath(resultLine.linePath); //It document exists in VS memory if (document != null) { EnvDTE.TextSelection selection = GetSelection(document); FillPreviewFromDocument(tbPreview.Document.Blocks, selection, resultLine); SelectOffsetLength(selection, resultLine); } else { FillPreviewFromFile(tbPreview.Document.Blocks, resultLine); } }
internal void MoveResultToFlatTreeList(TreeView tvResultFlatTree, FindSettings last_searchSetting, RichTextBox tbPreview, List <ResultItem> resultList, bool partialMode = true) { List <ResultItem> tmp = new List <ResultItem>(); string content = ""; foreach (ResultItem resultItem in resultList) { tmp.Add(resultItem.GetCopy()); } TreeViewItem treeItem; dictTVData[tvResultFlatTree] = new TVData() { longDir = GetSolutionFullName() }; if (!partialMode) { tvResultFlatTree.Items.Clear(); } foreach (ResultItem resultItem in resultList) { treeItem = GetTVItemByFilePath(tvResultFlatTree.Items, resultItem.linePath); content = resultItem.lineContent.Trim(); if (treeItem == null) { treeItem = new TreeViewItem() { Header = resultItem.linePath, FontWeight = FontWeights.Bold }; tvResultFlatTree.Items.Add(treeItem); } treeItem.Items.Add(AddLeafItem(resultItem)); } SetExpandAllInLvl(tvResultFlatTree.Items, true); this.Focusable = false; }
private void CopyItems(ItemCollection src, ItemCollection dst, FindSettings findSettings, RichTextBox tbPreview) { foreach (TreeViewItem item in src) { TreeViewItem newItem = new TreeViewItem() { Header = item.Header }; dst.Add(newItem); dictSearchSettings.Add(newItem, findSettings); //only leafs if (item.Items.Count == 0) { newItem.MouseDoubleClick += OpenResultShowPreview; newItem.MouseUp += PreviewResultDoc; newItem.MouseRightButtonUp += ShowResultTreeContextMenu; dictResultItems.Add(newItem, dictResultItems[item].GetCopy()); } newItem.FontWeight = item.FontWeight; //FontWeights.Bold - FontWeights is a static class, so it's ok CopyItems(item.Items, newItem.Items, findSettings, tbPreview); } }
//Preview internal EnvDTE.TextSelection OpenDocShowPreview(ResultItem resultLine, FindSettings settings, bool focus = true) { EnvDTE.TextSelection selection = null; if (Dte != null) { EnvDTE.Window docWindow = Dte.ItemOperations.OpenFile(resultLine.linePath, Constants.vsViewKindTextView); selection = GetSelection(Dte.ActiveDocument); if (selection != null) { selection.SelectAll(); int lastLine = selection.CurrentLine; FillPreviewFromDocument(dictTBPreview[settings].Document.Blocks, selection, resultLine); SelectOffsetLength(selection, resultLine); /* if (settings.chkRegExp == true) * Debug.Assert(false, "Brak obsługi RegExp"); * else * { * selection.MoveToLineAndOffset(resultLine.lineNumber.Value, resultLine.resultOffset + 1, false); * selection.MoveToLineAndOffset(resultLine.lineNumber.Value, resultLine.resultOffset + 1 + resultLine.ResultLength, true); * }*/ //Add action to set focus no doc window after finishing all action in queue (currenty there should be only double click event) if (focus) { Action showAction = () => docWindow.Activate(); this.Dispatcher.BeginInvoke(showAction); } } } else { Debug.Assert(false, "Brak DTE"); } return(selection); }
internal void FillWraperPanel(FindSettings settings, WrapPanel infoWrapPanel) { infoWrapPanel.Children.Clear(); AddLabel("`" + settings.tbPhrase + "`", infoWrapPanel); //separator AddExtraBold(AddLabel(" | ", infoWrapPanel)); //WholeWord if (settings.chkWholeWord) { AddExtraBold(AddLabel("W", infoWrapPanel)); } else { AddLabel("w", infoWrapPanel); } //Form if (settings.chkForm) { AddExtraBold(AddLabel("F", infoWrapPanel)); } else { AddLabel("f", infoWrapPanel); } //CharCase if (settings.chkCase) { AddExtraBold(AddLabel("C", infoWrapPanel)); } else { AddLabel("c", infoWrapPanel); } //RegExp if (settings.chkRegExp) { AddExtraBold(AddLabel("R", infoWrapPanel)); } else { AddLabel("r", infoWrapPanel); } //separator AddExtraBold(AddLabel(" | ", infoWrapPanel)); if (settings.rbCurrDoc) { AddLabel("CurDocum", infoWrapPanel); } else if (settings.rbOpenDocs) { AddLabel("Opened", infoWrapPanel); } else if (settings.rbProject) { AddLabel("Project", infoWrapPanel); } else if (settings.rbSolution) { AddLabel("Solution", infoWrapPanel); } else if (settings.rbLocation) { AddLabel(settings.tbLocation, infoWrapPanel); AddExtraBold(AddLabel(" | ", infoWrapPanel)); AddLabel(settings.tbfileFilter, infoWrapPanel); AddExtraBold(AddLabel(" | ", infoWrapPanel)); AddLabel(settings.chkSubDir.ToString(), infoWrapPanel); } else if (settings.rbLastResults) { AddLabel("LastRes", infoWrapPanel); } }
internal void MoveResultToTreeList(TreeView tvResultTree, FindSettings last_searchSettings, RichTextBox tbPreview, List <ResultItem> resultList, bool partialMode = true) { List <ResultItem> tmp = new List <ResultItem>(); foreach (ResultItem resultItem in resultList) { tmp.Add(resultItem.GetCopy()); } ItemCollection treeItemColleaction; string pathAgg; TreeViewItem treeItem; dictTVData[tvResultTree] = new TVData() { longDir = GetSolutionFullName() }; if (!partialMode) { tvResultTree.Items.Clear(); } foreach (ResultItem resultItem in resultList) { treeItemColleaction = tvResultTree.Items; treeItem = null; pathAgg = ""; for (int i = 0; i < resultItem.PathPartsList.Count; i++) { if (pathAgg == "") { pathAgg = resultItem.PathPartsList[i]; } else { pathAgg = pathAgg + @"\" + resultItem.PathPartsList[i]; } if (Directory.Exists(pathAgg) || File.Exists(pathAgg)) { treeItem = GetTVItemByFilePath(treeItemColleaction, resultItem.PathPartsList[i]); if (treeItem == null) { treeItem = new TreeViewItem() { Header = resultItem.PathPartsList[i], FontWeight = FontWeights.Bold }; treeItemColleaction.Add(treeItem); } treeItemColleaction = treeItem.Items; } if (i == resultItem.PathPartsList.Count - 1) { treeItemColleaction.Add(AddLeafItem(resultItem)); } } } if (!partialMode) { foreach (TreeViewItem tmpItem in tvResultTree.Items) { JoinNodesWOLeafs(tmpItem); } } SetExpandAllInLvl(tvResultTree.Items, true); }
private void AddSmapshotTab(string infoContent) { string snapshotNumber = (tbcMain.Items.Count - 2).ToString(); string snapshotTag = GetSnapshotTag(snapshotNumber); //new tab TabItem newTab = new TabItem() { Name = "tbi" + snapshotTag, Header = "Snap " + (tbcMain.Items.Count - 2).ToString(), }; //add new tab tbcMain.Items.Add(newTab); //add main grid in tab and row definitions Grid grid = new Grid() { Background = this.FindResource(SystemColors.ControlLightBrushKey) as Brush }; grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(20, GridUnitType.Pixel) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30, GridUnitType.Pixel) }); RowDefinition rowFlat = new RowDefinition() { Name = snapshotTag + "_rowFlat", Height = new GridLength(1, GridUnitType.Star) }; grid.RowDefinitions.Add(rowFlat); RowDefinition rowTree = new RowDefinition() { Name = snapshotTag + "_rowTree", Height = new GridLength(0, GridUnitType.Pixel) }; grid.RowDefinitions.Add(rowTree); grid.RowDefinitions.Add(new RowDefinition() { Name = snapshotTag + "_preview", Height = new GridLength(100, GridUnitType.Pixel) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(20, GridUnitType.Pixel) }); //add grid as the main element in tab newTab.Content = grid; //Set snapshot tab as selected //tbcMain.SelectedItem = newTab; //Info Wraper WrapPanel infoWrapPanel = new WrapPanel() { Orientation = Orientation.Horizontal, Name = snapshotTag + "_infoWrapPanel", VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; grid.Children.Add(infoWrapPanel); Grid.SetRow(infoWrapPanel, 0); Grid.SetColumn(infoWrapPanel, 0); FillWraperPanel(lastSearchSettings, infoWrapPanel); //navigator Grid navGrid = new Grid() { Background = this.FindResource(SystemColors.ControlLightBrushKey) as Brush, }; navGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); navGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(33, GridUnitType.Pixel) }); grid.Children.Add(navGrid); Grid.SetRow(navGrid, 1); //upper menu wrap panel WrapPanel upperMenuWrapPanel = new WrapPanel() { Orientation = Orientation.Horizontal, Name = snapshotTag + "upperMenuWrapPanel", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left }; navGrid.Children.Add(upperMenuWrapPanel); Grid.SetColumn(upperMenuWrapPanel, 0); //toggle button Flat/Tree ToggleButton tbFlatTree = new ToggleButton() { HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5, 0, 0, 0), Padding = new Thickness(3, 1, 3, 1), Width = 34, BorderBrush = this.FindResource(SystemColors.ControlDarkBrushKey) as Brush, Height = 21, Content = "Tree" }; tbFlatTree.Click += (o, e) => { ToggleButton tb = o as ToggleButton; if (tb.IsChecked == false) { rowFlat.Height = new GridLength(1, GridUnitType.Star); rowTree.Height = new GridLength(0, GridUnitType.Pixel); tb.ClearValue(ToggleButton.ForegroundProperty); } else { rowFlat.Height = new GridLength(0, GridUnitType.Pixel); rowTree.Height = new GridLength(1, GridUnitType.Star); tb.Foreground = Brushes.Red; } }; upperMenuWrapPanel.Children.Add(tbFlatTree); //Button Expand all Button btnExpAll = new Button() { Name = snapshotTag + "_ExpAll", Width = 21, Height = 21, Content = "+", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0), FontWeight = FontWeights.Bold, FontSize = 18, Padding = new Thickness(0, -5, 0, 0) }; upperMenuWrapPanel.Children.Add(btnExpAll); //Button UnExpand all Button btnUnExpAll = new Button() { Name = snapshotTag + "_UnExpAll", Width = 21, Height = 21, Content = "-", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0), FontWeight = FontWeights.Bold, FontSize = 18, Padding = new Thickness(0, -5, 0, 0) }; upperMenuWrapPanel.Children.Add(btnUnExpAll); //toggle button Flat/Tree ToggleButton tbShortDir = new ToggleButton() { HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5, 0, 0, 0), Padding = new Thickness(3, 1, 3, 1), Width = 40, BorderBrush = this.FindResource(SystemColors.ControlDarkBrushKey) as Brush, Height = 21, Content = "Short" }; upperMenuWrapPanel.Children.Add(tbShortDir); //Button Find again Button btnFindAgain = new Button() { Content = "Find again", HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(15, 0, 0, 0), Padding = new Thickness(2, 0, 2, 0), Height = 21 }; upperMenuWrapPanel.Children.Add(btnFindAgain); //Button Save Button btnSave = new Button() { Content = "save", HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5, 0, 0, 0), Padding = new Thickness(2, 0, 2, 0), Height = 21 }; upperMenuWrapPanel.Children.Add(btnSave); //Button remove snapshot Button btnRemoveSnapshot = new Button() { Content = "X", Foreground = Brushes.Red, HorizontalAlignment = HorizontalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontWeight = FontWeights.Bold, Margin = new Thickness(5, 0, 0, 0), Height = 21, Width = 21 }; navGrid.Children.Add(btnRemoveSnapshot); Grid.SetColumn(btnRemoveSnapshot, 1); //add Flat view TreeView flattv = new TreeView() { Name = snapshotTag + "_tvResultFlatTree", HorizontalContentAlignment = HorizontalAlignment.Stretch }; grid.Children.Add(flattv); Grid.SetRow(flattv, 2); Grid.SetColumnSpan(flattv, 1); //add Tree view TreeView treetv = new TreeView() { Name = snapshotTag + "_tvResultFlatTree", HorizontalContentAlignment = HorizontalAlignment.Stretch }; grid.Children.Add(treetv); Grid.SetRow(treetv, 3); Grid.SetColumnSpan(treetv, 2); //add preview RichTextBox tbPreview = new RichTextBox() { Name = snapshotTag + "_TBPreview", HorizontalScrollBarVisibility = ScrollBarVisibility.Auto }; grid.Children.Add(tbPreview); Grid.SetRow(tbPreview, 4); Grid.SetColumnSpan(tbPreview, 2); //Result summary Label infoLabel = new Label() { Name = snapshotTag + "labelInfo", Padding = new Thickness(5, 2, 5, 5), Content = infoContent }; grid.Children.Add(infoLabel); Grid.SetRow(infoLabel, 5); Grid.SetColumnSpan(infoLabel, 2); //Events btnExpAll.Click += (o, e) => { SetExpandAllInLvl(flattv.Items, true); SetExpandAllInLvl(treetv.Items, true); }; btnUnExpAll.Click += (o, e) => { SetExpandAllInLvl(flattv.Items, false); SetExpandAllInLvl(treetv.Items, false); }; btnFindAgain.Click += (o, e) => { findSettings[snapshotTag].Settings2Form(this); tbiSearch.Focus(); }; btnSave.Click += (o, e) => { SaveResultsToFile((Button)o); }; btnRemoveSnapshot.Click += (o, e) => { tbcMain.Items.Remove(newTab); findSettings.Remove(snapshotTag); }; tbShortDir.Checked += (o, e) => { (o as ToggleButton).Foreground = Brushes.Red; SetHeaderShortLong(flattv, flattv.Items, true); SetHeaderShortLong(treetv, treetv.Items, true); saveDict[btnSave] = treetv; }; tbShortDir.Unchecked += (o, e) => { (o as ToggleButton).ClearValue(ToggleButton.ForegroundProperty); SetHeaderShortLong(flattv, flattv.Items, false); SetHeaderShortLong(treetv, treetv.Items, false); saveDict[btnSave] = flattv; }; //Copy settings for snapshot FindSettings snapSettings = lastSearchSettings.GetCopy(); findSettings.Add(snapshotTag, snapSettings); //Copy ResultSummary for snapshot ResultSummary resultSummary = dictResultSummary[lastSearchSettings].GetCopy(); dictResultSummary.Add(snapSettings, resultSummary); //Populate new TreeViews from "last" FillSnapshotFromLast(snapshotTag, flattv, treetv, findSettings[snapshotTag], tbPreview); //Fill ResultSummary label FillResultSummary(infoLabel, resultSummary); //Expand new views SetExpandAllInLvl(flattv.Items, true); SetExpandAllInLvl(treetv.Items, true); //Snapshot views are filled from last views, so it's important to set short/long button also. tbShortDir.IsChecked = last_shortDir.IsChecked; //Connect "Save" button with TV saveDict[btnSave] = flattv; }
private void FillSnapshotFromLast(string snapshotTag, TreeView flattv, TreeView treetv, FindSettings findSettings, RichTextBox tbPreview) { dictTBPreview.Add(findSettings, tbPreview); CopyItems(last_tvResultFlatTree.Items, flattv.Items, findSettings, tbPreview); CopyItems(last_tvResultTree.Items, treetv.Items, findSettings, tbPreview); dictTVData[flattv] = new TVData() { longDir = System.IO.Path.GetDirectoryName(Dte.Solution.FullName) }; dictTVData[treetv] = new TVData() { longDir = System.IO.Path.GetDirectoryName(Dte.Solution.FullName) }; }