Skip to content

Commit

Permalink
Fix crash issue with selecting rows down and then up
Browse files Browse the repository at this point in the history
Fix moving rows when selecting up
Restore bits per sample combocox
Make tab press when phrase is being edited respect the copy folder setting
  • Loading branch information
CaffeineAU committed Aug 23, 2016
1 parent 650feed commit 3c4036a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
9 changes: 5 additions & 4 deletions Translator/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@
<CheckBox Margin="5" Content="Remember language settings" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=RememberLanguageSettings}"/>
<StackPanel Orientation="Horizontal">
<CheckBox Margin="5" Content="Encode MP3 to WAV" VerticalContentAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=EncodeToWav}"/>
<Label Margin="5" Content="Sample Rate"/>
<ComboBox Margin="5" ItemsSource="{Binding SampleRates}" SelectedItem="{Binding Source={x:Static properties:Settings.Default}, Path=WavSampleRate}" SelectionChanged="ComboBox_SelectionChanged"/>
<Label Margin="5" Content="Bits per sample"/>
<Label Margin="20,5,0,5" Content="Sample Rate"/>
<ComboBox Margin="0,5" ItemsSource="{Binding SampleRates}" VerticalContentAlignment="Center" SelectedItem="{Binding Source={x:Static properties:Settings.Default}, Path=WavSampleRate}" SelectionChanged="ComboBox_SelectionChanged"/>
<Label Margin="0,5" Content="Hz Bits per sample"/>
<ComboBox Margin="0,5" ItemsSource="{Binding BitsPerSamples}" VerticalContentAlignment="Center" SelectedItem="{Binding Source={x:Static properties:Settings.Default}, Path=WavBitsPerSample}" SelectionChanged="ComboBox_SelectionChanged"/>
</StackPanel>
</StackPanel>
</GroupBox>
<GroupBox Margin="5,0" Padding="10" Header="TTS specific options" BorderBrush="#FF4692D1" >
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Margin="0,5,5,5" Content="Ivona Region" HorizontalContentAlignment="Left" Width="120"/>
<ComboBox Margin="5" ItemsSource="{Binding IvonaRegions}" SelectedItem="{Binding Source={x:Static properties:Settings.Default}, Path=IvonaRegion}"/>
<ComboBox Margin="5" ItemsSource="{Binding IvonaRegions}" VerticalContentAlignment="Center" SelectedItem="{Binding Source={x:Static properties:Settings.Default}, Path=IvonaRegion}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Margin="0,5,5,5" Content="Bing Header String" HorizontalContentAlignment="Left" Width="120"/>
Expand Down
50 changes: 31 additions & 19 deletions Translator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,16 @@ private void MoveRowsUpCommand_CanExecute(object sender, CanExecuteRoutedEventAr

private void MoveRowsUpCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
foreach (PhraseItem item in WordsListView.SelectedItems)
List<int> indices = new List<int>();
foreach (var item in WordsListView.SelectedItems)
{
if (PhraseItems.IndexOf(item) > 0)
{
PhraseItems.Move(PhraseItems.IndexOf(item), PhraseItems.IndexOf(item) - 1);
indices.Add(PhraseItems.IndexOf(item as PhraseItem));
}
indices.Sort();
foreach (int index in indices)
{
PhraseItems.Move(index, index - 1);
NeedToSave = true;
}
}
}

Expand All @@ -736,15 +739,17 @@ private void MoveRowsDownCommand_CanExecute(object sender, CanExecuteRoutedEvent

private void MoveRowsDownCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
for (int i = WordsListView.SelectedItems.Count-1; i >= 0; i--)
List<int> indices = new List<int>();
foreach (var item in WordsListView.SelectedItems)
{
if (PhraseItems.IndexOf(WordsListView.SelectedItems[i] as PhraseItem) < PhraseItems.Count - 1)
{
Logger.Log(String.Format("Moving {0} to {1}", PhraseItems.IndexOf(WordsListView.SelectedItems[i] as PhraseItem), PhraseItems.IndexOf(WordsListView.SelectedItems[i] as PhraseItem) + 1));
PhraseItems.Move(PhraseItems.IndexOf(WordsListView.SelectedItems[i] as PhraseItem), PhraseItems.IndexOf(WordsListView.SelectedItems[i] as PhraseItem) + 1);
NeedToSave = true;

}
indices.Add(PhraseItems.IndexOf(item as PhraseItem));
}
indices.Sort();
indices.Reverse();
foreach (int index in indices)
{
PhraseItems.Move(index, index + 1);
NeedToSave = true;
}
}

Expand Down Expand Up @@ -810,11 +815,15 @@ private void WordsListView_PreviewKeyDown(object sender, KeyEventArgs e)
DataGridCell cell = dep as DataGridCell;
cell.IsSelected = false;
DependencyObject nextRowCell;
nextRowCell = cell.PredictFocus(FocusNavigationDirection.Right);

if (nextRowCell == null || (!(nextRowCell is Button)&&(nextRowCell as DataGridCell).Column.Header.ToString() == "Play"))
if (cell.Column.Header.ToString() == "Play" || cell.Column.Header.ToString() == "Phrase to Speak")
{
nextRowCell = cell.PredictFocus(FocusNavigationDirection.Left);

//}
nextRowCell = cell.PredictFocus(FocusNavigationDirection.Left);

//if (nextRowCell == null || (!(nextRowCell is Button)&&(nextRowCell as DataGridCell).Column.Header.ToString() == "Play"))
//{
// nextRowCell = cell.PredictFocus(FocusNavigationDirection.Left);

while ((nextRowCell as DataGridCell).PredictFocus(FocusNavigationDirection.Left) != null)
{
Expand All @@ -837,7 +846,10 @@ private void WordsListView_PreviewKeyDown(object sender, KeyEventArgs e)
SelectedRowCount = WordsListView.SelectedItems.Count;
if (Properties.Settings.Default.CopyFolderWhenSelectingEmptyRow && String.IsNullOrEmpty(((nextRow as DataGridRow).Item as PhraseItem).Folder))
{
nextRowCell = (nextRowCell as DataGridCell).PredictFocus(FocusNavigationDirection.Right);
if (cell.Column.Header.ToString() != "Play")
{
nextRowCell = (nextRowCell as DataGridCell).PredictFocus(FocusNavigationDirection.Right);
}
int rowselected = PhraseItems.IndexOf(((nextRow as DataGridRow).Item as PhraseItem) as PhraseItem);
while (String.IsNullOrEmpty(PhraseItems[rowselected].Folder) && rowselected >= 0) { rowselected--; } // traverse upwards
if (rowselected >= 0)
Expand Down Expand Up @@ -881,7 +893,7 @@ private void VolumeSlider_ValueChanged(object sender, RoutedPropertyChangedEvent
private void WordsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedRowCount = WordsListView.SelectedItems.Count;
if (SelectedRowCount == 1 && Properties.Settings.Default.CopyFolderWhenSelectingEmptyRow && String.IsNullOrEmpty((e.AddedItems[0] as PhraseItem).Folder))
if (SelectedRowCount == 1 && e.AddedItems.Count > 0 && Properties.Settings.Default.CopyFolderWhenSelectingEmptyRow && String.IsNullOrEmpty((e.AddedItems[0] as PhraseItem).Folder))
{
int rowselected = PhraseItems.IndexOf(e.AddedItems[0] as PhraseItem);
while (String.IsNullOrEmpty(PhraseItems[rowselected].Folder) && rowselected >=0){ rowselected--; } // traverse upwards
Expand Down
4 changes: 2 additions & 2 deletions Translator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.1")]
[assembly: AssemblyFileVersion("2.2.0.1")]
[assembly: AssemblyVersion("2.2.0.2")]
[assembly: AssemblyFileVersion("2.2.0.2")]

0 comments on commit 3c4036a

Please sign in to comment.