Skip to content
Snippets Groups Projects
Commit c14a4756 authored by Robert Loehning's avatar Robert Loehning Committed by Robert Löhning
Browse files

Squish: Refactored openContextMenuOnTextCursorPosition()


Change-Id: Ie7a903794c11ed32cc1786c66ee0fa8d654a93f2
Reviewed-by: default avatarChristian Stenger <christian.stenger@nokia.com>
parent d8a3b3a1
No related branches found
No related tags found
No related merge requests found
...@@ -40,11 +40,35 @@ def placeCursorToLine(editor,line,isRegex=False): ...@@ -40,11 +40,35 @@ def placeCursorToLine(editor,line,isRegex=False):
editor.setTextCursor(cursor) editor.setTextCursor(cursor)
return True 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 # this function simply opens the context menu inside the given editor
# at the same position where the text cursor is located at # at the same position where the text cursor is located at
def openContextMenuOnTextCursorPosition(editor): def openContextMenuOnTextCursorPosition(editor):
rect = editor.cursorRect(editor.textCursor()) rect = editor.cursorRect(editor.textCursor())
openContextMenu(editor, rect.x+rect.width/2, rect.y+rect.height/2, 0) 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 # this function marks/selects the text inside the given editor from position
# startPosition to endPosition (both inclusive) # startPosition to endPosition (both inclusive)
......
...@@ -63,12 +63,8 @@ def testRenameId(): ...@@ -63,12 +63,8 @@ def testRenameId():
return False return False
type(editor, "<Down>") type(editor, "<Down>")
searchFinished = False searchFinished = False
if platform.system() == "Darwin": ctxtMenu = openContextMenuOnTextCursorPosition(editor)
invokeMenuItem("Tools", "QML/JS", "Rename Symbol Under Cursor") activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Rename Symbol Under Cursor"))
else:
openContextMenuOnTextCursorPosition(editor)
ctxtMenu = waitForObject("{type='QMenu' visible='1' unnamed='1'}")
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Rename Symbol Under Cursor"))
waitFor("searchFinished") waitFor("searchFinished")
type(waitForObject("{leftWidget={text='Replace with:' type='QLabel' unnamed='1' visible='1'} " type(waitForObject("{leftWidget={text='Replace with:' type='QLabel' unnamed='1' visible='1'} "
"type='Find::Internal::WideEnoughLineEdit' unnamed='1' visible='1' " "type='Find::Internal::WideEnoughLineEdit' unnamed='1' visible='1' "
...@@ -100,12 +96,8 @@ def __invokeFindUsage__(treeView, filename, line, additionalKeyPresses, expected ...@@ -100,12 +96,8 @@ def __invokeFindUsage__(treeView, filename, line, additionalKeyPresses, expected
for ty in additionalKeyPresses: for ty in additionalKeyPresses:
type(editor, ty) type(editor, ty)
searchFinished = False searchFinished = False
if platform.system() == "Darwin": ctxtMenu = openContextMenuOnTextCursorPosition(editor)
invokeMenuItem("Tools", "QML/JS", "Find Usages") activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Find Usages"))
else:
openContextMenuOnTextCursorPosition(editor)
ctxtMenu = waitForObject("{type='QMenu' visible='1' unnamed='1'}")
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Find Usages"))
waitFor("searchFinished") waitFor("searchFinished")
validateSearchResult(expectedCount) validateSearchResult(expectedCount)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment