Пример #1
0
        public IActionResult PrivateFileList()
        {
            var privateFiles = new List <File>();

            var user = _userManager.GetUserAsync(User).Result; //Users = Claims principal, get the object instead

            if (User.Identity.IsAuthenticated)
            {
                privateFiles = _db.Files.Where(file => file.OwnerGuid.Id == user.Id).ToList();
            }

            var usedSpacePct = CalculateUsedPct(user.StorageUsed, DefaultStorage + user.StorageSpace);

            var mappedFiles = Mapper.Map <List <File>, List <FileViewModel> >(privateFiles);

            var viewmodel = new FileListViewModel(mappedFiles)
            {
                DiskUsedPct           = usedSpacePct,
                Editable              = true,
                ShowPublicMarker      = true,
                ShowDiskUsedPctMarker = true
            };


            return(View("PrivateTransferWindow", viewmodel));
        }
Пример #2
0
        public FileListCommands(FileList flist, FileListViewModel rootModel)
        {
            Func <ExModel[]> getSelectionFunc = new Func <ExModel[]>(() =>
                                                                     { return((from vm in rootModel.CurrentDirectoryModel.SelectedViewModels select vm.EmbeddedModel).ToArray()); });
            Func <DirectoryModel>       getCurrentFunc       = new Func <DirectoryModel>(() => { return(rootModel.CurrentDirectoryModel.EmbeddedDirectoryModel); });
            Func <System.Drawing.Point> getMousePositionFunc = new Func <System.Drawing.Point>(() =>
                                                                                               { Point pt = flist.PointToScreen(Mouse.GetPosition(flist)); return(new System.Drawing.Point((int)pt.X, (int)pt.Y)); });

            SetupCommands(getSelectionFunc, getCurrentFunc, getMousePositionFunc);
            SetupCommands(flist, rootModel);

            SimpleRoutedCommand.Register(typeof(FileList), RefreshCommand);
            SimpleRoutedCommand.Register(typeof(FileList), ContextMenuCommand);
            SimpleRoutedCommand.Register(typeof(FileList), NewFolderCommand);
            SimpleRoutedCommand.Register(typeof(FileList), OpenCommand, new KeyGesture(Key.Enter));
            SimpleRoutedCommand.Register(typeof(FileList), CopyCommand);
            SimpleRoutedCommand.Register(typeof(FileList), PasteCommand);
            SimpleRoutedCommand.Register(typeof(FileList), SelectAllCommand, new KeyGesture(Key.A, ModifierKeys.Control));
            SimpleRoutedCommand.Register(typeof(FileList), DeleteCommand, new KeyGesture(Key.Delete));
            SimpleRoutedCommand.Register(typeof(FileList), PropertiesCommand);
            SimpleRoutedCommand.Register(typeof(FileList), RenameCommand, new KeyGesture(Key.F2));
            SimpleRoutedCommand.Register(typeof(FileList), FindCommand, new KeyGesture(Key.F, ModifierKeys.Control));

            flist.AddHandler(TreeViewItem.MouseRightButtonUpEvent, new MouseButtonEventHandler(
                                 (MouseButtonEventHandler) delegate(object sender, MouseButtonEventArgs args)
            {
                ApplicationCommands.ContextMenu.Execute(null, flist);
            }));
        }
Пример #3
0
        public ActionResult Index()
        {
            FileListViewModel elvm  = new FileListViewModel();
            FileBusinessLayer fbl   = new FileBusinessLayer();
            List <FileDB>     files = fbl.GetFiles();

            List <FileViewModel> evmlist = new List <FileViewModel>();

            foreach (FileDB file in files)
            {
                if (!file.isDelete)
                {
                    FileViewModel fvm = new FileViewModel();
                    fvm.FileId     = file.FileId;
                    fvm.FileName   = file.FileName;
                    fvm.Creater    = file.Creater;
                    fvm.UploadTime = file.UploadTime;
                    fvm.Version    = file.Version;
                    evmlist.Add(fvm);
                }
            }

            elvm.FileList = evmlist;
            elvm.UserName = "******";

            return(View("Index", elvm));
        }
Пример #4
0
        public ActionResult History(int id)
        {
            FileListViewModel    flvm    = new FileListViewModel();
            FileBusinessLayer    fbl     = new FileBusinessLayer();
            List <FileDB>        files   = fbl.GetFiles();
            List <FileViewModel> evmlist = new List <FileViewModel>();

            FileDB filenow = fbl.GetFile(id);

            while (filenow != null)
            {
                FileViewModel fvm = new FileViewModel();
                fvm.FileId      = filenow.FileId;
                fvm.FileName    = filenow.FileName;
                fvm.Creater     = filenow.Creater;
                fvm.UploadTime  = filenow.UploadTime;
                fvm.Version     = filenow.Version;
                fvm.FileContent = filenow.FilePath;
                evmlist.Add(fvm);
                filenow = filenow.FormerId;
            }

            flvm.FileList   = evmlist;
            flvm.Permission = Convert.ToString(Session["Permission"]);
            return(View("Historys", flvm));
        }
Пример #5
0
 public FileList(MainWindow main)
 {
     InitializeComponent();
     _fileListViewModel = new FileListViewModel();
     DataContext        = _fileListViewModel;
     _main = main;
 }
        public FileListPage(SpyFileType fileType)
        {
            // Appena creata la pagina deve contenere la lista vuota;
            // lo spinner e' attivo mentre la pagina aspetta il messaggio dal ViewModel
            // di aggiornamento corretto della lista, che ferma lo spinner

            // In generale poi la lista e' composta da un nome del file e una pulsante "Download"
            // che quando premuto esegue un command?
            InitializeComponent();

            MessagingCenter.Subscribe <FileListViewModel, string>(this, "DownloadFilesListError", async(sender, message) =>
            {
                await DisplayAlert("CANAnalyzer", "An error occurred during the files list download.", "Ok");
            });

            MessagingCenter.Subscribe <FileListViewModel, string>(this, "DownloadFileError", async(sender, message) =>
            {
                await DisplayAlert("CANAnalyzer", "An error occurred during the file download.", "Ok");
            });

            _viewModel     = new FileListViewModel(fileType);
            BindingContext = _viewModel;

            _fileType     = fileType;
            _isDataLoaded = false;
        }
Пример #7
0
        public ActionResult List(int id, HomeIndexViewModel homeIndexViewModel)
        {
            var model = new FileListViewModel {
                Files = _service.Dal.FileProvider.Get()
            };

            model.NavigationModel = homeIndexViewModel;
            return(View(model));
        }
Пример #8
0
 public FileListView()
 {
     this.InitializeComponent();
     vm = SimpleIoc.Default.GetInstance <FileListViewModel>();
     // vm = new FileListViewModel();
     DataContext = vm;
     vm.RefreshCommand.Execute(null);
     vm.PropertyChanged += Vm_PropertyChanged;
 }
Пример #9
0
        public ActionResult List(string tagFilter)
        {
            var files = _fileService.List(tagFilter).Where(f => _orchardServices.Authorizer.Authorize(global::Orchard.Core.Contents.Permissions.ViewContent, f));
            var roles = _roleService.GetRoles().Select(r => r.Name).Where(s => s != "Administrator").Union(new[] { "Private" }).OrderBy(s => s);
            var tags  = Common.Tags <PipelineFilePart, PipelineFilePartRecord>(_orchardServices);

            var viewModel = new FileListViewModel(files, roles, tags);

            return(View(viewModel));
        }
Пример #10
0
        public void 削除()
        {
            var fileEntity1 = new FileEntity(
                "test",
                new PhysicalFileName(new Guid("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DA")),
                new FileSize(1230),
                new Comment("This is a pen.\n")
                );
            var fileEntitySlim1
                = new ReactivePropertySlim <FileEntity>(fileEntity1).ToReadOnlyReactivePropertySlim();
            var fileEntity2 = new FileEntity(
                "test2",
                new PhysicalFileName(new Guid("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DB")),
                new FileSize(1300234),
                new Comment("This is a \r\npen.")
                );
            var fileEntitySlim2
                = new ReactivePropertySlim <FileEntity>(fileEntity2).ToReadOnlyReactivePropertySlim();

            var fileDatabaseMock = new Mock <IFileDatabaseRepository>();
            var entities         = new List <FileEntity>();

            entities.Add(fileEntity1);
            entities.Add(fileEntity2);
            fileDatabaseMock.Setup(x => x.GetData()).Returns(entities);

            fileDatabaseMock.Setup(x => x.Delete(It.IsAny <FileEntity>()))
            .Callback <FileEntity>(value =>
            {
                entities.RemoveAll(entity => entity.Equals(value));
                fileDatabaseMock
                .Setup(x => x.GetData())
                .Returns(() => entities);
            });

            var viewModel = new FileListViewModel(
                fileDatabaseMock.Object,
                null,
                null
                );

            viewModel.FileList.Count.Is(2);

            viewModel.Delete(fileEntitySlim1);
            viewModel.FileList.Count.Is(1);
            viewModel.FileList[0].LogicalFileName.Value.Is("test2");
            viewModel.FileList[0].PhysicalFileName.Value.Is("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DB");
            viewModel.FileList[0].FileSize.Value.Is("1.24 MB");
            viewModel.FileList[0].Comment.Value.Is("This is a  pen.");

            viewModel.Delete(fileEntitySlim2);
            viewModel.FileList.Count.Is(0);
        }
Пример #11
0
        private async void LazyLoad(object sender, ScrollChangedEventArgs e)
        {
            lock (LazyLoadEventHandler)
            {
                LazyLoadEventHandler = null;
            }
            //懒加载的业务代码
            FileListViewModel vm = DataContext as FileListViewModel;
            await Task.Run(() => vm.LazyLoad());

            LazyLoadEventHandler = new ScrollChangedEventHandler(LazyLoad);
        }
Пример #12
0
        public void 初期状態()
        {
            var fileDatabaseMock = new Mock <IFileDatabaseRepository>();
            var entities         = new List <FileEntity>();

            fileDatabaseMock.Setup(x => x.GetData()).Returns(entities);

            var viewModel = new FileListViewModel(
                fileDatabaseMock.Object,
                null,
                null
                );

            viewModel.FileList.Count.Is(0);
        }
Пример #13
0
        public IActionResult PublicFileList()
        {
            var publicFiles  = _db.Files.Where(file => file.IsPublic).Include(file => file.OwnerGuid).ToList();
            var usedSpacePct = CalculateUsedPct(
                publicFiles.Where(file => file.OwnerGuid == null).Sum(file => file.Size), PublicStorageLimit);

            var mappedFiles = Mapper.Map <List <File>, List <FileViewModel> >(publicFiles);

            var viewmodel = new FileListViewModel(mappedFiles)
            {
                DiskUsedPct           = usedSpacePct,
                ShowDiskUsedPctMarker = true
            };


            return(View("PublicTransferWindow", viewmodel));
        }
Пример #14
0
        // GET
        public IActionResult Index(string sortcolumn, string sortorder)
        {
            var model = new FileListViewModel();
            var query = _movieRepository.GetAll().Select(r => new FileListViewModel.FilmViewModel
            {
                Id          = r.FilmId,
                ReleaseYear = r.ReleaseYear,
                Title       = r.Title
            });

            query = AddSorting(query, ref sortcolumn, ref sortorder);

            model.Films      = query.ToList();
            model.SortColumn = sortcolumn;
            model.SortOrder  = sortorder;
            return(View(model));
        }
Пример #15
0
        public FileListViewModel GetAllFiles()
        {
            var fileDtos  = CpAbeCloud.GetAllFiles();
            var viewModel = new FileListViewModel
            {
                Files = new List <FileViewModel>()
            };

            foreach (var dto in fileDtos)
            {
                viewModel.Files.Add(new FileViewModel
                {
                    FileId      = dto.FileId,
                    Name        = dto.Name,
                    CreatedDate = dto.CreatedDate
                });
            }
            return(viewModel);
        }
Пример #16
0
        public IActionResult Index()
        {
            // string path = $"{_env.WebRootPath}\\packages\\";
            string path  = Path.Combine(_env.WebRootPath, "packages");
            var    files = Directory.GetFiles(path);

            var fileListViewModel = new FileListViewModel();

            if (files != null && files.Length > 0)
            {
                fileListViewModel.Files = new Dictionary <string, string>();
                foreach (var file in files)
                {
                    var newFile = EnsureFileName(file);
                    fileListViewModel.Files[newFile] = $"{Request.Scheme}://{Request.Host.Value}/files/download?filename={HttpUtility.UrlEncode(newFile)}";
                }
            }

            return(View(fileListViewModel));
        }
Пример #17
0
        public async Task <IActionResult> FileList()
        {
            try
            {
                FileListViewModel model = new FileListViewModel();
                model._context         = _context;
                model._emailService    = _emailService;
                model._securityOptions = _securityOptions;
                model._user            = User;

                await model.PopulateDetail();

                ViewData.Model = model;
            }
            catch (Exception ex)
            {
                HelperFunctions.Log(_context, PublicEnums.LogLevel.LEVEL_EXCEPTION, "Controllers.FileShareController.FileList", ex.Message, User, ex);
            }

            return(View());
        }
Пример #18
0
        public void 最初からデータがある状態()
        {
            var fileDatabaseMock = new Mock <IFileDatabaseRepository>();
            var entities         = new List <FileEntity>();

            entities.Add(
                new FileEntity(
                    "test",
                    new PhysicalFileName(new Guid("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DA")),
                    new FileSize(1230),
                    new Comment("This is a pen.\n")
                    )
                );
            entities.Add(
                new FileEntity(
                    "test2",
                    new PhysicalFileName(new Guid("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DB")),
                    new FileSize(1300234),
                    new Comment("This is a \r\npen.")
                    )
                );
            fileDatabaseMock.Setup(x => x.GetData()).Returns(entities);

            var viewModel = new FileListViewModel(
                fileDatabaseMock.Object,
                null,
                null
                );

            viewModel.FileList.Count.Is(2);
            viewModel.FileList[0].LogicalFileName.Value.Is("test");
            viewModel.FileList[0].PhysicalFileName.Value.Is("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DA");
            viewModel.FileList[0].FileSize.Value.Is("1.20 KB");
            viewModel.FileList[0].Comment.Value.Is("This is a pen. ");
            viewModel.FileList[1].LogicalFileName.Value.Is("test2");
            viewModel.FileList[1].PhysicalFileName.Value.Is("2DA0C0DC-8EB9-4DF2-B224-DF57CC5671DB");
            viewModel.FileList[1].FileSize.Value.Is("1.24 MB");
            viewModel.FileList[1].Comment.Value.Is("This is a  pen.");
        }
Пример #19
0
        public ActionResult Index(FileListViewModel model)
        {
            var new_model = model;

            if (ModelState.IsValid)
            {
                //обрабатываем ситуацию очистки фильтра по услугам: в этом случае SelectedServiceId != -1, но SelectedService == null
                if (string.IsNullOrEmpty(model.SelectedService))
                {
                    model.SelectedServiceId = Service.All.Id;
                }

                //сохраняем настройки фильтра
                Session[FileControllerIndexKey] = new Dictionary <string, object>();
                var settings = Session[FileControllerIndexKey] as IDictionary <string, object>;
                if (!settings.ContainsKey(DateBeginKey))
                {
                    settings.Add(DateBeginKey, model.BeginDate);
                }
                else
                {
                    settings[DateBeginKey] = model.BeginDate;
                }

                if (!settings.ContainsKey(DateEndKey))
                {
                    settings.Add(DateEndKey, model.EndDate);
                }
                else
                {
                    settings[DateEndKey] = model.EndDate;
                }

                if (!settings.ContainsKey(ControllerKey))
                {
                    settings.Add(ControllerKey, model.SelectedControllerId);
                }
                else
                {
                    settings[ControllerKey] = model.SelectedControllerId;
                }

                if (!settings.ContainsKey(ExpertKey))
                {
                    settings.Add(ExpertKey, model.SelectedExpertId);
                }
                else
                {
                    settings[ExpertKey] = model.SelectedExpertId;
                }

                if (!settings.ContainsKey(OrgKey))
                {
                    settings.Add(OrgKey, model.SelectedOgvId);
                }
                else
                {
                    settings[OrgKey] = model.SelectedOgvId;
                }

                if (!settings.ContainsKey(StatusKey))
                {
                    settings.Add(StatusKey, model.SelectedStatusId);
                }
                else
                {
                    settings[StatusKey] = model.SelectedStatusId;
                }

                if (!settings.ContainsKey(ServiceKey))
                {
                    settings.Add(ServiceKey, model.SelectedServiceId);
                }
                else
                {
                    settings[ServiceKey] = model.SelectedServiceId;
                }

                model.Page = 1;

                model = CreateModel(model.BeginDate, model.EndDate, model.SelectedControllerId, model.SelectedExpertId, model.SelectedStatusId, model.SelectedOgvId, model.SelectedServiceId, model.Page);
            }

            return(View(model));
        }
Пример #20
0
        private FileListViewModel CreateModel(DateTime beginDate, DateTime endDate, Int64 controllerId = -1, Int64 expertId = -1, Int64 statusId = -1, Int64 orgId = -1, Int64 serviceId = -1, Int32 page = 1)
        {
            Logger.Debug($"FileController.CreateModel start ");

            var user_srv   = CompositionRoot.Resolve <IUserService>();
            var status_srv = CompositionRoot.Resolve <IFileStatusService>();
            var org_srv    = CompositionRoot.Resolve <IOrganizationService>();
            var file_srv   = CompositionRoot.Resolve <IFileService>();

            FileListViewModel model = new FileListViewModel();

            model.SelectedOgvId        = orgId == -1 ? Organization.All.Id : orgId;
            model.SelectedControllerId = controllerId == -1 ? mfc.domain.entities.User.All.Id : controllerId;
            model.SelectedExpertId     = expertId == -1 ? mfc.domain.entities.User.All.Id : expertId;
            model.SelectedStatusId     = statusId == -1 ? FileStatus.All.Id : statusId;
            model.SelectedServiceId    = serviceId == -1 ? Service.All.Id : serviceId;
            model.BeginDate            = beginDate;
            model.EndDate = endDate;
            model.Page    = page;

            if (page == 0)
            {
                model.Page = 1;
            }

            if (serviceId != Service.All.Id)
            {
                var service = ServiceService.GetServiceById(serviceId);
                if (service != null)
                {
                    model.SelectedService = service.Caption;
                }
            }

            if (User.IsInRole(Roles.Admin) || User.IsInRole(Roles.Controller))
            {
                //Для администратора и контролера заполняем список всеми экспертами и контролерами
                foreach (var user in user_srv.GetControllers())
                {
                    model.Controllers.Add(user);
                }
                model.Controllers.Insert(0, mfc.domain.entities.User.All);

                foreach (var user in user_srv.GetExperts())
                {
                    model.Experts.Add(user);
                }
                model.Experts.Insert(0, mfc.domain.entities.User.All);
            }
            else if (User.IsInRole(Roles.Expert))
            {
                //если только эксперт, то полный список контроллеров и один эксперт
                var user = user_srv.GetCurrentUser();

                model.Experts.Add(user_srv.GetCurrentUser());

                model.Controllers.Add(mfc.domain.entities.User.All);
                foreach (var controller in user_srv.GetControllers())
                {
                    model.Controllers.Add(controller);
                }

                model.SelectedExpertId = user.Id;
            }

            model.Statuses.Add(FileStatus.All);

            foreach (var item in status_srv.GetAllStatuses())
            {
                model.Statuses.Add(item);
            }

            model.Organizations.Add(Organization.All);

            foreach (var item in org_srv.GetAllOrganizations())
            {
                model.Organizations.Add(item);
            }

            foreach (var file in file_srv.GetFiles(model.BeginDate, model.EndDate, model.SelectedControllerId, model.SelectedExpertId, model.SelectedStatusId, model.SelectedOgvId, model.SelectedServiceId))
            {
                model.Files.Add(FileModelConverter.RecordToModelItem(file));
            }

            Logger.Debug($"FileController.CreateModel end ");

            return(model);
        }
Пример #21
0
        public void SetupCommands(FileList flist, FileListViewModel rootModel)
        {
            #region IndividualItemCommand - Open, Rename
            OpenCommand = new SimpleRoutedCommand(ApplicationCommands.Open)
            {
                CanExecuteDelegate = x =>
                {
                    return(rootModel.CurrentDirectoryModel != null && rootModel.CurrentDirectoryModel.SelectedCount == 1);
                },
                ExecuteDelegate = x =>
                {
                    rootModel.CurrentDirectoryModel.SelectedViewModels[0].Expand(rootModel,
                                                                                 rootModel.CurrentDirectoryModel.SelectedViewModels[0].EmbeddedModel);
                }
            };


            RenameCommand = new SimpleRoutedCommand(ApplicationCommands.SaveAs)
            {
                CanExecuteDelegate = x =>
                {
                    return(rootModel.CurrentDirectoryModel != null && rootModel.CurrentDirectoryModel.SelectedCount == 1);
                },
                ExecuteDelegate = x =>
                {
                    rootModel.CurrentDirectoryModel.IsEditing = !rootModel.CurrentDirectoryModel.IsEditing;
                }
            };

            #endregion

            #region NewFolderCommand
            NewFolderCommand = new SimpleRoutedCommand(FileListCommands.NewFolder)
            {
                CanExecuteDelegate = x =>
                {
                    if ((rootModel.CurrentDirectoryModel.EmbeddedDirectoryModel.EmbeddedDirectoryEntry.Attributes & FileAttributes.ReadOnly) != 0)
                    {
                        return(false);
                    }

                    if (x == null)
                    {
                        return(true);
                    }

                    if (x is string)
                    {
                        string type = (string)x;
                        switch (type.ToLower())
                        {
                        case "zip":
                        case "7z": return(true);
                        }
                    }

                    return(false);
                },
                ExecuteDelegate = x =>
                {
                    string type = x as string;
                    if (x != null)
                    {
                        type = type.ToLower();
                    }
                    rootModel.CurrentDirectoryModel.NewFolder();
                }
            };
            #endregion

            #region SelectAllCommand
            SelectAllCommand = new SimpleRoutedCommand(ApplicationCommands.SelectAll)
            {
                CanExecuteDelegate = x =>
                {
                    return(rootModel.CurrentDirectoryModel != null && rootModel.CurrentDirectoryModel.HasSubEntries);
                },
                ExecuteDelegate = x =>
                {
                    if (rootModel.CurrentDirectoryModel.SelectedCount == rootModel.CurrentDirectoryModel.SubEntriesInternal.Count)
                    {
                        rootModel.CurrentDirectoryModel.UnselectAll();
                    }
                    else
                    {
                        rootModel.CurrentDirectoryModel.SelectAll();
                    }
                }
            };
            #endregion

            #region RefreshCommand
            RefreshCommand = new SimpleRoutedCommand(NavigationCommands.Refresh)
            {
                CanExecuteDelegate = x => true,
                ExecuteDelegate    = x => rootModel.CurrentDirectoryModel.Refresh()
            };
            #endregion

            #region FindCommand

            FindCommand = new SimpleRoutedCommand(ApplicationCommands.Find)
            {
                CanExecuteDelegate = x =>
                {
                    return(rootModel.CurrentDirectoryModel != null && !rootModel.CurrentDirectoryModel.IsEditing);
                },
                ExecuteDelegate = x =>
                {
                    flist.LookupAdorner.UpdateVisibilty(true);
                    FocusManager.SetFocusedElement(flist, flist.LookupAdorner);
                }
            };


            #endregion
        }
Пример #22
0
 public static DependencyProperty PressedImageProperty;//依赖属性
 public FileListView()
 {
     InitializeComponent();
     viewModel        = new FileListViewModel(this);
     this.DataContext = viewModel;
 }
Пример #23
0
        public FileList()
        {
            ModelToExConverter     = new ModelToExConverter();
            ExModelToIconConverter = new ExModelToIconConverter();
            DataContext            = RootModel = new FileListViewModel();
            Commands = new FileListCommands(this, RootModel);

            InitializeComponent();

            //0.2
            Binding isLoadingBinding = new Binding("IsLoading");

            isLoadingBinding.Source = RootModel;
            this.SetBinding(IsLoadingProperty, isLoadingBinding);

            Binding sortByBinding = new Binding("SortBy");

            sortByBinding.Source = RootModel;
            sortByBinding.Mode   = BindingMode.TwoWay;
            this.SetBinding(SortByProperty, sortByBinding);

            Binding sortDirectionBinding = new Binding("SortDirection");

            sortDirectionBinding.Source = RootModel;
            sortDirectionBinding.Mode   = BindingMode.TwoWay;
            this.SetBinding(SortDirectionProperty, sortDirectionBinding);
            UpdateCollumnHeader();

            RootModel.OnProgress += (ProgressEventHandler) delegate(object sender, ProgressEventArgs e)
            {
                RaiseEvent(new ProgressRoutedEventArgs(ProgressEvent, e));
            };

            this.AddHandler(ListView.KeyDownEvent, (KeyEventHandler) delegate(object sender, KeyEventArgs args)
            {
                if ((args as RoutedEventArgs).OriginalSource == this)
                {
                    if ((int)args.Key >= (int)Key.A && (int)args.Key <= (int)Key.Z)
                    {
                        _lookupAdorner.UpdateVisibilty(true);
                        //_lookupAdorner.Focus();
                        Keyboard.Focus(_lookupAdorner);

                        //_lookupAdorner.Text = args.Key.ToString().ToLower();
                    }

                    if (args.Key == Key.Escape)
                    {
                        _lookupAdorner.UpdateVisibilty(false);
                    }
                }
                //if (args.Key == Key.F3)
                //    _lookupAdorner.UpdateVisibilty(true);
            });

            //0.2
            this.AddHandler(GridViewColumnHeader.ClickEvent, (RoutedEventHandler) delegate(object sender, RoutedEventArgs args)
            {
                if (args.OriginalSource is GridViewColumnHeader)
                {
                    GridViewColumnHeader header        = (GridViewColumnHeader)args.OriginalSource;
                    ExComparer.SortCriteria columnName = GetSortPropertyName(header.Column);

                    //if (string.IsNullOrEmpty(columnName))
                    //    return;

                    if (RootModel.SortBy != columnName)
                    {
                        RootModel.SortBy = columnName;
                    }
                    else
                    if (RootModel.SortDirection == ListSortDirection.Ascending)
                    {
                        RootModel.SortDirection = ListSortDirection.Descending;
                    }
                    else
                    {
                        RootModel.SortDirection = ListSortDirection.Ascending;
                    }

                    UpdateCollumnHeader();
                }
            });

            this.AddHandler(ListView.SelectionChangedEvent, (SelectionChangedEventHandler) delegate(object sender, SelectionChangedEventArgs args)
            {
                List <FileSystemInfoEx> selectedList = new List <FileSystemInfoEx>(SelectedEntries);

                foreach (FileListViewItemViewModel removeItem in args.RemovedItems)
                {
                    selectedList.Remove(removeItem.EmbeddedModel.EmbeddedEntry);
                }


                foreach (FileListViewItemViewModel addItem in args.AddedItems)
                {
                    selectedList.Add(addItem.EmbeddedModel.EmbeddedEntry);
                }

                //if (args.AddedItems.Count==1) {
                //    SelectedEntries.Clear();
                //    selectedList.Clear();
                //         foreach (FileListViewItemViewModel addItem in args.AddedItems)
                //            selectedList.Add(addItem.EmbeddedModel.EmbeddedEntry);
                //}


                SelectedEntries = selectedList;

                //The following does not work because of virtual items.
                //SelectedEntries = RootModel.CurrentDirectoryModel.SelectedEntries;
            });



            RootModel.PropertyChanged += (PropertyChangedEventHandler) delegate(object sender, PropertyChangedEventArgs args)
            {
                if (args.PropertyName == "CurrentDirectory")
                {
                    CurrentDirectory = RootModel.CurrentDirectory;
                    ScrollViewer scrollViewer = UITools.FindVisualChild <ScrollViewer>(this);
                    if (scrollViewer != null)
                    {
                        scrollViewer.ScrollToHome();
                    }

                    ExToIconConverter ati = this.TryFindResource("ati") as ExToIconConverter;
                    if (ati.IconCount > 500)
                    {
                        ati.ClearInstanceCache();
                    }
                }
            };

            //#region ExpandHandler
            //this.AddHandler(ListViewItem.MouseDoubleClickEvent, (RoutedEventHandler)delegate(object sender, RoutedEventArgs e)
            //{
            //    DependencyObject lvItem = getListViewItem(e.OriginalSource as DependencyObject);
            //    if (lvItem != null)
            //    {
            //        FileListViewItemViewModel model =
            //            (FileListViewItemViewModel)ItemContainerGenerator.ItemFromContainer(lvItem);
            //        if (model != null)
            //        {
            //            model.Expand();
            //        }
            //    }
            //});
            //#endregion

            #region ContextMenuWrapper - Obsoluted
            //_cmw = new ContextMenuWrapper();

            //this.AddHandler(TreeViewItem.MouseRightButtonUpEvent, new MouseButtonEventHandler(
            //    (MouseButtonEventHandler)delegate(object sender, MouseButtonEventArgs args)
            //    {
            //        if (SelectedValue is FileListViewItemViewModel)
            //        {
            //            var selectedItems = (from FileListViewItemViewModel model in SelectedItems
            //                                 select model.EmbeddedModel.EmbeddedEntry).ToArray();
            //            Point pt = this.PointToScreen(args.GetPosition(this));

            //            string command = _cmw.Popup(selectedItems, new System.Drawing.Point((int)pt.X, (int)pt.Y));
            //            switch (command)
            //            {
            //                case "rename":
            //                    if (this.SelectedValue != null)
            //                    {
            //                        SetIsEditing(ItemContainerGenerator.ContainerFromItem(this.SelectedValue), true);
            //                    }
            //                    break;
            //                case "refresh":
            //                    RootModel.CurrentDirectoryModel.Refresh();
            //                    break;
            //            }
            //        }
            //    }));
            #endregion
        }
Пример #24
0
 public AppViewModel(IEventAggregator events)
 {
     FileListModel = new FileListViewModel(events);
 }
Пример #25
0
 public IViewComponentResult Invoke(FileListViewModel viewModel)
 {
     return(View(viewModel));
 }