Ejemplo n.º 1
0
        private async void ImportFromClipboard()
        {
            if (_clipboardImportingInProgress)
            {
                return;
            }
            _clipboardImportingInProgress = true;
            var deck = await ClipboardImporter.Import();

            if (deck == null)
            {
                const string dialogTitle = "MainWindow_Import_Dialog_NoDeckFound_Title";
                const string dialogText  = "MainWindow_Import_Dialog_NoDeckFound_Text";
                this.ShowMessage(LocUtil.Get(dialogTitle), LocUtil.Get(dialogText)).Forget();
                _clipboardImportingInProgress = false;
                return;
            }
            var choice = Config.Instance.PasteImportingChoice == ImportingChoice.Manual
                                ? await this.ShowImportingChoiceDialog() : Config.Instance.PasteImportingChoice;

            if (choice.HasValue)
            {
                if (choice.Value == ImportingChoice.SaveLocal)
                {
                    SaveImportedDeck(deck);
                }
                else
                {
                    ExportDeck(deck);
                }
            }
            _clipboardImportingInProgress = false;
        }
        private async void MainWindow_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.V && Keyboard.Modifiers == ModifierKeys.Control)
            {
                if (FlyoutDeckEditor.IsOpen)
                {
                    var deck = await ClipboardImporter.Import();

                    if (deck != null)
                    {
                        var currentDeck = DeckEditorFlyout.CurrentDeck;
                        if (currentDeck != null && deck.Class == currentDeck.Class)
                        {
                            if (string.IsNullOrEmpty(currentDeck.Name))
                            {
                                DeckEditorFlyout.SetDeckName(deck.Name);
                            }
                            DeckEditorFlyout.SetCards(deck.Cards);
                        }
                        e.Handled = true;
                    }
                }
                else
                {
                    if (Keyboard.FocusedElement is TextBox)
                    {
                        return;
                    }
                    ImportFromClipboard();
                }
            }
        }
        internal async void ImportFromClipboard()
        {
            if (_clipboardImportingInProgress)
            {
                return;
            }
            _clipboardImportingInProgress = true;
            var deck = await ClipboardImporter.Import();

            if (deck == null)
            {
                const string dialogTitle = "MainWindow_Import_Dialog_NoDeckFound_Title";
                const string dialogText  = "MainWindow_Import_Dialog_NoDeckFound_Text";
                MessageDialogs.ShowMessage(this, LocUtil.Get(dialogTitle), LocUtil.Get(dialogText)).Forget();
                _clipboardImportingInProgress = false;
                return;
            }
            await ShowImportingChoice(deck);

            _clipboardImportingInProgress = false;
        }