You're on the right track. Dialogs should have one or two actions. They can contain form inputs but should not contain any other links or buttons which take the user away from the dialog.
A single button dialog is used when the user just needs to confirm they have read a message. A two button dialog is used when the user is about to perform an action that needs confirmation. The rightmost button (or leftmost if left aligned) should be the button which confirms the action with the other button being the one which cancels it and does nothing.
That last point is important here. I think it would be better if you flipped your logic around and asked the user if they wanted to delete their code instead of keeping it. Note: You could replace "Cancel" with "Keep" or "Skip" if that better suits your application flow.
Another option would be to keep the code by default and give the user a button that discards all of the code rather than interrupting their flow with a dialog. The user may have unintentionally changed the code language so popping up a dialog interrupts their flow and stops them from quickly changing it back. Keeping the code and then adding an option to the editor which clears the code gives the control back to the user and adds an additional feature to your editor. You should also show a similar dialog when that button is pressed.