Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Windows.Forms;
  16. using System.IO;
  17.  
  18. namespace WpfApp1
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window
  24. {
  25. public MainWindow()
  26. {
  27. InitializeComponent();
  28. }
  29.  
  30. private void mnuOpen_Click(object sender, RoutedEventArgs e)
  31. {
  32. //MessageBox.Show("Open");
  33.  
  34. var dlg = new FolderBrowserDialog() { Description = "Select directory to open" };
  35. DialogResult dlgResult = dlg.ShowDialog();
  36.  
  37. //if (dlgResult == DialogResult.OK)
  38. {
  39. //string[] files = Directory.GetFiles(dlg.SelectedPath);
  40.  
  41. string selectedFolder = string.Empty;
  42. selectedFolder = dlg.SelectedPath;
  43. if (selectedFolder == "")
  44. return;
  45. DirectoryInfo dir = new DirectoryInfo(selectedFolder);
  46. //addSubdirs(dir, trv);
  47. foreach (var directory in dir.GetDirectories("*"))
  48. {
  49. //ratWalk.LoadFromFile(file.FullName);
  50. //
  51. var item = new TreeViewItem
  52. {
  53. Header = directory.Name,
  54. Tag = directory.FullName
  55. };
  56. //root.Items.Add(item);
  57. addSubdirs(directory, item);
  58. addFiles(directory, item);
  59. trv.Items.Add(item);
  60. }
  61. foreach (var file in dir.GetFiles("*"))
  62. {
  63. //ratWalk.LoadFromFile(file.FullName);
  64. //
  65. var item = new TreeViewItem
  66. {
  67. Header = file.Name,
  68. Tag = file.FullName
  69. };
  70. //root.Items.Add(item);
  71. trv.Items.Add(item);
  72. }
  73. }
  74.  
  75. }
  76. private void addSubdirs(DirectoryInfo dir, TreeViewItem currentRoot)
  77. {
  78. foreach (var directory in dir.GetDirectories("*"))
  79. {
  80. var item = new TreeViewItem
  81. {
  82. Header = directory.Name,
  83. Tag = directory.FullName
  84. };
  85. //root.Items.Add(item);
  86. addSubdirs(directory, item);
  87. addFiles(directory, item);
  88.  
  89. currentRoot.Items.Add(item);
  90. }
  91. }
  92. private void addFiles(DirectoryInfo dir, TreeViewItem currentRoot)
  93. {
  94. foreach (var file in dir.GetFiles("*"))
  95. {
  96. var item = new TreeViewItem
  97. {
  98. Header = file.Name,
  99. Tag = file.FullName
  100. };
  101. currentRoot.Items.Add(item);
  102. }
  103. }
  104.  
  105.  
  106. /*
  107. // Display the appropriate context menu.
  108. private void trv_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  109. {
  110. // Make sure this is the right button.
  111. if (e.Button != MouseButtons.Right) return;
  112.  
  113. // Select this node.
  114. //TreeNode node_here = trv.GetNodeAt(e.X, e.Y);
  115. TreeNode node_here = trv.;
  116. trv.SelectedNode = node_here;
  117.  
  118. // See if we got a node.
  119. if (node_here == null) return;
  120.  
  121. // See what kind of object this is and
  122. // display the appropriate popup menu.
  123. if (node_here.Tag is FactoryData)
  124. ctxFactory.Show(trvOrg, new Point(e.X, e.Y));
  125. else if (node_here.Tag is GroupData)
  126. ctxGroup.Show(trvOrg, new Point(e.X, e.Y));
  127. else if (node_here.Tag is PersonData)
  128. ctxPerson.Show(trvOrg, new Point(e.X, e.Y));
  129. }*/
  130.  
  131. /*
  132. private TreeNode m_OldSelectNode;
  133. private void trv_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  134. {
  135. // Show menu only if the right mouse button is clicked.
  136. if (e.Button == MouseButtons.Right)
  137. {
  138.  
  139. // Point where the mouse is clicked.
  140. Point p = new Point(e.X, e.Y);
  141.  
  142. // Get the node that the user has clicked.
  143. TreeNode node = trv.GetNodeAt(p);
  144. if (node != null)
  145. {
  146.  
  147. // Select the node the user has clicked.
  148. // The node appears selected until the menu is displayed on the screen.
  149. m_OldSelectNode = trv.SelectedNode;
  150. trv.SelectedNode = node;
  151.  
  152. // Find the appropriate ContextMenu depending on the selected node.
  153. switch (Convert.ToString(node.Tag))
  154. {
  155. case "TextFile":
  156. mnuTextFile.Show(treeView1, p);
  157. break;
  158. case "File":
  159. mnuFile.Show(treeView1, p);
  160. break;
  161. }
  162.  
  163. // Highlight the selected node.
  164. treeView1.SelectedNode = m_OldSelectNode;
  165. m_OldSelectNode = null;
  166. }
  167. }
  168. }*/
  169.  
  170. private void trv_SelChg(object sender, RoutedPropertyChangedEventArgs<object> e)
  171. {
  172. Console.WriteLine("asdfsd");
  173. Console.WriteLine(((TreeViewItem)e.NewValue).Tag.ToString());
  174.  
  175. FileAttributes attributes = File.GetAttributes(((TreeViewItem)e.NewValue).Tag.ToString());
  176. String attr_str="rahs";
  177.  
  178.  
  179. if ((attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
  180. {
  181. attr_str = attr_str.Replace('r', '-');
  182. }
  183. if ((attributes & FileAttributes.Archive) != FileAttributes.Archive)
  184. {
  185. attr_str = attr_str.Replace('a', '-');
  186. }
  187. if ((attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
  188. {
  189. attr_str = attr_str.Replace('h', '-');
  190. }
  191. if ((attributes & FileAttributes.System) != FileAttributes.System)
  192. {
  193. attr_str = attr_str.Replace('s', '-');
  194. }
  195.  
  196. sbtxt.Text = attr_str;
  197.  
  198. if (e.NewValue.ToString().Contains(".txt"))
  199. {
  200. using (var textReader = File.OpenText(((TreeViewItem)e.NewValue).Tag.ToString()))
  201. {
  202. string text = textReader.ReadToEnd();
  203. txtBlock.Text = text;
  204. }
  205.  
  206.  
  207. }
  208. else
  209. {
  210. txtBlock.Text = "";
  211. }
  212. }
  213.  
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement