diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 4b6c6ecdeda..5e6e934b762 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -111,7 +111,8 @@ SOURCES += corejsextensions.cpp \ iwelcomepage.cpp \ externaltoolmanager.cpp \ systemsettings.cpp \ - coreicons.cpp + coreicons.cpp \ + diffservice.cpp HEADERS += corejsextensions.h \ mainwindow.h \ diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index e6ea7f8d3ce..2a6b1e6d23b 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -41,7 +41,7 @@ Project { "corejsextensions.cpp", "corejsextensions.h", "coreplugin.cpp", "coreplugin.h", "designmode.cpp", "designmode.h", - "diffservice.h", + "diffservice.cpp", "diffservice.h", "documentmanager.cpp", "documentmanager.h", "editmode.cpp", "editmode.h", "editortoolbar.cpp", "editortoolbar.h", diff --git a/src/plugins/coreplugin/dialogs/saveitemsdialog.cpp b/src/plugins/coreplugin/dialogs/saveitemsdialog.cpp index bad8aef38e3..edee9a6bca6 100644 --- a/src/plugins/coreplugin/dialogs/saveitemsdialog.cpp +++ b/src/plugins/coreplugin/dialogs/saveitemsdialog.cpp @@ -55,7 +55,7 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent, const QDialogButtonBox::ButtonRole discardButtonRole = Utils::HostOsInfo::isMacHost() ? QDialogButtonBox::ResetRole : QDialogButtonBox::DestructiveRole; - if (ExtensionSystem::PluginManager::getObject()) { + if (DiffService::instance()) { m_diffButton = m_ui.buttonBox->addButton(tr("&Diff"), discardButtonRole); connect(m_diffButton, &QAbstractButton::clicked, this, &SaveItemsDialog::collectFilesToDiff); } diff --git a/src/plugins/coreplugin/diffservice.cpp b/src/plugins/coreplugin/diffservice.cpp new file mode 100644 index 00000000000..312d08346ba --- /dev/null +++ b/src/plugins/coreplugin/diffservice.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "diffservice.h" + +#include + +namespace Core { + +DiffService *DiffService::instance() +{ + return ExtensionSystem::PluginManager::getObject(); +} + +} // Core diff --git a/src/plugins/coreplugin/diffservice.h b/src/plugins/coreplugin/diffservice.h index 25f2d698487..72b9881d9fc 100644 --- a/src/plugins/coreplugin/diffservice.h +++ b/src/plugins/coreplugin/diffservice.h @@ -26,6 +26,7 @@ #pragma once #include "core_global.h" + #include QT_FORWARD_DECLARE_CLASS(QStringList) @@ -35,6 +36,8 @@ namespace Core { class CORE_EXPORT DiffService { public: + static DiffService *instance(); + virtual ~DiffService() {} virtual void diffFiles(const QString &leftFileName, const QString &rightFileName) = 0; diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 7d7309f8ab2..49cc96566a4 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -641,7 +641,7 @@ static bool saveModifiedFilesHelper(const QList &documents, (*failedToSave) = modifiedDocuments; const QStringList filesToDiff = dia.filesToDiff(); if (!filesToDiff.isEmpty()) { - if (auto diffService = ExtensionSystem::PluginManager::getObject()) + if (auto diffService = DiffService::instance()) diffService->diffModifiedFiles(filesToDiff); } return false; @@ -1151,7 +1151,7 @@ void DocumentManager::checkForReload() } else { // Ask about content change previousReloadAnswer = reloadPrompt(document->filePath(), document->isModified(), - ExtensionSystem::PluginManager::getObject(), + DiffService::instance(), ICore::dialogParent()); switch (previousReloadAnswer) { case ReloadAll: @@ -1216,7 +1216,7 @@ void DocumentManager::checkForReload() } if (!filesToDiff.isEmpty()) { - if (auto diffService = ExtensionSystem::PluginManager::getObject()) + if (auto diffService = DiffService::instance()) diffService->diffModifiedFiles(filesToDiff); } diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index cab82df4cce..be364de7650 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -2180,7 +2180,7 @@ void EditorManagerPrivate::revertToSaved(IDocument *document) msgBox.button(QMessageBox::No)->setText(tr("Cancel")); QPushButton *diffButton = nullptr; - auto diffService = ExtensionSystem::PluginManager::getObject(); + auto diffService = DiffService::instance(); if (diffService) diffButton = msgBox.addButton(tr("Cancel && &Diff"), QMessageBox::RejectRole); diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 3a77485da45..a5d62eb1145 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -369,7 +369,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry); if (hasCurrentItem && !isDir) { - if (ExtensionSystem::PluginManager::getObject()) { + if (Core::DiffService::instance()) { menu.addAction( TextEditor::TextDocument::createDiffAgainstCurrentFileAction(&menu, [filePath]() { return filePath; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index b15cad5cb83..d6d0b5b19b3 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -261,11 +261,6 @@ static bool isTextFile(const QString &fileName) TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT); } -static bool isDiffServiceAvailable() -{ - return ExtensionSystem::PluginManager::getObject(); -} - class ProjectExplorerPluginPrivate : public QObject { Q_DECLARE_TR_FUNCTIONS(ProjectExplorer::ProjectExplorerPlugin) @@ -2963,7 +2958,7 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions() m_duplicateFileAction->setVisible(false); m_deleteFileAction->setVisible(true); m_runActionContextMenu->setVisible(false); - m_diffFileAction->setVisible(isDiffServiceAvailable()); + m_diffFileAction->setVisible(DiffService::instance()); m_openTerminalHere->setVisible(true); m_showInGraphicalShell->setVisible(true); @@ -3036,7 +3031,7 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions() m_renameFileAction->setEnabled(supports(Rename)); const bool currentNodeIsTextFile = isTextFile( currentNode->filePath().toString()); - m_diffFileAction->setEnabled(isDiffServiceAvailable() + m_diffFileAction->setEnabled(DiffService::instance() && currentNodeIsTextFile && TextEditor::TextDocument::currentTextDocument()); m_duplicateFileAction->setVisible(supports(DuplicateFile)); diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 404007382b4..fc54d6f0059 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -364,7 +364,7 @@ QAction *TextDocument::createDiffAgainstCurrentFileAction( QObject *parent, const std::function &filePath) { const auto diffAgainstCurrentFile = [filePath]() { - auto diffService = ExtensionSystem::PluginManager::getObject(); + auto diffService = DiffService::instance(); auto textDocument = TextEditor::TextDocument::currentTextDocument(); const QString leftFilePath = textDocument ? textDocument->filePath().toString() : QString(); const QString rightFilePath = filePath().toString();