Commit d3a743d7 authored by Jarek Kobus's avatar Jarek Kobus Committed by Jaroslaw Kobus
Browse files

Use namespace Core in diff editor plugin



Change-Id: I2409a6186d590a83ccde064c855e0261d600014e
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 4ae306a5
......@@ -50,6 +50,8 @@
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
using namespace Core;
namespace DiffEditor {
namespace Internal {
......@@ -57,13 +59,13 @@ class DiffFilesController : public DiffEditorController
{
Q_OBJECT
public:
DiffFilesController(Core::IDocument *document);
DiffFilesController(IDocument *document);
protected:
FileData diffFiles(const QString &leftContents, const QString &rightContents);
};
DiffFilesController::DiffFilesController(Core::IDocument *document)
DiffFilesController::DiffFilesController(IDocument *document)
: DiffEditorController(document)
{}
......@@ -101,7 +103,7 @@ class DiffCurrentFileController : public DiffFilesController
{
Q_OBJECT
public:
DiffCurrentFileController(Core::IDocument *document, const QString &fileName);
DiffCurrentFileController(IDocument *document, const QString &fileName);
protected:
void reload();
......@@ -110,7 +112,7 @@ private:
QString m_fileName;
};
DiffCurrentFileController::DiffCurrentFileController(Core::IDocument *document, const QString &fileName) :
DiffCurrentFileController::DiffCurrentFileController(IDocument *document, const QString &fileName) :
DiffFilesController(document), m_fileName(fileName)
{ }
......@@ -119,7 +121,7 @@ void DiffCurrentFileController::reload()
QList<FileData> fileDataList;
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(
Core::DocumentModel::documentForFilePath(m_fileName));
DocumentModel::documentForFilePath(m_fileName));
if (textDocument && textDocument->isModified()) {
QString errorString;
......@@ -158,24 +160,24 @@ class DiffOpenFilesController : public DiffFilesController
{
Q_OBJECT
public:
DiffOpenFilesController(Core::IDocument *document);
DiffOpenFilesController(IDocument *document);
protected:
void reload();
};
DiffOpenFilesController::DiffOpenFilesController(Core::IDocument *document) :
DiffOpenFilesController::DiffOpenFilesController(IDocument *document) :
DiffFilesController(document)
{ }
void DiffOpenFilesController::reload()
{
const QList<Core::IDocument *> openedDocuments =
Core::DocumentModel::openedDocuments();
const QList<IDocument *> openedDocuments =
DocumentModel::openedDocuments();
QList<FileData> fileDataList;
foreach (Core::IDocument *doc, openedDocuments) {
foreach (IDocument *doc, openedDocuments) {
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(doc);
if (textDocument && textDocument->isModified()) {
......@@ -217,7 +219,7 @@ class DiffModifiedFilesController : public DiffFilesController
{
Q_OBJECT
public:
DiffModifiedFilesController(Core::IDocument *document, const QStringList &fileNames);
DiffModifiedFilesController(IDocument *document, const QStringList &fileNames);
protected:
void reload();
......@@ -226,7 +228,7 @@ private:
QStringList m_fileNames;
};
DiffModifiedFilesController::DiffModifiedFilesController(Core::IDocument *document, const QStringList &fileNames) :
DiffModifiedFilesController::DiffModifiedFilesController(IDocument *document, const QStringList &fileNames) :
DiffFilesController(document), m_fileNames(fileNames)
{ }
......@@ -236,7 +238,7 @@ void DiffModifiedFilesController::reload()
foreach (const QString fileName, m_fileNames) {
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(
Core::DocumentModel::documentForFilePath(fileName));
DocumentModel::documentForFilePath(fileName));
if (textDocument && textDocument->isModified()) {
QString errorString;
......@@ -277,7 +279,7 @@ class DiffExternalFilesController : public DiffFilesController
{
Q_OBJECT
public:
DiffExternalFilesController(Core::IDocument *document, const QString &leftFileName,
DiffExternalFilesController(IDocument *document, const QString &leftFileName,
const QString &rightFileName);
protected:
......@@ -288,7 +290,7 @@ private:
QString m_rightFileName;
};
DiffExternalFilesController::DiffExternalFilesController(Core::IDocument *document, const QString &leftFileName,
DiffExternalFilesController::DiffExternalFilesController(IDocument *document, const QString &leftFileName,
const QString &rightFileName) :
DiffFilesController(document), m_leftFileName(leftFileName), m_rightFileName(rightFileName)
{ }
......@@ -297,7 +299,7 @@ void DiffExternalFilesController::reload()
{
QString errorString;
Utils::TextFileFormat format;
format.codec = Core::EditorManager::defaultTextCodec();
format.codec = EditorManager::defaultTextCodec();
QString leftText;
bool leftFileExists = true;
......@@ -339,7 +341,7 @@ void DiffExternalFilesController::reload()
static TextEditor::TextDocument *currentTextDocument()
{
return qobject_cast<TextEditor::TextDocument *>(
Core::EditorManager::currentDocument());
EditorManager::currentDocument());
}
DiffEditorServiceImpl::DiffEditorServiceImpl(QObject *parent) :
......@@ -358,7 +360,7 @@ void DiffEditorServiceImpl::diffModifiedFiles(const QStringList &fileNames)
if (!DiffEditorController::controller(document))
new DiffModifiedFilesController(document, fileNames);
Core::EditorManager::activateEditorForDocument(document);
EditorManager::activateEditorForDocument(document);
document->reload();
}
......@@ -368,39 +370,39 @@ bool DiffEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
Q_UNUSED(errorMessage)
//register actions
Core::ActionContainer *toolsContainer
= Core::ActionManager::actionContainer(Core::Constants::M_TOOLS);
ActionContainer *toolsContainer
= ActionManager::actionContainer(Core::Constants::M_TOOLS);
toolsContainer->insertGroup(Core::Constants::G_TOOLS_OPTIONS, Constants::G_TOOLS_DIFF);
Core::ActionContainer *diffContainer = Core::ActionManager::createMenu("Diff");
ActionContainer *diffContainer = ActionManager::createMenu("Diff");
diffContainer->menu()->setTitle(tr("&Diff"));
toolsContainer->addMenu(diffContainer, Constants::G_TOOLS_DIFF);
m_diffCurrentFileAction = new QAction(tr("Diff Current File"), this);
Core::Command *diffCurrentFileCommand = Core::ActionManager::registerAction(m_diffCurrentFileAction, "DiffEditor.DiffCurrentFile");
diffCurrentFileCommand->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+H") : tr("Ctrl+H")));
Command *diffCurrentFileCommand = ActionManager::registerAction(m_diffCurrentFileAction, "DiffEditor.DiffCurrentFile");
diffCurrentFileCommand->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+H") : tr("Ctrl+H")));
connect(m_diffCurrentFileAction, &QAction::triggered, this, &DiffEditorPlugin::diffCurrentFile);
diffContainer->addAction(diffCurrentFileCommand);
m_diffOpenFilesAction = new QAction(tr("Diff Open Files"), this);
Core::Command *diffOpenFilesCommand = Core::ActionManager::registerAction(m_diffOpenFilesAction, "DiffEditor.DiffOpenFiles");
diffOpenFilesCommand->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+H") : tr("Ctrl+Shift+H")));
Command *diffOpenFilesCommand = ActionManager::registerAction(m_diffOpenFilesAction, "DiffEditor.DiffOpenFiles");
diffOpenFilesCommand->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Shift+H") : tr("Ctrl+Shift+H")));
connect(m_diffOpenFilesAction, &QAction::triggered, this, &DiffEditorPlugin::diffOpenFiles);
diffContainer->addAction(diffOpenFilesCommand);
QAction *diffExternalFilesAction = new QAction(tr("Diff External Files..."), this);
Core::Command *diffExternalFilesCommand = Core::ActionManager::registerAction(diffExternalFilesAction, "DiffEditor.DiffExternalFiles");
Command *diffExternalFilesCommand = ActionManager::registerAction(diffExternalFilesAction, "DiffEditor.DiffExternalFiles");
connect(diffExternalFilesAction, &QAction::triggered, this, &DiffEditorPlugin::diffExternalFiles);
diffContainer->addAction(diffExternalFilesCommand);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
this, &DiffEditorPlugin::updateDiffCurrentFileAction);
connect(Core::EditorManager::instance(), &Core::EditorManager::currentDocumentStateChanged,
connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
this, &DiffEditorPlugin::updateDiffCurrentFileAction);
connect(Core::EditorManager::instance(), &Core::EditorManager::editorOpened,
connect(EditorManager::instance(), &EditorManager::editorOpened,
this, &DiffEditorPlugin::updateDiffOpenFilesAction);
connect(Core::EditorManager::instance(), &Core::EditorManager::editorsClosed,
connect(EditorManager::instance(), &EditorManager::editorsClosed,
this, &DiffEditorPlugin::updateDiffOpenFilesAction);
connect(Core::EditorManager::instance(), &Core::EditorManager::documentStateChanged,
connect(EditorManager::instance(), &EditorManager::documentStateChanged,
this, &DiffEditorPlugin::updateDiffOpenFilesAction);
updateDiffCurrentFileAction();
......@@ -424,7 +426,7 @@ void DiffEditorPlugin::updateDiffCurrentFileAction()
void DiffEditorPlugin::updateDiffOpenFilesAction()
{
const bool enabled = Utils::anyOf(Core::DocumentModel::openedDocuments(), [](Core::IDocument *doc) {
const bool enabled = Utils::anyOf(DocumentModel::openedDocuments(), [](IDocument *doc) {
return doc->isModified() && qobject_cast<TextEditor::TextDocument *>(doc);
});
m_diffOpenFilesAction->setEnabled(enabled);
......@@ -450,7 +452,7 @@ void DiffEditorPlugin::diffCurrentFile()
if (!DiffEditorController::controller(document))
new DiffCurrentFileController(document, fileName);
Core::EditorManager::activateEditorForDocument(document);
EditorManager::activateEditorForDocument(document);
document->reload();
}
......@@ -465,19 +467,19 @@ void DiffEditorPlugin::diffOpenFiles()
if (!DiffEditorController::controller(document))
new DiffOpenFilesController(document);
Core::EditorManager::activateEditorForDocument(document);
EditorManager::activateEditorForDocument(document);
document->reload();
}
void DiffEditorPlugin::diffExternalFiles()
{
const QString fileName1 = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
const QString fileName1 = QFileDialog::getOpenFileName(ICore::dialogParent(),
tr("Select First File for Diff"),
QString());
if (fileName1.isNull())
return;
const QString fileName2 = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
const QString fileName2 = QFileDialog::getOpenFileName(ICore::dialogParent(),
tr("Select Second File for Diff"),
QString());
if (fileName2.isNull())
......@@ -493,7 +495,7 @@ void DiffEditorPlugin::diffExternalFiles()
if (!DiffEditorController::controller(document))
new DiffExternalFilesController(document, fileName1, fileName2);
Core::EditorManager::activateEditorForDocument(document);
EditorManager::activateEditorForDocument(document);
document->reload();
}
......
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