Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 92ea669a authored by Anthony Fieroni's avatar Anthony Fieroni

[git plugin] Add log action

Differential Revision: https://phabricator.kde.org/D10267Signed-off-by: Anthony Fieroni's avatarAnthony Fieroni <bvbfan@abv.bg>
parent 1410dc5c
......@@ -39,6 +39,7 @@
#include <QStringList>
#include <QTextCodec>
#include <QDir>
#include <QTextBrowser>
K_PLUGIN_FACTORY(FileViewGitPluginFactory, registerPlugin<FileViewGitPlugin>();)
......@@ -106,6 +107,10 @@ FileViewGitPlugin::FileViewGitPlugin(QObject* parent, const QList<QVariant>& arg
connect(m_pullAction, SIGNAL(triggered()),
this, SLOT(pull()));
m_logAction = new QAction(this);
m_logAction->setText(xi18nd("@action:inmenu", "<application>Git</application> Log..."));
connect(m_logAction, &QAction::triggered, this, &FileViewGitPlugin::log);
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotOperationCompleted(int, QProcess::ExitStatus)));
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
......@@ -357,6 +362,9 @@ QList<QAction*> FileViewGitPlugin::contextMenuDirectoryActions(const QString& di
++it;
}
m_logAction->setEnabled(!m_pendingOperation);
actions.append(m_logAction);
m_showLocalChangesAction->setEnabled(!m_pendingOperation && showChanges);
actions.append(m_showLocalChangesAction);
......@@ -407,6 +415,75 @@ void FileViewGitPlugin::showLocalChanges()
KRun::runCommand(QLatin1String("git difftool --dir-diff ."), nullptr, m_contextDir);
}
void FileViewGitPlugin::showDiff(const QUrl &link)
{
if (link.scheme() != QLatin1String("rev")) {
return;
}
KRun::runCommand(QStringLiteral("git difftool --dir-diff %1^ %1").arg(link.path()), nullptr, m_contextDir);
}
void FileViewGitPlugin::log()
{
QProcess process;
process.setWorkingDirectory(m_contextDir);
process.start(
QLatin1String("git"),
QStringList {
QStringLiteral("log"),
QStringLiteral("--relative=."),
QStringLiteral("--date=format:%d-%m-%Y"),
QStringLiteral("-n 100"),
QStringLiteral("--pretty=format:<tr> <td><a href=\"rev:%h\">%h</a></td> <td>%ad</td> <td>%s</td> <td>%an</td> </tr>")
}
);
if (!process.waitForFinished() || process.exitCode() != 0) {
emit errorMessage(xi18nd("@info:status", "<application>Git</application> Log failed."));
return;
}
const QString gitOutput = process.readAllStandardOutput();
QPalette palette;
const QString styleSheet = QStringLiteral(
"body { background: %1; color: %2; }" \
"table.logtable td { padding: 9px 8px 9px; }" \
"a { color: %3; }" \
"a:visited { color: %4; } "
).arg(palette.background().color().name(),
palette.text().color().name(),
palette.link().color().name(),
palette.linkVisited().color().name());
auto view = new QTextBrowser();
view->setAttribute(Qt::WA_DeleteOnClose);
view->setWindowTitle(xi18nd("@title:window", "<application>Git</application> Log"));
view->setOpenLinks(false);
view->setOpenExternalLinks(false);
connect(view, &QTextBrowser::anchorClicked, this, &FileViewGitPlugin::showDiff);
view->setHtml(QStringLiteral(
"<html>" \
"<style> %1 </style>" \
"<table class=\"logtable\">" \
"<tr bgcolor=\"%2\">" \
"<td> %3 </td> <td> %4 </td> <td> %5 </p> </td> <td> %6 </td>" \
"</tr>" \
"%7" \
"</table>" \
"</html>"
).arg(styleSheet,
palette.highlight().color().name(),
i18nc("Git commit hash", "Commit"),
i18nc("Git commit date", "Date"),
i18nc("Git commit message", "Message"),
i18nc("Git commit author", "Author"),
gitOutput));
view->resize(QSize(720, 560));
view->show();
}
void FileViewGitPlugin::checkout()
{
CheckoutDialog dialog;
......
......@@ -56,6 +56,8 @@ private slots:
void createTag();
void push();
void pull();
void log();
void showDiff(const QUrl &link);
void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
void slotOperationError();
......@@ -112,6 +114,7 @@ private:
QAction* m_tagAction;
QAction* m_pushAction;
QAction* m_pullAction;
QAction* m_logAction;
QString m_currentDir;
QProcess m_process;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment