File indexing completed on 2025-01-05 05:14:49

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "fileblamedialog.h"
0008 
0009 #include "gitmanager.h"
0010 #include "models/logsmodel.h"
0011 
0012 #include <KLocalizedString>
0013 #include <QThread>
0014 
0015 FileBlameDialog::FileBlameDialog(Git::Manager *git, const Git::File &file, QWidget *parent)
0016     : AppDialog(git, parent)
0017     , mFile(file)
0018 {
0019     setupUi(this);
0020 
0021     widgetCommitDetails->setEnableCommitsLinks(false);
0022     plainTextEdit->setShowTitleBar(false);
0023 
0024     connect(plainTextEdit, &BlameCodeView::blockSelected, this, &FileBlameDialog::slotPlainTextEditBlockSelected);
0025 
0026     if (git->logsModel()->isLoaded())
0027         loadData();
0028     else
0029         connect(mGit->logsModel(), &Git::LogsModel::loaded, this, &FileBlameDialog::loadData);
0030 }
0031 
0032 void FileBlameDialog::loadData()
0033 {
0034     plainTextEdit->setHighlighting(mFile.fileName());
0035 
0036     const auto b = mGit->blame(mFile);
0037     plainTextEdit->setBlameData(b);
0038 
0039     setWindowTitle(i18nc("@title:window", "Blame file: %1", mFile.fileName()));
0040 }
0041 
0042 void FileBlameDialog::slotPlainTextEditBlockSelected()
0043 {
0044     auto data = plainTextEdit->currentBlockData();
0045     widgetCommitDetails->setCommit(data ? static_cast<Git::Commit *>(data->data) : nullptr);
0046 }
0047 
0048 #include "moc_fileblamedialog.cpp"