@@ -9,12 +9,16 @@
|
||||
Width="800"
|
||||
Height="600"
|
||||
Title="CsvView">
|
||||
<Grid RowDefinitions="Auto,Auto,*">
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0">
|
||||
<Button Name="BtnLoad" Click="BtnLoad_OnClick">...</Button>
|
||||
<TextBox Name="TxtFileName" IsReadOnly="true" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="1">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,*">
|
||||
<Grid ColumnDefinitions="Auto,*" Grid.Row="0">
|
||||
<Button Grid.Column="0" Name="BtnLoad" Click="BtnLoad_OnClick">...</Button>
|
||||
<TextBox Grid.Column="1" Name="TxtFileName" IsReadOnly="true" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="*,Auto" Grid.Row="1">
|
||||
<TextBox Grid.Column="0" Name="TxtSearch" />
|
||||
<Button Grid.Column="1" Name="BtnSearch" Click="BtnSearch_OnClick">🔍</Button>
|
||||
</Grid>
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="2">
|
||||
<Button Name="BtnFirst" Click="BtnFirst_OnClick">|◁</Button>
|
||||
<Button Name="BtnPrevious" Click="BtnPrevious_OnClick">◁</Button>
|
||||
<TextBox Name="TxtIndex" Text="{Binding Index}" TextChanged="TxtIndex_OnTextChanged"></TextBox>
|
||||
@@ -23,7 +27,7 @@
|
||||
<Button Name="BtnNext" Click="BtnNext_OnClick">▷</Button>
|
||||
<Button Name="BtnLast" Click="BtnLast_OnClick">▷|</Button>
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="2">
|
||||
<ScrollViewer Grid.Row="3">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<ItemsControl ItemsSource="{Binding Fields}">
|
||||
<ItemsControl.DataTemplates>
|
||||
|
||||
@@ -38,6 +38,11 @@ public partial class MainWindow : Window
|
||||
LoadFile(files[0].Path.LocalPath);
|
||||
}
|
||||
|
||||
private void BtnSearch_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Search(TxtSearch.Text);
|
||||
}
|
||||
|
||||
private void BtnFirst_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
RenderReg(0);
|
||||
@@ -68,9 +73,9 @@ public partial class MainWindow : Window
|
||||
private int _totalRegs;
|
||||
private List<long> _index = new();
|
||||
|
||||
|
||||
private void LoadFile(string fileName)
|
||||
{
|
||||
// TODO: Loading animation
|
||||
_loadedFile = fileName;
|
||||
TxtFileName.Text = fileName;
|
||||
|
||||
@@ -82,9 +87,22 @@ public partial class MainWindow : Window
|
||||
RenderReg(0);
|
||||
}
|
||||
|
||||
private void Search(string? textToSearch)
|
||||
{
|
||||
// TODO: Loading animation
|
||||
CsvFieldIndexer csvIndexer = new();
|
||||
csvIndexer.LoadIndexOfFile(_loadedFile);
|
||||
|
||||
List<long> newIndexes = csvIndexer.Search(_loadedFile, textToSearch);
|
||||
_index = newIndexes;
|
||||
_totalRegs = _index.Count - 1;
|
||||
|
||||
RenderReg(0, forceLoad: true);
|
||||
}
|
||||
|
||||
private bool _rendering;
|
||||
|
||||
private void RenderReg(long currentReg)
|
||||
private void RenderReg(long currentReg, bool forceLoad = false)
|
||||
{
|
||||
if (_rendering) { return; }
|
||||
_rendering = true;
|
||||
@@ -122,7 +140,7 @@ public partial class MainWindow : Window
|
||||
BtnNext.IsEnabled = (last == false);
|
||||
BtnLast.IsEnabled = (last == false);
|
||||
|
||||
if (_currentReg == currentReg)
|
||||
if (_currentReg == currentReg && forceLoad == false)
|
||||
{
|
||||
_rendering = false;
|
||||
return;
|
||||
@@ -143,7 +161,6 @@ public partial class MainWindow : Window
|
||||
|
||||
_rendering = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class FieldViewModel
|
||||
|
||||
Reference in New Issue
Block a user