forked from qt-creator/qt-creator
Git: Support change links on commit editor
Useful for commit messages with "reverts <hash>" for example. Can later be extended for interactive rebase Change-Id: Ibf77433ecddfacbd8d443636ddbc406bda474aa7 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
b90e3bbd8b
commit
05a6fc48ba
@@ -794,6 +794,19 @@ QString GitClient::findGitDirForRepository(const QString &repositoryDir) const
|
||||
return res;
|
||||
}
|
||||
|
||||
QString GitClient::findRepositoryForGitDir(const QString &gitDir) const
|
||||
{
|
||||
static QHash<QString, QString> gitDirCache;
|
||||
QString &res = gitDirCache[gitDir];
|
||||
if (!res.isEmpty())
|
||||
return res;
|
||||
QByteArray outputText;
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("rev-parse") << QLatin1String("--show-toplevel");
|
||||
fullySynchronousGit(gitDir, arguments, &outputText, 0, false);
|
||||
return QString::fromLocal8Bit(outputText.trimmed());
|
||||
}
|
||||
|
||||
VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *registerDynamicProperty,
|
||||
const QString &dynamicPropertyValue) const
|
||||
{
|
||||
|
@@ -138,6 +138,7 @@ public:
|
||||
|
||||
QString findRepositoryForDirectory(const QString &dir);
|
||||
QString findGitDirForRepository(const QString &repositoryDir) const;
|
||||
QString findRepositoryForGitDir(const QString &gitDir) const;
|
||||
|
||||
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
||||
void diff(const QString &workingDirectory, const QStringList &diffArgs,
|
||||
|
@@ -235,6 +235,16 @@ void GitEditor::init()
|
||||
new GitSubmitHighlighter(baseTextDocument().data());
|
||||
}
|
||||
|
||||
bool GitEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||
{
|
||||
bool res = VcsBaseEditorWidget::open(errorString, fileName, realFileName);
|
||||
if (editor()->id() == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID) {
|
||||
QFileInfo fi(fileName);
|
||||
setSource(GitPlugin::instance()->gitClient()->findRepositoryForGitDir(fi.absolutePath()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QString GitEditor::decorateVersion(const QString &revision) const
|
||||
{
|
||||
const QFileInfo fi(source());
|
||||
@@ -284,5 +294,11 @@ QString GitEditor::revisionSubject(const QTextBlock &inBlock) const
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool GitEditor::supportChangeLinks() const
|
||||
{
|
||||
return VcsBaseEditorWidget::supportChangeLinks()
|
||||
|| (editor()->id() == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Git
|
||||
|
@@ -60,6 +60,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void init();
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
QSet<QString> annotationChanges() const;
|
||||
QString changeUnderCursor(const QTextCursor &) const;
|
||||
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
|
||||
@@ -68,6 +69,7 @@ private:
|
||||
bool isValidRevision(const QString &revision) const;
|
||||
void addChangeActions(QMenu *menu, const QString &change);
|
||||
QString revisionSubject(const QTextBlock &inBlock) const;
|
||||
bool supportChangeLinks() const;
|
||||
|
||||
mutable QRegExp m_changeNumberPattern;
|
||||
QString m_currentChange;
|
||||
|
@@ -663,6 +663,17 @@ void VcsBaseEditorWidget::setLogEntryPattern(const QRegExp &pattern)
|
||||
d->m_logEntryPattern = pattern;
|
||||
}
|
||||
|
||||
bool VcsBaseEditorWidget::supportChangeLinks() const
|
||||
{
|
||||
switch (d->m_parameters->type) {
|
||||
case LogOutput:
|
||||
case AnnotateOutput:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void VcsBaseEditorWidget::init()
|
||||
{
|
||||
d->m_editor = editor();
|
||||
@@ -963,7 +974,7 @@ void VcsBaseEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
bool overrideCursor = false;
|
||||
Qt::CursorShape cursorShape;
|
||||
|
||||
if (d->m_parameters->type == LogOutput || d->m_parameters->type == AnnotateOutput) {
|
||||
if (supportChangeLinks()) {
|
||||
// Link emulation behaviour for 'click on change-interaction'
|
||||
const QTextCursor cursor = cursorForPosition(e->pos());
|
||||
Internal::AbstractTextCursorHandler *handler = d->findTextCursorHandler(cursor);
|
||||
@@ -987,7 +998,7 @@ void VcsBaseEditorWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
const bool wasDragging = d->m_mouseDragging;
|
||||
d->m_mouseDragging = false;
|
||||
if (!wasDragging && (d->m_parameters->type == LogOutput || d->m_parameters->type == AnnotateOutput)) {
|
||||
if (!wasDragging && supportChangeLinks()) {
|
||||
if (e->button() == Qt::LeftButton &&!(e->modifiers() & Qt::ShiftModifier)) {
|
||||
const QTextCursor cursor = cursorForPosition(e->pos());
|
||||
Internal::AbstractTextCursorHandler *handler = d->findTextCursorHandler(cursor);
|
||||
|
@@ -103,6 +103,7 @@ protected:
|
||||
void setDiffFilePattern(const QRegExp &pattern);
|
||||
// Pattern for log entry. hash/revision number must be in the first capture group
|
||||
void setLogEntryPattern(const QRegExp &pattern);
|
||||
virtual bool supportChangeLinks() const;
|
||||
|
||||
public:
|
||||
virtual void init();
|
||||
|
Reference in New Issue
Block a user