internal void SaveTo(StructuredText node) { node.Clear(); foreach (PreferenceItemBase t in _children) { PreferenceFolder ch_folder = t as PreferenceFolder; PreferenceFolderArray ch_array = t as PreferenceFolderArray; PreferenceItem ch_item = t as PreferenceItem; PreferenceLooseNode ch_loose = t as PreferenceLooseNode; if (ch_folder != null) { StructuredText ch = node.AddChild(ch_folder.Id); ch_folder.SaveTo(ch); } else if (ch_item != null) //item { if (ch_item.IsChanged) //デフォルト値と変わっていた場合のみ記録 { node.Set(ch_item.Id, ch_item.FormatValue()); } } else if (ch_array != null) // array { ch_array.SaveTo(node); } else if (ch_loose != null) { ch_loose.SaveTo(node.AddChild(ch_loose.Id)); } } }
//中身はValidation済みであることに注意 internal void ImportSnapshot(PreferenceFolder newvalues) { foreach (PreferenceItemBase t in _children) { PreferenceFolder child_folder = t as PreferenceFolder; if (child_folder != null) { child_folder.ImportSnapshot(newvalues.ChildAt(child_folder.Index) as PreferenceFolder); } else { PreferenceItem child_item = t as PreferenceItem; if (child_item != null) { child_item.ImportSnapshot(newvalues.ChildAt(child_item.Index) as PreferenceItem); } else { PreferenceLooseNode child_loosenode = t as PreferenceLooseNode; if (child_loosenode != null) { child_loosenode.ImportSnapshot(newvalues.ChildAt(child_loosenode.Index) as PreferenceLooseNode); } //FolderArray未サポート } } } }
protected IPrimitiveAdapter <T> _primitiveAdapter; //Parse等はGenericsパラメータで直接使えない public TypedPreferenceItem(PreferenceFolder parent, string id, int index, T initialValue, PreferenceItemValidator <T> validator, IPrimitiveAdapter <T> adapter) : base(parent, id, index) { _initialValue = initialValue; _validator = validator; _primitiveAdapter = adapter; }
internal PreferenceFolder _CreateNewFolder() { PreferenceFolder f = (PreferenceFolder)_template.CreateSnapshot(); _folders.Add(f); return(f); }
public PreferenceFolderArray(PlugInHost master, PreferenceFolder parent, string id, int index, PreferenceFolder template) : base(parent, id, index) { _master = master; _folders = new ArrayList(); _template = template; }
public IIntPreferenceItem DefineIntValue(IPreferenceFolder parent, string id, int initial_value, PreferenceItemValidator <int> validator) { PreferenceFolder f = CastFolder(parent); IntPreferenceItem item = new IntPreferenceItem(f, id, parent.ChildCount, initial_value, validator); f.AddChild(item); return(item); }
public IStringPreferenceItem DefineStringValue(IPreferenceFolder parent, string id, string initial_value, PreferenceItemValidator <string> validator) { PreferenceFolder f = CastFolder(parent); StringPreferenceItem item = new StringPreferenceItem(f, id, parent.ChildCount, initial_value, validator); f.AddChild(item); return(item); }
public IBoolPreferenceItem DefineBoolValue(IPreferenceFolder parent, string id, bool initial_value, PreferenceItemValidator <bool> validator) { PreferenceFolder f = CastFolder(parent); BoolPreferenceItem item = new BoolPreferenceItem(f, id, parent.ChildCount, initial_value, validator); f.AddChild(item); return(item); }
public IPreferenceLooseNode DefineLooseNode(IPreferenceFolder parent, IPreferenceLooseNodeContent content, string id) { PreferenceFolder p = CastFolder(parent); PreferenceLooseNode n = new PreferenceLooseNode(content, p, id, parent.ChildCount); p.AddChild(n); return(n); }
//これらはFolderとはちょっとコンベンション違う internal void LoadFrom(ArrayList notes) { _folders.Clear(); foreach (StructuredText ch in notes) { PreferenceFolder f = _CreateNewFolder(); f.LoadFrom(ch); } }
//IPreferenceBuilder実装 //TODO 以下でid duplication check だがこのあたりは起動するたびに必要なので過剰なチェックはいやらしいが public IPreferenceFolder DefineFolder(IPreferenceFolder parent, IPreferenceSupplier supplier, string id) { PreferenceFolder p = CastFolder(parent); PreferenceFolder ch = new PreferenceFolder(this, p, id, parent.ChildCount); p.AddChild(ch); ch.PreferenceSupplier = supplier == null? _supplier : supplier; //nullのときは自分自身を使う return(ch); }
public IPreferenceFolder DefineFolderArray(IPreferenceFolder parent, IPreferenceSupplier supplier, string id) { PreferenceFolder p = CastFolder(parent); PreferenceFolder template = new PreferenceFolder(this, p, id, parent.ChildCount); PreferenceFolderArray array = new PreferenceFolderArray(this, p, id, parent.ChildCount, template); p.AddChild(array); template.PreferenceSupplier = supplier == null? _supplier : supplier; //nullのときは自分自身のを使う return(template); }
internal override PreferenceItemBase CreateSnapshot() { PreferenceFolder snapshot = new PreferenceFolder(_master, _parent, _id, _index); snapshot.PreferenceSupplier = _supplier; foreach (PreferenceItemBase t in _children) { snapshot._children.Add(t.CreateSnapshot()); } return(snapshot); }
//Preferenceの内容を構築し、StorageNodeから読み込む internal void Build() { _supplierRootFolder = new PreferenceFolder(this, null, _supplierID, _index); _supplierRootFolder.PreferenceSupplier = _supplier; _supplier.InitializePreference(this, _supplierRootFolder); try { _loading = true; Debug.Assert(_storageNode.Parent != null); _supplierRootFolder.LoadFrom(_storageNode); } finally { _loading = false; } }
public PreferenceItem(PreferenceFolder parent, string id, int index) : base(parent, id, index) { }
public BoolPreferenceItem(PreferenceFolder parent, string id, int index, bool initialValue, PreferenceItemValidator <bool> validator) : base(parent, id, index, initialValue, validator, adapter) { }
public StringPreferenceItem(PreferenceFolder parent, string id, int index, string initialValue, PreferenceItemValidator <string> validator) : base(parent, id, index, initialValue, validator, adapter) { }
public PreferenceLooseNode(IPreferenceLooseNodeContent content, PreferenceFolder folder, string id, int index) : base(folder, id, index) { _content = content; }
internal void LoadFrom(StructuredText node) { bool dirty = false; int child_index = 0; int data_index = 0; while (child_index < _children.Count) { IPreferenceItemBase child = (IPreferenceItemBase)_children[child_index]; PreferenceFolder ch_folder = child as PreferenceFolder; PreferenceFolderArray ch_array = child as PreferenceFolderArray; PreferenceItem ch_item = child as PreferenceItem; PreferenceLooseNode ch_loose = child as PreferenceLooseNode; //TODO 以下の分岐汚すぎ、何とかする if (ch_folder != null) { StructuredText ch_data = node.GetChildOrNull(data_index); //大抵はうまく整列しているので検索の手間を省く if (ch_data == null || ch_data.Name != ch_folder.Id) { dirty = true; ch_data = node.FindChild(ch_folder.Id); } else { data_index++; } if (ch_data == null) { ch_folder.ResetValue(); } else { ch_folder.LoadFrom(ch_data); } } else if (ch_item != null) { StructuredText.Entry ch_data = node.GetEntryOrNull(data_index); //大抵はうまく整列しているので検索の手間を省く if (ch_data == null || ch_data.name != ch_item.Id) { dirty = true; ch_data = node.FindEntry(ch_item.Id); } else { data_index++; } if (ch_data == null) { ch_item.ResetValue(); } else { ch_item.TryToParse(ch_data.value, PreferenceItem.ErrorMode.Reset); } } else if (ch_array != null) { ArrayList ch_data = new ArrayList(); StructuredText t = node.GetChildOrNull(data_index); if (t == null || t.Name != ch_array.Id) { dirty = true; ch_data.Clear(); ch_data.AddRange(node.FindMultipleNote(ch_array.Id)); } else //最初の一つが合格だったら継続して読み続ける { data_index++; while (t != null && t.Name == ch_array.Id) { ch_data.Add(t); t = node.GetChildOrNull(data_index++); } } ch_array.LoadFrom(ch_data); } else if (ch_loose != null) { //TODO これはFolderのときと同じだ。まとめよう StructuredText ch_data = node.GetChildOrNull(data_index); //大抵はうまく整列しているので検索の手間を省く if (ch_data == null || ch_data.Name != ch_loose.Id) { dirty = true; ch_data = node.FindChild(ch_loose.Id); } else { data_index++; } if (ch_data == null) { ch_loose.ResetValue(); } else { ch_loose.LoadFrom(ch_data); } } child_index++; //自分の子をステップ } //一度エラーなく読むことができていればdirtyはfalseのまま node.IsDirty = dirty; }
public PreferenceFolder(PlugInHost master, PreferenceFolder parent, string id, int index) : base(parent, id, index) { _children = new ArrayList(); _master = master; }
protected PreferenceItemBase(PreferenceFolder folder, string id, int index) { _parent = folder; _id = id; _index = index; }