aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs')
-rw-r--r--Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs115
1 files changed, 115 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs b/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs
new file mode 100644
index 000000000..6f276f184
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Tango.Core.Commands;
+
+namespace Tango.Explorer
+{
+ public class ExplorerControl : Control
+ {
+ private bool _changing_current_path;
+
+ public String CurrentPath
+ {
+ get { return (String)GetValue(CurrentPathProperty); }
+ set { SetValue(CurrentPathProperty, value); }
+ }
+ public static readonly DependencyProperty CurrentPathProperty =
+ DependencyProperty.Register("CurrentPath", typeof(String), typeof(ExplorerControl), new PropertyMetadata(null, (d, e) => (d as ExplorerControl).OnCurrentPathChanged()));
+
+ public ExplorerFolderItem CurrentFolder
+ {
+ get { return (ExplorerFolderItem)GetValue(CurrentFolderProperty); }
+ set { SetValue(CurrentFolderProperty, value); }
+ }
+ public static readonly DependencyProperty CurrentFolderProperty =
+ DependencyProperty.Register("CurrentFolder", typeof(ExplorerFolderItem), typeof(ExplorerControl), new PropertyMetadata(null, (d, e) => (d as ExplorerControl).OnCurrentFolderChanged()));
+
+ public ExplorerItem SelectedItem
+ {
+ get { return (ExplorerItem)GetValue(SelectedItemProperty); }
+ set { SetValue(SelectedItemProperty, value); }
+ }
+ public static readonly DependencyProperty SelectedItemProperty =
+ DependencyProperty.Register("SelectedItem", typeof(ExplorerItem), typeof(ExplorerControl), new PropertyMetadata(null, (d, e) => (d as ExplorerControl).OnSelectedItemChanged()));
+
+ public RelayCommand BackCommand
+ {
+ get { return (RelayCommand)GetValue(BackCommandProperty); }
+ set { SetValue(BackCommandProperty, value); }
+ }
+ public static readonly DependencyProperty BackCommandProperty =
+ DependencyProperty.Register("BackCommand", typeof(RelayCommand), typeof(ExplorerControl), new PropertyMetadata(null));
+
+ static ExplorerControl()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(ExplorerControl), new FrameworkPropertyMetadata(typeof(ExplorerControl)));
+ }
+
+ public ExplorerControl()
+ {
+ BackCommand = new RelayCommand(NavigateBack);
+ }
+
+ private void OnCurrentPathChanged()
+ {
+ if (_changing_current_path) return;
+
+ _changing_current_path = true;
+
+ if (Directory.Exists(CurrentPath))
+ {
+ CurrentFolder = ExplorerFolderItem.LoadFromPath(CurrentPath);
+ }
+
+ _changing_current_path = false;
+ }
+
+ private void OnCurrentFolderChanged()
+ {
+ if (_changing_current_path) return;
+
+ _changing_current_path = true;
+
+ CurrentPath = CurrentFolder.Path;
+
+ _changing_current_path = false;
+ }
+
+ private void OnSelectedItemChanged()
+ {
+ if (SelectedItem != null)
+ {
+ if (SelectedItem is ExplorerFolderItem)
+ {
+ var folder = SelectedItem as ExplorerFolderItem;
+ folder = ExplorerFolderItem.LoadFromPath(folder.Path);
+ CurrentFolder = folder;
+ SelectedItem = null;
+ }
+ }
+ }
+
+ private void NavigateBack()
+ {
+ var parentPath = CurrentFolder.GetParentPath();
+
+ if (parentPath != null)
+ {
+ CurrentFolder = ExplorerFolderItem.LoadFromPath(parentPath);
+ }
+ }
+ }
+}