Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions JavaToCSharpGui/Infrastructure/ITextClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
/// </summary>
public interface ITextClipboard
{
/// <summary>
/// Gets the clipboard's text.
/// </summary>
/// <returns>A <c>Task</c> representing the async operation that returns the clipboard text.</returns>
Task<string?> GetTextAsync();

/// <summary>
/// Sets the clipboard's text.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions JavaToCSharpGui/Infrastructure/TextClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ internal class TextClipboard : ITextClipboard

public TextClipboard(IClipboard? clipboard) => _clipboard = clipboard;

/// <inheritdoc />
public async Task<string?> GetTextAsync()
{
if(_clipboard is null)
{
return null;
}
return await _clipboard.GetTextAsync();
}

/// <inheritdoc />
public async Task SetTextAsync(string? text)
{
Expand Down
20 changes: 20 additions & 0 deletions JavaToCSharpGui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ private async Task OpenFileDialog()
}
}

[RelayCommand]
private async Task PasteInput()
{
if (_clipboard is null)
{
return;
}

var text = await _clipboard.GetTextAsync();
if (!string.IsNullOrEmpty(text))
{
JavaText.Text = text;
ConversionStateLabel = "Pasted Java code from clipboard!";

await Task.Delay(2000);

await _dispatcher.InvokeAsync(() => { ConversionStateLabel = ""; }, DispatcherPriority.Background);
}
}

[RelayCommand]
private async Task CopyOutput()
{
Expand Down
9 changes: 8 additions & 1 deletion JavaToCSharpGui/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Grid ColumnDefinitions="*,Auto,*">
<Grid RowDefinitions="Auto,Auto,*">
<TextBlock Margin="10">Java Source Code Input:</TextBlock>
<Grid Grid.Row="1" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
<Grid Grid.Row="1" ColumnDefinitions="Auto,*,Auto,Auto" VerticalAlignment="Center">
<TextBlock Margin="10,5,10,5" VerticalAlignment="Center">File:</TextBlock>
<TextBox Name="OpenPath"
Grid.Column="1"
Expand All @@ -73,6 +73,13 @@
Name="OpenFileDialog">
<i:Icon Value="fa-folder-open" />
</Button>
<Button Grid.Column="3" Margin="10,5,10,5"
Name="PasteInput"
ToolTip.Tip="Paste from Clipboard"
AutomationProperties.Name="Paste from Clipboard"
Command="{CompiledBinding PasteInputCommand}">
<i:Icon Value="fa-paste" />
</Button>
</Grid>
<AvaloniaEdit:TextEditor
Name="JavaTextEditor"
Expand Down