|
@@ -77,6 +77,8 @@ namespace UICatalog.Scenarios {
|
|
|
};
|
|
|
|
|
|
treeViewFiles.ObjectActivated += TreeViewFiles_ObjectActivated;
|
|
|
+ treeViewFiles.MouseClick += TreeViewFiles_MouseClick;
|
|
|
+ treeViewFiles.KeyPress += TreeViewFiles_KeyPress;
|
|
|
|
|
|
SetupFileTree ();
|
|
|
|
|
@@ -88,6 +90,80 @@ namespace UICatalog.Scenarios {
|
|
|
red = Application.Driver.MakeAttribute (Color.Red, Color.Blue);
|
|
|
}
|
|
|
|
|
|
+ private void TreeViewFiles_KeyPress (View.KeyEventEventArgs obj)
|
|
|
+ {
|
|
|
+ if(obj.KeyEvent.Key == (Key.R | Key.CtrlMask)) {
|
|
|
+
|
|
|
+ var selected = treeViewFiles.SelectedObject;
|
|
|
+
|
|
|
+ // nothing is selected
|
|
|
+ if (selected == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var location = treeViewFiles.GetObjectRow (selected);
|
|
|
+
|
|
|
+ //selected object is offscreen or somehow not found
|
|
|
+ if (location == null || location < 0 || location > treeViewFiles.Frame.Height)
|
|
|
+ return;
|
|
|
+
|
|
|
+ ShowContextMenu (new Point (
|
|
|
+ 5 + treeViewFiles.Frame.X,
|
|
|
+ location.Value + treeViewFiles.Frame.Y + 2),
|
|
|
+ selected);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TreeViewFiles_MouseClick (View.MouseEventArgs obj)
|
|
|
+ {
|
|
|
+ // if user right clicks
|
|
|
+ if (obj.MouseEvent.Flags.HasFlag(MouseFlags.Button3Clicked)) {
|
|
|
+
|
|
|
+ var rightClicked = treeViewFiles.GetObjectOnRow ( obj.MouseEvent.Y);
|
|
|
+
|
|
|
+ // nothing was clicked
|
|
|
+ if (rightClicked == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ ShowContextMenu (new Point (
|
|
|
+ obj.MouseEvent.X + treeViewFiles.Frame.X,
|
|
|
+ obj.MouseEvent.Y + treeViewFiles.Frame.Y + 2),
|
|
|
+ rightClicked);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowContextMenu (Point screenPoint, FileSystemInfo forObject)
|
|
|
+ {
|
|
|
+ var menu = new ContextMenu ();
|
|
|
+ menu.Position = screenPoint;
|
|
|
+
|
|
|
+ menu.MenuItems = new MenuBarItem (new [] { new MenuItem ("Properties", null, () => ShowPropertiesOf (forObject)) });
|
|
|
+
|
|
|
+ Application.MainLoop.Invoke(menu.Show);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowPropertiesOf (FileSystemInfo fileSystemInfo)
|
|
|
+ {
|
|
|
+ if (fileSystemInfo is FileInfo f) {
|
|
|
+ System.Text.StringBuilder sb = new System.Text.StringBuilder ();
|
|
|
+ sb.AppendLine ($"Path:{f.DirectoryName}");
|
|
|
+ sb.AppendLine ($"Size:{f.Length:N0} bytes");
|
|
|
+ sb.AppendLine ($"Modified:{ f.LastWriteTime}");
|
|
|
+ sb.AppendLine ($"Created:{ f.CreationTime}");
|
|
|
+
|
|
|
+ MessageBox.Query (f.Name, sb.ToString (), "Close");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fileSystemInfo is DirectoryInfo dir) {
|
|
|
+
|
|
|
+ System.Text.StringBuilder sb = new System.Text.StringBuilder ();
|
|
|
+ sb.AppendLine ($"Path:{dir.Parent?.FullName}");
|
|
|
+ sb.AppendLine ($"Modified:{ dir.LastWriteTime}");
|
|
|
+ sb.AppendLine ($"Created:{ dir.CreationTime}");
|
|
|
+
|
|
|
+ MessageBox.Query (dir.Name, sb.ToString (), "Close");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void SetupScrollBar ()
|
|
|
{
|
|
|
// When using scroll bar leave the last row of the control free (for over-rendering with scroll bar)
|
|
@@ -140,25 +216,7 @@ namespace UICatalog.Scenarios {
|
|
|
|
|
|
private void TreeViewFiles_ObjectActivated (ObjectActivatedEventArgs<FileSystemInfo> obj)
|
|
|
{
|
|
|
- if (obj.ActivatedObject is FileInfo f) {
|
|
|
- System.Text.StringBuilder sb = new System.Text.StringBuilder ();
|
|
|
- sb.AppendLine ($"Path:{f.DirectoryName}");
|
|
|
- sb.AppendLine ($"Size:{f.Length:N0} bytes");
|
|
|
- sb.AppendLine ($"Modified:{ f.LastWriteTime}");
|
|
|
- sb.AppendLine ($"Created:{ f.CreationTime}");
|
|
|
-
|
|
|
- MessageBox.Query (f.Name, sb.ToString (), "Close");
|
|
|
- }
|
|
|
-
|
|
|
- if (obj.ActivatedObject is DirectoryInfo dir) {
|
|
|
-
|
|
|
- System.Text.StringBuilder sb = new System.Text.StringBuilder ();
|
|
|
- sb.AppendLine ($"Path:{dir.Parent?.FullName}");
|
|
|
- sb.AppendLine ($"Modified:{ dir.LastWriteTime}");
|
|
|
- sb.AppendLine ($"Created:{ dir.CreationTime}");
|
|
|
-
|
|
|
- MessageBox.Query (dir.Name, sb.ToString (), "Close");
|
|
|
- }
|
|
|
+ ShowPropertiesOf (obj.ActivatedObject);
|
|
|
}
|
|
|
|
|
|
private void ShowLines ()
|