ExplorerUserControl.cs

Description du code

ExplorerUserControl.cs est un fichier du projet BrolExplorer.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/brolexplorer/.

Projet BrolExplorer :

Explorateur de media en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using be.gaudry.explorer.model;
  9. using System.IO;
  10. using be.gaudry.explorer.view;
  11. using System.Collections;
  12. using be.gaudry.events;
  13. using be.gaudry.explorer.filestats.view.controls;
  14. using be.gaudry.model.config;
  15. using be.gaudry.model.drawing;
  16. using be.gaudry.model;
  17. using be.gaudry.model.file;
  18. using be.gaudry.explorer.metadata.model.tags;
  19. using be.gaudry.explorer.metadata.view.dialogs;
  20.  
  21. namespace be.gaudry.explorer.view.controls
  22. {
  23. public partial class ExplorerUserControl : UserControl
  24. {
  25. #region constructor and declarations
  26. private String shell32Path;
  27. private BrolFileStatsControl statsControl;
  28. #region treeview
  29. private int imageIndex_Desktop,
  30. imageIndex_MyDocuments,
  31. imageIndex_MyPictures,
  32. imageIndex_MyFavorites,
  33. imageIndex_MyNetwork,
  34. imageIndex_MyComuter,
  35. imageIndex_HardDrive,
  36. imageIndex_DirectoryNormal,
  37. imageIndex_DirectoryExpanded;
  38. private String desktopName,
  39. myComputerName,
  40. myDocumentsName,
  41. myPicturesName,
  42. myFavoriteName,
  43. myNetworkName;
  44. private bool showMyDocuments,
  45. showMyPictures,
  46. showMyFavorites,
  47. showMyNetwork,
  48. showDesktop;
  49. #endregion
  50. /// <summary>
  51. /// Type of view (explorer or images) used to dislpay the files in the fileListView
  52. /// </summary>
  53. public enum FILES_DISPLAY
  54. {
  55. /// <summary>
  56. /// Displays an explorer on the right panel
  57. /// </summary>
  58. explorer,
  59. /// <summary>
  60. /// Displays an image browser the right panel
  61. /// </summary>
  62. images,
  63. /// <summary>
  64. /// Displays a stat view on the right panel
  65. /// </summary>
  66. stats
  67. };
  68. private FILES_DISPLAY display;
  69.  
  70. #region listview
  71. private bool groupIcons;
  72. // Declare a Hashtable array in which to store the groups.
  73. private Hashtable[] groupTables;
  74.  
  75. // Declare a variable to store the current grouping column.
  76. int groupColumn = 0;
  77. #endregion
  78.  
  79. public ExplorerUserControl()
  80. {
  81. shell32Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll");
  82.  
  83. groupIcons = false;
  84. showMyDocuments = true;
  85. showMyPictures = true;
  86. showMyFavorites = true;
  87. showMyNetwork = true;
  88. showDesktop = true;
  89. desktopName = "Bureau";
  90. myComputerName = "Poste de travail";
  91. myDocumentsName = "Mes documents";
  92. myPicturesName = "Mes images";
  93. myFavoriteName = "Mes favoris";
  94. myNetworkName = "Favoris réseau";
  95.  
  96. InitializeComponent();
  97. imagesBrowser.setContextMenuStrip(filesListViewCMS);
  98.  
  99. initStatControl();
  100.  
  101. toogleIconsGroups();
  102.  
  103. addSources();
  104. }
  105.  
  106. private void addSources()
  107. {
  108. SourcesManager.addSource(new Source(
  109. "Listview",
  110. this.Name,
  111. "http://msdn2.microsoft.com/fr-fr/library/z4ka5fex(VS.80).aspx",
  112. "Composant utilisé à droite dans l'explorateur"
  113. )
  114. );
  115.  
  116. SourcesManager.addSource(new Source(
  117. "Context menu",
  118. this.Name,
  119. "http://support.microsoft.com/kb/810001/fr",
  120. "Un menu contextuel pour treenode"
  121. )
  122. );
  123.  
  124. SourcesManager.addSource(new Source(
  125. "Shell Context menu",
  126. this.Name,
  127. "http://www.theserverside.net/tt/articles/showarticle.tss?id=ShellExtensions",
  128. "Context menu utilisant certaines fonctionnalités du shell32"
  129. )
  130. );
  131.  
  132. SourcesManager.addSource(new Source(
  133. "Groupes ListView",
  134. this.Name,
  135. "http://msdn2.microsoft.com/fr-fr/library/system.windows.forms.listviewitem.group(VS.80).aspx",
  136. "Utilisation de l'affichage par groupes dans le listview"
  137. )
  138. );
  139. }
  140.  
  141. private void initStatControl()
  142. {
  143.  
  144. //todo : test if stats exe exists
  145. statsControl = new BrolFileStatsControl();
  146. this.explorerSC.Panel2.Controls.Add(this.statsControl);
  147. // statsControl.mainCMS.Items.AddRange(filesListViewCMS.Items);
  148. statsCTsMi.DropDownItems.Add(statsControl.searchOptionsTsMi);
  149. statsCTsMi.DropDownItems.Add(statsControl.displayOptionsTsMi);
  150. showStatsOptions(false);
  151. statsControl.ContextMenuStrip = filesListViewCMS;
  152. this.statsControl.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  153. this.statsControl.Dock = System.Windows.Forms.DockStyle.Fill;
  154. this.statsControl.Visible = false;
  155. }
  156. #endregion
  157.  
  158. #region properties
  159. [
  160. Category("Action"),
  161. Browsable(true),
  162. Description("Event called on file selected")
  163. ]
  164. public event FileSelectedEventHandler FileSelected;
  165. [
  166. Category("Action"),
  167. Browsable(true),
  168. Description("Event called on directory selected")
  169. ]
  170. public event FileSelectedEventHandler DirectorySelected;
  171. /// <summary>
  172. /// Show Desktop node
  173. /// </summary>
  174. [
  175. Category("Explorer options"),
  176. Description("Show Desktop node")
  177. ]
  178. public bool ShowDesktop
  179. {
  180. get
  181. {
  182. return showDesktop;
  183. }
  184. set
  185. {
  186. showDesktop = value;
  187. refreshTreeView();
  188. }
  189. }
  190. /// <summary>
  191. /// Show MyDocument node
  192. /// </summary>
  193. [
  194. Category("Explorer options"),
  195. Description("Show MyDocument node")
  196. ]
  197. public bool ShowMyDocuments
  198. {
  199. get
  200. {
  201. return showMyDocuments;
  202. }
  203. set
  204. {
  205. showMyDocuments = value;
  206. refreshTreeView();
  207. }
  208. }
  209. /// <summary>
  210. /// Show MyPictures node
  211. /// </summary>
  212. [
  213. Category("Explorer options"),
  214. Description("Show MyPictures node")
  215. ]
  216. public bool ShowMyPictures
  217. {
  218. get
  219. {
  220. return showMyPictures;
  221. }
  222. set
  223. {
  224. showMyPictures = value;
  225. refreshTreeView();
  226. }
  227. }
  228. /// <summary>
  229. /// Show MyFavorites node
  230. /// </summary>
  231. [
  232. Category("Explorer options"),
  233. Description("Show MyFavorites node")
  234. ]
  235. public bool ShowMyFavorites
  236. {
  237. get
  238. {
  239. return showMyFavorites;
  240. }
  241. set
  242. {
  243. showMyFavorites = value;
  244. refreshTreeView();
  245. }
  246. }
  247. /// <summary>
  248. /// Show MyNetwork node
  249. /// </summary>
  250. [
  251. Category("Explorer options"),
  252. Description("Show MyNetwork node")
  253. ]
  254. public bool ShowMyNetwork
  255. {
  256. get
  257. {
  258. return showMyNetwork;
  259. }
  260. set
  261. {
  262. showMyNetwork = value;
  263. refreshTreeView();
  264. }
  265. }
  266. /// <summary>
  267. /// Type of explorer view used to dislpay the files in the fileListView
  268. /// </summary>
  269. [
  270. Category("Explorer options"),
  271. Description("Type of explorer view used to dislpay the files in the fileListView")
  272. ]
  273. public System.Windows.Forms.View View
  274. {
  275. get { return filesListView.View; }
  276. set
  277. {
  278. this.filesListView.View = value;
  279. }
  280. }
  281.  
  282. /// <summary>
  283. /// Type of view (explorer or images) used to dislpay the files in the fileListView
  284. /// </summary>
  285. [
  286. Category("Explorer options"),
  287. Description("Type of view (explorer or images) used to dislpay the files in the fileListView")
  288. ]
  289. public FILES_DISPLAY Display
  290. {
  291. get { return display; }
  292. set
  293. {
  294. if (this.display != value)
  295. {
  296. this.display = value;
  297. editImageTSB.Enabled = false;
  298. switch (display)
  299. {
  300. case FILES_DISPLAY.explorer:
  301. statsControl.Visible = false;
  302. imagesBrowser.Visible = false;
  303. filesListView.Visible = true;
  304. showStatsOptions(false);
  305. break;
  306. case FILES_DISPLAY.images:
  307. imagesBrowser.setThumbsForDirectory(addressTSTB.Text);
  308. statsControl.Visible = false;
  309. imagesBrowser.Visible = true;
  310. filesListView.Visible = false;
  311. showStatsOptions(false);
  312. break;
  313. case FILES_DISPLAY.stats:
  314. statsControl.Visible = true;
  315. statsControl.parse(addressTSTB.Text);
  316. imagesBrowser.Visible = false;
  317. filesListView.Visible = false;
  318. showStatsOptions(true);
  319. break;
  320. }
  321. }
  322. }
  323. }
  324. #endregion
  325.  
  326. #region form events
  327. private void ExplorerUserControl_Load(object sender, EventArgs e)
  328. {
  329. String ttFormat = "Afficher ou masquer l'élément \"{0}\"";
  330. imageIndex_DirectoryNormal = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 3).ToBitmap(), Color.Transparent);
  331. imageIndex_DirectoryExpanded = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 4).ToBitmap(), Color.Transparent);
  332.  
  333. imageIndex_Desktop = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 34).ToBitmap(), Color.Transparent);
  334. showDesktopTSB.Image = directoriesImageList.Images[imageIndex_Desktop];
  335. showDesktopTSB.ToolTipText = String.Format(ttFormat, desktopName);
  336.  
  337. imageIndex_MyDocuments = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 126).ToBitmap(), Color.Transparent);
  338. showMyDocumentsTSB.Image = directoriesImageList.Images[imageIndex_MyDocuments];
  339. showMyDocumentsTSB.ToolTipText = String.Format(ttFormat, myDocumentsName);
  340.  
  341. imageIndex_MyPictures = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 127).ToBitmap(), Color.Transparent);
  342. showMyPicturesTSB.Image = directoriesImageList.Images[imageIndex_MyPictures];
  343. showMyPicturesTSB.ToolTipText = String.Format(ttFormat, myPicturesName);
  344.  
  345. imageIndex_MyFavorites = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 43).ToBitmap(), Color.Transparent);
  346. showMyFavouritesTSB.Image = directoriesImageList.Images[imageIndex_MyFavorites];
  347. showMyFavouritesTSB.ToolTipText = String.Format(ttFormat, myFavoriteName);
  348.  
  349. imageIndex_MyNetwork = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 17).ToBitmap(), Color.Transparent);
  350. showNetworksTSB.Image = directoriesImageList.Images[imageIndex_MyNetwork];
  351. showNetworksTSB.ToolTipText = String.Format(ttFormat, myNetworkName);
  352.  
  353. imageIndex_MyComuter = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 15).ToBitmap(), Color.Transparent);
  354. imageIndex_HardDrive = directoriesImageList.Images.Add(IconExtractor.ExtractIcon(shell32Path, 8).ToBitmap(), Color.Transparent);
  355.  
  356. filesListView.LargeImageList = largeIconList.ImageList;
  357. largeIconList.ImageList.ImageSize = new Size(32, 32);
  358. largeIconList.ImageList.ColorDepth = ColorDepth.Depth32Bit;
  359.  
  360. filesListView.SmallImageList = smallIconList.ImageList;
  361. filesListView.StateImageList = smallIconList.ImageList;
  362. smallIconList.ImageList.ImageSize = new Size(16, 16);
  363. smallIconList.ImageList.ColorDepth = ColorDepth.Depth32Bit;
  364.  
  365. refreshTreeView();
  366. }
  367. #endregion
  368.  
  369. #region treeView
  370.  
  371. #region drives
  372. private void addDriveNode(String driveName, DirectoryTreeNode node)
  373. {
  374. //DriveInfo di = new DriveInfo(driveName);
  375. Drive.DriveInfoHelper dih = new Drive.DriveInfoHelper(driveName);
  376. DirectoryTreeNode n = new DirectoryTreeNode(dih);
  377.  
  378. //DirectoryTreeNode n = new DirectoryTreeNode(new DirectoryInfo(path));
  379. n.ImageIndex = directoriesImageList.Images.Add(dih.Icon, Color.Transparent); ;
  380. n.SelectedImageIndex = n.ImageIndex;
  381. n.Nodes.Add(new DirectoryTreeNode());
  382. node.Nodes.Add(n);
  383. }
  384.  
  385. #endregion
  386.  
  387. private void refreshTreeView()
  388. {
  389. directoriesTreeView.BeginUpdate();
  390. directoriesTreeView.Nodes.Clear();
  391.  
  392. if (showDesktop)
  393. {
  394. DirectoryTreeNode desktopNode = new DirectoryTreeNode(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)));//new TreeNode("Bureau", 0, 0);
  395. desktopNode.ImageIndex = imageIndex_Desktop;
  396. desktopNode.SelectedImageIndex = imageIndex_Desktop;
  397. desktopNode.Nodes.Add(new DirectoryTreeNode());
  398. directoriesTreeView.Nodes.Add(desktopNode);
  399. }
  400.  
  401. DirectoryTreeNode myComputerNode = new DirectoryTreeNode();
  402. myComputerNode.Text = myComputerName;
  403. myComputerNode.ImageIndex = imageIndex_MyComuter;
  404. myComputerNode.SelectedImageIndex = imageIndex_MyComuter;
  405. myComputerNode.Nodes.Add(new DirectoryTreeNode());
  406. //myComputerNode.Expand();
  407. directoriesTreeView.Nodes.Add(myComputerNode);
  408.  
  409. if (showMyDocuments)
  410. {
  411. DirectoryTreeNode myDocsNode = new DirectoryTreeNode(
  412. new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)),
  413. imageIndex_MyDocuments
  414. );
  415. myDocsNode.Text = myDocumentsName;
  416. myDocsNode.Nodes.Add(new DirectoryTreeNode());
  417. directoriesTreeView.Nodes.Add(myDocsNode);
  418. }
  419. if (showMyPictures)
  420. {
  421. DirectoryTreeNode myPicsNode = new DirectoryTreeNode(
  422. new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)),
  423. imageIndex_MyPictures
  424. );
  425. //myPicsNode.Text = myPicturesName;
  426. myPicsNode.Nodes.Add(new DirectoryTreeNode());
  427. directoriesTreeView.Nodes.Add(myPicsNode);
  428. }
  429. if (showMyFavorites)
  430. {
  431. DirectoryTreeNode myFavNode = new DirectoryTreeNode(
  432. new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Favorites)),
  433. imageIndex_MyFavorites
  434. );
  435. //myFavNode.Text = myFavoriteName;
  436. myFavNode.Nodes.Add(new DirectoryTreeNode());
  437. directoriesTreeView.Nodes.Add(myFavNode);
  438. }
  439. /*if (showMyNetwork)
  440.   {
  441.   DirectoryTreeNode myNetNode = new DirectoryTreeNode(
  442.   new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.n)),
  443.   imageIndex_MyNetwork
  444.   );
  445.   //myNetNode.Text = myNetworkName;
  446.   myNetNode.Nodes.Add(new DirectoryTreeNode());
  447.   directoriesTreeView.Nodes.Add(myNetNode);
  448.   }*/
  449. directoriesTreeView.EndUpdate();
  450. }
  451.  
  452. private void directoriesTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
  453. {
  454. Cursor.Current = Cursors.WaitCursor;
  455. DirectoryTreeNode node = e.Node as DirectoryTreeNode;
  456.  
  457. if (node == null) return;
  458.  
  459. if ((e.Action & TreeViewAction.Expand) == TreeViewAction.Expand)
  460. {
  461.  
  462. node.Nodes.Clear();
  463.  
  464. DirectoryTreeNode childnode;
  465. if (node.DirectoryInfo != null)
  466. {
  467. try
  468. {
  469. foreach (DirectoryInfo directory in node.DirectoryInfo.GetDirectories())
  470. {
  471. childnode = new DirectoryTreeNode(directory);
  472.  
  473. childnode.ImageIndex = imageIndex_DirectoryNormal;
  474. childnode.SelectedImageIndex = imageIndex_DirectoryNormal;
  475.  
  476. childnode.Nodes.Add(new DirectoryTreeNode());
  477.  
  478. node.Nodes.Add(childnode);
  479. }
  480. }
  481. catch (Exception ex)
  482. {
  483. MessageBox.Show(
  484. this,
  485. String.Format(
  486. "Impossible de lire sur {0} \n\nType d'erreur : {1}",
  487. node.DirectoryInfo.FullName,
  488. ex.Message
  489. ),
  490. "Erreur de lecture",
  491. MessageBoxButtons.OK,
  492. MessageBoxIcon.Warning
  493. );
  494. }
  495. }
  496. else if(node.Text.Equals(myComputerName))
  497. {
  498. foreach (String name in Environment.GetLogicalDrives())
  499. {
  500. addDriveNode(name, node);
  501. }
  502. }
  503. }
  504. }
  505.  
  506. private void directoriesTreeView_AfterExpand(object sender, TreeViewEventArgs e)
  507. {
  508. Cursor.Current = DefaultCursor;
  509. if (e.Node.ImageIndex == imageIndex_DirectoryNormal)
  510. {
  511. e.Node.ImageIndex = imageIndex_DirectoryExpanded;
  512. e.Node.SelectedImageIndex = imageIndex_DirectoryExpanded;
  513. }
  514. }
  515.  
  516. private void directoriesTreeView_AfterCollapse(object sender, TreeViewEventArgs e)
  517. {
  518. if (e.Node.ImageIndex == imageIndex_DirectoryExpanded)
  519. {
  520. e.Node.ImageIndex = imageIndex_DirectoryNormal;
  521. e.Node.SelectedImageIndex = imageIndex_DirectoryNormal;
  522. }
  523. }
  524.  
  525. private void directoriesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
  526. {
  527. Cursor.Current = Cursors.WaitCursor;
  528. DirectoryTreeNode node = e.Node as DirectoryTreeNode;
  529. if (node == null) return;
  530. if (node.DirectoryInfo != null)
  531. {
  532. addressTSTB.Text = node.DirectoryInfo.FullName;
  533. }
  534. else
  535. {
  536. addressTSTB.Text = node.Text;
  537. }
  538. if (statsControl != null)
  539. {
  540. if (statsControl.Visible)
  541. {
  542. statsControl.parse(addressTSTB.Text);
  543. }
  544. else
  545. {
  546. statsControl.setStartPath(addressTSTB.Text);
  547. }
  548. }
  549. switch (display)
  550. {
  551. case FILES_DISPLAY.explorer:
  552. filesListView.BeginUpdate();
  553. if (node.DirectoryInfo != null)
  554. {
  555. setFileListViewItems(node.DirectoryInfo);
  556. }
  557. else
  558. {
  559. filesListView.Items.Clear();
  560. }
  561. filesListView.EndUpdate();
  562. break;
  563. case FILES_DISPLAY.images:
  564.  
  565. imagesBrowser.setThumbsForDirectory(addressTSTB.Text);
  566. break;
  567. }
  568. Cursor.Current = DefaultCursor;
  569. }
  570.  
  571.  
  572. #endregion
  573.  
  574. #region show items tsb
  575. private void showDesktopTSB_Click(object sender, EventArgs e)
  576. {
  577. showDesktopTSB.Checked = !showDesktopTSB.Checked;
  578. ShowDesktop = showDesktopTSB.Checked;
  579. }
  580.  
  581. private void showMyDocumentsTSB_Click(object sender, EventArgs e)
  582. {
  583. showMyDocumentsTSB.Checked = !showMyDocumentsTSB.Checked;
  584. ShowMyDocuments = showMyDocumentsTSB.Checked;
  585. }
  586.  
  587. private void showMyPicturesTSB_Click(object sender, EventArgs e)
  588. {
  589. showMyPicturesTSB.Checked = !showMyPicturesTSB.Checked;
  590. ShowMyPictures = showMyPicturesTSB.Checked;
  591. }
  592.  
  593. private void showMyFavouritesTSB_Click(object sender, EventArgs e)
  594. {
  595. showMyFavouritesTSB.Checked = !showMyFavouritesTSB.Checked;
  596. ShowMyFavorites = showMyFavouritesTSB.Checked;
  597. }
  598.  
  599. private void showNetworksTSB_Click(object sender, EventArgs e)
  600. {
  601. showNetworksTSB.Checked = !showNetworksTSB.Checked;
  602. showMyNetwork = showNetworksTSB.Checked;
  603. }
  604. #endregion
  605.  
  606. #region private methods
  607. private void toggleEditImageTSB_Click(object sender, EventArgs e)
  608. {
  609. editImageTSB.Checked = !editImageTSB.Checked;
  610. imagesBrowser.ImageFilterModeOn = editImageTSB.Checked;
  611. }
  612.  
  613. #endregion
  614.  
  615. private void imagesBrowser_FileSelected(object sender, string filePath)
  616. {
  617. editImageTSB.Enabled = !String.Empty.Equals(filePath);
  618. if (FileSelected != null)
  619. FileSelected(
  620. sender,
  621. filePath
  622. );
  623. }
  624.  
  625. private void collapseTreeTSB_Click(object sender, EventArgs e)
  626. {
  627. explorerSC.Panel1Collapsed = !explorerSC.Panel1Collapsed;
  628. }
  629.  
  630. #region listview features
  631.  
  632. private void setFileListViewItems(DirectoryInfo di)
  633. {
  634. filesListView.Items.Clear();
  635.  
  636. try
  637. {
  638. ListViewItem item;
  639. foreach (DirectoryInfo di2 in di.GetDirectories())
  640. {
  641. item = filesListView.Items.Add(
  642. new ListViewItem(new string[]{
  643. di2.Name,
  644. "",//length
  645. "Répertoire",//ext,
  646. di2.LastAccessTime.ToLongDateString(),
  647. ""
  648. })
  649. );
  650. item.ImageIndex = largeIconList[di2.FullName];
  651. smallIconList.addIcon(di2.FullName);
  652. item.ToolTipText = "Répertoire :\n"+FileTagHelper.getProperty(di2.FullName,FILE_TAG.GeneralTipInformation);
  653. item.Tag = di2.FullName;
  654. }
  655. foreach (FileInfo file in di.GetFiles())
  656. {
  657. item = filesListView.Items.Add(
  658. new ListViewItem(new string[]{
  659. file.Name,
  660. Units.getLengthString(file.Length),
  661. file.Extension,
  662. file.LastAccessTime.ToLongDateString(),
  663. file.Length.ToString()
  664. })
  665. );
  666. item.ImageIndex = largeIconList[file.FullName];
  667. smallIconList.addIcon(file.FullName);
  668. item.ToolTipText = "Fichier :\n" + FileTagHelper.getProperty(file.FullName, FILE_TAG.GeneralTipInformation);
  669. item.Tag = file.FullName;
  670. }
  671. if (groupIcons)
  672. {
  673. //if (groupTables == null)
  674. //{
  675. // Create the groupsTable array and populate it with one
  676. // hash table for each column.
  677. groupTables = new Hashtable[filesListView.Columns.Count];
  678. for (int column = 0; column < filesListView.Columns.Count; column++)
  679. {
  680. // Create a hash table containing all the groups
  681. // needed for a single column.
  682. groupTables[column] = CreateGroupsTable(column);
  683. }
  684. //}
  685. // Start with the groups created for the ParameterTitle column.
  686. SetGroups(0);
  687. }
  688. }
  689. catch (UnauthorizedAccessException)
  690. {
  691. MessageBox.Show(this, "Accès refusé", di.FullName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  692. }
  693. catch (Exception) { }
  694. }
  695.  
  696. #region sort files
  697.  
  698. // Groups the items using the groups created for the clicked
  699. // column.
  700. private void filesListView_ColumnClick(object sender, ColumnClickEventArgs e)
  701. {
  702. sortFilesListView(e.Column);
  703. }
  704.  
  705. private void sortFilesListView(int columnIndex)
  706. {
  707. // Set the sort order to ascending when changing
  708. // column groups; otherwise, reverse the sort order.
  709. if (filesListView.Sorting == SortOrder.Descending ||
  710. (groupIcons && (columnIndex != groupColumn)))
  711. {
  712. filesListView.Sorting = SortOrder.Ascending;
  713. }
  714. else
  715. {
  716. filesListView.Sorting = SortOrder.Descending;
  717. }
  718. groupColumn = columnIndex;
  719.  
  720. // Set the groups to those created for the clicked column.
  721. if (groupIcons)
  722. {
  723. SetGroups(columnIndex);
  724. }
  725. }
  726.  
  727.  
  728. private void iconsOrderByNameTsMi_Click(object sender, EventArgs e)
  729. {
  730. sortFilesListView(filesListView.Columns.IndexOf(fileNameColumnHeader));
  731. }
  732.  
  733. private void iconsOrderBySizeTsMi_Click(object sender, EventArgs e)
  734. {
  735. sortFilesListView(filesListView.Columns.IndexOf(fileLengthColumnHeader));
  736. }
  737.  
  738. private void iconsOrderByTypeTsMi_Click(object sender, EventArgs e)
  739. {
  740. sortFilesListView(filesListView.Columns.IndexOf(fileTypeColumnHeader));
  741. }
  742.  
  743. private void iconsOrderByModDateTsMi_Click(object sender, EventArgs e)
  744. {
  745. sortFilesListView(filesListView.Columns.IndexOf(fileDateColumnHeader));
  746. }
  747. #endregion
  748.  
  749. #region group files
  750.  
  751. private void toogleIconsGroups()
  752. {
  753. // Determine whether Windows XP or a later operating system is present.
  754. if (OSFeature.Feature.IsPresent(OSFeature.Themes))
  755. {
  756. groupIcons = !groupIcons;
  757. iconsDisplayGroupsTsMi.Checked = groupIcons;
  758. try
  759. {
  760. setFileListViewItems(new DirectoryInfo(addressTSTB.Text));
  761. }
  762. catch (Exception)
  763. { }
  764. }
  765. else groupIcons = false;
  766. }
  767.  
  768. // Sets filesListView to the groups created for the specified column.
  769. private void SetGroups(int column)
  770. {
  771. // Remove the current groups.
  772. filesListView.Groups.Clear();
  773.  
  774. // Retrieve the hash table corresponding to the column.
  775. Hashtable groups = (Hashtable)groupTables[column];
  776.  
  777. // Copy the groups for the column to an array.
  778. ListViewGroup[] groupsArray = new ListViewGroup[groups.Count];
  779. groups.Values.CopyTo(groupsArray, 0);
  780.  
  781. // Sort the groups and add them to filesListView.
  782. Array.Sort(groupsArray, new ListViewGroupSorter(filesListView.Sorting));
  783. filesListView.Groups.AddRange(groupsArray);
  784.  
  785. // Iterate through the items in filesListView, assigning each
  786. // one to the appropriate group.
  787. foreach (ListViewItem item in filesListView.Items)
  788. {
  789. // Retrieve the subitem text corresponding to the column.
  790. string subItemText = item.SubItems[column].Text;
  791.  
  792. // For the Name column, use only the first letter.
  793. subItemText = getSubItemText(column, subItemText);
  794.  
  795. // Assign the item to the matching group.
  796. item.Group = (ListViewGroup)groups[subItemText];
  797. }
  798. }
  799.  
  800.  
  801. // Creates a Hashtable object with one entry for each unique
  802. // subitem value (or initial letter for the parent item)
  803. // in the specified column.
  804. private Hashtable CreateGroupsTable(int column)
  805. {
  806. // Create a Hashtable object.
  807. Hashtable groups = new Hashtable();
  808.  
  809. // Iterate through the items in filesListView.
  810. foreach (ListViewItem item in filesListView.Items)
  811. {
  812. // Retrieve the text value for the column.
  813. string subItemText = item.SubItems[column].Text;
  814.  
  815. // Use the initial letter instead if it is the first column.
  816. subItemText = getSubItemText(column, subItemText);
  817.  
  818. // If the groups table does not already contain a group
  819. // for the subItemText value, add a new group using the
  820. // subItemText value for the group header and Hashtable key.
  821. if (!groups.Contains(subItemText))
  822. {
  823. groups.Add(
  824. subItemText,
  825. new ListViewGroup(
  826. subItemText,
  827. HorizontalAlignment.Left
  828. )
  829. );
  830. }
  831. }
  832.  
  833. // Return the Hashtable object.
  834. return groups;
  835. }
  836.  
  837. private void iconsDisplayGroupsTsMi_Click(object sender, EventArgs e)
  838. {
  839. toogleIconsGroups();
  840. }
  841.  
  842. #endregion
  843.  
  844.  
  845. private void filesListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  846. {
  847. if (e.Item.Selected)
  848. {
  849. filesListView.ContextMenuStrip = fileSelectedCMS;
  850. fileNameTsMi.Text = e.Item.Text;
  851. fileNameTsMi.ToolTipText = e.Item.Tag.ToString();
  852. /*
  853.   ListView lw = (ListView)sender;
  854.   Point pt = e.Item.Position;
  855.   string[] strFiles = new string[lw.SelectedItems.Count];
  856.   for (int i = 0; i < strFiles.Length; i++)
  857.   {
  858.   strFiles[i] = lw.SelectedItems[i].Tag.ToString();
  859.   }
  860.  
  861.   be.gaudry.model.win32.SysCntxtMenu.ShowContextMenu(this.Handle, strFiles, pt.X, pt.Y, true);
  862.   */
  863. }
  864. else
  865. {
  866. filesListView.ContextMenuStrip = filesListViewCMS;
  867. }
  868. if (FileSelected != null && e.Item.Selected)
  869. {
  870. editImageTSB.Enabled = ImageHelper.isImg(e.Item.Tag.ToString());
  871. FileSelected(
  872. filesListView,
  873. //filesListView.FocusedItem.ToolTipText
  874. e.Item.Tag.ToString()
  875. );
  876. }
  877. }
  878.  
  879. private void filesListView_DoubleClick(object sender, EventArgs e)
  880. {
  881. if (filesListView.FocusedItem.SubItems[fileTypeColumnHeader.Index].Text.Equals("Répertoire"))
  882. {
  883. /*MessageBox.Show(
  884.   this,
  885.   "Les actions sur les répertoires ne sont pas encore implémentées...",
  886.   "Aucune action associée",
  887.   MessageBoxButtons.OK,
  888.   MessageBoxIcon.Information
  889.   );*/
  890. FileHelper.openFileProperties(filesListView.FocusedItem.Tag.ToString());
  891. }
  892. else
  893. {
  894. FileHelper.open(
  895. filesListView.FocusedItem.Tag.ToString(),
  896. "BrolExplorer"
  897. );
  898. }
  899. }
  900.  
  901. private String getSubItemText(int columnId, String subItemText)
  902. {
  903. switch (columnId)
  904. {
  905. case 0 :
  906. return subItemText.Substring(0, 1).ToUpper();
  907. case 1:
  908. /*long fileLength = long.Parse(subItemText);
  909.   long reduc = 1048576;//1024*1024
  910.   long result;
  911.   Math.DivRem(fileLength, reduc, out result);
  912.   subItemText = BrolFile.getFileSize(result > 0 ? result * reduc : fileLength);
  913.   */
  914. return subItemText;
  915. case 2:
  916. //todo : get mime type
  917. return subItemText;
  918. default:
  919. return subItemText;
  920. }
  921. }
  922.  
  923. #endregion
  924.  
  925. #region listview comparator
  926. // Sorts ListViewGroup objects by header value.
  927. private class ListViewGroupSorter : IComparer
  928. {
  929. private SortOrder order;
  930.  
  931. // Stores the sort order.
  932. public ListViewGroupSorter(SortOrder theOrder)
  933. {
  934. order = theOrder;
  935. }
  936.  
  937. // Compares the groups by header value, using the saved sort
  938. // order to return the correct value.
  939. public int Compare(object x, object y)
  940. {
  941. int result = String.Compare(
  942. ((ListViewGroup)x).Header,
  943. ((ListViewGroup)y).Header
  944. );
  945. if (order == SortOrder.Ascending)
  946. {
  947. return result;
  948. }
  949. else
  950. {
  951. return -result;
  952. }
  953. }
  954. }
  955. #endregion
  956.  
  957. #region display menu
  958. private void stripTsMi_Click(object sender, EventArgs e)
  959. {
  960. Display = FILES_DISPLAY.images;
  961. }
  962.  
  963. private void smallIconsTsMi_Click(object sender, EventArgs e)
  964. {
  965. Display = FILES_DISPLAY.explorer;
  966. View = System.Windows.Forms.View.SmallIcon;
  967. }
  968.  
  969. private void tileTsMi_Click(object sender, EventArgs e)
  970. {
  971. Display = FILES_DISPLAY.explorer;
  972. View = System.Windows.Forms.View.Tile;
  973. }
  974.  
  975. private void largeIconsTsMi_Click(object sender, EventArgs e)
  976. {
  977. Display = FILES_DISPLAY.explorer;
  978. View = System.Windows.Forms.View.LargeIcon;
  979. }
  980.  
  981. private void listTsMi_Click(object sender, EventArgs e)
  982. {
  983. Display = FILES_DISPLAY.explorer;
  984. View = System.Windows.Forms.View.List;
  985. }
  986.  
  987. private void detailsTsMi_Click(object sender, EventArgs e)
  988. {
  989. Display = FILES_DISPLAY.explorer;
  990. View = System.Windows.Forms.View.Details;
  991. }
  992.  
  993. private void statsTsMi_Click(object sender, EventArgs e)
  994. {
  995. Display = FILES_DISPLAY.stats;
  996. }
  997. private void showStatsOptions(bool show)
  998. {
  999. foreach (ToolStripMenuItem tsMi in statsCTsMi.DropDownItems)
  1000. {
  1001. tsMi.Visible = show;
  1002. }
  1003. }
  1004. #endregion
  1005.  
  1006. private void explorerTS_Resize(object sender, EventArgs e)
  1007. {
  1008. int w = explorerTS.Width - (
  1009. addressTSL.Width + addressTSL.Margin.Horizontal +
  1010. goTSB.Width + goTSB.Margin.Horizontal +
  1011. explorerTS.Padding.Horizontal + explorerTS.Margin.Horizontal
  1012. +30//to be sure ;-)
  1013. );
  1014. addressTSTB.Width = (w>100)?w:100;
  1015. }
  1016.  
  1017. private void openSearchPanelTSB_Click(object sender, EventArgs e)
  1018. {
  1019. ((ExplorerForm)this.ParentForm).openMediaBrowser();
  1020. }
  1021.  
  1022. /// <summary>
  1023. /// Invoke delegate on path modification
  1024. /// Reinit the progress max value
  1025. /// </summary>
  1026. /// <param name="sender"></param>
  1027. /// <param name="e"></param>
  1028. private void addressTSTB_TextChanged(object sender, EventArgs e)
  1029. {
  1030. if (DirectorySelected != null)
  1031. {
  1032. DirectorySelected(
  1033. this,
  1034. addressTSTB.Text
  1035. );
  1036. }
  1037. }
  1038.  
  1039. #region properties
  1040. private void openMetadataCTsMi_Click(object sender, EventArgs e)
  1041. {
  1042. FilePropertiesForm form = new FilePropertiesForm();
  1043. form.setPath(fileNameTsMi.ToolTipText);
  1044. form.ShowDialog(this.ParentForm);
  1045. }
  1046.  
  1047. private void openPropertySumaryFileCTsMi_Click(object sender, EventArgs e)
  1048. {
  1049. FileTagHelper.showProperties(fileNameTsMi.ToolTipText, this.ParentForm);
  1050. }
  1051.  
  1052. private void openPropertiesMessageTsMi_Click(object sender, EventArgs e)
  1053. {
  1054. FileHelper.openFileProperties(fileNameTsMi.ToolTipText);
  1055. }
  1056. #endregion
  1057.  
  1058. private void openFileCTsMi_Click(object sender, EventArgs e)
  1059. {
  1060. FileHelper.open(fileNameTsMi.ToolTipText);
  1061. }
  1062.  
  1063. private void openWithCTsMi_Click(object sender, EventArgs e)
  1064. {
  1065. FileHelper.openWith(fileNameTsMi.ToolTipText);
  1066. }
  1067.  
  1068. }
  1069. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/brolexplorer/view/controls/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1730416408 01/11/2024 00:13:28
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/brolexplorer/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .resx|.resxThumbUserControl.resx5.68 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csSearchMediaUserControl.Designer.cs52.01 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csImagesBrowserUserControl.cs9.69 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csExplorerUserControl.cs38.67 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csExplorerUserControl.Designer.cs44.73 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxExplorerUserControl.resx15.83 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxImagesBrowserUserControl.resx6.06 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csImagesBrowserUserControl.Designer.cs10.53 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csThumbUserControl.Designer.cs3.29 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxSearchMediaUserControl.resx7.72 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csSearchMediaUserControl.cs25.76 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csThumbUserControl.cs4.7 Ko31/10/2018 18:32:50-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-brolexplorer-source-rf-view/controls//ExplorerUserControl.cs.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.