void JsonSummaryPage::versionControlHasChanged() { IVersionControl *vc = currentVersionControl(); m_wizard->setProperty("VersionControl", vc ? vc->id().toString() : QLatin1String("")); updateFileList(); }
void JsonSummaryPage::summarySettingsHaveChanged() { IVersionControl *vc = currentVersionControl(); m_wizard->setValue(QLatin1String(KEY_VERSIONCONTROL), vc ? vc->id().toString() : QString()); updateProjectData(currentNode()); }
bool VCSManager::showDeleteDialog(const QString &fileName) { IVersionControl *vc = findVersionControlForDirectory(QFileInfo(fileName).absolutePath()); if (!vc || !vc->supportsOperation(IVersionControl::DeleteOperation)) return true; const QString title = QCoreApplication::translate("VCSManager", "Version Control"); const QString msg = QCoreApplication::translate("VCSManager", "Would you like to remove this file from the version control system (%1)?\n" "Note: This might remove the local file.").arg(vc->name()); const QMessageBox::StandardButton button = QMessageBox::question(0, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (button != QMessageBox::Yes) return true; return vc->vcsDelete(fileName); }
QString StateListener::windowTitleVcsTopic(const QString &filePath) { QString searchPath; if (!filePath.isEmpty()) { searchPath = QFileInfo(filePath).absolutePath(); } else { // use single project's information if there is only one loaded. const QList<Project *> projects = SessionManager::projects(); if (projects.size() == 1) searchPath = projects.first()->projectDirectory().toString(); } if (searchPath.isEmpty()) return QString(); QString topLevelPath; IVersionControl *vc = VcsManager::findVersionControlForDirectory( searchPath, &topLevelPath); return (vc && !topLevelPath.isEmpty()) ? vc->vcsTopic(topLevelPath) : QString(); }
bool FileUtils::renameFile(const QString &orgFilePath, const QString &newFilePath) { if (orgFilePath == newFilePath) return false; QString dir = QFileInfo(orgFilePath).absolutePath(); IVersionControl *vc = VcsManager::findVersionControlForDirectory(dir); bool result = false; if (vc && vc->supportsOperation(IVersionControl::MoveOperation)) result = vc->vcsMove(orgFilePath, newFilePath); if (!result) // The moving via vcs failed or the vcs does not support moving, fall back result = fileSystemRenameFile(orgFilePath, newFilePath); if (result) { // yeah we moved, tell the filemanager about it Core::DocumentManager::renamedFile(orgFilePath, newFilePath); } return result; }
void VcsCommandPage::delayedInitialize() { auto wiz = qobject_cast<JsonWizard *>(wizard()); QTC_ASSERT(wiz, return); const QString vcsId = wiz->expander()->expand(m_vcsId); IVersionControl *vc = VcsManager::versionControl(Id::fromString(vcsId)); if (!vc) { qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage", "\"%1\" (%2) not found.") .arg(QLatin1String(VCSCOMMAND_VCSID), vcsId); return; } if (!vc->isConfigured()) { qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage", "Version control \"%1\" is not configured.") .arg(vcsId); return; } if (!vc->supportsOperation(IVersionControl::InitialCheckoutOperation)) { qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage", "Version control \"%1\" does not support initial checkouts.") .arg(vcsId); return; } const QString repo = wiz->expander()->expand(m_repository); if (repo.isEmpty()) { qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage", "\"%1\" is empty when trying to run checkout.") .arg(QLatin1String(VCSCOMMAND_REPO)); return; } const QString base = wiz->expander()->expand(m_directory); if (!QDir(base).exists()) { qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage", "\"%1\" (%2) does not exist.") .arg(QLatin1String(VCSCOMMAND_DIR), base); return; } const QString name = wiz->expander()->expand(m_name); if (name.isEmpty()) { qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage", "\"%1\" is empty when trying to run checkout.") .arg(QLatin1String(VCSCOMMAND_CHECKOUTNAME)); return; } const QString runMessage = wiz->expander()->expand(m_runMessage); if (!runMessage.isEmpty()) setStartedStatus(runMessage); QStringList extraArgs; foreach (const QString &in, m_arguments) { const QString tmp = wiz->expander()->expand(in); if (tmp.isEmpty()) continue; if (tmp == QStringLiteral("\"\"")) extraArgs << QString(); extraArgs << tmp; } ShellCommand *command = vc->createInitialCheckoutCommand(repo, Utils::FileName::fromString(base), name, extraArgs); foreach (const JobData &job, m_additionalJobs) { QTC_ASSERT(!job.job.isEmpty(), continue); if (!JsonWizard::boolFromVariant(job.condition, wiz->expander())) continue; QString commandString = wiz->expander()->expand(job.job.at(0)); if (commandString.isEmpty()) continue; QStringList args; for (int i = 1; i < job.job.count(); ++i) { const QString tmp = wiz->expander()->expand(job.job.at(i)); if (tmp.isEmpty() && job.skipEmptyArguments) continue; args << tmp; } const QString dir = wiz->expander()->expand(job.workDirectory); const int timeoutS = command->defaultTimeoutS() * job.timeOutFactor; command->addJob(Utils::FileName::fromUserInput(commandString), args, timeoutS, dir); }
QString VcsJsExtension::displayName(const QString &vcsId) const { IVersionControl *vc = VcsManager::versionControl(Id::fromString(vcsId)); return vc ? vc->displayName() : QString(); }
bool VcsJsExtension::isConfigured(const QString &vcsId) const { IVersionControl *vc = VcsManager::versionControl(Id::fromString(vcsId)); return vc && vc->isConfigured(); }
void StateListener::slotStateChanged() { // Get the current file. Are we on a temporary submit editor indicated by // temporary path prefix or does the file contains a hash, indicating a project // folder? State state; IDocument *currentDocument = EditorManager::currentDocument(); if (!currentDocument) { state.currentFile.clear(); } else { state.currentFile = currentDocument->filePath().toString(); if (state.currentFile.isEmpty() || currentDocument->isTemporary()) 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 IVersionControl *fileControl = 0; if (!state.currentFile.isEmpty()) { if (currentFileInfo.isNull()) currentFileInfo.reset(new QFileInfo(state.currentFile)); if (currentFileInfo->isDir()) { state.currentFile.clear(); state.currentFileDirectory = currentFileInfo->absoluteFilePath(); } else { state.currentFileDirectory = currentFileInfo->absolutePath(); state.currentFileName = currentFileInfo->fileName(); } fileControl = VcsManager::findVersionControlForDirectory( state.currentFileDirectory, &state.currentFileTopLevel); if (!fileControl) state.clearFile(); } // Check for project, find the control IVersionControl *projectControl = 0; Project *currentProject = ProjectTree::currentProject(); if (!currentProject) currentProject = SessionManager::startupProject(); if (currentProject) { state.currentProjectPath = currentProject->projectDirectory().toString(); state.currentProjectName = currentProject->displayName(); projectControl = VcsManager::findVersionControlForDirectory(state.currentProjectPath, &state.currentProjectTopLevel); if (projectControl) { // If we have both, let the file's one take preference if (fileControl && projectControl != fileControl) state.clearProject(); } else { state.clearProject(); // No control found } } // Assemble state and emit signal. IVersionControl *vc = fileControl; if (!vc) vc = projectControl; if (!vc) state.clearPatchFile(); // Need a repository to patch if (debug) qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control")); EditorManager::updateWindowTitles(); emit stateChanged(state, vc); }