private void MenuCommandExecute(MenuItem menuItem)
        {
            var tag = menuItem?.Tag as string;
            if (string.IsNullOrEmpty(tag))
                return;

            var translationItem = menuItem.DataContext as TranslationItem;
            if (translationItem == null)
                return;

            var textWithOverflow = translationItem.TextWithOverflow;
            switch (tag.ToLower())
            {
                case "replace":
                    if(!string.IsNullOrEmpty(textWithOverflow))
                        ReplaceSnapshotSpanText(textWithOverflow);
                    break;
                case "copy":
                    Clipboard.SetText(textWithOverflow);
                    break;
                case "edit":
                    Visibility = Visibility.Hidden;
                    var editTranslationDialog = new EditTranslationDialog(translationItem,
                        item =>
                        {
                            if (item != null)
                            {
                                ReplaceSnapshotSpanText(item.Text);
                                TranslationCache.AddUserEditedItem(item.TranslationSource, item.RequestSourceLanguage,
                                    item.DestinationLanguage, item.OriginalText, item.Text);
                            }

                        }, this);
                    editTranslationDialog.ShowModal();
                    Visibility = Visibility.Visible;
                    break;
                case "copyall":
                    var s1 = spListBox.Items.Cast<object>()
                        .Aggregate("", (current, item) => current + (item + Environment.NewLine));
                    Clipboard.SetText(s1);
                    break;
                case "removeedit":
                    var removed = TranslationCache.RemoveUserEditedItem(translationItem.TranslationSource, translationItem.RequestSourceLanguage,
                                    translationItem.DestinationLanguage, translationItem.OriginalText, translationItem.Text);
                    if (removed)
                    {
                        _resultsCollection.Remove(translationItem);
                        MoveCurrentItem(true);
                    }
                    break;
            }
        }
Exemplo n.º 2
0
        private void MenuCommandExecute(MenuItem menuItem)
        {
            var tag = menuItem?.Tag as string;

            if (string.IsNullOrEmpty(tag))
            {
                return;
            }

            var translationItem = menuItem.DataContext as TranslationItem;

            if (translationItem == null)
            {
                return;
            }

            var textWithOverflow = translationItem.TextWithOverflow;

            switch (tag.ToLower())
            {
            case "replace":
                if (!string.IsNullOrEmpty(textWithOverflow))
                {
                    ReplaceSnapshotSpanText(textWithOverflow);
                }
                break;

            case "copy":
                Clipboard.SetText(textWithOverflow);
                break;

            case "edit":
                Visibility = Visibility.Hidden;
                var editTranslationDialog = new EditTranslationDialog(translationItem,
                                                                      item =>
                {
                    if (item != null)
                    {
                        ReplaceSnapshotSpanText(item.Text);
                        TranslationCache.AddUserEditedItem(item.TranslationSource, item.RequestSourceLanguage,
                                                           item.DestinationLanguage, item.OriginalText, item.Text);
                    }
                }, this);
                editTranslationDialog.ShowModal();
                Visibility = Visibility.Visible;
                break;

            case "copyall":
                var s1 = spListBox.Items.Cast <object>()
                         .Aggregate("", (current, item) => current + (item + Environment.NewLine));
                Clipboard.SetText(s1);
                break;

            case "removeedit":
                var removed = TranslationCache.RemoveUserEditedItem(translationItem.TranslationSource, translationItem.RequestSourceLanguage,
                                                                    translationItem.DestinationLanguage, translationItem.OriginalText, translationItem.Text);
                if (removed)
                {
                    _resultsCollection.Remove(translationItem);
                    MoveCurrentItem(true);
                }
                break;
            }
        }