From 64e380926251130869829423c31d29f492efde08 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sat, 5 Aug 2023 15:40:12 +0200 Subject: [PATCH 1/3] Add AvaloniaUI App project. --- CsvView.csproj => CsvView.Old.csproj | 2 +- CsvView.sln | 8 +++++++- CsvView.sln.DotSettings | 4 ++-- CsvView/App.axaml | 10 ++++++++++ CsvView/App.axaml.cs | 23 +++++++++++++++++++++++ CsvView/CsvView.csproj | 20 ++++++++++++++++++++ CsvView/MainWindow.axaml | 11 +++++++++++ CsvView/MainWindow.axaml.cs | 12 ++++++++++++ CsvView/Program.cs | 21 +++++++++++++++++++++ CsvView/app.manifest | 18 ++++++++++++++++++ 10 files changed, 125 insertions(+), 4 deletions(-) rename CsvView.csproj => CsvView.Old.csproj (99%) create mode 100644 CsvView/App.axaml create mode 100644 CsvView/App.axaml.cs create mode 100644 CsvView/CsvView.csproj create mode 100644 CsvView/MainWindow.axaml create mode 100644 CsvView/MainWindow.axaml.cs create mode 100644 CsvView/Program.cs create mode 100644 CsvView/app.manifest diff --git a/CsvView.csproj b/CsvView.Old.csproj similarity index 99% rename from CsvView.csproj rename to CsvView.Old.csproj index 97cb645..b870ec6 100644 --- a/CsvView.csproj +++ b/CsvView.Old.csproj @@ -8,7 +8,7 @@ WinExe Properties CsvView - CsvView + CsvView.Old v4.6.1 512 true diff --git a/CsvView.sln b/CsvView.sln index 1ccb1fb..4366a40 100644 --- a/CsvView.sln +++ b/CsvView.sln @@ -3,12 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvView", "CsvView.csproj", "{587169B9-7891-4A2F-8537-9196898B86AF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvView.Old", "CsvView.Old.csproj", "{587169B9-7891-4A2F-8537-9196898B86AF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvLib", "CsvLib\CsvLib.csproj", "{EB0FDB60-8B9D-401C-85A8-4CF4105D5063}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvLib.Tests", "CsvLib.Tests\CsvLib.Tests.csproj", "{EC5C84D8-1CDE-4AED-9C16-6C4086A20893}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvView", "CsvView\CsvView.csproj", "{65A0A7DA-5884-4DFE-8223-C8F5DBD881A8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {EC5C84D8-1CDE-4AED-9C16-6C4086A20893}.Debug|Any CPU.Build.0 = Debug|Any CPU {EC5C84D8-1CDE-4AED-9C16-6C4086A20893}.Release|Any CPU.ActiveCfg = Release|Any CPU {EC5C84D8-1CDE-4AED-9C16-6C4086A20893}.Release|Any CPU.Build.0 = Release|Any CPU + {65A0A7DA-5884-4DFE-8223-C8F5DBD881A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65A0A7DA-5884-4DFE-8223-C8F5DBD881A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65A0A7DA-5884-4DFE-8223-C8F5DBD881A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65A0A7DA-5884-4DFE-8223-C8F5DBD881A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CsvView.sln.DotSettings b/CsvView.sln.DotSettings index 9b6148b..f9ba49e 100644 --- a/CsvView.sln.DotSettings +++ b/CsvView.sln.DotSettings @@ -1,3 +1,3 @@  - /usr/lib/mono/msbuild/15.0/bin/MSBuild.dll - 983040 \ No newline at end of file + /usr/share/dotnet/sdk/7.0.107/MSBuild.dll + 4294967293 \ No newline at end of file diff --git a/CsvView/App.axaml b/CsvView/App.axaml new file mode 100644 index 0000000..1df1472 --- /dev/null +++ b/CsvView/App.axaml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/CsvView/App.axaml.cs b/CsvView/App.axaml.cs new file mode 100644 index 0000000..585757c --- /dev/null +++ b/CsvView/App.axaml.cs @@ -0,0 +1,23 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +namespace CsvView; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow(); + } + + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/CsvView/CsvView.csproj b/CsvView/CsvView.csproj new file mode 100644 index 0000000..1496670 --- /dev/null +++ b/CsvView/CsvView.csproj @@ -0,0 +1,20 @@ + + + WinExe + net7.0 + enable + true + app.manifest + true + + + + + + + + + + + + diff --git a/CsvView/MainWindow.axaml b/CsvView/MainWindow.axaml new file mode 100644 index 0000000..0852b81 --- /dev/null +++ b/CsvView/MainWindow.axaml @@ -0,0 +1,11 @@ + + Hello CvsView! + diff --git a/CsvView/MainWindow.axaml.cs b/CsvView/MainWindow.axaml.cs new file mode 100644 index 0000000..5c17c5c --- /dev/null +++ b/CsvView/MainWindow.axaml.cs @@ -0,0 +1,12 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; + +namespace CsvView; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} diff --git a/CsvView/Program.cs b/CsvView/Program.cs new file mode 100644 index 0000000..977975b --- /dev/null +++ b/CsvView/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace CsvView; + +class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} diff --git a/CsvView/app.manifest b/CsvView/app.manifest new file mode 100644 index 0000000..07df98d --- /dev/null +++ b/CsvView/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + From 51f3e8b0c77183f1aead8b5ea6d205769050b824 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Thu, 17 Aug 2023 14:22:38 +0200 Subject: [PATCH 2/3] Implement basic UI using AvaloniaUI. --- CsvView/CsvView.csproj | 5 ++ CsvView/MainWindow.axaml | 29 ++++++- CsvView/MainWindow.axaml.cs | 159 ++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 1 deletion(-) diff --git a/CsvView/CsvView.csproj b/CsvView/CsvView.csproj index 1496670..8de198e 100644 --- a/CsvView/CsvView.csproj +++ b/CsvView/CsvView.csproj @@ -17,4 +17,9 @@ + + + + + diff --git a/CsvView/MainWindow.axaml b/CsvView/MainWindow.axaml index 0852b81..5e42ce7 100644 --- a/CsvView/MainWindow.axaml +++ b/CsvView/MainWindow.axaml @@ -2,10 +2,37 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:csvView="clr-namespace:CsvView" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" x:Class="CsvView.MainWindow" + x:DataType="csvView:MainWindowViewModel" Width="800" Height="600" Title="CsvView"> - Hello CvsView! + + + + + + + + + + / + + + + + + + + + + + + + + + + diff --git a/CsvView/MainWindow.axaml.cs b/CsvView/MainWindow.axaml.cs index 5c17c5c..4567d1f 100644 --- a/CsvView/MainWindow.axaml.cs +++ b/CsvView/MainWindow.axaml.cs @@ -1,5 +1,9 @@ +using System.Collections.Generic; +using System.Linq; using Avalonia.Controls; using Avalonia.Interactivity; +using Avalonia.Platform.Storage; +using CsvLib; namespace CsvView; @@ -8,5 +12,160 @@ public partial class MainWindow : Window public MainWindow() { InitializeComponent(); + RenderReg(0); } + + private async void BtnLoad_OnClick(object? sender, RoutedEventArgs e) + { + TopLevel? topLevel = GetTopLevel(this); + if (topLevel == null) { return; } + + IReadOnlyList files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = "Open CSV File", + AllowMultiple = false, + FileTypeFilter = new List + { + new("CSV Files") { Patterns = new[] { "*.csv" } }, + new("Any File") { Patterns = new[] { "*" } }, + }, + }); + + if (files.Count <= 0) { return; } + + LoadFile(files[0].Path.LocalPath); + } + + private void BtnFirst_OnClick(object? sender, RoutedEventArgs e) + { + RenderReg(0); + } + + private void BtnPrevious_OnClick(object? sender, RoutedEventArgs e) + { + RenderReg(_currentReg - 1); + } + + private void TxtIndex_OnTextChanged(object? sender, TextChangedEventArgs e) + { + RenderReg(int.TryParse(TxtIndex.Text, out int newReg) ? newReg : _currentReg); + } + + private void BtnNext_OnClick(object? sender, RoutedEventArgs e) + { + RenderReg(_currentReg + 1); + } + + private void BtnLast_OnClick(object? sender, RoutedEventArgs e) + { + RenderReg(_totalRegs - 1); + } + + private string _loadedFile = string.Empty; + private long _currentReg; + private int _totalRegs; + private List _index = new(); + + + private void LoadFile(string fileName) + { + _loadedFile = fileName; + TxtFileName.Text = fileName; + + CsvIndexer csvIndexer = new(); + csvIndexer.LoadIndexOfFile(_loadedFile); + _index = csvIndexer.Index; + _totalRegs = _index.Count - 1; + + RenderReg(0); + } + + private MainWindowViewModel Index_LoadReg(int idx, int maxIndex) + { + CsvParser csvParser = new(); + csvParser.ParseFile(_loadedFile, _index[idx], 1); + MainWindowViewModel viewModel = new() + { + Index = idx, + MaxIndex = maxIndex, + Fields = csvParser.Data[0].Select(f => new FieldViewModel { Text = f, }).ToList(), + }; + return viewModel; + } + + bool _rendering; + private void RenderReg(long currentReg) + { + if (_rendering) { return; } + _rendering = true; + + if (_index.Count <= 0) + { + _currentReg = -1; + BtnFirst.IsEnabled = false; + BtnPrevious.IsEnabled = false; + TxtIndex.IsEnabled = false; + BtnNext.IsEnabled = false; + BtnLast.IsEnabled = false; + + DataContext = new MainWindowViewModel { Index = 0, Fields = new(), }; + _rendering = false; + return; + } + + bool first = false; + bool last = false; + if (currentReg <= 0) + { + currentReg = 0; + first = true; + } + if (currentReg >= (_totalRegs - 1)) + { + currentReg = _totalRegs - 1; + last = true; + } + + BtnFirst.IsEnabled = (first == false); + BtnPrevious.IsEnabled = (first == false); + TxtIndex.IsEnabled = true; + BtnNext.IsEnabled = (last == false); + BtnLast.IsEnabled = (last == false); + + if (_currentReg == currentReg) + { + _rendering = false; + return; + } + + _currentReg = currentReg; + + CsvParser csvParser = new(); + csvParser.ParseFile(_loadedFile, _index[(int)currentReg], 1); + MainWindowViewModel viewModel = new() + { + Index = (int)currentReg, + MaxIndex = _totalRegs, + Fields = csvParser.Data[0].Select(f => new FieldViewModel { Text = f, }).ToList(), + }; + + DataContext = viewModel; + + _rendering = false; + } + +} + +public class FieldViewModel +{ + public string Text { get; set; } = string.Empty; +} + +public class MainWindowViewModel +{ + public int? Index { get; set; } + + public int? MaxIndex { get; set; } + + public List? Fields { get; set; } } From bbea4845d40c294a3f3a9e8515c759723a0c14a1 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Thu, 17 Aug 2023 14:27:34 +0200 Subject: [PATCH 3/3] Delete old Windows.Forms project. --- CsvView.Old.csproj | 116 ----------------- CsvView.sln | 14 +- Program.cs | 26 ---- Properties/AssemblyInfo.cs | 14 -- UI/CTextBox.cs | 34 ----- UI/DoubleBufferPanel.cs | 56 -------- UI/FrmCsvViewer.Designer.cs | 247 ------------------------------------ UI/FrmCsvViewer.cs | 203 ----------------------------- UI/MessageBoxEx.cs | 86 ------------- app.manifest | 75 ----------- 10 files changed, 8 insertions(+), 863 deletions(-) delete mode 100644 CsvView.Old.csproj delete mode 100644 Program.cs delete mode 100644 Properties/AssemblyInfo.cs delete mode 100644 UI/CTextBox.cs delete mode 100644 UI/DoubleBufferPanel.cs delete mode 100644 UI/FrmCsvViewer.Designer.cs delete mode 100644 UI/FrmCsvViewer.cs delete mode 100644 UI/MessageBoxEx.cs delete mode 100644 app.manifest diff --git a/CsvView.Old.csproj b/CsvView.Old.csproj deleted file mode 100644 index b870ec6..0000000 --- a/CsvView.Old.csproj +++ /dev/null @@ -1,116 +0,0 @@ - - - - - Debug - AnyCPU - {587169B9-7891-4A2F-8537-9196898B86AF} - WinExe - Properties - CsvView - CsvView.Old - v4.6.1 - 512 - true - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - app.manifest - - - - - - - - - - - - - - - - - Component - - - Component - - - Form - - - FrmCsvViewer.cs - - - - - - - - - - - - False - Microsoft .NET Framework 4.6.1 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - - - - - - - - {eb0fdb60-8b9d-401c-85a8-4cf4105d5063} - CsvLib - - - - - \ No newline at end of file diff --git a/CsvView.sln b/CsvView.sln index 4366a40..7e87715 100644 --- a/CsvView.sln +++ b/CsvView.sln @@ -3,24 +3,26 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvView.Old", "CsvView.Old.csproj", "{587169B9-7891-4A2F-8537-9196898B86AF}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvLib", "CsvLib\CsvLib.csproj", "{EB0FDB60-8B9D-401C-85A8-4CF4105D5063}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvLib.Tests", "CsvLib.Tests\CsvLib.Tests.csproj", "{EC5C84D8-1CDE-4AED-9C16-6C4086A20893}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsvView", "CsvView\CsvView.csproj", "{65A0A7DA-5884-4DFE-8223-C8F5DBD881A8}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{94D4A247-9453-45F4-8552-0D106801C9F0}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + LICENSE.txt = LICENSE.txt + .editorconfig = .editorconfig + .gitignore = .gitignore + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {587169B9-7891-4A2F-8537-9196898B86AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {587169B9-7891-4A2F-8537-9196898B86AF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {587169B9-7891-4A2F-8537-9196898B86AF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {587169B9-7891-4A2F-8537-9196898B86AF}.Release|Any CPU.Build.0 = Release|Any CPU {EB0FDB60-8B9D-401C-85A8-4CF4105D5063}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EB0FDB60-8B9D-401C-85A8-4CF4105D5063}.Debug|Any CPU.Build.0 = Debug|Any CPU {EB0FDB60-8B9D-401C-85A8-4CF4105D5063}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Program.cs b/Program.cs deleted file mode 100644 index 5169956..0000000 --- a/Program.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Windows.Forms; -using CsvView.UI; - -namespace CsvView -{ - static class Program - { - [STAThread] - static void Main(string[] args) - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - - var frmCsvViewer = new FrmCsvViewer(); - if (args.Length > 0) - { - if (System.IO.File.Exists(args[0])) - { - frmCsvViewer.LoadFile(args[0]); - } - } - Application.Run(frmCsvViewer); - } - } -} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 0636657..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("CSVView.Net")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CSVView.Net")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("587169b9-7891-4a2f-8537-9196898b86af")] -[assembly: AssemblyVersion("1.0.*")] diff --git a/UI/CTextBox.cs b/UI/CTextBox.cs deleted file mode 100644 index 5278cea..0000000 --- a/UI/CTextBox.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Windows.Forms; -using System.Runtime.InteropServices; -using System.Drawing; - -namespace CsvView.UI -{ - public class CTextBox : TextBox - { - public CTextBox() - { - WordWrap = false; - ScrollBars = ScrollBars.Horizontal; - Font = new Font("Courier New", 9, FontStyle.Regular, GraphicsUnit.Point, 0); - } - - [DllImport("user32.dll")] - private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); - - private const int WM_MOUSEWHEEL = 0x20a; - - protected override void WndProc(ref Message m) - { - if (m.Msg == WM_MOUSEWHEEL) - { - SendMessage(Parent.Handle, m.Msg, m.WParam, m.LParam); - } - else - { - base.WndProc(ref m); - } - } - } -} diff --git a/UI/DoubleBufferPanel.cs b/UI/DoubleBufferPanel.cs deleted file mode 100644 index e5ad59c..0000000 --- a/UI/DoubleBufferPanel.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.ComponentModel; -using System.Drawing; -using System.Runtime.InteropServices; -using System.Windows.Forms; - -namespace CsvView.UI -{ - public class DoubleBufferPanel : Panel - { - public DoubleBufferPanel() - { - DoubleBuffered = true; - SetStyle(ControlStyles.UserPaint | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.ResizeRedraw | - ControlStyles.ContainerControl | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.SupportsTransparentBackColor - , true); - } - - [DllImport("user32.dll", CharSet = CharSet.Auto)] - public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam); - - private const int WM_SetRedraw = 0XB; - - public void SuspendDrawing() - { - SuspendLayout(); - SendMessage(Handle, WM_SetRedraw, false, 0); - } - - public void ResumeDrawing() - { - ResumeLayout(true); - SendMessage(Handle, WM_SetRedraw, true, 0); - Refresh(); - } - - [DefaultValue(false)] - [Localizable(false)] - [Category("CatLayout")] - [Description("DisableAutoScrollDescr")] - public bool DisableAutoScroll { get; set; } - - protected override Point ScrollToControl(Control activeControl) - { - if (DisableAutoScroll) - { - return DisplayRectangle.Location; - } - return base.ScrollToControl(activeControl); - } - } -} diff --git a/UI/FrmCsvViewer.Designer.cs b/UI/FrmCsvViewer.Designer.cs deleted file mode 100644 index 5a28af5..0000000 --- a/UI/FrmCsvViewer.Designer.cs +++ /dev/null @@ -1,247 +0,0 @@ -namespace CsvView.UI -{ - partial class FrmCsvViewer - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.txtPath = new System.Windows.Forms.TextBox(); - this.btnLoad = new System.Windows.Forms.Button(); - this.grpFile = new System.Windows.Forms.GroupBox(); - this.pnlScrollData = new CsvView.UI.DoubleBufferPanel(); - this.pnlData = new CsvView.UI.DoubleBufferPanel(); - this.pnlReg = new CsvView.UI.DoubleBufferPanel(); - this.btnPrevReg = new System.Windows.Forms.Button(); - this.tblRegNumbers = new System.Windows.Forms.TableLayoutPanel(); - this.txtCurrentReg = new System.Windows.Forms.TextBox(); - this.txtTotalRegs = new System.Windows.Forms.TextBox(); - this.btnFirstReg = new System.Windows.Forms.Button(); - this.btnLastReg = new System.Windows.Forms.Button(); - this.btnNextReg = new System.Windows.Forms.Button(); - this.grpFile.SuspendLayout(); - this.pnlScrollData.SuspendLayout(); - this.pnlReg.SuspendLayout(); - this.tblRegNumbers.SuspendLayout(); - this.SuspendLayout(); - // - // txtPath - // - this.txtPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtPath.Location = new System.Drawing.Point(5, 18); - this.txtPath.Name = "txtPath"; - this.txtPath.Size = new System.Drawing.Size(452, 20); - this.txtPath.TabIndex = 0; - this.txtPath.DoubleClick += new System.EventHandler(this.txtPath_DoubleClick); - // - // btnLoad - // - this.btnLoad.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnLoad.Location = new System.Drawing.Point(461, 18); - this.btnLoad.Name = "btnLoad"; - this.btnLoad.Size = new System.Drawing.Size(45, 20); - this.btnLoad.TabIndex = 3; - this.btnLoad.Text = "Load"; - this.btnLoad.UseVisualStyleBackColor = true; - this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); - // - // grpFile - // - this.grpFile.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.grpFile.Controls.Add(this.btnLoad); - this.grpFile.Controls.Add(this.txtPath); - this.grpFile.Location = new System.Drawing.Point(13, 8); - this.grpFile.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.grpFile.Name = "grpFile"; - this.grpFile.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.grpFile.Size = new System.Drawing.Size(511, 44); - this.grpFile.TabIndex = 12; - this.grpFile.TabStop = false; - this.grpFile.Text = "File"; - // - // pnlScrollData - // - this.pnlScrollData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pnlScrollData.AutoScroll = true; - this.pnlScrollData.Controls.Add(this.pnlData); - this.pnlScrollData.DisableAutoScroll = true; - this.pnlScrollData.Location = new System.Drawing.Point(13, 85); - this.pnlScrollData.Margin = new System.Windows.Forms.Padding(2); - this.pnlScrollData.Name = "pnlScrollData"; - this.pnlScrollData.Size = new System.Drawing.Size(511, 429); - this.pnlScrollData.TabIndex = 12; - // - // pnlData - // - this.pnlData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pnlData.BackColor = System.Drawing.SystemColors.Control; - this.pnlData.DisableAutoScroll = true; - this.pnlData.Location = new System.Drawing.Point(0, 1); - this.pnlData.Name = "pnlData"; - this.pnlData.Size = new System.Drawing.Size(511, 51); - this.pnlData.TabIndex = 11; - // - // pnlReg - // - this.pnlReg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pnlReg.BackColor = System.Drawing.SystemColors.Control; - this.pnlReg.Controls.Add(this.btnPrevReg); - this.pnlReg.Controls.Add(this.tblRegNumbers); - this.pnlReg.Controls.Add(this.btnFirstReg); - this.pnlReg.Controls.Add(this.btnLastReg); - this.pnlReg.Controls.Add(this.btnNextReg); - this.pnlReg.Enabled = false; - this.pnlReg.Location = new System.Drawing.Point(14, 57); - this.pnlReg.Name = "pnlReg"; - this.pnlReg.Size = new System.Drawing.Size(510, 456); - this.pnlReg.TabIndex = 11; - // - // btnPrevReg - // - this.btnPrevReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnPrevReg.Location = new System.Drawing.Point(41, 0); - this.btnPrevReg.Name = "btnPrevReg"; - this.btnPrevReg.Size = new System.Drawing.Size(36, 23); - this.btnPrevReg.TabIndex = 5; - this.btnPrevReg.Text = "<"; - this.btnPrevReg.UseVisualStyleBackColor = true; - this.btnPrevReg.Click += new System.EventHandler(this.btnPrevReg_Click); - // - // tblRegNumbers - // - this.tblRegNumbers.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tblRegNumbers.ColumnCount = 2; - this.tblRegNumbers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tblRegNumbers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tblRegNumbers.Controls.Add(this.txtCurrentReg, 0, 0); - this.tblRegNumbers.Controls.Add(this.txtTotalRegs, 1, 0); - this.tblRegNumbers.Location = new System.Drawing.Point(83, 0); - this.tblRegNumbers.Name = "tblRegNumbers"; - this.tblRegNumbers.RowCount = 1; - this.tblRegNumbers.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tblRegNumbers.Size = new System.Drawing.Size(345, 28); - this.tblRegNumbers.TabIndex = 10; - // - // txtCurrentReg - // - this.txtCurrentReg.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtCurrentReg.Location = new System.Drawing.Point(3, 3); - this.txtCurrentReg.Name = "txtCurrentReg"; - this.txtCurrentReg.Size = new System.Drawing.Size(166, 20); - this.txtCurrentReg.TabIndex = 8; - this.txtCurrentReg.TextChanged += new System.EventHandler(this.txtCurrentReg_TextChanged); - // - // txtTotalRegs - // - this.txtTotalRegs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtTotalRegs.Location = new System.Drawing.Point(175, 3); - this.txtTotalRegs.Name = "txtTotalRegs"; - this.txtTotalRegs.ReadOnly = true; - this.txtTotalRegs.Size = new System.Drawing.Size(167, 20); - this.txtTotalRegs.TabIndex = 9; - // - // btnFirstReg - // - this.btnFirstReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnFirstReg.Location = new System.Drawing.Point(0, 0); - this.btnFirstReg.Name = "btnFirstReg"; - this.btnFirstReg.Size = new System.Drawing.Size(36, 23); - this.btnFirstReg.TabIndex = 4; - this.btnFirstReg.Text = "|<"; - this.btnFirstReg.UseVisualStyleBackColor = true; - this.btnFirstReg.Click += new System.EventHandler(this.btnFirstReg_Click); - // - // btnLastReg - // - this.btnLastReg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnLastReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnLastReg.Location = new System.Drawing.Point(474, 0); - this.btnLastReg.Name = "btnLastReg"; - this.btnLastReg.Size = new System.Drawing.Size(36, 23); - this.btnLastReg.TabIndex = 7; - this.btnLastReg.Text = ">|"; - this.btnLastReg.UseVisualStyleBackColor = true; - this.btnLastReg.Click += new System.EventHandler(this.btnLastReg_Click); - // - // btnNextReg - // - this.btnNextReg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnNextReg.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnNextReg.Location = new System.Drawing.Point(433, 0); - this.btnNextReg.Name = "btnNextReg"; - this.btnNextReg.Size = new System.Drawing.Size(36, 23); - this.btnNextReg.TabIndex = 6; - this.btnNextReg.Text = ">"; - this.btnNextReg.UseVisualStyleBackColor = true; - this.btnNextReg.Click += new System.EventHandler(this.btnNextReg_Click); - // - // FrmCsvViewer - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(532, 521); - this.Controls.Add(this.pnlScrollData); - this.Controls.Add(this.grpFile); - this.Controls.Add(this.pnlReg); - this.Name = "FrmCsvViewer"; - this.Text = "CsvViewer"; - this.grpFile.ResumeLayout(false); - this.grpFile.PerformLayout(); - this.pnlScrollData.ResumeLayout(false); - this.pnlReg.ResumeLayout(false); - this.tblRegNumbers.ResumeLayout(false); - this.tblRegNumbers.PerformLayout(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.TextBox txtPath; - private System.Windows.Forms.Button btnLoad; - private System.Windows.Forms.Button btnFirstReg; - private System.Windows.Forms.Button btnPrevReg; - private System.Windows.Forms.Button btnNextReg; - private System.Windows.Forms.Button btnLastReg; - private System.Windows.Forms.TextBox txtCurrentReg; - private System.Windows.Forms.TextBox txtTotalRegs; - private System.Windows.Forms.TableLayoutPanel tblRegNumbers; - private CsvView.UI.DoubleBufferPanel pnlReg; - private CsvView.UI.DoubleBufferPanel pnlData; - private System.Windows.Forms.GroupBox grpFile; - private CsvView.UI.DoubleBufferPanel pnlScrollData; - } -} - diff --git a/UI/FrmCsvViewer.cs b/UI/FrmCsvViewer.cs deleted file mode 100644 index ad4eea5..0000000 --- a/UI/FrmCsvViewer.cs +++ /dev/null @@ -1,203 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Windows.Forms; -using CsvLib; - -namespace CsvView.UI -{ - public partial class FrmCsvViewer : Form - { - public FrmCsvViewer() - { - InitializeComponent(); - } - - private void txtPath_DoubleClick(object sender, EventArgs e) - { - OpenFileDialog loadDialog = new OpenFileDialog(); - loadDialog.InitialDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); - loadDialog.DefaultExt = "csv"; - loadDialog.Filter = "CSV Files|*.csv|Any File|*"; - DialogResult result = loadDialog.ShowDialog(); - if (result == DialogResult.OK) - { - txtPath.Text = loadDialog.FileName; - } - } - - private string _loadedFile = string.Empty; - private long _currentReg; - private long _totalRegs; - private List _index; - - private void btnLoad_Click(object sender, EventArgs e) - { - if (File.Exists(txtPath.Text) == false) - { - RenderRegClean(); - _loadedFile = null; - _totalRegs = 0; - _index = null; - MessageBoxEx.Show(this, "FileNotFound"); - return; - } - - LoadFile(txtPath.Text); - } - - public void LoadFile(string fileName) - { - _loadedFile = fileName; - txtPath.Text = fileName; - - CsvIndexer csvIndexer = new CsvIndexer(); - csvIndexer.LoadIndexOfFile(_loadedFile); - _index = csvIndexer.Index; - _totalRegs = _index.Count - 1; - - RenderReg(0); - } - - private List Index_LoadReg(int idx) - { - var csvParser = new CsvParser(); - csvParser.ParseFile(_loadedFile, _index[idx], 1); - return csvParser.Data[0]; - } - - bool _rendering; - private void RenderReg(long currentReg) - { - if (_index == null || _index.Count <= 0) - { - RenderRegClean(); - } - - if (_rendering) { return; } - _rendering = true; - - pnlReg.Enabled = true; - bool first = false; - bool last = false; - if (currentReg <= 0) - { - currentReg = 0; - first = true; - } - if (currentReg >= (_totalRegs - 1)) - { - currentReg = _totalRegs - 1; - last = true; - } - - pnlScrollData.SuspendDrawing(); - pnlScrollData.VerticalScroll.Value = 0; - pnlData.Height = 10; - - pnlData.Controls.Clear(); - _currentReg = currentReg; - txtCurrentReg.Text = Convert.ToString(currentReg); - txtTotalRegs.Text = Convert.ToString(_totalRegs); - - btnFirstReg.Enabled = (first == false); - btnPrevReg.Enabled = (first == false); - btnLastReg.Enabled = (last == false); - btnNextReg.Enabled = (last == false); - - List currentData = Index_LoadReg((int)currentReg); - - int y = 0; - const int textBoxPadding = 5; - const int paddingLeft = 0; - const int paddingRight = 0; - const int paddingBetween = 10; - const int lineHeight = 15; - for (int i = 0; i < currentData.Count; i++) - { - TextBox txtValue = RenderValue(currentData[i], y, textBoxPadding, paddingLeft, paddingRight, lineHeight); - pnlData.Controls.Add(txtValue); - y += txtValue.Height + paddingBetween; - } - pnlData.Height = y; - - pnlScrollData.ResumeDrawing(); - _rendering = false; - } - - private TextBox RenderValue(string value, int y, int textBoxPadding, int paddingLeft, int paddingRight, int lineHeight) - { - string[] valueLines = value.Split('\n'); - CTextBox txtValue = new CTextBox() - { - Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right), - Width = pnlData.Width - (paddingLeft + paddingRight), - Height = (valueLines.Length * lineHeight) + textBoxPadding, - Multiline = (valueLines.Length > 1), - Top = y, - Left = paddingLeft, - ReadOnly = true, - }; - for (int j = 0; j < valueLines.Length; j++) - { - if (j > 0) - { - txtValue.AppendText("\n"); - } - txtValue.AppendText(valueLines[j]); - } - return txtValue; - } - - private void RenderRegClean() - { - if (_rendering) { return; } - _rendering = true; - - pnlScrollData.SuspendDrawing(); - pnlScrollData.VerticalScroll.Value = 0; - pnlData.Height = 10; - - pnlData.Controls.Clear(); - pnlReg.Enabled = false; - txtCurrentReg.Text = string.Empty; - txtTotalRegs.Text = string.Empty; - - pnlScrollData.ResumeDrawing(); - _rendering = false; - } - - private void btnFirstReg_Click(object sender, EventArgs e) - { - RenderReg(0); - } - - private void btnPrevReg_Click(object sender, EventArgs e) - { - RenderReg(_currentReg - 1); - } - - private void btnNextReg_Click(object sender, EventArgs e) - { - RenderReg(_currentReg + 1); - } - - private void btnLastReg_Click(object sender, EventArgs e) - { - RenderReg(_totalRegs - 1); - } - - private void txtCurrentReg_TextChanged(object sender, EventArgs e) - { - int newReg = 0; - if (int.TryParse(txtCurrentReg.Text, out newReg)) - { - RenderReg(newReg); - } - else - { - RenderReg(_currentReg); - } - } - } -} diff --git a/UI/MessageBoxEx.cs b/UI/MessageBoxEx.cs deleted file mode 100644 index 7723e81..0000000 --- a/UI/MessageBoxEx.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Windows.Forms; - -namespace CsvView.UI -{ - public static class MessageBoxEx - { - public static DialogResult Show(string text) - { - Initialize(); - return MessageBox.Show(text); - } - - public static DialogResult Show(string text, string caption) - { - Initialize(); - return MessageBox.Show(text, caption); - } - - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons) - { - Initialize(); - return MessageBox.Show(text, caption, buttons); - } - - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) - { - Initialize(); - return MessageBox.Show(text, caption, buttons, icon); - } - - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton) - { - Initialize(); - return MessageBox.Show(text, caption, buttons, icon, defButton); - } - - public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options) - { - Initialize(); - return MessageBox.Show(text, caption, buttons, icon, defButton, options); - } - - public static DialogResult Show(IWin32Window owner, string text) - { - Initialize(); - return MessageBox.Show(owner, text); - } - - public static DialogResult Show(IWin32Window owner, string text, string caption) - { - Initialize(); - return MessageBox.Show(owner, text, caption); - } - - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons) - { - Initialize(); - return MessageBox.Show(owner, text, caption, buttons); - } - - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) - { - Initialize(); - return MessageBox.Show(owner, text, caption, buttons, icon); - } - - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton) - { - Initialize(); - return MessageBox.Show(owner, text, caption, buttons, icon, defButton); - } - - public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options) - { - Initialize(); - return MessageBox.Show(owner, text, caption, buttons, icon, - defButton, options); - } - - private static void Initialize() - { - - } - - } -} \ No newline at end of file diff --git a/app.manifest b/app.manifest deleted file mode 100644 index 6c647ae..0000000 --- a/app.manifest +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - -