| 
									
										
										
										
											2013-05-15 13:17:33 +02:00
										 |  |  | ############################################################################# | 
					
						
							|  |  |  | ## | 
					
						
							| 
									
										
										
										
											2014-01-07 13:27:11 +01:00
										 |  |  | ## Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2013-05-15 13:17:33 +02:00
										 |  |  | ## Contact: http://www.qt-project.org/legal | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## This file is part of Qt Creator. | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ## Commercial License Usage | 
					
						
							|  |  |  | ## Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ## accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ## Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ## a written agreement between you and Digia.  For licensing terms and | 
					
						
							| 
									
										
										
										
											2014-10-01 13:21:18 +02:00
										 |  |  | ## conditions see http://www.qt.io/licensing.  For further information | 
					
						
							|  |  |  | ## use the contact form at http://www.qt.io/contact-us. | 
					
						
							| 
									
										
										
										
											2013-05-15 13:17:33 +02:00
										 |  |  | ## | 
					
						
							|  |  |  | ## GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ## Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							| 
									
										
										
										
											2014-10-01 13:21:18 +02:00
										 |  |  | ## General Public License version 2.1 or version 3 as published by the Free | 
					
						
							|  |  |  | ## Software Foundation and appearing in the file LICENSE.LGPLv21 and | 
					
						
							|  |  |  | ## LICENSE.LGPLv3 included in the packaging of this file.  Please review the | 
					
						
							|  |  |  | ## following information to ensure the GNU Lesser General Public License | 
					
						
							|  |  |  | ## requirements will be met: https://www.gnu.org/licenses/lgpl.html and | 
					
						
							|  |  |  | # http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
					
						
							| 
									
										
										
										
											2013-05-15 13:17:33 +02:00
										 |  |  | ## | 
					
						
							|  |  |  | ## In addition, as a special exception, Digia gives you certain additional | 
					
						
							|  |  |  | ## rights.  These rights are described in the Digia Qt LGPL Exception | 
					
						
							|  |  |  | ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ## | 
					
						
							|  |  |  | ############################################################################# | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:04:36 +02:00
										 |  |  | source("../../shared/qtcreator.py") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							|  |  |  |     # prepare example project | 
					
						
							|  |  |  |     projectName = "declarative-music-browser" | 
					
						
							|  |  |  |     sourceExample = os.path.join(sdkPath, "Examples", "QtMobility", projectName) | 
					
						
							|  |  |  |     proFile = projectName + ".pro" | 
					
						
							|  |  |  |     if not neededFilePresent(os.path.join(sourceExample, proFile)): | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     # copy example project to temp directory | 
					
						
							|  |  |  |     templateDir = prepareTemplate(sourceExample) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     startApplication("qtcreator" + SettingsPath) | 
					
						
							|  |  |  |     if not startedWithoutPluginError(): | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     usedProFile = os.path.join(templateDir, proFile) | 
					
						
							|  |  |  |     openQmakeProject(usedProFile) | 
					
						
							| 
									
										
										
										
											2014-10-27 15:40:24 +01:00
										 |  |  |     progressBarWait() | 
					
						
							| 
									
										
										
										
											2013-04-25 16:04:36 +02:00
										 |  |  |     for filetype, filename in [["Headers", "utility.h"], | 
					
						
							|  |  |  |                                ["Sources", "main.cpp"], | 
					
						
							|  |  |  |                                ["Sources", "utility.cpp"], | 
					
						
							|  |  |  |                                ["Resources", "musicbrowser.qrc"], | 
					
						
							|  |  |  |                                ["QML", "musicbrowser.qml"]]: | 
					
						
							|  |  |  |         filenames = ["ABCD" + filename.upper(), "abcd" + filename.lower(), "test", "TEST", 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 | 
					
						
							| 
									
										
										
										
											2014-05-22 16:48:35 +02:00
										 |  |  |             if filetype == "QML" and previous[-4:] != ".qml": | 
					
						
							| 
									
										
										
										
											2013-04-25 16:04:36 +02:00
										 |  |  |                 tempFiletype = "Other files" | 
					
						
							| 
									
										
										
										
											2013-12-06 13:02:06 +01:00
										 |  |  |             # following is necessary due to QTCREATORBUG-10179 | 
					
						
							|  |  |  |             # will be fixed when Qt5's MIME type database can be used | 
					
						
							| 
									
										
										
										
											2014-05-22 16:48:35 +02:00
										 |  |  |             if ((filenames[-1] in ("main.cpp", "utility.cpp") and previous[-4:] != ".cpp") | 
					
						
							|  |  |  |                 or (filenames[-1] == "utility.h" and previous[-2:].lower() != ".h") | 
					
						
							|  |  |  |                 or (filetype == "Resources" and previous[-4:] != ".qrc")): | 
					
						
							| 
									
										
										
										
											2013-12-06 13:02:06 +01:00
										 |  |  |                 tempFiletype = "Other files" | 
					
						
							|  |  |  |             # end of handling QTCREATORBUG-10179 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:04:36 +02:00
										 |  |  |             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 | 
					
						
							|  |  |  |             progressBarWait() | 
					
						
							| 
									
										
										
										
											2014-10-21 12:41:14 +02:00
										 |  |  |             if tempFiletype == "Headers":   # QTCREATORBUG-13204 | 
					
						
							|  |  |  |                 verifyRenamedIncludes(templateDir, "main.cpp", previous, filename) | 
					
						
							|  |  |  |                 verifyRenamedIncludes(templateDir, "utility.cpp", previous, filename) | 
					
						
							|  |  |  |             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) | 
					
						
							|  |  |  |     itemText = branch + "." + oldname.replace(".", "\\.") | 
					
						
							|  |  |  |     treeview = waitForObject(":Qt Creator_Utils::NavigationTreeView") | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         openItemContextMenu(treeview, itemText, 5, 5, 0) | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         openItemContextMenu(treeview, addBranchWildcardToRoot(itemText), 5, 5, 0) | 
					
						
							| 
									
										
										
										
											2014-03-10 15:37:26 +01:00
										 |  |  |     # hack for Squish5/Qt5.2 problems of handling menus on Mac - remove asap | 
					
						
							|  |  |  |     if platform.system() == 'Darwin': | 
					
						
							| 
									
										
										
										
											2014-03-11 12:22:07 +01:00
										 |  |  |         waitFor("macHackActivateContextMenuItem('Rename...')", 5000) | 
					
						
							| 
									
										
										
										
											2014-02-20 17:03:55 +01:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2014-03-10 15:37:26 +01:00
										 |  |  |         if oldname.endswith(".qrc"): | 
					
						
							| 
									
										
										
										
											2014-03-11 12:22:07 +01:00
										 |  |  |             menu = ":Qt Creator.Project.Menu.Folder_QMenu" | 
					
						
							| 
									
										
										
										
											2014-03-10 15:37:26 +01:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2014-03-11 12:22:07 +01:00
										 |  |  |             menu = ":Qt Creator.Project.Menu.File_QMenu" | 
					
						
							|  |  |  |         activateItem(waitForObjectItem(menu, "Rename...")) | 
					
						
							| 
									
										
										
										
											2013-04-25 16:04:36 +02:00
										 |  |  |     type(waitForObject(":Qt Creator_Utils::NavigationTreeView::QExpandingLineEdit"), newname) | 
					
						
							|  |  |  |     type(waitForObject(":Qt Creator_Utils::NavigationTreeView::QExpandingLineEdit"), "<Return>") | 
					
						
							|  |  |  |     test.verify(waitFor("os.path.exists(newFilePath)", 1000), | 
					
						
							|  |  |  |                 "Verify that file with new name exists: %s" % newFilePath) | 
					
						
							|  |  |  |     test.compare(readFile(newFilePath), oldFileText, | 
					
						
							|  |  |  |                  "Comparing content of file before and after renaming") | 
					
						
							|  |  |  |     test.verify(waitFor("newname in safeReadFile(proFile)", 2000), | 
					
						
							|  |  |  |                 "Verify that new filename '%s' was added to pro-file." % newname) | 
					
						
							|  |  |  |     if not oldname in newname: | 
					
						
							|  |  |  |         test.verify(not oldname in readFile(proFile), | 
					
						
							|  |  |  |                     "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')): | 
					
						
							|  |  |  |         test.verify(not oldname in os.listdir(projectDir), | 
					
						
							|  |  |  |                     "Verify that file with old name does not exist: %s" % oldFilePath) | 
					
						
							| 
									
										
										
										
											2013-04-25 16:04:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def safeReadFile(filename): | 
					
						
							|  |  |  |     text = "" | 
					
						
							|  |  |  |     while text == "": | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             text = readFile(filename) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |     return text |