forked from qt-creator/qt-creator
VCS: perforce, cvs, subversion: Goto current line in blame.
This commit is contained in:
@@ -760,14 +760,17 @@ void CVSPlugin::annotate(const QString &file)
|
|||||||
|
|
||||||
// Re-use an existing view if possible to support
|
// Re-use an existing view if possible to support
|
||||||
// the common usage pattern of continuously changing and diffing a file
|
// the common usage pattern of continuously changing and diffing a file
|
||||||
|
const int lineNumber = VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor(file);
|
||||||
|
|
||||||
if (Core::IEditor *editor = locateEditor("annotateFileName", file)) {
|
if (Core::IEditor *editor = locateEditor("annotateFileName", file)) {
|
||||||
editor->createNew(response.stdOut);
|
editor->createNew(response.stdOut);
|
||||||
|
VCSBase::VCSBaseEditor::gotoLineOfEditor(editor, lineNumber);
|
||||||
Core::EditorManager::instance()->activateEditor(editor);
|
Core::EditorManager::instance()->activateEditor(editor);
|
||||||
} else {
|
} else {
|
||||||
const QString title = QString::fromLatin1("cvs annotate %1").arg(QFileInfo(file).fileName());
|
const QString title = QString::fromLatin1("cvs annotate %1").arg(QFileInfo(file).fileName());
|
||||||
Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, file, codec);
|
Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, file, codec);
|
||||||
newEditor->setProperty("annotateFileName", file);
|
newEditor->setProperty("annotateFileName", file);
|
||||||
|
VCSBase::VCSBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -298,10 +298,10 @@ void GitClient::show(const QString &source, const QString &id)
|
|||||||
executeGit(workDir, arguments, editor);
|
executeGit(workDir, arguments, editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::blame(const QString &workingDirectory, const QString &fileName)
|
void GitClient::blame(const QString &workingDirectory, const QString &fileName, int lineNumber /* = -1 */)
|
||||||
{
|
{
|
||||||
if (Git::Constants::debug)
|
if (Git::Constants::debug)
|
||||||
qDebug() << "blame" << workingDirectory << fileName;
|
qDebug() << "blame" << workingDirectory << fileName << lineNumber;
|
||||||
QStringList arguments(QLatin1String("blame"));
|
QStringList arguments(QLatin1String("blame"));
|
||||||
arguments << QLatin1String("--") << fileName;
|
arguments << QLatin1String("--") << fileName;
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
|
|
||||||
void status(const QString &workingDirectory);
|
void status(const QString &workingDirectory);
|
||||||
void log(const QString &workingDirectory, const QString &fileName);
|
void log(const QString &workingDirectory, const QString &fileName);
|
||||||
void blame(const QString &workingDirectory, const QString &fileName);
|
void blame(const QString &workingDirectory, const QString &fileName, int lineNumber = -1);
|
||||||
void showCommit(const QString &workingDirectory, const QString &commit);
|
void showCommit(const QString &workingDirectory, const QString &commit);
|
||||||
void checkout(const QString &workingDirectory, const QString &file);
|
void checkout(const QString &workingDirectory, const QString &file);
|
||||||
void checkoutBranch(const QString &workingDirectory, const QString &branch);
|
void checkoutBranch(const QString &workingDirectory, const QString &branch);
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ void GitPlugin::statusFile()
|
|||||||
|
|
||||||
void GitPlugin::logFile()
|
void GitPlugin::logFile()
|
||||||
{
|
{
|
||||||
const QFileInfo fileInfo = currentFile();
|
const QFileInfo fileInfo = currentFile();
|
||||||
const QString fileName = fileInfo.fileName();
|
const QString fileName = fileInfo.fileName();
|
||||||
const QString workingDirectory = fileInfo.absolutePath();
|
const QString workingDirectory = fileInfo.absolutePath();
|
||||||
m_gitClient->log(workingDirectory, fileName);
|
m_gitClient->log(workingDirectory, fileName);
|
||||||
@@ -492,7 +492,9 @@ void GitPlugin::blameFile()
|
|||||||
const QFileInfo fileInfo = currentFile();
|
const QFileInfo fileInfo = currentFile();
|
||||||
const QString fileName = fileInfo.fileName();
|
const QString fileName = fileInfo.fileName();
|
||||||
const QString workingDirectory = fileInfo.absolutePath();
|
const QString workingDirectory = fileInfo.absolutePath();
|
||||||
m_gitClient->blame(workingDirectory, fileName);
|
|
||||||
|
m_gitClient->blame(workingDirectory, fileName,
|
||||||
|
VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor(fileInfo.absoluteFilePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitPlugin::logProject()
|
void GitPlugin::logProject()
|
||||||
|
|||||||
@@ -651,9 +651,11 @@ void PerforcePlugin::annotate(const QString &fileName)
|
|||||||
const PerforceResponse result = runP4Cmd(args, QStringList(),
|
const PerforceResponse result = runP4Cmd(args, QStringList(),
|
||||||
CommandToWindow|StdErrToWindow|ErrorToWindow, codec);
|
CommandToWindow|StdErrToWindow|ErrorToWindow, codec);
|
||||||
if (!result.error) {
|
if (!result.error) {
|
||||||
|
const int lineNumber = VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor(fileName);
|
||||||
const QFileInfo fi(fileName);
|
const QFileInfo fi(fileName);
|
||||||
showOutputInEditor(tr("p4 annotate %1").arg(fi.fileName()),
|
Core::IEditor *ed = showOutputInEditor(tr("p4 annotate %1").arg(fi.fileName()),
|
||||||
result.stdOut, VCSBase::AnnotateOutput, codec);
|
result.stdOut, VCSBase::AnnotateOutput, codec);
|
||||||
|
VCSBase::VCSBaseEditor::gotoLineOfEditor(ed, lineNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -690,7 +690,7 @@ void SubversionPlugin::startCommit(const QStringList &files)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_commitMessageFileName = changeTmpFile.fileName();
|
m_commitMessageFileName = changeTmpFile.fileName();
|
||||||
// TODO: Retrieve submit template from
|
// TODO: Regitctrieve submit template from
|
||||||
const QString submitTemplate;
|
const QString submitTemplate;
|
||||||
// Create a submit
|
// Create a submit
|
||||||
changeTmpFile.write(submitTemplate.toUtf8());
|
changeTmpFile.write(submitTemplate.toUtf8());
|
||||||
@@ -780,14 +780,17 @@ void SubversionPlugin::annotate(const QString &file)
|
|||||||
|
|
||||||
// Re-use an existing view if possible to support
|
// Re-use an existing view if possible to support
|
||||||
// the common usage pattern of continuously changing and diffing a file
|
// the common usage pattern of continuously changing and diffing a file
|
||||||
|
const int lineNumber = VCSBase::VCSBaseEditor::lineNumberOfCurrentEditor(file);
|
||||||
|
|
||||||
if (Core::IEditor *editor = locateEditor("annotateFileName", file)) {
|
if (Core::IEditor *editor = locateEditor("annotateFileName", file)) {
|
||||||
editor->createNew(response.stdOut);
|
editor->createNew(response.stdOut);
|
||||||
Core::EditorManager::instance()->activateEditor(editor);
|
VCSBase::VCSBaseEditor::gotoLineOfEditor(editor, lineNumber);
|
||||||
|
Core::EditorManager::instance()->activateEditor(editor);
|
||||||
} else {
|
} else {
|
||||||
const QString title = QString::fromLatin1("svn annotate %1").arg(QFileInfo(file).fileName());
|
const QString title = QString::fromLatin1("svn annotate %1").arg(QFileInfo(file).fileName());
|
||||||
Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, file, codec);
|
Core::IEditor *newEditor = showOutputInEditor(title, response.stdOut, VCSBase::AnnotateOutput, file, codec);
|
||||||
newEditor->setProperty("annotateFileName", file);
|
newEditor->setProperty("annotateFileName", file);
|
||||||
|
VCSBase::VCSBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/ifile.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <projectexplorer/editorconfiguration.h>
|
#include <projectexplorer/editorconfiguration.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
@@ -601,4 +602,33 @@ VCSBaseEditor *VCSBaseEditor::getVcsBaseEditor(const Core::IEditor *editor)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return line number of current editor if it matches.
|
||||||
|
int VCSBaseEditor::lineNumberOfCurrentEditor(const QString ¤tFile)
|
||||||
|
{
|
||||||
|
Core::IEditor *ed = Core::EditorManager::instance()->currentEditor();
|
||||||
|
if (!ed)
|
||||||
|
return -1;
|
||||||
|
if (!currentFile.isEmpty()) {
|
||||||
|
const Core::IFile *ifile = ed->file();
|
||||||
|
if (!ifile || ifile->fileName() != currentFile)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
const TextEditor::BaseTextEditorEditable *eda = qobject_cast<const TextEditor::BaseTextEditorEditable *>(ed);
|
||||||
|
if (!eda)
|
||||||
|
return -1;
|
||||||
|
return eda->currentLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VCSBaseEditor::gotoLineOfEditor(Core::IEditor *e, int lineNumber)
|
||||||
|
{
|
||||||
|
if (lineNumber >= 0 && e) {
|
||||||
|
if (TextEditor::BaseTextEditorEditable *be = qobject_cast<TextEditor::BaseTextEditorEditable*>(e)) {
|
||||||
|
be->gotoLine(lineNumber);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace VCSBase
|
} // namespace VCSBase
|
||||||
|
|||||||
@@ -119,6 +119,15 @@ public:
|
|||||||
// manager which is a BaseTextEditable.
|
// manager which is a BaseTextEditable.
|
||||||
static VCSBaseEditor *getVcsBaseEditor(const Core::IEditor *editor);
|
static VCSBaseEditor *getVcsBaseEditor(const Core::IEditor *editor);
|
||||||
|
|
||||||
|
// Utility to find the line number of the current editor. Optionally,
|
||||||
|
// pass in the file name to match it. To be used when jumping to current
|
||||||
|
// line number in a 'annnotate current file' slot, which checks if the
|
||||||
|
// current file originates from the current editor or the project selection.
|
||||||
|
static int lineNumberOfCurrentEditor(const QString ¤tFile = QString());
|
||||||
|
|
||||||
|
//Helper to go to line of editor if it is a text editor
|
||||||
|
static bool gotoLineOfEditor(Core::IEditor *e, int lineNumber);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void describeRequested(const QString &source, const QString &change);
|
void describeRequested(const QString &source, const QString &change);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user