Commit 3a2974b3 authored by mae's avatar mae
Browse files

some action cleanup for the qml editor

done with Erik Verbruggen
parent dc40d764
...@@ -1868,7 +1868,8 @@ void CPPEditor::setFontSettings(const TextEditor::FontSettings &fs) ...@@ -1868,7 +1868,8 @@ void CPPEditor::setFontSettings(const TextEditor::FontSettings &fs)
<< QLatin1String(TextEditor::Constants::C_LABEL) << QLatin1String(TextEditor::Constants::C_LABEL)
<< QLatin1String(TextEditor::Constants::C_COMMENT) << QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_COMMENT) << QLatin1String(TextEditor::Constants::C_DOXYGEN_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_TAG); << QLatin1String(TextEditor::Constants::C_DOXYGEN_TAG)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
} }
const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories); const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories);
......
...@@ -49,6 +49,7 @@ enum CppFormats { ...@@ -49,6 +49,7 @@ enum CppFormats {
CppCommentFormat, CppCommentFormat,
CppDoxygenCommentFormat, CppDoxygenCommentFormat,
CppDoxygenTagFormat, CppDoxygenTagFormat,
CppVisualWhitespace,
NumCppFormats NumCppFormats
}; };
......
...@@ -44,7 +44,6 @@ using namespace CPlusPlus; ...@@ -44,7 +44,6 @@ using namespace CPlusPlus;
CppHighlighter::CppHighlighter(QTextDocument *document) : CppHighlighter::CppHighlighter(QTextDocument *document) :
QSyntaxHighlighter(document) QSyntaxHighlighter(document)
{ {
visualSpaceFormat.setForeground(Qt::lightGray);
} }
void CppHighlighter::highlightBlock(const QString &text) void CppHighlighter::highlightBlock(const QString &text)
...@@ -75,7 +74,7 @@ void CppHighlighter::highlightBlock(const QString &text) ...@@ -75,7 +74,7 @@ void CppHighlighter::highlightBlock(const QString &text)
} }
TextEditDocumentLayout::clearParentheses(currentBlock()); TextEditDocumentLayout::clearParentheses(currentBlock());
if (text.length()) // the empty line can still contain whitespace if (text.length()) // the empty line can still contain whitespace
setFormat(0, text.length(), visualSpaceFormat); setFormat(0, text.length(), m_formats[CppVisualWhitespace]);
return; return;
} }
...@@ -98,7 +97,7 @@ void CppHighlighter::highlightBlock(const QString &text) ...@@ -98,7 +97,7 @@ void CppHighlighter::highlightBlock(const QString &text)
if (previousTokenEnd != tk.position()) { if (previousTokenEnd != tk.position()) {
setFormat(previousTokenEnd, tk.position() - previousTokenEnd, setFormat(previousTokenEnd, tk.position() - previousTokenEnd,
visualSpaceFormat); m_formats[CppVisualWhitespace]);
} }
if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) { if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) {
...@@ -176,7 +175,7 @@ void CppHighlighter::highlightBlock(const QString &text) ...@@ -176,7 +175,7 @@ void CppHighlighter::highlightBlock(const QString &text)
const SimpleToken tk = tokens.last(); const SimpleToken tk = tokens.last();
const int lastTokenEnd = tk.position() + tk.length(); const int lastTokenEnd = tk.position() + tk.length();
if (text.length() > lastTokenEnd) if (text.length() > lastTokenEnd)
setFormat(lastTokenEnd, text.length() - lastTokenEnd, visualSpaceFormat); setFormat(lastTokenEnd, text.length() - lastTokenEnd, m_formats[CppVisualWhitespace]);
} }
if (TextBlockUserData *userData = TextEditDocumentLayout::testUserData(currentBlock())) { if (TextBlockUserData *userData = TextEditDocumentLayout::testUserData(currentBlock())) {
......
...@@ -65,7 +65,6 @@ private: ...@@ -65,7 +65,6 @@ private:
bool isQtKeyword(const QStringRef &text) const; bool isQtKeyword(const QStringRef &text) const;
QTextCharFormat m_formats[NumCppFormats]; QTextCharFormat m_formats[NumCppFormats];
QTextCharFormat visualSpaceFormat;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/uniqueidmanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <texteditor/basetextdocument.h> #include <texteditor/basetextdocument.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
...@@ -364,14 +365,17 @@ protected: ...@@ -364,14 +365,17 @@ protected:
#endif #endif
}; };
ScriptEditorEditable::ScriptEditorEditable(ScriptEditor *editor, const QList<int> &context) ScriptEditorEditable::ScriptEditorEditable(ScriptEditor *editor)
: BaseTextEditorEditable(editor), m_context(context) : BaseTextEditorEditable(editor)
{ {
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
m_context << uidm->uniqueIdentifier(QmlEditor::Constants::C_QMLEDITOR);
m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
} }
ScriptEditor::ScriptEditor(const Context &context, QWidget *parent) : ScriptEditor::ScriptEditor(QWidget *parent) :
TextEditor::BaseTextEditor(parent), TextEditor::BaseTextEditor(parent),
m_context(context),
m_methodCombo(0), m_methodCombo(0),
m_modelManager(0) m_modelManager(0)
{ {
...@@ -411,7 +415,7 @@ QStringList ScriptEditor::words() const ...@@ -411,7 +415,7 @@ QStringList ScriptEditor::words() const
Core::IEditor *ScriptEditorEditable::duplicate(QWidget *parent) Core::IEditor *ScriptEditorEditable::duplicate(QWidget *parent)
{ {
ScriptEditor *newEditor = new ScriptEditor(m_context, parent); ScriptEditor *newEditor = new ScriptEditor(parent);
newEditor->duplicateFrom(editor()); newEditor->duplicateFrom(editor());
QmlEditorPlugin::instance()->initializeEditor(newEditor); QmlEditorPlugin::instance()->initializeEditor(newEditor);
return newEditor->editableInterface(); return newEditor->editableInterface();
...@@ -605,7 +609,8 @@ void ScriptEditor::setFontSettings(const TextEditor::FontSettings &fs) ...@@ -605,7 +609,8 @@ void ScriptEditor::setFontSettings(const TextEditor::FontSettings &fs)
<< QLatin1String(TextEditor::Constants::C_KEYWORD) << QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_PREPROCESSOR) << QLatin1String(TextEditor::Constants::C_PREPROCESSOR)
<< QLatin1String(TextEditor::Constants::C_LABEL) << QLatin1String(TextEditor::Constants::C_LABEL)
<< QLatin1String(TextEditor::Constants::C_COMMENT); << QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
} }
highlighter->setFormats(fs.toTextCharFormats(categories)); highlighter->setFormats(fs.toTextCharFormats(categories));
...@@ -674,7 +679,7 @@ void ScriptEditor::indentBlock(QTextDocument *, QTextBlock block, QChar typedCha ...@@ -674,7 +679,7 @@ void ScriptEditor::indentBlock(QTextDocument *, QTextBlock block, QChar typedCha
TextEditor::BaseTextEditorEditable *ScriptEditor::createEditableInterface() TextEditor::BaseTextEditorEditable *ScriptEditor::createEditableInterface()
{ {
ScriptEditorEditable *editable = new ScriptEditorEditable(this, m_context); ScriptEditorEditable *editable = new ScriptEditorEditable(this);
createToolBar(editable); createToolBar(editable);
return editable; return editable;
} }
......
...@@ -59,7 +59,7 @@ class ScriptEditorEditable : public TextEditor::BaseTextEditorEditable ...@@ -59,7 +59,7 @@ class ScriptEditorEditable : public TextEditor::BaseTextEditorEditable
Q_OBJECT Q_OBJECT
public: public:
ScriptEditorEditable(ScriptEditor *, const QList<int> &); ScriptEditorEditable(ScriptEditor *);
QList<int> context() const; QList<int> context() const;
bool duplicateSupported() const { return true; } bool duplicateSupported() const { return true; }
...@@ -95,8 +95,7 @@ class ScriptEditor : public TextEditor::BaseTextEditor ...@@ -95,8 +95,7 @@ class ScriptEditor : public TextEditor::BaseTextEditor
public: public:
typedef QList<int> Context; typedef QList<int> Context;
ScriptEditor(const Context &context, ScriptEditor(QWidget *parent = 0);
QWidget *parent = 0);
~ScriptEditor(); ~ScriptEditor();
QList<Declaration> declarations() const; QList<Declaration> declarations() const;
......
...@@ -41,18 +41,15 @@ ...@@ -41,18 +41,15 @@
using namespace QmlEditor::Internal; using namespace QmlEditor::Internal;
using namespace QmlEditor::Constants; using namespace QmlEditor::Constants;
QmlEditorFactory::QmlEditorFactory(const Context &context, QObject *parent) QmlEditorFactory::QmlEditorFactory(QObject *parent)
: Core::IEditorFactory(parent), : Core::IEditorFactory(parent),
m_kind(QLatin1String(C_QMLEDITOR)), m_kind(QLatin1String(C_QMLEDITOR)),
m_mimeTypes(QLatin1String(QmlEditor::Constants::QMLEDITOR_MIMETYPE)), m_mimeTypes(QLatin1String(QmlEditor::Constants::QMLEDITOR_MIMETYPE))
m_context(context),
m_actionHandler(new QmlEditorActionHandler)
{ {
} }
QmlEditorFactory::~QmlEditorFactory() QmlEditorFactory::~QmlEditorFactory()
{ {
delete m_actionHandler;
} }
QString QmlEditorFactory::kind() const QString QmlEditorFactory::kind() const
...@@ -72,7 +69,7 @@ Core::IFile *QmlEditorFactory::open(const QString &fileName) ...@@ -72,7 +69,7 @@ Core::IFile *QmlEditorFactory::open(const QString &fileName)
Core::IEditor *QmlEditorFactory::createEditor(QWidget *parent) Core::IEditor *QmlEditorFactory::createEditor(QWidget *parent)
{ {
ScriptEditor *rc = new ScriptEditor(m_context, parent); ScriptEditor *rc = new ScriptEditor(parent);
QmlEditorPlugin::instance()->initializeEditor(rc); QmlEditorPlugin::instance()->initializeEditor(rc);
return rc->editableInterface(); return rc->editableInterface();
} }
......
...@@ -48,9 +48,7 @@ class QmlEditorFactory : public Core::IEditorFactory ...@@ -48,9 +48,7 @@ class QmlEditorFactory : public Core::IEditorFactory
Q_OBJECT Q_OBJECT
public: public:
typedef QList<int> Context; QmlEditorFactory(QObject *parent);
QmlEditorFactory(const Context &context, QObject *parent);
~QmlEditorFactory(); ~QmlEditorFactory();
virtual QStringList mimeTypes() const; virtual QStringList mimeTypes() const;
...@@ -62,9 +60,6 @@ public: ...@@ -62,9 +60,6 @@ public:
private: private:
const QString m_kind; const QString m_kind;
const QStringList m_mimeTypes; const QStringList m_mimeTypes;
const Context m_context;
TextEditor::TextEditorActionHandler *m_actionHandler;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -92,13 +92,10 @@ bool QmlEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err ...@@ -92,13 +92,10 @@ bool QmlEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
m_modelManager = new QmlModelManager(this); m_modelManager = new QmlModelManager(this);
addAutoReleasedObject(m_modelManager); addAutoReleasedObject(m_modelManager);
m_scriptcontext << core->uniqueIDManager()->uniqueIdentifier(QmlEditor::Constants::C_QMLEDITOR); QList<int> context;
m_context = m_scriptcontext; context<< core->uniqueIDManager()->uniqueIdentifier(QmlEditor::Constants::C_QMLEDITOR);
m_context << core->uniqueIDManager()->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
registerActions(); m_editor = new QmlEditorFactory(this);
m_editor = new QmlEditorFactory(m_context, this);
addObject(m_editor); addObject(m_editor);
Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard); Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
...@@ -150,8 +147,4 @@ void QmlEditorPlugin::initializeEditor(QmlEditor::Internal::ScriptEditor *editor ...@@ -150,8 +147,4 @@ void QmlEditorPlugin::initializeEditor(QmlEditor::Internal::ScriptEditor *editor
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool))); TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool)));
} }
void QmlEditorPlugin::registerActions()
{
}
Q_EXPORT_PLUGIN(QmlEditorPlugin) Q_EXPORT_PLUGIN(QmlEditorPlugin)
...@@ -65,14 +65,8 @@ public: ...@@ -65,14 +65,8 @@ public:
void initializeEditor(ScriptEditor *editor); void initializeEditor(ScriptEditor *editor);
private: private:
void registerActions();
static QmlEditorPlugin *m_instance; static QmlEditorPlugin *m_instance;
typedef QList<int> Context;
Context m_context;
Context m_scriptcontext;
QmlModelManagerInterface *m_modelManager; QmlModelManagerInterface *m_modelManager;
QmlFileWizard *m_wizard; QmlFileWizard *m_wizard;
QmlEditorFactory *m_editor; QmlEditorFactory *m_editor;
......
...@@ -322,7 +322,8 @@ void ScriptEditor::setFontSettings(const TextEditor::FontSettings &fs) ...@@ -322,7 +322,8 @@ void ScriptEditor::setFontSettings(const TextEditor::FontSettings &fs)
<< QLatin1String(TextEditor::Constants::C_KEYWORD) << QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_PREPROCESSOR) << QLatin1String(TextEditor::Constants::C_PREPROCESSOR)
<< QLatin1String(TextEditor::Constants::C_LABEL) << QLatin1String(TextEditor::Constants::C_LABEL)
<< QLatin1String(TextEditor::Constants::C_COMMENT); << QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
} }
highlighter->setFormats(fs.toTextCharFormats(categories)); highlighter->setFormats(fs.toTextCharFormats(categories));
......
...@@ -93,6 +93,7 @@ const char * const C_LABEL = "Label"; ...@@ -93,6 +93,7 @@ const char * const C_LABEL = "Label";
const char * const C_COMMENT = "Comment"; const char * const C_COMMENT = "Comment";
const char * const C_DOXYGEN_COMMENT = "Doxygen.Comment"; const char * const C_DOXYGEN_COMMENT = "Doxygen.Comment";
const char * const C_DOXYGEN_TAG = "Doxygen.Tag"; const char * const C_DOXYGEN_TAG = "Doxygen.Tag";
const char * const C_VISUAL_WHITESPACE = "VisualWhitespace";
const char * const C_DISABLED_CODE = "DisabledCode"; const char * const C_DISABLED_CODE = "DisabledCode";
...@@ -101,6 +102,7 @@ const char * const C_REMOVED_LINE = "RemovedLine"; ...@@ -101,6 +102,7 @@ const char * const C_REMOVED_LINE = "RemovedLine";
const char * const C_DIFF_FILE = "DiffFile"; const char * const C_DIFF_FILE = "DiffFile";
const char * const C_DIFF_LOCATION = "DiffLocation"; const char * const C_DIFF_LOCATION = "DiffLocation";
} // namespace Constants } // namespace Constants
} // namespace TextEditor } // namespace TextEditor
......
...@@ -92,6 +92,7 @@ TextEditorSettings::TextEditorSettings(QObject *parent) ...@@ -92,6 +92,7 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
formatDescriptions.append(FormatDescription(QLatin1String(C_COMMENT), tr("Comment"), Qt::darkGreen)); formatDescriptions.append(FormatDescription(QLatin1String(C_COMMENT), tr("Comment"), Qt::darkGreen));
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_COMMENT), tr("Doxygen Comment"), Qt::darkBlue)); formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_COMMENT), tr("Doxygen Comment"), Qt::darkBlue));
formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_TAG), tr("Doxygen Tag"), Qt::blue)); formatDescriptions.append(FormatDescription(QLatin1String(C_DOXYGEN_TAG), tr("Doxygen Tag"), Qt::blue));
formatDescriptions.append(FormatDescription(QLatin1String(C_VISUAL_WHITESPACE), tr("Visual Whitespace"), Qt::lightGray));
formatDescriptions.append(FormatDescription(QLatin1String(C_DISABLED_CODE), tr("Disabled Code"), Qt::gray)); formatDescriptions.append(FormatDescription(QLatin1String(C_DISABLED_CODE), tr("Disabled Code"), Qt::gray));
// Diff categories // Diff categories
......
...@@ -203,6 +203,7 @@ const QVector<QTextCharFormat> &QScriptHighlighter::defaultFormats() ...@@ -203,6 +203,7 @@ const QVector<QTextCharFormat> &QScriptHighlighter::defaultFormats()
rc[CommentFormat].setForeground(Qt::red); rc[CommentFormat].setForeground(Qt::red);
rc[CommentFormat].setFontItalic(true); rc[CommentFormat].setFontItalic(true);
rc[PreProcessorFormat].setForeground(Qt::darkBlue); rc[PreProcessorFormat].setForeground(Qt::darkBlue);
rc[VisualWhitespace].setForeground(Qt::lightGray);
} }
return rc; return rc;
} }
......
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
enum { NumberFormat, StringFormat, TypeFormat, enum { NumberFormat, StringFormat, TypeFormat,
KeywordFormat, PreProcessorFormat, LabelFormat, CommentFormat, KeywordFormat, PreProcessorFormat, LabelFormat, CommentFormat,
VisualWhitespace,
NumFormats }; NumFormats };
bool isDuiEnabled() const; bool isDuiEnabled() const;
......
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