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

Method showChunksReferences

src/plugins/chat/widgets/messagecomponent.cpp:371–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369}
370
371void MessageComponent::showChunksReferences()
372{
373 if (finished || messageData.messageType() == MessageData::Ask)
374 return;
375
376 QJsonArray chunks = ChatManager::instance()->getCurrentChunks()["Chunks"].toArray();
377 if (chunks.isEmpty())
378 return;
379
380 auto separator = new QHBoxLayout;
381 separator->setContentsMargins(0, 0, 0, 0);
382 auto toggleBtn = new DPushButton(this);
383 toggleBtn->setText(tr("Show Reference"));
384 toggleBtn->setFlat(true);
385 toggleBtn->setIcon(QIcon::fromTheme("uc_codegeex_project_chat"));
386 separator->addWidget(toggleBtn);
387 msgLayout->addLayout(separator);
388
389 DListView *view = new DListView(this);
390 view->setItemSpacing(2);
391 view->setSelectionMode(DListView::NoSelection);
392 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
393 view->setEditTriggers(DListView::EditTrigger::NoEditTriggers);
394 view->setTextElideMode(Qt::ElideLeft);
395 auto listModel = new QStringListModel(this);
396 QStringList stringList;
397 view->setModel(listModel);
398
399 for (auto chunk : chunks) {
400 QString title = chunk.toObject()["fileName"].toString();
401 stringList.append(title);
402 view->addItem(title);
403 }
404 listModel->setStringList(stringList);
405 msgLayout->addWidget(view);
406
407 connect(view, &DListView::doubleClicked, this, [=](const QModelIndex &index) {
408 auto codeRange = index.data().toString();
409 QRegularExpression re("(.+)\\[(\\d+)-\\d+\\]");
410 QRegularExpressionMatch match = re.match(codeRange);
411
412 if (match.hasMatch()) {
413 QString filePath = match.captured(1);
414 int startLine = match.captured(2).toInt();
415 editor.gotoLine(filePath, startLine);
416 }
417 });
418 connect(toggleBtn, &DPushButton::clicked, this, [=]() {
419 if (view->isVisible()) {
420 msgLayout->removeWidget(view);
421 view->hide();
422 } else {
423 view->show();
424 msgLayout->addWidget(view);
425 }
426 });
427}

Callers

nothing calls this directly

Calls 15

connectFunction · 0.85
messageTypeMethod · 0.80
toArrayMethod · 0.80
getCurrentChunksMethod · 0.80
isVisibleMethod · 0.80
removeWidgetMethod · 0.80
isEmptyMethod · 0.45
setTextMethod · 0.45
setIconMethod · 0.45
addWidgetMethod · 0.45
setModelMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected