public override void Load(string fileName) { ContentName = fileName; if (pobject == null) { var dict = new PDictionary(); if (dict.Reload(fileName)) { pobject = dict; } else { var arr = new PArray(); if (!arr.Reload(fileName)) { MessageService.ShowError(GettextCatalog.GetString("Can't load plist file {0}.", fileName)); return; } pobject = arr; } Buffer = null; widget.SetPListContainer(pobject); pobject.Changed += (sender, e) => { Buffer = null; IsDirty = true; }; } this.IsDirty = false; }
void AddToTree(Gtk.TreeStore treeStore, Gtk.TreeIter iter, PArray arr) { iterTable[arr] = iter; for (int i = 0; i < arr.Count; i++) { var item = arr[i]; var txt = string.Format(GettextCatalog.GetString("Item {0}"), i); var subIter = iter.Equals(TreeIter.Zero) ? treeStore.AppendValues(txt, item) : treeStore.AppendValues(iter, txt, item); if (item is PArray) { AddToTree(treeStore, subIter, (PArray)item); } if (item is PDictionary) { AddToTree(treeStore, subIter, (PDictionary)item); } if (expandedObjects.Contains(item)) { treeview.ExpandRow(treeStore.GetPath(subIter), true); } } AddCreateNewEntry(iter); if (!rebuildArrays.Contains(arr)) { rebuildArrays.Add(arr); arr.Changed += HandleArrRebuild; } }
public override PObject Clone() { var array = new PArray(); foreach (var item in this) { array.Add(item.Clone()); } return(array); }
public PArray GetArray(string key) { var result = Get <PArray> (key); if (result == null) { this[key] = result = new PArray(); } return(result); }
public void SetPListContainer(PObjectContainer container) { if (!(container is PArray)) { throw new ArgumentException("The PList container must be a PArray.", "container"); } array = (PArray)container; array.Changed += OnArrayChanged; RefreshList(); }
void AddNewArrayElement(PArray array) { var values = PListScheme.AvailableKeys(array, CurrentTree); if (values == null) { array.Add(PObject.Create(DefaultNewObjectType)); } else if (values.Any()) { array.Add(values.First().Create()); } }
public static PObject FromNSObject(NSObject val) { if (val == null) { return(null); } var dict = val as NSDictionary; if (dict != null) { var result = new PDictionary(); foreach (var pair in dict) { string k = pair.Key.ToString(); result[k] = FromNSObject(pair.Value); } return(result); } var arr = val as NSArray; if (arr != null) { var result = new PArray(); uint count = arr.Count; for (uint i = 0; i < count; i++) { var obj = MonoMac.ObjCRuntime.Runtime.GetNSObject(arr.ValueAt(i)); if (obj != null) { result.Add(FromNSObject(obj)); } } return(result); } var str = val as NSString; if (str != null) { return(str.ToString()); } var nr = val as NSNumber; if (nr != null) { char t; unsafe { t = (char)*((byte *)MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend(val.Handle, selObjCType)); } if (t == 'c' || t == 'C' || t == 'B') { return(nr.BoolValue); } return(nr.Int32Value); } var date = val as NSDate; if (date != null) { return((DateTime)date); } var data = val as NSData; if (data != null) { var bytes = new byte[data.Length]; Marshal.Copy(data.Bytes, bytes, 0, (int)data.Length); return(bytes); } throw new NotSupportedException(val.ToString()); }
public PObject Create() { if (Type == PDictionary.Type) { var dictionary = new PDictionary(); foreach (var v in Values) { if (v.Required) { dictionary.Add(v.Identifier, v.Create()); } } // If nothing was required, create an initial one anyway if (dictionary.Count == 0) { var first = Values.FirstOrDefault(); if (first == null) { dictionary.Add("newNode", PObject.Create(PString.Type)); } else { dictionary.Add(first.Identifier ?? "newNode", first.Create()); } } return(dictionary); } else if (Type == PArray.Type) { var array = new PArray(); foreach (var v in Values) { if (v.Required) { array.Add(v.Create()); } } // If nothing was required, create an initial one anyway if (array.Count == 0) { var first = Values.FirstOrDefault(); if (first == null) { array.Add(PObject.Create(ArrayType)); } else { array.Add(first.Create()); } } return(array); } else if (Values.Any()) { return(Values.First().Create()); } else { var obj = PObject.Create(Type); if (!string.IsNullOrEmpty(Identifier) && !(this is Key)) { obj.SetValue(Identifier); } return(obj); } }
internal static PObject Conv(NSObject val) { if (val == null) { return(null); } if (val is NSDictionary) { var result = new PDictionary(); foreach (var pair in (NSDictionary)val) { string k = pair.Key.ToString(); result[k] = Conv(pair.Value); } return(result); } if (val is NSArray) { var result = new PArray(); var arr = NSArray.ArrayFromHandle <NSObject> (((NSArray)val).Handle); if (arr == null) { return(null); } foreach (var f in arr) { if (f != null) { result.Add(Conv(f)); } } return(result); } if (val is NSString) { return(((NSString)val).ToString()); } if (val is NSNumber) { var nr = (NSNumber)val; var str = Marshal.PtrToStringAnsi(MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend(val.Handle, selObjCType)); if (str == "c" || str == "C" || str == "B") { return(nr.BoolValue); } return(nr.Int32Value); } if (val is NSDate) { return(PDate.referenceDate + TimeSpan.FromSeconds(((NSDate)val).SecondsSinceReferenceDate)); } if (val is NSData) { var data = (NSData)val; var bytes = new byte[data.Length]; Marshal.Copy(data.Bytes, bytes, 0, (int)data.Length); return(bytes); } throw new NotSupportedException(val.ToString()); }