// // Category list // void loadCategoryList() { try { selectedIndex = null; string content = File.ReadAllText(indexBox.Text); allIndex = JsonConvert.DeserializeObject<List<CategoryIndex>>(content); fileList.SetObjects(allIndex); panel1.Enabled = true; } catch (Exception ex) { Console.Write(ex.Message + "\r\n" + ex.StackTrace); closeOpenedBranch(); fileList.ClearObjects(); panel1.Enabled = false; } }
// // Close methods // void closeOpenedBranch() { closeEditing(); if (branchEdited) { branchEdited = false; selectedIndex.ver++; saveIndex(); } selectedIndex = null; treeList.ClearObjects(); splitContainer1.Enabled = false; catFileLabel.Text = "No Opened Category"; }
// // Category Branch // void loadCategoryBranch(CategoryIndex catIndx) { try { if (selectedIndex == catIndx) return; //first close previous branch closeOpenedBranch(); //open content string filename = getCategoryFile(catIndx.file); if (filename == null || !File.Exists(filename)) return; string content = File.ReadAllText(filename); //parse data selectedBranch = JsonConvert.DeserializeObject<CategoryNode>(content); selectedBranch.updateParent(); treeList.SetObjects(new CategoryNode[] { selectedBranch }); treeList.Expand(selectedBranch); treeList.SelectObject(selectedBranch); //set others selectedIndex = catIndx; splitContainer1.Enabled = true; catFileLabel.Text = string.Format("{0} : Version {1}", catIndx.file, catIndx.ver); } catch (Exception ex) { Console.Write(ex.Message + "\r\n" + ex.StackTrace); } }
private void addButton_Click(object sender, System.EventArgs e) { string name = filenameBox.Text; if (!isValidFile(name)) { MessageBox.Show("Filename is not valid"); return; } if (!name.EndsWith(EXTENSION)) name += EXTENSION; //check if category index already has similar file foreach (CategoryIndex v in allIndex) { if (v.file == name) { MessageBox.Show("Another file exist with same name"); return; } } CategoryIndex catInd = new CategoryIndex(name); string fullName = getCategoryFile(catInd.file); if (!File.Exists(fullName)) { string json = JsonConvert.SerializeObject(new CategoryNode(name), Formatting.Indented); File.WriteAllText(fullName, json); } allIndex.Add(catInd); fileList.SetObjects(allIndex); filenameBox.Clear(); saveIndex(); }