void (@NotNull MenuItemInternal mi) { // exec at glib main-loop thread if (mi.nativePeer == null) { return; } // sort mi.children.sort(Comparator.comparingInt(MenuItemInternal::getPosition)); // remove marked items Iterator<MenuItemInternal> i = mi.children.iterator(); while (i.hasNext()) { final MenuItemInternal child = i.next(); if (child.position != -1) { break; } if (child.nativePeer != null) { ourLib.removeMenuItem(mi.nativePeer, child.nativePeer); child.nativePeer = null; } i.remove(); } // update/create and reorder for (int pos = 0; pos < mi.children.size(); ++pos) { final MenuItemInternal child = mi.children.get(pos); if (child.nativePeer == null) { if (child.action == null) { child.nativePeer = ourLib.addSeparator(mi.nativePeer, child.uid, pos); continue; } child.nativePeer = ourLib.addMenuItem(mi.nativePeer, child.uid, child.txt, child.type, child.position); } else if (child.position != pos) { // System.out.printf("reorder: '%s' [%d] -> [%d]\n", child, child.position, pos); ourLib.reorderMenuItem(mi.nativePeer, child.nativePeer, child.position); } child.updateNative(); _processChildren(child); } }