Skip to content
Permalink
Browse files

Tweaking tree style

  • Loading branch information...
destanko destanko
destanko authored and destanko committed Aug 6, 2012
1 parent 1d536b6 commit bbb1814f6420abf38948f766b9a593379f54d656
@@ -40,11 +40,6 @@ public override bool Initialize(GrepEngineInitParams param)
}
}

public GrepEnginePdf(GrepEngineInitParams param)
:
base(param)
{ }

#endregion

public bool IsSearchOnly
@@ -0,0 +1,75 @@
using dnGREP.Common;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace dnGREP.WPF.MVHelpers
{
public class LazyResultsList : ObservableCollection<FormattedGrepLine>, INotifyPropertyChanged
{
private GrepSearchResult result;
private FormattedGrepResult formattedResult;

public LazyResultsList(GrepSearchResult result, FormattedGrepResult formattedResult)
{
this.result = result;
this.formattedResult = formattedResult;
GrepSearchResult.GrepLine emptyLine = new GrepSearchResult.GrepLine(-1, "", true, null);
this.Add(new FormattedGrepLine(emptyLine, formattedResult, 30));
}

private int lineNumberColumnWidth = 30;
public int LineNumberColumnWidth
{
get { return lineNumberColumnWidth; }
set { lineNumberColumnWidth = value; OnPropertyChanged("LineNumberColumnWidth"); }
}

public void Load()
{
if (this.Count == 1 && this[0].GrepLine.LineNumber == -1)
this.Clear();
int currentLine = -1;
List<GrepSearchResult.GrepLine> linesWithContext = new List<GrepSearchResult.GrepLine>();
if (GrepSettings.Instance.Get<bool>(GrepSettings.Key.ShowLinesInContext))
linesWithContext = result.GetLinesWithContext(GrepSettings.Instance.Get<int>(GrepSettings.Key.ContextLinesBefore),
GrepSettings.Instance.Get<int>(GrepSettings.Key.ContextLinesAfter));
else
linesWithContext = result.GetLinesWithContext(0, 0);

for (int i = 0; i < linesWithContext.Count; i++)
{
GrepSearchResult.GrepLine line = linesWithContext[i];

// Adding separator
if (this.Count > 0 && GrepSettings.Instance.Get<bool>(GrepSettings.Key.ShowLinesInContext) &&
(currentLine != line.LineNumber && currentLine + 1 != line.LineNumber))
{
GrepSearchResult.GrepLine emptyLine = new GrepSearchResult.GrepLine(-1, "", true, null);
this.Add(new FormattedGrepLine(emptyLine, formattedResult, 30));
}

currentLine = line.LineNumber;
if (currentLine <= 999 && LineNumberColumnWidth < 30)
LineNumberColumnWidth = 30;
else if (currentLine > 999 && LineNumberColumnWidth < 35)
LineNumberColumnWidth = 35;
else if (currentLine > 9999 && LineNumberColumnWidth < 47)
LineNumberColumnWidth = 47;
else if (currentLine > 99999 && LineNumberColumnWidth < 50)
LineNumberColumnWidth = 50;
this.Add(new FormattedGrepLine(line, formattedResult, LineNumberColumnWidth));
}
}

public event EventHandler<PropertyChangedEventArgs> LineNumberColumnWidthChanged;

protected void OnPropertyChanged(string name)
{
LineNumberColumnWidthChanged(this, new PropertyChangedEventArgs(name));
}
}
}
@@ -13,6 +13,7 @@
using System.Runtime.InteropServices;
using System.ComponentModel;
using dnGREP.Common.UI;
using dnGREP.WPF.MVHelpers;

namespace dnGREP.WPF
{
@@ -164,7 +165,11 @@ public string Label
public bool IsExpanded
{
get { return isExpanded; }
set { isExpanded = value; OnPropertyChanged("IsExpanded"); }
set {
isExpanded = value;
if (value == true)
FormattedLines.Load();
OnPropertyChanged("IsExpanded"); }
}

private int lineNumberColumnWidth = 30;
@@ -182,8 +187,8 @@ public BitmapSource Icon
set { icon = value; }
}

private List<FormattedGrepLine> formattedLines = new List<FormattedGrepLine>();
public List<FormattedGrepLine> FormattedLines
private LazyResultsList formattedLines;
public LazyResultsList FormattedLines
{
get { return formattedLines; }
}
@@ -228,29 +233,16 @@ public FormattedGrepResult(GrepSearchResult result, string folderPath)
style = "Error";
}

if (result.Matches != null && result.Matches.Count > 0)
{
int currentLine = -1;
var linesWithContext = result.GetLinesWithContext(GrepSettings.Instance.Get<int>(GrepSettings.Key.ContextLinesBefore),
GrepSettings.Instance.Get<int>(GrepSettings.Key.ContextLinesAfter));
for (int i = 0; i < linesWithContext.Count; i++)
{
GrepSearchResult.GrepLine line = linesWithContext[i];

currentLine = line.LineNumber;
if (currentLine <= 999 && LineNumberColumnWidth < 30)
LineNumberColumnWidth = 30;
else if (currentLine > 999 && LineNumberColumnWidth < 35)
LineNumberColumnWidth = 35;
else if (currentLine > 9999 && LineNumberColumnWidth < 47)
LineNumberColumnWidth = 47;
else if (currentLine > 99999 && LineNumberColumnWidth < 50)
LineNumberColumnWidth = 50;
formattedLines.Add(new FormattedGrepLine(line, this, LineNumberColumnWidth));
}
}
formattedLines = new LazyResultsList(result, this);
formattedLines.LineNumberColumnWidthChanged += formattedLines_PropertyChanged;
}

void formattedLines_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "LineNumberColumnWidth")
LineNumberColumnWidth = formattedLines.LineNumberColumnWidth;
}

#region PropertyChanged Members
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
@@ -291,21 +283,7 @@ public InlineCollection FormattedText
}
}

private SyntaxHighlighterViewModel previewViewModel;

public SyntaxHighlighterViewModel PreviewViewModel
{
get {
if (previewViewModel == null)
previewViewModel = new SyntaxHighlighterViewModel();
previewViewModel.Text = GrepLine.LineText;
previewViewModel.LineNumbers = new int[] { GrepLine.LineNumber };
return previewViewModel;
}
}


private string style = "";
private string style = "";
public string Style
{
get { return style; }
@@ -355,18 +333,18 @@ public FormattedGrepLine(GrepSearchResult.GrepLine line, FormattedGrepResult par
private InlineCollection formatLine(GrepSearchResult.GrepLine line)
{
Paragraph paragraph = new Paragraph();
var font = new FontFamily("Consolas");


string fullLine = line.LineText;

if (line.Matches.Count == 0)
{
Run mainRun = new Run(line.LineText);
Run mainRun = new Run(fullLine);
paragraph.Inlines.Add(mainRun);
}
else
{
int counter = 0;
string fullLine = line.LineText;
GrepSearchResult.GrepMatch[] lineMatches = new GrepSearchResult.GrepMatch[line.Matches.Count];
GrepSearchResult.GrepMatch[] lineMatches = new GrepSearchResult.GrepMatch[line.Matches.Count];
line.Matches.CopyTo(lineMatches);
foreach (GrepSearchResult.GrepMatch m in lineMatches)
{
@@ -385,13 +363,11 @@ private InlineCollection formatLine(GrepSearchResult.GrepLine line)
}

Run regularRun = new Run(regLine);
regularRun.FontFamily = font;
paragraph.Inlines.Add(regularRun);

if (fmtLine != null)
{
Run highlightedRun = new Run(fmtLine);
highlightedRun.FontFamily = font;
highlightedRun.Background = Brushes.Yellow;
paragraph.Inlines.Add(highlightedRun);
}
@@ -403,7 +379,6 @@ private InlineCollection formatLine(GrepSearchResult.GrepLine line)
catch (Exception e)
{
Run regularRun = new Run(fullLine);
regularRun.FontFamily = font;
paragraph.Inlines.Add(regularRun);
}
finally
@@ -417,13 +392,11 @@ private InlineCollection formatLine(GrepSearchResult.GrepLine line)
{
string regLine = fullLine.Substring(counter);
Run regularRun = new Run(regLine);
regularRun.FontFamily = font;
paragraph.Inlines.Add(regularRun);
}
catch (Exception e)
{
Run regularRun = new Run(fullLine);
regularRun.FontFamily = font;
paragraph.Inlines.Add(regularRun);
}
}
@@ -36,37 +36,102 @@
</Style.Triggers>
</Style>

<!--<Style TargetType="{x:Type GridSplitter}">
<Setter Property="Height" Value="5"/>
<Setter Property="TextElement.Foreground" Value="#FFA6B8D0" />
<Setter Property="Border.BorderBrush" Value="#FF808C9B" />
<Setter Property="Panel.Background" Value="{StaticResource PanelBackgroundBrush}" />
<Setter Property="Border.BorderThickness" Value="0,1,0,0" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Padding" Value="7,7,7,7" />
<Setter Property="Cursor" Value="SizeNS" />
<Setter Property="Template">
<Style x:Key="TreeViewItemFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" Height="5">
<Border BorderThickness="1,1,0,0" BorderBrush="{StaticResource PanelBackgroundBrush}">
<Canvas Width="19" Height="3">
<Rectangle Fill="{StaticResource PanelBackgroundBrush}" Width="2" Height="2" Canvas.Left="1" Canvas.Top="0" />
<Rectangle Fill="{StaticResource PanelBackgroundBrush}" Width="2" Height="2" Canvas.Left="5" Canvas.Top="0" />
<Rectangle Fill="{StaticResource PanelBackgroundBrush}" Width="2" Height="2" Canvas.Left="9" Canvas.Top="0" />
<Rectangle Fill="{StaticResource PanelBackgroundBrush}" Width="2" Height="2" Canvas.Left="13" Canvas.Top="0" />
<Rectangle Fill="{StaticResource PanelBackgroundBrush}" Width="2" Height="2" Canvas.Left="17" Canvas.Top="0" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Width="2" Height="2" Canvas.Left="0" Canvas.Top="0" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Width="2" Height="2" Canvas.Left="4" Canvas.Top="0" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Width="2" Height="2" Canvas.Left="8" Canvas.Top="0" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Width="2" Height="2" Canvas.Left="12" Canvas.Top="0" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Width="2" Height="2" Canvas.Left="16" Canvas.Top="0" />
</Canvas>
</Border>
<Rectangle/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>

<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Width" Value="16"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Width="16" Height="16" Background="Transparent" Padding="5,5,5,5">
<Path x:Name="ExpandPath" Fill="Transparent" Stroke="#FF989898" Data="{StaticResource TreeArrow}">
<Path.RenderTransform>
<RotateTransform Angle="135" CenterX="3" CenterY="3"/>
</Path.RenderTransform>
</Path>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
<Setter Property="Fill" TargetName="ExpandPath" Value="Transparent"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="RenderTransform" TargetName="ExpandPath">
<Setter.Value>
<RotateTransform Angle="180" CenterX="3" CenterY="3"/>
</Setter.Value>
</Setter>
<Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
<Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>-->
</Style>
<Style x:Key="TreeViewItemStyle1" TargetType="{x:Type TreeViewItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="1,0,0,0"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="19" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
<Border x:Name="Bd" SnapsToDevicePixels="true" Grid.Column="1" Grid.ColumnSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<ContentPresenter x:Name="PART_Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header"/>
</Border>
<ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="false">
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
</Trigger>
<Trigger Property="HasItems" Value="false">
<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

0 comments on commit bbb1814

Please sign in to comment.
You can’t perform that action at this time.