Skip to content

Commit

Permalink
Fixed autosize of MemoEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Jun 19, 2024
1 parent 14dedc8 commit b3ef12d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 138 deletions.
4 changes: 4 additions & 0 deletions AudioCuesheetEditor/AudioCuesheetEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,9 @@
<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions AudioCuesheetEditor/Extensions/SessionStateContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ public ViewMode CurrentViewMode
}
}

public IImportfile? Importfile
{
get
{
if (TextImportFile != null)
{
return TextImportFile;
}
if (CuesheetImportFile != null)
{
return CuesheetImportFile;
}
return null;
}
}

public void ResetImport()
{
TextImportFile = null;
Expand Down
15 changes: 6 additions & 9 deletions AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@

namespace AudioCuesheetEditor.Model.IO.Import
{
public class CuesheetImportfile
public class CuesheetImportfile : IImportfile
{
private IEnumerable<String?> fileContent;

public EventHandler? AnalysisFinished;

/// <summary>
/// File content (each element is a file line)
/// </summary>
/// <inheritdoc />
public IEnumerable<String?> FileContent
{
get => fileContent;
Expand All @@ -39,16 +37,15 @@ public IEnumerable<String?> FileContent
}
}

/// <summary>
/// File content with marking which passages has been reconized by scheme
/// </summary>
public IEnumerable<String?>? FileContentRecognized { get; private set; }
/// <inheritdoc />
public IEnumerable<String?> FileContentRecognized { get; private set; }
public Exception? AnalyseException { get; private set; }
public Cuesheet? Cuesheet { get; private set; }
public ApplicationOptions ApplicationOptions { get; private set; }

public CuesheetImportfile(MemoryStream fileContentStream, ApplicationOptions applicationOptions)
{
FileContentRecognized = [];
fileContentStream.Position = 0;
using var reader = new StreamReader(fileContentStream);
List<String?> lines = [];
Expand Down Expand Up @@ -321,7 +318,7 @@ private void Analyse()
{
AnalyseException = ex;
Cuesheet = null;
FileContentRecognized = null;
FileContentRecognized = FileContent;
}
AnalysisFinished?.Invoke(this, EventArgs.Empty);
}
Expand Down
29 changes: 29 additions & 0 deletions AudioCuesheetEditor/Model/IO/Import/IImportfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//AudioCuesheetEditor is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
namespace AudioCuesheetEditor.Model.IO.Import
{
public interface IImportfile
{
/// <summary>
/// File content (each element is a file line)
/// </summary>
public IEnumerable<String?> FileContent { get; set; }
/// <summary>
/// File content with marking which passages has been reconized by scheme
/// </summary>
public IEnumerable<String?> FileContentRecognized { get; }
}
}
15 changes: 6 additions & 9 deletions AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace AudioCuesheetEditor.Model.IO.Import
{
public class TextImportfile : IDisposable
public class TextImportfile : IImportfile, IDisposable
{
public const String MimeType = "text/plain";
public const String FileExtension = ".txt";
Expand All @@ -36,6 +36,7 @@ public class TextImportfile : IDisposable

public TextImportfile(MemoryStream fileContentStream, ImportOptions? importOptions = null)
{
FileContentRecognized = [];
textImportScheme = new TextImportScheme();
fileContent = [];
fileContentStream.Position = 0;
Expand All @@ -61,9 +62,7 @@ public TextImportfile(MemoryStream fileContentStream, ImportOptions? importOptio
}
}

/// <summary>
/// File content (each element is a file line)
/// </summary>
/// <inheritdoc />
public IEnumerable<String?> FileContent
{
get => fileContent;
Expand All @@ -74,10 +73,8 @@ public IEnumerable<String?> FileContent
}
}

/// <summary>
/// File content with marking which passages has been reconized by scheme
/// </summary>
public IEnumerable<String?>? FileContentRecognized { get; private set; }
/// <inheritdoc />
public IEnumerable<String?> FileContentRecognized { get; private set; }

public TextImportScheme TextImportScheme
{
Expand Down Expand Up @@ -133,7 +130,7 @@ private void Analyse()
try
{
Cuesheet = new Cuesheet();
FileContentRecognized = null;
FileContentRecognized = [];
AnalyseException = null;
Boolean cuesheetRecognized = false;
List<String?> recognizedFileContent = [];
Expand Down
42 changes: 30 additions & 12 deletions AudioCuesheetEditor/Pages/ImportFileView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ along with Foobar. If not, see
@implements IDisposable

@inject ITextLocalizer<ImportFileView> _localizer
@inject ImportManager _importManager
@inject SessionStateContainer _sessionStateContainer

<Card>
<CardHeader>
<Tabs @bind-SelectedTab="selectedTab">
<Tabs SelectedTab="@selectedTab" SelectedTabChanged="SelectedTabChanged">
<Items>
<Tab Name="recognizedFilecontent">@_localizer["Preview"]</Tab>
<Tab Name="editFilecontent">@_localizer["Edit"]</Tab>
Expand All @@ -33,10 +33,10 @@ along with Foobar. If not, see
<TabsContent @bind-SelectedPanel="selectedTab">
<TabPanel Name="recognizedFilecontent">
<Text>
@if (_importManager.FileContentRecognized != null)
@if (FileContentRecognized != null)
{
<pre>
@foreach (var line in _importManager.FileContentRecognized)
@foreach (var line in FileContentRecognized)
{
if (line != null)
{
Expand All @@ -48,36 +48,54 @@ along with Foobar. If not, see
</Text>
</TabPanel>
<TabPanel Name="editFilecontent">
<MemoEdit Text="@_importManager.FileContent" TextChanged="FileContent_TextChanged" />
<MemoEdit Text="@fileContent" TextChanged="FileContent_TextChanged" AutoSize />
</TabPanel>
</TabsContent>
</CardBody>
</Card>

@code {
//TODO: FileContent height
//TODO: Enable input of tabs
String selectedTab = "recognizedFilecontent";
String? fileContent;

public IEnumerable<String?>? FileContentRecognized => _sessionStateContainer.Importfile?.FileContentRecognized;

public void Dispose()
{
_importManager.FileContentChanged -= ImportManager_FileContentChanged;
_sessionStateContainer.ImportCuesheetChanged -= SessionStateContainer_ImportCuesheetChanged;
}

protected override void OnInitialized()
{
base.OnInitialized();
_importManager.FileContentChanged += ImportManager_FileContentChanged;
_sessionStateContainer.ImportCuesheetChanged += SessionStateContainer_ImportCuesheetChanged;
}

void SelectedTabChanged(string newTabName)
{
selectedTab = newTabName;
fileContent = null;
if (newTabName == "editFilecontent")
{
//Set fileContent just when component is visible in order to autosize the MemoEdit
if (_sessionStateContainer.Importfile != null)
{
fileContent = String.Join(Environment.NewLine, _sessionStateContainer.Importfile.FileContent);
}
}
}

void ImportManager_FileContentChanged(object? sender, EventArgs args)
void SessionStateContainer_ImportCuesheetChanged(object? sender, EventArgs e)
{
StateHasChanged();
}

void FileContent_TextChanged(string text)
{
_importManager.FileContent = text;
var fileContentValue = text?.Split(Environment.NewLine);
if ((fileContentValue != null) && (_sessionStateContainer.Importfile != null))
{
_sessionStateContainer.Importfile.FileContent = fileContentValue;
}
}
}
2 changes: 0 additions & 2 deletions AudioCuesheetEditor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using AudioCuesheetEditor.Extensions;
using AudioCuesheetEditor.Model.UI;
using AudioCuesheetEditor.Model.Utility;
using AudioCuesheetEditor.Services.IO;
using BlazorDownloadFile;
using Blazorise;
using Blazorise.Bootstrap5;
Expand Down Expand Up @@ -52,7 +51,6 @@
builder.Services.AddScoped<SessionStateContainer>();
builder.Services.AddScoped<TraceChangeManager>();
builder.Services.AddScoped<DateTimeUtility>();
builder.Services.AddScoped<ImportManager>();

builder.Services.AddLogging();
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
Expand Down
105 changes: 0 additions & 105 deletions AudioCuesheetEditor/Services/IO/ImportManager.cs

This file was deleted.

1 change: 0 additions & 1 deletion AudioCuesheetEditor/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@using AudioCuesheetEditor.Data.Options
@using AudioCuesheetEditor.Model.Utility
@using AudioCuesheetEditor.Data.Services
@using AudioCuesheetEditor.Services.IO
@using Microsoft.Extensions.Logging
@using Blazorise
@using Blazorise.Components
Expand Down

0 comments on commit b3ef12d

Please sign in to comment.