diff --git a/DataNode.cs b/DataNode.cs deleted file mode 100644 index ef3248d..0000000 --- a/DataNode.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Substrate.Core; -using Substrate.Nbt; -using System.Collections.Generic; -using System; -using System.Windows.Forms; - -namespace NBTExplorer -{ - public class DataNodeOld - { - public DataNodeOld () - { - } - - public DataNodeOld (DataNodeOld parent) - { - Parent = parent; - } - - public DataNodeOld Parent { get; set; } - - private bool _modified; - public bool Modified - { - get { return _modified; } - set - { - if (value && Parent != null) { - Parent.Modified = value; - } - _modified = value; - } - } - - public bool Expanded { get; set; } - } - - public class NbtDataNode : DataNodeOld - { - public NbtDataNode () - { - } - - public NbtDataNode (DataNodeOld parent) - : base(parent) - { - } - - public NbtTree Tree { get; set; } - } - - public class RegionChunkData : NbtDataNode - { - public RegionChunkData (RegionFile file, int x, int z) - : this(null, file, x, z) - { - } - - public RegionChunkData (DataNodeOld parent, RegionFile file, int x, int z) - : base(parent) - { - Region = file; - X = x; - Z = z; - } - - public RegionFile Region { get; private set; } - public int X { get; private set; } - public int Z { get; private set; } - } - - public class RegionData : DataNodeOld - { - public RegionData (string path) - : this(null, path) - { - } - - public RegionData (DataNodeOld parent, string path) - : base(parent) - { - Path = path; - } - - public string Path { get; private set; } - } - - public class NbtFileData : NbtDataNode - { - public NbtFileData (string path, CompressionType cztype) - : this(null, path, cztype) - { - } - - public NbtFileData (DataNodeOld parent, string path, CompressionType cztype) - : base(parent) - { - Path = path; - CompressionType = cztype; - } - - public string Path { get; private set; } - public CompressionType CompressionType { get; private set; } - } - - public class DirectoryData : DataNodeOld - { - public DirectoryData (string path) - : this(null, path) - { - } - - public DirectoryData (DataNodeOld parent, string path) - : base(parent) - { - Path = path; - } - - public string Path { get; private set; } - } -} diff --git a/FormRegistry.cs b/FormRegistry.cs new file mode 100644 index 0000000..770959b --- /dev/null +++ b/FormRegistry.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using Substrate.Nbt; + +namespace NBTExplorer +{ + public static class FormRegistry + { + public delegate bool EditStringAction (StringFormData data); + public delegate bool EditRestrictedStringAction (RestrictedStringFormData data); + public delegate bool EditTagScalarAction (TagScalarFormData data); + public delegate bool EditByteArrayAction (ByteArrayFormData data); + + public static EditStringAction EditString { get; set; } + public static EditRestrictedStringAction RenameTag { get; set; } + public static EditTagScalarAction EditTagScalar { get; set; } + public static EditByteArrayAction EditByteArray { get; set; } + } + + public class TagScalarFormData + { + public TagScalarFormData (TagNode tag) + { + Tag = tag; + } + + public TagNode Tag { get; private set; } + } + + public class StringFormData + { + public StringFormData (String value) + { + Value = value; + } + + public String Value { get; set; } + } + + public class RestrictedStringFormData : StringFormData + { + private List _restricted = new List(); + + public RestrictedStringFormData (String value) + : base(value) + { + } + + public List RestrictedValues + { + get { return _restricted; } + } + } + + public class ByteArrayFormData + { + public string NodeName { get; set; } + public int BytesPerElement { get; set; } + public byte[] Data { get; set; } + } +} \ No newline at end of file diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..03e6795 --- /dev/null +++ b/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDocumentTypes + + CFBundleIconFiles + + dead_bush.icns + + CFBundleIdentifier + jaquadro.NBTExplorer + CFBundleName + NBTExplorer + CFBundleShortVersionString + 2.0.3 + CFBundleVersion + 1 + LSApplicationCategoryType + public.app-category.utilities + LSMinimumSystemVersion + 10.6 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/Mac/AppDelegate.cs b/Mac/AppDelegate.cs new file mode 100644 index 0000000..bf5b294 --- /dev/null +++ b/Mac/AppDelegate.cs @@ -0,0 +1,29 @@ +using System; +using System.Drawing; +using MonoMac.Foundation; +using MonoMac.AppKit; +using MonoMac.ObjCRuntime; + +namespace NBTExplorer +{ + public partial class AppDelegate : NSApplicationDelegate + { + MainWindowController mainWindowController; + + public AppDelegate () + { + } + + public override void FinishedLaunching (NSObject notification) + { + mainWindowController = new MainWindowController (); + mainWindowController.Window.MakeKeyAndOrderFront (this); + } + + partial void ActionRename (NSObject sender) + { + mainWindowController.Window.ActionEditValue(); + } + } +} + diff --git a/Mac/AppDelegate.designer.cs b/Mac/AppDelegate.designer.cs new file mode 100644 index 0000000..79392b8 --- /dev/null +++ b/Mac/AppDelegate.designer.cs @@ -0,0 +1,27 @@ +// WARNING +// +// This file has been generated automatically by MonoDevelop to store outlets and +// actions made in the Xcode designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using MonoMac.Foundation; + +namespace NBTExplorer +{ + [Register ("AppDelegate")] + partial class AppDelegate + { + [Action ("ActionRename:")] + partial void ActionRename (MonoMac.Foundation.NSObject sender); + + [Action ("ActionEditValue:")] + partial void ActionEditValue (MonoMac.Foundation.NSObject sender); + + [Action ("ActionDelete:")] + partial void ActionDelete (MonoMac.Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + } + } +} diff --git a/Mac/EditValue.cs b/Mac/EditValue.cs new file mode 100644 index 0000000..7bb94d6 --- /dev/null +++ b/Mac/EditValue.cs @@ -0,0 +1,158 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; +using Substrate.Nbt; + +namespace NBTExplorer.Mac +{ + public partial class EditValue : MonoMac.AppKit.NSWindow + { + public enum DialogResult + { + OK, + Cancel, + } + + private TagNode _tag; + private DialogResult _result; + + #region Constructors + + // Called when created from unmanaged code + public EditValue (IntPtr handle) : base (handle) + { + Initialize (); + } + + // Called when created directly from a XIB file + [Export ("initWithCoder:")] + public EditValue (NSCoder coder) : base (coder) + { + Initialize (); + } + + public EditValue (TagNode tag) + { + Initialize (); + + _tag = tag; + + if (tag == null) { + _result = DialogResult.Cancel; + Close(); + return; + } + + _valueField.StringValue = _tag.ToString(); + } + + // Shared initialization code + void Initialize () + { + } + + #endregion + + public TagNode NodeTag + { + get { return _tag; } + } + + public DialogResult Result + { + get { return _result; } + } + + /*private TagNode _tag; + + public EditValue (TagNode tag) + { + InitializeComponent(); + + _tag = tag; + + if (tag == null) { + DialogResult = DialogResult.Abort; + Close(); + return; + } + + textBox1.Text = _tag.ToString(); + } + + public TagNode NodeTag + { + get { return _tag; } + } + + private void Apply () + { + if (ValidateInput()) { + DialogResult = DialogResult.OK; + Close(); + } + } + + private bool ValidateInput () + { + return ValidateValueInput(); + } + + private bool ValidateValueInput () + { + try { + switch (_tag.GetTagType()) { + case TagType.TAG_BYTE: + _tag.ToTagByte().Data = unchecked((byte)sbyte.Parse(textBox1.Text)); + break; + + case TagType.TAG_SHORT: + _tag.ToTagShort().Data = short.Parse(textBox1.Text); + break; + + case TagType.TAG_INT: + _tag.ToTagInt().Data = int.Parse(textBox1.Text); + break; + + case TagType.TAG_LONG: + _tag.ToTagLong().Data = long.Parse(textBox1.Text); + break; + + case TagType.TAG_FLOAT: + _tag.ToTagFloat().Data = float.Parse(textBox1.Text); + break; + + case TagType.TAG_DOUBLE: + _tag.ToTagDouble().Data = double.Parse(textBox1.Text); + break; + + case TagType.TAG_STRING: + _tag.ToTagString().Data = textBox1.Text; + break; + } + } + catch (FormatException) { + MessageBox.Show("The value is formatted incorrectly for the given type."); + return false; + } + catch (OverflowException) { + MessageBox.Show("The value is outside the acceptable range for the given type."); + return false; + } + catch { + return false; + } + + return true; + } + + private void _buttonOK_Click (object sender, EventArgs e) + { + Apply(); + }*/ + } +} + diff --git a/Mac/EditValue.designer.cs b/Mac/EditValue.designer.cs new file mode 100644 index 0000000..1644bfa --- /dev/null +++ b/Mac/EditValue.designer.cs @@ -0,0 +1,31 @@ +// WARNING +// +// This file has been generated automatically by MonoDevelop to store outlets and +// actions made in the Xcode designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using MonoMac.Foundation; + +namespace NBTExplorer.Mac +{ + [Register ("EditValue")] + partial class EditValue + { + [Outlet] + MonoMac.AppKit.NSTextField _valueField { get; set; } + + [Action ("ActionOK:")] + partial void ActionOK (MonoMac.Foundation.NSObject sender); + + [Action ("ActionCancel:")] + partial void ActionCancel (MonoMac.Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + if (_valueField != null) { + _valueField.Dispose (); + _valueField = null; + } + } + } +} diff --git a/Mac/EditValue.xib b/Mac/EditValue.xib new file mode 100644 index 0000000..76a7cc7 --- /dev/null +++ b/Mac/EditValue.xib @@ -0,0 +1,390 @@ + + + + 1080 + 12B2080 + 2844 + 1187 + 624.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2844 + + + YES + NSButton + NSButtonCell + NSCustomObject + NSTextField + NSTextFieldCell + NSView + NSWindowTemplate + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + EditValue + + + FirstResponder + + + NSApplication + + + 3 + 2 + {{131, 86}, {262, 91}} + 611844096 + Edit Value... + EditValue + + + + + 256 + + YES + + + 266 + {{20, 49}, {222, 22}} + + + _NS:9 + YES + + -1804599231 + 272630848 + + + LucidaGrande + 13 + 1044 + + _NS:9 + + YES + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + textColor + + 3 + MAA + + + + NO + + + + 268 + {{166, 13}, {82, 32}} + + + _NS:9 + YES + + 67108864 + 134217728 + OK + + _NS:9 + + -2038284288 + 129 + + DQ + 200 + 25 + + NO + + + + 268 + {{84, 13}, {82, 32}} + + + _NS:9 + YES + + 67108864 + 134217728 + Cancel + + _NS:9 + + -2038284288 + 129 + + Gw + 200 + 25 + + NO + + + {262, 91} + + + + {{0, 0}, {1600, 1178}} + {10000000000000, 10000000000000} + YES + + + + + YES + + + _valueField + + + + 9 + + + + ActionOK: + + + + 10 + + + + ActionCancel: + + + + 11 + + + + + YES + + 0 + + YES + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + YES + + + + + + 2 + + + YES + + + + + + + + 3 + + + YES + + + + + + 4 + + + + + 5 + + + YES + + + + + + 6 + + + + + 7 + + + YES + + + + + + 8 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 1.IBPluginDependency + 1.IBWindowTemplateEditedContentRect + 1.NSWindowTemplate.visibleAtLaunch + 2.IBPluginDependency + 3.IBPluginDependency + 4.IBPluginDependency + 5.IBPluginDependency + 6.IBPluginDependency + 7.IBPluginDependency + 8.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{361, 348}, {602, 342}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 11 + + + + YES + + EditValue + NSWindow + + YES + + YES + ActionCancel: + ActionOK: + + + YES + id + id + + + + YES + + YES + ActionCancel: + ActionOK: + + + YES + + ActionCancel: + id + + + ActionOK: + id + + + + + _valueField + NSTextField + + + _valueField + + _valueField + NSTextField + + + + IBProjectSource + ./Classes/EditValue.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + diff --git a/Mac/IconRegistry.cs b/Mac/IconRegistry.cs new file mode 100644 index 0000000..28fafad --- /dev/null +++ b/Mac/IconRegistry.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using MonoMac.AppKit; + +namespace NBTExplorer.Mac +{ + public class IconRegistry + { + private Dictionary _iconRegistry; + + public IconRegistry () + { + _iconRegistry = new Dictionary(); + } + + public NSImage DefaultIcon { get; set; } + + public NSImage Lookup (Type type) + { + if (_iconRegistry.ContainsKey(type)) + return _iconRegistry[type]; + else + return DefaultIcon; + } + + public void Register (Type type, NSImage icon) + { + _iconRegistry[type] = icon; + } + } +} + diff --git a/Mac/ImageAndTextCell.cs b/Mac/ImageAndTextCell.cs new file mode 100644 index 0000000..d3e0aaa --- /dev/null +++ b/Mac/ImageAndTextCell.cs @@ -0,0 +1,210 @@ +using System; +using MonoMac.Foundation; +using MonoMac.AppKit; +using MonoMac.CoreGraphics; +using System.Drawing; +using MonoMac.ObjCRuntime; +using System.Collections.Generic; + +namespace NBTExplorer.Mac +{ + [Register("ImageAndTextCell")] + public class ImageAndTextCell : NSTextFieldCell + { + private NSImage _image; + private bool _copyCalled; + private bool _disposeCalled; + private bool _deallocCalled; + private bool _drawCalled; + + public ImageAndTextCell () + { + } + + public ImageAndTextCell (IntPtr handle) + : base(handle) + { + Initialize(); + } + + // Called when created directly from a XIB file + [Export ("initWithCoder:")] + public ImageAndTextCell (NSCoder coder) + : base (coder) + { + Initialize (); + } + + private void Initialize () + { + LineBreakMode = NSLineBreakMode.TruncatingTail; + Selectable = true; + } + + protected override void Dispose (bool disposing) + { + //if (_image != null) + // _image.Dispose(); + + //if (_noDispose) + // Handle = IntPtr.Zero; + _disposeCalled = true; + + base.Dispose (disposing); + } + + /*[Export("copyWithZone:")] + public virtual NSObject CopyWithZone(IntPtr zone) { + ImageAndTextCell cell = new ImageAndTextCell() { + Title = Title, + Image = Image, + }; + cell._noDispose = true; + return cell; + }*/ + + static List _refPool = new List(); + + //static IntPtr selRetain = Selector.GetHandle ("retain"); + //static IntPtr selAutoRelease = Selector.GetHandle("autorelease"); + //static IntPtr selRelease = Selector.GetHandle("release"); + //static IntPtr selCopyWithZone = Selector.GetHandle("copyWithZone:"); + + [Export("copyWithZone:")] + public NSObject CopyWithZone (IntPtr zone) + { + //IntPtr copy = Messaging.IntPtr_objc_msgSendSuper_IntPtr(SuperHandle, selCopyWithZone, zone); + //var cloned = new ImageAndTextCell(copy); + //cloned.Title = Title; + //cloned.Image = Image; + + var cloned = new ImageAndTextCell { + Title = Title, + Image = Image, + }; + cloned._copyCalled = true; + + _refPool.Add(cloned); + + //Messaging.void_objc_msgSend (cloned.Handle, selRetain); + return cloned; + } + + //static IntPtr selDealloc = Selector.GetHandle("dealloc"); + + [Export("dealloc")] + public void Dealloc () + { + _deallocCalled = true; + _refPool.Remove(this); + + //Messaging.void_objc_msgSendSuper(SuperHandle, selDealloc); + } + + public new NSImage Image + { + get { return _image; } + set { _image = value; } + } + + public override RectangleF ImageRectForBounds (RectangleF theRect) + { + if (_image != null) { + PointF origin = new PointF(theRect.X + 3, theRect.Y + (float)Math.Ceiling((theRect.Height - _image.Size.Height) / 2)); + return new RectangleF(origin, _image.Size); + } + else + return RectangleF.Empty; + } + + public override RectangleF TitleRectForBounds (RectangleF theRect) + { + if (_image != null) { + PointF origin = new PointF(theRect.X + 3 + _image.Size.Width, theRect.Y); + SizeF size = new SizeF(theRect.Width - 3 - _image.Size.Width, theRect.Height); + return new RectangleF(origin, size); + } + else + return base.TitleRectForBounds(theRect); + } + + public override void EditWithFrame (RectangleF aRect, NSView inView, NSText editor, NSObject delegateObject, NSEvent theEvent) + { + RectangleF textFrame, imageFrame; + aRect.Divide(3 + _image.Size.Width, CGRectEdge.MinXEdge, out imageFrame, out textFrame); + base.EditWithFrame(textFrame, inView, editor, delegateObject, theEvent); + } + + public override void SelectWithFrame (RectangleF aRect, NSView inView, NSText editor, NSObject delegateObject, int selStart, int selLength) + { + RectangleF textFrame, imageFrame; + aRect.Divide(3 + _image.Size.Width, CGRectEdge.MinXEdge, out imageFrame, out textFrame); + base.SelectWithFrame(textFrame, inView, editor, delegateObject, selStart, selLength); + } + + public override void DrawWithFrame (RectangleF cellFrame, NSView inView) + { + Assert (!_deallocCalled, "DrawWithFrame: Dealloc was called on object"); + Assert (!_disposeCalled, "DrawWithFrame: Dispose was called on object"); + + _drawCalled = true; + if (_image != null) { + RectangleF imageFrame; + cellFrame.Divide (3 + _image.Size.Width, CGRectEdge.MinXEdge, out imageFrame, out cellFrame); + + if (DrawsBackground) { + BackgroundColor.Set (); + NSGraphics.RectFill (imageFrame); + } + + imageFrame.X += 3; + imageFrame.Size = _image.Size; + + //if (inView.IsFlipped) { + // imageFrame.Y += (float)Math.Ceiling((cellFrame.Height + imageFrame.Height) / 2); + //} + //else { + imageFrame.Y += (float)Math.Ceiling ((cellFrame.Height - imageFrame.Height) / 2); + //} + + _image.Draw (imageFrame, new RectangleF (PointF.Empty, _image.Size), NSCompositingOperation.SourceOver, 1f, true, null); + } + + base.DrawWithFrame (cellFrame, inView); + } + + public override SizeF CellSize + { + get { + if (_image != null) + return new SizeF(base.CellSize.Width + 3 + _image.Size.Width, base.CellSize.Height); + else + return new SizeF(base.CellSize.Width + 3, base.CellSize.Height); + } + } + + public override NSCellHit HitTest (NSEvent forEvent, RectangleF inRect, NSView ofView) + { + PointF point = ofView.ConvertPointFromView (forEvent.LocationInWindow, null); + + if (_image != null) { + RectangleF imageFrame; + inRect.Divide(3 + _image.Size.Width, CGRectEdge.MinXEdge, out imageFrame, out inRect); + + imageFrame.X += 3; + imageFrame.Size = _image.Size; + if (ofView.MouseinRect(point, imageFrame)) + return NSCellHit.ContentArea; + } + + return base.HitTest (forEvent, inRect, ofView); + } + + private void Assert (bool condition, string message) + { + if (!condition) + throw new Exception("Assert failed: " + message); + } + } +} + diff --git a/Mac/MainMenu.xib b/Mac/MainMenu.xib new file mode 100644 index 0000000..d8693c3 --- /dev/null +++ b/Mac/MainMenu.xib @@ -0,0 +1,952 @@ + + + + 1080 + 12B2080 + 2844 + 1187 + 624.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2844 + + + YES + NSCustomObject + NSMenu + NSMenuItem + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + NSApplication + + + FirstResponder + + + NSApplication + + + AMainMenu + + YES + + + NBTExplorer + + 1048576 + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + submenuAction: + + NBTExplorer + + YES + + + About NBTExplorer + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Quit NBTExplorer + q + 1048576 + 2147483647 + + + + + _NSAppleMenu + + + + + File + + 1048576 + 2147483647 + + + submenuAction: + + File + + YES + + + Open… + o + 1048576 + 2147483647 + + + + + + Open Folder... + O + 1048576 + 2147483647 + + + + + + Open Minecraft Save Folder + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Save + s + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Recent Files + R + 2147483647 + + + submenuAction: + + Recent Files + + YES + + _NSRecentDocumentsMenu + + + + + Recent Folders + + 2147483647 + + + submenuAction: + + Recent Folders + + YES + + + + + + + + + Edit + + 1048576 + 2147483647 + + + submenuAction: + + Edit + + YES + + + Cut + x + 1048576 + 2147483647 + + + + + + Copy + c + 1048576 + 2147483647 + + + + + + Paste + v + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Rename + r + 1048576 + 2147483647 + + + + + + Edit Value + e + 1048576 + 2147483647 + + + + + + Delete +  + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Find... + f + 1048576 + 2147483647 + + + + + + Find Next + + 2147483647 + + + + + + + + + View + + 1048576 + 2147483647 + + + submenuAction: + + View + + YES + + + Show Toolbar + t + 1572864 + 2147483647 + + + + + + Customize Toolbar… + + 1048576 + 2147483647 + + + + + + + + + Window + + 1048576 + 2147483647 + + + + + + Help + + 2147483647 + + + + + _NSMainMenu + + + NSFontManager + + + AppDelegate + + + + + YES + + + terminate: + + + + 449 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + delegate + + + + 534 + + + + copy: + + + + 224 + + + + paste: + + + + 226 + + + + cut: + + + + 228 + + + + saveDocument: + + + + 362 + + + + runToolbarCustomizationPalette: + + + + 365 + + + + toggleToolbarShown: + + + + 366 + + + + openDocument: + + + + 374 + + + + ActionEditValue: + + + + 546 + + + + ActionRename: + + + + 547 + + + + ActionDelete: + + + + 548 + + + + + YES + + 0 + + YES + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 29 + + + YES + + + + + + + + + + + 19 + + + YES + + + + + 56 + + + YES + + + + + + 217 + + + YES + + + + + + 83 + + + YES + + + + + + 81 + + + YES + + + + + + + + + + + + + 75 + + + + + 72 + + + + + 124 + + + YES + + + + + + 79 + + + + + 125 + + + YES + + + + + 205 + + + YES + + + + + + + + + + + + + + + 202 + + + + + 214 + + + + + 199 + + + + + 203 + + + + + 197 + + + + + 57 + + + YES + + + + + + + + 58 + + + + + 136 + + + + + 236 + + + + + 295 + + + YES + + + + + + 296 + + + YES + + + + + + + 297 + + + + + 298 + + + + + 420 + + + + + 490 + + + YES + + + + + 533 + + + + + 535 + + + + + 536 + + + + + 537 + + + + + 538 + + + + + 539 + + + YES + + + + + + 540 + + + YES + + + + + 542 + + + + + 543 + + + + + 544 + + + + + 545 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 124.IBPluginDependency + 125.IBPluginDependency + 136.IBPluginDependency + 19.IBPluginDependency + 197.IBPluginDependency + 199.IBPluginDependency + 202.IBPluginDependency + 203.IBPluginDependency + 205.IBPluginDependency + 214.IBPluginDependency + 217.IBPluginDependency + 236.IBPluginDependency + 29.IBPluginDependency + 295.IBPluginDependency + 296.IBPluginDependency + 297.IBPluginDependency + 298.IBPluginDependency + 420.IBPluginDependency + 490.IBPluginDependency + 533.IBPluginDependency + 535.IBPluginDependency + 536.IBPluginDependency + 537.IBPluginDependency + 538.IBPluginDependency + 539.IBPluginDependency + 540.IBPluginDependency + 542.IBPluginDependency + 543.IBPluginDependency + 544.IBPluginDependency + 545.IBPluginDependency + 56.IBPluginDependency + 57.IBPluginDependency + 58.IBPluginDependency + 72.IBPluginDependency + 75.IBPluginDependency + 79.IBPluginDependency + 81.IBPluginDependency + 83.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 548 + + + + YES + + AppDelegate + NSObject + + YES + + YES + ActionDelete: + ActionEditValue: + ActionRename: + + + YES + id + id + id + + + + YES + + YES + ActionDelete: + ActionEditValue: + ActionRename: + + + YES + + ActionDelete: + id + + + ActionEditValue: + id + + + ActionRename: + id + + + + + IBProjectSource + ./Classes/AppDelegate.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + YES + + YES + NSMenuCheckmark + NSMenuMixedState + + + YES + {11, 11} + {10, 3} + + + + diff --git a/Mac/MainWindow.cs b/Mac/MainWindow.cs new file mode 100644 index 0000000..ff31d6e --- /dev/null +++ b/Mac/MainWindow.cs @@ -0,0 +1,318 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; +using NBTExplorer.Mac; +using System.IO; +using NBTExplorer.Model; + +namespace NBTExplorer +{ + public partial class MainWindow : MonoMac.AppKit.NSWindow + { + #region Constructors + + // Called when created from unmanaged code + public MainWindow (IntPtr handle) : base (handle) + { + Initialize (); + } + + // Called when created directly from a XIB file + [Export ("initWithCoder:")] + public MainWindow (NSCoder coder) : base (coder) + { + Initialize (); + } + + // Shared initialization code + void Initialize () + { + InitializeIconRegistry(); + } + + private NBTExplorer.Mac.IconRegistry _iconRegistry; + + private void InitializeIconRegistry () + { + _iconRegistry = new NBTExplorer.Mac.IconRegistry(); + _iconRegistry.DefaultIcon = NSImage.ImageNamed("question-white.png"); + + _iconRegistry.Register(typeof(TagByteDataNode), NSImage.ImageNamed("document-attribute-b.png")); + _iconRegistry.Register(typeof(TagShortDataNode), NSImage.ImageNamed("document-attribute-s.png")); + _iconRegistry.Register(typeof(TagIntDataNode), NSImage.ImageNamed("document-attribute-i.png")); + _iconRegistry.Register(typeof(TagLongDataNode), NSImage.ImageNamed("document-attribute-l.png")); + _iconRegistry.Register(typeof(TagFloatDataNode), NSImage.ImageNamed("document-attribute-f.png")); + _iconRegistry.Register(typeof(TagDoubleDataNode), NSImage.ImageNamed("document-attribute-d.png")); + _iconRegistry.Register(typeof(TagByteArrayDataNode), NSImage.ImageNamed("edit-code.png")); + _iconRegistry.Register(typeof(TagStringDataNode), NSImage.ImageNamed("edit-small-caps.png")); + _iconRegistry.Register(typeof(TagListDataNode), NSImage.ImageNamed("edit-list.png")); + _iconRegistry.Register(typeof(TagCompoundDataNode), NSImage.ImageNamed("box.png")); + _iconRegistry.Register(typeof(RegionChunkDataNode), NSImage.ImageNamed("wooden-box.png")); + _iconRegistry.Register(typeof(DirectoryDataNode), NSImage.ImageNamed("folder-open")); + _iconRegistry.Register(typeof(RegionFileDataNode), NSImage.ImageNamed("block.png")); + _iconRegistry.Register(typeof(CubicRegionDataNode), NSImage.ImageNamed("block.png")); + _iconRegistry.Register(typeof(NbtFileDataNode), NSImage.ImageNamed("wooden-box.png")); + _iconRegistry.Register(typeof(TagIntArrayDataNode), NSImage.ImageNamed("edit-code-i.png")); + } + + #endregion + + private TreeDataSource _dataSource; + + public override void AwakeFromNib () + { + base.AwakeFromNib (); + + _dataSource = new TreeDataSource(); + _mainOutlineView.DataSource = _dataSource; + _mainOutlineView.Delegate = new MyDelegate(this); + + string[] args = Environment.GetCommandLineArgs(); + if (args.Length > 2) { + string[] paths = new string[args.Length - 1]; + Array.Copy(args, 1, paths, 0, paths.Length); + OpenPaths(paths); + } + else { + OpenMinecraftDirectory(); + } + } + + public class MyDelegate : NSOutlineViewDelegate + { + private MainWindow _main; + + public MyDelegate (MainWindow main) + { + _main = main; + } + + public override void ItemWillExpand (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + Console.WriteLine ("Preparing to expand: " + node.Data.NodeDisplay); + _main.ExpandNode(node); + } + } + + public override void ItemDidExpand (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + Console.WriteLine("Finished Expanding: " + node.Data.NodeDisplay); + } + } + + public override void ItemWillCollapse (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + if (node.Data.NodeDisplay == "saves") // The root node + Console.WriteLine ("Uh-oh..."); + Console.WriteLine("Preparing to collapse: " + node.Data.NodeDisplay); + } + } + + public override void ItemDidCollapse (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + _main.CollapseNode(node); + } + } + + public override void WillDisplayCell (NSOutlineView outlineView, NSObject cell, NSTableColumn tableColumn, NSObject item) + { + ImageAndTextCell c = cell as ImageAndTextCell; + TreeDataNode node = item as TreeDataNode; + + c.Title = node.CombinedName; + c.Image = _main._iconRegistry.Lookup(node.Data.GetType()); + //c.StringValue = node.Name; + //throw new System.NotImplementedException (); + } + } + + #region Actions + + partial void ActionOpenFolder (MonoMac.Foundation.NSObject sender) + { + OpenFolder (); + } + + #endregion + + private string _openFolderPath = null; + + private void OpenFolder () + { + NSOpenPanel opanel = new NSOpenPanel (); + opanel.CanChooseDirectories = true; + opanel.CanChooseFiles = false; + + if (_openFolderPath != null) + opanel.DirectoryUrl = new NSUrl (_openFolderPath, true); + + if (opanel.RunModal () == (int)NSPanelButtonType.Ok) { + _openFolderPath = opanel.DirectoryUrl.AbsoluteString; + OpenPaths(new string[] { opanel.DirectoryUrl.Path }); + } + + //UpdateUI(); + } + + private void OpenMinecraftDirectory () + { + try { + string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); + path = Path.Combine(path, "Library", "Application Support"); + path = Path.Combine(path, "minecraft", "saves"); + + if (!Directory.Exists(path)) { + path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); + } + + OpenPaths(new string[] { path }); + } + catch (Exception e) { + //NSAlert.WithMessage("Could not open default Minecraft save directory", "OK", null, null, null).RunModal(); + Console.WriteLine(e.Message); + + try { + OpenPaths(new string[] { Directory.GetCurrentDirectory() }); + } + catch (Exception) { + //MessageBox.Show("Could not open current directory, this tool is probably not compatible with your platform."); + Console.WriteLine(e.Message); + NSApplication.SharedApplication.Terminate(this); + } + } + + //UpdateUI(); + } + + private void OpenPaths (string[] paths) + { + _dataSource.Nodes.Clear (); + _mainOutlineView.ReloadData (); + + foreach (string path in paths) { + if (Directory.Exists (path)) { + DirectoryDataNode node = new DirectoryDataNode (path); + _dataSource.Nodes.Add (new TreeDataNode (node)); + + // AddPathToHistory(Settings.Default.RecentDirectories, path); + } else if (File.Exists (path)) { + DataNode node = null; + } + } + + if (_dataSource.Nodes.Count > 0) { + _mainOutlineView.ExpandItem(_dataSource.Nodes[0]); + } + + _mainOutlineView.ReloadData(); + + // UpdateUI(); + // UpdateOpenMenu(); + + /*_nodeTree.Nodes.Clear(); + + foreach (string path in paths) { + if (Directory.Exists(path)) { + DirectoryDataNode node = new DirectoryDataNode(path); + _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); + + AddPathToHistory(Settings.Default.RecentDirectories, path); + } + else if (File.Exists(path)) { + DataNode node = null; + foreach (var item in FileTypeRegistry.RegisteredTypes) { + if (item.Value.NamePatternTest(path)) + node = item.Value.NodeCreate(path); + } + + if (node != null) { + _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); + AddPathToHistory(Settings.Default.RecentFiles, path); + } + } + } + + if (_nodeTree.Nodes.Count > 0) { + _nodeTree.Nodes[0].Expand(); + } + + UpdateUI(); + UpdateOpenMenu();*/ + } + + private void ExpandNode (TreeDataNode node) + { + if (node == null || node.IsExpanded) + return; + + Console.WriteLine ("Expand Node: " + node.Data.NodeDisplay); + + node.IsExpanded = true; + node.Nodes.Clear (); + + DataNode backNode = node.Data; + if (!backNode.IsExpanded) { + backNode.Expand (); + } + + foreach (DataNode child in backNode.Nodes) { + if (child != null) { + node.Nodes.Add (new TreeDataNode (child)); + } + } + } + + private void CollapseNode (TreeDataNode node) + { + if (node == null || !node.IsExpanded) + return; + + /*Console.WriteLine("Collapse Node: " + node.Data.NodeDisplay); + + DataNode backNode = node.Data; + if (backNode.IsModified) + return; + + backNode.Collapse(); + + node.IsExpanded = false; + node.Nodes.Clear();*/ + } + + public void ActionEditValue () + { + TreeDataNode node = _mainOutlineView.ItemAtRow(_mainOutlineView.SelectedRow) as TreeDataNode; + if (node != null) + EditNode(node); + } + + private void EditNode (TreeDataNode node) + { + if (node == null) + return; + + if (!node.Data.CanEditNode) + return; + + //NBTExplorer.Mac.EditValue form = new NBTExplorer.Mac.EditValue(node.Data); + + + //if (node.Data.EditNode()) { + //node.Text = dataNode.NodeDisplay; + //UpdateUI(dataNode); + //} + } + } +} + diff --git a/Mac/MainWindow.designer.cs b/Mac/MainWindow.designer.cs new file mode 100644 index 0000000..677619b --- /dev/null +++ b/Mac/MainWindow.designer.cs @@ -0,0 +1,72 @@ +// WARNING +// +// This file has been generated automatically by MonoDevelop to store outlets and +// actions made in the Xcode designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using MonoMac.Foundation; + +namespace NBTExplorer +{ + [Register ("MainWindow")] + partial class MainWindow + { + [Outlet] + MonoMac.AppKit.NSToolbar _toolbar { get; set; } + + [Outlet] + MonoMac.AppKit.NSToolbarItem _toolbarOpenFolder { get; set; } + + [Outlet] + MonoMac.AppKit.NSToolbarItem _toolbarSave { get; set; } + + [Outlet] + MonoMac.AppKit.NSScrollView _mainScrollView { get; set; } + + [Outlet] + MonoMac.AppKit.NSOutlineView _mainOutlineView { get; set; } + + [Action ("ActionOpenFolder:")] + partial void ActionOpenFolder (MonoMac.Foundation.NSObject sender); + + [Action ("ActionSave:")] + partial void ActionSave (MonoMac.Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + if (_toolbar != null) { + _toolbar.Dispose (); + _toolbar = null; + } + + if (_toolbarOpenFolder != null) { + _toolbarOpenFolder.Dispose (); + _toolbarOpenFolder = null; + } + + if (_toolbarSave != null) { + _toolbarSave.Dispose (); + _toolbarSave = null; + } + + if (_mainScrollView != null) { + _mainScrollView.Dispose (); + _mainScrollView = null; + } + + if (_mainOutlineView != null) { + _mainOutlineView.Dispose (); + _mainOutlineView = null; + } + } + } + + [Register ("MainWindowController")] + partial class MainWindowController + { + + void ReleaseDesignerOutlets () + { + } + } +} diff --git a/Mac/MainWindow.xib b/Mac/MainWindow.xib new file mode 100644 index 0000000..85a490d --- /dev/null +++ b/Mac/MainWindow.xib @@ -0,0 +1,788 @@ + + + + 1080 + 12B2080 + 2844 + 1187 + 624.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2844 + + + YES + IBCustomCell + NSCustomObject + NSOutlineView + NSScrollView + NSScroller + NSTableColumn + NSToolbar + NSToolbarFlexibleSpaceItem + NSToolbarItem + NSToolbarSpaceItem + NSUserDefaultsController + NSView + NSWindowTemplate + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + MainWindowController + + + FirstResponder + + + NSApplication + + + 15 + 2 + {{131, 74}, {776, 558}} + 611844096 + NBTExplorer + MainWindow + + + A9746BAB-CAB3-4A72-9A03-237662FA7440 + + + YES + YES + YES + YES + 1 + 2 + + YES + + YES + 0156226B-2E18-4406-BBE6-7C88F62B4E27 + B62CA8DD-7D49-4BF3-B4AB-417078852D8B + NSToolbarFlexibleSpaceItem + NSToolbarSpaceItem + + + YES + + + 0156226B-2E18-4406-BBE6-7C88F62B4E27 + + Open + Open + + + + NSImage + folder-open-24 + + + + {0, 0} + {0, 0} + YES + YES + -1 + YES + 0 + + + + B62CA8DD-7D49-4BF3-B4AB-417078852D8B + + Save + Save + + + + NSImage + disk-24 + + + + {0, 0} + {0, 0} + YES + YES + -1 + YES + 0 + + + NSToolbarFlexibleSpaceItem + + Flexible Space + + + + + + {1, 5} + {20000, 32} + YES + YES + -1 + YES + 0 + + YES + YES + + + 1048576 + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + + + + NSToolbarSpaceItem + + Space + + + + + + {32, 5} + {32, 32} + YES + YES + -1 + YES + 0 + + YES + YES + + + 1048576 + 2147483647 + + + + + + + + YES + + + + + + + YES + + + + + + YES + + + + + + 256 + + YES + + + 286 + + YES + + + 2304 + + YES + + + 256 + + YES + + {776, 558} + + + + _NS:13 + YES + NO + YES + + + -2147483392 + {{224, 0}, {16, 17}} + + _NS:18 + + + YES + + 773 + 16 + 1000 + + 75497536 + 2048 + + + LucidaGrande + 11 + 3100 + + + 3 + MC4zMzMzMzI5ODU2AA + + + 6 + System + headerTextColor + + 3 + MAA + + + + + 0 + 0 + + + 3 + YES + YES + + + + 3 + 2 + + 3 + MQA + + + 6 + System + gridColor + + 3 + MC41AA + + + 17 + 306184192 + + + 0 + 15 + 0 + YES + 0 + 1 + + + {{1, 1}, {776, 558}} + + + + _NS:11 + + + 6 + System + controlBackgroundColor + + 3 + MC42NjY2NjY2NjY3AA + + + 4 + + + + -2147483392 + {{224, 17}, {15, 102}} + + + + _NS:58 + NO + + _doScroller: + 0.99821109123434704 + + + + -2147483392 + {{1, 544}, {776, 15}} + + + + _NS:60 + NO + 1 + + _doScroller: + 0.99871299871299868 + + + {{-1, -1}, {778, 560}} + + + + _NS:9 + 133682 + + + + QSAAAEEgAABBmAAAQZgAAA + 0.25 + 4 + 1 + + + {776, 558} + + + + + {{0, 0}, {1600, 1178}} + {10000000000000, 10000000000000} + YES + + + YES + + + + + YES + + + window + + + + 6 + + + + _mainScrollView + + + + 36 + + + + _mainOutlineView + + + + 37 + + + + _toolbar + + + + 38 + + + + _toolbarOpenFolder + + + + 39 + + + + _toolbarSave + + + + 40 + + + + ActionOpenFolder: + + + + 41 + + + + ActionSave: + + + + 42 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 2 + + + YES + + + + + + + 3 + + + YES + + + + + + 14 + + + YES + + + + + + + + + 15 + + + + + 18 + + + + + 20 + + + + + 21 + + + + + 22 + + + YES + + + + + + + + 23 + + + YES + + + + + + 24 + + + + + 26 + + + + + 27 + + + YES + + + + + + 44 + + + + + 71 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 14.IBPluginDependency + 15.IBPluginDependency + 18.IBPluginDependency + 2.IBPluginDependency + 2.IBWindowTemplateEditedContentRect + 2.NSWindowTemplate.visibleAtLaunch + 20.IBPluginDependency + 20.designableToolbarItemIdentifier + 21.IBPluginDependency + 21.designableToolbarItemIdentifier + 22.IBPluginDependency + 23.IBPluginDependency + 24.IBPluginDependency + 26.IBPluginDependency + 27.IBPluginDependency + 3.IBPluginDependency + 44.IBPluginDependency + 71.CustomClassName + 71.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{319, 371}, {606, 354}} + + com.apple.InterfaceBuilder.CocoaPlugin + ToolbarOpen + com.apple.InterfaceBuilder.CocoaPlugin + ToolbarSave + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + ImageAndTextCell + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 71 + + + + YES + + ImageAndTextCell + NSTextFieldCell + + IBProjectSource + ./Classes/ImageAndTextCell.h + + + + MainWindow + NSWindow + + YES + + YES + ActionOpenFolder: + ActionSave: + + + YES + id + id + + + + YES + + YES + ActionOpenFolder: + ActionSave: + + + YES + + ActionOpenFolder: + id + + + ActionSave: + id + + + + + YES + + YES + _mainOutlineView + _mainScrollView + _toolbar + _toolbarOpenFolder + _toolbarSave + + + YES + NSOutlineView + NSScrollView + NSToolbar + NSToolbarItem + NSToolbarItem + + + + YES + + YES + _mainOutlineView + _mainScrollView + _toolbar + _toolbarOpenFolder + _toolbarSave + + + YES + + _mainOutlineView + NSOutlineView + + + _mainScrollView + NSScrollView + + + _toolbar + NSToolbar + + + _toolbarOpenFolder + NSToolbarItem + + + _toolbarSave + NSToolbarItem + + + + + IBProjectSource + ./Classes/MainWindow.h + + + + MainWindowController + NSWindowController + + IBProjectSource + ./Classes/MainWindowController.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + + YES + + YES + NSMenuCheckmark + NSMenuMixedState + disk-24 + folder-open-24 + + + YES + {11, 11} + {10, 3} + {24, 24} + {24, 24} + + + + + + + NSCell + + + + diff --git a/Mac/MainWindowController.cs b/Mac/MainWindowController.cs new file mode 100644 index 0000000..c39fd21 --- /dev/null +++ b/Mac/MainWindowController.cs @@ -0,0 +1,48 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using MonoMac.Foundation; +using MonoMac.AppKit; + +namespace NBTExplorer +{ + public partial class MainWindowController : MonoMac.AppKit.NSWindowController + { + #region Constructors + + // Called when created from unmanaged code + public MainWindowController (IntPtr handle) : base (handle) + { + Initialize (); + } + + // Called when created directly from a XIB file + [Export ("initWithCoder:")] + public MainWindowController (NSCoder coder) : base (coder) + { + Initialize (); + } + + // Call to load from the XIB/NIB file + public MainWindowController () : base ("MainWindow") + { + Initialize (); + } + + // Shared initialization code + void Initialize () + { + } + + #endregion + + //strongly typed window accessor + public new MainWindow Window { + get { + return (MainWindow)base.Window; + } + } + } +} + diff --git a/Mac/Scratch.cs b/Mac/Scratch.cs new file mode 100644 index 0000000..3313185 --- /dev/null +++ b/Mac/Scratch.cs @@ -0,0 +1,177 @@ +using System; + +namespace NBTExplorer.Mac.Test +{ + public partial class MainWindow : MonoMac.AppKit.NSWindow + { + // ... + + [Outlet] + MonoMac.AppKit.NSOutlineView _mainOutlineView { get; set; } + + private TreeDataSource _dataSource; + + public override void AwakeFromNib () + { + base.AwakeFromNib (); + + _dataSource = new TreeDataSource(); + _mainOutlineView.DataSource = _dataSource; + _mainOutlineView.Delegate = new MyDelegate(this); + } + + public class MyDelegate : NSOutlineViewDelegate + { + private MainWindow _main; + + public MyDelegate (MainWindow main) + { + _main = main; + } + + public override void ItemWillExpand (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + Console.WriteLine ("Preparing to expand: " + node.Data.NodeDisplay); + _main.ExpandNode(node); + } + } + + public override void ItemDidExpand (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + Console.WriteLine("Finished Expanding: " + node.Data.NodeDisplay); + } + } + + public override void ItemWillCollapse (NSNotification notification) + { + TreeDataNode node = notification.UserInfo ["NSObject"] as TreeDataNode; + if (node != null) { + if (node.Data.NodeDisplay == "saves") // The root node + Console.WriteLine ("Uh-oh..."); + Console.WriteLine("Preparing to collapse: " + node.Data.NodeDisplay); + } + } + } + + // ... + + private void ExpandNode (TreeDataNode node) + { + if (node == null || node.IsExpanded) + return; + + Console.WriteLine ("Expand Node: " + node.Data.NodeDisplay); + + node.IsExpanded = true; + node.Nodes.Clear (); + + DataNode backNode = node.Data; + if (!backNode.IsExpanded) { + backNode.Expand (); + } + + foreach (DataNode child in backNode.Nodes) { + if (child != null) { + node.Nodes.Add (new TreeDataNode (child)); + } + } + } + } + + public class TreeDataSource : NSOutlineViewDataSource + { + private List _nodes; + + public TreeDataSource () + { + _nodes = new List(); + } + + public List Nodes + { + get { return _nodes; } + } + + public override int GetChildrenCount (NSOutlineView outlineView, NSObject item) + { + if (item is TreeDataNode) { + TreeDataNode nodeItem = item as TreeDataNode; + return nodeItem.Nodes.Count; + } + + return _nodes.Count; + } + + public override NSObject GetObjectValue (NSOutlineView outlineView, NSTableColumn forTableColumn, NSObject byItem) + { + TreeDataNode nodeItem = byItem as TreeDataNode; + if (nodeItem == null) + return null; + + return (NSString)nodeItem.CombinedName; + } + + public override NSObject GetChild (NSOutlineView outlineView, int childIndex, NSObject ofItem) + { + TreeDataNode nodeItem = ofItem as TreeDataNode; + if (nodeItem != null) { + return nodeItem.Nodes [childIndex]; + } + + return Nodes[childIndex]; + } + + public override bool ItemExpandable (NSOutlineView outlineView, NSObject item) + { + TreeDataNode nodeItem = item as TreeDataNode; + if (nodeItem != null) + return nodeItem.HasChildren; + + return false; + } + } + + public class TreeDataNode : NSObject + { + private DataNode _dataNode; + private List _children; + private bool _expanded; + + public TreeDataNode (DataNode node) + { + _dataNode = node; + _children = new List(); + } + + public DataNode Data + { + get { return _dataNode; } + } + + public string CombinedName + { + get { return _dataNode.NodeDisplay; } + } + + public bool IsExpanded + { + get { return _expanded; } + set { _expanded = value; } + } + + public bool HasChildren + { + get { return _children.Count > 0 || _dataNode.HasUnexpandedChildren; } + } + + public List Nodes + { + get { return _children; } + } + } +} + diff --git a/Mac/TreeDataNode.cs b/Mac/TreeDataNode.cs new file mode 100644 index 0000000..6349bf0 --- /dev/null +++ b/Mac/TreeDataNode.cs @@ -0,0 +1,53 @@ +using System; +using MonoMac.Foundation; +using MonoMac.AppKit; +using NBTExplorer.Model; +using System.Collections.Generic; + +namespace NBTExplorer.Mac +{ + public class TreeDataNode : NSObject + { + private DataNode _dataNode; + private List _children; + private bool _expanded; + + public TreeDataNode (DataNode node) + { + _dataNode = node; + _children = new List(); + } + + public DataNode Data + { + get { return _dataNode; } + } + + public string CombinedName + { + get { return _dataNode.NodeDisplay; } + } + + public string Name + { + get { return _dataNode.NodeName; } + } + + public bool IsExpanded + { + get { return _expanded; } + set { _expanded = value; } + } + + public bool HasChildren + { + get { return _children.Count > 0 || _dataNode.HasUnexpandedChildren; } + } + + public List Nodes + { + get { return _children; } + } + } +} + diff --git a/Mac/TreeDataSource.cs b/Mac/TreeDataSource.cs new file mode 100644 index 0000000..2791c2e --- /dev/null +++ b/Mac/TreeDataSource.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using MonoMac.AppKit; +using MonoMac.Foundation; + +namespace NBTExplorer.Mac +{ + public class TreeDataSource : NSOutlineViewDataSource + { + private List _nodes; + + public TreeDataSource () + { + _nodes = new List(); + } + + public List Nodes + { + get { return _nodes; } + } + + public override int GetChildrenCount (NSOutlineView outlineView, NSObject item) + { + if (item is TreeDataNode) { + TreeDataNode nodeItem = item as TreeDataNode; + return nodeItem.Nodes.Count; + } + + return _nodes.Count; + } + + public override NSObject GetObjectValue (NSOutlineView outlineView, NSTableColumn forTableColumn, NSObject byItem) + { + TreeDataNode nodeItem = byItem as TreeDataNode; + if (nodeItem == null) + return null; + + return (NSString)nodeItem.CombinedName; + } + + public override NSObject GetChild (NSOutlineView outlineView, int childIndex, NSObject ofItem) + { + TreeDataNode nodeItem = ofItem as TreeDataNode; + if (nodeItem != null) { + return nodeItem.Nodes [childIndex]; + } + + return Nodes[childIndex]; + } + + public override bool ItemExpandable (NSOutlineView outlineView, NSObject item) + { + TreeDataNode nodeItem = item as TreeDataNode; + if (nodeItem != null) + return nodeItem.HasChildren; + + return false; + } + } +} + diff --git a/MainForm.resources b/MainForm.resources new file mode 100644 index 0000000..9c8c28e Binary files /dev/null and b/MainForm.resources differ diff --git a/Model/TagCompoundDataNode.cs b/Model/TagCompoundDataNode.cs index d4810ae..e6a36d5 100644 --- a/Model/TagCompoundDataNode.cs +++ b/Model/TagCompoundDataNode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using NBTExplorer.Windows; using Substrate.Nbt; namespace NBTExplorer.Model diff --git a/Model/TagDataNode.cs b/Model/TagDataNode.cs index 9ddc61f..0631752 100644 --- a/Model/TagDataNode.cs +++ b/Model/TagDataNode.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Windows.Forms; +//susing System.Windows.Forms; using Substrate.Nbt; namespace NBTExplorer.Model @@ -221,11 +221,12 @@ namespace NBTExplorer.Model public override bool RenameNode () { - if (CanRenameNode && TagParent.IsNamedContainer) { - EditName form = new EditName(TagParent.NamedTagContainer.GetTagName(Tag)); - form.InvalidNames.AddRange(TagParent.NamedTagContainer.TagNamesInUse); - if (form.ShowDialog() == DialogResult.OK && form.IsModified) { - if (TagParent.NamedTagContainer.RenameTag(Tag, form.TagName)) { + if (CanRenameNode && TagParent.IsNamedContainer && FormRegistry.EditString != null) { + RestrictedStringFormData data = new RestrictedStringFormData(TagParent.NamedTagContainer.GetTagName(Tag)); + data.RestrictedValues.AddRange(TagParent.NamedTagContainer.TagNamesInUse); + + if (FormRegistry.RenameTag(data)) { + if (TagParent.NamedTagContainer.RenameTag(Tag, data.Value)) { IsModified = true; return true; } @@ -284,61 +285,77 @@ namespace NBTExplorer.Model protected bool EditScalarValue (TagNode tag) { - EditValue form = new EditValue(tag); - if (form.ShowDialog() == DialogResult.OK) { - IsModified = true; - return true; + if (FormRegistry.EditTagScalar != null) { + if (FormRegistry.EditTagScalar(new TagScalarFormData(tag))) { + IsModified = true; + return true; + } } - else - return false; + return false; } protected bool EditStringValue (TagNode tag) { - EditString form = new EditString(tag.ToTagString().Data); - if (form.ShowDialog() == DialogResult.OK) { - tag.ToTagString().Data = form.StringValue; - - IsModified = true; - return true; + if (FormRegistry.EditString != null) { + StringFormData data = new StringFormData(tag.ToTagString().Data); + if (FormRegistry.EditString(data)) { + tag.ToTagString().Data = data.Value; + IsModified = true; + return true; + } } - else - return false; + return false; } protected bool EditByteHexValue (TagNode tag) { - HexEditor form = new HexEditor(NodeName, tag.ToTagByteArray().Data, 1); - if (form.ShowDialog() == DialogResult.OK && form.Modified) { - Array.Copy(form.Data, tag.ToTagByteArray().Data, tag.ToTagByteArray().Length); + if (FormRegistry.EditByteArray != null) { + byte[] byteData = new byte[tag.ToTagByteArray().Length]; + Array.Copy(tag.ToTagByteArray().Data, byteData, byteData.Length); - IsModified = true; - return true; + ByteArrayFormData data = new ByteArrayFormData() { + NodeName = NodeName, + BytesPerElement = 1, + Data = byteData, + }; + + if (FormRegistry.EditByteArray(data)) { + Array.Copy(data.Data, tag.ToTagByteArray().Data, tag.ToTagByteArray().Length); + IsModified = true; + return true; + } } - else - return false; + + return false; } protected bool EditIntHexValue (TagNode tag) { - TagNodeIntArray iatag = tag.ToTagIntArray(); - byte[] data = new byte[iatag.Length * 4]; - for (int i = 0; i < iatag.Length; i++) { - byte[] buf = BitConverter.GetBytes(iatag.Data[i]); - Array.Copy(buf, 0, data, 4 * i, 4); - } - - HexEditor form = new HexEditor(NodeName, data, 4); - if (form.ShowDialog() == DialogResult.OK && form.Modified) { + if (FormRegistry.EditByteArray != null) { + TagNodeIntArray iatag = tag.ToTagIntArray(); + byte[] byteData = new byte[iatag.Length * 4]; for (int i = 0; i < iatag.Length; i++) { - iatag.Data[i] = BitConverter.ToInt32(form.Data, i * 4); + byte[] buf = BitConverter.GetBytes(iatag.Data[i]); + Array.Copy(buf, 0, byteData, 4 * i, 4); } - IsModified = true; - return true; + ByteArrayFormData data = new ByteArrayFormData() { + NodeName = NodeName, + BytesPerElement = 4, + Data = byteData, + }; + + if (FormRegistry.EditByteArray(data)) { + for (int i = 0; i < iatag.Length; i++) { + iatag.Data[i] = BitConverter.ToInt32(data.Data, i * 4); + } + + IsModified = true; + return true; + } } - else - return false; + + return false; } } } diff --git a/TagKey.cs b/Model/TagKey.cs similarity index 96% rename from TagKey.cs rename to Model/TagKey.cs index d9279f1..a6f73bb 100644 --- a/TagKey.cs +++ b/Model/TagKey.cs @@ -1,7 +1,7 @@ using System; using Substrate.Nbt; -namespace NBTExplorer +namespace NBTExplorer.Model { public class TagKey : IComparable { diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index 60c630e..a207237 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -58,6 +58,7 @@ TRACE True pdbonly + AnyCPU bin\Release\NBTExplorer.exe.CodeAnalysisLog.xml true GlobalSuppressions.cs @@ -79,60 +80,60 @@ - + + Form - + CancelSearchForm.cs - - + + Form - + MainForm.cs - - + Form - + About.cs - + Form - + EditName.cs - + Form - + EditString.cs - + Form - + CreateNode.cs - + Form - + EditValue.cs - + Form - + Find.cs - + Form - + EditHex.cs @@ -169,6 +170,7 @@ Settings.settings + Component @@ -189,32 +191,33 @@ - + + CancelSearchForm.cs - + MainForm.cs Designer - + About.cs - + EditName.cs - + EditString.cs - + CreateNode.cs - + EditValue.cs - + Find.cs - + EditHex.cs @@ -233,7 +236,6 @@ Designer - @@ -245,6 +247,7 @@ +