@@ -336,6 +336,63 @@ private async Task PasteJavaCode()
336336 await _dispatcher . InvokeAsync ( ( ) => { ConversionStateLabel = "" ; } , DispatcherPriority . Background ) ;
337337 }
338338
339+ [ RelayCommand ]
340+ private async Task ClipboardConvert ( )
341+ {
342+ if ( _clipboard is null )
343+ {
344+ return ;
345+ }
346+
347+ // Get clipboard text
348+ string ? clipboardText = await _clipboard . GetTextAsync ( ) ;
349+ if ( clipboardText is null )
350+ {
351+ ShowMessage ( "Clipboard is empty or unavailable." , "Clipboard Convert Error" ) ;
352+ return ;
353+ }
354+
355+ // Set Java text
356+ JavaText . Text = clipboardText ;
357+
358+ // Perform conversion
359+ CurrentOptions . Options . WarningEncountered += Options_WarningEncountered ;
360+ CurrentOptions . Options . StateChanged += Options_StateChanged ;
361+
362+ IsConvertEnabled = false ;
363+ _usingFolderConvert = false ;
364+
365+ await Task . Run ( async ( ) =>
366+ {
367+ try
368+ {
369+ string ? csharp = JavaToCSharpConverter . ConvertText ( clipboardText , CurrentOptions . Options ) ;
370+ await DispatcherInvoke ( ( ) => CSharpText . Text = csharp ?? "" ) ;
371+
372+ // Copy result to clipboard
373+ await _clipboard . SetTextAsync ( csharp ?? "" ) ;
374+ ConversionStateLabel = "Conversion complete! C# code copied to clipboard." ;
375+
376+ await Task . Delay ( 2000 ) ;
377+ await _dispatcher . InvokeAsync ( ( ) => { ConversionStateLabel = "" ; } , DispatcherPriority . Background ) ;
378+ }
379+ catch ( Exception ex )
380+ {
381+ await DispatcherInvoke ( ( ) =>
382+ ShowMessage ( $ "There was an error converting the text to C#: { ex . GetBaseException ( ) . Message } ",
383+ "Conversion Error" ) ) ;
384+
385+ ConversionStateLabel = "" ;
386+ }
387+ finally
388+ {
389+ await DispatcherInvoke ( ( ) => IsConvertEnabled = true ) ;
390+ CurrentOptions . Options . WarningEncountered -= Options_WarningEncountered ;
391+ CurrentOptions . Options . StateChanged -= Options_StateChanged ;
392+ }
393+ } ) ;
394+ }
395+
339396 [ RelayCommand ]
340397 private async Task CopyOutput ( )
341398 {
0 commit comments