Skip to content

Commit

Permalink
New : Start & End of regions are now displayed within the filter resu…
Browse files Browse the repository at this point in the history
…lts. #375
  • Loading branch information
Pressacco committed Jan 18, 2025
1 parent 4e982b8 commit 0c4fd43
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Src/BlueDotBrigade.Weevil.Common/IRegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public interface IRegionManager
void MarkEnd(int lineNumber);

void MarkStart(int lineNumber);

bool StartsWith(int lineNumber);

bool EndsWith(int lineNumber);

public bool Contains(int lineNumber);
}
}
15 changes: 15 additions & 0 deletions Src/BlueDotBrigade.Weevil.Core/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ public void MarkEnd(int lineNumber)
}
}

public bool StartsWith(int lineNumber)
{
return _regions.Any(r => r.Minimum.LineNumber == lineNumber);
}

public bool EndsWith(int lineNumber)
{
return _regions.Any(r => r.Maximum.LineNumber == lineNumber);
}

public bool Contains(int lineNumber)
{
return _regions.Any(r => r.Contains(lineNumber));
}

public void Clear()
{
_regions.Clear();
Expand Down
73 changes: 73 additions & 0 deletions Src/BlueDotBrigade.Weevil.Gui/Converters/RegionConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace BlueDotBrigade.Weevil.Gui.Converters
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlueDotBrigade.Weevil.Data;
using System.Windows.Data;
using System.Windows;
using BlueDotBrigade.Weevil.Gui.Filter;

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

using System;
using System.Globalization;
using System.Windows.Data;

public class RegionStringConverter : IMultiValueConverter
{
/// <summary>
/// Expects:
/// values[0]: The current IRecord (the item in the ListView)
/// values[1]: The parent FilterViewModel (the DataContext of the UserControl/Window)
/// Returns a string indicating the record's region status:
/// - "Start of Region"
/// - "In Region"
/// - "End of Region"
/// - string.Empty (when the record isn't in any region)
/// </summary>
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values?.Length < 2)
return string.Empty;

var record = values[0] as IRecord;
var viewModel = values[1] as FilterViewModel;

if (record == null || viewModel == null)
return string.Empty;

// You can define your own logic:
// e.g., if region is a single continuous block, you might define:
// - starts with a region if ...
// - ends with a region if ...
// - or "in region" otherwise
if (viewModel.RegionStartsWith(record))
{
return "Start of Region";
}
else if (viewModel.RegionEndsWith(record))
{
return "End of Region";
}
else if (viewModel.RegionContains(record))
{
return "In Region";
}

return string.Empty;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

}
22 changes: 17 additions & 5 deletions Src/BlueDotBrigade.Weevil.Gui/Filter/FilterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<converters:FilterMultiValueConverter x:Key="FiltersMultiValueConverter" />
<converters:ContentConverter x:Key="ContentConverter" />
<converters:CheckBoxValidationErrorConverter x:Key="CheckBoxValidationErrorConverter" />
<converters:RegionStringConverter x:Key="RegionStringConverter" />
<Style x:Key="CommandMenuItemStyle"
TargetType="{x:Type MenuItem}">
<Setter Property="Header"
Expand Down Expand Up @@ -257,9 +258,6 @@
<Separator/>
<MenuItem Header="Paste Comments" Command="{Binding ClipboardPasteCommand}" InputGestureText="Ctrl+V" />
<MenuItem Header="Overwrite Comments" Command="{Binding ClipboardPasteOverwriteCommand}" InputGestureText="Ctrl+Shift+V" />
<Separator/>
<MenuItem Header="Add Region" Command="{Binding AddRegionCommand}" InputGestureText="Ctrl+B" />
<MenuItem Header="Remove All Regions" Command="{Binding RemoveAllRegionsCommand}" />
</MenuItem>
<Separator/>
<MenuItem Header="Filtering...">
Expand Down Expand Up @@ -306,6 +304,9 @@
<MenuItem Header="Show Dashboard" Command="{Binding ShowDashboardCommand}" InputGestureText="Ctrl+D" />
<MenuItem Header="Show Graph" Command="{Binding GraphDataCommand}" InputGestureText="Ctrl+Shift+G" />
<MenuItem Header="Analyze...">
<MenuItem Header="Add Region" Command="{Binding AddRegionCommand}" InputGestureText="Ctrl+B" />
<MenuItem Header="Remove All Regions" Command="{Binding RemoveAllRegionsCommand}" />
<Separator/>
<MenuItem Header="Detect Data" Command="{Binding DetectDataCommand}" InputGestureText="F8" />
<MenuItem Header="Detect Data Transitions" Command="{Binding DetectDataTransitionsCommand}" InputGestureText="F9" />
<MenuItem Header="Detect Rising Edges" Command="{Binding DataTransitionsRisingEdgeCommand}" />
Expand Down Expand Up @@ -432,8 +433,19 @@
<GridViewColumnHeader Content="Content" Padding="{StaticResource ColumnHeaderPadding}"/>
<GridViewColumn.CellTemplate>
<DataTemplate DataType="data:IRecord">
<TextBlock TextWrapping="WrapWithOverflow" HorizontalAlignment="Right"
Text="{Binding Mode=OneWay, Converter={StaticResource ContentConverter}}">
<TextBlock>
<TextBlock TextWrapping="WrapWithOverflow" HorizontalAlignment="Right"
Text="{Binding Mode=OneWay, Converter={StaticResource ContentConverter}}"/>
<TextBlock Margin="0,5,0,0" FontWeight="Bold" Foreground="Red">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource RegionStringConverter}">
<!-- 1) The current item (record) -->
<Binding Path="." />
<!-- 2) The parent ViewModel (the UserControl.DataContext) -->
<Binding Path="DataContext" RelativeSource="{RelativeSource AncestorType=UserControl}" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
Expand Down
15 changes: 15 additions & 0 deletions Src/BlueDotBrigade.Weevil.Gui/Filter/FilterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,5 +1475,20 @@ private Dictionary<string, object> GetFilterConfiguration()

return configuration;
}

public bool RegionStartsWith(IRecord record)
{
return _engine.Regions.StartsWith(record.LineNumber);
}

public bool RegionEndsWith(IRecord record)
{
return _engine.Regions.EndsWith(record.LineNumber);
}

public bool RegionContains(IRecord record)
{
return _engine.Regions.Contains(record.LineNumber);
}
}
}

0 comments on commit 0c4fd43

Please sign in to comment.