MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / childMenu

Method childMenu

src/plugins/project/mainframe/projecttree.cpp:476–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474}
475
476DMenu *ProjectTree::childMenu(const QStandardItem *root, QStandardItem *childItem)
477{
478 DMenu *menu = nullptr;
479 QString toolKitName = ProjectInfo::get(root).kitName();
480 // 获取支持右键菜单生成器
481 auto &ctx = dpfInstance.serviceContext();
482 ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name());
483 if (projectService->supportGeneratorName<ProjectGenerator>().contains(toolKitName)) {
484 menu = projectService->createGenerator<ProjectGenerator>(toolKitName)->createItemMenu(childItem);
485 }
486
487 if (!menu)
488 menu = new DMenu();
489
490 QAction *newDirAction = new QAction(tr("New Directory"), this);
491 QObject::connect(newDirAction, &QAction::triggered, this, [=]() {
492 actionNewDirectory(childItem);
493 });
494
495 QAction *newDocAction = new QAction(tr("New Document"), this);
496 QObject::connect(newDocAction, &QAction::triggered, this, [=]() {
497 actionNewDocument(childItem);
498 });
499
500 QAction *renameDocAction = new QAction(tr("Rename"), this);
501 QObject::connect(renameDocAction, &QAction::triggered, this, [=]() {
502 actionRenameDocument(childItem);
503 });
504
505 QModelIndex index = d->itemModel->indexFromItem(childItem);
506 QFileInfo info(index.data(Qt::ToolTipRole).toString());
507
508 // add open in terminal menu item.
509 QAction *openInTerminal = new QAction(tr("Open In Terminal"), this);
510 menu->addAction(openInTerminal);
511 connect(openInTerminal, &QAction::triggered, [=]() {
512 actionOpenInTerminal(childItem);
513 });
514
515 if (info.isDir()) {
516 menu->addAction(newDocAction);
517 menu->addAction(newDirAction);
518 }
519
520 if (info.isFile()) {
521 newDocAction->setEnabled(false);
522 // add delete file menu item.
523 QAction *deleteDocAction = new QAction(tr("Delete Document"), this);
524 QObject::connect(deleteDocAction, &QAction::triggered, this, [=]() {
525 actionDeleteDocument(childItem);
526 });
527 deleteDocAction->setEnabled(true);
528
529 menu->addAction(deleteDocAction);
530 menu->addAction(renameDocAction);
531 }
532
533 return menu;

Callers

nothing calls this directly

Calls 11

connectFunction · 0.85
indexFromItemMethod · 0.80
getFunction · 0.50
nameFunction · 0.50
kitNameMethod · 0.45
containsMethod · 0.45
createItemMenuMethod · 0.45
toStringMethod · 0.45
dataMethod · 0.45
addActionMethod · 0.45
setEnabledMethod · 0.45

Tested by

no test coverage detected