diff options
author | hjk <hjk121@nokiamail.com> | 2014-08-20 00:07:43 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2014-08-20 15:52:47 +0200 |
commit | f0dfe2dcaba9eb446bf5f9d6c9da72f44d4d9c25 (patch) | |
tree | 99fea7c383b9cc5585344f9a2d4540d01a5fd1e1 /src/plugins/cmakeprojectmanager/cmakeeditor.cpp | |
parent | b86269edbdfacc27e4b967e4a41c4359c7af0ae5 (diff) | |
download | qt-creator-f0dfe2dcaba9eb446bf5f9d6c9da72f44d4d9c25.tar.gz |
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>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/cmakeeditor.cpp')
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeeditor.cpp | 108 |
1 files changed, 72 insertions, 36 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index ad5cb4350d..d0e34e06ff 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -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>()); -} - -Core::IEditor *CMakeEditor::duplicate() -{ - CMakeEditorWidget *ret = new CMakeEditorWidget; - ret->setTextDocument(editorWidget()->textDocumentPtr()); - return ret->editor(); + setEditorCreator([]() { return new CMakeEditor; }); + setWidgetCreator([]() { return new CMakeEditorWidget; }); + + 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)); + setId(Constants::CMAKE_EDITOR_ID); + setMimeType(QLatin1String(Constants::CMAKEMIMETYPE)); - Core::MimeType mimeType = Core::MimeDatabase::findByType(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 |