How to change the default file format for save

Hello,

When we click on the save button the default file format for saving a scene is .mrml. Is there any way I can change it to .mrb? Is there a way to edit the config file so that the save data dialog opens with .mrb file format to save?

I am willing to edit the qSlicerSaveDataDialog.cxx file and maintain it, if it is like one or two line edit. If that is the only case please tell me how to do it. Or should I subclass the save data dialog and make my own save widget? If so please instruct me on how to do it.

Thanks for your help in advance.

I was curious as well so did a brief chat with GitHub Copilot. Here is the relevant part of the results, maybe it helps:

… but not as a simple “default extension setting” in the Save dialog UI—to force a default (your option B) you typically need either:

  1. a small core change in Slicer (recommended if you control the build), or
  2. a scripted override of the scene save dialog (works without rebuilding, but it replaces the standard dialog behavior).

Below is what the current Slicer code is doing and where you’d change it.


1) MRML vs MRB default in the Save dialog (“Save scene and unsaved data”)

That dialog is implemented here:

void qSlicerSaveDataDialogPrivate::saveSceneAsDataBundle()
{
  int sceneRow = this->findSceneRow();
  QComboBox* box = qobject_cast<QComboBox*>(this->FileWidget->cellWidget(sceneRow, FileFormatColumn));
  int mrbIndex = box->findText("mrb", Qt::MatchContains);
  int mrmlIndex = box->findText("mrml", Qt::MatchContains);
  // Toggle between scene data bundle entry and mrml entry
  if (mrbIndex != -1)
  {
    if (box->currentIndex() != mrbIndex)
    {
      box->setCurrentIndex(mrbIndex);
    }
    else
    {
      if (mrmlIndex != -1)
      {
        box->setCurrentIndex(mrmlIndex);
      }
    }
  }
}

Key point: MRB is currently a “toggle button” behavior, not a persisted “default”. So “force MRB always” is not exposed as a preference; you’d need to change logic so that on dialog initialization/population it sets the scene’s file format combobox to MRB and (optionally) disables toggling back.

What to change (core approach)

You’d look for where the scene row is populated (e.g., populateScene() / populateItems() in the same file) and make it do something like:

  • find the scene row combobox
  • set it to the mrb entry unconditionally
  • optionally call the logic that hides other rows when MRB is selected (since MRB implies bundling; Slicer already has code that hides non-scene rows when saving as MRB)

There is already code that hides other rows when saving as MRB:

// When scene is saved as .mrb then item selection state,
// file format, and options may be ignored. To indicate
// this clearly to the users, we only show the scene in the table
// and hide all the other storable nodes.

So the feature is conceptually supported; it’s just not “force MRB by default”.

Alternative (no rebuild): override the scene save dialog

Slicer supports overriding the default scene save dialog from a scripted module. This is documented here:

### Override default scene save dialog

Place this class in the scripted module file to override

```python
class MyModuleFileDialog ():
  ...
  def execDialog(self):
    # Implement custom scene save operation here.
    ...
```

With that approach you could implement “Save always writes an .mrb” (for example by calling slicer.util.saveScene("something.mrb"))—but it replaces the normal dialog, so it’s a heavier UX change.