Esempio n. 1
0
        private void newEntryTool_Click(object sender, EventArgs e)
        {
            string defCate;

            if (listView1.SelectedItems.Count > 0)
            {
                defCate = ((Category)listView1.SelectedItems[0].Tag).name;
                if (defCate == NoCategory)
                {
                    defCate = string.Empty;
                }
            }
            else
            {
                defCate = String.Empty;
            }

            // ==============================================================

            frmCsfEntryEdit f = new frmCsfEntryEdit(DevStringTable.Instance);

            //f.Text = translateData["GUI:CSFNewEntry"];
            f.name      = defCate;
            f.content   = string.Empty;
            f.extraData = string.Empty;

            f.ShowDialog(this);

            while (!f.isCanceled && !CheckEntryName(f.name, 1))
            {
                f.ShowDialog(this);
            }

            Entry ent = new Entry(this);

            if (!f.isCanceled)
            {
                string newCate = GetCategory(f.name);
                ent.cate = newCate;

                bool cateExists = true;
                // 类别是否存在?
                try
                {
                    ent.parent = Find(newCate);
                }
                catch
                {
                    Category newCat = new Category();
                    newCat.name = newCate;
                    newCat.data = new List <Entry>();
                    fileData.Add(newCat);

                    ent.parent = newCat;

                    cateExists = false;
                }

                ent.parent.data.Add(ent);

                ent.name  = f.name;
                ent.extra = f.extraData;
                ent.text  = f.content;

                if (!cateExists | newCate != defCate)
                {
                    //isMCListed = true;
                    ListCategory();//ent.parent
                    ListEntry(ent.parent, ent);
                }
                else
                {
                    ListViewItem itm = listView2.Items.Add(ent.name);
                    itm.Tag = ent;
                    itm.SubItems.Add(ent.text);
                    itm.SubItems.Add(ent.extra);
                    itm.Selected = true;

                    ListViewItem[] cis = listView1.Items.Find(defCate, false);

                    if (cis.Length > 0)
                    {
                        cis[0].SubItems[1].Text = (int.Parse(cis[0].SubItems[1].Text) + 1).ToString();
                    }
                }

                Saved = false;
            }

            f.Dispose();
        }
Esempio n. 2
0
        bool EditEntry(Entry ent, out bool isNewCate, IWindowsFormsEditorService edSvc)
        {
            frmCsfEntryEdit f = new frmCsfEntryEdit(DevStringTable.Instance);

            //f.Text = Program.StringTable["GUI:CSFEdit"];
            f.name      = ent.name;
            f.content   = ent.text;
            f.extraData = ent.extra;

            if (edSvc == null)
            {
                f.ShowDialog(this);
            }
            else
            {
                edSvc.ShowDialog(f);
            }

            while (!f.isCanceled && !CheckEntryName(f.name, 2))
            {
                if (edSvc == null)
                {
                    f.ShowDialog(this);
                }
                else
                {
                    edSvc.ShowDialog(f);
                }
            }

            isNewCate = false;
            if (!f.isCanceled)
            {
                string newCate = GetCategory(f.name);

                // 类别是否相同?
                if (newCate != ent.cate)
                {
                    isNewCate = true;

                    // 从旧类别中去除
                    ent.parent.data.Remove(ent);
                    FlushCategory(ent.parent);

                    ent.cate = newCate;

                    // 新类别是否存在?
                    try
                    {
                        ent.parent = Find(newCate);
                    }
                    catch
                    {
                        Category newCat = new Category();
                        newCat.name = newCate;
                        newCat.data = new List <Entry>();
                        fileData.Add(newCat);

                        ent.parent = newCat;
                    }

                    ent.parent.data.Add(ent);
                }

                ent.name  = f.name;
                ent.extra = f.extraData;
                ent.text  = f.content;

                f.Dispose();
                return(true);
            }

            f.Dispose();
            return(false);
        }