WordPress link by default only for gallery images

The following code adds a link to the file itself when inserting an image using the WordPress editor:

function my_new_default_image_settings() {
    update_option( 'image_default_link_type', 'file' );
}
add_action( 'after_setup_theme', 'my_new_default_image_settings' );

Currently all my images are getting a link. Is it possible to only have this executed when adding a gallery?