forked from qt-creator/qt-creator
VCS: Introduce Base class for VCS plugins, use in git.
Fixes: - Cannot diff a file that does not belong to a project - Cannot commit when a temporary diff/log view is open due to the current file pointing to a temporary directory - git's project-related actions not passing the correct relative path. Implementation: - Centralize code to listen for Qt Creator's relevant state changes in VCSBasePlugin, dispatching the changes to the instances affected. (avoiding multiple invocations of searches/QFileInfo on current). - Do the same for the corelistener catching closing SubmitEditors. - Introduce VCSBasePluginState representing the relevant state (current file/project). - Call git with working directory set and relative arguments - Remove setEnabled/isEnabled() logic of IVersionControl - Pass toplevel from VCSManager to avoid duplicate searches.
This commit is contained in:
@@ -630,5 +630,41 @@ bool VCSBaseEditor::gotoLineOfEditor(Core::IEditor *e, int lineNumber)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return source file or directory string depending on parameters
|
||||
// ('git diff XX' -> 'XX' , 'git diff XX file' -> 'XX/file').
|
||||
QString VCSBaseEditor::getSource(const QString &workingDirectory,
|
||||
const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
return workingDirectory;
|
||||
|
||||
QString rc = workingDirectory;
|
||||
const QChar slash = QLatin1Char('/');
|
||||
if (!rc.isEmpty() && !(rc.endsWith(slash) || rc.endsWith(QLatin1Char('\\'))))
|
||||
rc += slash;
|
||||
rc += fileName;
|
||||
return rc;
|
||||
}
|
||||
|
||||
QString VCSBaseEditor::getSource(const QString &workingDirectory,
|
||||
const QStringList &fileNames)
|
||||
{
|
||||
return fileNames.size() == 1 ?
|
||||
getSource(workingDirectory, fileNames.front()) :
|
||||
workingDirectory;
|
||||
}
|
||||
|
||||
QString VCSBaseEditor::getTitleId(const QString &workingDirectory, const QStringList &fileNames)
|
||||
{
|
||||
switch (fileNames.size()) {
|
||||
case 0:
|
||||
return workingDirectory;
|
||||
case 1:
|
||||
return fileNames.front();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return fileNames.join(QLatin1String(", "));
|
||||
}
|
||||
|
||||
} // namespace VCSBase
|
||||
|
||||
Reference in New Issue
Block a user