/**
  * Adds the section buttons' icons to the imgDict
  */
 public void GetSectionImages()
 {
     allChildren = SectionContentPar.GetComponentsInChildren <Transform>();
     foreach (Transform t in allChildren)
     {
         if (t.name.Equals("Image"))
         {
             if (t.GetComponent <Image>().sprite.name != null && !t.GetComponent <Image>().sprite.name.Equals(""))
             {
                 string             s   = t.GetComponent <Image>().sprite.name;
                 SpriteHolderScript shs = new SpriteHolderScript(s);
                 ds.AddImg(t.parent.Find("SectionLinkToText").GetComponent <Text>().text, t.GetComponent <Image>().sprite);
                 foreach (Image img in shs.iconHolder.GetComponentsInChildren <Image>())
                 {
                     if (img.sprite.name.Equals(s))
                     {
                         ds.AddImg(t.parent.Find("SectionLinkToText").GetComponent <Text>().text, img.transform.parent.name);
                         break;
                     }
                 }
             }
         }
     }
     //Debug.Log (string.Join (", ", ds.GetImages ().Keys.ToArray ()));
     //Debug.Log (string.Join ("-----", ds.GetImages ().Select (x => x.Value.GetXMLText()).ToArray ()));
 }
    /**
     * Opens the edit section panel. Pass in display text value
     */
    public void OpenSectionPanel(TextMeshProUGUI t)
    {
        if (BG == null)
        {
            Start();
        }

        tObject = t;

        sectionEditPrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/SectionEditorBG")) as GameObject;
        sectionEditPrefab.transform.SetParent(parentBG.transform, false);
        //editSectionPanel = transform.Find ("SectionEditorBG").gameObject;
        sectionEditPrefab.transform.SetAsLastSibling();
        sectionEditPrefab.transform.SetSiblingIndex(sectionEditPrefab.transform.GetSiblingIndex() - 1);
        sectionEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField>().text = t.text;
        colorPanelParent   = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row3");
        customColorParent  = colorPanelParent.Find("Column0/RowCustomColor/TMPInputField/ColorHexValue");
        colorSlidersParent = colorPanelParent.Find("Column1");
        deleteButton       = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row5/DeleteSectionButton");

        // Checks if this tab has Patient Info, if so then this section cannot be deleted
        foreach (Transform child in tm.TabButtonContentPar.transform)
        {
            if (child.name == "Personal InfoTabButton")
            {
                deleteButton.gameObject.SetActive(false);
            }
        }


        //Check the Background Info box if the background info tab is already spawned
        //Debug.Log(string.Join(",", ds.GetData(tm.getCurrentSection()).GetTabList().ToArray()));
        bool   spawn        = (ds.GetData(tm.getCurrentSection()).GetTabList().Find((string obj) => obj.StartsWith("Background_InfoTab")) != null);
        Toggle bgInfoToggle = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row1").GetComponentInChildren <Toggle>();

        bgInfoToggle.isOn = false;
        if (spawn)
        {
            bgInfoToggle.isOn = true;
        }

        //Set the selected section icon at the bottom to the section's current icon
        SpriteHolderScript shs = ds.GetImage(tObject.text);

        if (shs == null)
        {
            sectionEditPrefab.transform.Find("SectionEditorPanel/Content/ScrollView/Viewport/Content").GetChild(0).GetComponentInChildren <Toggle>().isOn = true;
        }
        else
        {
            foreach (Toggle tog in sectionEditPrefab.transform.Find("SectionEditorPanel/Content/ScrollView/Viewport/Content").GetComponentsInChildren <Toggle>())
            {
                if (tog.name.Equals(shs.referenceName))
                {
                    tog.isOn = true;
                }
                else
                {
                    tog.isOn = false;
                }
            }
        }

        //Set the selected color to the section's current color
        SpriteHolderScript temp;

        if ((temp = ds.GetImage(tObject.text)) != null && temp.useColor)
        {
            bool isColorCustom = true;
            foreach (Toggle tog in colorPanelParent.GetChild(0).GetComponentsInChildren <Toggle>())
            {
                if (tog.transform.GetComponent <Image> ().color == temp.color)
                {
                    isColorCustom = false;
                    tog.isOn      = true;
                }
                else
                {
                    tog.isOn = false;
                }
            }
            if (isColorCustom)
            {
                customColorParent.parent.parent.GetChild(0).GetComponent <Image> ().color = temp.color;
                customColorParent.parent.parent.GetChild(0).GetComponent <Toggle> ().isOn = true;

                /*
                 * //Set slider values
                 * colorSlidersParent.Find ("Row0/RSlider").GetComponent<Slider> ().value = temp.color.r;
                 * colorSlidersParent.Find ("Row1/GSlider").GetComponent<Slider> ().value = temp.color.g;
                 * colorSlidersParent.Find ("Row2/BSlider").GetComponent<Slider> ().value = temp.color.b;
                 * string newTextString = "";
                 * newTextString += ((int)(temp.color.r*255)).ToString ("X").PadLeft (2, '0');
                 * newTextString += ((int)(temp.color.g*255)).ToString ("X").PadLeft (2, '0');
                 * newTextString += ((int)(temp.color.b*255)).ToString ("X").PadLeft (2, '0');
                 * //Debug.Log (newTextString);
                 * customColorParent.GetComponentInChildren<TextMeshProUGUI> ().text = newTextString;
                 */
            }
            else
            {
                customColorParent.parent.parent.GetChild(0).GetComponent <Toggle> ().isOn = false;
            }

            //Set the slider values to match the section's current color
            colorSlidersParent.Find("Row0/RSlider").GetComponent <Slider> ().value = temp.color.r;
            colorSlidersParent.Find("Row1/GSlider").GetComponent <Slider> ().value = temp.color.g;
            colorSlidersParent.Find("Row2/BSlider").GetComponent <Slider> ().value = temp.color.b;
            string newTextString = "";
            newTextString += ((int)(temp.color.r * 255)).ToString("X").PadLeft(2, '0');
            newTextString += ((int)(temp.color.g * 255)).ToString("X").PadLeft(2, '0');
            newTextString += ((int)(temp.color.b * 255)).ToString("X").PadLeft(2, '0');
            //Debug.Log (newTextString);
            customColorParent.GetComponentInChildren <TextMeshProUGUI> ().text = newTextString;
        }
        //editSectionPanel.gameObject.SetActive (true);
    }