Commit f0dfe2dc authored by hjk's avatar hjk
Browse files

CMakeProjectManager: General editor related code consolidation



Merge editor files, convert to new editor setup scheme,
fix names according to convention.

Change-Id: I2b3a72149be608df3813aaa00592c7c2facffc05
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent b86269ed
...@@ -33,56 +33,68 @@ ...@@ -33,56 +33,68 @@
#include "cmakeprojectconstants.h" #include "cmakeprojectconstants.h"
#include "cmakeproject.h" #include "cmakeproject.h"
#include <coreplugin/icore.h>
#include <coreplugin/infobar.h>
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/icore.h>
#include <coreplugin/infobar.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <texteditor/highlighterutils.h>
#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <texteditor/highlighterutils.h>
#include <utils/qtcassert.h>
#include <QFileInfo> #include <QFileInfo>
#include <QSharedPointer>
#include <QTextBlock> #include <QTextBlock>
using namespace CMakeProjectManager; using namespace Core;
using namespace CMakeProjectManager::Internal; using namespace TextEditor;
using namespace CMakeProjectManager::Constants;
namespace CMakeProjectManager {
namespace Internal {
// //
// ProFileEditorEditable // CMakeEditor
// //
CMakeEditor::CMakeEditor() CMakeEditor::CMakeEditor()
{ {
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR, addContext(Constants::C_CMAKEEDITOR);
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::HashStyle); setCommentStyle(Utils::CommentDefinition::HashStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
} setEditorCreator([]() { return new CMakeEditor; });
setWidgetCreator([]() { return new CMakeEditorWidget; });
Core::IEditor *CMakeEditor::duplicate()
{ setDocumentCreator([this]() -> BaseTextDocument * {
CMakeEditorWidget *ret = new CMakeEditorWidget; auto doc = new CMakeDocument;
ret->setTextDocument(editorWidget()->textDocumentPtr()); connect(doc, &IDocument::changed, this, &CMakeEditor::markAsChanged);
return ret->editor(); return doc;
});
} }
void CMakeEditor::markAsChanged() void CMakeEditor::markAsChanged()
{ {
if (!document()->isModified()) if (!document()->isModified())
return; return;
Core::InfoBar *infoBar = document()->infoBar(); InfoBar *infoBar = document()->infoBar();
Core::Id infoRunCmake("CMakeEditor.RunCMake"); Id infoRunCmake("CMakeEditor.RunCMake");
if (!infoBar->canInfoBeAdded(infoRunCmake)) if (!infoBar->canInfoBeAdded(infoRunCmake))
return; return;
Core::InfoBarEntry info(infoRunCmake, InfoBarEntry info(infoRunCmake,
tr("Changes to cmake files are shown in the project tree after building."), tr("Changes to cmake files are shown in the project tree after building."),
Core::InfoBarEntry::GlobalSuppressionEnabled); InfoBarEntry::GlobalSuppressionEnabled);
info.setCustomButtonInfo(tr("Build now"), this, SLOT(build())); info.setCustomButtonInfo(tr("Build now"), this, SLOT(build()));
infoBar->addInfo(info); infoBar->addInfo(info);
} }
...@@ -103,7 +115,7 @@ void CMakeEditor::build() ...@@ -103,7 +115,7 @@ void CMakeEditor::build()
QString CMakeEditor::contextHelpId() const QString CMakeEditor::contextHelpId() const
{ {
int pos = position(); int pos = position();
TextEditor::BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument(); BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument();
QChar chr; QChar chr;
do { do {
...@@ -143,7 +155,7 @@ QString CMakeEditor::contextHelpId() const ...@@ -143,7 +155,7 @@ QString CMakeEditor::contextHelpId() const
} }
// //
// CMakeEditor // CMakeEditorWidget
// //
CMakeEditorWidget::CMakeEditorWidget() CMakeEditorWidget::CMakeEditorWidget()
...@@ -151,11 +163,9 @@ CMakeEditorWidget::CMakeEditorWidget() ...@@ -151,11 +163,9 @@ CMakeEditorWidget::CMakeEditorWidget()
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
} }
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor() BaseTextEditor *CMakeEditorWidget::createEditor()
{ {
auto editor = new CMakeEditor; QTC_ASSERT("should not happen anymore" && false, return 0);
connect(textDocument(), &Core::IDocument::changed, editor, &CMakeEditor::markAsChanged);
return editor;
} }
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e) void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
...@@ -165,14 +175,12 @@ void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e) ...@@ -165,14 +175,12 @@ void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
static bool isValidFileNameChar(const QChar &c) static bool isValidFileNameChar(const QChar &c)
{ {
if (c.isLetterOrNumber() return c.isLetterOrNumber()
|| c == QLatin1Char('.') || c == QLatin1Char('.')
|| c == QLatin1Char('_') || c == QLatin1Char('_')
|| c == QLatin1Char('-') || c == QLatin1Char('-')
|| c == QLatin1Char('/') || c == QLatin1Char('/')
|| c == QLatin1Char('\\')) || c == QLatin1Char('\\');
return true;
return false;
} }
CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
...@@ -239,17 +247,16 @@ CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, ...@@ -239,17 +247,16 @@ CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
return link; return link;
} }
// //
// CMakeDocument // CMakeDocument
// //
CMakeDocument::CMakeDocument() CMakeDocument::CMakeDocument()
: TextEditor::BaseTextDocument()
{ {
setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID); setId(Constants::CMAKE_EDITOR_ID);
setMimeType(QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE)); setMimeType(QLatin1String(Constants::CMAKEMIMETYPE));
Core::MimeType mimeType = Core::MimeDatabase::findByType(QLatin1String(Constants::CMAKEMIMETYPE)); MimeType mimeType = MimeDatabase::findByType(QLatin1String(Constants::CMAKEMIMETYPE));
setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(mimeType)); setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(mimeType));
} }
...@@ -264,3 +271,32 @@ QString CMakeDocument::suggestedFileName() const ...@@ -264,3 +271,32 @@ QString CMakeDocument::suggestedFileName() const
QFileInfo fi(filePath()); QFileInfo fi(filePath());
return fi.fileName(); return fi.fileName();
} }
//
// CMakeEditorFactory
//
CMakeEditorFactory::CMakeEditorFactory()
{
setId(Constants::CMAKE_EDITOR_ID);
setDisplayName(tr(Constants::CMAKE_EDITOR_DISPLAY_NAME));
addMimeType(Constants::CMAKEMIMETYPE);
addMimeType(Constants::CMAKEPROJECTMIMETYPE);
new TextEditorActionHandler(this, Constants::C_CMAKEEDITOR,
TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
contextMenu->addAction(ActionManager::command(TextEditor::Constants::JUMP_TO_FILE_UNDER_CURSOR));
contextMenu->addSeparator(Context(C_CMAKEEDITOR));
contextMenu->addAction(ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION));
}
IEditor *CMakeEditorFactory::createEditor()
{
return new CMakeEditor;
}
} // namespace Internal
} // namespace CMakeProjectManager
...@@ -33,17 +33,12 @@ ...@@ -33,17 +33,12 @@
#include <texteditor/basetextdocument.h> #include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <texteditor/codeassist/completionassistprovider.h> #include <texteditor/codeassist/completionassistprovider.h>
#include <utils/uncommentselection.h> #include <coreplugin/editormanager/ieditorfactory.h>
namespace TextEditor { class FontSettings; }
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
class CMakeEditorWidget; class CMakeEditorWidget;
class CMakeHighlighter;
class CMakeManager;
class CMakeEditor : public TextEditor::BaseTextEditor class CMakeEditor : public TextEditor::BaseTextEditor
{ {
...@@ -52,7 +47,6 @@ class CMakeEditor : public TextEditor::BaseTextEditor ...@@ -52,7 +47,6 @@ class CMakeEditor : public TextEditor::BaseTextEditor
public: public:
CMakeEditor(); CMakeEditor();
Core::IEditor *duplicate();
QString contextHelpId() const; QString contextHelpId() const;
friend class CMakeEditorWidget; friend class CMakeEditorWidget;
...@@ -69,11 +63,9 @@ class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget ...@@ -69,11 +63,9 @@ class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget
public: public:
CMakeEditorWidget(); CMakeEditorWidget();
private:
bool save(const QString &fileName = QString()); bool save(const QString &fileName = QString());
Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true, bool inNextSplit = false); Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true, bool inNextSplit = false);
protected:
TextEditor::BaseTextEditor *createEditor(); TextEditor::BaseTextEditor *createEditor();
void contextMenuEvent(QContextMenuEvent *e); void contextMenuEvent(QContextMenuEvent *e);
}; };
...@@ -84,10 +76,20 @@ class CMakeDocument : public TextEditor::BaseTextDocument ...@@ -84,10 +76,20 @@ class CMakeDocument : public TextEditor::BaseTextDocument
public: public:
CMakeDocument(); CMakeDocument();
QString defaultPath() const; QString defaultPath() const;
QString suggestedFileName() const; QString suggestedFileName() const;
}; };
class CMakeEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
CMakeEditorFactory();
Core::IEditor *createEditor();
};
} // namespace Internal } // namespace Internal
} // namespace CMakeProjectManager } // namespace CMakeProjectManager
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cmakeeditorfactory.h"
#include "cmakeprojectconstants.h"
#include "cmakeeditor.h"
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h>
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
: m_manager(manager)
{
using namespace Core;
using namespace TextEditor;
setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
setDisplayName(tr(CMakeProjectManager::Constants::CMAKE_EDITOR_DISPLAY_NAME));
addMimeType(CMakeProjectManager::Constants::CMAKEMIMETYPE);
addMimeType(CMakeProjectManager::Constants::CMAKEPROJECTMIMETYPE);
new TextEditorActionHandler(this, Constants::C_CMAKEEDITOR,
TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
ActionContainer *contextMenu = Core::ActionManager::createMenu(Constants::M_CONTEXT);
Command *cmd;
Context cmakeEditorContext = Context(Constants::C_CMAKEEDITOR);
cmd = Core::ActionManager::command(TextEditor::Constants::JUMP_TO_FILE_UNDER_CURSOR);
contextMenu->addAction(cmd);
contextMenu->addSeparator(cmakeEditorContext);
cmd = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu->addAction(cmd);
}
Core::IEditor *CMakeEditorFactory::createEditor()
{
CMakeEditorWidget *widget = new CMakeEditorWidget;
widget->setTextDocument(TextEditor::BaseTextDocumentPtr(new CMakeDocument));
return widget->editor();
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CMAKEEDITORFACTORY_H
#define CMAKEEDITORFACTORY_H
#include "cmakeprojectmanager.h"
#include <coreplugin/editormanager/ieditorfactory.h>
namespace CMakeProjectManager {
namespace Internal {
class CMakeEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
CMakeEditorFactory(CMakeManager *parent);
Core::IEditor *createEditor();
private:
const QStringList m_mimeTypes;
CMakeManager *m_manager;
};
} // namespace Internal
} // namespace CMakeProjectManager
#endif // CMAKEEDITORFACTORY_H
...@@ -10,7 +10,6 @@ HEADERS = cmakebuildinfo.h \ ...@@ -10,7 +10,6 @@ HEADERS = cmakebuildinfo.h \
cmakerunconfiguration.h \ cmakerunconfiguration.h \
cmakeopenprojectwizard.h \ cmakeopenprojectwizard.h \
cmakebuildconfiguration.h \ cmakebuildconfiguration.h \
cmakeeditorfactory.h \
cmakeeditor.h \ cmakeeditor.h \
cmakelocatorfilter.h \ cmakelocatorfilter.h \
cmakefilecompletionassist.h \ cmakefilecompletionassist.h \
...@@ -27,7 +26,6 @@ SOURCES = cmakeproject.cpp \ ...@@ -27,7 +26,6 @@ SOURCES = cmakeproject.cpp \
cmakerunconfiguration.cpp \ cmakerunconfiguration.cpp \
cmakeopenprojectwizard.cpp \ cmakeopenprojectwizard.cpp \
cmakebuildconfiguration.cpp \ cmakebuildconfiguration.cpp \
cmakeeditorfactory.cpp \
cmakeeditor.cpp \ cmakeeditor.cpp \
cmakelocatorfilter.cpp \ cmakelocatorfilter.cpp \
cmakefilecompletionassist.cpp \ cmakefilecompletionassist.cpp \
......
...@@ -25,8 +25,6 @@ QtcPlugin { ...@@ -25,8 +25,6 @@ QtcPlugin {
"cmakebuildinfo.h", "cmakebuildinfo.h",
"cmakeeditor.cpp", "cmakeeditor.cpp",
"cmakeeditor.h", "cmakeeditor.h",
"cmakeeditorfactory.cpp",
"cmakeeditorfactory.h",
"cmakefilecompletionassist.cpp", "cmakefilecompletionassist.cpp",
"cmakefilecompletionassist.h", "cmakefilecompletionassist.h",
"cmakelocatorfilter.cpp", "cmakelocatorfilter.cpp",
......
...@@ -28,10 +28,11 @@ ...@@ -28,10 +28,11 @@
****************************************************************************/ ****************************************************************************/
#include "cmakeprojectplugin.h" #include "cmakeprojectplugin.h"
#include "cmakeeditor.h"
#include "cmakeprojectmanager.h" #include "cmakeprojectmanager.h"
#include "cmakebuildconfiguration.h" #include "cmakebuildconfiguration.h"
#include "cmakerunconfiguration.h" #include "cmakerunconfiguration.h"
#include "cmakeeditorfactory.h"
#include "makestep.h" #include "makestep.h"
#include "cmakeprojectconstants.h" #include "cmakeprojectconstants.h"
#include "cmakelocatorfilter.h" #include "cmakelocatorfilter.h"
...@@ -39,7 +40,6 @@ ...@@ -39,7 +40,6 @@
#include <coreplugin/featureprovider.h> #include <coreplugin/featureprovider.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <texteditor/texteditoractionhandler.h>
#include <QtPlugin> #include <QtPlugin>
#include <QDebug> #include <QDebug>
...@@ -61,13 +61,12 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString * ...@@ -61,13 +61,12 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
return false; return false;
CMakeSettingsPage *cmp = new CMakeSettingsPage(); CMakeSettingsPage *cmp = new CMakeSettingsPage();
addAutoReleasedObject(cmp); addAutoReleasedObject(cmp);
CMakeManager *manager = new CMakeManager(cmp); addAutoReleasedObject(new CMakeManager(cmp));
addAutoReleasedObject(manager);
addAutoReleasedObject(new MakeStepFactory); addAutoReleasedObject(new MakeStepFactory);
addAutoReleasedObject(new CMakeRunConfigurationFactory); addAutoReleasedObject(new CMakeRunConfigurationFactory);
addAutoReleasedObject(new CMakeBuildConfigurationFactory); addAutoReleasedObject(new CMakeBuildConfigurationFactory);
addAutoReleasedObject(new CMakeEditorFactory(manager)); addAutoReleasedObject(new CMakeEditorFactory);
addAutoReleasedObject(new CMakeLocatorFilter); addAutoReleasedObject(new CMakeLocatorFilter);
addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp)); addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp));
......
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