How to observe save button event

Hi!
I am writing a Python script and encountered a problem recently. I want to save a specific component’s data through MRMLTextnode. However, I need to update and write them into the MRMLTextnode before users open the save dialog.

Is there a way to observe the Save Scene and Unsaved Data button event?

You can override the default scene save dialog as shown in the example in the script repository.

Hi, I added this module to my code, but it doesn’t seem to work. When I click the save button, there is no output in the console. Should I register it?

import os

import vtk

import slicer, qt
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixin

class MyModuleFileDialog ():
  """This specially named class is detected by the scripted loadable
  module and is the target for optional drag and drop operations.
  See: Base/QTGUI/qSlicerScriptedFileDialog.h.

  This class is used for overriding default scene save dialog
  with simple saving the scene without asking anything.
  """

  def __init__(self,qSlicerFileDialog ):
    self.qSlicerFileDialog = qSlicerFileDialog
    qSlicerFileDialog.fileType = "NoFile"
    qSlicerFileDialog.description = "Save scene"
    qSlicerFileDialog.action = slicer.qSlicerFileDialog.Write

  def execDialog(self):
    # Implement custom scene save operation here.
    # Return True if saving completed successfully,
    # return False if saving was cancelled.
    print("hello")
    return True
  
  
#
# BCMaker
#
....