Commit 1882a770 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Add toImportString and change toString in Import

Change-Id: Ic6d4fc225b7f1ccc78593b28a0a96dc4fefec614
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 8b925007
......@@ -85,12 +85,12 @@ void DebugView::importsChanged(const QList<Import> &addedImports, const QList<Im
QString message;
message += tr("Added imports:") += lineBreak;
foreach (const Import &import, addedImports) {
message += import.toString() += lineBreak;
message += import.toImportString() += lineBreak;
}
message += tr("Removed imports:") += lineBreak;
foreach (const Import &import, removedImports) {
message += import.toString() += lineBreak;
message += import.toImportString() += lineBreak;
}
log(tr("Imports changed:"), message);
......
......@@ -151,7 +151,7 @@ void DesignDocumentView::toClipboard() const
data->setText(toText());
QStringList imports;
foreach (const Import &import, model()->imports())
imports.append(import.toString());
imports.append(import.toImportString());
data->setData("QmlDesigner::imports", stringListToArray(imports));
clipboard->setMimeData(data);
......@@ -208,7 +208,7 @@ void DesignDocumentView::fromText(QString text)
QPlainTextEdit textEdit;
QString imports;
foreach (const Import &import, model()->imports())
imports += import.toString(true, true) + QLatin1Char('\n');
imports += QLatin1String("import ") + import.toString(true) + QLatin1Char(';') + QLatin1Char('\n');
textEdit.setPlainText(imports + text);
NotIndentingTextEditModifier modifier(&textEdit);
......
......@@ -61,9 +61,9 @@ bool ChangeImportsVisitor::add(QmlJS::AST::UiProgram *ast, const Import &import)
if (!c.isSpace() && c != QLatin1Char(';'))
break;
}
replace(insertionPoint+1, 0, QLatin1String("\n") + import.toString(false));
replace(insertionPoint+1, 0, QLatin1String("\n") + import.toImportString());
} else {
replace(0, 0, import.toString(false) + QLatin1String("\n\n"));
replace(0, 0, import.toImportString() + QLatin1String("\n\n"));
}
setDidRewriting(true);
......
......@@ -56,7 +56,8 @@ public:
QString alias() const { return m_alias; }
QStringList importPaths() const { return m_importPathList; }
QString toString(bool addSemicolon = false, bool skipAlias = false) const;
QString toString(bool skipAlias = false) const;
QString toImportString() const;
bool operator==(const Import &other) const;
......
......@@ -48,6 +48,15 @@ Import Import::empty()
return Import(QString(), QString(), QString(), QString(), QStringList());
}
QString Import::toImportString() const
{
QString result = QLatin1String("import ");
result += toString(false);
return result;
}
Import::Import(const QString &url, const QString &file, const QString &version, const QString &alias, const QStringList &importPaths):
m_url(url),
m_file(file),
......@@ -57,9 +66,9 @@ Import::Import(const QString &url, const QString &file, const QString &version,
{
}
QString Import::toString(bool addSemicolon, bool skipAlias) const
QString Import::toString(bool skipAlias) const
{
QString result = QLatin1String("import ");
QString result;
if (isFileImport())
result += '"' + file() + '"';
......@@ -74,9 +83,6 @@ QString Import::toString(bool addSemicolon, bool skipAlias) const
if (hasAlias() && !skipAlias)
result += " as " + alias();
if (addSemicolon)
result += ';';
return result;
}
......
......@@ -358,7 +358,7 @@ bool AddImportRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring,
if (!result)
qDebug() << "*** AddImportRewriteAction::execute failed in changeImports ("
<< m_import.toString()
<< m_import.toImportString()
<< ") **"
<< info();
return result;
......@@ -376,7 +376,7 @@ bool RemoveImportRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring
if (!result)
qDebug() << "*** RemoveImportRewriteAction::execute failed in changeImports ("
<< m_import.toString()
<< m_import.toImportString()
<< ") **"
<< info();
return result;
......
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