Skip to content

Added a new preference category for the editor. #8861 #8959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/en_US/images/preferences_editor_options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/preferences_graph_visualiser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/preferences_sql_auto_completion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/preferences_sql_csv_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/preferences_sql_display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/en_US/images/preferences_sql_editor.png
Binary file not shown.
Binary file modified docs/en_US/images/preferences_sql_explain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/en_US/images/preferences_sql_formatting.png
Binary file not shown.
Binary file modified docs/en_US/images/preferences_sql_keyboard_shortcuts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/preferences_sql_options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/preferences_sql_results_grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 84 additions & 68 deletions docs/en_US/preferences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,90 @@ Use the fields on the *Options* panel to manage ERD preferences.
It allows to set the limit on the depth level pgAdmin should traverse
to find the relations. Use -1 to set no limit.


The Editor Node
*****************

Expand the *Editor* node to access panels that allow you to specify your preferences
for the editor across pgAdmin 4

.. image:: images/preferences_editor_keyboard_shortcuts.png
:alt: Preferences editor keyboard shortcuts section
:align: center

Use the fields on the *Keyboard shortcuts* panel to configure shortcuts for the
editor.

.. image:: images/preferences_editor_options.png
:alt: Preferences editor options section
:align: center

Use the fields on the *Options* panel to manage editor preferences.

* Use the *Auto-indent new line?* switch to specify whether the editor will
automatically indent new lines. When set to *True*, the editor will indent
new lines according to the indentation of the previous line.

* When the *Brace matching?* switch is set to *True*, the editor will highlight
pairs of matched braces.

* When the *Code folding?* switch is set to *False*, the editor will disable
code folding. Disabling will improve editor performance with large files.

* Use the *Font family* field to be used for all SQL editors. The specified
font should already be installed on your system. If the font is not found,
the editor will fall back to the default font, Source Code Pro.

* When the *Font ligatures?* switch is set to *True*, ligatures will be
enabled in SQL text boxes and editors provided the configured font family
supports them.

* Use the *Font size* field to specify the font size that will be used in text
boxes and editors.

* When the *Highlight selection matches?* switch is set to *True*, the editor will
highlight matched selected text.

* When the *Insert bracket pairs?* switch is set to *True*, the editor will
automatically insert paired brackets.

* When the *Line wrapping* switch is set to *True*, the editor will implement
line-wrapping behavior.

* When the *Plain text mode?* switch is set to *True*, the editor mode will be
changed to text/plain. Keyword highlighting and code folding will be disabled.
This will improve editor performance with large files.

.. image:: images/preferences_editor_sql_formatting.png
:alt: Preferences SQL Formatting section
:align: center

Use the fields on the *SQL formatting* panel to specify your preferences for
reformatting of SQL.

* Use the *Data type case* option to specify whether to change data types
into upper, lower, or preserve case.
* Use the *Expression width* option to specify maximum number of characters
in parenthesized expressions to be kept on single line.
* Use the *Function case* option to specify whether to change function
names into upper, lower, or preserve case.
* Use the *Identifier case* option to specify whether to change identifiers
(object names) into upper, lower, or capitalized case.
* Use the *Keyword case* option to specify whether to change keywords into
upper, lower, or preserve case.
* Use *Lines between queries* to specify how many empty lines to leave
between SQL statements. If set to zero it puts no new line.
* Use *Logical operator new line* to specify newline placement before or
after logical operators (AND, OR, XOR).
* Use *New line before semicolon?* to specify whether to place query
separator (;) on a separate line.
* Use the *Spaces around operators?* option to specify whether or not to include
spaces on either side of operators.
* Use the *Tab size* option to specify the number of spaces per tab or indent.
* Use the *Use spaces?* option to select whether to use spaces or tabs when
indenting.


The Graphs Node
***************

Expand Down Expand Up @@ -427,46 +511,6 @@ Tool display.
* When the *Show query success notification?* switch is set to *True*, the Query Tool
will show notifications on successful query execution.

.. image:: images/preferences_sql_editor.png
:alt: Preferences sqleditor editor settings
:align: center

Use the fields on the *Editor* panel to change settings of the query editor.

* Use the *Auto-indent new line?* switch to specify whether the editor will
automatically indent new lines. When set to *True*, the editor will indent
new lines according to the indentation of the previous line.

* When the *Brace matching?* switch is set to *True*, the editor will highlight
pairs of matched braces.

* When the *Code folding?* switch is set to *False*, the editor will disable
code folding. Disabling will improve editor performance with large files.

* Use the *Font family* field to be used for all SQL editors. The specified
font should already be installed on your system. If the font is not found,
the editor will fall back to the default font, Source Code Pro.

* When the *Font ligatures?* switch is set to *True*, ligatures will be
enabled in SQL text boxes and editors provided the configured font family
supports them.

* Use the *Font size* field to specify the font size that will be used in text
boxes and editors.

* When the *Highlight selection matches?* switch is set to *True*, the editor will
highlight matched selected text.

* When the *Insert bracket pairs?* switch is set to *True*, the editor will
automatically insert paired brackets.

* When the *Line wrapping* switch is set to *True*, the editor will implement
line-wrapping behavior.

* When the *Plain text mode?* switch is set to *True*, the editor mode will be
changed to text/plain. Keyword highlighting and code folding will be disabled.
This will improve editor performance with large files.

.. image:: images/preferences_sql_explain.png
:alt: Preferences sqleditor explain options
:align: center
Expand Down Expand Up @@ -592,34 +636,6 @@ preferences for copied data.
Use the fields on the *Keyboard shortcuts* panel to configure shortcuts for the
Query Tool window navigation.

.. image:: images/preferences_sql_formatting.png
:alt: Preferences SQL Formatting section
:align: center

Use the fields on the *SQL formatting* panel to specify your preferences for
reformatting of SQL.

* Use the *Data type case* option to specify whether to change data types
into upper, lower, or preserve case.
* Use the *Expression width* option to specify maximum number of characters
in parenthesized expressions to be kept on single line.
* Use the *Function case* option to specify whether to change function
names into upper, lower, or preserve case.
* Use the *Identifier case* option to specify whether to change identifiers
(object names) into upper, lower, or capitalized case.
* Use the *Keyword case* option to specify whether to change keywords into
upper, lower, or preserve case.
* Use *Lines between queries* to specify how many empty lines to leave
between SQL statements. If set to zero it puts no new line.
* Use *Logical operator new line* to specify newline placement before or
after logical operators (AND, OR, XOR).
* Use *New line before semicolon?* to specify whether to place query
separator (;) on a separate line.
* Use the *Spaces around operators?* option to specify whether or not to include
spaces on either side of operators.
* Use the *Tab size* option to specify the number of spaces per tab or indent.
* Use the *Use spaces?* option to select whether to use spaces or tabs when
indenting.

The Schema Diff Node
********************
Expand Down
102 changes: 102 additions & 0 deletions web/migrations/versions/e6ed5dac37c2_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

"""empty message

Revision ID: e6ed5dac37c2
Revises: e24b1c4def17
Create Date: 2025-07-15 12:27:48.780562

"""
from alembic import op
from sqlalchemy.orm.session import Session
from pgadmin.model import Preferences, ModulePreference, PreferenceCategory,\
UserPreference
from pgadmin.browser import register_editor_preferences


# revision identifiers, used by Alembic.
revision = 'e6ed5dac37c2'
down_revision = 'e24b1c4def17'
branch_labels = None
depends_on = None


class Migration:
"""
This is a placeholder class for registering editor preferences
"""
def __init__(self, value=None):
self.editor_preference = value


def upgrade():
"""
Migrate the user saved preferences from the 'sqleditor' module to the
'editor' module.
"""
migration_obj = Migration()
register_editor_preferences(migration_obj, migration_gettext=lambda x: x)

session = Session(bind=op.get_bind())
pref_categories = ['keyboard_shortcuts', 'editor', 'Editor']
new_categories = ['keyboard_shortcuts', 'sql_formatting', 'options']
prefs = ['find', 'replace', 'goto_line_col',
'comment', 'format_sql', 'plain_editor_mode',
'code_folding', 'wrap_code', 'insert_pair_brackets',
'highlight_selection_matches', 'brace_matching', 'sql_font_size',
'sql_font_ligatures', 'sql_font_family', 'indent_new_line',
'keyword_case', 'identifier_case', 'function_case',
'data_type_case', 'spaces_around_operators', 'tab_size',
'use_spaces', 'expression_width', 'logical_operator_new_line',
'lines_between_queries', 'new_line_before_semicolon']
category_ids = []
new_ids = []
pref_map = {}

category_data = session.query(ModulePreference, PreferenceCategory,).join(
PreferenceCategory).filter(
ModulePreference.name == 'sqleditor',
PreferenceCategory.name.in_(pref_categories)).all()

for module_data, pref_cat in category_data:
category_ids.append(pref_cat.id)

new_data = session.query(ModulePreference, PreferenceCategory).join(
PreferenceCategory).filter(
ModulePreference.name == 'editor', PreferenceCategory.name.in_(
new_categories)).all()

for module_data, pref_cat in new_data:
new_ids.append(pref_cat.id)

prefs_data = session.query(Preferences).filter(Preferences.cid.in_(
category_ids), Preferences.name.in_(prefs)).all()

new_prefs_data = session.query(Preferences).filter(Preferences.cid.in_(
new_ids), Preferences.name.in_(prefs)).all()

for pref in prefs_data:
for new_pref in new_prefs_data:
if pref.name == new_pref.name:
pref_map[pref.id] = new_pref.id

for key, val in pref_map.items():
record_to_update = session.query(UserPreference).filter_by(
pid=key).first()
if record_to_update:
record_to_update.pid = val

# Delete the old preferences and categories
session.query(Preferences).filter(Preferences.name.in_(prefs),
Preferences.cid.in_(category_ids)
).delete(synchronize_session=False)

session.query(PreferenceCategory).filter(
PreferenceCategory.name.in_(['editor', 'Editor'])).delete(
synchronize_session=False)

session.commit()


def downgrade():
# pgAdmin only upgrades, downgrade not implemented.
pass
3 changes: 3 additions & 0 deletions web/pgadmin/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
from pgadmin.utils.preferences import Preferences
from pgadmin.browser.register_browser_preferences import \
register_browser_preferences
from pgadmin.browser.register_editor_preferences import \
register_editor_preferences
from pgadmin.utils.master_password import validate_master_password, \
set_masterpass_check_text, cleanup_master_password, get_crypt_key, \
set_crypt_key, process_masterpass_disabled, \
Expand Down Expand Up @@ -87,6 +89,7 @@ class BrowserModule(PgAdminModule):

def register_preferences(self):
register_browser_preferences(self)
register_editor_preferences(self)

def get_exposed_url_endpoints(self):
"""
Expand Down
Loading
Loading