Skip to content

Commit

Permalink
lepší práce s názvem souboru
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Oct 2, 2024
1 parent 4fb44f6 commit 9419de5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ZZZO/ZZZO.Common/API/Zasedani.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public string VystupniSoubor
{
_vystupniSoubor = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
$"zápis-{DatumKonani:yyyy-MM}-zo");
$"zo-{DatumKonani:yyyy-MM}");
}

return _vystupniSoubor;
Expand Down
2 changes: 1 addition & 1 deletion ZZZO/ZZZO/Converters/EnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public object ConvertBack(object value, Type targetType, object parameter,

#region Metody

private static string GetEnumDescription(Enum value)
public static string GetEnumDescription(Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());

Expand Down
11 changes: 8 additions & 3 deletions ZZZO/ZZZO/ViewModels/GeneratorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.IO;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Input;
using CefSharp;
using CefSharp.Wpf;
using ZZZO.Commands;
using ZZZO.Common;
using ZZZO.Common.Generators;
using static ZZZO.Common.Generators.Generator;
using EnumConverter = ZZZO.Converters.EnumConverter;

namespace ZZZO.ViewModels
{
Expand Down Expand Up @@ -197,7 +200,8 @@ public GeneratorViewModel(ZzzoCore core)
private void ExportHtml()
{
string html = GeneratedHtml;
string file = ZzzoCore.ChooseSaveFile(Core.Zasedani, "html", true);
string suffix = EnumConverter.GetEnumDescription(SelectedKindOfDocument).ToLower();
string file = ZzzoCore.ChooseSaveFile(Core.Zasedani, "html", true, suffix);

if (!string.IsNullOrWhiteSpace(file))
{
Expand All @@ -214,7 +218,8 @@ private void ExportHtml()

private async void ExportPdf(ChromiumWebBrowser browser)
{
string file = ZzzoCore.ChooseSaveFile(Core.Zasedani, "pdf", true);
string suffix = EnumConverter.GetEnumDescription(SelectedKindOfDocument).ToLower();
string file = ZzzoCore.ChooseSaveFile(Core.Zasedani, "pdf", true, suffix);

if (!string.IsNullOrWhiteSpace(file))
{
Expand Down
15 changes: 13 additions & 2 deletions ZZZO/ZZZO/ZzzoCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ public static string ChooseSaveFile(
Zasedani zasedani,
string fileSuffix,
bool forceChooseFile,
string fileNameSuffix = null,
string title = null)
{
string initialFullPath = (zasedani?.VystupniSoubor ?? string.Empty) + $".{fileSuffix}";
string initialFullPath = (zasedani?.VystupniSoubor ?? string.Empty) +
(!string.IsNullOrWhiteSpace(fileNameSuffix) ? $"-{fileNameSuffix}" : string.Empty) +
$".{fileSuffix}";

if (!forceChooseFile && File.Exists(initialFullPath))
{
Expand All @@ -105,7 +108,10 @@ public static string ChooseSaveFile(
if (zasedani != null && !string.IsNullOrWhiteSpace(zasedani.VystupniSoubor))
{
string initialDirectory = Path.GetDirectoryName(zasedani.VystupniSoubor);
string initialFileName = Path.GetFileName(zasedani.VystupniSoubor) + $".{fileSuffix}";

string initialFileName = string.IsNullOrWhiteSpace(fileNameSuffix)
? Path.GetFileName(zasedani.VystupniSoubor) + $".{fileSuffix}"
: $"{Path.GetFileName(zasedani.VystupniSoubor)}-{fileNameSuffix}" + $".{fileSuffix}";

d.InitialDirectory = initialDirectory != null && Directory.Exists(initialDirectory) ? initialDirectory : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
d.FileName = initialFileName;
Expand All @@ -118,6 +124,11 @@ public static string ChooseSaveFile(
string chosenDir = Path.GetDirectoryName(d.FileName);
string chosenFile = Path.GetFileNameWithoutExtension(d.FileName);

if (!string.IsNullOrWhiteSpace(fileNameSuffix) && chosenFile.EndsWith($"-{fileNameSuffix}"))
{
chosenFile = chosenFile.Substring(0, chosenFile.Length - fileNameSuffix.Length - 1);
}

zasedani.VystupniSoubor = Path.Combine(chosenDir, chosenFile);
}

Expand Down

0 comments on commit 9419de5

Please sign in to comment.