Beispiel #1
0
        private void OpenList(DataManager.DataType dataType, GetEntry entryOp, CreateEntry createOp)
        {
            DataList choices = new DataList();

            choices.Text = dataType.ToString();
            string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true);
            choices.AddEntries(entries);
            choices.SelectedOKEvent = () => {
                if (choices.ChosenEntry > -1)
                {
                    ElementForm editor   = new ElementForm();
                    int         entryNum = choices.ChosenEntry;
                    editor.Text = entries[entryNum];
                    IEntryData data = entryOp(entryNum);
                    editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum;
                    DataEditor.LoadDataControls(data, editor.ControlPanel);

                    editor.OnOK += (object okSender, EventArgs okE) => {
                        object obj = data;
                        DataEditor.SaveDataControls(ref obj, editor.ControlPanel);
                        data = (IEntryData)obj;
                        DataManager.SaveData(entryNum, dataType.ToString(), data);
                        DataManager.Instance.ClearCache(dataType);
                        IEntryData   entryData    = ((IEntryData)data);
                        EntrySummary entrySummary = entryData.GenerateEntrySummary();
                        DataManager.Instance.DataIndices[dataType].Entries[entryNum] = entrySummary;
                        DataManager.Instance.SaveIndex(dataType);
                        choices.ModifyEntry(entryNum, entrySummary.GetLocalString(true));
                        editor.Close();
                    };
                    editor.OnCancel += (object okSender, EventArgs okE) => {
                        editor.Close();
                    };

                    editor.Show();
                }
            };
            choices.SelectedAddEvent = () => {
                ElementForm editor   = new ElementForm();
                int         entryNum = DataManager.Instance.DataIndices[dataType].Entries.Count;
                editor.Text = "New " + dataType.ToString();
                IEntryData data = createOp();
                editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum;
                DataEditor.LoadDataControls(data, editor.ControlPanel);

                editor.OnOK += (object okSender, EventArgs okE) => {
                    object obj = data;
                    DataEditor.SaveDataControls(ref obj, editor.ControlPanel);
                    data = (IEntryData)obj;
                    DataManager.SaveData(entryNum, dataType.ToString(), data);
                    DataManager.Instance.ClearCache(dataType);
                    IEntryData   entryData    = ((IEntryData)data);
                    EntrySummary entrySummary = entryData.GenerateEntrySummary();
                    DataManager.Instance.DataIndices[dataType].Entries.Add(entrySummary);
                    DataManager.Instance.SaveIndex(dataType);
                    entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true);
                    choices.AddEntry(entrySummary.GetLocalString(true));
                    editor.Close();
                };
                editor.OnCancel += (object okSender, EventArgs okE) => {
                    editor.Close();
                };

                editor.Show();
            };
            choices.Show();
        }