@@ -269,17 +269,24 @@ private async void FormatCSharpier_Click(object sender, RoutedEventArgs e)
269269 {
270270
271271 string ? code = mainViewModel . SelectedSnippet ? . Category ? . Language ? . Code ;
272- if ( code is not null and "cs" )
272+ if ( code is not null )
273273 {
274- string originalCode = textEditor . Text ;
275- var ( isSuccess , formatted , error ) = await FormattingService . TryFormatCodeWithCSharpierAsync ( originalCode ) ;
274+ var originalCode = textEditor . Text ;
275+
276+ ( bool isSuccess , string ? formatted , string ? error ) = code switch
277+ {
278+ "cs" => await FormattingService . TryFormatCodeWithCSharpierAsync ( originalCode ) ,
279+ "xml" => await FormattingService . TryFormatXmlWithCSharpierAsync ( originalCode ) ,
280+ _ => ( false , null , $ "Formatting for '{ code } ' is not supported with CSharpier")
281+ } ;
282+
276283 if ( isSuccess )
277284 {
278- textEditor . Document . Text = formatted ;
285+ textEditor . Document . Text = formatted ! ;
279286 }
280287 else
281288 {
282- MessageBox . Show ( $ "Formatting failed: { error } ") ;
289+ MessageBox . Show ( $ "Formatting failed:\n { error } ") ;
283290 }
284291 }
285292 }
@@ -357,7 +364,7 @@ private async void FormatAll_Click(object sender, RoutedEventArgs e)
357364 }
358365 else
359366 {
360- MessageBox . Show ( errorDfmt ) ;
367+ MessageBox . Show ( $ "Formatting (dfmt) failed: \n { errorDfmt } " ) ;
361368 }
362369 break ;
363370
@@ -369,7 +376,7 @@ private async void FormatAll_Click(object sender, RoutedEventArgs e)
369376 }
370377 else
371378 {
372- MessageBox . Show ( $ "Formatting (CSharpier) failed: { errorCs } ") ;
379+ MessageBox . Show ( $ "Formatting (CSharpier) failed:\n { errorCs } ") ;
373380 }
374381 break ;
375382
@@ -381,7 +388,7 @@ private async void FormatAll_Click(object sender, RoutedEventArgs e)
381388 }
382389 else
383390 {
384- MessageBox . Show ( errorBlack ) ;
391+ MessageBox . Show ( $ "Formatting (Black) failed: \n { errorBlack } " ) ;
385392 }
386393 break ;
387394
@@ -393,8 +400,21 @@ private async void FormatAll_Click(object sender, RoutedEventArgs e)
393400 }
394401 else
395402 {
396- MessageBox . Show ( errorRust ) ;
403+ MessageBox . Show ( $ "Formatting (rustfmt) failed:\n { errorRust } ") ;
404+ }
405+ break ;
406+
407+ case "xml" :
408+ var ( successXml , formattedXml , errorXml ) = await FormattingService . TryFormatXmlWithCSharpierAsync ( originalCode ) ;
409+ if ( successXml )
410+ {
411+ textEditor . Document . Text = formattedXml ;
412+ }
413+ else
414+ {
415+ MessageBox . Show ( $ "Formatting (CSharpier XML) failed:\n { errorXml } ") ;
397416 }
417+
398418 break ;
399419
400420 default :
@@ -416,7 +436,7 @@ private async void FormatAll_Click(object sender, RoutedEventArgs e)
416436 }
417437 else
418438 {
419- MessageBox . Show ( errorClang ) ;
439+ MessageBox . Show ( $ "Formatting (clang-format) failed: \n { errorClang } " ) ;
420440 }
421441 }
422442 break ;
0 commit comments