Commit c14a4756 authored by Robert Loehning's avatar Robert Loehning Committed by Robert Löhning

Squish: Refactored openContextMenuOnTextCursorPosition()

Change-Id: Ie7a903794c11ed32cc1786c66ee0fa8d654a93f2
Reviewed-by: default avatarChristian Stenger <christian.stenger@nokia.com>
parent d8a3b3a1
......@@ -40,11 +40,35 @@ def placeCursorToLine(editor,line,isRegex=False):
editor.setTextCursor(cursor)
return True
# this function returns True if a QMenu is
# popped up above the given editor
# param editor is the editor where the menu should appear
# param menuInList is a list containing one item. This item will be assigned the menu if there is one.
# THIS IS A HACK to get a pass-by-reference
def menuVisibleAtEditor(editor, menuInList):
menuInList[0] = None
try:
menu = waitForObject("{type='QMenu' unnamed='1' visible='1'}", 200)
success = menu.visible and widgetContainsPoint(editor, menu.mapToGlobal(QPoint(0, 0)))
if success:
menuInList[0] = menu
return success
except:
return False
# this function checks whether the given global point (QPoint)
# is contained in the given widget
def widgetContainsPoint(widget, point):
return QRect(widget.mapToGlobal(QPoint(0, 0)), widget.size).contains(point)
# this function simply opens the context menu inside the given editor
# at the same position where the text cursor is located at
def openContextMenuOnTextCursorPosition(editor):
rect = editor.cursorRect(editor.textCursor())
openContextMenu(editor, rect.x+rect.width/2, rect.y+rect.height/2, 0)
menuInList = [None]
waitFor("menuVisibleAtEditor(editor, menuInList)", 5000)
return menuInList[0]
# this function marks/selects the text inside the given editor from position
# startPosition to endPosition (both inclusive)
......
......@@ -63,12 +63,8 @@ def testRenameId():
return False
type(editor, "<Down>")
searchFinished = False
if platform.system() == "Darwin":
invokeMenuItem("Tools", "QML/JS", "Rename Symbol Under Cursor")
else:
openContextMenuOnTextCursorPosition(editor)
ctxtMenu = waitForObject("{type='QMenu' visible='1' unnamed='1'}")
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Rename Symbol Under Cursor"))
ctxtMenu = openContextMenuOnTextCursorPosition(editor)
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Rename Symbol Under Cursor"))
waitFor("searchFinished")
type(waitForObject("{leftWidget={text='Replace with:' type='QLabel' unnamed='1' visible='1'} "
"type='Find::Internal::WideEnoughLineEdit' unnamed='1' visible='1' "
......@@ -100,12 +96,8 @@ def __invokeFindUsage__(treeView, filename, line, additionalKeyPresses, expected
for ty in additionalKeyPresses:
type(editor, ty)
searchFinished = False
if platform.system() == "Darwin":
invokeMenuItem("Tools", "QML/JS", "Find Usages")
else:
openContextMenuOnTextCursorPosition(editor)
ctxtMenu = waitForObject("{type='QMenu' visible='1' unnamed='1'}")
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Find Usages"))
ctxtMenu = openContextMenuOnTextCursorPosition(editor)
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Find Usages"))
waitFor("searchFinished")
validateSearchResult(expectedCount)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment