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

Method accept

src/plugins/chat/widgets/inputeditwidget.cpp:570–630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570void InputEditWidget::accept(const QModelIndex &index)
571{
572 if (!index.isValid())
573 return;
574 auto row = index.row();
575 if (row < 0 || row >= d->model.rowCount())
576 return;
577
578 EditorService *editorSrv = dpfGetService(EditorService);
579 ItemInfo item = d->model.getItems().at(row);
580
581 auto notify = [=](const QString &message){
582 WindowService *windowSrv = dpfGetService(WindowService);
583 windowSrv->notify(2, "Chat", message, {});
584 };
585
586 auto appendTag = [=](const QString &filePath) {
587 QFileInfo info(filePath);
588 d->selectedFiles.append(filePath);
589 auto tag = "file: " + info.dir().dirName() + '/' + info.fileName();
590 d->edit->appendTag(tag);
591 d->tagMap.insert('@' + tag, { filePath });
592 };
593 if (item.type == reference_current_file) {
594 auto filePath = editorSrv->currentFile();
595 if (filePath.isEmpty()) {
596 notify(tr("No opened file"));
597 return;
598 }
599 appendTag(filePath);
600 } else if (item.type == reference_select_file) {
601 QString result = QFileDialog::getOpenFileName(this, QAction::tr("Select File"), QDir::homePath());
602 if (result.isEmpty())
603 return;
604 appendTag(result);
605 } else if (item.type == reference_opened_files) {
606 auto openedFiles = editorSrv->openedFiles();
607 if (openedFiles.isEmpty()) {
608 notify(tr("No opened file"));
609 return;
610 }
611 QList<ItemInfo> items;
612 for (auto file : openedFiles) {
613 ItemInfo item;
614 item.extraInfo = file;
615 item.displayName = QFileInfo(file).fileName();
616 items.append(item);
617 }
618 d->model.clear();
619 d->model.addItems(items);
620 return;
621 } else if (item.type == reference_codebase) {
622 ChatManager::instance()->setReferenceCodebase(true);
623 d->edit->appendTag(reference_codebase);
624 } else if (!item.extraInfo.isEmpty()) {
625 appendTag(item.extraInfo);
626 }
627

Callers

nothing calls this directly

Calls 15

notifyFunction · 0.85
rowMethod · 0.80
atMethod · 0.80
fileNameMethod · 0.80
appendTagMethod · 0.80
insertMethod · 0.80
setReferenceCodebaseMethod · 0.80
setReferenceFilesMethod · 0.80
isValidMethod · 0.45
rowCountMethod · 0.45
getItemsMethod · 0.45
notifyMethod · 0.45

Tested by

no test coverage detected