Commit 8bb87fcd authored by Friedemann Kleint's avatar Friedemann Kleint

VCS[Mercurial]: Single file log annotation.

Task-number: QTCREATORBUG-503
parent bcba9ea6
......@@ -159,11 +159,22 @@ QString MercurialClient::branchQuerySync(const QString &repositoryRoot)
return QLatin1String("Unknown Branch");
}
void MercurialClient::annotate(const QString &workingDir, const QString &file)
void MercurialClient::slotAnnotateRevisionRequested(const QString &source, const QString &change, int lineNumber)
{
QStringList args;
args << QLatin1String("annotate") << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d") << file;
const QFileInfo fi(source);
annotate(fi.absolutePath(), fi.fileName(), change, lineNumber);
}
void MercurialClient::annotate(const QString &workingDir, const QString &file,
const QString revision /* = QString() */,
int lineNumber /* = -1 */)
{
Q_UNUSED(lineNumber)
QStringList args;
args << QLatin1String("annotate") << QLatin1String("-u") << QLatin1String("-c") << QLatin1String("-d");
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
args << file;
const QString kind = QLatin1String(Constants::ANNOTATELOG);
const QString id = VCSBase::VCSBaseEditor::getSource(workingDir, QStringList(file));
const QString title = tr("Hg Annotate %1").arg(id);
......@@ -197,7 +208,8 @@ void MercurialClient::diff(const QString &workingDir, const QStringList &files)
}
void MercurialClient::log(const QString &workingDir, const QStringList &files)
void MercurialClient::log(const QString &workingDir, const QStringList &files,
bool enableAnnotationContextMenu)
{
QStringList args(QLatin1String("log"));
if (!files.empty())
......@@ -210,6 +222,7 @@ void MercurialClient::log(const QString &workingDir, const QStringList &files)
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingDir, true,
"log", id);
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
QSharedPointer<HgTask> job(new HgTask(workingDir, args, editor));
enqueueJob(job);
......@@ -440,6 +453,8 @@ VCSBase::VCSBaseEditor *MercurialClient::createVCSEditor(const QString &kind, QS
outputEditor = core->editorManager()->openEditorWithContents(kind, &title, progressMsg);
outputEditor->file()->setProperty(registerDynamicProperty, dynamicPropertyValue);
baseEditor = VCSBase::VCSBaseEditor::getVcsBaseEditor(outputEditor);
connect(baseEditor, SIGNAL(annotateRevisionRequested(QString,QString,int)),
this, SLOT(slotAnnotateRevisionRequested(QString,QString,int)));
QTC_ASSERT(baseEditor, return 0);
baseEditor->setSource(source);
if (setSourceCodec)
......
......@@ -64,9 +64,11 @@ public:
bool remove(const QString &workingDir, const QString &fileName);
bool manifestSync(const QString &repository, const QString &filename);
QString branchQuerySync(const QString &repositoryRoot);
void annotate(const QString &workingDir, const QString &files);
void annotate(const QString &workingDir, const QString &files,
const QString revision = QString(), int lineNumber = -1);
void diff(const QString &workingDir, const QStringList &files = QStringList());
void log(const QString &workingDir, const QStringList &files = QStringList());
void log(const QString &workingDir, const QStringList &files = QStringList(),
bool enableAnnotationContextMenu = false);
void import(const QString &repositoryRoot, const QStringList &files);
void pull(const QString &repositoryRoot, const QString &repository = QString());
void push(const QString &repositoryRoot, const QString &repository = QString());
......@@ -93,6 +95,7 @@ public slots:
private slots:
void statusParser(const QByteArray &data);
void slotAnnotateRevisionRequested(const QString &source, const QString &change, int lineNumber);
private:
bool executeHgSynchronously(const QString &workingDir,
......
......@@ -272,7 +272,7 @@ void MercurialPlugin::logCurrentFile()
{
const VCSBase::VCSBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
client->log(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), true);
}
void MercurialPlugin::revertCurrentFile()
......
......@@ -62,6 +62,8 @@
#include <QtGui/QTextEdit>
#include <QtGui/QComboBox>
#include <QtGui/QToolBar>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
namespace VCSBase {
......@@ -159,6 +161,7 @@ struct VCSBaseEditorPrivate
QList<int> m_diffSections; // line number where this section starts
int m_cursorLine;
QString m_annotateRevisionTextFormat;
QString m_copyRevisionTextFormat;
bool m_fileLogAnnotateEnabled;
};
......@@ -166,6 +169,7 @@ VCSBaseEditorPrivate::VCSBaseEditorPrivate(const VCSBaseEditorParameters *type)
m_parameters(type),
m_cursorLine(-1),
m_annotateRevisionTextFormat(VCSBaseEditor::tr("Annotate \"%1\"")),
m_copyRevisionTextFormat(VCSBaseEditor::tr("Copy \"%1\"")),
m_fileLogAnnotateEnabled(false)
{
}
......@@ -229,6 +233,16 @@ void VCSBaseEditor::setAnnotateRevisionTextFormat(const QString &f)
d->m_annotateRevisionTextFormat = f;
}
QString VCSBaseEditor::copyRevisionTextFormat() const
{
return d->m_copyRevisionTextFormat;
}
void VCSBaseEditor::setCopyRevisionTextFormat(const QString &f)
{
d->m_copyRevisionTextFormat = f;
}
bool VCSBaseEditor::isFileLogAnnotateEnabled() const
{
return d->m_fileLogAnnotateEnabled;
......@@ -381,6 +395,14 @@ QAction *VCSBaseEditor::createAnnotateAction(const QString &change)
return a;
}
QAction *VCSBaseEditor::createCopyRevisionAction(const QString &change)
{
QAction *a = new QAction(d->m_copyRevisionTextFormat.arg(change), 0);
a->setData(change);
connect(a, SIGNAL(triggered()), this, SLOT(slotCopyRevision()));
return a;
}
void VCSBaseEditor::contextMenuEvent(QContextMenuEvent *e)
{
QMenu *menu = createStandardContextMenu();
......@@ -391,12 +413,14 @@ void VCSBaseEditor::contextMenuEvent(QContextMenuEvent *e)
switch (d->m_parameters->type) {
case LogOutput: // Describe current / Annotate file of current
menu->addSeparator();
menu->addAction(createCopyRevisionAction(d->m_currentChange));
menu->addAction(createDescribeAction(d->m_currentChange));
if (d->m_fileLogAnnotateEnabled)
menu->addAction(createAnnotateAction(d->m_currentChange));
break;
case AnnotateOutput: { // Describe current / annotate previous
menu->addSeparator();
menu->addAction(createCopyRevisionAction(d->m_currentChange));
menu->addAction(createDescribeAction(d->m_currentChange));
const QStringList previousVersions = annotationPreviousVersions(d->m_currentChange);
if (!previousVersions.isEmpty()) {
......@@ -809,6 +833,11 @@ void VCSBaseEditor::slotAnnotateRevision()
editableInterface()->currentLine());
}
void VCSBaseEditor::slotCopyRevision()
{
QApplication::clipboard()->setText(d->m_currentChange);
}
QStringList VCSBaseEditor::annotationPreviousVersions(const QString &) const
{
return QStringList();
......
......@@ -91,6 +91,7 @@ class VCSBASE_EXPORT VCSBaseEditor : public TextEditor::BaseTextEditor
Q_PROPERTY(QString diffBaseDirectory READ diffBaseDirectory WRITE setDiffBaseDirectory)
Q_PROPERTY(QTextCodec *codec READ codec WRITE setCodec)
Q_PROPERTY(QString annotateRevisionTextFormat READ annotateRevisionTextFormat WRITE setAnnotateRevisionTextFormat)
Q_PROPERTY(QString copyRevisionTextFormat READ copyRevisionTextFormat WRITE setCopyRevisionTextFormat)
Q_PROPERTY(bool isFileLogAnnotateEnabled READ isFileLogAnnotateEnabled WRITE setFileLogAnnotateEnabled)
Q_OBJECT
protected:
......@@ -110,6 +111,10 @@ public:
QString annotateRevisionTextFormat() const;
void setAnnotateRevisionTextFormat(const QString &);
// Format for "Copy" revision menu entries. Should contain '%1" placeholder
QString copyRevisionTextFormat() const;
void setCopyRevisionTextFormat(const QString &);
// Enable "Annotate" context menu in file log view
// (set to true if the source is a single file and the VCS implements it)
bool isFileLogAnnotateEnabled() const;
......@@ -191,6 +196,7 @@ private slots:
void slotDiffBrowse(int);
void slotDiffCursorPositionChanged();
void slotAnnotateRevision();
void slotCopyRevision();
protected:
/* A helper that can be used to locate a file in a diff in case it
......@@ -217,6 +223,7 @@ private:
void jumpToChangeFromDiff(QTextCursor cursor);
QAction *createDescribeAction(const QString &change);
QAction *createAnnotateAction(const QString &change);
QAction *createCopyRevisionAction(const QString &change);
VCSBaseEditorPrivate *d;
};
......
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