Example #1
0
        /// <summary>
        /// Displays a menu dialog from list of items
        /// </summary>
        public static List<MultiSelectionItem> ShowMultiSelectionDialog(string heading, List<MultiSelectionItem> items)
        {
            List<MultiSelectionItem> result = new List<MultiSelectionItem>();
            if (items == null) return result;

            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowMultiSelectionDialogDelegate d = ShowMultiSelectionDialog;
                return (List<MultiSelectionItem>)GUIGraphicsContext.form.Invoke(d, heading, items);
            }

            GUIWindow dlgMultiSelectOld = (GUIWindow)GUIWindowManager.GetWindow(2100);
            GUIDialogMultiSelect dlgMultiSelect = new GUIDialogMultiSelect();
            dlgMultiSelect.Init();
            GUIWindowManager.Replace(2100, dlgMultiSelect);

            try
            {
                dlgMultiSelect.Reset();
                dlgMultiSelect.SetHeading(heading);

                foreach (MultiSelectionItem multiSelectionItem in items)
                {
                    GUIListItem item = new GUIListItem();
                    item.Label = multiSelectionItem.ItemTitle;
                    item.Label2 = multiSelectionItem.ItemTitle2;
                    item.MusicTag = multiSelectionItem.Tag;
                    item.TVTag = multiSelectionItem.IsToggle;
                    item.Selected = multiSelectionItem.Selected;
                    dlgMultiSelect.Add(item);
                }

                dlgMultiSelect.DoModal(GUIWindowManager.ActiveWindow);

                if (dlgMultiSelect.DialogModalResult == ModalResult.OK)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        MultiSelectionItem item = items[i];
                        MultiSelectionItem newMultiSelectionItem = new MultiSelectionItem();
                        newMultiSelectionItem.ItemTitle = item.ItemTitle;
                        newMultiSelectionItem.ItemTitle2 = item.ItemTitle2;
                        newMultiSelectionItem.ItemID = item.ItemID;
                        newMultiSelectionItem.Tag = item.Tag;
                        try
                        {
                            newMultiSelectionItem.Selected = dlgMultiSelect.ListItems[i].Selected;
                        }
                        catch
                        {
                            newMultiSelectionItem.Selected = item.Selected;
                        }

                        result.Add(newMultiSelectionItem);
                    }
                }
                else
                    return null;

                return result;
            }
            finally
            {
                GUIWindowManager.Replace(2100, dlgMultiSelectOld);
            }
        }
Example #2
0
        /// <summary>
        /// Displays a menu dialog from list of items
        /// </summary>
        public static List <MultiSelectionItem> ShowMultiSelectionDialog(string heading, List <MultiSelectionItem> items)
        {
            List <MultiSelectionItem> result = new List <MultiSelectionItem>();

            if (items == null)
            {
                return(result);
            }

            if (GUIGraphicsContext.form.InvokeRequired)
            {
                ShowMultiSelectionDialogDelegate d = ShowMultiSelectionDialog;
                return((List <MultiSelectionItem>)GUIGraphicsContext.form.Invoke(d, heading, items));
            }

            GUIWindow            dlgMultiSelectOld = (GUIWindow)GUIWindowManager.GetWindow(2100);
            GUIDialogMultiSelect dlgMultiSelect    = new GUIDialogMultiSelect();

            dlgMultiSelect.Init();
            GUIWindowManager.Replace(2100, dlgMultiSelect);

            try
            {
                dlgMultiSelect.Reset();
                dlgMultiSelect.SetHeading(heading);

                foreach (MultiSelectionItem multiSelectionItem in items)
                {
                    GUIListItem item = new GUIListItem();
                    item.Label    = multiSelectionItem.ItemTitle;
                    item.Label2   = multiSelectionItem.ItemTitle2;
                    item.MusicTag = multiSelectionItem.Tag;
                    item.TVTag    = multiSelectionItem.IsToggle;
                    item.Selected = multiSelectionItem.Selected;
                    dlgMultiSelect.Add(item);
                }

                dlgMultiSelect.DoModal(GUIWindowManager.ActiveWindow);

                if (dlgMultiSelect.DialogModalResult == ModalResult.OK)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        MultiSelectionItem item = items[i];
                        MultiSelectionItem newMultiSelectionItem = new MultiSelectionItem();
                        newMultiSelectionItem.ItemTitle  = item.ItemTitle;
                        newMultiSelectionItem.ItemTitle2 = item.ItemTitle2;
                        newMultiSelectionItem.ItemID     = item.ItemID;
                        newMultiSelectionItem.Tag        = item.Tag;
                        try
                        {
                            newMultiSelectionItem.Selected = dlgMultiSelect.ListItems[i].Selected;
                        }
                        catch
                        {
                            newMultiSelectionItem.Selected = item.Selected;
                        }

                        result.Add(newMultiSelectionItem);
                    }
                }
                else
                {
                    return(null);
                }

                return(result);
            }
            finally
            {
                GUIWindowManager.Replace(2100, dlgMultiSelectOld);
            }
        }