@@ -92,6 +92,7 @@ internal class App : Application {
92
92
93
93
public static readonly RoutedUICommand OpenFileCommand = new RoutedUICommand ( "Open File..." , "OpenFileCommand" ,
94
94
typeof ( App ) ) ;
95
+ public static readonly RoutedUICommand SaveSvgCommand = new RoutedUICommand ( "Save SVG" , "SaveSvgCommand" , typeof ( App ) ) ;
95
96
96
97
97
98
public static readonly RoutedUICommand CancelLayoutCommand = new RoutedUICommand ( "Cancel Layout..." , "CancelLayoutCommand" ,
@@ -605,6 +606,8 @@ void UpdateThumbOnDrag(Slider slider, double del, Thumb draggedThumb) {
605
606
606
607
607
608
void SetCommands ( ) {
609
+ appWindow . CommandBindings . Add ( new CommandBinding ( SaveSvgCommand , SaveSvg ) ) ;
610
+
608
611
appWindow . CommandBindings . Add ( new CommandBinding ( SaveImageCommand , SaveImage ) ) ;
609
612
appWindow . CommandBindings . Add ( new CommandBinding ( SaveMsaglCommand , SaveMsagl ) ) ;
610
613
appWindow . CommandBindings . Add ( new CommandBinding ( ExitCommand , ExitHandler ) ) ;
@@ -629,6 +632,29 @@ void SetCommands() {
629
632
630
633
}
631
634
635
+ private void SaveSvg ( object sender , ExecutedRoutedEventArgs e ) {
636
+ if ( graphViewer . Graph == null ) {
637
+ MessageBox . Show ( "Graph is not loaded" , "No Graph" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
638
+ return ;
639
+ }
640
+ Microsoft . Win32 . SaveFileDialog dlg = new Microsoft . Win32 . SaveFileDialog ( ) ;
641
+ dlg . FileName = lastFileName + ".svg" ; // Default file name
642
+ dlg . DefaultExt = ".svg " ; // Default file extension
643
+ dlg . Filter = "svg files (.svg )|*.svg " ; // Filter files by extension
644
+
645
+ Nullable < bool > result = dlg . ShowDialog ( ) ;
646
+
647
+ if ( result != true ) {
648
+ return ;
649
+ }
650
+
651
+ using ( StreamWriter writer = new StreamWriter ( dlg . FileName ) ) {
652
+ var svgWriter = new SvgGraphWriter ( writer . BaseStream , graphViewer . Graph ) ;
653
+ svgWriter . Write ( ) ;
654
+ }
655
+
656
+ }
657
+
632
658
void SaveImage ( object sender , ExecutedRoutedEventArgs e )
633
659
{
634
660
Microsoft . Win32 . SaveFileDialog dlg = new Microsoft . Win32 . SaveFileDialog ( ) ;
@@ -641,6 +667,7 @@ void SaveImage(object sender, ExecutedRoutedEventArgs e)
641
667
if ( result == true )
642
668
{
643
669
graphViewer . DrawImage ( dlg . FileName ) ;
670
+
644
671
}
645
672
}
646
673
@@ -693,7 +720,9 @@ void SetViewMenu(Menu mainMenu) {
693
720
void SetFileMenu ( Menu mainMenu ) {
694
721
var fileMenu = new MenuItem { Header = "_File" } ;
695
722
var openFileMenuItem = new MenuItem { Header = "_Open" , Command = OpenFileCommand } ;
696
- fileMenu . Items . Add ( openFileMenuItem ) ;
723
+ fileMenu . Items . Add ( openFileMenuItem ) ;
724
+ fileMenu . Items . Add ( new MenuItem { Header = "Save _SVG" , Command = SaveSvgCommand } ) ;
725
+
697
726
var reloadFileMenuItem = new MenuItem { Header = "_Reload" , Command = ReloadCommand } ;
698
727
fileMenu . Items . Add ( reloadFileMenuItem ) ;
699
728
@@ -702,7 +731,7 @@ void SetFileMenu(Menu mainMenu) {
702
731
mainMenu . Items . Add ( fileMenu ) ;
703
732
toolBar . Items . Add ( mainMenu ) ;
704
733
705
- var saveImageMenuItem = new MenuItem { Header = "_Save Image " , Command = SaveImageCommand } ;
734
+ var saveImageMenuItem = new MenuItem { Header = "Save _Image " , Command = SaveImageCommand } ;
706
735
fileMenu . Items . Add ( saveImageMenuItem ) ;
707
736
708
737
var saveMsaglMenuItem = new MenuItem { Header = "_Save MSAGL" , Command = SaveMsaglCommand } ;
0 commit comments