public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { IList selectedItems = (IList)values[0]; int selectedCount = (int)values[1]; int itemsCount = (int)values[2]; if (itemsCount == 0) { return(new DetailsMessageViewModel(Tx.T("msg.nothing available"), Tx.T("msg.nothing available.desc"), "ArrowUp")); } if (selectedItems.Count == 0) { return(new DetailsMessageViewModel(Tx.T("msg.nothing selected"), Tx.T("msg.nothing selected.desc"), "ArrowLeft")); } if (selectedItems.Count == 1) { TextKeyViewModel tkVM = selectedItems[0] as TextKeyViewModel; if (tkVM != null && !tkVM.IsFullKey) { return(new DetailsMessageViewModel(Tx.T("msg.incomplete key selected"), Tx.T("msg.incomplete key selected.desc"), "ArrowLeft")); } return(selectedItems[0]); } Type firstType = null; foreach (object item in selectedItems) { if (firstType == null) { firstType = item.GetType(); } else if (item.GetType() != firstType) { return(new DetailsMessageViewModel("Inconsistent selection", "Multiple items of different types are selected. Only elements of the same type can be displayed and edited concurrently.", "Flash")); } } if (firstType == typeof(TextKeyViewModel)) { return(new DetailsMessageViewModel(selectedItems.Count + " text key nodes selected")); //TextKeyViewModel[] nodes = new TextKeyViewModel[items.Count]; //for (int i = 0; i < items.Count; i++) //{ // nodes[i] = (TextKeyViewModel) items[i]; //} //return new TextKeyMultiViewModel(nodes); } return(new DetailsMessageViewModel(selectedItems.Count + " " + firstType.Name + " items selected")); }
private void OKButton_Click(object sender, RoutedEventArgs args) { string errorMessage; if (!TextKeyViewModel.ValidateName(TextKey, out errorMessage)) { App.WarningMessage(Tx.T("msg.invalid text key entered", "msg", errorMessage)); return; } DialogResult = true; Close(); }
private void ScanAllTexts(TextKeyViewModel tk) { int maxDistance = (int)Math.Round((float)TranslationText.Text.Length / 2, MidpointRounding.AwayFromZero); if (tk.IsFullKey && tk.CultureTextVMs[0].Text == TranslationText.Text) { suggestions.Add(new SuggestionViewModel(null) { TextKey = tk.TextKey, BaseText = tk.CultureTextVMs[0].Text, ScoreNum = 1000, IsExactMatch = true }); } else if (tk.IsFullKey && !String.IsNullOrEmpty(tk.CultureTextVMs[0].Text)) { // TODO: Maybe we should split both strings in words and compare them separately, only accepting if at least one word has a small distance int distance = ComputeEditDistance(TranslationText.Text, tk.CultureTextVMs[0].Text); if (distance <= maxDistance) { float score; if (distance == 0) { score = 1000; } else { score = 100f / distance; } suggestions.Add(new SuggestionViewModel(null) { TextKey = tk.TextKey, BaseText = tk.CultureTextVMs[0].Text, ScoreNum = score }); } } foreach (TextKeyViewModel child in tk.Children) { ScanAllTexts(child); } }
private void OKButton_Click(object sender, RoutedEventArgs args) { // Unfocus parameter name TextBox to have its changes updated OKButton.Focus(); string textKey = TextKeyText.Text != null?TextKeyText.Text.Trim() : ""; // Validate the entered text key string errorMessage; if (!TextKeyViewModel.ValidateName(textKey, out errorMessage)) { App.WarningMessage(Tx.T("msg.invalid text key entered", "msg", errorMessage)); TextKeyText.Focus(); return; } string colonSuffix = null; string translationString = TranslationText.Text; if (SourceCSharpButton.IsChecked == true && AddColonCheckbox.IsChecked == true) { var match = Regex.Match(parsedText, @"^(.+?)\s*:(\s*)$"); if (match.Success) { translationString = match.Groups[1].Value; colonSuffix = match.Groups[2].Value; } } // Check if the text key already exists but the translated text is different TextKeyViewModel existingTextKeyVM; if (MainViewModel.Instance.TextKeys.TryGetValue(textKey, out existingTextKeyVM)) { if (translationString != existingTextKeyVM.CultureTextVMs[0].Text) { TaskDialogResult result = TaskDialog.Show( owner: this, allowDialogCancellation: true, title: "TxEditor", mainInstruction: Tx.T("window.wizard.text key exists", "key", Tx.Q(textKey)), content: Tx.T("window.wizard.text key exists.content"), customButtons: new string[] { Tx.T("task dialog.button.overwrite"), Tx.T("task dialog.button.cancel") }); if (result.CustomButtonResult != 0) { TextKeyText.Focus(); return; } } } // Backup current clipboard content ClipboardBackup = ClipboardHelper.GetDataObject(); // Build the text to paste back into the source document, depending on the selected code // language if (SourceCSharpButton.IsChecked == true && SourceHtmlButton.IsChecked != true) { App.Settings.Wizard.SourceCode = "C#"; string keyString = textKey.Replace("\\", "\\\\").Replace("\"", "\\\""); StringBuilder codeSb = new StringBuilder(); if (isPartialString) { codeSb.Append("\" + "); } codeSb.Append("Tx.T"); if (AddColonCheckbox.IsChecked == true) { codeSb.Append("C"); } codeSb.Append("(\"" + keyString + "\""); var countPlaceholder = placeholders.FirstOrDefault(p => p.Name == "#"); if (countPlaceholder != null) { codeSb.Append(", "); codeSb.Append(countPlaceholder.Code); } foreach (var pd in placeholders) { if (pd == countPlaceholder) { continue; // Already processed } if (string.IsNullOrWhiteSpace(pd.Name)) { continue; // Not used anymore } codeSb.Append(", \"" + pd.Name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""); codeSb.Append(", "); if (pd.IsQuoted) { codeSb.Append("Tx.Q("); } codeSb.Append(pd.Code); if (pd.IsQuoted) { codeSb.Append(")"); } } codeSb.Append(")"); if (isPartialString) { codeSb.Append(" + \""); if (!string.IsNullOrEmpty(colonSuffix)) { codeSb.Append(colonSuffix); } } else if (!string.IsNullOrEmpty(colonSuffix)) { codeSb.Append(" + \""); codeSb.Append(colonSuffix); codeSb.Append("\""); } Clipboard.SetText(codeSb.ToString()); } if (SourceHtmlButton.IsChecked == true && SourceCSharpButton.IsChecked == true) { App.Settings.Wizard.SourceCode = "cshtml"; string keyString = textKey.Replace("\\", "\\\\").Replace("\"", "\\\""); StringBuilder codeSb = new StringBuilder(); codeSb.Append("@Tx.T"); if (AddColonCheckbox.IsChecked == true) { codeSb.Append("C"); } codeSb.Append("(\"" + keyString + "\")"); if (!string.IsNullOrEmpty(colonSuffix)) { codeSb.Append(colonSuffix); } Clipboard.SetText(codeSb.ToString()); } if (SourceXamlButton.IsChecked == true) { App.Settings.Wizard.SourceCode = "XAML"; string keyString = textKey.Replace("\\", "\\\\").Replace("'", "\\'"); string defaultString = translationString.Replace("\\", "\\\\").Replace("'", "\\'"); string code = "{Tx:T '" + keyString + "'"; if (SetDefaultCheckbox.IsChecked == true) { code += ", Default='" + defaultString + "'"; } code += "}"; Clipboard.SetText(code); } if (SourceAspxButton.IsChecked == true) { App.Settings.Wizard.SourceCode = "aspx"; string keyString = textKey.Replace("\\", "\\\\").Replace("\"", "\\\""); StringBuilder codeSb = new StringBuilder(); codeSb.Append("<%= Tx.T(\"" + keyString + "\") %>"); Clipboard.SetText(codeSb.ToString()); } // Remember the text key for next time and close the wizard dialog window prevTextKey = textKey; TranslationText.Text = translationString; DialogResult = true; Close(); }