mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-03 00:04:47 -04:00
Add common actions for run script, run selection
Allows these shortcuts to be customised
This commit is contained in:
parent
1e3167082c
commit
1db5d1d246
@ -2,12 +2,16 @@
|
||||
# monkey patching scoped based enum
|
||||
QgsShortcutsManager.CommonAction.CodeToggleComment.__doc__ = "Toggle code comments"
|
||||
QgsShortcutsManager.CommonAction.CodeReformat.__doc__ = "Reformat code"
|
||||
QgsShortcutsManager.CommonAction.CodeRunScript.__doc__ = "Run script"
|
||||
QgsShortcutsManager.CommonAction.CodeRunSelection.__doc__ = "Run selection from script"
|
||||
QgsShortcutsManager.CommonAction.__doc__ = """Contains common actions which are used across a variety of classes.
|
||||
|
||||
.. versionadded:: 4.0
|
||||
|
||||
* ``CodeToggleComment``: Toggle code comments
|
||||
* ``CodeReformat``: Reformat code
|
||||
* ``CodeRunScript``: Run script
|
||||
* ``CodeRunSelection``: Run selection from script
|
||||
|
||||
"""
|
||||
# --
|
||||
|
@ -27,6 +27,8 @@ rather accessed through :py:func:`QgsGui.shortcutsManager()`.
|
||||
{
|
||||
CodeToggleComment,
|
||||
CodeReformat,
|
||||
CodeRunScript,
|
||||
CodeRunSelection,
|
||||
};
|
||||
|
||||
QgsShortcutsManager( QObject *parent /TransferThis/ = 0, const QString &settingsRoot = "/shortcuts/" );
|
||||
|
@ -297,27 +297,24 @@ class PythonConsoleWidget(QWidget):
|
||||
self.paste_action.setText(pasteEditorBt)
|
||||
|
||||
# Action Run Script (subprocess)
|
||||
runScriptEditorBt = QCoreApplication.translate("PythonConsole", "Run Script")
|
||||
self.run_script_action = QAction(self)
|
||||
self.run_script_action.setIcon(QgsApplication.getThemeIcon("mActionStart.svg"))
|
||||
self.run_script_action.setMenuRole(QAction.MenuRole.PreferencesRole)
|
||||
self.run_script_action.setIconVisibleInMenu(True)
|
||||
self.run_script_action.setToolTip(runScriptEditorBt + " <b>Ctrl+Shift+E</b>")
|
||||
self.run_script_action.setText(runScriptEditorBt)
|
||||
QgsGui.shortcutsManager().initializeCommonAction(
|
||||
self.run_script_action, QgsShortcutsManager.CommonAction.CodeRunScript
|
||||
)
|
||||
|
||||
# Action Run Selected
|
||||
runSelectedEditorBt = QCoreApplication.translate(
|
||||
"PythonConsole", "Run Selected"
|
||||
)
|
||||
self.run_selection_action = QAction(self)
|
||||
self.run_selection_action.setIcon(
|
||||
QgsApplication.getThemeIcon("mActionRunSelected.svg")
|
||||
)
|
||||
self.run_selection_action.setMenuRole(QAction.MenuRole.PreferencesRole)
|
||||
self.run_selection_action.setIconVisibleInMenu(True)
|
||||
self.run_selection_action.setToolTip(runSelectedEditorBt + " <b>Ctrl+E</b>")
|
||||
self.run_selection_action.setShortcut("Ctrl+E")
|
||||
self.run_selection_action.setText(runSelectedEditorBt)
|
||||
QgsGui.shortcutsManager().initializeCommonAction(
|
||||
self.run_selection_action, QgsShortcutsManager.CommonAction.CodeRunSelection
|
||||
)
|
||||
|
||||
# Action Toggle comment
|
||||
self.toggle_comment_action = QAction(self)
|
||||
|
@ -165,15 +165,6 @@ class Editor(QgsCodeEditorPython):
|
||||
syntaxCheckAction.setShortcut("Ctrl+4")
|
||||
menu.addAction(syntaxCheckAction)
|
||||
|
||||
runSelected = QAction(
|
||||
QgsApplication.getThemeIcon("mActionRunSelected.svg"), # spellok
|
||||
QCoreApplication.translate("PythonConsole", "Run Selected"),
|
||||
menu,
|
||||
)
|
||||
runSelected.triggered.connect(self.runSelectedCode) # spellok
|
||||
runSelected.setShortcut("Ctrl+E") # spellok
|
||||
menu.addAction(runSelected) # spellok
|
||||
|
||||
word = self.selectedText() or self.wordAtPoint(e.pos())
|
||||
if word:
|
||||
context_help_action = QAction(
|
||||
@ -191,13 +182,24 @@ class Editor(QgsCodeEditorPython):
|
||||
context_help_action.setShortcut(QKeySequence.StandardKey.HelpContents)
|
||||
menu.addAction(context_help_action)
|
||||
|
||||
start_action = QAction(
|
||||
QgsApplication.getThemeIcon("mActionStart.svg"),
|
||||
QCoreApplication.translate("PythonConsole", "Run Script"),
|
||||
menu,
|
||||
run_selection_action = QAction(menu)
|
||||
run_selection_action.setIcon(
|
||||
QgsApplication.getThemeIcon("mActionRunSelected.svg"),
|
||||
)
|
||||
run_selection_action.triggered.connect(self.runSelectedCode)
|
||||
QgsGui.shortcutsManager().initializeCommonAction(
|
||||
run_selection_action,
|
||||
QgsShortcutsManager.CommonAction.CodeRunSelection,
|
||||
)
|
||||
menu.addAction(run_selection_action)
|
||||
|
||||
start_action = QAction(self)
|
||||
start_action.setIcon(QgsApplication.getThemeIcon("mActionStart.svg"))
|
||||
start_action.triggered.connect(self.runScriptCode)
|
||||
start_action.setShortcut("Ctrl+Shift+E")
|
||||
QgsGui.shortcutsManager().initializeCommonAction(
|
||||
start_action,
|
||||
QgsShortcutsManager.CommonAction.CodeRunScript,
|
||||
)
|
||||
menu.addAction(start_action)
|
||||
|
||||
menu.addSeparator()
|
||||
@ -318,14 +320,14 @@ class Editor(QgsCodeEditorPython):
|
||||
syntaxCheckAction.setEnabled(False)
|
||||
pasteAction.setEnabled(False)
|
||||
cutAction.setEnabled(False)
|
||||
runSelected.setEnabled(False) # spellok
|
||||
run_selection_action.setEnabled(False)
|
||||
copyAction.setEnabled(False)
|
||||
selectAllAction.setEnabled(False)
|
||||
undoAction.setEnabled(False)
|
||||
redoAction.setEnabled(False)
|
||||
showCodeInspection.setEnabled(False)
|
||||
if self.hasSelectedText():
|
||||
runSelected.setEnabled(True) # spellok
|
||||
run_selection_action.setEnabled(True)
|
||||
copyAction.setEnabled(True)
|
||||
cutAction.setEnabled(True)
|
||||
if not self.text() == "":
|
||||
|
@ -2,12 +2,16 @@
|
||||
# monkey patching scoped based enum
|
||||
QgsShortcutsManager.CommonAction.CodeToggleComment.__doc__ = "Toggle code comments"
|
||||
QgsShortcutsManager.CommonAction.CodeReformat.__doc__ = "Reformat code"
|
||||
QgsShortcutsManager.CommonAction.CodeRunScript.__doc__ = "Run script"
|
||||
QgsShortcutsManager.CommonAction.CodeRunSelection.__doc__ = "Run selection from script"
|
||||
QgsShortcutsManager.CommonAction.__doc__ = """Contains common actions which are used across a variety of classes.
|
||||
|
||||
.. versionadded:: 4.0
|
||||
|
||||
* ``CodeToggleComment``: Toggle code comments
|
||||
* ``CodeReformat``: Reformat code
|
||||
* ``CodeRunScript``: Run script
|
||||
* ``CodeRunSelection``: Run selection from script
|
||||
|
||||
"""
|
||||
# --
|
||||
|
@ -27,6 +27,8 @@ rather accessed through :py:func:`QgsGui.shortcutsManager()`.
|
||||
{
|
||||
CodeToggleComment,
|
||||
CodeReformat,
|
||||
CodeRunScript,
|
||||
CodeRunSelection,
|
||||
};
|
||||
|
||||
QgsShortcutsManager( QObject *parent /TransferThis/ = 0, const QString &settingsRoot = "/shortcuts/" );
|
||||
|
@ -41,6 +41,8 @@ QgsShortcutsManager::QgsShortcutsManager( QObject *parent, const QString &settin
|
||||
};
|
||||
registerCommonAction( CommonAction::CodeToggleComment, QgsApplication::getThemeIcon( QStringLiteral( "console/iconCommentEditorConsole.svg" ), QgsApplication::palette().color( QPalette::ColorRole::WindowText ) ), tr( "Toggle Comment" ), tr( "Toggle comment" ), QStringLiteral( "Ctrl+/" ), QStringLiteral( "mEditorToggleComment" ), QStringLiteral( "Editor" ) );
|
||||
registerCommonAction( CommonAction::CodeReformat, QgsApplication::getThemeIcon( QStringLiteral( "console/iconFormatCode.svg" ) ), tr( "Reformat Code" ), tr( "Reformat code" ), QStringLiteral( "Ctrl+Alt+F" ), QStringLiteral( "mEditorReformatCode" ), QStringLiteral( "Editor" ) );
|
||||
registerCommonAction( CommonAction::CodeRunScript, QgsApplication::getThemeIcon( QStringLiteral( "mActionStart.svg" ) ), tr( "Run Script" ), tr( "Run entire script" ), QStringLiteral( "Ctrl+Shift+E" ), QStringLiteral( "mEditorRunScript" ), QStringLiteral( "Editor" ) );
|
||||
registerCommonAction( CommonAction::CodeRunSelection, QgsApplication::getThemeIcon( QStringLiteral( "mActionRunSelected.svg" ) ), tr( "Run Selection" ), tr( "Run selected part of script" ), QStringLiteral( "Ctrl+E" ), QStringLiteral( "mEditorRunSelection" ), QStringLiteral( "Editor" ) );
|
||||
}
|
||||
|
||||
QgsShortcutsManager::~QgsShortcutsManager()
|
||||
|
@ -46,6 +46,8 @@ class GUI_EXPORT QgsShortcutsManager : public QObject
|
||||
{
|
||||
CodeToggleComment, //!< Toggle code comments
|
||||
CodeReformat, //!< Reformat code
|
||||
CodeRunScript, //!< Run script
|
||||
CodeRunSelection, //!< Run selection from script
|
||||
};
|
||||
Q_ENUM( CommonAction )
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user