Skip to content

Commit

Permalink
Add automatic fill in of folder name options
Browse files Browse the repository at this point in the history
Improved regex
Removed sorting of columns
Fixed handling of filename when Save As is selected
Correctly ientif file 'dirty' status when adding or moving lines
  • Loading branch information
CaffeineAU committed Aug 19, 2016
1 parent f354831 commit 98da9ef
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 19 deletions.
6 changes: 6 additions & 0 deletions Translator/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<setting name="LastTTSNumericSpeed" serializeAs="String">
<value>10</value>
</setting>
<setting name="CopyFolderWhenInsertingLines" serializeAs="String">
<value>True</value>
</setting>
<setting name="CopyFolderWhenSelectingEmptyRow" serializeAs="String">
<value>True</value>
</setting>
</TTSAutomate.Properties.Settings>
<TTSTranslate.Properties.Settings>
<setting name="LastPhraseFile" serializeAs="String">
Expand Down
2 changes: 2 additions & 0 deletions Translator/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<StackPanel>
<CheckBox Margin="5" Content="Re-open last PSV file" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=ReopenLastPSVFile}"/>
<CheckBox Margin="5" Content="Set output directory to last output directory" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=SetOutputDirectory}"/>
<CheckBox Margin="5" Content="Copy previous folder when inserting rows" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=CopyFolderWhenInsertingLines}"/>
<CheckBox Margin="5" Content="Copy previous folder when selecting empty row" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=CopyFolderWhenSelectingEmptyRow}"/>
</StackPanel>
</GroupBox>
<GroupBox Margin="5" Padding="10" Header="Voice options" BorderBrush="#FF4692D1" >
Expand Down
8 changes: 4 additions & 4 deletions Translator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
</DataTemplate>
</DataGrid.RowHeaderTemplate>
<DataGrid.Columns>
<DataGridTextColumn Header="Folder" Binding="{Binding Folder}" />
<DataGridTextColumn Header="Filename" Binding="{Binding FileName}" />
<DataGridTextColumn Header="Phrase to Speak" Binding="{Binding Phrase}"/>
<DataGridTemplateColumn Header="Play">
<DataGridTextColumn Header="Folder" Binding="{Binding Folder}" CanUserSort="False" />
<DataGridTextColumn Header="Filename" Binding="{Binding FileName}" CanUserSort="False" />
<DataGridTextColumn Header="Phrase to Speak" Binding="{Binding Phrase}" CanUserSort="False"/>
<DataGridTemplateColumn Header="Play" CanUserSort="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="PlayButton_Click" CommandParameter="{Binding FullPathAndFile}" >
Expand Down
26 changes: 21 additions & 5 deletions Translator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private void WordsListView_CellEditEnding(object sender, DataGridCellEditEndingE
private void LoadPhraseFile(String filename)
{
PhraseItems.Clear();
Regex r = new Regex(@"(?<Folder>.+)\|(?<FileName>.+)\|(?<Phrase>.+)\b");
Regex r = new Regex(@"(?<Folder>.+)\|(?<FileName>.*)\|(?<Phrase>[.-[\s]]*)\s*");

List<PhraseItem> items = new List<PhraseItem>();

Expand Down Expand Up @@ -474,7 +474,7 @@ private void BrowsePhraseFileCommand_Executed(object sender, ExecutedRoutedEvent
var dlg = new System.Windows.Forms.OpenFileDialog();
if (!String.IsNullOrEmpty(Properties.Settings.Default.LastPhraseFile ))
{
dlg.InitialDirectory = Path.GetDirectoryName(Properties.Settings.Default.LastPhraseFile);
dlg.InitialDirectory = Path.GetDirectoryName(Properties.Settings.Default.LastPhraseFile);

}
dlg.FileName = Properties.Settings.Default.LastPhraseFile;
Expand Down Expand Up @@ -634,7 +634,7 @@ private Boolean SaveAs()
if (result == System.Windows.Forms.DialogResult.OK)
{
SavePhraseFile(dlg.FileName);
Properties.Settings.Default.LastPhraseFile = Path.GetDirectoryName(dlg.FileName);
Properties.Settings.Default.LastPhraseFile = dlg.FileName;
}
return result == System.Windows.Forms.DialogResult.OK;
}
Expand Down Expand Up @@ -683,7 +683,8 @@ private void InsertRowsAboveCommand_Executed(object sender, ExecutedRoutedEventA
int rowsToAdd = WordsListView.SelectedItems.Count;
for (int i = 0; i < rowsToAdd; i++)
{
PhraseItems.Insert(PhraseItems.IndexOf(WordsListView.SelectedItems[0] as PhraseItem), new PhraseItem());
PhraseItems.Insert(PhraseItems.IndexOf(WordsListView.SelectedItems[0] as PhraseItem), Properties.Settings.Default.CopyFolderWhenInsertingLines ? new PhraseItem { Folder = PhraseItems[PhraseItems.IndexOf(WordsListView.SelectedItems[0] as PhraseItem) - 1].Folder } : new PhraseItem());
NeedToSave = true;
}
}

Expand All @@ -697,7 +698,9 @@ private void InsertRowsBelowCommand_Executed(object sender, ExecutedRoutedEventA
int rowsToAdd = WordsListView.SelectedItems.Count;
for (int i = 0; i < rowsToAdd; i++)
{
PhraseItems.Insert(PhraseItems.IndexOf(WordsListView.SelectedItems[WordsListView.SelectedItems.Count - 1] as PhraseItem) + 1, new PhraseItem());
PhraseItems.Insert(PhraseItems.IndexOf(WordsListView.SelectedItems[WordsListView.SelectedItems.Count - 1] as PhraseItem) + 1, Properties.Settings.Default.CopyFolderWhenInsertingLines ? new PhraseItem { Folder = (WordsListView.SelectedItems[WordsListView.SelectedItems.Count - 1] as PhraseItem).Folder } : new PhraseItem());
NeedToSave = true;

}
}

Expand All @@ -713,6 +716,7 @@ private void MoveRowsUpCommand_Executed(object sender, ExecutedRoutedEventArgs e
if (PhraseItems.IndexOf(item) > 0)
{
PhraseItems.Move(PhraseItems.IndexOf(item), PhraseItems.IndexOf(item) - 1);
NeedToSave = true;
}
}
}
Expand All @@ -730,6 +734,8 @@ private void MoveRowsDownCommand_Executed(object sender, ExecutedRoutedEventArgs
{
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;

}
}
}
Expand Down Expand Up @@ -846,6 +852,16 @@ 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))
{
int rowselected = PhraseItems.IndexOf(e.AddedItems[0] as PhraseItem);
while (String.IsNullOrEmpty(PhraseItems[rowselected].Folder) && rowselected >=0){ rowselected--; } // traverse upwards
if (rowselected >=0)
{
(e.AddedItems[0] as PhraseItem).Folder = PhraseItems[rowselected].Folder;
NeedToSave = true;
}
}
}

private void Window_GotFocus(object sender, RoutedEventArgs e)
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.1.1.2")]
[assembly: AssemblyFileVersion("2.1.1.2")]
[assembly: AssemblyVersion("2.1.2.0")]
[assembly: AssemblyFileVersion("2.1.2.0")]
28 changes: 28 additions & 0 deletions Translator/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Translator/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@
<Setting Name="LastTTSNumericSpeed" Provider="PortableSettingsProvider" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">10</Value>
</Setting>
<Setting Name="CopyFolderWhenInsertingLines" Provider="PortableSettingsProvider" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CopyFolderWhenSelectingEmptyRow" Provider="PortableSettingsProvider" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
23 changes: 15 additions & 8 deletions Translator/TTSProvider/IvonaTTSProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@ public IvonaTTSProvider()
BackgroundWorker loadVoicesWorker = new BackgroundWorker();
loadVoicesWorker.DoWork += delegate
{
AvailableVoices = IvonaListVoices().Voices;
SelectedVoice = AvailableVoices[0];
if (Properties.Settings.Default.RememberLanguageSettings && this.Name == Properties.Settings.Default.LastTTSProvider)
try
{
SelectedVoice = AvailableVoices.Find(n => n.Name == Properties.Settings.Default.LastTTSVoice);
AvailableVoices = IvonaListVoices().Voices;
if (Properties.Settings.Default.RememberLanguageSettings && this.Name == Properties.Settings.Default.LastTTSProvider)
{
SelectedVoice = AvailableVoices.Find(n => n.Name == Properties.Settings.Default.LastTTSVoice);
}
else
{
SelectedVoice = AvailableVoices[0];
}

}
else
catch (Exception)
{
SelectedVoice = AvailableVoices[0];
}
};
//Couldn't load voices :(
//throw;
} };
loadVoicesWorker.RunWorkerAsync();

AvailableSpeeds.AddRange(new String[] { "x-slow", "slow", "medium", "fast", "x-fast" });
Expand Down

0 comments on commit 98da9ef

Please sign in to comment.