示例#1
0
        public void LoadTable(IDataTable <T> table)
        {
            datatable = table;

            headers.Clear();
            FieldInfo[] fields = table.GetStructType().GetFields();
            foreach (FieldInfo info in fields)
            {
                DataTableHeader h = new DataTableHeader(info.Name);
                h.Clicked   += OnHeaderClicked;
                h.Repainted += OnRepaint;
                h.Resized   += OnResized;
                headers.Add(h);
            }
            keyHeader            = new DataTableHeader("Key", 80f);
            keyHeader.Repainted += OnRepaint;
            keyHeader.Resized   += OnResized;
            keyHeader.Clicked   += OnHeaderClicked;

            rows.Clear();
            table.ForEachEntries((string key, T value) =>
            {
                DataTableRow r = new DataTableRow(headers.Count, value, key);
                r.Clicked     += OnRowClicked;
                rows.Add(r);
            });
            OnSearchUpdated();
            RefreshRowSizes();
            Repaint();
        }
示例#2
0
        private void AddAction()
        {
            if (Event.current.type == EventType.Layout && addAction)
            {
                if (string.IsNullOrEmpty(idbox) || datatable.ContainsKey(idbox))
                {
                    int y = 1;
                    idbox = "NewEntry";
                    while (datatable.ContainsKey(idbox))
                    {
                        idbox = "NewEntry_" + y;
                        y++;
                    }
                }

                //todo CTRL - Z
                T            r   = datatable.CreateStruct();
                DataTableRow uir = new DataTableRow(headers.Count, r, idbox);
                uir.Clicked += OnRowClicked;
                datatable.SetEntry(idbox, r);
                rows.Add(uir);
                EditorUtility.SetDirty((ScriptableObject)datatable);
                GUI.FocusControl("");
                OnSearchUpdated();
                RefreshRowSizes();
                Repaint();
                OnRowClicked(uir, EventArgs.Empty);
            }

            addAction = false;
        }
示例#3
0
        private int SortSelected(DataTableRow x, DataTableRow y)
        {
            string A = selectedField.GetValue(x.row)?.ToString();
            string B = selectedField.GetValue(y.row)?.ToString();

            return(A.CompareTo(B));
        }
示例#4
0
 private void OnRowClicked(object sender, EventArgs e)
 {
     if (selectedRow != null)
     {
         selectedRow.SetSelected(false);
     }
     selectedRow = (DataTableRow)sender;
     selectedRow.SetSelected(true);
     idbox = selectedRow.key;
     Repaint();
 }
示例#5
0
        private void DeleteAction()
        {
            if (Event.current.type == EventType.Layout && deleteAction)
            {
                datatable.DeleteEntry(selectedRow.key);
                EditorUtility.SetDirty((ScriptableObject)datatable);
                int index = rows.IndexOf(selectedRow);
                rows.Remove(selectedRow);
                if (rows.Count > index - 1 && rows.Count != 0)
                {
                    OnRowClicked(rows[index - 1], EventArgs.Empty);
                }
                else
                {
                    selectedRow = null;
                    idbox       = "";
                    OnSearchUpdated();
                    Repaint();
                }
            }

            deleteAction = false;
        }
示例#6
0
 private int SortKeys(DataTableRow x, DataTableRow y)
 {
     return(x.key.CompareTo(y.key));
 }