Commit b84a47ff authored by hjk's avatar hjk

QmakeProjectManager: Some editor creation related cleanup

Use a BaseEditorFactory derived class, move some code around.

Change-Id: I051ae55d106610ca818abdd3a5f6fd9f17131af2
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 3430514e
......@@ -46,6 +46,8 @@
#include <QDir>
#include <QTextBlock>
using namespace TextEditor;
namespace QmakeProjectManager {
namespace Internal {
......@@ -53,23 +55,33 @@ namespace Internal {
// ProFileEditor
//
ProFileEditor::ProFileEditor()
class ProFileEditor : public TextEditor::BaseTextEditor
{
addContext(Constants::C_PROFILEEDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
setEditorCreator([]() { return new ProFileEditor; });
setDocumentCreator([]() { return new ProFileDocument; });
setWidgetCreator([]() { return new ProFileEditorWidget; });
}
public:
ProFileEditor()
{
addContext(Constants::C_PROFILEEDITOR);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>());
}
};
//
// ProFileEditorWidget
//
ProFileEditorWidget::ProFileEditorWidget()
{}
class ProFileEditorWidget : public BaseTextEditorWidget
{
public:
ProFileEditorWidget() {}
protected:
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
bool inNextSplit = false);
BaseTextEditor *createEditor();
void contextMenuEvent(QContextMenuEvent *);
};
static bool isValidFileNameChar(const QChar &c)
{
......@@ -159,7 +171,7 @@ ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cur
return link;
}
TextEditor::BaseTextEditor *ProFileEditorWidget::createEditor()
BaseTextEditor *ProFileEditorWidget::createEditor()
{
QTC_ASSERT("should not happen anymore" && false, return 0);
}
......@@ -173,6 +185,18 @@ void ProFileEditorWidget::contextMenuEvent(QContextMenuEvent *e)
// ProFileDocument
//
class ProFileDocument : public BaseTextDocument
{
public:
ProFileDocument();
QString defaultPath() const;
QString suggestedFileName() const;
// qmake project files doesn't support UTF8-BOM
// If the BOM would be added qmake would fail and QtCreator couldn't parse the project file
bool supportsUtf8Bom() { return false; }
};
ProFileDocument::ProFileDocument()
{
setId(Constants::PROFILE_EDITOR_ID);
......@@ -192,34 +216,33 @@ QString ProFileDocument::suggestedFileName() const
return fi.fileName();
}
//
// ProFileEditorFactory
//
ProFileEditorFactory::ProFileEditorFactory()
{
setId(QmakeProjectManager::Constants::PROFILE_EDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", QmakeProjectManager::Constants::PROFILE_EDITOR_DISPLAY_NAME));
addMimeType(QmakeProjectManager::Constants::PROFILE_MIMETYPE);
addMimeType(QmakeProjectManager::Constants::PROINCLUDEFILE_MIMETYPE);
addMimeType(QmakeProjectManager::Constants::PROFEATUREFILE_MIMETYPE);
addMimeType(QmakeProjectManager::Constants::PROCONFIGURATIONFILE_MIMETYPE);
addMimeType(QmakeProjectManager::Constants::PROCACHEFILE_MIMETYPE);
addMimeType(QmakeProjectManager::Constants::PROSTASHFILE_MIMETYPE);
new TextEditor::TextEditorActionHandler(this, Constants::C_PROFILEEDITOR,
TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::JumpToFileUnderCursor);
setId(Constants::PROFILE_EDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::PROFILE_EDITOR_DISPLAY_NAME));
addMimeType(Constants::PROFILE_MIMETYPE);
addMimeType(Constants::PROINCLUDEFILE_MIMETYPE);
addMimeType(Constants::PROFEATUREFILE_MIMETYPE);
addMimeType(Constants::PROCONFIGURATIONFILE_MIMETYPE);
addMimeType(Constants::PROCACHEFILE_MIMETYPE);
addMimeType(Constants::PROSTASHFILE_MIMETYPE);
setDocumentCreator([]() { return new ProFileDocument; });
setEditorWidgetCreator([]() { return new ProFileEditorWidget; });
setEditorCreator([]() { return new ProFileEditor; });
setEditorActionHandlers(Constants::C_PROFILEEDITOR,
TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pro");
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "pri");
Core::FileIconProvider::registerIconOverlayForSuffix(QtSupport::Constants::ICON_QT_PROJECT, "prf");
}
Core::IEditor *ProFileEditorFactory::createEditor()
{
return new ProFileEditor;
}
} // namespace Internal
} // namespace QmakeProjectManager
......@@ -30,57 +30,17 @@
#ifndef PROFILEEDITOR_H
#define PROFILEEDITOR_H
#include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h>
namespace QmakeProjectManager {
namespace Internal {
class ProFileEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
ProFileEditor();
};
class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
ProFileEditorWidget();
protected:
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
bool inNextSplit = false);
TextEditor::BaseTextEditor *createEditor();
void contextMenuEvent(QContextMenuEvent *);
};
class ProFileDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
ProFileDocument();
QString defaultPath() const;
QString suggestedFileName() const;
// qmake project files doesn't support UTF8-BOM
// If the BOM would be added qmake would fail and QtCreator couldn't parse the project file
bool supportsUtf8Bom() { return false; }
};
class ProFileEditorFactory : public Core::IEditorFactory
class ProFileEditorFactory : public TextEditor::BaseTextEditorFactory
{
Q_OBJECT
public:
ProFileEditorFactory();
Core::IEditor *createEditor();
};
} // namespace Internal
......
......@@ -28,20 +28,23 @@
****************************************************************************/
#include "profilehoverhandler.h"
#include "profileeditor.h"
#include "profilecompletionassist.h"
#include "qmakeprojectmanagerconstants.h"
#include <coreplugin/helpmanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/basetexteditor.h>
#include <utils/htmldocextractor.h>
#include <QTextBlock>
#include <QUrl>
using namespace QmakeProjectManager;
using namespace QmakeProjectManager::Internal;
using namespace Core;
namespace QmakeProjectManager {
namespace Internal {
ProFileHoverHandler::ProFileHoverHandler(QObject *parent)
: BaseHoverHandler(parent),
m_manualKind(UnknownManual)
......@@ -56,20 +59,18 @@ ProFileHoverHandler::~ProFileHoverHandler()
bool ProFileHoverHandler::acceptEditor(IEditor *editor)
{
if (qobject_cast<ProFileEditor *>(editor) != 0)
return true;
return false;
return editor->context().contains(Constants::C_PROFILEEDITOR);
}
void ProFileHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
{
m_docFragment.clear();
m_manualKind = UnknownManual;
if (ProFileEditorWidget *proFileEditor = qobject_cast<ProFileEditorWidget *>(editor->widget())) {
if (!proFileEditor->extraSelectionTooltip(pos).isEmpty()) {
setToolTip(proFileEditor->extraSelectionTooltip(pos));
if (TextEditor::BaseTextEditorWidget *widget = editor->editorWidget()) {
if (!widget->extraSelectionTooltip(pos).isEmpty()) {
setToolTip(widget->extraSelectionTooltip(pos));
} else {
QTextDocument *document = proFileEditor->document();
QTextDocument *document = widget->document();
QTextBlock block = document->findBlock(pos);
identifyQMakeKeyword(block.text(), pos - block.position());
......@@ -161,3 +162,5 @@ void ProFileHoverHandler::identifyDocFragment(ProFileHoverHandler::ManualKind ma
}
}
} // namespace Internal
} // namespace QmakeProjectManager
......@@ -45,19 +45,19 @@
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
#include <texteditor/basetexteditor.h>
#include <QDir>
#include <QFileInfo>
#include <QVariant>
#include <QMessageBox>
using namespace ProjectExplorer;
using namespace QmakeProjectManager;
using namespace QmakeProjectManager::Internal;
using namespace TextEditor;
QmakeManager::QmakeManager(QmakeProjectManagerPlugin *plugin)
: m_plugin(plugin),
m_contextNode(0),
namespace QmakeProjectManager {
QmakeManager::QmakeManager()
: m_contextNode(0),
m_contextProject(0),
m_contextFile(0)
{
......@@ -132,9 +132,7 @@ void QmakeManager::setContextFile(ProjectExplorer::FileNode *file)
void QmakeManager::addLibrary()
{
ProFileEditor *editor =
qobject_cast<ProFileEditor*>(Core::EditorManager::currentEditor());
if (editor)
if (auto editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor()))
addLibrary(editor->document()->filePath(), editor);
}
......@@ -145,19 +143,19 @@ void QmakeManager::addLibraryContextMenu()
addLibrary(node->path());
}
void QmakeManager::addLibrary(const QString &fileName, ProFileEditor *editor)
void QmakeManager::addLibrary(const QString &fileName, BaseTextEditor *editor)
{
AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
Internal::AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)
return;
if (!editor)
editor = qobject_cast<ProFileEditor *> (Core::EditorManager::openEditor(fileName,
QmakeProjectManager::Constants::PROFILE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible));
editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::openEditor(fileName,
Constants::PROFILE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible));
if (!editor)
return;
const int endOfDoc = editor->position(TextEditor::BaseTextEditor::EndOfDoc);
const int endOfDoc = editor->position(BaseTextEditor::EndOfDoc);
editor->setCursorPosition(endOfDoc);
QString snippet = wizard.snippet();
......@@ -297,3 +295,5 @@ void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isF
bc->setSubNodeBuild(0);
bc->setFileNodeBuild(0);
}
} // namespace QmakeProjectManager
......@@ -36,7 +36,7 @@
#include <projectexplorer/projectnodes.h>
namespace Core { class IEditor; }
namespace ExtensionSystem { class PluginManager; }
namespace TextEditor { class BaseTextEditor; }
namespace ProjectExplorer {
class Project;
......@@ -46,11 +46,6 @@ class ToolChain;
namespace QmakeProjectManager {
namespace Internal {
class ProFileEditor;
class QmakeProjectManagerPlugin;
} // namespace Internal
class QmakeProject;
class QMAKEPROJECTMANAGER_EXPORT QmakeManager : public ProjectExplorer::IProjectManager
......@@ -58,7 +53,7 @@ class QMAKEPROJECTMANAGER_EXPORT QmakeManager : public ProjectExplorer::IProject
Q_OBJECT
public:
QmakeManager(Internal::QmakeProjectManagerPlugin *plugin);
QmakeManager();
~QmakeManager();
void registerProject(QmakeProject *project);
......@@ -96,10 +91,9 @@ private:
ProjectExplorer::Project *contextProject,
ProjectExplorer::Node *contextNode,
ProjectExplorer::FileNode *contextFile);
void addLibrary(const QString &fileName, Internal::ProFileEditor *editor = 0);
void addLibrary(const QString &fileName, TextEditor::BaseTextEditor *editor = 0);
void runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
Internal::QmakeProjectManagerPlugin *m_plugin;
ProjectExplorer::Node *m_contextNode;
ProjectExplorer::Project *m_contextProject;
ProjectExplorer::FileNode *m_contextFile;
......
......@@ -106,7 +106,7 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
m_projectExplorer = ProjectExplorerPlugin::instance();
//create and register objects
m_qmakeProjectManager = new QmakeManager(this);
m_qmakeProjectManager = new QmakeManager;
addObject(m_qmakeProjectManager);
ProjectExplorer::KitManager::registerKitInformation(new QmakeKitInformation);
......
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