From a688f2a692c51e65fe4fef090f0dca46e2d37bf4 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Mon, 21 Aug 2023 04:41:02 +0200 Subject: [PATCH] Add UI for the search feature. Fixes #3 --- CsvView/MainWindow.axaml | 18 +++++++++++------- CsvView/MainWindow.axaml.cs | 25 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CsvView/MainWindow.axaml b/CsvView/MainWindow.axaml index f8c2663..3def5a3 100644 --- a/CsvView/MainWindow.axaml +++ b/CsvView/MainWindow.axaml @@ -9,12 +9,16 @@ Width="800" Height="600" Title="CsvView"> - - - - - - + + + + + + + + + + @@ -23,7 +27,7 @@ - + diff --git a/CsvView/MainWindow.axaml.cs b/CsvView/MainWindow.axaml.cs index e57351d..aa1077e 100644 --- a/CsvView/MainWindow.axaml.cs +++ b/CsvView/MainWindow.axaml.cs @@ -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 _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 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