2016-01-15 14:55:33 +01:00
|
|
|
# Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-05-15 13:17:33 +02:00
|
|
|
|
2013-04-25 16:04:36 +02:00
|
|
|
source("../../shared/qtcreator.py")
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
# prepare example project
|
2016-08-18 18:22:53 +02:00
|
|
|
projectName = "adding"
|
2023-02-22 13:49:54 +01:00
|
|
|
sourceExample = os.path.join(QtPath.examplesPath(Targets.DESKTOP_5_14_1_DEFAULT),
|
2016-08-18 18:22:53 +02:00
|
|
|
"qml", "referenceexamples", "adding")
|
2013-04-25 16:04:36 +02:00
|
|
|
proFile = projectName + ".pro"
|
|
|
|
|
if not neededFilePresent(os.path.join(sourceExample, proFile)):
|
|
|
|
|
return
|
|
|
|
|
# copy example project to temp directory
|
|
|
|
|
templateDir = prepareTemplate(sourceExample)
|
|
|
|
|
|
2018-08-22 14:37:34 +02:00
|
|
|
startQC()
|
2013-04-25 16:04:36 +02:00
|
|
|
if not startedWithoutPluginError():
|
|
|
|
|
return
|
|
|
|
|
usedProFile = os.path.join(templateDir, proFile)
|
|
|
|
|
openQmakeProject(usedProFile)
|
2016-08-18 18:22:53 +02:00
|
|
|
openDocument(projectName + "." + projectName + "\\.pro")
|
|
|
|
|
typeLines(waitForObject(":Qt Creator_TextEditor::TextEditorWidget"),
|
|
|
|
|
"OTHER_FILES += example.qml")
|
|
|
|
|
invokeMenuItem("File", "Save All")
|
|
|
|
|
invokeMenuItem("File", "Close All")
|
2019-08-16 08:36:52 +02:00
|
|
|
waitForProjectParsing()
|
2016-08-18 18:22:53 +02:00
|
|
|
for filetype, filename in [["Headers", "person.h"],
|
2013-04-25 16:04:36 +02:00
|
|
|
["Sources", "main.cpp"],
|
2016-08-18 18:22:53 +02:00
|
|
|
["Sources", "person.cpp"],
|
|
|
|
|
["Resources", "adding.qrc"],
|
|
|
|
|
["QML", "example.qml"]]:
|
2013-04-25 16:04:36 +02:00
|
|
|
filenames = ["ABCD" + filename.upper(), "abcd" + filename.lower(), "test", "TEST", filename]
|
2020-04-15 22:29:11 +02:00
|
|
|
if filename.endswith(".h"):
|
|
|
|
|
filenames.remove("TEST")
|
2019-10-31 16:20:36 +01:00
|
|
|
if filename.endswith(".qrc"):
|
|
|
|
|
filenames = ["ABCD" + filename.lower(), "abcd" + filename.lower(), filename]
|
2014-05-22 16:48:35 +02:00
|
|
|
previous = filenames[-1]
|
|
|
|
|
for filename in filenames:
|
2013-04-25 16:04:36 +02:00
|
|
|
tempFiletype = filetype
|
2020-02-11 19:30:03 +01:00
|
|
|
if filetype == "QML" and not previous.endswith(".qml"):
|
2013-04-25 16:04:36 +02:00
|
|
|
tempFiletype = "Other files"
|
|
|
|
|
renameFile(templateDir, usedProFile, projectName + "." + tempFiletype,
|
2014-05-22 16:48:35 +02:00
|
|
|
previous, filename)
|
2014-10-14 08:57:01 +02:00
|
|
|
# QTCREATORBUG-13176 does update the navigator async
|
2019-08-16 08:36:52 +02:00
|
|
|
waitForProjectParsing()
|
2016-08-18 18:22:53 +02:00
|
|
|
if filetype == "Headers":
|
2014-10-21 12:41:14 +02:00
|
|
|
verifyRenamedIncludes(templateDir, "main.cpp", previous, filename)
|
2016-08-18 18:22:53 +02:00
|
|
|
verifyRenamedIncludes(templateDir, "person.cpp", previous, filename)
|
2014-10-21 12:41:14 +02:00
|
|
|
previous = filename
|
2013-04-25 16:04:36 +02:00
|
|
|
invokeMenuItem("File", "Exit")
|
|
|
|
|
|
2014-10-21 12:41:14 +02:00
|
|
|
def grep(pattern, text):
|
|
|
|
|
return "\n".join(filter(lambda x: pattern in x, text.splitlines()))
|
|
|
|
|
|
|
|
|
|
def verifyRenamedIncludes(templateDir, file, oldname, newname):
|
|
|
|
|
fileText = readFile(os.path.join(templateDir, file))
|
|
|
|
|
if not (test.verify('#include "%s"' % oldname not in fileText,
|
|
|
|
|
'Verify that old filename is no longer included in %s' % file) and
|
|
|
|
|
test.verify('#include "%s"' % newname in fileText,
|
|
|
|
|
'Verify that new filename is included in %s' % file)):
|
|
|
|
|
test.log(grep("include", fileText))
|
|
|
|
|
|
2013-04-25 16:04:36 +02:00
|
|
|
def renameFile(projectDir, proFile, branch, oldname, newname):
|
|
|
|
|
oldFilePath = os.path.join(projectDir, oldname)
|
|
|
|
|
newFilePath = os.path.join(projectDir, newname)
|
|
|
|
|
oldFileText = readFile(oldFilePath)
|
2021-07-13 00:31:49 +02:00
|
|
|
oldItemText = branch + "." + oldname.replace(".", "\\.")
|
|
|
|
|
newItemText = branch + "." + newname.replace(".", "\\.")
|
2013-04-25 16:04:36 +02:00
|
|
|
treeview = waitForObject(":Qt Creator_Utils::NavigationTreeView")
|
|
|
|
|
try:
|
2021-07-13 00:31:49 +02:00
|
|
|
openItemContextMenu(treeview, oldItemText, 5, 5, 0)
|
2013-04-25 16:04:36 +02:00
|
|
|
except:
|
2021-07-13 00:31:49 +02:00
|
|
|
oldItemText = addBranchWildcardToRoot(oldItemText)
|
|
|
|
|
newItemText = addBranchWildcardToRoot(newItemText)
|
|
|
|
|
waitForObjectItem(treeview, oldItemText, 10000)
|
|
|
|
|
openItemContextMenu(treeview, oldItemText, 5, 5, 0)
|
2019-12-03 09:36:32 +01:00
|
|
|
if oldname.lower().endswith(".qrc"):
|
|
|
|
|
menu = ":Qt Creator.Project.Menu.Folder_QMenu"
|
2014-02-20 17:03:55 +01:00
|
|
|
else:
|
2019-12-03 09:36:32 +01:00
|
|
|
menu = ":Qt Creator.Project.Menu.File_QMenu"
|
|
|
|
|
activateItem(waitForObjectItem(menu, "Rename..."))
|
2018-03-13 23:03:33 +01:00
|
|
|
replaceEdit = waitForObject(":Qt Creator_Utils::NavigationTreeView::QExpandingLineEdit")
|
2018-06-13 16:39:08 +02:00
|
|
|
test.compare(replaceEdit.selectedText, oldname.rsplit(".", 1)[0],
|
|
|
|
|
"Only the filename without the extension is selected?")
|
2018-03-13 23:03:33 +01:00
|
|
|
replaceEditorContent(replaceEdit, newname)
|
|
|
|
|
type(replaceEdit, "<Return>")
|
2019-11-18 16:34:01 +01:00
|
|
|
if oldname == "adding.qrc":
|
|
|
|
|
clickButton(waitForObject("{text='No' type='QPushButton' unnamed='1' visible='1' "
|
|
|
|
|
"window={type='QMessageBox' unnamed='1' visible='1' "
|
|
|
|
|
" windowTitle='Rename More Files?'}}"))
|
2013-04-25 16:04:36 +02:00
|
|
|
test.verify(waitFor("os.path.exists(newFilePath)", 1000),
|
|
|
|
|
"Verify that file with new name exists: %s" % newFilePath)
|
2020-02-11 19:30:03 +01:00
|
|
|
test.verify(waitFor("' ' + newname in safeReadFile(proFile)", 2000),
|
2013-04-25 16:04:36 +02:00
|
|
|
"Verify that new filename '%s' was added to pro-file." % newname)
|
2021-07-08 14:22:03 +02:00
|
|
|
if oldname.endswith(".h"):
|
|
|
|
|
# Creator updates include guards in renamed header files and changes line breaks
|
|
|
|
|
oldFileText = oldFileText.replace("\r\n", "\n")
|
|
|
|
|
includeGuard = " " + newname.upper().replace(".", "_")
|
|
|
|
|
if not includeGuard.endswith("_H"):
|
|
|
|
|
includeGuard += "_H"
|
|
|
|
|
oldFileText = oldFileText.replace(" " + oldname.upper().replace(".", "_"), includeGuard)
|
|
|
|
|
waitFor("includeGuard in safeReadFile(newFilePath)", 2000)
|
|
|
|
|
test.compare(readFile(newFilePath), oldFileText,
|
|
|
|
|
"Comparing content of file before and after renaming")
|
2019-05-02 18:16:47 +02:00
|
|
|
if oldname not in newname:
|
|
|
|
|
test.verify(oldname not in readFile(proFile),
|
2013-04-25 16:04:36 +02:00
|
|
|
"Verify that old filename '%s' was removed from pro-file." % oldname)
|
2014-01-16 15:33:02 +01:00
|
|
|
if not (oldname.lower() == newname.lower() and platform.system() in ('Windows', 'Microsoft')):
|
2019-05-02 18:16:47 +02:00
|
|
|
test.verify(oldname not in os.listdir(projectDir),
|
2014-01-16 15:33:02 +01:00
|
|
|
"Verify that file with old name does not exist: %s" % oldFilePath)
|
2013-04-25 16:04:36 +02:00
|
|
|
|
2021-07-13 00:31:49 +02:00
|
|
|
if newItemText.endswith("\\.qml"):
|
|
|
|
|
newItemText = newItemText.replace(".Other files.", ".QML.")
|
|
|
|
|
else:
|
|
|
|
|
newItemText = newItemText.replace(".QML.", ".Other files.")
|
|
|
|
|
waitForObjectItem(treeview, newItemText)
|
|
|
|
|
|
|
|
|
|
|
2013-04-25 16:04:36 +02:00
|
|
|
def safeReadFile(filename):
|
|
|
|
|
text = ""
|
|
|
|
|
while text == "":
|
|
|
|
|
try:
|
|
|
|
|
text = readFile(filename)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
return text
|