Exemplo n.º 1
0
        private void Folder_Expanded(object sender, RoutedEventArgs e)
        {
            var item = (TreeViewItem)sender;

            if (item.Items.Count == 1 && item.Items[0] == _dummyNode)
            {
                item.Items.Clear();
                try
                {
                    foreach (string s in Directory.GetDirectories(item.Tag.ToString()))
                    {
                        TreeViewItem subitem = new TreeViewItem
                        {
                            Header     = s.Substring(s.LastIndexOf("\\") + 1),
                            Tag        = s,
                            FontWeight = FontWeights.Normal
                        };
                        subitem.Items.Add(_dummyNode);
                        subitem.Expanded += Folder_Expanded;
                        item.Items.Add(subitem);
                    }
                }
                catch (Exception ex)
                {
                    OnNavigationException?.Invoke(this, ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        private IEnumerable RenderHome()
        {
            try
            {
                var items = new List <string>();

                var drives = from drive in DriveInfo.GetDrives()
                             where drive.IsReady == true
                             select drive.Name;

                items.AddRange(drives);
                items.AddRange(new string[]
                {
                    Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                    Environment.GetFolderPath(Environment.SpecialFolder.MyMusic),
                    Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                    Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)
                });

                return(items);
            }
            catch (Exception ex)
            {
                OnNavigationException?.Invoke(this, ex.Message);
                return(null);
            }
        }
Exemplo n.º 3
0
        private void RenderFolderView(string driveLetter)
        {
            if (string.IsNullOrEmpty(driveLetter))
            {
                return;
            }

            try
            {
                string[] directories = null;

                if (!IsHiddenVisible)
                {
                    var dir = new DirectoryInfo(Directory.GetDirectoryRoot(driveLetter));



                    var folders = from i in dir.GetDirectories()
                                  where !i.Attributes.HasFlag(FileAttributes.Hidden)
                                  select i.FullName;
                    directories = folders.ToArray();
                }
                else
                {
                    directories = Directory.GetDirectories(driveLetter);
                }
                foreach (string s in directories)
                {
                    var folder = new TreeViewItem
                    {
                        Header     = Path.GetFileName(s),
                        Tag        = s,
                        FontWeight = FontWeights.Normal
                    };
                    folder.Items.Add(_dummyNode);
                    folder.Expanded += Folder_Expanded;
                    Items.Add(folder);
                }
            }
            catch (Exception ex)
            {
                OnNavigationException?.Invoke(this, ex.Message);
            }
        }
Exemplo n.º 4
0
        private void Render()
        {
            try
            {
                string[] parts = SelectedPath?.Split('/', '\\');
                if (parts == null || parts.Length < 0)
                {
                    return;
                }

                for (int i = 0; i < parts.Length; i++)
                {
                    if (string.IsNullOrEmpty(parts[i]))
                    {
                        continue;
                    }

                    Button b = new Button
                    {
                        Style   = Application.Current.TryFindResource(typeof(Button)) as Style,
                        ToolTip = BuildPathString(parts, i),
                        Content = parts[i]
                    };
                    b.Click += B_Click;
                    BreadCumbs.Children.Add(b);

                    TextBlock div = new TextBlock();
                    div.Text = @"\";
                    BreadCumbs.Children.Add(div);
                }
            }
            catch (Exception ex)
            {
                OnNavigationException?.Invoke(this, ex.Message);
            }
        }
Exemplo n.º 5
0
        private void RenderFileList(string path)
        {
            if (path == HomePath)
            {
                ItemsSource = RenderHome();
                return;
            }

            var items = new List <string>();

            try
            {
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                var dir = new DirectoryInfo(path);

                if (IsHiddenVisible)
                {
                    items.AddRange(Directory.GetDirectories(path));
                    if (FilteredExtensions != null && FilteredExtensions.Any())
                    {
                        var files = from i in dir.GetFiles()
                                    where FilteredExtensions.Contains(i.Extension)
                                    select i.FullName;
                        items.AddRange(files);
                    }
                    else
                    {
                        var files = from i in dir.GetFiles()
                                    select i.FullName;
                        items.AddRange(files);
                    }
                }
                else
                {
                    var folders = from i in dir.GetDirectories()
                                  where !i.Attributes.HasFlag(FileAttributes.Hidden)
                                  select i.FullName;
                    items.AddRange(folders);

                    if (FilteredExtensions != null && FilteredExtensions.Any())
                    {
                        var files = from i in dir.GetFiles()
                                    where !i.Attributes.HasFlag(FileAttributes.Hidden) &&
                                    FilteredExtensions.Contains(i.Extension)
                                    select i.FullName;
                        items.AddRange(files);
                    }
                    else
                    {
                        var files = from i in dir.GetFiles()
                                    where !i.Attributes.HasFlag(FileAttributes.Hidden)
                                    select i.FullName;
                        items.AddRange(files);
                    }
                }
                ItemsSource = null;
                ItemsSource = items;
            }
            catch (Exception ex)
            {
                ItemsSource = null;
                OnNavigationException?.Invoke(this, ex.Message);
            }
        }