|
| 1 | +using Jam.Explorer.Properties; |
| 2 | +using Jam.Shell; |
| 3 | +using Jam.Shell.Controls; |
1 | 4 | using System; |
2 | 5 | using System.Collections.Generic; |
3 | 6 | using System.ComponentModel; |
4 | 7 | using System.Data; |
5 | 8 | using System.Drawing; |
6 | | -using System.Text; |
7 | | -using System.Windows.Forms; |
8 | | -using Jam.Shell; |
9 | | -using Jam.Shell.Controls; |
10 | | -using Jam.Explorer.Properties; |
11 | 9 | using System.Globalization; |
12 | 10 | using System.IO; |
| 11 | +using System.Linq; |
| 12 | +using System.Text; |
| 13 | +using System.Windows.Forms; |
13 | 14 |
|
14 | 15 | namespace Jam.Explorer |
15 | 16 | { |
16 | | - |
| 17 | + |
17 | 18 | public partial class JamExplorerMainForm : Form |
18 | 19 | { |
19 | 20 | public JamExplorerMainForm() |
20 | 21 | { |
21 | 22 | InitializeComponent(); |
22 | 23 | setPreviewVisibility(false); |
| 24 | + |
| 25 | + detailsPane1.CustomizeProperties += DetailsPane_DemonstrateCustomization; |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + #region --- DetailsPane Customization Examples --- |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// This is the central event handler to demonstrate the various ways |
| 33 | + /// the DetailsPane can be customized. |
| 34 | + /// It acts as a dispatcher, calling specific methods for different file types |
| 35 | + /// to keep the examples clear and separated. |
| 36 | + /// </summary> |
| 37 | + private void DetailsPane_DemonstrateCustomization(object sender, CustomizePropertiesEventArgs e) |
| 38 | + { |
| 39 | + var path = e.ItemIdList?.GetDisplayName(ItemIdList.DisplayNameFormat.DisplayPath); |
| 40 | + if (string.IsNullOrEmpty(path)) |
| 41 | + return; |
| 42 | + |
| 43 | + e.ShowPropertiesButton = !ItemIdList.IsNullOrInvalid(e.ItemIdList) && e.ItemIdList.IsFolder; |
| 44 | + |
| 45 | + var ext = Path.GetExtension(path).ToLowerInvariant(); |
| 46 | + |
| 47 | + switch (ext) |
| 48 | + { |
| 49 | + // For image files, we want to completely override the default view. |
| 50 | + case ".jpg": |
| 51 | + case ".jpeg": |
| 52 | + case ".png": |
| 53 | + case ".bmp": |
| 54 | + Example1_OverrideAllProperties(e); |
| 55 | + break; |
| 56 | + |
| 57 | + // For audio files, we want to add an extra shell property to the default list. |
| 58 | + case ".mp3": |
| 59 | + case ".wav": |
| 60 | + Example2_ExtendWithShellProperty(e); |
| 61 | + break; |
| 62 | + |
| 63 | + // For text files, we want to add our own calculated data. |
| 64 | + case ".txt": |
| 65 | + Example3_AddCustomCalculatedProperty(e); |
| 66 | + break; |
| 67 | + |
| 68 | + // For all other file types, we do nothing and let the DetailsPane |
| 69 | + // show its default properties. |
| 70 | + default: |
| 71 | + break; |
| 72 | + } |
23 | 73 | } |
24 | 74 |
|
| 75 | + /// <summary> |
| 76 | + /// EXAMPLE 1: How to completely replace the default properties with a custom set. |
| 77 | + /// This is useful for file types where you want a very specific view. |
| 78 | + /// </summary> |
| 79 | + private void Example1_OverrideAllProperties(CustomizePropertiesEventArgs e) |
| 80 | + { |
| 81 | + // 1. Start by clearing the default list provided by the component. |
| 82 | + e.ColumnsToDisplay.Clear(); |
| 83 | + |
| 84 | + // 2. Add the specific SHCOLUMNIDs you want to display. |
| 85 | + e.ColumnsToDisplay.Add(new SHCOLUMNID("System.ItemTypeText")); |
| 86 | + e.ColumnsToDisplay.Add(new SHCOLUMNID("System.Image.Dimensions")); |
| 87 | + e.ColumnsToDisplay.Add(new SHCOLUMNID("System.Size")); |
| 88 | + e.ColumnsToDisplay.Add(new SHCOLUMNID("System.DateModified")); |
| 89 | + e.ColumnsToDisplay.Add(new SHCOLUMNID("System.Photo.DateTaken")); |
| 90 | + |
| 91 | + // 3. You can even mix this with your own custom properties. |
| 92 | + e.CustomProperties.Add("Review Status", "Approved"); |
| 93 | + } |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// EXAMPLE 2: How to add an additional shell property to the default list. |
| 97 | + /// This is the most common use case. |
| 98 | + /// </summary> |
| 99 | + private void Example2_ExtendWithShellProperty(CustomizePropertiesEventArgs e) |
| 100 | + { |
| 101 | + // The e.ColumnsToDisplay list already contains the defaults. |
| 102 | + // Simply add the SHCOLUMNID you need. |
| 103 | + e.ColumnsToDisplay.Add(new SHCOLUMNID("System.Media.Bitrate")); |
| 104 | + } |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// EXAMPLE 3: How to add a completely custom property based on your own logic. |
| 108 | + /// This is perfect for integrating data from a database, a web service, or calculations. |
| 109 | + /// </summary> |
| 110 | + private void Example3_AddCustomCalculatedProperty(CustomizePropertiesEventArgs e) |
| 111 | + { |
| 112 | + try |
| 113 | + { |
| 114 | + var path = e.ItemIdList.GetDisplayName(ItemIdList.DisplayNameFormat.DisplayPath); |
| 115 | + |
| 116 | + // Your custom logic: calculate the word count. |
| 117 | + int wordCount = File.ReadAllText(path).Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length; |
| 118 | + |
| 119 | + // Add the result to the CustomProperties dictionary. |
| 120 | + // The key is the caption, the value is the text to display. |
| 121 | + e.CustomProperties.Add("Word Count (approx.)", wordCount.ToString()); |
| 122 | + } |
| 123 | + catch (Exception ex) |
| 124 | + { |
| 125 | + // It's good practice to handle potential errors gracefully. |
| 126 | + e.CustomProperties.Add("Word Count", $"Error: {ex.Message}"); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + #endregion |
| 131 | + |
| 132 | + |
25 | 133 | private void ToolbarFolderUp_Click(object sender, EventArgs e) |
26 | 134 | { |
27 | 135 | shellListView1.GoUp(); |
28 | | - |
| 136 | + |
29 | 137 | } |
30 | 138 |
|
31 | 139 | private void MenuShowPropertiesItem_Click(object sender, EventArgs e) |
32 | 140 | { |
33 | 141 | if (shellTreeView1.Focused) |
34 | | - shellTreeView1.InvokeCommandOnSelected(ShellCommand.Properties); |
| 142 | + shellTreeView1.InvokeCommandOnSelected(ShellCommand.Properties); |
35 | 143 | else |
36 | | - shellListView1.InvokeCommandOnSelected(ShellCommand.Properties); |
| 144 | + shellListView1.InvokeCommandOnSelected(ShellCommand.Properties); |
37 | 145 | } |
38 | 146 |
|
39 | 147 | private void MenuRenameItem_Click(object sender, EventArgs e) |
@@ -94,7 +202,7 @@ private void enabledToolStripMenuItem_CheckedChanged(object sender, EventArgs e) |
94 | 202 |
|
95 | 203 | private void showSelectedToolStripMenuItem_Click(object sender, EventArgs e) |
96 | 204 | { |
97 | | - PathSelectionList selectionList = |
| 205 | + PathSelectionList selectionList = |
98 | 206 | shellControlConnector1.SelectionList; |
99 | 207 |
|
100 | 208 | string selection = shellControlConnector1.SelectionList.ToString(); |
@@ -279,7 +387,7 @@ private void showFilesToolStripMenuItem_CheckedChanged(object sender, EventArgs |
279 | 387 | private void desktopToolStripMenuItemSpecialFolder_Click(object sender, EventArgs e) |
280 | 388 | { |
281 | 389 |
|
282 | | - ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; |
| 390 | + ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; |
283 | 391 |
|
284 | 392 | if (toolStripMenuItem != null) |
285 | 393 | { |
@@ -322,7 +430,8 @@ private void shellListView1_BeforeShellCommand(object sender, BeforeShellCommand |
322 | 430 | if (dialogShown) |
323 | 431 | return; |
324 | 432 |
|
325 | | - if ((e.Verb == ShellCommand.Default) || (e.Verb == ShellCommand.Open)) { |
| 433 | + if ((e.Verb == ShellCommand.Default) || (e.Verb == ShellCommand.Open)) |
| 434 | + { |
326 | 435 | DialogResult dialogResult = |
327 | 436 | MessageBox.Show(String.Format("Do you want to open the file selected?{0}" + |
328 | 437 | "(This message is shown only once as a demonstration of the 'BeforeShellCommand' event)", |
@@ -464,7 +573,7 @@ private void ToggleBackground(Control control) |
464 | 573 | switch (m_currentBackground) |
465 | 574 | { |
466 | 575 | case 0: |
467 | | - control.BackgroundImage = Resources.background; |
| 576 | + control.BackgroundImage = Jam.Explorer.Properties.Resources.background; |
468 | 577 | break; |
469 | 578 | case 1: |
470 | 579 | case 2: |
@@ -541,8 +650,11 @@ private void JamExplorerMainForm_Load(object sender, EventArgs e) |
541 | 650 |
|
542 | 651 | toolStripSplitButtonView.DefaultItem = toolStripSplitButtonView.DropDownItems[0]; |
543 | 652 |
|
| 653 | + //uncomment the following line to not search for file content when the search box is used, only for filenames. |
| 654 | + //this.addressBar1.SearchEdit.ContentSearch = false; |
| 655 | + |
544 | 656 | //Un-comment for a custom entry in the background context menu. |
545 | | -// shellListView1.BackgroundContextMenu = new MyBackgroundContextMenu(); |
| 657 | + // shellListView1.BackgroundContextMenu = new MyBackgroundContextMenu(); |
546 | 658 | } |
547 | 659 |
|
548 | 660 | private void OpenControlPanelTask(Jam.Shell.Dialogs.ControlPanelItem pControlPanelItem) |
@@ -748,6 +860,11 @@ private void shellListView1_SelectionChanged(object sender, EventArgs e) |
748 | 860 | toolStripStatusLabel1.Text = shellListView1.SelectedItems.Count.ToString() + " item(s) selected."; |
749 | 861 |
|
750 | 862 | } |
| 863 | + |
| 864 | + private void checkBoxDetails_CheckedChanged(object sender, EventArgs e) |
| 865 | + { |
| 866 | + detailsPane1.Visible = checkBoxDetails.Checked; |
| 867 | + } |
751 | 868 | } |
752 | 869 |
|
753 | 870 | class CustomPreviewHandler : IShellPreviewHandler |
|
0 commit comments