Skip to content

Commit

Permalink
Expose 'Search Selection in PyQGIS docs' action for all python code e…
Browse files Browse the repository at this point in the history
…ditors
  • Loading branch information
nyalldawson committed Apr 5, 2023
1 parent ca6df18 commit 895a68f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion python/console/console_editor.py
Expand Up @@ -112,7 +112,7 @@ def contextMenuEvent(self, e):
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"),
Expand Down
2 changes: 1 addition & 1 deletion python/console/console_output.py
Expand Up @@ -179,7 +179,7 @@ def contextMenuEvent(self, e):
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(
Expand Down
8 changes: 0 additions & 8 deletions python/console/console_sci.py
Expand Up @@ -213,14 +213,6 @@ def keyPressEvent(self, e):
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.
Expand Down
Expand Up @@ -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:

Expand Down
17 changes: 17 additions & 0 deletions src/gui/codeeditors/qgscodeeditorpython.cpp
Expand Up @@ -32,6 +32,8 @@
#include <Qsci/qscilexerpython.h>
#include <QDesktopServices>
#include <QKeyEvent>
#include <QAction>
#include <QMenu>

const QMap<QString, QString> QgsCodeEditorPython::sCompletionPairs
{
Expand Down Expand Up @@ -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() )
Expand Down
1 change: 1 addition & 0 deletions src/gui/codeeditors/qgscodeeditorpython.h
Expand Up @@ -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:

Expand Down

0 comments on commit 895a68f

Please sign in to comment.