docs: function (id, obj) {
              for (var k = 0, len = this.length; k < len; k++) {
                  var dlg = this[k];
                  var $dlg = $(dlg);
                  var data = $dlg.data('selectId');
                  if (!data || !data.$tree || !data.objects) continue;
  
                  if (id.match(/^enum\.rooms/))     {
                      data.rooms = {};
                      data.roomsColored = {};
                  }
                  if (id.match(/^enum\.functions/)) {
                      data.funcs = {};
                      data.funcsColored = {};
                  }
  
                  var tree = data.$tree.fancytree('getTree');
                  var node = tree.getNodeByKey(id);
                  // var node = null;
                  // tree.visit(function (n) {
                  //     if (n.key === id) {
                  //         node = n;
                  //         return false;
                  //     }
                  // });
  
                  // If new node
                  if (!node && obj) {
                      // Filter it
                      if (data.stats) {
                          data.stats.objs++;
                          if (obj.type === 'state') {
                              data.stats.states++;
                          }
                          updateStats(data);
                      }
  
                      data.objects[id] = obj;
                      var addedNodes = [];
  
                      if (!filterId(data, id)) {
                          return;
                      }
                      // add ID to IDS;
                      if (data.ids.length) {
                          var p = 0;
                          while (data.ids[p] < id) {
                              p++;
                          }
                          data.ids.splice(p, 0, id);
                      }
                      treeInsert(data, id, false, addedNodes);
  
                      for (var i = 0; i < addedNodes.length; i++) {
                          if (!addedNodes[i].parent.root) {
                              node = tree.getNodeByKey(addedNodes[i].parent.key);
                              // tree.visit(function (n) {
                              //     if (n.key === addedNodes[i].parent.key) {
                              //         node = n;
                              //         return false;
                              //     }
                              // });
  
                          } else {
                              node = data.$tree.fancytree('getRootNode');
                          }
                          // if no children
                          if (!node.children || !node.children.length) {
                              // add
                              node.addChildren(addedNodes[i]);
                              node.folder = true;
                              node.expanded = false;
                              node.render(true);
                              node.children[0].match = true;
                          } else {
                              var c;
                              for (c = 0; c < node.children.length; c++) {
                                  if (node.children[c].key > addedNodes[i].key) break;
                              }
                              // if some found greater than new one
                              if (c !== node.children.length) {
                                  node.addChildren(addedNodes[i], node.children[c]);
                                  node.children[c].match = true;
                                  node.render(true);
                              } else {
                                  // just add
                                  node.addChildren(addedNodes[i]);
                                  node.children[node.children.length - 1].match = true;
                                  node.render(true);
                              }
                          }
                      }
                  } else if (!obj) {
                      if (data.stats && data.objects[id]) {
                          data.stats.objs--;
                          if (data.objects[id] && data.objects[id].type === 'state') {
                              data.stats.states--;
                          }
                          updateStats(data);
                      }
  
                      // object deleted
                      delete data.objects[id];
                      deleteTree(data, id);
  
                      if (data.ids.length) {
                          var pos = data.ids.indexOf(id);
                          if (pos !== -1) {
                              data.ids.splice(pos, 1);
                          }
                      }
  
                      if (node) {
                          var prev = node.getPrevSibling();
                          var parent = node.parent;
                          node.removeChildren();
                          node.remove();
                          prev && prev.setActive();
  
                          while (parent && (!parent.children || !parent.children.length)) {
                              var _parent = parent.parent;
                              parent.remove();
                              if (_parent) {
                                  _parent.setActive();
                              }
                              parent = _parent;
                          }
  
                          // recalculate numbers of all children
                          if (data.ids.length) {
                              recalcChildrenCounters(parent, data);
                          }
                          // if (node.children && node.children.length) {
                          //     if (node.children.length === 1) {
                          //         node.folder = false;
                          //         node.expanded = false;
                          //     }
                          //     node.render(true);
                          // } else {
                          //     if (node.parent && node.parent.children.length === 1) {
                          //         node.parent.folder = false;
                          //         node.parent.expanded = false;
                          //         node.parent.render(true);
                          //     }
                          //     node.remove();
                          // }
                      }
                  } else {
                      // object updated
                      if (node) {
                          node.render(true);
                      }
                  }
              }
              return this;
          }