Expose 'Search Selection in PyQGIS docs' action for all python code editors

This commit is contained in:
Nyall Dawson 2023-04-04 08:37:35 +10:00
parent ca6df18671
commit 895a68faee
6 changed files with 22 additions and 10 deletions

View File

@ -112,7 +112,7 @@ class Editor(QgsCodeEditorPython):
QCoreApplication.translate("PythonConsole", "Run Selected"),
self.runSelectedCode, 'Ctrl+E') # spellok
pyQGISHelpAction = menu.addAction(QgsApplication.getThemeIcon("console/iconHelpConsole.svg"),
QCoreApplication.translate("PythonConsole", "Search Selected in PyQGIS docs"),
QCoreApplication.translate("PythonConsole", "Search Selection in PyQGIS Documentation"),
self.searchSelectedTextInPyQGISDocs)
menu.addAction(QgsApplication.getThemeIcon("mActionStart.svg"),
QCoreApplication.translate("PythonConsole", "Run Script"),

View File

@ -179,7 +179,7 @@ class ShellOutputScintilla(QgsCodeEditorPython):
QCoreApplication.translate("PythonConsole", "Clear Console"),
self.clearConsole)
pyQGISHelpAction = menu.addAction(QgsApplication.getThemeIcon("console/iconHelpConsole.svg"),
QCoreApplication.translate("PythonConsole", "Search Selected in PyQGIS docs"),
QCoreApplication.translate("PythonConsole", "Search Selection in PyQGIS Documentation"),
self.searchSelectedTextInPyQGISDocs)
menu.addSeparator()
copyAction = menu.addAction(

View File

@ -213,14 +213,6 @@ class ShellScintilla(QgsCodeEditorPython):
QgsCodeEditorPython.keyPressEvent(self, e)
self.updatePrompt()
def populateContextMenu(self, menu):
pyQGISHelpAction = menu.addAction(
QgsApplication.getThemeIcon("console/iconHelpConsole.svg"),
QCoreApplication.translate("PythonConsole", "Search Selected in PyQGIS docs"),
self.searchSelectedTextInPyQGISDocs
)
pyQGISHelpAction.setEnabled(self.hasSelectedText())
def mousePressEvent(self, e):
"""
Re-implemented to handle the mouse press event.

View File

@ -115,6 +115,8 @@ Toggle comment for the selected text.
virtual void keyPressEvent( QKeyEvent *event );
virtual QString reformatCodeString( const QString &string );
virtual void populateContextMenu( QMenu *menu );
protected slots:

View File

@ -32,6 +32,8 @@
#include <Qsci/qscilexerpython.h>
#include <QDesktopServices>
#include <QKeyEvent>
#include <QAction>
#include <QMenu>
const QMap<QString, QString> QgsCodeEditorPython::sCompletionPairs
{
@ -516,6 +518,21 @@ QString QgsCodeEditorPython::reformatCodeString( const QString &string )
return newText;
}
void QgsCodeEditorPython::populateContextMenu( QMenu *menu )
{
QgsCodeEditor::populateContextMenu( menu );
QAction *pyQgisHelpAction = new QAction(
QgsApplication::getThemeIcon( QStringLiteral( "console/iconHelpConsole.svg" ) ),
tr( "Search Selection in PyQGIS Documentation" ),
menu );
pyQgisHelpAction->setEnabled( hasSelectedText() );
connect( pyQgisHelpAction, &QAction::triggered, this, &QgsCodeEditorPython::searchSelectedTextInPyQGISDocs );
menu->addSeparator();
menu->addAction( pyQgisHelpAction );
}
void QgsCodeEditorPython::autoComplete()
{
switch ( autoCompletionSource() )

View File

@ -142,6 +142,7 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
void initializeLexer() override;
virtual void keyPressEvent( QKeyEvent *event ) override;
QString reformatCodeString( const QString &string ) override;
void populateContextMenu( QMenu *menu ) override;
protected slots: