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:
@@ -315,7 +315,6 @@ public:
|
|||||||
void duplicateFile();
|
void duplicateFile();
|
||||||
void deleteFile();
|
void deleteFile();
|
||||||
void handleRenameFile();
|
void handleRenameFile();
|
||||||
void handleDiffFile();
|
|
||||||
void handleSetStartupProject();
|
void handleSetStartupProject();
|
||||||
void setStartupProject(ProjectExplorer::Project *project);
|
void setStartupProject(ProjectExplorer::Project *project);
|
||||||
|
|
||||||
@@ -1118,7 +1117,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
|
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
|
||||||
|
|
||||||
// diff file action
|
// diff file action
|
||||||
dd->m_diffFileAction = new QAction(tr("Diff Against Current File"), this);
|
dd->m_diffFileAction = TextEditor::TextDocument::createDiffAgainstCurrentFileAction(
|
||||||
|
this, &ProjectTree::currentFilePath);
|
||||||
cmd = ActionManager::registerAction(dd->m_diffFileAction, Constants::DIFFFILE, projecTreeContext);
|
cmd = ActionManager::registerAction(dd->m_diffFileAction, Constants::DIFFFILE, projecTreeContext);
|
||||||
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
|
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
|
||||||
|
|
||||||
@@ -1362,8 +1362,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
dd, &ProjectExplorerPluginPrivate::deleteFile);
|
dd, &ProjectExplorerPluginPrivate::deleteFile);
|
||||||
connect(dd->m_renameFileAction, &QAction::triggered,
|
connect(dd->m_renameFileAction, &QAction::triggered,
|
||||||
dd, &ProjectExplorerPluginPrivate::handleRenameFile);
|
dd, &ProjectExplorerPluginPrivate::handleRenameFile);
|
||||||
connect(dd->m_diffFileAction, &QAction::triggered,
|
|
||||||
dd, &ProjectExplorerPluginPrivate::handleDiffFile);
|
|
||||||
connect(dd->m_setStartupProjectAction, &QAction::triggered,
|
connect(dd->m_setStartupProjectAction, &QAction::triggered,
|
||||||
dd, &ProjectExplorerPluginPrivate::handleSetStartupProject);
|
dd, &ProjectExplorerPluginPrivate::handleSetStartupProject);
|
||||||
connect(dd->m_projectTreeCollapseAllAction, &QAction::triggered,
|
connect(dd->m_projectTreeCollapseAllAction, &QAction::triggered,
|
||||||
@@ -3379,39 +3377,6 @@ void ProjectExplorerPluginPrivate::handleRenameFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPluginPrivate::handleDiffFile()
|
|
||||||
{
|
|
||||||
// current editor's file
|
|
||||||
auto textDocument = TextEditor::TextDocument::currentTextDocument();
|
|
||||||
|
|
||||||
if (!textDocument)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QString leftFileName = textDocument->filePath().toString();
|
|
||||||
|
|
||||||
if (leftFileName.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// current item's file
|
|
||||||
Node *currentNode = ProjectTree::findCurrentNode();
|
|
||||||
QTC_ASSERT(currentNode && currentNode->nodeType() == NodeType::File, return);
|
|
||||||
|
|
||||||
FileNode *fileNode = currentNode->asFileNode();
|
|
||||||
|
|
||||||
if (!fileNode)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QString rightFileName = currentNode->filePath().toString();
|
|
||||||
if (rightFileName.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!isTextFile(rightFileName))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>())
|
|
||||||
diffService->diffFiles(leftFileName, rightFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath)
|
void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath)
|
||||||
{
|
{
|
||||||
const QString oldFilePath = node->filePath().toFileInfo().absoluteFilePath();
|
const QString oldFilePath = node->filePath().toFileInfo().absoluteFilePath();
|
||||||
|
|||||||
@@ -110,6 +110,12 @@ Node *ProjectTree::findCurrentNode()
|
|||||||
return s_instance->m_currentNode;
|
return s_instance->m_currentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileName ProjectTree::currentFilePath()
|
||||||
|
{
|
||||||
|
Node *currentNode = findCurrentNode();
|
||||||
|
return currentNode ? currentNode->filePath() : FileName();
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectTree::registerWidget(ProjectTreeWidget *widget)
|
void ProjectTree::registerWidget(ProjectTreeWidget *widget)
|
||||||
{
|
{
|
||||||
s_instance->m_projectTreeWidgets.append(widget);
|
s_instance->m_projectTreeWidgets.append(widget);
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
namespace Utils { class FileName; }
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class FileNode;
|
class FileNode;
|
||||||
class FolderNode;
|
class FolderNode;
|
||||||
@@ -52,6 +54,7 @@ public:
|
|||||||
|
|
||||||
static Project *currentProject();
|
static Project *currentProject();
|
||||||
static Node *findCurrentNode();
|
static Node *findCurrentNode();
|
||||||
|
static Utils::FileName currentFilePath();
|
||||||
|
|
||||||
// Integration with ProjectTreeWidget
|
// Integration with ProjectTreeWidget
|
||||||
static void registerWidget(Internal::ProjectTreeWidget *widget);
|
static void registerWidget(Internal::ProjectTreeWidget *widget);
|
||||||
|
|||||||
@@ -36,12 +36,15 @@
|
|||||||
#include "texteditorconstants.h"
|
#include "texteditorconstants.h"
|
||||||
#include "typingsettings.h"
|
#include "typingsettings.h"
|
||||||
#include <texteditor/generichighlighter/highlighter.h>
|
#include <texteditor/generichighlighter/highlighter.h>
|
||||||
|
#include <coreplugin/diffservice.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/documentmodel.h>
|
#include <coreplugin/editormanager/documentmodel.h>
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/textutils.h>
|
#include <utils/textutils.h>
|
||||||
#include <utils/guard.h>
|
#include <utils/guard.h>
|
||||||
#include <utils/mimetypes/mimedatabase.h>
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -357,6 +360,22 @@ void TextDocument::setFontSettings(const FontSettings &fontSettings)
|
|||||||
emit fontSettingsChanged();
|
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()
|
void TextDocument::triggerPendingUpdates()
|
||||||
{
|
{
|
||||||
if (d->m_fontSettingsNeedsApply)
|
if (d->m_fontSettingsNeedsApply)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QAction;
|
||||||
class QTextCursor;
|
class QTextCursor;
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -138,6 +139,9 @@ public:
|
|||||||
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
void setTabSettings(const TextEditor::TabSettings &tabSettings);
|
||||||
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||||
|
|
||||||
|
static QAction *createDiffAgainstCurrentFileAction(QObject *parent,
|
||||||
|
const std::function<Utils::FileName()> &filePath);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void aboutToOpen(const QString &fileName, const QString &realFileName);
|
void aboutToOpen(const QString &fileName, const QString &realFileName);
|
||||||
void openFinishedSuccessfully();
|
void openFinishedSuccessfully();
|
||||||
|
|||||||
Reference in New Issue
Block a user