예제 #1
0
        public DirectoryItem(string name, DirectoryItem parent, ItemType type)
        {
            Parent = parent;
            Name   = name;
            Type   = type;
            FileInfo fileInfo = new FileInfo(GetFullPath());

            DateCreated  = fileInfo.CreationTime;
            DateModified = fileInfo.LastWriteTime;
            switch (Type)
            {
            case ItemType.Directory:
                Children = new ObservableCollection <DirectoryItem>();
                if (name != LOADING_STR)
                {
                    Children.Add(new DirectoryItem(LOADING_STR, null, ItemType.Directory));
                }

                Size = string.Empty;

                Bitmap bitmapIcon = new Bitmap("..\\..\\Img\\folder.png");
                ItemIcon = FileUtil.ToImageSource(bitmapIcon);
                break;

            case ItemType.File:
            default:
                Size = FileUtil.StringifyShort(fileInfo.Length);

                Icon icon = Icon.ExtractAssociatedIcon(GetFullPath());
                ItemIcon = FileUtil.ToImageSource(icon);
                break;
            }
        }
예제 #2
0
        public DirectoryItem SearchRelativePath(string path)
        {
            DirectoryItem result = this;

            result.RefreshChildren();
            foreach (string dirName in path.Split('\\'))
            {
                if (dirName != string.Empty)
                {
                    if (dirName == HOME_NAME && Name == HOME_NAME)
                    {
                        return(this);
                    }
                    else
                    {
                        var filteredChildren = result.Children.Where(child => {
                            return(child.Name == dirName);
                        });
                        if (filteredChildren.Count() > 0)
                        {
                            result = filteredChildren.First();
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
            }
            return(result);
        }
예제 #3
0
        private DirectoryItem _jump(int offset)
        {
            DirectoryItem target = null;

            if (HistoryPointer + offset < History.Count && HistoryPointer + offset > -1)
            {
                HistoryPointer += offset;
                target          = History[HistoryPointer];
            }
            return(target);
        }
예제 #4
0
        public static DirectoryItem GetHome()
        {
            DirectoryItem homeItem = new DirectoryItem(HOME_NAME, null, ItemType.Directory);

            homeItem.Children.Clear();
            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                homeItem.Children.Add(new DirectoryItem(drive.Name.Replace("\\", string.Empty), homeItem, ItemType.Directory));
            }
            return(homeItem);
        }
예제 #5
0
        public string GetFullPath()
        {
            string        fullPath = NameInPath;
            DirectoryItem tmp      = this;

            while (!(tmp.Parent == null))
            {
                tmp = tmp.Parent;
                if (tmp.Name != HOME_NAME)
                {
                    fullPath = tmp.NameInPath + fullPath;
                }
            }
            return(fullPath);
        }
예제 #6
0
 public AppModel()
 {
     _recent      = new ObservableCollection <string>();
     _dirItems    = DirectoryItem.GetHome();
     _currentPath = _dirItems.NameInPath;
 }
예제 #7
0
 public void Add(DirectoryItem item)
 {
     History.Add(item);
     HistoryPointer++;
 }