void ProjectTree::updateExternalFileWarning() { Core::IDocument *document = qobject_cast<Core::IDocument *>(sender()); if (!document || document->filePath().isEmpty()) return; Core::InfoBar *infoBar = document->infoBar(); Core::Id externalFileId(EXTERNAL_FILE_WARNING); if (!document->isModified()) { infoBar->removeInfo(externalFileId); return; } if (!infoBar->canInfoBeAdded(externalFileId)) return; const FileName fileName = document->filePath(); const QList<Project *> projects = SessionManager::projects(); if (projects.isEmpty()) return; foreach (Project *project, projects) { FileName projectDir = project->projectDirectory(); if (projectDir.isEmpty()) continue; if (fileName.isChildOf(projectDir)) return; // External file. Test if it under the same VCS QString topLevel; if (Core::VcsManager::findVersionControlForDirectory(projectDir.toString(), &topLevel) && fileName.isChildOf(FileName::fromString(topLevel))) { return; } }
void ProjectTree::emitFoldersAdded(FolderNode *folder) { if (!isInNodeHierarchy(folder)) return; emit foldersAdded(); if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus)) return; if (!m_currentNode) { Core::IDocument *document = Core::EditorManager::currentDocument(); const FileName fileName = document ? document->filePath() : FileName(); FindNodesForFileVisitor findNodes(fileName); foreach (FolderNode *fn, m_foldersAdded) fn->accept(&findNodes); Node *bestNode = ProjectTreeWidget::mostExpandedNode(findNodes.nodes()); if (!bestNode) return; updateFromNode(bestNode); } m_foldersAdded.clear(); }
void ProjectTree::emitFilesAdded(FolderNode *folder) { if (!isInNodeHierarchy(folder)) return; emit filesAdded(); if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus)) return; if (!m_currentNode) { Core::IDocument *document = Core::EditorManager::currentDocument(); const FileName fileName = document ? document->filePath() : FileName(); int index = Utils::indexOf(m_filesAdded, [&fileName](FileNode *node) { return node->filePath() == fileName; }); if (index == -1) return; updateFromNode(m_filesAdded.at(index)); } m_filesAdded.clear(); }
void TabBar::addEditorTab(Core::IEditor *editor) { Core::IDocument *document = editor->document(); const int index = addTab(document->displayName()); setTabIcon(index, Core::FileIconProvider::icon(QFileInfo(document->filePath()))); setTabToolTip(index, document->filePath()); m_editors.append(editor); connect(document, &Core::IDocument::changed, [this, editor, document]() { const int index = m_editors.indexOf(editor); if (index == -1) return; QString tabText = document->displayName(); if (document->isModified()) tabText += QLatin1Char('*'); setTabText(index, tabText); }); }
bool BazaarPlugin::submitEditorAboutToClose() { CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor()); QTC_ASSERT(commitEditor, return true); Core::IDocument *editorDocument = commitEditor->document(); QTC_ASSERT(editorDocument, return true); bool dummyPrompt = false; const VcsBase::VcsBaseSubmitEditor::PromptSubmitResult response = commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"), tr("Message check failed. Do you want to proceed?"), &dummyPrompt, !m_submitActionTriggered); m_submitActionTriggered = false; switch (response) { case VcsBase::VcsBaseSubmitEditor::SubmitCanceled: return false; case VcsBase::VcsBaseSubmitEditor::SubmitDiscarded: return true; default: break; } QStringList files = commitEditor->checkedFiles(); if (!files.empty()) { //save the commit message if (!Core::DocumentManager::saveDocument(editorDocument)) return false; //rewrite entries of the form 'file => newfile' to 'newfile' because //this would mess the commit command for (QStringList::iterator iFile = files.begin(); iFile != files.end(); ++iFile) { const QStringList parts = iFile->split(QLatin1String(" => "), QString::SkipEmptyParts); if (!parts.isEmpty()) *iFile = parts.last(); } BazaarCommitWidget *commitWidget = commitEditor->commitWidget(); QStringList extraOptions; // Author if (!commitWidget->committer().isEmpty()) extraOptions.append(QLatin1String("--author=") + commitWidget->committer()); // Fixed bugs foreach (const QString &fix, commitWidget->fixedBugs()) { if (!fix.isEmpty()) extraOptions << QLatin1String("--fixes") << fix; } // Whether local commit or not if (commitWidget->isLocalOptionEnabled()) extraOptions += QLatin1String("--local"); m_client->commit(m_submitRepository, files, editorDocument->filePath(), extraOptions); } return true; }
void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode) { Core::IDocument *document = Core::EditorManager::currentDocument(); const FileName fileName = document ? document->filePath() : FileName(); Node *currentNode = 0; if (!invalidCurrentNode && m_currentNode && m_currentNode->filePath() == fileName) currentNode = m_currentNode; else currentNode = ProjectTreeWidget::nodeForFile(fileName); updateFromNode(currentNode); }
bool MercurialPlugin::submitEditorAboutToClose() { CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor()); QTC_ASSERT(commitEditor, return true); Core::IDocument *editorFile = commitEditor->document(); QTC_ASSERT(editorFile, return true); bool dummyPrompt = false; const VcsBaseSubmitEditor::PromptSubmitResult response = commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"), tr("Message check failed. Do you want to proceed?"), &dummyPrompt, !m_submitActionTriggered); m_submitActionTriggered = false; switch (response) { case VcsBaseSubmitEditor::SubmitCanceled: return false; case VcsBaseSubmitEditor::SubmitDiscarded: return true; default: break; } const QStringList files = commitEditor->checkedFiles(); if (!files.empty()) { //save the commit message if (!Core::DocumentManager::saveDocument(editorFile)) return false; QStringList extraOptions; if (!commitEditor->committerInfo().isEmpty()) extraOptions << QLatin1String("-u") << commitEditor->committerInfo(); m_client->commit(m_submitRepository, files, editorFile->filePath().toString(), extraOptions); } return true; }
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; Core::IDocument *currentDocument = Core::EditorManager::currentDocument(); if (!currentDocument) { state.currentFile.clear(); } else { state.currentFile = currentDocument->filePath(); if (state.currentFile.isEmpty()) { 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 Core::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 = Core::VcsManager::findVersionControlForDirectory( state.currentFileDirectory, &state.currentFileTopLevel); if (!fileControl) state.clearFile(); } // Check for project, find the control Core::IVersionControl *projectControl = 0; if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject()) { state.currentProjectPath = currentProject->projectDirectory().toString(); state.currentProjectName = currentProject->displayName(); projectControl = Core::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. Core::IVersionControl *vc = fileControl; if (!vc) vc = projectControl; if (!vc) { state.clearPatchFile(); // Need a repository to patch Core::EditorManager::setWindowTitleVcsTopic(QString()); } if (debug) qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control")); emit stateChanged(state, vc); }