| 1557 | } |
| 1558 | |
| 1559 | PythonContext *PythonShell::newImportedDummyContext() |
| 1560 | { |
| 1561 | sptr_t pos = scriptEditor->currentPos(); |
| 1562 | |
| 1563 | PythonContext *context = new PythonContext(); |
| 1564 | |
| 1565 | setGlobals(context); |
| 1566 | |
| 1567 | // super hack. Try to import any modules to get completion suggestions from them. |
| 1568 | // we only process imports with no indentation since they should be unconditional. We ignore |
| 1569 | // imports that fail. |
| 1570 | QByteArray text = scriptEditor->getText(pos + 1); |
| 1571 | |
| 1572 | for(int offs = 0; offs < text.length();) |
| 1573 | { |
| 1574 | // find the next newline (may be NULL if we're at the end) |
| 1575 | int newline = text.indexOf('\n', offs); |
| 1576 | |
| 1577 | // execute the import if there is one |
| 1578 | const char *c = text.data() + offs; |
| 1579 | if(!strncmp(c, "import ", 7)) |
| 1580 | { |
| 1581 | context->executeString(newline >= 0 ? QString::fromUtf8(c, newline - offs + 1) |
| 1582 | : QString::fromUtf8(c)); |
| 1583 | } |
| 1584 | |
| 1585 | if(newline < 0) |
| 1586 | break; |
| 1587 | |
| 1588 | // move to the next line |
| 1589 | offs = newline + 1; |
| 1590 | } |
| 1591 | |
| 1592 | return context; |
| 1593 | } |
| 1594 | |
| 1595 | PythonContext *PythonShell::newContext() |
| 1596 | { |
nothing calls this directly
no test coverage detected