Возврат к основной форме (но есть ошибка при запуске...)

This commit is contained in:
2025-04-30 19:50:30 +04:00
parent 5d3c06e921
commit 197a9862b3
8 changed files with 99 additions and 71 deletions
+14 -15
View File
@@ -1,4 +1,5 @@
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Pf2eModel; using Pf2eModel;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Common.I18n;
@@ -10,13 +11,7 @@ public partial class DatabaseViewerControl : UserControl
{ {
public readonly Pf2eDbContext Context = new(); public readonly Pf2eDbContext Context = new();
private int _perPage = 30; [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
private int _page = 1;
private EntityType _type;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int PerPage public int PerPage
{ {
get => _perPage; get => _perPage;
@@ -26,6 +21,7 @@ public partial class DatabaseViewerControl : UserControl
UpdateView(); UpdateView();
} }
} }
private int _perPage = 30;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int Page public int Page
@@ -37,14 +33,7 @@ public partial class DatabaseViewerControl : UserControl
UpdateView(); UpdateView();
} }
} }
private int _page = 1;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int Count { get; private set; }
public int MaxPage => Convert.ToInt32(Math.Ceiling(1.0 * Count / PerPage));
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public EntityView CurrentEntity { get; private set; } = null!;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public EntityType Type public EntityType Type
@@ -56,6 +45,16 @@ public partial class DatabaseViewerControl : UserControl
UpdateView(); UpdateView();
} }
} }
private EntityType _type;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int Count { get; private set; } = 0;
public int MaxPage => Convert.ToInt32(Math.Ceiling(1.0 * Count / PerPage));
[AllowNull]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public EntityView CurrentEntity { get; private set; }
private bool _updating = false; private bool _updating = false;
+30 -36
View File
@@ -1,4 +1,6 @@
namespace Pf2eViewer; using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
namespace Pf2eViewer;
partial class MainViewForm partial class MainViewForm
{ {
@@ -31,23 +33,21 @@ partial class MainViewForm
RootSplitContainer = new SplitContainer(); RootSplitContainer = new SplitContainer();
InnerSplitContainer = new SplitContainer(); InnerSplitContainer = new SplitContainer();
TypesListBox = new ListBox(); TypesListBox = new ListBox();
DatabaseViewer = new DatabaseViewerControl();
ResultSplitContainer = new SplitContainer(); ResultSplitContainer = new SplitContainer();
JsonWebView = new Microsoft.Web.WebView2.WinForms.WebView2(); EntityTreeViewerControl = new Pf2eViewer.EntityTreeViewer.EntityTreeViewerControl();
DatabaseViewer = new DatabaseViewerControl();
DescriptionTextBox = new TextBox(); DescriptionTextBox = new TextBox();
((System.ComponentModel.ISupportInitialize) RootSplitContainer).BeginInit(); ((System.ComponentModel.ISupportInitialize)RootSplitContainer).BeginInit();
RootSplitContainer.Panel1.SuspendLayout(); RootSplitContainer.Panel1.SuspendLayout();
RootSplitContainer.Panel2.SuspendLayout(); RootSplitContainer.Panel2.SuspendLayout();
RootSplitContainer.SuspendLayout(); RootSplitContainer.SuspendLayout();
((System.ComponentModel.ISupportInitialize) InnerSplitContainer).BeginInit(); ((System.ComponentModel.ISupportInitialize)InnerSplitContainer).BeginInit();
InnerSplitContainer.Panel1.SuspendLayout(); InnerSplitContainer.Panel1.SuspendLayout();
InnerSplitContainer.Panel2.SuspendLayout();
InnerSplitContainer.SuspendLayout(); InnerSplitContainer.SuspendLayout();
((System.ComponentModel.ISupportInitialize) ResultSplitContainer).BeginInit(); ((System.ComponentModel.ISupportInitialize)ResultSplitContainer).BeginInit();
ResultSplitContainer.Panel1.SuspendLayout(); ResultSplitContainer.Panel1.SuspendLayout();
ResultSplitContainer.Panel2.SuspendLayout(); ResultSplitContainer.Panel2.SuspendLayout();
ResultSplitContainer.SuspendLayout(); ResultSplitContainer.SuspendLayout();
((System.ComponentModel.ISupportInitialize) JsonWebView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// RootSplitContainer // RootSplitContainer
@@ -79,32 +79,30 @@ partial class MainViewForm
// InnerSplitContainer.Panel1 // InnerSplitContainer.Panel1
// //
InnerSplitContainer.Panel1.Controls.Add(TypesListBox); InnerSplitContainer.Panel1.Controls.Add(TypesListBox);
InnerSplitContainer.Size = new Size(254, 688);
InnerSplitContainer.SplitterDistance = 102;
InnerSplitContainer.TabIndex = 1;
// //
// InnerSplitContainer.Panel2 // InnerSplitContainer.Panel2
// //
InnerSplitContainer.Panel2.Controls.Add(DatabaseViewer); InnerSplitContainer.Panel2.Controls.Add(DatabaseViewer);
InnerSplitContainer.Size = new Size(254, 688);
InnerSplitContainer.SplitterDistance = 102;
InnerSplitContainer.TabIndex = 1;
// //
// TypesListBox // TypesListBox
// //
TypesListBox.Dock = DockStyle.Fill; TypesListBox.Dock = DockStyle.Fill;
TypesListBox.FormattingEnabled = true; TypesListBox.FormattingEnabled = true;
TypesListBox.ItemHeight = 15;
TypesListBox.Location = new Point(0, 0); TypesListBox.Location = new Point(0, 0);
TypesListBox.Name = "TypesListBox"; TypesListBox.Name = "TypesListBox";
TypesListBox.Size = new Size(254, 102); TypesListBox.Size = new Size(254, 102);
TypesListBox.TabIndex = 0; TypesListBox.TabIndex = 0;
TypesListBox.SelectedIndexChanged += TypesListBox_SelectedIndexChanged; TypesListBox.SelectedIndexChanged += TypesListBox_SelectedIndexChanged;
// //
// EntityView // DatabaseViewer
// //
DatabaseViewer.Dock = DockStyle.Fill; DatabaseViewer.Dock = DockStyle.Fill;
DatabaseViewer.Location = new Point(0, 0); DatabaseViewer.Location = new Point(0, 0);
DatabaseViewer.Name = "DatabaseViewer"; DatabaseViewer.Name = "DatabaseViewer";
DatabaseViewer.Size = new Size(254, 582); DatabaseViewer.TabIndex = 1;
DatabaseViewer.TabIndex = 0;
// //
// ResultSplitContainer // ResultSplitContainer
// //
@@ -114,38 +112,36 @@ partial class MainViewForm
// //
// ResultSplitContainer.Panel1 // ResultSplitContainer.Panel1
// //
ResultSplitContainer.Panel1.Controls.Add(JsonWebView); ResultSplitContainer.Panel1.Controls.Add(EntityTreeViewerControl);
// //
// ResultSplitContainer.Panel2 // ResultSplitContainer.Panel2
// //
ResultSplitContainer.Panel2.Controls.Add(DescriptionTextBox); ResultSplitContainer.Panel2.Controls.Add(DescriptionTextBox);
ResultSplitContainer.Size = new Size(923, 688); ResultSplitContainer.Size = new Size(923, 688);
ResultSplitContainer.SplitterDistance = 467; ResultSplitContainer.SplitterDistance = 382;
ResultSplitContainer.TabIndex = 1; ResultSplitContainer.TabIndex = 1;
// //
// JsonWebView // EntityTreeViewerControl
// //
JsonWebView.AllowExternalDrop = true; EntityTreeViewerControl.DepthSize = 20;
JsonWebView.CreationProperties = null; EntityTreeViewerControl.Dock = DockStyle.Fill;
JsonWebView.DefaultBackgroundColor = Color.White; EntityTreeViewerControl.EntityView = null;
JsonWebView.Dock = DockStyle.Fill; EntityTreeViewerControl.ItemHeight = 20;
JsonWebView.Location = new Point(0, 0); EntityTreeViewerControl.Location = new Point(0, 0);
JsonWebView.Name = "JsonWebView"; EntityTreeViewerControl.Name = "EntityTreeViewerControl";
JsonWebView.Size = new Size(467, 688); EntityTreeViewerControl.Size = new Size(382, 688);
JsonWebView.TabIndex = 0; EntityTreeViewerControl.TabIndex = 0;
JsonWebView.Visible = false;
JsonWebView.ZoomFactor = 1D;
JsonWebView.CoreWebView2InitializationCompleted += JsonWebView_CoreWebView2InitializationCompleted;
// //
// DescriptionTextBox // DescriptionTextBox
// //
DescriptionTextBox.Dock = DockStyle.Fill; DescriptionTextBox.Dock = DockStyle.Fill;
DescriptionTextBox.Font = new Font("Consolas", 9F);
DescriptionTextBox.Location = new Point(0, 0); DescriptionTextBox.Location = new Point(0, 0);
DescriptionTextBox.Multiline = true; DescriptionTextBox.Multiline = true;
DescriptionTextBox.Name = "DescriptionTextBox"; DescriptionTextBox.Name = "DescriptionTextBox";
DescriptionTextBox.ReadOnly = true; DescriptionTextBox.ReadOnly = true;
DescriptionTextBox.ScrollBars = ScrollBars.Vertical; DescriptionTextBox.ScrollBars = ScrollBars.Vertical;
DescriptionTextBox.Size = new Size(452, 688); DescriptionTextBox.Size = new Size(537, 688);
DescriptionTextBox.TabIndex = 0; DescriptionTextBox.TabIndex = 0;
// //
// MainViewForm // MainViewForm
@@ -158,18 +154,16 @@ partial class MainViewForm
Text = "DataBaseViewer"; Text = "DataBaseViewer";
RootSplitContainer.Panel1.ResumeLayout(false); RootSplitContainer.Panel1.ResumeLayout(false);
RootSplitContainer.Panel2.ResumeLayout(false); RootSplitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize) RootSplitContainer).EndInit(); ((System.ComponentModel.ISupportInitialize)RootSplitContainer).EndInit();
RootSplitContainer.ResumeLayout(false); RootSplitContainer.ResumeLayout(false);
InnerSplitContainer.Panel1.ResumeLayout(false); InnerSplitContainer.Panel1.ResumeLayout(false);
InnerSplitContainer.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)InnerSplitContainer).EndInit();
((System.ComponentModel.ISupportInitialize) InnerSplitContainer).EndInit();
InnerSplitContainer.ResumeLayout(false); InnerSplitContainer.ResumeLayout(false);
ResultSplitContainer.Panel1.ResumeLayout(false); ResultSplitContainer.Panel1.ResumeLayout(false);
ResultSplitContainer.Panel2.ResumeLayout(false); ResultSplitContainer.Panel2.ResumeLayout(false);
ResultSplitContainer.Panel2.PerformLayout(); ResultSplitContainer.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize) ResultSplitContainer).EndInit(); ((System.ComponentModel.ISupportInitialize)ResultSplitContainer).EndInit();
ResultSplitContainer.ResumeLayout(false); ResultSplitContainer.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize) JsonWebView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
@@ -180,6 +174,6 @@ partial class MainViewForm
private ListBox TypesListBox; private ListBox TypesListBox;
private SplitContainer ResultSplitContainer; private SplitContainer ResultSplitContainer;
private TextBox DescriptionTextBox; private TextBox DescriptionTextBox;
private Microsoft.Web.WebView2.WinForms.WebView2 JsonWebView;
private DatabaseViewerControl DatabaseViewer; private DatabaseViewerControl DatabaseViewer;
private EntityTreeViewer.EntityTreeViewerControl EntityTreeViewerControl;
} }
+8 -12
View File
@@ -1,4 +1,5 @@
using Newtonsoft.Json; using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using Pf2eModel; using Pf2eModel;
@@ -16,7 +17,8 @@ public partial class MainViewForm : Form
public readonly string JsonViewerHtml; public readonly string JsonViewerHtml;
public readonly EntityView Viewer; [AllowNull]
public readonly EntityView Viewer = null;
public MainViewForm() public MainViewForm()
{ {
@@ -67,7 +69,8 @@ public partial class MainViewForm : Form
string json = result[..^1] + $",\"SubEntity\":{subResult}}}"; string json = result[..^1] + $",\"SubEntity\":{subResult}}}";
RenderJson(json); EntityTreeViewerControl.EntityView = newEntity;
// RenderJson(json);
DescriptionTextBox.Text = newEntity.Entity!.Description; DescriptionTextBox.Text = newEntity.Entity!.Description;
} }
@@ -85,6 +88,7 @@ public partial class MainViewForm : Form
public void RenderJson(string json) public void RenderJson(string json)
{ {
/*
if (JsonWebView.CoreWebView2 == null) if (JsonWebView.CoreWebView2 == null)
{ {
JsonWebView.EnsureCoreWebView2Async(); JsonWebView.EnsureCoreWebView2Async();
@@ -93,14 +97,6 @@ public partial class MainViewForm : Form
string html = JsonViewerHtml.Replace("{JSON}", json); string html = JsonViewerHtml.Replace("{JSON}", json);
JsonWebView.CoreWebView2.NavigateToString(html); JsonWebView.CoreWebView2.NavigateToString(html);
} */
private void JsonWebView_CoreWebView2InitializationCompleted(
object sender,
Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e
)
{
JsonWebView.Visible = true;
DatabaseViewer_EntityChange(DatabaseViewer.CurrentEntity);
} }
} }
+3 -4
View File
@@ -8,16 +8,15 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FontAwesome.Sharp" Version="6.6.0" /> <PackageReference Include="FontAwesome.Sharp" Version="6.6.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3179.45" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Pf2eModel\Pf2eModel.csproj" /> <ProjectReference Include="..\Pf2eModel\Pf2eModel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Properties\" /> <None Update="Properties\Settings.settings">
</ItemGroup> <Generator>SettingsSingleFileGenerator</Generator>
<ItemGroup> </None>
<None Update="Resources\json-viewer.html"> <None Update="Resources\json-viewer.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
+9 -2
View File
@@ -11,7 +11,14 @@ internal static class Program
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
// Application.Run(new MainViewForm());
Application.Run(new TestForm()); Application.SetHighDpiMode(HighDpiMode.SystemAware);
#pragma warning disable WFO5001
Application.SetColorMode(SystemColorMode.System);
#pragma warning restore WFO5001
Application.Run(new MainViewForm() { StartPosition = FormStartPosition.CenterScreen });
// Application.Run(new TestForm() { StartPosition = FormStartPosition.CenterScreen });
} }
} }
+26
View File
@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Pf2eViewer.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.13.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>
+1
View File
@@ -37,6 +37,7 @@ partial class TestForm
// RandomButton // RandomButton
// //
RandomButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; RandomButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
RandomButton.FlatStyle = FlatStyle.System;
RandomButton.Location = new Point(12, 12); RandomButton.Location = new Point(12, 12);
RandomButton.Name = "RandomButton"; RandomButton.Name = "RandomButton";
RandomButton.Size = new Size(426, 23); RandomButton.Size = new Size(426, 23);