forked from qt-creator/qt-creator
QmlDesigner: Fix project tree widget renaming
When renaming an item in the project tree widget which has concatenated filename extensions like *.ui.qml the selection in the LineEdit will reach till the last dot. * Extend FilePath suffix and completeBaseName function so they will treat the suffix *.ui.qml as one * Make use of the function in ProjectTreeWidget::editCurrentItem * Replace QFileInfo::suffix with Utils::FilePath::suffix in FlatModel::setData Task-number: QDS-2713 Change-Id: I30d0e6d87a7512d42fd3d40b2282b94e79b43684 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
committed by
Henning Gründl
parent
3930679f27
commit
a09ec2e0e9
@@ -528,22 +528,28 @@ QString FilePath::baseName() const
|
||||
/// \returns the complete base name of the file without the path.
|
||||
///
|
||||
/// The complete base name consists of all characters in the file up to
|
||||
/// (but not including) the last '.' character
|
||||
/// (but not including) the last '.' character. In case of ".ui.qml"
|
||||
/// it will be treated as one suffix.
|
||||
|
||||
QString FilePath::completeBaseName() const
|
||||
{
|
||||
const QString &name = fileName();
|
||||
if (name.endsWith(".ui.qml"))
|
||||
return name.left(name.length() - QString(".ui.qml").length());
|
||||
return name.left(name.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
/// \returns the suffix (extension) of the file.
|
||||
///
|
||||
/// The suffix consists of all characters in the file after
|
||||
/// (but not including) the last '.'.
|
||||
/// (but not including) the last '.'. In case of ".ui.qml" it will
|
||||
/// be treated as one suffix.
|
||||
|
||||
QString FilePath::suffix() const
|
||||
{
|
||||
const QString &name = fileName();
|
||||
if (name.endsWith(".ui.qml"))
|
||||
return "ui.qml";
|
||||
const int index = name.lastIndexOf('.');
|
||||
if (index >= 0)
|
||||
return name.mid(index + 1);
|
||||
|
||||
@@ -305,7 +305,7 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
||||
|
||||
// The base name of the file was changed. Go look for other files with the same base name
|
||||
// and offer to rename them as well.
|
||||
if (orgFilePath != newFilePath && orgFileInfo.suffix() == newFilePath.suffix()) {
|
||||
if (orgFilePath != newFilePath && orgFilePath.suffix() == newFilePath.suffix()) {
|
||||
const QList<Node *> candidateNodes = ProjectTree::siblingsWithSameBaseName(node);
|
||||
if (!candidateNodes.isEmpty()) {
|
||||
const QMessageBox::StandardButton reply = QMessageBox::question(
|
||||
|
||||
@@ -473,8 +473,7 @@ void ProjectTreeWidget::editCurrentItem()
|
||||
if (!editor)
|
||||
return;
|
||||
|
||||
const QString text = editor->text();
|
||||
const int dotIndex = text.lastIndexOf('.');
|
||||
const int dotIndex = Utils::FilePath::fromString(editor->text()).completeBaseName().length();
|
||||
if (dotIndex > 0)
|
||||
editor->setSelection(0, dotIndex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user