Commit 58ef8754 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Allow seeing file history on clicking commit

parent 41c50ec0
......@@ -128,4 +128,23 @@ FileHistoryWidget::FileHistoryWidget(const QString &file, QWidget *parent)
model->refresh(parseCommits(getFileHistory(file)));
m_listView->setModel(model);
connect(m_listView, &QListView::clicked, this, &FileHistoryWidget::itemClicked);
}
void FileHistoryWidget::itemClicked(const QModelIndex &idx)
{
QProcess git;
QFileInfo fi(m_file);
git.setWorkingDirectory(fi.absolutePath());
QStringList args{QStringLiteral("diff"), QString::fromUtf8(idx.data(CommitListModel::Hash).toByteArray()), QStringLiteral("--"), m_file};
git.start(QStringLiteral("git"), args, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return;
}
QByteArray contents = git.readAll();
// we send this signal to the parent, which will pass it on to
// the GitWidget from where a temporary file is opened
Q_EMIT commitClicked(fi.fileName(), QStringLiteral("XXXXXX %1.diff"), contents);
}
}
......@@ -11,6 +11,9 @@ class FileHistoryWidget : public QWidget
public:
explicit FileHistoryWidget(const QString &file, QWidget *parent = nullptr);
private Q_SLOTS:
void itemClicked(const QModelIndex &idx);
private:
QPushButton m_backBtn;
QListView *m_listView;
......@@ -18,6 +21,7 @@ private:
Q_SIGNALS:
void backClicked();
void commitClicked(const QString &file, const QString &templString, const QByteArray &contents);
};
#endif // FILEHISTORYWIDGET_H
......@@ -251,7 +251,7 @@ void GitWidget::openAtHEAD(const QString &file)
if (es != QProcess::NormalExit || exitCode != 0) {
sendMessage(i18n("Failed to open file at HEAD. Error:\n%1", QString::fromUtf8(git.readAllStandardError())), true);
} else {
openTempFile(QFileInfo(file).fileName(), QStringLiteral("XXXXXX - (HEAD) - %1"));
openTempFile(QFileInfo(file).fileName(), QStringLiteral("XXXXXX - (HEAD) - %1"), git.readAllStandardOutput());
}
});
......@@ -278,7 +278,7 @@ void GitWidget::showDiff(const QString &file, bool staged)
sendMessage(i18n("Failed to get Diff of file. Error:\n%1", QString::fromUtf8(git.readAllStandardError())), true);
} else {
const QString filename = file.isEmpty() ? QString() : QFileInfo(file).fileName();
openTempFile(filename, QStringLiteral("XXXXXX %1.diff"));
openTempFile(filename, QStringLiteral("XXXXXX %1.diff"), git.readAllStandardOutput());
}
});
......@@ -495,8 +495,12 @@ void GitWidget::clearTempFile(KTextEditor::Document *document)
m_tempFiles.end());
}
void GitWidget::openTempFile(const QString &file, const QString &templatString)
void GitWidget::openTempFile(const QString &file, const QString &templatString, const QByteArray &contents)
{
if (contents.isEmpty()) {
return;
}
std::unique_ptr<QTemporaryFile> f(new QTemporaryFile);
if (!templatString.isEmpty() && !file.isEmpty()) {
f->setFileTemplate(templatString.arg(file));
......@@ -504,12 +508,13 @@ void GitWidget::openTempFile(const QString &file, const QString &templatString)
f->setFileTemplate(templatString);
}
if (!f->open()) {
qWarning() << "Gitwidget: Failed to open temp file";
qWarning() << "Gitwidget: Failed to open temp file" << f->errorString();
return;
}
f->write(git.readAllStandardOutput());
f->write(contents);
f->flush();
const QUrl tempFileUrl(QUrl::fromLocalFile(f->fileName()));
QPointer<KTextEditor::View> v = m_mainWin->openUrl(tempFileUrl);
......
......@@ -45,7 +45,7 @@ public:
using TempFileViewPair = std::pair<std::unique_ptr<QTemporaryFile>, QPointer<KTextEditor::View>>;
std::vector<TempFileViewPair> *tempFilesVector();
void openTempFile(const QString &file, const QString &templatString);
void openTempFile(const QString &file, const QString &templatString, const QByteArray &contents);
private:
QToolButton *m_menuBtn;
......
......@@ -481,6 +481,14 @@ void KateProjectPluginView::switchToProject(const QDir &dir)
}
}
void KateProjectPluginView::openTempFile(const QString &file, const QString &templateString, const QByteArray &contents)
{
if (QWidget *current = m_stackedgitViews->currentWidget()) {
m_stackedgitViews->setFocusProxy(current);
static_cast<GitWidget *>(current)->openTempFile(file, templateString, contents);
}
}
void KateProjectPluginView::slotViewCreated(KTextEditor::View *view)
{
/**
......
......@@ -115,6 +115,11 @@ public Q_SLOTS:
*/
void switchToProject(const QDir &dir);
/**
* tells Git widget to open a temporary file for diff etc.
*/
void openTempFile(const QString &file, const QString &templateString, const QByteArray &contents);
private Q_SLOTS:
/**
* Plugin config updated
......
......@@ -148,6 +148,7 @@ void KateProjectView::showFileGitHistory(const QString &file)
// create on demand and on switch back delete
auto fhs = new FileHistoryWidget(file);
connect(fhs, &FileHistoryWidget::backClicked, this, &KateProjectView::setTreeViewAsCurrent);
connect(fhs, &FileHistoryWidget::commitClicked, m_pluginView, &KateProjectPluginView::openTempFile);
m_stackWidget->addWidget(fhs);
m_stackWidget->setCurrentWidget(fhs);
}
......@@ -447,7 +447,7 @@ void StashDialog::showStash(const QByteArray &index)
if (es != QProcess::NormalExit || exitCode != 0) {
gitWidget->sendMessage(i18n("Show stash failed. Error:\n%1", QString::fromUtf8(gitWidget->gitprocess()->readAllStandardError())), true);
} else {
gitWidget->openTempFile(QString(), QStringLiteral("XXXXXX.diff"));
gitWidget->openTempFile(QString(), QStringLiteral("XXXXXX.diff"), gitWidget->gitprocess()->readAllStandardOutput());
}
});
......
......@@ -68,9 +68,13 @@ void KatePluginManager::setupPluginList()
// handle all install KTextEditor plugins
m_pluginList.clear();
QSet<QString> unique;
const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("ktexteditor"), [](const KPluginMetaData &md) {
return md.serviceTypes().contains(QLatin1String("KTextEditor/Plugin"));
});
// const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("ktexteditor"), [](const KPluginMetaData &md) {
// return md.serviceTypes().contains(QLatin1String("KTextEditor/Plugin"));
// });
const QVector<KPluginMetaData> plugins =
KPluginLoader::findPlugins(QStringLiteral("/home/waqar/kde/src/kde/applications/kate/Release/bin"), [](const KPluginMetaData &md) {
return md.serviceTypes().contains(QLatin1String("KTextEditor/Plugin"));
});
for (const auto &pluginMetaData : plugins) {
KatePluginInfo info;
info.metaData = pluginMetaData;
......
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