docs: def save_selected_state_as():
      """Save selected state as separate state machine
  
      :return True if successfully stored, False if the storing process was canceled or stopped by condition fail
      :rtype bool:
      :raises exceptions.ValueError: If dialog response ids are out of bounds
      """
  
      state_machine_manager_model = rafcon.gui.singleton.state_machine_manager_model
      selection = state_machine_manager_model.get_selected_state_machine_model().selection
      selected_state = selection.get_selected_state()
      state_machine_id = state_machine_manager_model.get_selected_state_machine_model().state_machine.state_machine_id
      if len(selection.states) == 1:
          state_m = copy.copy(selected_state)
          sm_m = StateMachineModel(StateMachine(root_state=state_m.state))
          sm_m.root_state = state_m
          path = interface.create_folder_func("Please choose a root folder and a folder name for the state-machine your "
                                              "state is saved in. The default folder name is the name of state.",
                                              format_default_folder_name(selected_state.state.name))
          if path:
              storage.save_state_machine_to_path(sm_m.state_machine, base_path=path)
              sm_m.store_meta_data()
          else:
              logger.warning("No valid path specified")
              return False
  
          def open_as_state_machine_saved_state_as_separate_state_machine():
              logger.debug("Open state machine.")
              try:
                  open_state_machine(path=path, recent_opened_notification=True)
              except (ValueError, IOError) as e:
                  logger.error('Error while trying to open state machine: {0}'.format(e))
  
          # check if state machine is in library path
          root_window = rafcon.gui.singleton.main_window_controller.get_root_window()
          if library_manager.is_os_path_within_library_root_paths(path):
  
              _library_path, _library_name = \
                  library_manager.get_library_path_and_name_for_os_path(sm_m.state_machine.file_system_path)
              overwrote_old_lib = library_manager.is_library_in_libraries(_library_path, _library_name)
  
              message_string = "You stored your state machine in a path that is within the library root paths. " \
                               "Thereby your state machine can be used as a library state.\n\n"\
                               "Do you want to:"
  
              table_header = ["Option", "Description"]
              table_data = [(True, "Substitute the original state by this new library state."),
                            (True, "Open the newly created library state machine.")]
              if overwrote_old_lib:
                  table_data.append((False, "Refresh all open state machines, as an already existing library was "
                                            "overwritten."))
  
              dialog = RAFCONCheckBoxTableDialog(message_string,
                                                 button_texts=("Apply", "Cancel"),
                                                 table_header=table_header, table_data=table_data,
                                                 message_type=Gtk.MessageType.QUESTION,
                                                 parent=root_window,
                                                 width=800, standalone=False)
              response_id = dialog.run()
              if response_id == 1:  # Apply pressed
  
                  if overwrote_old_lib and dialog.list_store[2][0]:  # refresh all open state machine selected
                      logger.debug("Refresh all is triggered.")
                      refresh_all()
                  else:  # if not all was refreshed at least the libraries are refreshed
                      logger.debug("Library refresh is triggered.")
                      refresh_libraries()
  
                  if dialog.list_store[0][0]:  # Substitute saved state with Library selected
                      logger.debug("Substitute saved state with Library.")
                      if dialog.list_store[0][0] or dialog.list_store[0][1]:
                          refresh_libraries()
                      state_machine_manager_model.selected_state_machine_id = state_machine_id
                      [library_path, library_name] = library_manager.get_library_path_and_name_for_os_path(path)
                      state = library_manager.get_library_instance(library_path, library_name)
                      try:
                          substitute_selected_state(state, as_template=False)
                      except ValueError as e:
                          logger.error('Error while trying to open state machine: {0}'.format(e))
                  if dialog.list_store[1][0]:  # Open as state machine saved state as separate state machine selected
                      open_as_state_machine_saved_state_as_separate_state_machine()
              elif response_id in [2, -4]:  # Cancel or Close pressed
                  pass
              else:
                  raise ValueError("Response id: {} is not considered".format(response_id))
              dialog.destroy()
          else:
              # Offer to open saved state machine dialog
              message_string = "Should the newly created state machine be opened?"
              dialog = RAFCONButtonDialog(message_string, ["Open", "Do not open"],
                                          message_type=Gtk.MessageType.QUESTION,
                                          parent=root_window)
              response_id = dialog.run()
              if response_id == 1:  # Apply pressed
                  open_as_state_machine_saved_state_as_separate_state_machine()
              elif response_id in [2, -4]:  # Cancel or Close pressed
                  pass
              else:
                  raise ValueError("Response id: {} is not considered".format(response_id))
              dialog.destroy()
  
          return True
      else:
          logger.warning("Multiple states can not be saved as state machine directly. Group them before.")
          return False