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

Method doItemMenuRequest

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

Source from the content-addressed store, hash-verified

222}
223
224void ProjectTree::doItemMenuRequest(QStandardItem *item, QContextMenuEvent *event)
225{
226 if (!item)
227 return;
228
229 auto rootItem = ProjectGenerator::root(item);
230 DMenu *menu = nullptr;
231
232 if (rootItem == item) {
233 menu = rootMenu(rootItem);
234 // add action that running.
235 auto runCommand = ActionManager::instance()->command("Debug.Running");
236 if (getActiveProjectInfo().workspaceFolder() == dpfservice::ProjectInfo::get(rootItem).workspaceFolder()
237 && runCommand && runCommand->action()) {
238 menu->addSeparator();
239 menu->addAction(runCommand->action());
240 }
241 QFileInfo info(item->data(Qt::ToolTipRole).toString());
242 if (info.isDir()) {
243 menu->addSeparator();
244 QAction *newDocAction = new QAction(tr("New Document"), this);
245 QObject::connect(newDocAction, &QAction::triggered, this, [=]() {
246 actionNewDocument(item);
247 });
248 QAction *newDirAction = new QAction(tr("New Directory"), this);
249 QObject::connect(newDirAction, &QAction::triggered, this, [=]() {
250 actionNewDirectory(item);
251 });
252 menu->addAction(newDocAction);
253 menu->addAction(newDirAction);
254 }
255 } else {
256 menu = childMenu(rootItem, item);
257 }
258
259 // add action that show contain folder.
260 menu->addSeparator();
261 QAction *showContainFolder = new QAction(tr("Show Containing Folder"), this);
262 connect(showContainFolder, &QAction::triggered, [=]() {
263 QString filePath = item->data(Project::ProjectItemRole::FilePathRole).toString();
264 QFileInfo info(filePath);
265 if (info.isFile())
266 DDesktopServices::showFileItem(filePath);
267 else
268 DDesktopServices::showFolder(filePath);
269 });
270 menu->addAction(showContainFolder);
271
272 connect(this, &ProjectTree::itemDeleted, menu, [=](QStandardItem *deletedItem) {
273 if (item == deletedItem || ProjectGenerator::root(item) == deletedItem)
274 menu->close();
275 });
276
277 if (menu) {
278 menu->move(event->globalPos());
279 menu->exec();
280 delete menu;
281 }

Callers

nothing calls this directly

Calls 10

connectFunction · 0.85
addSeparatorMethod · 0.80
getFunction · 0.50
commandMethod · 0.45
actionMethod · 0.45
addActionMethod · 0.45
toStringMethod · 0.45
dataMethod · 0.45
closeMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected