Commit f358034f authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed BAUHAUS-1.

parent a98db7b0
......@@ -379,7 +379,7 @@ ScriptEditor::ScriptEditor(const Context &context, QWidget *parent) :
setMarksVisible(true);
setCodeFoldingSupported(true);
setCodeFoldingVisible(true);
setMimeType(DuiEditor::Constants::C_DUIEDITOR_MIMETYPE);
setMimeType(DuiEditor::Constants::DUIEDITOR_MIMETYPE);
m_updateDocumentTimer = new QTimer(this);
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
......
......@@ -26,7 +26,8 @@ HEADERS += duieditor.h \
qmlexpressionundercursor.h \
qmllookupcontext.h \
qmlresolveexpression.h \
qmlsymbol.h
qmlsymbol.h \
qmlfilewizard.h
SOURCES += duieditor.cpp \
duieditorfactory.cpp \
duieditorplugin.cpp \
......@@ -43,5 +44,6 @@ SOURCES += duieditor.cpp \
qmlexpressionundercursor.cpp \
qmllookupcontext.cpp \
qmlresolveexpression.cpp \
qmlsymbol.cpp
qmlsymbol.cpp \
qmlfilewizard.cpp
RESOURCES += duieditor.qrc
......@@ -38,7 +38,7 @@ const char * const RUN_SEP = "DuiEditor.Run.Separator";
const char * const C_DUIEDITOR = "QML Editor";
const char * const TASK_INDEX = "DuiEditor.TaskIndex";
const char * const C_DUIEDITOR_MIMETYPE = "application/x-dui";
const char * const DUIEDITOR_MIMETYPE = "application/x-dui";
} // namespace Constants
} // namespace DuiEditor
......
......@@ -44,7 +44,7 @@ using namespace DuiEditor::Constants;
DuiEditorFactory::DuiEditorFactory(const Context &context, QObject *parent)
: Core::IEditorFactory(parent),
m_kind(QLatin1String(C_DUIEDITOR)),
m_mimeTypes(QLatin1String(DuiEditor::Constants::C_DUIEDITOR_MIMETYPE)),
m_mimeTypes(QLatin1String(DuiEditor::Constants::DUIEDITOR_MIMETYPE)),
m_context(context),
m_actionHandler(new DuiEditorActionHandler)
{
......
......@@ -36,6 +36,7 @@
#include "duicodecompletion.h"
#include "duihoverhandler.h"
#include "duimodelmanager.h"
#include "qmlfilewizard.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
......@@ -57,6 +58,7 @@
#include <QtCore/QSettings>
#include <QtGui/QAction>
using namespace DuiEditor;
using namespace DuiEditor::Internal;
using namespace DuiEditor::Constants;
......@@ -75,7 +77,6 @@ DuiEditorPlugin::DuiEditorPlugin() :
DuiEditorPlugin::~DuiEditorPlugin()
{
removeObject(m_editor);
removeObject(m_wizard);
delete m_actionHandler;
m_instance = 0;
}
......@@ -101,15 +102,11 @@ bool DuiEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addObject(m_editor);
Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setDescription(tr("Creates a Qt QML file."));
wizardParameters.setName(tr("Qt QML File"));
wizardParameters.setCategory(QLatin1String("Qt"));
wizardParameters.setTrCategory(tr("Qt"));
m_wizard = new TextEditor::TextFileWizard(QLatin1String(DuiEditor::Constants::C_DUIEDITOR_MIMETYPE),
QLatin1String(DuiEditor::Constants::C_DUIEDITOR),
QLatin1String("dui$"),
wizardParameters, this);
addObject(m_wizard);
wizardParameters.setDescription(tr("Creates a Qt QML file."));
wizardParameters.setName(tr("Qt QML File"));
addAutoReleasedObject(new QmlFileWizard(wizardParameters, core));
m_actionHandler = new TextEditor::TextEditorActionHandler(DuiEditor::Constants::C_DUIEDITOR,
TextEditor::TextEditorActionHandler::Format
......
......@@ -33,13 +33,13 @@
#include <extensionsystem/iplugin.h>
namespace TextEditor {
class TextFileWizard;
class TextEditorActionHandler;
} // namespace TextEditor
namespace DuiEditor {
class DuiModelManagerInterface;
class QmlFileWizard;
namespace Internal {
......@@ -74,7 +74,7 @@ private:
Context m_scriptcontext;
DuiModelManagerInterface *m_modelManager;
TextEditor::TextFileWizard *m_wizard;
QmlFileWizard *m_wizard;
DuiEditorFactory *m_editor;
TextEditor::TextEditorActionHandler *m_actionHandler;
DuiCodeCompletion *m_completion;
......
#include "duieditorconstants.h"
#include "qmlfilewizard.h"
#include <QtCore/QFileInfo>
#include <QtCore/QTextStream>
using namespace DuiEditor;
QmlFileWizard::QmlFileWizard(const BaseFileWizardParameters &parameters,
QObject *parent):
Core::StandardFileWizard(parameters, parent)
{
}
Core::GeneratedFiles QmlFileWizard::generateFilesFromPath(const QString &path,
const QString &name,
QString * /*errorMessage*/) const
{
const QString mimeType = QLatin1String(Constants::DUIEDITOR_MIMETYPE);
const QString fileName = Core::BaseFileWizard::buildFileName(path, name, preferredSuffix(mimeType));
Core::GeneratedFile file(fileName);
file.setEditorKind(QLatin1String(Constants::C_DUIEDITOR));
file.setContents(fileContents(fileName));
return Core::GeneratedFiles() << file;
}
QString QmlFileWizard::fileContents(const QString &fileName) const
{
const QString baseName = QFileInfo(fileName).completeBaseName();
QString contents;
QTextStream str(&contents);
// str << CppTools::AbstractEditorSupport::licenseTemplate();
str << QLatin1String("import Qt 4.6\n")
<< QLatin1String("\n")
<< QLatin1String("Rectangle {\n")
<< QLatin1String(" width: 640\n")
<< QLatin1String(" height: 480\n")
<< QLatin1String("}\n");
return contents;
}
#ifndef QMLFILEWIZARD_H
#define QMLFILEWIZARD_H
#include <coreplugin/basefilewizard.h>
namespace DuiEditor {
class QmlFileWizard: public Core::StandardFileWizard
{
Q_OBJECT
public:
typedef Core::BaseFileWizardParameters BaseFileWizardParameters;
QmlFileWizard(const BaseFileWizardParameters &parameters,
QObject *parent = 0);
protected:
QString fileContents(const QString &baseName) const;
protected:
Core::GeneratedFiles generateFilesFromPath(const QString &path,
const QString &fileName,
QString *errorMessage) const;
};
} // namespace DuiEditor
#endif // QMLFILEWIZARD_H
......@@ -168,3 +168,40 @@ QString QmlLookupContext::toString(UiQualifiedId *id)
return str;
}
QList<QmlSymbol*> QmlLookupContext::visibleSymbols(QmlJS::AST::Node *scope)
{
// FIXME
}
QList<QmlSymbol*> QmlLookupContext::visibleTypes()
{
QList<QmlSymbol*> result;
UiProgram *program = _doc->program();
if (!program)
return result;
for (UiImportList *iter = program->imports; iter; iter = iter->next) {
UiImport *import = iter->import;
if (!import)
continue;
if (!(import->fileName))
continue;
const QString path = import->fileName->asString();
// TODO: handle "import as".
const QMap<QString, DuiDocument::Ptr> types = _snapshot.componentsDefinedByImportedDocuments(_doc, path);
foreach (const DuiDocument::Ptr typeDoc, types) {
UiProgram *typeProgram = typeDoc->program();
if (typeProgram && typeProgram->members && typeProgram->members->member) {
result.append(createSymbol(typeDoc->fileName(), typeProgram->members->member));
}
}
}
return result;
}
......@@ -27,6 +27,9 @@ public:
DuiDocument::Ptr document() const
{ return _doc; }
QList<QmlSymbol*> visibleSymbols(QmlJS::AST::Node *scope);
QList<QmlSymbol*> visibleTypes();
private:
QmlSymbol *createSymbol(const QString &fileName, QmlJS::AST::UiObjectMember *node);
......
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