private void btnSaveCategories_Click(object sender, EventArgs e) { try { string central, user; Utilities.CategorySettingsFile.GetFolders(out central, out user); string target = central; if (Utilities.Utility.CanWriteToFolder(central) == false) { target = user; } saveFileDialog1.Filter = "CategorySettings Files(*.categories)|*.categories|All Files(*.*)|*.*"; saveFileDialog1.InitialDirectory = target; if (saveFileDialog1.ShowDialog(this) == DialogResult.OK) { // we need to capture the current settings Utilities.CategorySettingsFile cf = new Utilities.CategorySettingsFile(saveFileDialog1.FileName); populateCategoriesToSave(cf, treeView1.Nodes[0]); cf.Save(saveFileDialog1.FileName); MessageBox.Show("Current Settings saved as " + cf.Name + Environment.NewLine + "File: " + cf.Filename); } } catch (Exception ex) { MessageBox.Show("Unexpected error while attempting to save category list: " + ex.GetType().Name + ": " + ex.Message); } }
private void onCategorySettingChanged(object sender, EventArgs e) { if (cbSelectionSets.SelectedIndex == 0) { return; // the select entry. } // first, set all nodes to blank. updateChecks(treeView1.Nodes[0], false); // now let's retrieve all of the nodes which are set. HashSet <int> idsToEnable = new HashSet <int>(); HashSet <int> typesToEnable = new HashSet <int>(); Utilities.CategorySettingsFile cf = cbSelectionSets.SelectedItem as Utilities.CategorySettingsFile; if (cf != null) { foreach (Utilities.CategorySetting cs in cf.Settings) { // look specifically for types first. if (cs.Name.ToUpper().StartsWith("TYPE:")) { if (cs.Enabled) { typesToEnable.Add(cs.CategoryId); } } else { // regular categories. if (cs.Enabled) { idsToEnable.Add(cs.CategoryId); } } } } updateChecksByInfo(treeView1.Nodes[0], idsToEnable, typesToEnable); }
private void populateCategoriesToSave(Utilities.CategorySettingsFile cf, TreeNode node) { if (node.Tag is Category) { Category c = node.Tag as Category; if (node.Checked) { cf.Settings.Add(new Utilities.CategorySetting() { Name = c.Name, CategoryId = c.Id.IntegerValue, Enabled = true }); } } // let's handle CategoryType level selections differently. Store just the categorytype, and none of the children. if (node.Tag is CategoryType) { CategoryType cType = (CategoryType)node.Tag; if (node.Checked && areAllChildrenChecked(node)) { // store as negative, to use as an indicator. cf.Settings.Add(new Utilities.CategorySetting() { Name = "Type:" + cType, CategoryId = (int)cType, Enabled = true }); // in this case, there's no need to store individuals, and the individuals might change over time. return; } } if (node.Nodes.Count > 0) { foreach (TreeNode child in node.Nodes) { populateCategoriesToSave(cf, child); } } }