Inheritance: Caliburn.Micro.Screen, IEditableScreen
Exemple #1
0
 private void setEditMode(MetaLabelsViewModel section, bool editMode)
 {
     section.CanEdit = editMode;
     foreach (var metaLabel in section.Content)
     {
         if (!metaLabel.Meta.IsEditable) continue;
         metaLabel.Meta.InEditMode = editMode;
         var poiMl = metaLabel.PoI.GetMetaLabels().First(ml => ml.Meta.Label == metaLabel.Meta.Label);
         if (poiMl != null)
         {
             poiMl.Meta.EditActive = editMode;
         }
     }
 }
Exemple #2
0
        public void UpdateCallOut()
        {
            Execute.OnUIThread(() =>
            {
                //Todo:Jeroen - Properly fix update changes (also remove labels/sections instead of add only)
                //If there is no poi, there is no info to collect! (Nothing to show here.. moving on)
                if (Poi == null) return;

                //Collect all info
                var defaultSection = new MetaLabelsViewModel
                {
                    DisplayName = "Info",
                    CallOut = CallOut,
                    Content = new BindableCollection<MetaLabel>()
                };
                var dict = new Dictionary<string, MetaLabelsViewModel> { { defaultSection.DisplayName, defaultSection } };

                //Get all labels from the poi
                var mll = Poi.GetMetaLabels();
                if (mll == null) return;
                foreach (var ml in mll)
                {
                    //If it is not visible, skip it!
                    if (!ml.Meta.VisibleInCallOut) continue;
                    //Get the section/category for the label
                    var sectionLabel = ml.Meta.Section;
                    if (string.IsNullOrEmpty(sectionLabel))
                        sectionLabel = "Info";

                    if (!dict.ContainsKey(sectionLabel))
                        dict[sectionLabel] = new MetaLabelsViewModel() { DisplayName = sectionLabel, CallOut = CallOut, Content = new BindableCollection<MetaLabel>() };
                    //Add label content
                    dict[sectionLabel].Content.Add(ml);
                }

                // Remove the default section if it is empty.
                if (defaultSection.Content.Count == 0) dict.Remove(defaultSection.DisplayName);

                //Propagate changes
                //Check if Sections exists
                if (Sections == null)
                    Sections = new BindableCollection<IEditableScreen>();

                //Propagate section changes
                var addSections = dict.Values.Where(k => Sections.All(g => g.DisplayName != k.DisplayName)).ToList();
                var remSections = Sections.Where(k => dict.Values.All(g => g.DisplayName != k.DisplayName)).ToList();
                foreach (var sect in remSections)
                    Sections.Remove(sect);
                foreach (var sect in addSections)
                    Sections.Add(sect);

                //propagate label changes
                foreach (var sect in Sections.OfType<MetaLabelsViewModel>().ToList())
                {
                    setEditMode(sect, InEditMode || Poi.NEffectiveStyle.TapMode == TapMode.CallOutEdit);
                    //foreach (var content in dict[sect.DisplayName].Content)
                    //{
                    //    var cont = sect.Content.FirstOrDefault(k => k.Meta.Title == content.Meta.Title);
                    //    if (cont != null)
                    //    {

                    //    }
                    //}
                    var addcontent = dict[sect.DisplayName].Content.Where(k => sect.Content.All(g => g.Meta.Title != k.Meta.Title)).ToList();
                    var remcontent = sect.Content.Where(k => dict[sect.DisplayName].Content.All(g => g.Meta.Title != k.Meta.Title)).ToList();
                    var updcontent = sect.Content.Where(k => dict[sect.DisplayName].Content.Any(g => g.Meta.Title == k.Meta.Title)).ToList();
                    foreach (var r in remcontent)
                        sect.Content.Remove(r);
                    foreach (var a in addcontent)
                        sect.Content.Add(a);
                    foreach (var u in updcontent)
                    {
                        var idx = sect.Content.IndexOf(u);
                        sect.Content.RemoveAt(idx);
                        sect.Content.Insert(idx, u);
                    }
                }

                var vms = Poi.ModelInstances.Values.Where(k => k.ViewModel != null).Select(k => k.ViewModel);
                foreach (var vm in vms)
                {
                    vm.CallOut = CallOut;
                    Sections.Add(vm);
                }

                foreach (var mf in Poi.GetMetaLabels().Where(k => k.Meta.Type == MetaTypes.mediafolder))
                {
                    var mvm = new MediaViewModel() { CallOut = CallOut, Label = mf, DisplayName = mf.Meta.Section };
                    Sections.Add(mvm);
                }
            });
        }