forked from qt-creator/qt-creator
Vcs: Simplify state detection code
Simplify handling of temporary files, clean up and simplify the code a bit, remove "project nodes" which can not be open in an editor (and do not use the '#'-syntax anymore). Side effect is that files in git repositories in $TEMPDIR now work as expected. Task-number: QTCREATORBUG-15053 Change-Id: Ib5918301ec2f0ab5d0985edba8f6c1cc1aae3f0b Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -263,59 +263,52 @@ void StateListener::slotStateChanged()
|
|||||||
// folder?
|
// folder?
|
||||||
State state;
|
State state;
|
||||||
IDocument *currentDocument = EditorManager::currentDocument();
|
IDocument *currentDocument = EditorManager::currentDocument();
|
||||||
if (!currentDocument) {
|
if (currentDocument) {
|
||||||
state.currentFile.clear();
|
|
||||||
} else {
|
|
||||||
state.currentFile = currentDocument->filePath().toString();
|
state.currentFile = currentDocument->filePath().toString();
|
||||||
if (state.currentFile.isEmpty() || currentDocument->isTemporary())
|
if (state.currentFile.isEmpty() || currentDocument->isTemporary())
|
||||||
state.currentFile = VcsBasePlugin::source(currentDocument);
|
state.currentFile = VcsBasePlugin::source(currentDocument);
|
||||||
}
|
}
|
||||||
QScopedPointer<QFileInfo> currentFileInfo; // Instantiate QFileInfo only once if required.
|
|
||||||
if (!state.currentFile.isEmpty()) {
|
|
||||||
const bool isTempFile = state.currentFile.startsWith(QDir::tempPath());
|
|
||||||
// Quick check: Does it look like a patch?
|
|
||||||
const bool isPatch = state.currentFile.endsWith(QLatin1String(".patch"))
|
|
||||||
|| state.currentFile.endsWith(QLatin1String(".diff"));
|
|
||||||
if (isPatch) {
|
|
||||||
// Patch: Figure out a name to display. If it is a temp file, it could be
|
|
||||||
// Codepaster. Use the display name of the editor.
|
|
||||||
state.currentPatchFile = state.currentFile;
|
|
||||||
if (isTempFile)
|
|
||||||
state.currentPatchFileDisplayName = displayNameOfEditor(state.currentPatchFile);
|
|
||||||
if (state.currentPatchFileDisplayName.isEmpty()) {
|
|
||||||
currentFileInfo.reset(new QFileInfo(state.currentFile));
|
|
||||||
state.currentPatchFileDisplayName = currentFileInfo->fileName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// For actual version control operations on it:
|
|
||||||
// Do not show temporary files and project folders ('#')
|
|
||||||
if (isTempFile || state.currentFile.contains(QLatin1Char('#')))
|
|
||||||
state.currentFile.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the file and its control. Do not use the file unless we find one
|
// Get the file and its control. Do not use the file unless we find one
|
||||||
IVersionControl *fileControl = 0;
|
IVersionControl *fileControl = 0;
|
||||||
|
|
||||||
if (!state.currentFile.isEmpty()) {
|
if (!state.currentFile.isEmpty()) {
|
||||||
if (currentFileInfo.isNull())
|
QFileInfo currentFi(state.currentFile);
|
||||||
currentFileInfo.reset(new QFileInfo(state.currentFile));
|
|
||||||
if (currentFileInfo->isDir()) {
|
if (currentFi.exists()) {
|
||||||
state.currentFile.clear();
|
// Quick check: Does it look like a patch?
|
||||||
state.currentFileDirectory = currentFileInfo->absoluteFilePath();
|
const bool isPatch = state.currentFile.endsWith(QLatin1String(".patch"))
|
||||||
} else {
|
|| state.currentFile.endsWith(QLatin1String(".diff"));
|
||||||
state.currentFileDirectory = currentFileInfo->absolutePath();
|
if (isPatch) {
|
||||||
state.currentFileName = currentFileInfo->fileName();
|
// Patch: Figure out a name to display. If it is a temp file, it could be
|
||||||
|
// Codepaster. Use the display name of the editor.
|
||||||
|
state.currentPatchFile = state.currentFile;
|
||||||
|
state.currentPatchFileDisplayName = displayNameOfEditor(state.currentPatchFile);
|
||||||
|
if (state.currentPatchFileDisplayName.isEmpty())
|
||||||
|
state.currentPatchFileDisplayName = currentFi.fileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentFi.isDir()) {
|
||||||
|
state.currentFile.clear();
|
||||||
|
state.currentFileDirectory = currentFi.absoluteFilePath();
|
||||||
|
} else {
|
||||||
|
state.currentFileDirectory = currentFi.absolutePath();
|
||||||
|
state.currentFileName = currentFi.fileName();
|
||||||
|
}
|
||||||
|
fileControl = VcsManager::findVersionControlForDirectory(state.currentFileDirectory,
|
||||||
|
&state.currentFileTopLevel);
|
||||||
}
|
}
|
||||||
fileControl = VcsManager::findVersionControlForDirectory(
|
|
||||||
state.currentFileDirectory,
|
|
||||||
&state.currentFileTopLevel);
|
|
||||||
if (!fileControl)
|
if (!fileControl)
|
||||||
state.clearFile();
|
state.clearFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for project, find the control
|
// Check for project, find the control
|
||||||
IVersionControl *projectControl = 0;
|
IVersionControl *projectControl = 0;
|
||||||
Project *currentProject = ProjectTree::currentProject();
|
Project *currentProject = ProjectTree::currentProject();
|
||||||
if (!currentProject)
|
if (!currentProject)
|
||||||
currentProject = SessionManager::startupProject();
|
currentProject = SessionManager::startupProject();
|
||||||
|
|
||||||
if (currentProject) {
|
if (currentProject) {
|
||||||
state.currentProjectPath = currentProject->projectDirectory().toString();
|
state.currentProjectPath = currentProject->projectDirectory().toString();
|
||||||
state.currentProjectName = currentProject->displayName();
|
state.currentProjectName = currentProject->displayName();
|
||||||
@@ -329,14 +322,14 @@ void StateListener::slotStateChanged()
|
|||||||
state.clearProject(); // No control found
|
state.clearProject(); // No control found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble state and emit signal.
|
// Assemble state and emit signal.
|
||||||
IVersionControl *vc = fileControl;
|
IVersionControl *vc = fileControl;
|
||||||
if (!vc)
|
if (!vc)
|
||||||
vc = projectControl;
|
vc = projectControl;
|
||||||
if (!vc)
|
if (!vc)
|
||||||
state.clearPatchFile(); // Need a repository to patch
|
state.clearPatchFile(); // Need a repository to patch
|
||||||
if (debug)
|
|
||||||
qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control"));
|
|
||||||
EditorManager::updateWindowTitles();
|
EditorManager::updateWindowTitles();
|
||||||
emit stateChanged(state, vc);
|
emit stateChanged(state, vc);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user