qml: fix refactoring to separate component

* avoid extra spaces
* warn about existing files

Fixes: QTCREATORBUG-21091
Change-Id: Ic9ed4444bd028455e1b2d1755e6c43f352dfd5e3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fawzi Mohamed
2020-08-01 02:20:32 +02:00
parent eddf2bead8
commit 103b35bcd5
2 changed files with 13 additions and 3 deletions

View File

@@ -168,5 +168,8 @@ QString ComponentNameDialog::isValid() const
if (!ui->pathEdit->isValid()) if (!ui->pathEdit->isValid())
return tr("Invalid path"); return tr("Invalid path");
if (QDir(ui->pathEdit->path()).exists(compName + u".qml"))
return tr("Component exists already");
return QString(); return QString();
} }

View File

@@ -60,11 +60,18 @@ public:
ProjectExplorer::actualTabSettings(fileName, textDocument); ProjectExplorer::actualTabSettings(fileName, textDocument);
CreatorCodeFormatter codeFormatter(tabSettings); CreatorCodeFormatter codeFormatter(tabSettings);
codeFormatter.updateStateUntil(block); codeFormatter.updateStateUntil(block);
do { do {
const int depth = codeFormatter.indentFor(block); int depth = codeFormatter.indentFor(block);
if (depth != -1) if (depth != -1) {
if (QStringView(block.text()).trimmed().isEmpty()) {
// we do not want to indent empty lines (as one is indentent when pressing tab
// assuming that the user will start writing something), and get rid of that
// space if one had pressed tab in an empty line just before refactoring.
// If depth == -1 (inside a multiline string for example) leave the spaces.
depth = 0;
}
tabSettings.indentLine(block, depth); tabSettings.indentLine(block, depth);
}
codeFormatter.updateLineStateChange(block); codeFormatter.updateLineStateChange(block);
block = block.next(); block = block.next();
} while (block.isValid() && block != end); } while (block.isValid() && block != end);