docs: def add_state_editor(self, state_m):
          """Triggered whenever a state is selected.
  
          :param state_m: The selected state model.
          """
          state_identifier = self.get_state_identifier(state_m)
  
          if state_identifier in self.closed_tabs:
              state_editor_ctrl = self.closed_tabs[state_identifier]['controller']
              state_editor_view = state_editor_ctrl.view
              handler_id = self.closed_tabs[state_identifier]['source_code_changed_handler_id']
              source_code_view_is_dirty = self.closed_tabs[state_identifier]['source_code_view_is_dirty']
              del self.closed_tabs[state_identifier]  # pages not in self.closed_tabs and self.tabs at the same time
          else:
              state_editor_view = StateEditorView()
              if isinstance(state_m, LibraryStateModel):
                  state_editor_view['main_notebook_1'].set_current_page(
                      state_editor_view['main_notebook_1'].page_num(state_editor_view.page_dict["Data Linkage"]))
              state_editor_ctrl = StateEditorController(state_m, state_editor_view)
              self.add_controller(state_identifier, state_editor_ctrl)
              if state_editor_ctrl.get_controller('source_ctrl') and state_m.state.get_next_upper_library_root_state() is None:
                  # observe changed to set the mark dirty flag
                  handler_id = state_editor_view.source_view.get_buffer().connect('changed', self.script_text_changed,
                                                                                  state_m)
                  self.view.get_top_widget().connect('draw', state_editor_view.source_view.on_draw)
              else:
                  handler_id = None
              source_code_view_is_dirty = False
  
          (tab, inner_label, sticky_button) = create_tab_header('', self.on_tab_close_clicked,
                                                                self.on_toggle_sticky_clicked, state_m)
          set_tab_label_texts(inner_label, state_m, source_code_view_is_dirty)
  
          state_editor_view.get_top_widget().title_label = inner_label
          state_editor_view.get_top_widget().sticky_button = sticky_button
  
          page_content = state_editor_view.get_top_widget()
          page_id = self.view.notebook.prepend_page(page_content, tab)
          page = self.view.notebook.get_nth_page(page_id)
          self.view.notebook.set_tab_reorderable(page, True)
          page.show_all()
  
          self.view.notebook.show()
          self.tabs[state_identifier] = {'page': page, 'state_m': state_m,
                                         'controller': state_editor_ctrl, 'sm_id': self.model.selected_state_machine_id,
                                         'is_sticky': False,
                                         'source_code_view_is_dirty': source_code_view_is_dirty,
                                         'source_code_changed_handler_id': handler_id}
          return page_id