Пример #1
0
        private ObservableCollection <MenuItemViewModel> CreateMenuItemViewModels(IList <BookmarkItem> items)
        {
            var menuVms = new ObservableCollection <MenuItemViewModel>();

            if (items == null || !items.Any())
            {
                return(menuVms);
            }

            var applicationDirectory = AppDomain.CurrentDomain.BaseDirectory;

            var iconsDirectory = new DirectoryInfo(Path.Combine(applicationDirectory, "Resources", "Icons"));

            foreach (var bookmarkItem in items)
            {
                var path = bookmarkItem.Path;

                var vm = new MenuItemViewModel(path)
                {
                    Items = CreateMenuItemViewModels(bookmarkItem.Children)
                };

                if (path == null)
                {
                    vm.Header   = bookmarkItem.BookmarkFolderName;
                    vm.IconPath = Path.Combine(iconsDirectory.FullName, IconName.BookmarkFolder + ".svg");
                }
                else
                {
                    try
                    {
                        DefinitionPathToVm(vm, path, iconsDirectory);
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }

                menuVms.Add(vm);
            }

            return(menuVms);
        }
Пример #2
0
        private void DefinitionPathToVm(MenuItemViewModel vm, string path, DirectoryInfo iconsDirectory)
        {
            vm.Command = BookmarkClickCommand;

            var attr = File.GetAttributes(path);

            if (attr.HasFlag(FileAttributes.Directory))
            {
                vm.Header   = new DirectoryInfo(path).Name;
                vm.IconPath = Path.Combine(iconsDirectory.FullName, IconName.Folder + ".svg");
            }
            else
            {
                var extension = new FileInfo(path).Extension;

                vm.Header   = new FileInfo(path).Name;
                vm.IconPath =
                    _converter.GetImagePath(string.IsNullOrEmpty(extension) ? "" : extension.Substring(1))
                    .FullName;
            }
        }