1
0
mirror of synced 2025-02-22 05:19:50 +01:00

Improve file removing from object editor

This commit is contained in:
KillzXGaming 2019-07-31 20:11:10 -04:00
parent 25bc66e505
commit 2340d6a7a4
8 changed files with 46 additions and 42 deletions

View File

@ -975,8 +975,6 @@ namespace FirstPlugin
public void LoadFile(ResU.ResFile res) public void LoadFile(ResU.ResFile res)
{ {
CanDelete = true;
resFileU = res; resFileU = res;
Text = resFileU.Name; Text = resFileU.Name;

View File

@ -38,16 +38,6 @@ namespace FirstPlugin.NodeWrappers
return Items.ToArray(); return Items.ToArray();
} }
public override void Delete()
{
var editor = LibraryGUI.GetObjectEditor();
if (editor != null)
{
editor.RemoveFile(this);
editor.ResetControls();
}
}
protected void SettingBooleanAction(object sender, EventArgs e) protected void SettingBooleanAction(object sender, EventArgs e)
{ {
if (sender is ToolStripMenuItem) if (sender is ToolStripMenuItem)

View File

@ -71,7 +71,6 @@ namespace Toolbox.Library
var editor = LibraryGUI.GetObjectEditor(); var editor = LibraryGUI.GetObjectEditor();
if (editor != null) if (editor != null)
{ {
editor.RemoveFile(this);
editor.ResetControls(); editor.ResetControls();
} }
} }

View File

@ -20,8 +20,6 @@ namespace Toolbox.Library.Forms
private ObjectEditorTree ObjectTree; private ObjectEditorTree ObjectTree;
private ObjectEditorList ObjectList; //Optionally usable for archives private ObjectEditorList ObjectList; //Optionally usable for archives
private TreeView _fieldsTreeCache;
public void BeginUpdate() { ObjectTree.BeginUpdate(); } public void BeginUpdate() { ObjectTree.BeginUpdate(); }
public void EndUpdate() { ObjectTree.EndUpdate(); } public void EndUpdate() { ObjectTree.EndUpdate(); }
@ -178,21 +176,10 @@ namespace Toolbox.Library.Forms
if (viewport != null) if (viewport != null)
viewport.FormClosing(); viewport.FormClosing();
if (ObjectTree != null) if (ObjectTree != null)
ObjectTree.FormClosing(); ObjectTree.FormClosing();
} }
public void RemoveFile(TreeNode File)
{
if (File is IFileFormat) {
((IFileFormat)File).Unload();
}
ObjectTree.RemoveFile(File);
}
public void ResetControls() public void ResetControls()
{ {
ObjectTree.ResetControls(); ObjectTree.ResetControls();

View File

@ -23,8 +23,6 @@ namespace Toolbox.Library.Forms
public ObjectEditor ObjectEditor; public ObjectEditor ObjectEditor;
private List<TreeNode> _fieldsTreeCache = new List<TreeNode>();
public void BeginUpdate() { treeViewCustom1.BeginUpdate(); } public void BeginUpdate() { treeViewCustom1.BeginUpdate(); }
public void EndUpdate() { treeViewCustom1.EndUpdate(); } public void EndUpdate() { treeViewCustom1.EndUpdate(); }
@ -258,8 +256,22 @@ namespace Toolbox.Library.Forms
{ {
if (e.Node is IContextMenuNode) if (e.Node is IContextMenuNode)
{ {
bool IsRoot = e.Node.Parent == null;
treeNodeContextMenu.Items.Clear(); treeNodeContextMenu.Items.Clear();
if (IsRoot)
{
foreach (var item in ((IContextMenuNode)e.Node).GetContextMenuItems())
{
if (item.Text != "Delete" || item.Text != "Remove")
treeNodeContextMenu.Items.Add(item);
}
treeNodeContextMenu.Items.Add(new ToolStripMenuItem("Delete", null, DeleteAction, Keys.Control | Keys.Delete));
}
else
{
treeNodeContextMenu.Items.AddRange(((IContextMenuNode)e.Node).GetContextMenuItems()); treeNodeContextMenu.Items.AddRange(((IContextMenuNode)e.Node).GetContextMenuItems());
}
treeNodeContextMenu.Show(Cursor.Position); treeNodeContextMenu.Show(Cursor.Position);
//Select the node without the evemt //Select the node without the evemt
@ -275,6 +287,34 @@ namespace Toolbox.Library.Forms
} }
} }
private void DeleteAction(object sender, EventArgs args)
{
var node = treeViewCustom1.SelectedNode;
if (node != null)
{
if (node is IFileFormat)
{
((IFileFormat)node).Unload();
}
treeViewCustom1.Nodes.Remove(node);
ResetEditor();
}
}
private void ResetEditor()
{
foreach (Control control in stPanel2.Controls)
{
if (control is STUserControl)
((STUserControl)control).OnControlClosing();
control.Dispose();
}
stPanel2.Controls.Clear();
}
private void OnAnimationSelected(TreeNode Node) private void OnAnimationSelected(TreeNode Node)
{ {
if (Node is Animation) if (Node is Animation)
@ -351,8 +391,9 @@ namespace Toolbox.Library.Forms
public void ResetControls() public void ResetControls()
{ {
treeViewCustom1.Nodes.Clear(); treeViewCustom1.Nodes.Clear();
stPanel2.Controls.Clear();
Text = ""; Text = "";
ResetEditor();
} }
bool UpdateViewport = false; bool UpdateViewport = false;

View File

@ -449,6 +449,7 @@ namespace Toolbox.Library
} }
} }
//Method from https://github.com/aboood40091/BNTX-Editor/blob/master/formConv.py
private static byte[] DecodeLA8(byte[] Input, int Width, int Height) private static byte[] DecodeLA8(byte[] Input, int Width, int Height)
{ {
int bpp = 16; int bpp = 16;
@ -1073,18 +1074,6 @@ namespace Toolbox.Library
return comp; return comp;
} }
public override void Delete()
{
DisposeRenderable();
var editor = LibraryGUI.GetObjectEditor();
if (editor != null)
{
editor.RemoveFile(this);
editor.ResetControls();
}
}
public Properties GenericProperties public Properties GenericProperties
{ {
get get