Commit 6290aa83 authored by Leandro Melo's avatar Leandro Melo

Started mechanism to scan directory, find definition files, and register mime types.

parent cafba7db
This diff is collapsed.
......@@ -30,7 +30,8 @@ DATA_DIRS = \
styles \
gdbmacros \
qmldesigner \
qml-type-descriptions
qml-type-descriptions \
generic-highlighter
!isEmpty(copydata) {
......
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/css">
<sub-class-of type="text/plain"/>
<comment>CSS file</comment>
<glob pattern="*.css"/>
</mime-type>
<mime-type type="text/x-fortran">
<sub-class-of type="text/plain"/>
<comment>Fortran file</comment>
<glob pattern="*.f90"/>
</mime-type>
<mime-type type="text/html">
<sub-class-of type="text/plain"/>
<comment>HTML file</comment>
<glob pattern="*.htm"/>
<glob pattern="*.html"/>
<glob pattern="*.shtml"/>
</mime-type>
<mime-type type="text/x-java">
<sub-class-of type="text/plain"/>
<comment>Java file</comment>
<glob pattern="*.java"/>
</mime-type>
<mime-type type="application/x-javascript">
<sub-class-of type="text/plain"/>
<comment>Javascript file</comment>
<glob pattern="*.js"/>
</mime-type>
<mime-type type="application/x-perl">
<sub-class-of type="text/plain"/>
<comment>Perl file</comment>
<glob pattern="*.pl"/>
<glob pattern="*.pm"/>
</mime-type>
<mime-type type="application/x-php">
<sub-class-of type="text/plain"/>
<comment>PHP file</comment>
<glob pattern="*.php"/>
</mime-type>
<mime-type type="text/x-python">
<sub-class-of type="text/plain"/>
<comment>Python file</comment>
<glob pattern="*.py"/>
</mime-type>
<mime-type type="text/x-ruby">
<sub-class-of type="text/plain"/>
<comment>Ruby file</comment>
<glob pattern="*.rb"/>
</mime-type>
<mime-type type="text/x-sql">
<sub-class-of type="text/plain"/>
<comment>SQL file</comment>
<glob pattern="*.sql"/>
</mime-type>
<mime-type type="application/x-tcl">
<sub-class-of type="text/plain"/>
<comment>TCL file</comment>
<glob pattern="*.tcl"/>
</mime-type>
<mime-type type="text/x-csrc">
<sub-class-of type="text/plain"/>
<comment>C Source file</comment>
<glob pattern="*.c"/>
<!-- NVIDIA CUDA files are like C -->
<glob pattern="*.cu"/>
</mime-type>
<!-- A C Header file is virtually undistinguishable from the C++ header -->
<mime-type type="text/x-chdr">
<sub-class-of type="text/x-csrc"/>
<comment>C Header file</comment>
<glob pattern="*.h"/>
</mime-type>
<!-- Those are used to find matching headers by the CppTools plugin,
so, they should match -->
<mime-type type="text/x-c++hdr">
<sub-class-of type="text/x-chdr"/>
<comment>C++ Header file</comment>
<comment>C++ header</comment>
<glob pattern="*.h"/>
<glob pattern="*.hh"/>
<glob pattern="*.hxx"/>
<glob pattern="*.h++"/>
<glob pattern="*.H"/>
<glob pattern="*.hpp"/>
<glob pattern="*.hp"/>
<!-- Find include guards of header files without extension, for
example, STL ones like <string> -->
<magic priority="50">
<match value="#ifndef" type="string" offset="0:1000"/>
</magic>
</mime-type>
<mime-type type="text/x-c++src">
<comment>C++ Source file</comment>
<sub-class-of type="text/x-csrc"/>
<comment>C++ source code</comment>
<glob pattern="*.cpp"/>
<glob pattern="*.cp"/>
<glob pattern="*.cc"/>
<glob pattern="*.cxx"/>
<glob pattern="*.c++"/>
<glob pattern="*.C"/>
<glob pattern="*.inl"/>
<glob pattern="*.moc"/>
<glob pattern="*.qdoc"/>
</mime-type>
<mime-type type="text/x-objcsrc">
<comment>Objective-C source code</comment>
<sub-class-of type="text/x-csrc"/>
<magic priority="30">
<match value="#import" type="string" offset="0"/>
</magic>
<glob pattern="*.m"/>
<glob pattern="*.mm"/>
</mime-type>
</mime-info>
This diff is collapsed.
......@@ -38,25 +38,7 @@ using namespace GenericEditor;
using namespace Internal;
EditorFactory::EditorFactory(QObject *parent) : Core::IEditorFactory(parent)
{
// Note: This is temporary until it is definied how definition files should be "integrated".
m_mimeTypes << QLatin1String(GenericEditor::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::C_SOURCE_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::CPP_HEADER_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::CSS_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::FORTRAN_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::HTML_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::JAVA_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::JAVASCRIPT_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::OBJECTIVEC_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::PERL_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::PHP_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::PYTHON_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::RUBY_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::SQL_MIMETYPE)
<< QLatin1String(GenericEditor::Constants::TCL_MIMETYPE);
}
{}
EditorFactory::~EditorFactory()
{}
......@@ -68,14 +50,14 @@ Core::IEditor *EditorFactory::createEditor(QWidget *parent)
return genericEditor->editableInterface();
}
QStringList EditorFactory::mimeTypes() const
{ return m_mimeTypes; }
QString EditorFactory::id() const
{
return QLatin1String(GenericEditor::Constants::GENERIC_EDITOR);
}
QStringList EditorFactory::mimeTypes() const
{ return m_mimeTypes; }
QString EditorFactory::displayName() const
{
return tr(GenericEditor::Constants::GENERIC_EDITOR_DISPLAY_NAME);
......
......@@ -43,6 +43,7 @@ class EditorFactory : public Core::IEditorFactory
{
Q_OBJECT
friend class GenericEditorPlugin;
public:
EditorFactory(QObject *parent = 0);
virtual ~EditorFactory();
......
......@@ -40,7 +40,4 @@ SOURCES += \
editor.cpp \
editorfactory.cpp
OTHER_FILES += GenericEditor.pluginspec GenericEditor.mimetypes.xml
RESOURCES += \
genericeditor.qrc
OTHER_FILES += GenericEditor.pluginspec
<RCC>
<qresource prefix="/genericeditor">
<file>XML/c.xml</file>
<file>XML/cpp.xml</file>
<file>XML/fortran.xml</file>
<file>XML/html.xml</file>
<file>XML/java.xml</file>
<file>XML/javadoc.xml</file>
<file>XML/javascript.xml</file>
<file>XML/objectivec.xml</file>
<file>XML/perl.xml</file>
<file>XML/php.xml</file>
<file>XML/python.xml</file>
<file>XML/ruby.xml</file>
<file>XML/sql.xml</file>
<file>XML/tcl.xml</file>
<file>XML/alert.xml</file>
<file>XML/css.xml</file>
<file>XML/doxygen.xml</file>
<file>GenericEditor.mimetypes.xml</file>
</qresource>
</RCC>
......@@ -39,23 +39,6 @@ const char * const GENERIC_EDITOR = "GenericEditorPlugin.GenericEditor";
const char * const GENERIC_EDITOR_DISPLAY_NAME =
QT_TRANSLATE_NOOP("OpenWith::Editors", "Generic Editor");
const char * const C_SOURCE_MIMETYPE = "text/x-csrc";
const char * const C_HEADER_MIMETYPE = "text/x-chdr";
const char * const CPP_SOURCE_MIMETYPE = "text/x-c++src";
const char * const CPP_HEADER_MIMETYPE = "text/x-c++hdr";
const char * const CSS_MIMETYPE = "text/css";
const char * const FORTRAN_MIMETYPE = "text/x-fortran";
const char * const HTML_MIMETYPE = "text/html";
const char * const JAVA_MIMETYPE = "text/x-java";
const char * const JAVASCRIPT_MIMETYPE = "application/x-javascript";
const char * const OBJECTIVEC_MIMETYPE = "text/x-objcsrc";
const char * const PERL_MIMETYPE = "application/x-perl";
const char * const PHP_MIMETYPE = "application/x-php";
const char * const PYTHON_MIMETYPE = "text/x-python";
const char * const RUBY_MIMETYPE = "text/x-ruby";
const char * const SQL_MIMETYPE = "text/x-sql";
const char * const TCL_MIMETYPE = "application/x-tcl";
} // namespace Constants
} // namespace GenericEditor
......
......@@ -34,19 +34,25 @@
#include <texteditor/texteditoractionhandler.h>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QLatin1String>
#include <QtCore/QHash>
#include <QtCore/QMultiHash>
#include <QtCore/QSet>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
class QFileInfo;
class QStringList;
QT_END_NAMESPACE
namespace GenericEditor {
namespace Internal {
class HighlightDefinition;
class HighlightDefinitionMetadata;
class Editor;
// Note: The general interface of this class is temporary. Still need discussing details about
// the definition files integration with Creator.
class EditorFactory;
class GenericEditorPlugin : public ExtensionSystem::IPlugin
{
......@@ -68,23 +74,8 @@ public:
bool isBuildingDefinition(const QString &id) const;
const QSharedPointer<HighlightDefinition> &definition(const QString &id);
static const QLatin1String kAlertDefinitionId;
static const QLatin1String kCDefinitionId;
static const QLatin1String kCppDefinitionId;
static const QLatin1String kCssDefinitionId;
static const QLatin1String kDoxygenDefinitionId;
static const QLatin1String kFortranDefinitionId;
static const QLatin1String kHtmlDefinitionId;
static const QLatin1String kJavaDefinitionId;
static const QLatin1String kJavadocDefinitionId;
static const QLatin1String kJavascriptDefinitionId;
static const QLatin1String kObjectiveCDefinitionId;
static const QLatin1String kPerlDefinitionId;
static const QLatin1String kPhpDefinitionId;
static const QLatin1String kPythonDefinitionId;
static const QLatin1String kRubyDefinitionId;
static const QLatin1String kSqlDefinitionId;
static const QLatin1String kTclDefinitionId;
private slots:
void lookforAvailableDefinitions();
private:
GenericEditorPlugin(const GenericEditorPlugin &HighlighterPlugin);
......@@ -92,12 +83,28 @@ private:
static GenericEditorPlugin *m_instance;
QSet<QString> m_isBuilding;
QHash<QString, QString> m_idByName;
QHash<QString, QString> m_idByMimeType;
QHash<QString, QSharedPointer<HighlightDefinition> > m_definitions;
void parseDefinitionMetadata(const QFileInfo &fileInfo);
void registerMimeTypes(const QString &comment,
const QStringList &types,
const QStringList &patterns);
struct PriorityCompare
{
bool operator()(const QString &a, const QString &b)
{ return m_priorityById.value(a) < m_priorityById.value(b); }
QHash<QString, int> m_priorityById;
};
PriorityCompare m_priorityComp;
TextEditor::TextEditorActionHandler *m_actionHandler;
EditorFactory *m_factory;
QHash<QString, QString> m_idByName;
QMultiHash<QString, QString> m_idByMimeType;
QHash<QString, QSharedPointer<HighlightDefinition> > m_definitions;
QSet<QString> m_isBuilding;
};
} // namespace Internal
......
......@@ -165,15 +165,3 @@ void HighlightDefinition::setKeywordsSensitive(const QString &sensitivity)
Qt::CaseSensitivity HighlightDefinition::keywordsSensitive() const
{ return m_keywordCaseSensitivity; }
void HighlightDefinition::setLanguageName(const QString &name)
{ m_languageName = name; }
const QString &HighlightDefinition::languageName() const
{ return m_languageName; }
void HighlightDefinition::setFileExtensions(const QString &extensions)
{
//Todo
Q_UNUSED(extensions);
}
......@@ -81,12 +81,6 @@ public:
void setMultiLineCommentRegion(const QString &region);
const QString &multiLineCommentRegion() const;
void setLanguageName(const QString &name);
const QString &languageName() const;
//Todo: Will use?
void setFileExtensions(const QString &extensions);
private:
HighlightDefinition(const HighlightDefinition &);
......
......@@ -179,8 +179,6 @@ bool HighlightDefinitionHandler::startElement(const QString &,
detectSpacesStarted(atts);
} else if (qName == kDetectIdentifier) {
detectIdentifier(atts);
} else if (qName == kLanguage) {
languageElementStarted(atts);
}
return true;
......@@ -211,12 +209,6 @@ bool HighlightDefinitionHandler::characters(const QString& ch)
return true;
}
void HighlightDefinitionHandler::languageElementStarted(const QXmlAttributes &atts) const
{
m_definition->setLanguageName(atts.value(kName));
m_definition->setFileExtensions(atts.value(kExtensions));
}
void HighlightDefinitionHandler::listElementStarted(const QXmlAttributes &atts)
{
m_currentList = m_definition->createKeywordList(atts.value(kName));
......
......@@ -59,7 +59,6 @@ public:
bool characters(const QString &ch);
private:
void languageElementStarted(const QXmlAttributes &atts) const;
void listElementStarted(const QXmlAttributes &atts);
void itemElementStarted();
void contextElementStarted(const QXmlAttributes &atts);
......
......@@ -438,12 +438,14 @@ void Highlighter::configureFormats(const TextEditor::FontSettings & fs)
QLatin1String(TextEditor::Constants::C_KEYWORD));
m_genericFormats[ItemData::kDsDataType] = fs.toTextCharFormat(
QLatin1String(TextEditor::Constants::C_TYPE));
// Currenlty using C_NUMBER for all kinds of numbers.
m_genericFormats[ItemData::kDsDecVal] = fs.toTextCharFormat(
QLatin1String(TextEditor::Constants::C_NUMBER));
m_genericFormats[ItemData::kDsBaseN] = fs.toTextCharFormat(
QLatin1String(TextEditor::Constants::C_NUMBER));
m_genericFormats[ItemData::kDsFloat] = fs.toTextCharFormat(
QLatin1String(TextEditor::Constants::C_NUMBER));
// Currently using C_STRING for strings and chars.
m_genericFormats[ItemData::kDsChar] = fs.toTextCharFormat(
QLatin1String(TextEditor::Constants::C_STRING));
m_genericFormats[ItemData::kDsString] = fs.toTextCharFormat(
......
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