void (@NotNull Module module, @NotNull List<? extends VirtualFile> roots, boolean exclude) { if (roots.isEmpty()) return; Project project = module.getProject(); final class MyUndoable extends GlobalUndoableAction { @Override public void undo() { excludeEntriesInner(module, roots, !exclude); } @Override public void redo() { excludeEntriesInner(module, roots, exclude); } } String title = IdeBundle.message("command.name.choice.exclude.include", exclude ? 0 : 1, getDisplayName(roots)); WriteCommandAction.writeCommandAction(project) .withName(title) .withUndoConfirmationPolicy(UndoConfirmationPolicy.REQUEST_CONFIRMATION).run(()-> { MyUndoable undoable = new MyUndoable(); undoable.redo(); UndoManager.getInstance(project).undoableActionPerformed(undoable); }); }