Немного работы
This commit is contained in:
@@ -8,6 +8,7 @@ using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Base;
|
||||
using Pf2eModel.Model.Common.I18n;
|
||||
using Pf2eModel.Model.Enum;
|
||||
using Pf2eViewer.Converters;
|
||||
|
||||
namespace Pf2eViewer;
|
||||
|
||||
@@ -15,12 +16,22 @@ public partial class MainViewForm : Form
|
||||
{
|
||||
public Pf2eDbContext Context = new();
|
||||
|
||||
public string JsonViewerHtml = string.Empty;
|
||||
|
||||
private DarkModeCS dm = null;
|
||||
|
||||
public MainViewForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
dm = new DarkModeCS(this) { ColorMode = DarkModeCS.DisplayMode.SystemDefault };
|
||||
|
||||
Reset();
|
||||
|
||||
EntityGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
|
||||
using StreamReader reader = new("Resources/json-viewer.html");
|
||||
JsonViewerHtml = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
@@ -50,7 +61,7 @@ public partial class MainViewForm : Form
|
||||
|
||||
private void UpdateTreeView()
|
||||
{
|
||||
EntityTreeView.Nodes.Clear();
|
||||
// EntityTreeView.Nodes.Clear();
|
||||
EntityType type = (EntityType)TypesListBox.SelectedItem!;
|
||||
|
||||
Count = Context.Entities.Count(e => e.Type == type);
|
||||
@@ -142,7 +153,7 @@ public partial class MainViewForm : Form
|
||||
|
||||
public void ViewEntity(int id)
|
||||
{
|
||||
EntityTreeView.Nodes.Clear();
|
||||
// EntityTreeView.Nodes.Clear();
|
||||
|
||||
Entity? entity = Context
|
||||
.Entities.Where(e => e.Id == id && e.Type == (EntityType)TypesListBox.SelectedItem!)
|
||||
@@ -163,19 +174,47 @@ public partial class MainViewForm : Form
|
||||
|
||||
string json = SerializeEntity(entity);
|
||||
|
||||
JsonToTreeview(EntityTreeView, json, "Entity");
|
||||
// JsonToTreeview(EntityTreeView, json, "Entity");
|
||||
|
||||
RenderJson(json);
|
||||
|
||||
DescriptionTextBox.Text = entity.Description.Replace("\\r", "").Replace("\\n", "\\r\\n");
|
||||
}
|
||||
|
||||
public void RenderJson(string json)
|
||||
{
|
||||
if (JsonWebView.CoreWebView2 == null)
|
||||
{
|
||||
JsonWebView.EnsureCoreWebView2Async();
|
||||
return;
|
||||
}
|
||||
|
||||
string html = JsonViewerHtml.Replace("{JSON}", json);
|
||||
JsonWebView.CoreWebView2.NavigateToString(html);
|
||||
}
|
||||
|
||||
private void JsonWebView_CoreWebView2InitializationCompleted(
|
||||
object sender,
|
||||
Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e
|
||||
)
|
||||
{
|
||||
JsonWebView.Visible = true;
|
||||
DataGridViewRow row = EntityGridView.SelectedRows[0];
|
||||
|
||||
EntityGridRow data = (EntityGridRow)row.DataBoundItem;
|
||||
|
||||
ViewEntity(data.Id);
|
||||
}
|
||||
|
||||
public string SerializeEntity(Entity entity)
|
||||
{
|
||||
JsonSerializerSettings settings = new()
|
||||
{
|
||||
Converters =
|
||||
[
|
||||
new EntityConverter(),
|
||||
new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() },
|
||||
new EntityConverter(),
|
||||
new LocaleStringConverter(),
|
||||
],
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user