forked from qt-creator/qt-creator
Project tree: Make code for diff against current file reusable
The same functionality should be available in the file system view. Change-Id: Ib31cb84924e767ebe06f595bf638a5e674d4f8b5 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -36,12 +36,15 @@
|
||||
#include "texteditorconstants.h"
|
||||
#include "typingsettings.h"
|
||||
#include <texteditor/generichighlighter/highlighter.h>
|
||||
#include <coreplugin/diffservice.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/guard.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
@@ -357,6 +360,22 @@ void TextDocument::setFontSettings(const FontSettings &fontSettings)
|
||||
emit fontSettingsChanged();
|
||||
}
|
||||
|
||||
QAction *TextDocument::createDiffAgainstCurrentFileAction(
|
||||
QObject *parent, const std::function<Utils::FileName()> &filePath)
|
||||
{
|
||||
const auto diffAgainstCurrentFile = [filePath]() {
|
||||
auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>();
|
||||
auto textDocument = TextEditor::TextDocument::currentTextDocument();
|
||||
const QString leftFilePath = textDocument ? textDocument->filePath().toString() : QString();
|
||||
const QString rightFilePath = filePath().toString();
|
||||
if (diffService && !leftFilePath.isEmpty() && !rightFilePath.isEmpty())
|
||||
diffService->diffFiles(leftFilePath, rightFilePath);
|
||||
};
|
||||
auto diffAction = new QAction(tr("Diff Against Current File"), parent);
|
||||
QObject::connect(diffAction, &QAction::triggered, parent, diffAgainstCurrentFile);
|
||||
return diffAction;
|
||||
}
|
||||
|
||||
void TextDocument::triggerPendingUpdates()
|
||||
{
|
||||
if (d->m_fontSettingsNeedsApply)
|
||||
|
||||
Reference in New Issue
Block a user