Skip to content

Commit

Permalink
Text key wizard: 'Add colon' option when one was found in the text
Browse files Browse the repository at this point in the history
  • Loading branch information
ygoe committed Jan 19, 2016
1 parent da9f9bb commit e479690
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
2 changes: 2 additions & 0 deletions TxEditor/Dictionary.txd
Expand Up @@ -506,6 +506,7 @@ Als Vorschläge werden andere Texte angezeigt, die ähnliche Wörter enthalten w
<text key="window.text key.rename.caption">Geben Sie den neuen Namen des ausgewählten Textschlüssels an:</text>
<text key="window.text key.rename.title">Textschlüssel umbenennen</text>
<text key="window.title.in path">in</text>
<text key="window.wizard.add colon">Add c_olon (TC)</text>
<text key="window.wizard.button.cancel">Abbrechen</text>
<text key="window.wizard.button.reset">Zu_rücksetzen</text>
<text key="window.wizard.button.save">Text _speichern</text>
Expand Down Expand Up @@ -1063,6 +1064,7 @@ Suggestions are other texts that contain similar words as the selected text key.
<text key="window.text key.rename.caption">Enter the new name of the selected text key:</text>
<text key="window.text key.rename.title">Rename text key</text>
<text key="window.title.in path">in</text>
<text key="window.wizard.add colon">D_oppelpunkt hinzufügen (TC)</text>
<text key="window.wizard.button.cancel">Cancel</text>
<text key="window.wizard.button.reset">_Reset</text>
<text key="window.wizard.button.save">_Save text</text>
Expand Down
12 changes: 10 additions & 2 deletions TxEditor/Views/TextKeyWizardWindow.xaml
Expand Up @@ -42,6 +42,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -140,14 +141,21 @@
IsChecked="True"
Content="{Tx:T 'window.wizard.include default text', Default='Include _default text for design time'}"/>

<CheckBox
Name="AddColonCheckbox"
Grid.Row="5" Grid.Column="1"
Margin="8,4,0,0" HorizontalAlignment="Left"
IsChecked="True"
Content="{Tx:T 'window.wizard.add colon', Default='Add colon (TC)'}"/>

<TextBlock
x:Name="ParametersLabel"
Grid.Row="5" Grid.Column="0"
Grid.Row="6" Grid.Column="0"
Margin="0,7,0,0" VerticalAlignment="Top"
Text="{Tx:TC 'window.wizard.parameters', Default='Parameters:'}"/>
<Grid
x:Name="ParametersGrid"
Grid.Row="5" Grid.Column="1"
Grid.Row="6" Grid.Column="1"
Margin="8,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down
47 changes: 44 additions & 3 deletions TxEditor/Views/TextKeyWizardWindow.xaml.cs
Expand Up @@ -219,14 +219,27 @@ private void OKButton_Click(object sender, RoutedEventArgs args)
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 (TranslationText.Text != existingTextKeyVM.CultureTextVMs[0].Text)
if (translationString != existingTextKeyVM.CultureTextVMs[0].Text)
{
TaskDialogResult result = TaskDialog.Show(
owner: this,
Expand All @@ -237,6 +250,7 @@ private void OKButton_Click(object sender, RoutedEventArgs args)
customButtons: new string[] { Tx.T("task dialog.button.overwrite"), Tx.T("task dialog.button.cancel") });
if (result.CustomButtonResult != 0)
{
TextKeyText.Focus();
return;
}
}
Expand All @@ -258,7 +272,12 @@ private void OKButton_Click(object sender, RoutedEventArgs args)
{
codeSb.Append("\" + ");
}
codeSb.Append("Tx.T(\"" + keyString + "\"");
codeSb.Append("Tx.T");
if (AddColonCheckbox.IsChecked == true)
{
codeSb.Append("C");
}
codeSb.Append("(\"" + keyString + "\"");
var countPlaceholder = placeholders.FirstOrDefault(p => p.Name == "#");
if (countPlaceholder != null)
{
Expand All @@ -284,6 +303,16 @@ private void OKButton_Click(object sender, RoutedEventArgs args)
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());
}
Expand All @@ -292,7 +321,7 @@ private void OKButton_Click(object sender, RoutedEventArgs args)
App.Settings.Wizard.SourceCode = "XAML";

string keyString = textKey.Replace("\\", "\\\\").Replace("'", "\\'");
string defaultString = TranslationText.Text.Replace("\\", "\\\\").Replace("'", "\\'");
string defaultString = translationString.Replace("\\", "\\\\").Replace("'", "\\'");

string code = "{Tx:T '" + keyString + "'";
if (SetDefaultCheckbox.IsChecked == true)
Expand All @@ -315,6 +344,7 @@ private void OKButton_Click(object sender, RoutedEventArgs args)

// Remember the text key for next time and close the wizard dialog window
prevTextKey = textKey;
TranslationText.Text = translationString;
DialogResult = true;
Close();
}
Expand Down Expand Up @@ -403,6 +433,9 @@ private void AddParsedPlaceholder(StringBuilder textContent, StringBuilder place

private void Reset(bool setTextKey)
{
AddColonCheckbox.IsChecked = false;
AddColonCheckbox.Visibility = Visibility.Collapsed;

// Detect parameters in the code
placeholders.Clear();
parsedText = "";
Expand Down Expand Up @@ -692,6 +725,14 @@ private void Reset(bool setTextKey)
AddParsedPlaceholder(textContent, placeholderContent);
}
parsedText = textContent.ToString();

// Detect trailing colon to offer the option to cut off and generate it
var match = Regex.Match(parsedText, @"^(.+)\s?:(\s*)$");
if (match.Success)
{
AddColonCheckbox.IsChecked = true;
AddColonCheckbox.Visibility = Visibility.Visible;
}
}
if (SourceXamlButton.IsChecked == true)
{
Expand Down
2 changes: 1 addition & 1 deletion _scripts/buildscript/control.ps1
Expand Up @@ -66,7 +66,7 @@ if (IsSelected transfer-web)
# Upload to NuGet
if (IsSelected transfer-nuget)
{
Push-NuGetPackage "TxLib\bin\Unclassified.TxLib" $nuGetApiKey 45
Push-NuGetPackage "TxLib\bin\Unclassified.TxLib" $nuGetApiKey 11
}

End-BuildScript

0 comments on commit e479690

Please sign in to comment.