示例#1
0
        private void FolderCollapsed(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)sender;

            AssetTag tag = (AssetTag)item.Tag;

            if (tag.Type != AssetType.DRIVE)
            {
                AssetType type;

                if (item.IsExpanded)
                {
                    type = AssetType.FOLDER_EXPANDED;
                }
                else
                {
                    type = AssetType.FOLDER;
                }

                //update element accordingly
                //Already searched recursively, just set tag
                item.Tag = new AssetTag(type, ((AssetTag)item.Tag).Path);
                ((UIElement)item).Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render);
            }
        }
示例#2
0
        private void SubItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)sender;
            AssetTag     tag  = (AssetTag)item.Tag;

            if (System.IO.File.Exists(tag.Path))
            {
                Process fileopener = new Process();
                fileopener.StartInfo.FileName  = "explorer";
                fileopener.StartInfo.Arguments = "\"" + tag.Path + "\"";
                fileopener.Start();
            }
        }
示例#3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            AssetTag tag = (AssetTag)value;

            switch (tag.Type)
            {
            case AssetType.DRIVE:
                return("pack://application:,,,/res/images/icons/hard_drive.png");

            case AssetType.FOLDER:
                return("pack://application:,,,/res/images/icons/folder.png");

            case AssetType.FOLDER_EXPANDED:
                return("pack://application:,,,/res/images/icons/folder_open.png");

            case AssetType.FILE:
                return("pack://application:,,,/res/images/icons/file.png");
            }

            //default
            return("pack://application:,,,/res/images/icons/folder.png");
        }
示例#4
0
        private void FolderExpanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)sender;

            AssetTag tag = (AssetTag)item.Tag;


            if (tag.Type != AssetType.DRIVE)
            {
                AssetType type;

                if (item.IsExpanded)
                {
                    type = AssetType.FOLDER_EXPANDED;
                }
                else
                {
                    type = AssetType.FOLDER;
                }

                //update element accordingly
                //Already searched recursively, just set tag
                item.Tag = new AssetTag(type, ((AssetTag)item.Tag).Path);
                ((UIElement)item).Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render);
            }

            if (item.Items.Count == 1 && item.Items[0] == null)
            {
                item.Items.Clear();

                try
                {
                    foreach (string s in System.IO.Directory.GetDirectories(tag.Path))
                    {
                        //Folder (sub-directories)
                        TreeViewItem subItem = new TreeViewItem();
                        subItem.Header = s.Substring(s.LastIndexOf("\\") + 1);
                        subItem.Tag    = new AssetTag(AssetType.FOLDER, s);
                        subItem.Items.Add(null);
                        subItem.Expanded  += new RoutedEventHandler(FolderExpanded);
                        subItem.Collapsed += new RoutedEventHandler(FolderCollapsed);
                        item.Items.Add(subItem);
                    }


                    foreach (string s in System.IO.Directory.GetFiles(tag.Path))
                    {
                        //Files cannot be nested
                        TreeViewItem subItem = new TreeViewItem();
                        subItem.Header = s.Substring(s.LastIndexOf("\\") + 1);
                        subItem.Tag    = new AssetTag(AssetType.FILE, s);
                        item.Items.Add(subItem);

                        //Add handler for opening files
                        subItem.MouseDoubleClick += SubItem_MouseDoubleClick;
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }