Commit cc945489 authored by Eike Ziller's avatar Eike Ziller

Add function for getting DiffService

Hides the implementation detail that this is fetched from the object
pool from most places.

Change-Id: I0ea06c877fade50f62b62011bbc0d2f89fa8e885
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
parent e4085dd0
......@@ -111,7 +111,8 @@ SOURCES += corejsextensions.cpp \
iwelcomepage.cpp \
externaltoolmanager.cpp \
systemsettings.cpp \
coreicons.cpp
coreicons.cpp \
diffservice.cpp
HEADERS += corejsextensions.h \
mainwindow.h \
......
......@@ -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",
......
......@@ -55,7 +55,7 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
const QDialogButtonBox::ButtonRole discardButtonRole = Utils::HostOsInfo::isMacHost()
? QDialogButtonBox::ResetRole : QDialogButtonBox::DestructiveRole;
if (ExtensionSystem::PluginManager::getObject<Core::DiffService>()) {
if (DiffService::instance()) {
m_diffButton = m_ui.buttonBox->addButton(tr("&Diff"), discardButtonRole);
connect(m_diffButton, &QAbstractButton::clicked, this, &SaveItemsDialog::collectFilesToDiff);
}
......
/****************************************************************************
**
** 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 <extensionsystem/pluginmanager.h>
namespace Core {
DiffService *DiffService::instance()
{
return ExtensionSystem::PluginManager::getObject<DiffService>();
}
} // Core
......@@ -26,6 +26,7 @@
#pragma once
#include "core_global.h"
#include <QObject>
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;
......
......@@ -641,7 +641,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
(*failedToSave) = modifiedDocuments;
const QStringList filesToDiff = dia.filesToDiff();
if (!filesToDiff.isEmpty()) {
if (auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>())
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>(),
DiffService::instance(),
ICore::dialogParent());
switch (previousReloadAnswer) {
case ReloadAll:
......@@ -1216,7 +1216,7 @@ void DocumentManager::checkForReload()
}
if (!filesToDiff.isEmpty()) {
if (auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>())
if (auto diffService = DiffService::instance())
diffService->diffModifiedFiles(filesToDiff);
}
......
......@@ -2180,7 +2180,7 @@ void EditorManagerPrivate::revertToSaved(IDocument *document)
msgBox.button(QMessageBox::No)->setText(tr("Cancel"));
QPushButton *diffButton = nullptr;
auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>();
auto diffService = DiffService::instance();
if (diffService)
diffButton = msgBox.addButton(tr("Cancel && &Diff"), QMessageBox::RejectRole);
......
......@@ -369,7 +369,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry);
if (hasCurrentItem && !isDir) {
if (ExtensionSystem::PluginManager::getObject<Core::DiffService>()) {
if (Core::DiffService::instance()) {
menu.addAction(
TextEditor::TextDocument::createDiffAgainstCurrentFileAction(&menu, [filePath]() {
return filePath;
......
......@@ -261,11 +261,6 @@ static bool isTextFile(const QString &fileName)
TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT);
}
static bool isDiffServiceAvailable()
{
return ExtensionSystem::PluginManager::getObject<DiffService>();
}
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));
......
......@@ -364,7 +364,7 @@ QAction *TextDocument::createDiffAgainstCurrentFileAction(
QObject *parent, const std::function<Utils::FileName()> &filePath)
{
const auto diffAgainstCurrentFile = [filePath]() {
auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>();
auto diffService = DiffService::instance();
auto textDocument = TextEditor::TextDocument::currentTextDocument();
const QString leftFilePath = textDocument ? textDocument->filePath().toString() : QString();
const QString rightFilePath = filePath().toString();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment