| 820 | } |
| 821 | |
| 822 | void SourceFormatterController::formatFiles() |
| 823 | { |
| 824 | Q_D(SourceFormatterController); |
| 825 | |
| 826 | if (d->prjItems.isEmpty() && d->urls.isEmpty()) |
| 827 | return; |
| 828 | |
| 829 | //get a list of all files in this folder recursively |
| 830 | QList<KDevelop::ProjectFolderItem*> folders; |
| 831 | for (KDevelop::ProjectBaseItem* item : std::as_const(d->prjItems)) { |
| 832 | if (!item) |
| 833 | continue; |
| 834 | if (item->folder()) |
| 835 | folders.append(item->folder()); |
| 836 | else if (item->file()) |
| 837 | d->urls.append(item->file()->path().toUrl()); |
| 838 | else if (item->target()) { |
| 839 | const auto files = item->fileList(); |
| 840 | for (KDevelop::ProjectFileItem* f : files) { |
| 841 | d->urls.append(f->path().toUrl()); |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | while (!folders.isEmpty()) { |
| 847 | KDevelop::ProjectFolderItem *item = folders.takeFirst(); |
| 848 | const auto folderList = item->folderList(); |
| 849 | for (KDevelop::ProjectFolderItem* f : folderList) { |
| 850 | folders.append(f); |
| 851 | } |
| 852 | const auto targets = item->targetList(); |
| 853 | for (KDevelop::ProjectTargetItem* f : targets) { |
| 854 | const auto childs = f->fileList(); |
| 855 | for (KDevelop::ProjectFileItem* child : childs) { |
| 856 | d->urls.append(child->path().toUrl()); |
| 857 | } |
| 858 | } |
| 859 | const auto files = item->fileList(); |
| 860 | for (KDevelop::ProjectFileItem* f : files) { |
| 861 | d->urls.append(f->path().toUrl()); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | auto win = ICore::self()->uiController()->activeMainWindow()->window(); |
| 866 | |
| 867 | QMessageBox msgBox(QMessageBox::Question, i18nc("@title:window", "Reformat Files?"), |
| 868 | i18n("Reformat all files in the selected folder?"), |
| 869 | QMessageBox::Ok|QMessageBox::Cancel, win); |
| 870 | msgBox.setDefaultButton(QMessageBox::Cancel); |
| 871 | auto okButton = msgBox.button(QMessageBox::Ok); |
| 872 | okButton->setText(i18nc("@action:button", "Reformat")); |
| 873 | msgBox.exec(); |
| 874 | |
| 875 | if (msgBox.clickedButton() == okButton) { |
| 876 | auto formatterJob = new SourceFormatterJob(this); |
| 877 | formatterJob->setFiles(d->urls); |
| 878 | ICore::self()->runController()->registerJob(formatterJob); |
| 879 | } |
nothing calls this directly
no test coverage detected