private void Window_Loaded(object sender, RoutedEventArgs args) { // Require a primary culture for the wizard if (MainViewModel.Instance.LoadedCultureNames.Count == 0) { App.WarningMessage(Tx.T("window.wizard.no culture added")); Close(); return; } // Text input UI setup TranslationText.HiddenChars = App.Settings.View.ShowHiddenChars; TranslationText.FontSize = MainViewModel.Instance.FontSize; if (App.Settings.View.MonospaceFont) { MonospaceFontConverter monospaceFontConverter = new MonospaceFontConverter(); TranslationText.FontFamily = monospaceFontConverter.Convert(App.Settings.View.MonospaceFont, null, null, null) as FontFamily; } TextOptions.SetTextFormattingMode(TranslationText, MainViewModel.Instance.TextFormattingMode); // Read the source text from the clipboard initialClipboardText = ReadClipboard(); if (initialClipboardText == null) { // Nothing to read, close the dialog again. There's nothing we can do. Close(); return; } // Restore clipboard if (ClipboardBackup != null) { Clipboard.SetDataObject(ClipboardBackup, true); ClipboardBackup = null; } // Parse the source text and perform other keys lookup Reset(true); UpdateLayout(); if (App.Settings != null && App.Settings.Wizard.RememberLocation && App.Settings.Wizard.WindowLeft != int.MinValue && App.Settings.Wizard.WindowTop != int.MinValue) { Left = App.Settings.Wizard.WindowLeft; Top = App.Settings.Wizard.WindowTop; } else { Left = SystemParameters.WorkArea.Right - 40 - ActualWidth; Top = SystemParameters.WorkArea.Bottom - 40 - ActualHeight; } Unclassified.Util.WinApi.SetForegroundWindow(new Unclassified.UI.Wpf32Window(this).Handle); TextKeyText.Focus(); }
private void OtherKeysList_MouseDoubleClick(object sender, MouseButtonEventArgs args) { if (args.ChangedButton == MouseButton.Left) { SuggestionViewModel suggestion = OtherKeysList.SelectedItem as SuggestionViewModel; if (suggestion != null) { TextKeyText.Text = suggestion.TextKey; AutoSelectKeyText(); TextKeyText.Focus(); // TODO: Also update the translated text from suggestion.BaseText? Consider different parameter names! } } }
private void OtherKeysList_KeyDown(object sender, KeyEventArgs args) { if (args.Key == Key.Enter && args.KeyboardDevice.Modifiers == 0) { // See OtherKeysList_MouseDoubleClick! SuggestionViewModel suggestion = OtherKeysList.SelectedItem as SuggestionViewModel; if (suggestion != null) { TextKeyText.Text = suggestion.TextKey; AutoSelectKeyText(); TextKeyText.Focus(); } args.Handled = true; } }
private void Window_Loaded(object sender, RoutedEventArgs args) { //TextKeyText.SelectAll(); if (!RenameSelectMode) { Match m = Regex.Match(TextKey, @"^((?:.*?:)?(?:[^.]*\.)*)([^.]*[:.])$"); if (m.Success) { TextKeyText.SelectionStart = m.Groups[1].Length; TextKeyText.SelectionLength = m.Groups[2].Length; } } else { Match m = Regex.Match(TextKey, @"^((?:.*?:)?(?:[^.]*\.)*)([^.]*)$"); if (m.Success) { TextKeyText.SelectionStart = m.Groups[1].Length; TextKeyText.SelectionLength = m.Groups[2].Length; } } TextKeyText.Focus(); }
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(); }