RecipeSelectDialog.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. using System.Xml;
  5. using Aitex.Core.UI.View.Common;
  6. namespace Aitex.Core.UI.Dialog
  7. {
  8. /// <summary>
  9. /// Interaction logic for RecipeSelectDialog.xaml
  10. /// </summary>
  11. public partial class RecipeSelectDialog : Window
  12. {
  13. private string _recipeList;
  14. public RecipeSelectDialog(string recipeList)
  15. {
  16. _recipeList = recipeList;
  17. InitializeComponent();
  18. Loaded += new RoutedEventHandler(RecipeSelectDialog_Loaded);
  19. }
  20. /// <summary>
  21. /// load recipe file list
  22. /// </summary>
  23. /// <param name="sender"></param>
  24. /// <param name="e"></param>
  25. void RecipeSelectDialog_Loaded(object sender, RoutedEventArgs e)
  26. {
  27. XmlDocument doc = new XmlDocument();
  28. doc.LoadXml(_recipeList);
  29. CreateTreeViewItems(doc.DocumentElement, this.treeView1);
  30. }
  31. /// <summary>
  32. /// Create TreeViewItems
  33. /// </summary>
  34. /// <param name="curElementNode"></param>
  35. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  36. {
  37. foreach (XmlElement ele in curElementNode.ChildNodes)
  38. {
  39. if (ele.Name == "File")
  40. {
  41. string fileName = ele.Attributes["Name"].Value;
  42. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  43. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  44. item.Tag = ele.Attributes["Name"].Value;
  45. item.ToolTip = ele.Attributes["Name"].Value;
  46. itemsControl.Items.Add(item);
  47. }
  48. else if (ele.Name == "Folder")
  49. {
  50. string folderName = ele.Attributes["Name"].Value;
  51. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  52. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  53. item.Tag = ele.Attributes["Name"].Value;
  54. CreateTreeViewItems(ele, item);
  55. item.IsExpanded = false;
  56. itemsControl.Items.Add(item);
  57. }
  58. }
  59. }
  60. /// <summary>
  61. /// Selected recipe file
  62. /// </summary>
  63. public string SelectedRecipe
  64. {
  65. get
  66. {
  67. var file = treeView1.SelectedItem as TreeViewFileItem;
  68. if (file != null)
  69. return file.FileName;
  70. return string.Empty;
  71. }
  72. }
  73. /// <summary>
  74. /// On click cancel button
  75. /// </summary>
  76. /// <param name="sender"></param>
  77. /// <param name="e"></param>
  78. private void btnCancel_Click(object sender, RoutedEventArgs e)
  79. {
  80. DialogResult = false;
  81. Hide();
  82. }
  83. /// <summary>
  84. /// On click ok button
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void btnOK_Click(object sender, RoutedEventArgs e)
  89. {
  90. DialogResult = true;
  91. Close();
  92. }
  93. private void TreeView1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  94. {
  95. btnOK_Click(sender, e);
  96. }
  97. }
  98. }