fix(desktop): let markdown changes reflect immediately

This commit is contained in:
Anna 2020-11-12 14:26:01 -05:00
parent 0416c9efaa
commit 7377da1bfd
6 changed files with 35 additions and 16 deletions

View File

@ -9,6 +9,7 @@ using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using XIVChatCommon;
namespace XIVChat_Desktop {
@ -127,8 +128,9 @@ namespace XIVChat_Desktop {
}
[JsonObject]
public class Tab : IEnumerable<ServerMessage>, INotifyCollectionChanged {
public class Tab : IEnumerable<ServerMessage>, INotifyCollectionChanged, INotifyPropertyChanged {
private string name;
private bool processMarkdown;
public Tab(string name) {
this.name = name;
@ -138,12 +140,19 @@ namespace XIVChat_Desktop {
get => this.name;
set {
this.name = value;
this.OnPropertyChanged(nameof(this.Name));
}
}
public Filter Filter { get; set; } = new Filter();
public bool ProcessMarkdown { get; set; }
public bool ProcessMarkdown {
get => this.processMarkdown;
set {
this.processMarkdown = value;
this.OnPropertyChanged(nameof(this.ProcessMarkdown));
}
}
[JsonIgnore]
public List<ServerMessage> Messages { get; } = new List<ServerMessage>();
@ -261,6 +270,11 @@ namespace XIVChat_Desktop {
}
public event NotifyCollectionChangedEventHandler? CollectionChanged;
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
[JsonObject]

View File

@ -16,16 +16,16 @@ namespace XIVChat_Desktop.Controls {
set => this.SetValue(MessageProperty, value);
}
public static readonly DependencyProperty TabProperty = DependencyProperty.Register(
"Tab",
typeof(Tab),
public static readonly DependencyProperty ProcessMarkdownProperty = DependencyProperty.Register(
"ProcessMarkdown",
typeof(bool),
typeof(MessageTextBlock),
new PropertyMetadata(null, PropertyChanged)
new PropertyMetadata(false, PropertyChanged)
);
public Tab? Tab {
get => (Tab)this.GetValue(TabProperty);
set => this.SetValue(TabProperty, value);
public bool ProcessMarkdown {
get => (bool)this.GetValue(ProcessMarkdownProperty);
set => this.SetValue(ProcessMarkdownProperty, value);
}
public static readonly DependencyProperty ShowTimestampsProperty = DependencyProperty.Register(
@ -47,9 +47,8 @@ namespace XIVChat_Desktop.Controls {
}
var message = textBlock.Message;
var tab = textBlock.Tab;
if (message == null || tab == null) {
if (message == null) {
return;
}
@ -58,7 +57,13 @@ namespace XIVChat_Desktop.Controls {
// Create new formatted text
var lineHeight = textBlock.FontFamily.LineSpacing * textBlock.FontSize;
foreach (var inline in MessageFormatter.ChunksToTextBlock(lineHeight, message, tab.ProcessMarkdown, textBlock.ShowTimestamps)) {
var inlines = MessageFormatter.ChunksToTextBlock(
message,
lineHeight,
textBlock.ProcessMarkdown,
textBlock.ShowTimestamps
);
foreach (var inline in inlines) {
textBlock.Inlines.Add(inline);
}
}

View File

@ -49,7 +49,7 @@
<cc:MessageTextBlock FontFamily="Global User Interface, /fonts/#XIV AXIS Std ATK"
TextWrapping="Wrap"
FontSize="{Binding App.Config.FontSize, ElementName=Main, UpdateSourceTrigger=PropertyChanged}"
Tab="{Binding ExportTab, ElementName=Main}"
ProcessMarkdown="{Binding ExportTab.ProcessMarkdown, ElementName=Main}"
Message="{Binding .}"
ShowTimestamps="{Binding ShowTimestamps, ElementName=Main}" />
</DataTemplate>

View File

@ -256,7 +256,7 @@ namespace XIVChat_Desktop {
this.Dispatch(DispatcherPriority.Background, () => {
var paragraph = new Paragraph();
// this has to be done on the main thread
var inlines = MessageFormatter.ChunksToTextBlock(this.App.Config.FontSize, message, this.ExportTab.ProcessMarkdown, this.ShowTimestamps);
var inlines = MessageFormatter.ChunksToTextBlock(message, this.App.Config.FontSize, this.ExportTab.ProcessMarkdown, this.ShowTimestamps);
paragraph.Inlines.AddRange(inlines);
flow.Blocks.Add(paragraph);
});

View File

@ -95,7 +95,7 @@
<cc:MessageTextBlock FontFamily="Global User Interface, /fonts/#XIV AXIS Std ATK"
TextWrapping="Wrap"
FontSize="{Binding App.Config.FontSize, ElementName=Main, UpdateSourceTrigger=PropertyChanged}"
Tab="{Binding DataContext, ElementName=TabGrid}"
ProcessMarkdown="{Binding DataContext.ProcessMarkdown, ElementName=TabGrid}"
Message="{Binding .}" />
</DataTemplate>
</ItemsControl.ItemTemplate>

View File

@ -45,7 +45,7 @@ namespace XIVChat_Desktop {
// }
// }
public static IEnumerable<Inline> ChunksToTextBlock(double lineHeight, ServerMessage message, bool processMarkdown, bool showTimestamp) {
public static IEnumerable<Inline> ChunksToTextBlock(ServerMessage message, double lineHeight, bool processMarkdown, bool showTimestamp) {
var elements = new List<Inline>();
if (showTimestamp) {