Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
better filedialog and textbox placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
ArttuKuikka committed Dec 6, 2021
1 parent b881509 commit ac78d21
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Y2SharpWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
mc:Ignorable="d"
Title="Y2Sharp WPF" Height="400" Width="800">
<Grid Background="#FF2E2E2E">
<TextBox x:Name="URLtextbox" HorizontalAlignment="Center" Margin="0,52,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="668" Background="#FF535353" BorderBrush="#FF686868" Foreground="White" Height="25" TextChanged="URLtextbox_TextChanged"/>
<TextBox x:Name="URLtextbox" HorizontalAlignment="Center" Margin="0,67,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="668" Background="#FF535353" BorderBrush="#FF686868" Foreground="White" Height="25" TextChanged="URLtextbox_TextChanged" GotFocus="URLtextbox_GotFocus" LostFocus="URLtextbox_LostFocus" FontSize="14" Text="Youtube URL..."/>
<Button x:Name="DownloadButton" Content="Download" Margin="254,283,254,16" Background="#FF535353" BorderBrush="#FF686868" FontSize="22" Click="DownloadButton_ClickAsync"/>
<ComboBox x:Name="typebox" HorizontalAlignment="Center" Margin="0,124,0,0" VerticalAlignment="Top" Width="270" Height="47" Background="#FF535353" FontSize="18" SelectionChanged="typebox_SelectionChanged"/>
<TextBlock HorizontalAlignment="Center" Margin="0,5,0,0" Text="Youtube URL:" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="Black" Height="47" Width="232" FontSize="34" TextAlignment="Center"/>
<TextBlock HorizontalAlignment="Center" Margin="0,5,0,0" Text="Y2SharpWPF" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" Height="47" Width="232" FontSize="38" TextAlignment="Center"/>
<ComboBox x:Name="qualitybox" HorizontalAlignment="Center" Margin="0,203,0,0" VerticalAlignment="Top" Width="270" Height="47" Background="#FF535353"/>

</Grid>
</Window>
44 changes: 36 additions & 8 deletions Y2SharpWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,38 @@ public async Task downloadAsync()
saveFileDialog.Filter = typetext + " | *." + typebox.SelectedItem.ToString().ToLower();
saveFileDialog.DefaultExt = "." + typebox.SelectedItem.ToString().ToLower();
saveFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
saveFileDialog.ShowDialog();





try

if(saveFileDialog.ShowDialog() == true)
{
await Y2Sharp.youtube.DownloadAsync(videoid, System.IO.Path.GetFullPath(saveFileDialog.FileName).ToString(), typebox.SelectedItem.ToString().ToLower(), quality);
try
{
await Y2Sharp.youtube.DownloadAsync(videoid, System.IO.Path.GetFullPath(saveFileDialog.FileName).ToString(), typebox.SelectedItem.ToString().ToLower(), quality);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Y2Sharp WPF error message");
return;
}

MessageBox.Show("Video saved to: " + System.IO.Path.GetFullPath(saveFileDialog.FileName.ToString()), "Y2Sharp info message");
}
catch (Exception ex)
else
{
MessageBox.Show(ex.ToString(), "Y2Sharp WPF error message");

return;
}

MessageBox.Show("Video saved to: " + System.IO.Path.GetFullPath(saveFileDialog.FileName.ToString()), "Y2Sharp info message");

}

private async void URLtextbox_TextChanged(object sender, TextChangedEventArgs e)
{
if(URLtextbox.Text == "Youtube URL...") { return; }
if(URLtextbox.Text == string.Empty) { return; }

string videourl = URLtextbox.Text;
videoid = videourl.Remove(0, 32);
videoid = videoid.Remove(11, videoid.Length - 11);
Expand All @@ -138,6 +149,23 @@ private async void URLtextbox_TextChanged(object sender, TextChangedEventArgs e)
{
qualitybox.Items.Add(res);
}

}
}

private void URLtextbox_GotFocus(object sender, RoutedEventArgs e)
{
if(URLtextbox.Text == "Youtube URL...")
{
URLtextbox.Text = string.Empty;
}
}

private void URLtextbox_LostFocus(object sender, RoutedEventArgs e)
{
if(URLtextbox.Text == string.Empty)
{
URLtextbox.Text = "Youtube URL...";
}
}
}
Expand Down

0 comments on commit ac78d21

Please sign in to comment.