| 51 | } |
| 52 | |
| 53 | ContextMenuExtension ProjectFilterProvider::contextMenuExtension(Context* context, QWidget* parent) |
| 54 | { |
| 55 | ContextMenuExtension ret; |
| 56 | if (!context->hasType(Context::ProjectItemContext)) { |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | auto* ctx = static_cast<ProjectItemContext*>( context ); |
| 61 | |
| 62 | QList<ProjectBaseItem*> items = ctx->items(); |
| 63 | // filter out project roots and items in targets |
| 64 | QList< ProjectBaseItem* >::iterator it = items.begin(); |
| 65 | while (it != items.end()) { |
| 66 | if ((*it)->isProjectRoot() || !(*it)->parent()->folder()) { |
| 67 | it = items.erase(it); |
| 68 | } else { |
| 69 | ++it; |
| 70 | } |
| 71 | } |
| 72 | if (items.isEmpty()) { |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | auto* action = new QAction(QIcon::fromTheme(QStringLiteral("view-filter")), |
| 77 | i18ncp("@action:inmenu", "Exclude Item from Project", |
| 78 | "Exclude Items from Project", |
| 79 | items.size()), parent); |
| 80 | action->setData(QVariant::fromValue(items)); |
| 81 | connect(action, &QAction::triggered, this, &ProjectFilterProvider::addFilterFromContextMenu); |
| 82 | ret.addAction(ContextMenuExtension::FileGroup, action); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | void ProjectFilterProvider::addFilterFromContextMenu() |
| 87 | { |