示例#1
0
        private void buttonCustomListNew_Click(object sender, EventArgs e)
        {
            // Get name of destination file
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Title = "Eagle - Save new custom list as...";
            dialog.Filter = "Eagle Custom List | *.ecl";
            var result = dialog.ShowDialog(this);
            if (result != DialogResult.OK) return;
            string filePath = dialog.FileName;
            string fileName = Path.GetFileNameWithoutExtension(filePath);

            // List existing list names
            var existingListNames = new List<string>();
            foreach (ListViewItem item in listView1.Items)
            {
                existingListNames.Add(item.Text);
            }

            // Create unique list name
            int counter = 1;
            string suffix = "";
            while (existingListNames.Contains(fileName + suffix))
            {
                suffix = String.Format(" ({0})", counter++);
            }
            string newListName = fileName + suffix;

            // Create actual IgnoreList
            IgnoreList list = new IgnoreList();
            list.Name = newListName;
            list.SaveAs(filePath);

            // Update list view
            ListViewItem newItem = new ListViewItem(newListName);
            newItem.SubItems.Add(filePath);
            listView1.Items.Add(newItem);

            dialog.Dispose();
        }