using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Editor
{
    public partial class ReferencesDialog : Form
    {
        public ReferencesDialog()
        {
            InitializeComponent();
        }

        public void SetReferences(string[] references)
        {
            TreeView referencesTreeView  = Controls["refTreeView"] as TreeView;

            if (referencesTreeView == null)
            {
                throw new Exception("We have a big issue, we expect to have a tree view here!");
            }

            referencesTreeView.Nodes.Clear();

            foreach (string refStr in references)
            {
                referencesTreeView.Nodes.Add(refStr);
            }
        }

        public void AddReference(string refStr)
        {
            TreeView referencesTreeView  = Controls["refTreeView"] as TreeView;

            if (referencesTreeView == null)
            {
                throw new Exception("We have a big issue, we expect to have a tree view here!");
            }
            referencesTreeView.Nodes.Add(refStr);
        }

        public string[] GetReferences()
        {
            TreeView referencesTreeView  = Controls["refTreeView"] as TreeView;

            if (referencesTreeView == null)
            {
                throw new Exception("We have a big issue, we expect to have a tree view here!");
            }

            string[] references = new string[referencesTreeView.Nodes.Count];

            for (int i = 0; i < references.Length; i++)
            {
                references[i] = referencesTreeView.Nodes[i].Text;
            }

            return references;
        }

        private void addRefBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog fDialog = new OpenFileDialog();

            if (fDialog.ShowDialog() == DialogResult.OK)
            {
                AddReference(fDialog.FileName);
            }
        }

        private void validateRefBtn_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void cancelRefBtn_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void removeBtn_Click(object sender, EventArgs e)
        {
            TreeView referencesTreeView = Controls["refTreeView"] as TreeView;

            referencesTreeView.Nodes.Remove(referencesTreeView.SelectedNode);
        }
    }
}