nodes: 0, module; 1, function_definition; 2, function_name:__sort_toplevel_items; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, comment:"""
          Sort the root file items in alphabetical order if
          'sort_files_alphabetically' is True, else order the items as
          specified in the 'self.ordered_editor_ids' list.
          """; 12, comparison_operator:self.show_all_files is False; 13, block; 14, assignment; 15, attribute; 16, block; 17, else_clause; 18, comparison_operator:current_ordered_items != new_ordered_items; 19, block; 20, attribute; 21, False; 22, return_statement; 23, identifier:current_ordered_items; 24, list_comprehension; 25, identifier:self; 26, identifier:sort_files_alphabetically; 27, expression_statement; 28, block; 29, identifier:current_ordered_items; 30, identifier:new_ordered_items; 31, expression_statement; 32, expression_statement; 33, for_statement; 34, for_statement; 35, expression_statement; 36, expression_statement; 37, if_statement; 38, identifier:self; 39, identifier:show_all_files; 40, call; 41, for_in_clause; 42, assignment; 43, expression_statement; 44, assignment; 45, call; 46, identifier:index; 47, call; 48, block; 49, pattern_list; 50, call; 51, block; 52, call; 53, call; 54, identifier:selected_items; 55, block; 56, attribute; 57, argument_list; 58, identifier:index; 59, call; 60, identifier:new_ordered_items; 61, call; 62, assignment; 63, identifier:selected_items; 64, call; 65, attribute; 66, argument_list; 67, identifier:range; 68, argument_list; 69, expression_statement; 70, identifier:index; 71, identifier:item; 72, identifier:enumerate; 73, argument_list; 74, expression_statement; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, expression_statement; 80, identifier:self; 81, identifier:topLevelItem; 82, identifier:index; 83, identifier:range; 84, argument_list; 85, identifier:sorted; 86, argument_list; 87, identifier:new_ordered_items; 88, list_comprehension; 89, attribute; 90, argument_list; 91, identifier:self; 92, identifier:save_expanded_state; 93, call; 94, call; 95, identifier:new_ordered_items; 96, call; 97, identifier:self; 98, identifier:restore_expanded_state; 99, identifier:self; 100, identifier:clearSelection; 101, call; 102, call; 103, identifier:current_ordered_items; 104, keyword_argument; 105, call; 106, for_in_clause; 107, if_clause; 108, identifier:self; 109, identifier:selectedItems; 110, attribute; 111, argument_list; 112, attribute; 113, argument_list; 114, attribute; 115, argument_list; 116, attribute; 117, argument_list; 118, attribute; 119, argument_list; 120, identifier:key; 121, lambda; 122, attribute; 123, argument_list; 124, identifier:e_id; 125, attribute; 126, comparison_operator:self.editor_items.get(e_id) is not None; 127, identifier:self; 128, identifier:topLevelItemCount; 129, identifier:self; 130, identifier:takeTopLevelItem; 131, integer:0; 132, identifier:self; 133, identifier:insertTopLevelItem; 134, identifier:index; 135, identifier:item; 136, subscript; 137, identifier:setSelected; 138, True; 139, identifier:self; 140, identifier:topLevelItemCount; 141, lambda_parameters; 142, call; 143, attribute; 144, identifier:get; 145, identifier:e_id; 146, identifier:self; 147, identifier:ordered_editor_ids; 148, call; 149, None; 150, identifier:selected_items; 151, unary_operator; 152, identifier:item; 153, attribute; 154, argument_list; 155, identifier:self; 156, identifier:editor_items; 157, attribute; 158, argument_list; 159, integer:1; 160, identifier:osp; 161, identifier:basename; 162, call; 163, attribute; 164, identifier:get; 165, identifier:e_id; 166, attribute; 167, argument_list; 168, identifier:self; 169, identifier:editor_items; 170, attribute; 171, identifier:lower; 172, identifier:item; 173, identifier:path
code: def __sort_toplevel_items(self):
          """
          Sort the root file items in alphabetical order if
          'sort_files_alphabetically' is True, else order the items as
          specified in the 'self.ordered_editor_ids' list.
          """
          if self.show_all_files is False:
              return
  
          current_ordered_items = [self.topLevelItem(index) for index in
                                   range(self.topLevelItemCount())]
          if self.sort_files_alphabetically:
              new_ordered_items = sorted(
                  current_ordered_items,
                  key=lambda item: osp.basename(item.path.lower()))
          else:
              new_ordered_items = [
                  self.editor_items.get(e_id) for e_id in
                  self.ordered_editor_ids if
                  self.editor_items.get(e_id) is not None]
  
          if current_ordered_items != new_ordered_items:
              selected_items = self.selectedItems()
              self.save_expanded_state()
              for index in range(self.topLevelItemCount()):
                  self.takeTopLevelItem(0)
              for index, item in enumerate(new_ordered_items):
                  self.insertTopLevelItem(index, item)
              self.restore_expanded_state()
              self.clearSelection()
              if selected_items:
                  selected_items[-1].setSelected(True)