Example #1
0
        private static void FocusBindingPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            if (DesignerProperties.GetIsInDesignMode(obj))
            {
                return;
            }

            var control = (FrameworkElement)obj;

            if ((bool)args.NewValue)
            {
                if (control.Focusable)
                {
                    control.Focus();
                }
                else
                {
                    if (!control.IsLoaded)
                    {
                        control.Loaded += Control_Loaded;
                    }
                    else
                    {
                        foreach (var child in ElementTreeHelper.FindVisualChildren <FrameworkElement>(control))
                        {
                            if (child.Focusable && child.IsVisible)
                            {
                                child.Focus();
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private void ListBoxEx_Loaded(object sender, RoutedEventArgs e)
 {
     itemsPanel = ElementTreeHelper.FindVisualChildren <FullscreenTilePanel>(this).FirstOrDefault();
     if (itemsPanel != null)
     {
         itemsPanel.InternalChildrenGenerated += ItemsPanel_InternalChildrenGenerated;
     }
 }
Example #3
0
        private void FilterSettings_FilterChanged(object sender, FilterChangedEventArgs e)
        {
            if (mainModel.AppSettings.ViewSettings.GamesViewType != viewType)
            {
                return;
            }

            var scrollViewer = ElementTreeHelper.FindVisualChildren <ScrollViewer>(ListGames).FirstOrDefault();

            scrollViewer?.ScrollToTop();
        }
Example #4
0
        private static void Control_Loaded(object sender, RoutedEventArgs e)
        {
            var elem = (FrameworkElement)sender;

            elem.Loaded -= Control_Loaded;
            foreach (var child in ElementTreeHelper.FindVisualChildren <FrameworkElement>(elem))
            {
                if (child.Focusable)
                {
                    child.Focus();
                    return;
                }
            }
        }
Example #5
0
        private void ViewSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (mainModel.AppSettings.ViewSettings.GamesViewType != viewType)
            {
                return;
            }

            if (e.PropertyName == nameof(ViewSettings.GroupingOrder))
            {
                ListGames.ItemsPanel = GetItemsPanelTemplateCache();
                var scrollViewer = ElementTreeHelper.FindVisualChildren <ScrollViewer>(ListGames).FirstOrDefault();
                scrollViewer?.ScrollToTop();
            }
        }
        private static void ScrollAmountPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            if (DesignerProperties.GetIsInDesignMode(obj))
            {
                return;
            }

            if (obj is ScrollViewer scr)
            {
                scr.PreviewMouseWheel -= Test_PreviewMouseWheel;
                if ((double)args.NewValue > 0)
                {
                    scr.PreviewMouseWheel += Test_PreviewMouseWheel;
                }
            }
            else
            {
                var control = (FrameworkElement)obj;
                if (control.IsLoaded)
                {
                    var scroll = ElementTreeHelper.FindVisualChildren <ScrollViewer>(obj).FirstOrDefault();
                    if (scroll != null)
                    {
                        SetScrollAmount(scroll, (double)args.NewValue);
                    }
                }
                else
                {
                    control.Loaded += (a, b) =>
                    {
                        var ctrl   = (FrameworkElement)a;
                        var scroll = ElementTreeHelper.FindVisualChildren <ScrollViewer>(control).FirstOrDefault();
                        if (scroll != null)
                        {
                            SetScrollAmount(scroll, (double)args.NewValue);
                        }
                    };
                }
            }
        }
Example #7
0
        protected override Size MeasureOverride(Size availableSize)
        {
            // This is for weird edge case where Measuring can occur and OnItemsChanged was not called by WPF first
            if (ItemWidth == 0)
            {
                var startPosition = ItemContainerGenerator.GeneratorPositionFromIndex(0);
                using (ItemContainerGenerator.StartAt(startPosition, GeneratorDirection.Forward, true))
                {
                    var child = (UIElement)ItemContainerGenerator.GenerateNext();
                    if (child != null)
                    {
                        AddInternalChild(child);
                        ItemContainerGenerator.PrepareItemContainer(child);
                        child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    }
                }
            }

            var groupItem = ItemsOwner as IHierarchicalVirtualizationAndScrollInfo;

            if (groupItem != null)
            {
                // This is a workaround for issues like #2454, caused by some bug in WPF.
                // Collapsed groups are SOMETIMES treated as expandeded and will force initialization of child items.
                var expander = ElementTreeHelper.FindVisualChildren <Expander>(groupItem as GroupItem).FirstOrDefault();
                if (expander != null && expander.IsExpanded == false)
                {
                    UpdateScrollInfo(new Size(0, 0));
                    CleanUpItems();
                    return(new Size(0, 0));
                }
                else
                {
                    UpdateScrollInfo(groupItem.Constraints.Viewport.Size);
                }

                Offset = groupItem.Constraints.Viewport.Location;
            }
            else
            {
                UpdateScrollInfo(availableSize);
            }

            GetVisibleRange(out var firstItemIndex, out var lastItemIndex);
            if (lastItemIndex < 0)
            {
                return(Extent);
            }

            var startPos   = ItemContainerGenerator.GeneratorPositionFromIndex(firstItemIndex);
            var childIndex = (startPos.Offset == 0) ? startPos.Index : startPos.Index + 1;

            using (ItemContainerGenerator.StartAt(startPos, GeneratorDirection.Forward, true))
            {
                for (int itemIndex = firstItemIndex; itemIndex <= lastItemIndex; ++itemIndex, ++childIndex)
                {
                    UIElement child = ItemContainerGenerator.GenerateNext(out var newlyRealized) as UIElement;
                    if (child == null)
                    {
                        continue;
                    }

                    if (newlyRealized)
                    {
                        if (childIndex >= InternalChildren.Count)
                        {
                            AddInternalChild(child);
                        }
                        else
                        {
                            InsertInternalChild(childIndex, child);
                        }

                        ItemContainerGenerator.PrepareItemContainer(child);
                    }
                    else if (!InternalChildren.Contains(child))
                    {
                        InsertInternalChild(childIndex, child);
                        ItemContainerGenerator.PrepareItemContainer(child);
                    }

                    child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                }
            }

            CleanUpItems(firstItemIndex, lastItemIndex);
            return(Extent);
        }
        private void InitializeCommands()
        {
            WindowClosingCommand = new RelayCommand <CancelEventArgs>((a) =>
            {
                if (!ignoreCloseActions)
                {
                    Dispose();
                    App.Quit();
                }
            });

            WindowGotFocusCommand = new RelayCommand <EventArgs>((a) =>
            {
                if (Keyboard.FocusedElement == Window.Window && isInitialized && !ignoreCloseActions)
                {
                    Logger.Warn("Lost keyboard focus from known controls, trying to focus something.");
                    foreach (var child in ElementTreeHelper.FindVisualChildren <FrameworkElement>(Window.Window))
                    {
                        if (child.Focusable && child.IsVisible)
                        {
                            Logger.Debug($"Focusing {child}");
                            child.Focus();
                            return;
                        }
                    }
                }
            });

            ToggleFullscreenCommand = new RelayCommand <object>((a) =>
            {
                ToggleFullscreen();
            });

            OpenGameMenuCommand = new RelayCommand <object>((a) =>
            {
                OpenGameMenu();
            }, (a) => SelectedGameDetails != null);

            ToggleGameDetailsCommand = new RelayCommand <object>((a) =>
            {
                GameDetailsVisible = !GameDetailsVisible;
                GameListVisible    = !GameListVisible;

                if (!GameDetailsVisible)
                {
                    GameDetailsFocused = false;
                    GameListFocused    = true;
                }
                else
                {
                    GameDetailsFocused = true;
                    GameListFocused    = false;
                }
            }, (a) => SelectedGame != null);

            LoadSubFilterCommand = new RelayCommand <GameField>((gameField) =>
            {
                switch (gameField)
                {
                case GameField.PluginId:
                    OpenSubFilter("LOCLibrary", nameof(DatabaseFilter.Libraries), nameof(FilterSettings.Library), true);
                    break;

                case GameField.Categories:
                    OpenSubFilter("LOCCategoryLabel", nameof(DatabaseFilter.Categories), nameof(FilterSettings.Category), true);
                    break;

                case GameField.Platforms:
                    OpenSubFilter("LOCPlatformTitle", nameof(DatabaseFilter.Platforms), nameof(FilterSettings.Platform), true);
                    break;

                case GameField.CompletionStatus:
                    OpenSubFilter("LOCCompletionStatus", nameof(DatabaseFilter.CompletionStatuses), nameof(FilterSettings.CompletionStatuses));
                    break;

                case GameField.ReleaseYear:
                    OpenSubStringFilter("LOCGameReleaseYearTitle", nameof(DatabaseFilter.ReleaseYears), nameof(FilterSettings.ReleaseYear));
                    break;

                case GameField.Genres:
                    OpenSubFilter("LOCGenreLabel", nameof(DatabaseFilter.Genres), nameof(FilterSettings.Genre));
                    break;

                case GameField.Developers:
                    OpenSubFilter("LOCDeveloperLabel", nameof(DatabaseFilter.Developers), nameof(FilterSettings.Developer));
                    break;

                case GameField.Publishers:
                    OpenSubFilter("LOCPublisherLabel", nameof(DatabaseFilter.Publishers), nameof(FilterSettings.Publisher));
                    break;

                case GameField.Features:
                    OpenSubFilter("LOCFeatureLabel", nameof(DatabaseFilter.Features), nameof(FilterSettings.Feature));
                    break;

                case GameField.Tags:
                    OpenSubFilter("LOCTagLabel", nameof(DatabaseFilter.Tags), nameof(FilterSettings.Tag));
                    break;

                case GameField.Playtime:
                    OpenSubEnumFilter("LOCTimePlayed", typeof(PlaytimeCategory), nameof(FilterSettings.PlayTime));
                    break;

                case GameField.Series:
                    OpenSubFilter("LOCSeriesLabel", nameof(DatabaseFilter.Series), nameof(FilterSettings.Series));
                    break;

                case GameField.Regions:
                    OpenSubFilter("LOCRegionLabel", nameof(DatabaseFilter.Regions), nameof(FilterSettings.Region));
                    break;

                case GameField.Source:
                    OpenSubFilter("LOCSourceLabel", nameof(DatabaseFilter.Sources), nameof(FilterSettings.Source));
                    break;

                case GameField.AgeRatings:
                    OpenSubFilter("LOCAgeRatingLabel", nameof(DatabaseFilter.AgeRatings), nameof(FilterSettings.AgeRating));
                    break;

                case GameField.UserScore:
                    OpenSubEnumFilter("LOCUserScore", typeof(ScoreGroup), nameof(FilterSettings.UserScore));
                    break;

                case GameField.CommunityScore:
                    OpenSubEnumFilter("LOCCommunityScore", typeof(ScoreGroup), nameof(FilterSettings.CommunityScore));
                    break;

                case GameField.CriticScore:
                    OpenSubEnumFilter("LOCCriticScore", typeof(ScoreGroup), nameof(FilterSettings.CriticScore));
                    break;

                case GameField.LastActivity:
                    OpenSubEnumFilter("LOCGameLastActivityTitle", typeof(PastTimeSegment), nameof(FilterSettings.LastActivity));
                    break;

                case GameField.Added:
                    OpenSubEnumFilter("LOCAddedLabel", typeof(PastTimeSegment), nameof(FilterSettings.Added));
                    break;

                case GameField.Modified:
                    OpenSubEnumFilter("LOCModifiedLabel", typeof(PastTimeSegment), nameof(FilterSettings.Modified));
                    break;
                }
            });

            OpenAdditionalFiltersCommand = new RelayCommand <object>((a) =>
            {
                FilterPanelVisible           = false;
                FilterAdditionalPanelVisible = true;
            });

            CloseAdditionalFiltersCommand = new RelayCommand <object>((a) =>
            {
                FilterAdditionalPanelVisible = false;
                FilterPanelVisible           = true;
            });

            CloseAdditionalFilterCommand = new RelayCommand <object>((a) =>
            {
                ((IDisposable)SubFilterControl).Dispose();
                SubFilterControl             = null;
                FilterAdditionalPanelVisible = true;
            });

            CloseSubFilterCommand = new RelayCommand <object>((a) =>
            {
                if (SubFilterControl != null)
                {
                    FilterPanelVisible = true;
                    ((IDisposable)SubFilterControl).Dispose();
                    SubFilterControl = null;
                }
            });

            ToggleFiltersCommand = new RelayCommand <object>((a) =>
            {
                if (SubFilterVisible)
                {
                    ((IDisposable)SubFilterControl).Dispose();
                    SubFilterControl   = null;
                    FilterPanelVisible = false;
                }
                else if (FilterAdditionalPanelVisible)
                {
                    FilterAdditionalPanelVisible = false;
                }
                else
                {
                    FilterPanelVisible = !FilterPanelVisible;
                }

                if (FilterPanelVisible)
                {
                    GameListFocused = false;
                }
                else
                {
                    GameListFocused = true;
                }
            });

            ClearFiltersCommand = new RelayCommand <object>((a) =>
            {
                AppSettings.Fullscreen.FilterSettings.ClearFilters();
                ActiveFilterPreset = null;
            });

            ActivateSelectedCommand = new RelayCommand <object>((a) =>
            {
                if (SelectedGame?.IsInstalled == true)
                {
                    GamesEditor.PlayGame(SelectedGame.Game);
                }
                else if (SelectedGame?.IsInstalled == false)
                {
                    GamesEditor.InstallGame(SelectedGame.Game);
                }
            }, (a) => Database?.IsOpen == true);

            OpenSearchCommand = new RelayCommand <object>((a) =>
            {
                GameListFocused        = false;
                var oldSearch          = AppSettings.Fullscreen.FilterSettings.Name;
                var input              = new Windows.TextInputWindow();
                input.PropertyChanged += SearchText_PropertyChanged;
                var res = input.ShowInput(WindowManager.CurrentWindow, "", "", AppSettings.Fullscreen.FilterSettings.Name);
                input.PropertyChanged -= SearchText_PropertyChanged;
                if (res.Result != true)
                {
                    AppSettings.Fullscreen.FilterSettings.Name = oldSearch;
                }

                GameListFocused = true;
            });

            NextFilterViewCommand = new RelayCommand <object>((a) =>
            {
                var presets = SortedFilterFullscreenPresets;
                if (!presets.HasItems())
                {
                    return;
                }

                if (ActiveFilterPreset == null)
                {
                    ActiveFilterPreset = presets[0];
                }
                else
                {
                    var curIndex = presets.IndexOf(ActiveFilterPreset);
                    if (curIndex < (presets.Count - 1))
                    {
                        ActiveFilterPreset = presets[curIndex + 1];
                    }
                }
            }, (a) => Database?.IsOpen == true);

            PrevFilterViewCommand = new RelayCommand <object>((a) =>
            {
                var presets = SortedFilterFullscreenPresets;
                if (!presets.HasItems())
                {
                    return;
                }

                if (ActiveFilterPreset == null)
                {
                    ActiveFilterPreset = presets[0];
                }
                else
                {
                    var curIndex = presets.IndexOf(ActiveFilterPreset);
                    if (curIndex > 0)
                    {
                        ActiveFilterPreset = presets[curIndex - 1];
                    }
                }
            }, (a) => Database?.IsOpen == true);

            SelectPrevGameCommand = new RelayCommand <object>((a) =>
            {
                var currIndex = GamesView.CollectionView.IndexOf(SelectedGame);
                var prevIndex = currIndex - 1;
                if (prevIndex >= 0)
                {
                    SelectedGame = GamesView.CollectionView.GetItemAt(prevIndex) as GamesCollectionViewEntry;
                }
            }, (a) => Database?.IsOpen == true);

            SelectNextGameCommand = new RelayCommand <object>((a) =>
            {
                var currIndex = GamesView.CollectionView.IndexOf(SelectedGame);
                var nextIndex = currIndex + 1;
                if (nextIndex < GamesView.CollectionView.Count)
                {
                    SelectedGame = GamesView.CollectionView.GetItemAt(nextIndex) as GamesCollectionViewEntry;
                }
            }, (a) => Database?.IsOpen == true);

            FileDroppedCommand = new RelayCommand <DragEventArgs>((args) =>
            {
                OnFileDropped(args);
            });

            OpenMainMenuCommand          = new RelayCommand <object>((_) => OpenMainMenu());
            OpenNotificationsMenuCommand = new RelayCommand <object>((_) => OpenNotificationsMenu());

            CloseGameStatusCommand = new RelayCommand <object>((_) =>
            {
                GameStatusVisible = false;
                GameListFocused   = true;
            });

            SwitchToDesktopCommand = new RelayCommand(() => SwitchToDesktopMode());
        }