1
0
mirror of synced 2025-01-31 04:13:51 +01:00

Allow multiple window dialogs for sarc archives

This commit is contained in:
KillzXGaming 2019-05-17 18:02:46 -04:00
parent 423aa38414
commit 5654105016
14 changed files with 125 additions and 31 deletions

Binary file not shown.

View File

@ -383,25 +383,38 @@ namespace FirstPlugin
private void OpenFormDialog(IFileFormat fileFormat)
{
Type objectType = fileFormat.GetType();
STForm form = GetEditorForm(fileFormat);
var parentForm = LibraryGUI.Instance.GetActiveForm();
form.Text = (((IFileFormat)fileFormat).FileName);
form.FormClosing += (sender, e) => FormClosing(sender, e, fileFormat);
form.Show(parentForm);
}
private void FormClosing(object sender, EventArgs args, IFileFormat fileFormat)
{
if (((Form)sender).DialogResult != DialogResult.OK)
return;
if (fileFormat.CanSave)
{
Data = fileFormat.Save();
UpdateHexView();
}
}
private STForm GetEditorForm(IFileFormat fileFormat)
{
Type objectType = fileFormat.GetType();
foreach (var inter in objectType.GetInterfaces())
{
if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IEditor<>))
{
System.Reflection.MethodInfo method = objectType.GetMethod("OpenForm");
var form = (STForm)method.Invoke(fileFormat, new object[0]);
form.Text = (((IFileFormat)fileFormat).FileName);
if (form.ShowDialog() == DialogResult.OK)
{
if (fileFormat.CanSave)
{
Data = fileFormat.Save();
UpdateHexView();
}
}
return (STForm)method.Invoke(fileFormat, new object[0]);
}
}
return null;
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

View File

@ -136,6 +136,7 @@
this.stButton1.TabIndex = 12;
this.stButton1.Text = "Cancel";
this.stButton1.UseVisualStyleBackColor = false;
this.stButton1.Click += new System.EventHandler(this.stButton1_Click);
//
// stButton2
//
@ -148,6 +149,7 @@
this.stButton2.TabIndex = 13;
this.stButton2.Text = "Save";
this.stButton2.UseVisualStyleBackColor = false;
this.stButton2.Click += new System.EventHandler(this.stButton2_Click);
//
// splitContainer1
//
@ -180,28 +182,28 @@
// addItemToolStripMenuItem
//
this.addItemToolStripMenuItem.Name = "addItemToolStripMenuItem";
this.addItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addItemToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.addItemToolStripMenuItem.Text = "Add Item";
this.addItemToolStripMenuItem.Click += new System.EventHandler(this.addNodeToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.editToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.editToolStripMenuItem.Text = "Edit";
this.editToolStripMenuItem.Click += new System.EventHandler(this.editValueNodeMenuItem_Click);
//
// renameToolStripMenuItem
//
this.renameToolStripMenuItem.Name = "renameToolStripMenuItem";
this.renameToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.renameToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.renameToolStripMenuItem.Text = "Rename";
this.renameToolStripMenuItem.Click += new System.EventHandler(this.renameToolStripMenuItem_Click);
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.deleteToolStripMenuItem.Text = "Delete";
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click);
//
@ -213,7 +215,7 @@
this.renameToolStripMenuItem,
this.deleteToolStripMenuItem});
this.stContextMenuStrip1.Name = "stContextMenuStrip1";
this.stContextMenuStrip1.Size = new System.Drawing.Size(181, 114);
this.stContextMenuStrip1.Size = new System.Drawing.Size(124, 92);
this.stContextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.stContextMenuStrip1_Opening);
//
// AampEditorBase

View File

@ -205,5 +205,17 @@ namespace FirstPlugin.Forms
{
}
private void stButton2_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void stButton1_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>172, 17</value>
</metadata>

View File

@ -50,10 +50,10 @@
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.stContextMenuStrip1 = new Switch_Toolbox.Library.Forms.STContextMenuStrip(this.components);
this.addItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.renameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contentContainer.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -214,6 +214,7 @@
this.stButton1.TabIndex = 12;
this.stButton1.Text = "Cancel";
this.stButton1.UseVisualStyleBackColor = false;
this.stButton1.Click += new System.EventHandler(this.stButton1_Click);
//
// stButton2
//
@ -226,6 +227,7 @@
this.stButton2.TabIndex = 13;
this.stButton2.Text = "Save";
this.stButton2.UseVisualStyleBackColor = false;
this.stButton2.Click += new System.EventHandler(this.stButton2_Click);
//
// splitContainer1
//
@ -263,36 +265,36 @@
this.renameToolStripMenuItem,
this.deleteToolStripMenuItem});
this.stContextMenuStrip1.Name = "stContextMenuStrip1";
this.stContextMenuStrip1.Size = new System.Drawing.Size(181, 114);
this.stContextMenuStrip1.Size = new System.Drawing.Size(124, 92);
//
// addItemToolStripMenuItem
//
this.addItemToolStripMenuItem.Name = "addItemToolStripMenuItem";
this.addItemToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.addItemToolStripMenuItem.Text = "Add Item";
this.addItemToolStripMenuItem.Click += new System.EventHandler(this.addNodeToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.editToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.editToolStripMenuItem.Text = "Edit";
this.editToolStripMenuItem.Click += new System.EventHandler(this.editValueNodeMenuItem_Click);
//
// renameToolStripMenuItem
//
this.renameToolStripMenuItem.Name = "renameToolStripMenuItem";
this.renameToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.renameToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.renameToolStripMenuItem.Text = "Rename";
this.renameToolStripMenuItem.Click += new System.EventHandler(this.renameToolStripMenuItem_Click);
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
this.deleteToolStripMenuItem.Text = "Delete";
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click);
//
// addItemToolStripMenuItem
//
this.addItemToolStripMenuItem.Name = "addItemToolStripMenuItem";
this.addItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addItemToolStripMenuItem.Text = "Add Item";
this.addItemToolStripMenuItem.Click += new System.EventHandler(this.addNodeToolStripMenuItem_Click);
//
// ByamlEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -40,6 +40,7 @@ namespace FirstPlugin
public ByamlEditor(System.Collections.IEnumerable by, bool _pathSupport, ushort _ver, ByteOrder defaultOrder = ByteOrder.LittleEndian, bool IsSaveDialog = false, BYAML byaml = null)
{
InitializeComponent();
CenterToScreen();
treeView1.BackColor = FormThemes.BaseTheme.FormBackColor;
treeView1.ForeColor = FormThemes.BaseTheme.FormForeColor;
@ -616,5 +617,17 @@ namespace FirstPlugin
stContextMenuStrip1.Show(pt);
}
}
private void stButton2_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void stButton1_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Threading;
using System.Windows;
using System.Windows.Interop;
namespace Switch_Toolbox.Library.Forms
{
public static class NoneBlockingDialog
{
public static DialogResult ShowDialogNonBlocking(this Form window, Form ownder)
{
var frame = new DispatcherFrame();
void closeHandler(object sender, EventArgs args)
{
frame.Continue = false;
}
try
{
SetNativeEnabled(ownder.Handle, false);
window.Closed += closeHandler;
window.Show();
Dispatcher.PushFrame(frame);
}
finally
{
window.Closed -= closeHandler;
SetNativeEnabled(ownder.Handle, true);
}
return window.DialogResult;
}
const int GWL_STYLE = -16;
const int WS_DISABLED = 0x08000000;
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
static void SetNativeEnabled(IntPtr hWnd, bool enabled)
{
SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~WS_DISABLED | (enabled ? 0 : WS_DISABLED));
}
}
}

View File

@ -470,6 +470,7 @@
<Compile Include="Forms\HintHelpDialog.Designer.cs">
<DependentUpon>HintHelpDialog.cs</DependentUpon>
</Compile>
<Compile Include="Forms\NonBlickingDialog.cs" />
<Compile Include="Forms\PropertyBinding.cs" />
<Compile Include="Forms\STConsole.cs">
<SubType>Component</SubType>