Logo Search packages:      
Sourcecode: pan version File versions

void PanTreeStore::reparent ( Row parent_or_null_for_root,
Row child,
int  pos = INT_MAX 

Move a row to a new parent.

Definition at line 1059 of file pan-tree.cc.

References PanTreeStore::Row::children, get_path(), PanTreeStore::Row::n_children(), and walk().

  g_return_if_fail (row != 0);

  GtkTreeModel * model (GTK_TREE_MODEL(this));

  if (!new_parent)
    new_parent = root;

  // remove our subtree's toplevel from its old parent
  rows_t tmp;
  tmp.push_back (row);
  remove_siblings (tmp, false);

  // add the subtree's toplevel to its new parent row
  const int new_parent_old_n_children (new_parent->n_children());
  position = std::min (position, new_parent_old_n_children);
  new_parent->children.insert (new_parent->children.begin()+position, row);
  renumber_children (new_parent, position);

  // emit a row-inserted for iter
  GtkTreeIter iter (get_iter (row));
  GtkTreePath * path (get_path (row));
  gtk_tree_model_row_inserted (model, path, &iter);
  gtk_tree_path_free (path);

  // this emits all the row-inserted and has-child-toggled signals EXCEPT
  // for iter's row-inserted (above) and parent-iter's has-child-toggled (below).
  // It's kind of kludgy but gets all the signals emitted in the right sequence.
  ReparentWalker walk (this);
  prefix_walk (walk, &iter, true);

  // if this was the new parent's first child, fire a has-child-toggled event
  if (!new_parent_old_n_children) {
    GtkTreePath * path (get_path (new_parent));
    GtkTreeIter new_parent_iter;
    get_iter (new_parent, &new_parent_iter);
    gtk_tree_model_row_has_child_toggled (model, path, &new_parent_iter);
    gtk_tree_path_free (path);

Generated by  Doxygen 1.6.0   Back to index