private void UpdateModelAndTemplates() { Templates.Clear(); CurrentModel = Models.GetCurrent(isForDeck); TemplatesJson = CurrentModel.GetNamedArray("tmpls"); foreach (var t in TemplatesJson) { uint newOrd = (uint)t.GetObject().GetNamedNumber("ord"); Templates.Add(new TemplateInformation(t.GetObject().GetNamedString("name"), newOrd)); } }
public void AddNewTemplate(string name, uint ordToClone = 0) { var newTemplate = Models.NewTemplate(name); var cloneTemplate = TemplatesJson.GetObjectAt(ordToClone); newTemplate["qfmt"] = JsonValue.CreateStringValue(cloneTemplate.GetNamedString("qfmt")); newTemplate["afmt"] = JsonValue.CreateStringValue(cloneTemplate.GetNamedString("afmt")); Models.AddTemplate(CurrentModel, newTemplate); Models.Save(CurrentModel, true); TemplatesJson = CurrentModel.GetNamedArray("tmpls"); Templates.Add(new TemplateInformation(name, (uint)newTemplate.GetNamedNumber("ord"))); }
public TemplateInformationViewModel(AnkiU.AnkiCore.Models models, bool forDeck = true) { isForDeck = forDeck; Models = models; CurrentModel = models.GetCurrent(isForDeck); TemplatesJson = CurrentModel.GetNamedArray("tmpls"); List <TemplateInformation> temp = new List <TemplateInformation>(); foreach (var template in TemplatesJson) { string name = template.GetObject().GetNamedString("name"); uint ord = (uint)template.GetObject().GetNamedNumber("ord"); TemplateInformation m = new TemplateInformation(name, ord); temp.Add(m); } temp.Sort((x, y) => { return(x.Ord.CompareTo(y.Ord)); }); this.Templates = new ObservableCollection <TemplateInformation>(temp); }