mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-24 03:36:52 -04:00
Add support for custom date formats in settings
This commit is contained in:
parent
efae0e99b8
commit
69184a74fe
6 changed files with 32 additions and 7 deletions
|
@ -12,9 +12,9 @@ namespace DiscordChatExporter
|
|||
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
|
||||
|
||||
// Services
|
||||
SimpleIoc.Default.Register<IDataService, DataService>(true);
|
||||
SimpleIoc.Default.Register<IExportService, ExportService>(true);
|
||||
SimpleIoc.Default.Register<ISettingsService, SettingsService>(true);
|
||||
SimpleIoc.Default.Register<IDataService, DataService>();
|
||||
SimpleIoc.Default.Register<IExportService, ExportService>();
|
||||
SimpleIoc.Default.Register<ISettingsService, SettingsService>();
|
||||
|
||||
// View models
|
||||
SimpleIoc.Default.Register<IErrorViewModel, ErrorViewModel>(true);
|
||||
|
|
|
@ -12,10 +12,18 @@ namespace DiscordChatExporter.Services
|
|||
{
|
||||
public partial class ExportService : IExportService
|
||||
{
|
||||
private readonly ISettingsService _settingsService;
|
||||
|
||||
public ExportService(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
|
||||
public void Export(string filePath, ChannelChatLog channelChatLog, Theme theme)
|
||||
{
|
||||
var doc = GetTemplate();
|
||||
var style = GetStyle(theme);
|
||||
var dateFormat = _settingsService.DateFormat;
|
||||
|
||||
// Set theme
|
||||
var themeHtml = doc.GetElementbyId("theme");
|
||||
|
@ -61,7 +69,7 @@ namespace DiscordChatExporter.Services
|
|||
messageRightHtml.AppendChild(HtmlNode.CreateNode($"<span class=\"msg-user\">{authorName}</span>"));
|
||||
|
||||
// Date
|
||||
var timeStamp = HtmlDocument.HtmlEncode(messageGroup.TimeStamp.ToString("g"));
|
||||
var timeStamp = HtmlDocument.HtmlEncode(messageGroup.TimeStamp.ToString(dateFormat));
|
||||
messageRightHtml.AppendChild(HtmlNode.CreateNode($"<span class=\"msg-date\">{timeStamp}</span>"));
|
||||
|
||||
// Individual messages
|
||||
|
@ -80,7 +88,7 @@ namespace DiscordChatExporter.Services
|
|||
{
|
||||
contentHtml.AppendChild(
|
||||
HtmlNode.CreateNode(
|
||||
$"<span class=\"msg-edited\" title=\"{message.EditedTimeStamp:g}\">(edited)</span>"));
|
||||
$"<span class=\"msg-edited\" title=\"{message.EditedTimeStamp.Value.ToString(dateFormat)}\">(edited)</span>"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +158,7 @@ namespace DiscordChatExporter.Services
|
|||
|
||||
private static string NormalizeFileSize(long fileSize)
|
||||
{
|
||||
string[] units = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||
string[] units = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
|
||||
double size = fileSize;
|
||||
var unit = 0;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace DiscordChatExporter.Services
|
|||
{
|
||||
string Token { get; set; }
|
||||
Theme Theme { get; set; }
|
||||
string DateFormat { get; set; }
|
||||
|
||||
void Load();
|
||||
void Save();
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace DiscordChatExporter.Services
|
|||
{
|
||||
public string Token { get; set; }
|
||||
public Theme Theme { get; set; }
|
||||
public string DateFormat { get; set; } = "dd-MMM-yy hh:mm";
|
||||
|
||||
public SettingsService()
|
||||
{
|
||||
|
|
|
@ -19,6 +19,12 @@ namespace DiscordChatExporter.ViewModels
|
|||
set => _settingsService.Theme = value;
|
||||
}
|
||||
|
||||
public string DateFormat
|
||||
{
|
||||
get => _settingsService.DateFormat;
|
||||
set => _settingsService.DateFormat = value;
|
||||
}
|
||||
|
||||
public SettingsViewModel(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
|
|
|
@ -7,7 +7,7 @@ UserControl "DiscordChatExporter.Views.SettingsDialog" {
|
|||
StackPanel {
|
||||
// Theme
|
||||
ComboBox {
|
||||
Margin: 16
|
||||
Margin: "16 16 16 8"
|
||||
HintAssist.Hint: "Theme"
|
||||
HintAssist.IsFloating: true
|
||||
IsReadOnly: true
|
||||
|
@ -15,6 +15,15 @@ UserControl "DiscordChatExporter.Views.SettingsDialog" {
|
|||
SelectedItem: bind Theme
|
||||
}
|
||||
|
||||
// Date format
|
||||
TextBox {
|
||||
Margin: "16 8 16 8"
|
||||
HintAssist.Hint: "Date format"
|
||||
HintAssist.IsFloating: true
|
||||
Text: bind DateFormat
|
||||
}
|
||||
|
||||
|
||||
// Save
|
||||
Button {
|
||||
Margin: 8
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue