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
        }
Exemplo n.º 2
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);

                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
        }