Esempio n. 1
0
        private async void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            var key = e.Key == Key.System ? e.SystemKey : e.Key;

            ApplyKeyboardModifiers();

            if (!tasklist.SearchBox.TextBox.IsFocused)
            {
                if (AP.IsMouseOver && !AP.IsKeyboardFocusWithin)
                {
                    e.Handled = true;
                    switch (key)
                    {
                    case Key.Space:
                        if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            tasklist.FILEList.ScrollIntoView(AP.CurrentPlaying);
                        }
                        else
                        {
                            if (AP.Player.State == MediaStates.Stopped || AP.Player.State == MediaStates.NothingSpecial)
                            {
                                await PlayFile(tasklist.FILEList.SelectedItem as Fichier, null);
                            }
                            else
                            {
                                await AP.PlayPause();
                            }
                        }
                        break;

                    case Key.S:
                        if (Keyboard.Modifiers == ModifierKeys.Shift)
                        {
                            await VGMStream.DeleteTempFilesIfNotUsed();

                            GC.Collect();
                        }
                        else
                        {
                            await CancelAndStop();
                        }
                        break;

                    case Key.PageDown:
                        await NextWithRandom();

                        break;

                    case Key.PageUp:
                        await PreviousWithRandom();

                        break;

                    case Key.Insert:
                        tasklist.OpenFileDialog((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control, (Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt);
                        break;

                    case Key.Delete:
                        switch (Keyboard.Modifiers)
                        {
                        case ModifierKeys.Control:
                            tasklist.RemoveInvalidItems();
                            break;

                        case ModifierKeys.Shift:
                            tasklist.RemoveAll();
                            break;

                        case ModifierKeys.Alt:
                            tasklist.RemoveDFiles();
                            break;

                        case ModifierKeys.Control | ModifierKeys.Alt:
                            tasklist.RemoveSNFiles();
                            break;

                        default:
                            tasklist.RemoveSelectedItems();
                            break;
                        }
                        break;

                    case Key.Left:
                        await AP.PositionMinus();

                        break;

                    case Key.Right:
                        await AP.PositionPlus();

                        break;

                    default:
                        goto NoMouseOver;
                    }
                }
                if (tasklist.IsMouseOver && !tasklist.IsKeyboardFocusWithin)
                {
                    switch (key)
                    {
                    case Key.F:
                        if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            e.Handled = true;
                            if (tasklist.SearchBox.Visibility == Visibility.Visible)
                            {
                                tasklist.SearchBox.TextBox.Focus();
                            }
                            else
                            {
                                tasklist.SearchBox.Visibility = Visibility.Visible;
                            }
                        }
                        break;

                    case Key.C:
                        if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            tasklist.CopySelectedFiles();
                        }
                        break;

                    case Key.X:
                        if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            tasklist.CutSelectedFiles();
                        }
                        break;

                    case Key.V:
                        if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            tasklist.PasteFiles();
                        }
                        break;
                    }

                    if (!tasklist.IsKeyboardFocusWithin)
                    {
                        tasklist.FILEList_PreviewKeyDown(sender, e);
                    }
                }
                if (tasklist.IsMouseOver && !AP.IsKeyboardFocusWithin)
                {
                    switch (key)
                    {
                    case Key.Space:
                        e.Handled = true;
                        if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            tasklist.FILEList.ScrollIntoView(AP.CurrentPlaying);
                        }
                        else
                        {
                            if (AP.Player.State == MediaStates.Stopped || AP.Player.State == MediaStates.NothingSpecial)
                            {
                                await PlayFile(tasklist.FILEList.SelectedItem as Fichier, null);
                            }
                            else
                            {
                                await AP.PlayPause();
                            }
                        }
                        break;

                    case Key.S:
                        if (Keyboard.Modifiers == ModifierKeys.Shift)
                        {
                            await VGMStream.DeleteTempFilesIfNotUsed();

                            GC.Collect();
                        }
                        else
                        {
                            await CancelAndStop();
                        }
                        break;

                    case Key.PageDown:
                        e.Handled = true;
                        await NextWithRandom();

                        break;

                    case Key.PageUp:
                        e.Handled = true;
                        await PreviousWithRandom();

                        break;
                    }
                }
            }

NoMouseOver:
            switch (key)
            {
            case Key.Play:
                if (AP.Player.State == MediaStates.Stopped || AP.Player.State == MediaStates.NothingSpecial)
                {
                    await PlayFile(tasklist.FILEList.SelectedItem as Fichier, null);
                }
                else
                {
                    await AP.Play();
                }
                break;

            case Key.Pause:
                await AP.Pause();

                break;

            case Key.MediaPlayPause:
                if (AP.Player.State == MediaStates.Stopped || AP.Player.State == MediaStates.NothingSpecial)
                {
                    await PlayFile(tasklist.FILEList.SelectedItem as Fichier, null);
                }
                else
                {
                    await AP.PlayPause();
                }
                break;

            case Key.MediaStop:
                await CancelAndStop();

                break;

            case Key.MediaNextTrack:
                await NextWithRandom();

                break;

            case Key.MediaPreviousTrack:
                await PreviousWithRandom();

                break;

            case Key.B:
                if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
                {
                    e.Handled         = true;
                    StatusBar.Display = !StatusBar.Display;
                    Settings.SettingsData["StatusBar"]["Display"] = StatusBar.Display.ToString();
                }
                break;

            case Key.P:
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    OpenSettingsWindow();
                }
                break;

            case Key.O:
                switch (Keyboard.Modifiers)
                {
                case ModifierKeys.Control | ModifierKeys.Shift:
                    tasklist.OpenFileDialog(true, false);
                    break;

                case ModifierKeys.Control:
                    tasklist.OpenFileDialog(false, false);
                    break;

                case ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift:
                    tasklist.OpenFileDialog(true, true);
                    break;

                case ModifierKeys.Control | ModifierKeys.Alt:
                    tasklist.OpenFileDialog(false, true);
                    break;
                }
                break;

            case Key.D:
                switch (Keyboard.Modifiers)
                {
                case ModifierKeys.Control | ModifierKeys.Alt:
                    if (await VGMStream.DownloadVLC())
                    {
                        MessageBox.Show(App.Str("WW_VLCDownloaded"), string.Empty, MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    break;

                case ModifierKeys.Control:
                    await VGMStream.DownloadVGMStream();

                    break;
                }
                break;

            case Key.F5:
                StartButton_Click(StartButton, new RoutedEventArgs());
                break;

#if DEBUG
            case Key.X:
                if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Alt))
                {
                    /*switch (App.CurrentCulture.ToString())
                     * {
                     *  case "fr-FR":
                     *      App.SetLanguage("en-US");
                     *      break;
                     *  case "en-US":
                     *      App.SetLanguage("fr-FR");
                     *      break;
                     * }*/
                }
                break;
#endif
            }
        }