diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-21 14:30:01 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-21 14:30:01 +0200 |
| commit | 36dcf50eec20835ab1955932e89f9c6ffc68acde (patch) | |
| tree | 3ca1331b626f04c8f19af24b65b7459b5f0660cb /Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs | |
| parent | 5f321b419501b2c836e8b03400fff2934be5f135 (diff) | |
| download | Tango-36dcf50eec20835ab1955932e89f9c6ffc68acde.tar.gz Tango-36dcf50eec20835ab1955932e89f9c6ffc68acde.zip | |
Working on Touch FileExplorer !
Diffstat (limited to 'Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Explorer/ExplorerControl.cs | 115 |
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); + } + } + } +} |
