forked from qt-creator/qt-creator
QmlDesigner: Fix renaming a folder in Assets View expands the wrong folder
The previous implementation was saving the _row_ of the TreeView before performing the rename, and after the rename it was expanding that _row_. However, when renaming a folder causes it to be moved up or down between the rows, the saved _row_ number becomes invalid. The better way is just to use the same mechanism that is being used when creating a new folder: add the new folder path to a list, and later on expand rows based on that list. Task-number: QDS-8896 Change-Id: I6a6bb2faaa7d03ea2af384e5f2b635000577a94c Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -252,22 +252,15 @@ TreeViewDelegate {
|
|||||||
let modelIndex = assetsModel.indexForPath(model.filePath)
|
let modelIndex = assetsModel.indexForPath(model.filePath)
|
||||||
|
|
||||||
function onFolderCreated(path) {
|
function onFolderCreated(path) {
|
||||||
root.assetsView.addCreatedFolder(path)
|
if (path)
|
||||||
|
root.assetsView.addCreatedFolder(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root.__isDirectory) {
|
if (root.__isDirectory) {
|
||||||
var row = root.assetsView.rowAtIndex(modelIndex)
|
|
||||||
var expanded = root.assetsView.isExpanded(row)
|
|
||||||
|
|
||||||
var allExpandedState = root.assetsView.computeAllExpandedState()
|
var allExpandedState = root.assetsView.computeAllExpandedState()
|
||||||
|
|
||||||
function onFolderRenamed() {
|
|
||||||
if (expanded)
|
|
||||||
root.assetsView.rowToExpand = row
|
|
||||||
}
|
|
||||||
|
|
||||||
root.assetsView.contextMenu.openContextMenuForDir(modelIndex, model.filePath,
|
root.assetsView.contextMenu.openContextMenuForDir(modelIndex, model.filePath,
|
||||||
model.fileName, allExpandedState, onFolderCreated, onFolderRenamed)
|
model.fileName, allExpandedState, onFolderCreated)
|
||||||
} else {
|
} else {
|
||||||
let parentDirIndex = assetsModel.parentDirIndex(model.filePath)
|
let parentDirIndex = assetsModel.parentDirIndex(model.filePath)
|
||||||
let selectedPaths = root.assetsView.selectedPathsAsList()
|
let selectedPaths = root.assetsView.selectedPathsAsList()
|
||||||
|
@@ -16,7 +16,6 @@ StudioControls.Menu {
|
|||||||
property string __dirPath: ""
|
property string __dirPath: ""
|
||||||
property string __dirName: ""
|
property string __dirName: ""
|
||||||
property var __onFolderCreated: null
|
property var __onFolderCreated: null
|
||||||
property var __onFolderRenamed: null
|
|
||||||
property var __dirIndex: null
|
property var __dirIndex: null
|
||||||
property string __allExpandedState: ""
|
property string __allExpandedState: ""
|
||||||
property var __selectedAssetPathsList: null
|
property var __selectedAssetPathsList: null
|
||||||
@@ -37,12 +36,11 @@ StudioControls.Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openContextMenuForDir(dirModelIndex, dirPath, dirName, allExpandedState,
|
function openContextMenuForDir(dirModelIndex, dirPath, dirName, allExpandedState,
|
||||||
onFolderCreated, onFolderRenamed)
|
onFolderCreated)
|
||||||
{
|
{
|
||||||
rootView.updateHasMaterialLibrary()
|
rootView.updateHasMaterialLibrary()
|
||||||
|
|
||||||
root.__onFolderCreated = onFolderCreated
|
root.__onFolderCreated = onFolderCreated
|
||||||
root.__onFolderRenamed = onFolderRenamed
|
|
||||||
root.__dirPath = dirPath
|
root.__dirPath = dirPath
|
||||||
root.__dirName = dirName
|
root.__dirName = dirName
|
||||||
root.__fileIndex = ""
|
root.__fileIndex = ""
|
||||||
@@ -159,7 +157,7 @@ StudioControls.Menu {
|
|||||||
dirPath: root.__dirPath
|
dirPath: root.__dirPath
|
||||||
dirName: root.__dirName
|
dirName: root.__dirName
|
||||||
|
|
||||||
onAccepted: root.__onFolderRenamed()
|
onAccepted: root.__onFolderCreated(renameFolderDialog.renamedDirPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,7 +29,6 @@ TreeView {
|
|||||||
property int rootPathRow: 0
|
property int rootPathRow: 0
|
||||||
// i.e. first child of the root path
|
// i.e. first child of the root path
|
||||||
readonly property int firstRow: root.rootPathRow + 1
|
readonly property int firstRow: root.rootPathRow + 1
|
||||||
property int rowToExpand: -1
|
|
||||||
property var __createdDirectories: []
|
property var __createdDirectories: []
|
||||||
|
|
||||||
rowHeightProvider: (row) => {
|
rowHeightProvider: (row) => {
|
||||||
@@ -170,11 +169,6 @@ TreeView {
|
|||||||
if (root.requestedExpandAll)
|
if (root.requestedExpandAll)
|
||||||
root.__doExpandAll()
|
root.__doExpandAll()
|
||||||
} else {
|
} else {
|
||||||
if (root.rowToExpand > 0) {
|
|
||||||
root.expand(root.rowToExpand)
|
|
||||||
root.rowToExpand = -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// on collapsing, set expandAll flag to false.
|
// on collapsing, set expandAll flag to false.
|
||||||
root.requestedExpandAll = false;
|
root.requestedExpandAll = false;
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ Dialog {
|
|||||||
modal: true
|
modal: true
|
||||||
|
|
||||||
property bool renameError: false
|
property bool renameError: false
|
||||||
|
property string renamedDirPath: ""
|
||||||
required property string dirPath
|
required property string dirPath
|
||||||
required property string dirName
|
required property string dirName
|
||||||
|
|
||||||
@@ -84,8 +85,10 @@ Dialog {
|
|||||||
enabled: folderRename.text !== ""
|
enabled: folderRename.text !== ""
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var success = assetsModel.renameFolder(root.dirPath, folderRename.text)
|
var success = assetsModel.renameFolder(root.dirPath, folderRename.text)
|
||||||
if (success)
|
if (success) {
|
||||||
|
root.renamedDirPath = root.dirPath.replace(/(.*\/)[^/]+$/, "$1" + folderRename.text)
|
||||||
root.accept()
|
root.accept()
|
||||||
|
}
|
||||||
|
|
||||||
root.renameError = !success
|
root.renameError = !success
|
||||||
}
|
}
|
||||||
@@ -104,4 +107,8 @@ Dialog {
|
|||||||
folderRename.forceActiveFocus()
|
folderRename.forceActiveFocus()
|
||||||
root.renameError = false
|
root.renameError = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onRejected: {
|
||||||
|
root.renamedDirPath = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user