forked from qt-creator/qt-creator
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: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -33,56 +33,68 @@
|
||||
#include "cmakeprojectconstants.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/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 <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <texteditor/highlighterutils.h>
|
||||
#include <texteditor/texteditoractionhandler.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/highlighterutils.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QSharedPointer>
|
||||
#include <QTextBlock>
|
||||
|
||||
using namespace CMakeProjectManager;
|
||||
using namespace CMakeProjectManager::Internal;
|
||||
using namespace Core;
|
||||
using namespace TextEditor;
|
||||
using namespace CMakeProjectManager::Constants;
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
//
|
||||
// ProFileEditorEditable
|
||||
// CMakeEditor
|
||||
//
|
||||
|
||||
CMakeEditor::CMakeEditor()
|
||||
{
|
||||
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
|
||||
TextEditor::Constants::C_TEXTEDITOR));
|
||||
addContext(Constants::C_CMAKEEDITOR);
|
||||
setDuplicateSupported(true);
|
||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
||||
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>());
|
||||
}
|
||||
setEditorCreator([]() { return new CMakeEditor; });
|
||||
setWidgetCreator([]() { return new CMakeEditorWidget; });
|
||||
|
||||
Core::IEditor *CMakeEditor::duplicate()
|
||||
{
|
||||
CMakeEditorWidget *ret = new CMakeEditorWidget;
|
||||
ret->setTextDocument(editorWidget()->textDocumentPtr());
|
||||
return ret->editor();
|
||||
setDocumentCreator([this]() -> BaseTextDocument * {
|
||||
auto doc = new CMakeDocument;
|
||||
connect(doc, &IDocument::changed, this, &CMakeEditor::markAsChanged);
|
||||
return doc;
|
||||
});
|
||||
}
|
||||
|
||||
void CMakeEditor::markAsChanged()
|
||||
{
|
||||
if (!document()->isModified())
|
||||
return;
|
||||
Core::InfoBar *infoBar = document()->infoBar();
|
||||
Core::Id infoRunCmake("CMakeEditor.RunCMake");
|
||||
InfoBar *infoBar = document()->infoBar();
|
||||
Id infoRunCmake("CMakeEditor.RunCMake");
|
||||
if (!infoBar->canInfoBeAdded(infoRunCmake))
|
||||
return;
|
||||
Core::InfoBarEntry info(infoRunCmake,
|
||||
tr("Changes to cmake files are shown in the project tree after building."),
|
||||
Core::InfoBarEntry::GlobalSuppressionEnabled);
|
||||
InfoBarEntry info(infoRunCmake,
|
||||
tr("Changes to cmake files are shown in the project tree after building."),
|
||||
InfoBarEntry::GlobalSuppressionEnabled);
|
||||
info.setCustomButtonInfo(tr("Build now"), this, SLOT(build()));
|
||||
infoBar->addInfo(info);
|
||||
}
|
||||
@@ -103,7 +115,7 @@ void CMakeEditor::build()
|
||||
QString CMakeEditor::contextHelpId() const
|
||||
{
|
||||
int pos = position();
|
||||
TextEditor::BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument();
|
||||
BaseTextDocument *doc = const_cast<CMakeEditor*>(this)->textDocument();
|
||||
|
||||
QChar chr;
|
||||
do {
|
||||
@@ -143,7 +155,7 @@ QString CMakeEditor::contextHelpId() const
|
||||
}
|
||||
|
||||
//
|
||||
// CMakeEditor
|
||||
// CMakeEditorWidget
|
||||
//
|
||||
|
||||
CMakeEditorWidget::CMakeEditorWidget()
|
||||
@@ -151,11 +163,9 @@ CMakeEditorWidget::CMakeEditorWidget()
|
||||
setCodeFoldingSupported(true);
|
||||
}
|
||||
|
||||
TextEditor::BaseTextEditor *CMakeEditorWidget::createEditor()
|
||||
BaseTextEditor *CMakeEditorWidget::createEditor()
|
||||
{
|
||||
auto editor = new CMakeEditor;
|
||||
connect(textDocument(), &Core::IDocument::changed, editor, &CMakeEditor::markAsChanged);
|
||||
return editor;
|
||||
QTC_ASSERT("should not happen anymore" && false, return 0);
|
||||
}
|
||||
|
||||
void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||
@@ -165,14 +175,12 @@ void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||
|
||||
static bool isValidFileNameChar(const QChar &c)
|
||||
{
|
||||
if (c.isLetterOrNumber()
|
||||
return c.isLetterOrNumber()
|
||||
|| c == QLatin1Char('.')
|
||||
|| c == QLatin1Char('_')
|
||||
|| c == QLatin1Char('-')
|
||||
|| c == QLatin1Char('/')
|
||||
|| c == QLatin1Char('\\'))
|
||||
return true;
|
||||
return false;
|
||||
|| c == QLatin1Char('\\');
|
||||
}
|
||||
|
||||
CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
@@ -239,17 +247,16 @@ CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
return link;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CMakeDocument
|
||||
//
|
||||
CMakeDocument::CMakeDocument()
|
||||
: TextEditor::BaseTextDocument()
|
||||
{
|
||||
setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
|
||||
setMimeType(QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE));
|
||||
|
||||
Core::MimeType mimeType = Core::MimeDatabase::findByType(QLatin1String(Constants::CMAKEMIMETYPE));
|
||||
CMakeDocument::CMakeDocument()
|
||||
{
|
||||
setId(Constants::CMAKE_EDITOR_ID);
|
||||
setMimeType(QLatin1String(Constants::CMAKEMIMETYPE));
|
||||
|
||||
MimeType mimeType = MimeDatabase::findByType(QLatin1String(Constants::CMAKEMIMETYPE));
|
||||
setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(mimeType));
|
||||
}
|
||||
|
||||
@@ -264,3 +271,32 @@ QString CMakeDocument::suggestedFileName() const
|
||||
QFileInfo fi(filePath());
|
||||
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 @@
|
||||
#include <texteditor/basetextdocument.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/codeassist/completionassistprovider.h>
|
||||
#include <utils/uncommentselection.h>
|
||||
|
||||
|
||||
namespace TextEditor { class FontSettings; }
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class CMakeEditorWidget;
|
||||
class CMakeHighlighter;
|
||||
class CMakeManager;
|
||||
|
||||
class CMakeEditor : public TextEditor::BaseTextEditor
|
||||
{
|
||||
@@ -52,7 +47,6 @@ class CMakeEditor : public TextEditor::BaseTextEditor
|
||||
public:
|
||||
CMakeEditor();
|
||||
|
||||
Core::IEditor *duplicate();
|
||||
QString contextHelpId() const;
|
||||
|
||||
friend class CMakeEditorWidget;
|
||||
@@ -69,11 +63,9 @@ class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
public:
|
||||
CMakeEditorWidget();
|
||||
|
||||
private:
|
||||
bool save(const QString &fileName = QString());
|
||||
|
||||
Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true, bool inNextSplit = false);
|
||||
|
||||
protected:
|
||||
TextEditor::BaseTextEditor *createEditor();
|
||||
void contextMenuEvent(QContextMenuEvent *e);
|
||||
};
|
||||
@@ -84,10 +76,20 @@ class CMakeDocument : public TextEditor::BaseTextDocument
|
||||
|
||||
public:
|
||||
CMakeDocument();
|
||||
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
};
|
||||
|
||||
class CMakeEditorFactory : public Core::IEditorFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CMakeEditorFactory();
|
||||
Core::IEditor *createEditor();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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();
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 \
|
||||
cmakerunconfiguration.h \
|
||||
cmakeopenprojectwizard.h \
|
||||
cmakebuildconfiguration.h \
|
||||
cmakeeditorfactory.h \
|
||||
cmakeeditor.h \
|
||||
cmakelocatorfilter.h \
|
||||
cmakefilecompletionassist.h \
|
||||
@@ -27,7 +26,6 @@ SOURCES = cmakeproject.cpp \
|
||||
cmakerunconfiguration.cpp \
|
||||
cmakeopenprojectwizard.cpp \
|
||||
cmakebuildconfiguration.cpp \
|
||||
cmakeeditorfactory.cpp \
|
||||
cmakeeditor.cpp \
|
||||
cmakelocatorfilter.cpp \
|
||||
cmakefilecompletionassist.cpp \
|
||||
|
||||
@@ -25,8 +25,6 @@ QtcPlugin {
|
||||
"cmakebuildinfo.h",
|
||||
"cmakeeditor.cpp",
|
||||
"cmakeeditor.h",
|
||||
"cmakeeditorfactory.cpp",
|
||||
"cmakeeditorfactory.h",
|
||||
"cmakefilecompletionassist.cpp",
|
||||
"cmakefilecompletionassist.h",
|
||||
"cmakelocatorfilter.cpp",
|
||||
|
||||
@@ -28,10 +28,11 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "cmakeprojectplugin.h"
|
||||
|
||||
#include "cmakeeditor.h"
|
||||
#include "cmakeprojectmanager.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakerunconfiguration.h"
|
||||
#include "cmakeeditorfactory.h"
|
||||
#include "makestep.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakelocatorfilter.h"
|
||||
@@ -39,7 +40,6 @@
|
||||
|
||||
#include <coreplugin/featureprovider.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <texteditor/texteditoractionhandler.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QDebug>
|
||||
@@ -61,13 +61,12 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
|
||||
return false;
|
||||
CMakeSettingsPage *cmp = new CMakeSettingsPage();
|
||||
addAutoReleasedObject(cmp);
|
||||
CMakeManager *manager = new CMakeManager(cmp);
|
||||
addAutoReleasedObject(manager);
|
||||
addAutoReleasedObject(new CMakeManager(cmp));
|
||||
addAutoReleasedObject(new MakeStepFactory);
|
||||
addAutoReleasedObject(new CMakeRunConfigurationFactory);
|
||||
addAutoReleasedObject(new CMakeBuildConfigurationFactory);
|
||||
|
||||
addAutoReleasedObject(new CMakeEditorFactory(manager));
|
||||
addAutoReleasedObject(new CMakeEditorFactory);
|
||||
addAutoReleasedObject(new CMakeLocatorFilter);
|
||||
addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user