← Back to team overview

kicad-developers team mailing list archive

[PATCH] Incorrect save-on-quit in pcbnew with unsaved board

 

In pcbnew, if you exit with a new (totally unsaved, but not empty) board open, and click 'yes' in the save-on-exit box, an error is raised due to passing an empty filename string to the save routine. Correct behavior is to execute a 'save as' if the filename is still blank.

Attached is a patch that does this.

Chris

diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h
index ecdf62f..7444f6d 100644
--- a/include/wxPcbStruct.h
+++ b/include/wxPcbStruct.h
@@ -848,6 +848,12 @@ public:
     void OnFileHistory( wxCommandEvent& event );
 
     /**
+     * Function Files_io_from_id
+     * command handler for read and write file commands; operates directly from event ID.
+     */
+    void Files_io_from_id( int id );
+
+    /**
      * Function Files_io
      * is the command event handler for read and write file commands.
      */
diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp
index 5796d8f..939b58e 100644
--- a/pcbnew/files.cpp
+++ b/pcbnew/files.cpp
@@ -222,6 +222,11 @@ void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event )
 void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
 {
     int        id = event.GetId();
+    Files_io_from_id( id );
+}
+
+void PCB_EDIT_FRAME::Files_io_from_id( int id )
+{
     wxString   msg;
 
     // If an edition is in progress, stop it.
diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp
index 50af8f0..386972a 100644
--- a/pcbnew/pcbframe.cpp
+++ b/pcbnew/pcbframe.cpp
@@ -595,7 +595,14 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
             break;
 
         case wxID_YES:
-            SavePcbFile( GetBoard()->GetFileName() );
+            if( GetBoard()->GetFileName() == "" )
+            {
+                Files_io_from_id( ID_SAVE_BOARD_AS );
+            }
+            else
+            {
+                SavePcbFile( GetBoard()->GetFileName() );
+            }
             break;
         }
     }

Follow ups