public void AddNewTool() { NewToolDialog ntd = new NewToolDialog(this); ntd.ShowDialog(); ToolData.ToolTypes tt = ntd.CurrentToolType; Tool temp; if (CurrentProject != null) { temp = CurrentProject.Tools.Where(x => x.Language.ToLower() == tt.ToString().ToLower()).FirstOrDefault(); } else { temp = Tools.Where(x => x.Language.ToLower() == tt.ToString().ToLower()).FirstOrDefault(); } if (temp == null) { switch (tt) { case ToolData.ToolTypes.Javascript: JavascriptTool jt = new JavascriptTool(); if (CurrentProject != null) { CurrentProject.Tools.Add(jt); } else { Tools.Add(jt); } break; } } }
protected void OnAddTool(object parameter) { if (CurrentItem != null) { if (CurrentItem.GetType() == typeof(TreeViewItem)) { TreeViewItem tvItem = (TreeViewItem)CurrentItem; Tool tool; Project tempProject = null; if (tvItem.DataContext.GetType() == typeof(Project)) { tempProject = (Project)tvItem.DataContext; tool = new Tool(tempProject); tempProject.Tools.Add(tool); } else { tool = new Tool(null); } NewToolDialog ntd = new NewToolDialog(tool); ntd.ShowDialog(); UpdateCurrentItem(); OnPropertyChanged("CurrentItem"); TreeViewItem tvi = new TreeViewItem(); tvi.Header = tool.Name; tvi.DataContext = tool; TreeViewItem tvi_ = null; if (tempProject != null) { tvi_ = TreeViewItems.Where(x => x.Header.ToString() == tempProject.Name).FirstOrDefault(); } if (tvi_ != null) { tvi_.Items.Add(tvi); } else { TreeViewItems.Add(tvi); } Tools.Add(tool); CurrentItem = tvi; } } else { Tool tool = new Tool(); //object tool = new object(); NewToolDialog ntd = new NewToolDialog(tool); ntd.ShowDialog(); UpdateCurrentItem(); OnPropertyChanged("CurrentItem"); TreeViewItem tvi = new TreeViewItem(); tvi.Header = tool.Name; tvi.DataContext = tool; //Items.Add(tool); TreeViewItems.Add(tvi); Tools.Add(tool); CurrentItem = tvi; } }