Skip to content

Commit 90f1357

Browse files
danialahmad-ucliamdanialahmadpaulirwinCopilot
committed
Add Paste button to Java Input pane (paulirwin#136) (paulirwin#139)
* GUI: Add Paste button to Java Input pane, paulirwin#136 * GUI: Fix Paste button positioning in file controls row, paulirwin#136 * Update JavaToCSharpGui/Infrastructure/TextClipboard.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Danial Ahmad <108906119+iamdanialahmad@users.noreply.github.com> Co-authored-by: Paul Irwin <paulirwin@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e6cfa05 commit 90f1357

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

JavaToCSharpGui/Infrastructure/ITextClipboard.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
/// </summary>
66
public interface ITextClipboard
77
{
8+
/// <summary>
9+
/// Gets the clipboard's text.
10+
/// </summary>
11+
/// <returns>A <c>Task</c> representing the async operation that returns the clipboard text.</returns>
12+
Task<string?> GetTextAsync();
13+
814
/// <summary>
915
/// Sets the clipboard's text.
1016
/// </summary>

JavaToCSharpGui/Infrastructure/TextClipboard.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ internal class TextClipboard : ITextClipboard
99

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

12+
/// <inheritdoc />
13+
public async Task<string?> GetTextAsync()
14+
{
15+
if (_clipboard is null)
16+
{
17+
return null;
18+
}
19+
return await _clipboard.GetTextAsync();
20+
}
21+
1222
/// <inheritdoc />
1323
public async Task SetTextAsync(string? text)
1424
{

JavaToCSharpGui/ViewModels/MainWindowViewModel.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,26 @@ private async Task OpenFileDialog()
313313
}
314314
}
315315

316+
[RelayCommand]
317+
private async Task PasteInput()
318+
{
319+
if (_clipboard is null)
320+
{
321+
return;
322+
}
323+
324+
var text = await _clipboard.GetTextAsync();
325+
if (!string.IsNullOrEmpty(text))
326+
{
327+
JavaText.Text = text;
328+
ConversionStateLabel = "Pasted Java code from clipboard!";
329+
330+
await Task.Delay(2000);
331+
332+
await _dispatcher.InvokeAsync(() => { ConversionStateLabel = ""; }, DispatcherPriority.Background);
333+
}
334+
}
335+
316336
[RelayCommand]
317337
private async Task CopyOutput()
318338
{

JavaToCSharpGui/Views/MainWindow.axaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<Grid ColumnDefinitions="*,Auto,*">
6060
<Grid RowDefinitions="Auto,Auto,*">
6161
<TextBlock Margin="10">Java Source Code Input:</TextBlock>
62-
<Grid Grid.Row="1" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
62+
<Grid Grid.Row="1" ColumnDefinitions="Auto,*,Auto,Auto" VerticalAlignment="Center">
6363
<TextBlock Margin="10,5,10,5" VerticalAlignment="Center">File:</TextBlock>
6464
<TextBox Name="OpenPath"
6565
Grid.Column="1"
@@ -73,6 +73,13 @@
7373
Name="OpenFileDialog">
7474
<i:Icon Value="fa-folder-open" />
7575
</Button>
76+
<Button Grid.Column="3" Margin="10,5,10,5"
77+
Name="PasteInput"
78+
ToolTip.Tip="Paste from Clipboard"
79+
AutomationProperties.Name="Paste from Clipboard"
80+
Command="{CompiledBinding PasteInputCommand}">
81+
<i:Icon Value="fa-paste" />
82+
</Button>
7683
</Grid>
7784
<AvaloniaEdit:TextEditor
7885
Name="JavaTextEditor"

0 commit comments

Comments
 (0)