code: def on_top_level_changed(self, top_level):
          
          if top_level:
              self.undock_action.setDisabled(True)
          else:
              self.undock_action.setDisabled(False)
docs: Actions to perform when a plugin is undocked to be moved.