Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
register_browser_preferences.py512 linesDownload Raw Back to browser
1##########################################################################2#3# pgAdmin 4 - PostgreSQL Tools4#5# Copyright (C) 2013 - 2024, The pgAdmin Development Team6# This software is released under the PostgreSQL Licence7#8##########################################################################9import sys10from flask_babel import gettext11from pgadmin.utils.constants import PREF_LABEL_DISPLAY,\12    PREF_LABEL_KEYBOARD_SHORTCUTS, PREF_LABEL_TABS_SETTINGS, \13    PREF_LABEL_OPTIONS, QT_DEFAULT_PLACEHOLDER, VW_EDT_DEFAULT_PLACEHOLDER, \14    PREF_LABEL_BREADCRUMBS15from flask import current_app16import config17 18 19def register_browser_preferences(self):20    self.show_system_objects = self.preference.register(21        'display', 'show_system_objects',22        gettext("Show system objects?"), 'boolean', False,23        category_label=PREF_LABEL_DISPLAY24    )25 26    self.show_empty_coll_nodes = self.preference.register(27        'display', 'show_empty_coll_nodes',28        gettext("Show empty object collections?"), 'boolean', True,29        category_label=PREF_LABEL_DISPLAY,30        help_str=gettext(31            'If turned off, then all object collections which are empty '32            'will be hidden from browser tree.'33        )34    )35 36    self.show_user_defined_templates = self.preference.register(37        'display', 'show_user_defined_templates',38        gettext("Show template databases?"), 'boolean', False,39        category_label=PREF_LABEL_DISPLAY40    )41 42    if config.SERVER_MODE:43        self.hide_shared_server = self.preference.register(44            'display', 'hide_shared_server',45            gettext("Hide shared servers?"), 'boolean', False,46            category_label=gettext('Display'),47            help_str=gettext(48                'If set to True, then all shared servers will be '49                'hidden from browser tree'50            )51        )52 53    self.preference.register(54        'display', 'browser_tree_state_save_interval',55        gettext("Object explorer tree state saving interval"), 'integer',56        30, category_label=PREF_LABEL_DISPLAY,57        help_str=gettext(58            'Object explorer state saving interval in seconds. '59            'Use -1 to disable the tree saving mechanism.'60        )61    )62 63    self.preference.register(64        'display', 'confirm_on_refresh_close',65        gettext("Confirm on close or refresh?"), 'boolean',66        True, category_label=PREF_LABEL_DISPLAY,67        help_str=gettext(68            'Confirm closure or refresh of the browser or browser tab is '69            'intended before proceeding.'70        )71    )72 73    self.preference.register(74        'display', 'confirm_on_properties_close',75        gettext("Confirm before Close/Reset in object properties dialog?"),76        'boolean',77        True, category_label=PREF_LABEL_DISPLAY,78        help_str=gettext(79            'Confirm before closing or resetting the changes in the '80            'properties dialog for an object if the changes are not saved.'81        )82    )83 84    self.preference.register(85        'display', 'auto_expand_sole_children',86        gettext("Auto-expand sole children"), 'boolean', True,87        category_label=PREF_LABEL_DISPLAY,88        help_str=gettext(89            'If a treeview node is expanded and has only a single '90            'child, automatically expand the child node as well.'91        )92    )93 94    self.table_row_count_threshold = self.preference.register(95        'properties', 'table_row_count_threshold',96        gettext("Count rows if estimated less than"), 'integer', 2000,97        category_label=gettext('Properties')98    )99 100    self.pg_agent_row_threshold = self.preference.register(101        'properties', 'pgagent_row_threshold',102        gettext("Maximum job history rows"), 'integer', 250,103        category_label=gettext('Properties'),104        min_val=1, max_val=9999,105        help_str=gettext(106            'The maximum number of history rows to show on '107            'the Statistics tab for pgAgent jobs'108        )109    )110 111    self.table_row_count_threshold = self.preference.register(112        'processes', 'process_retain_days',113        gettext("Process details/logs retention days"), 'integer', 5,114        min_val=1,115        category_label=gettext('Processes'),116        help_str=gettext(117            'After this many days, the process info and logs '118            'will be automatically cleared.'119        )120    )121 122    fields = [123        {'name': 'key', 'type': 'keyCode', 'label': gettext('Key')},124        {'name': 'shift', 'type': 'checkbox', 'label': gettext('Shift')},125        {'name': 'control', 'type': 'checkbox', 'label': gettext('Ctrl')},126        {'name': 'alt', 'type': 'checkbox', 'label': gettext('Alt/Option')}127    ]128 129    self.preference.register(130        'keyboard_shortcuts',131        'browser_tree',132        gettext('Object Explorer'),133        'keyboardshortcut',134        {135            'alt': True,136            'shift': True,137            'control': False,138            'key': {'key_code': 66, 'char': 'b'}139        },140        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,141        fields=fields142    )143 144    self.preference.register(145        'keyboard_shortcuts',146        'tabbed_panel_backward',147        gettext('Tabbed panel backward'),148        'keyboardshortcut',149        {150            'alt': True,151            'shift': True,152            'control': False,153            'key': {'key_code': 91, 'char': '['}154        },155        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,156        fields=fields157    )158 159    self.preference.register(160        'keyboard_shortcuts',161        'tabbed_panel_forward',162        gettext('Tabbed panel forward'),163        'keyboardshortcut',164        {165            'alt': True,166            'shift': True,167            'control': False,168            'key': {'key_code': 93, 'char': ']'}169        },170        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,171        fields=fields172    )173 174    if not current_app.PGADMIN_RUNTIME:175        self.preference.register(176            'keyboard_shortcuts',177            'main_menu_file',178            gettext('File main menu'),179            'keyboardshortcut',180            {181                'alt': True,182                'shift': True,183                'control': False,184                'key': {'key_code': 70, 'char': 'f'}185            },186            category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,187            fields=fields188        )189 190        self.preference.register(191            'keyboard_shortcuts',192            'main_menu_object',193            gettext('Object main menu'),194            'keyboardshortcut',195            {196                'alt': True,197                'shift': True,198                'control': False,199                'key': {'key_code': 79, 'char': 'o'}200            },201            category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,202            fields=fields203        )204 205        self.preference.register(206            'keyboard_shortcuts',207            'main_menu_tools',208            gettext('Tools main menu'),209            'keyboardshortcut',210            {211                'alt': True,212                'shift': True,213                'control': False,214                'key': {'key_code': 76, 'char': 'l'}215            },216            category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,217            fields=fields218        )219 220        self.preference.register(221            'keyboard_shortcuts',222            'main_menu_help',223            gettext('Help main menu'),224            'keyboardshortcut',225            {226                'alt': True,227                'shift': True,228                'control': False,229                'key': {'key_code': 72, 'char': 'h'}230            },231            category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,232            fields=fields233        )234 235    self.preference.register(236        'keyboard_shortcuts',237        'sub_menu_query_tool',238        gettext('Open query tool'),239        'keyboardshortcut',240        {241            'alt': True,242            'shift': True,243            'control': False,244            'key': {'key_code': 81, 'char': 'q'}245        },246        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,247        fields=fields248    )249 250    self.preference.register(251        'keyboard_shortcuts',252        'sub_menu_view_data',253        gettext('View data'),254        'keyboardshortcut',255        {256            'alt': True,257            'shift': True,258            'control': False,259            'key': {'key_code': 86, 'char': 'v'}260        },261        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,262        fields=fields263    )264 265    self.preference.register(266        'keyboard_shortcuts',267        'sub_menu_search_objects',268        gettext('Search objects'),269        'keyboardshortcut',270        {271            'alt': True,272            'shift': True,273            'control': False,274            'key': {'key_code': 83, 'char': 's'}275        },276        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,277        fields=fields278    )279 280    self.preference.register(281        'keyboard_shortcuts',282        'sub_menu_create',283        gettext('Create object'),284        'keyboardshortcut',285        {286            'alt': True,287            'shift': True,288            'control': False,289            'key': {'key_code': 78, 'char': 'n'}290        },291        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,292        fields=fields293    )294 295    self.preference.register(296        'keyboard_shortcuts',297        'sub_menu_properties',298        gettext('Edit object properties'),299        'keyboardshortcut',300        {301            'alt': True,302            'shift': True,303            'control': False,304            'key': {'key_code': 69, 'char': 'e'}305        },306        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,307        fields=fields308    )309 310    self.preference.register(311        'keyboard_shortcuts',312        'sub_menu_delete',313        gettext('Delete object'),314        'keyboardshortcut',315        {316            'alt': True,317            'shift': True,318            'control': False,319            'key': {'key_code': 68, 'char': 'd'}320        },321        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,322        fields=fields323    )324 325    self.preference.register(326        'keyboard_shortcuts',327        'context_menu',328        gettext('Open context menu'),329        'keyboardshortcut',330        {331            'alt': True,332            'shift': True,333            'control': False,334            'key': {'key_code': 67, 'char': 'c'}335        },336        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,337        fields=fields338    )339 340    self.preference.register(341        'keyboard_shortcuts',342        'direct_debugging',343        gettext('Direct debugging'),344        'keyboardshortcut',345        {346            'alt': True,347            'shift': True,348            'control': False,349            'key': {'key_code': 71, 'char': 'g'}350        },351        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,352        fields=fields353    )354 355    self.preference.register(356        'keyboard_shortcuts',357        'sub_menu_refresh',358        gettext('Refresh object explorer'),359        'keyboardshortcut',360        {361            'alt': False,362            'shift': False,363            'control': False,364            'key': {'key_code': 116, 'char': 'F5'}365        },366        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,367        fields=fields368    )369 370    self.preference.register(371        'keyboard_shortcuts',372        'add_grid_row',373        gettext('Add grid row'),374        'keyboardshortcut',375        {376            'alt': False,377            'shift': True,378            'control': True,379            'key': {'key_code': 65, 'char': 'a'}380        },381        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,382        fields=fields383    )384 385    self.preference.register(386        'keyboard_shortcuts', 'open_quick_search',387        gettext('Quick Search'), 'keyboardshortcut',388        {389            'alt': False,390            'shift': True,391            'control': True,392            'key': {'key_code': 70, 'char': 'f'}393        },394        category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,395        fields=fields396    )397 398    self.dynamic_tab_title = self.preference.register(399        'tab_settings', 'dynamic_tabs',400        gettext("Dynamic tab size"), 'boolean', False,401        category_label=PREF_LABEL_TABS_SETTINGS,402        help_str=gettext(403            'If set to True, the tabs will take full size as per the title, '404            'it will also applicable for already opened tabs')405    )406 407    self.qt_tab_title = self.preference.register(408        'tab_settings', 'qt_tab_title_placeholder',409        gettext("Query tool tab title"),410        'text', QT_DEFAULT_PLACEHOLDER,411        category_label=PREF_LABEL_DISPLAY,412        help_str=gettext(413            'Supported placeholders are %DATABASE%, %USERNAME%, and %SERVER%. '414            'Users can provide any string with or without placeholders of'415            ' their choice. The blank title will be revert back to the'416            ' default title with placeholders.'417        )418    )419 420    self.ve_edt_tab_title = self.preference.register(421        'tab_settings', 'vw_edt_tab_title_placeholder',422        gettext("View/Edit data tab title"),423        'text', VW_EDT_DEFAULT_PLACEHOLDER,424        category_label=PREF_LABEL_DISPLAY,425        help_str=gettext(426            'Supported placeholders are %SCHEMA%, %TABLE%, %DATABASE%, '427            '%USERNAME%, and %SERVER%. Users can provide any string with or '428            'without placeholders of their choice. The blank title will be '429            'revert back to the default title with placeholders.'430        )431    )432 433    self.debugger_tab_title = self.preference.register(434        'tab_settings', 'debugger_tab_title_placeholder',435        gettext("Debugger tab title"),436        'text', '%FUNCTION%(%ARGS%)',437        category_label=PREF_LABEL_DISPLAY,438        help_str=gettext(439            'Supported placeholders are %FUNCTION%, %ARGS%, %SCHEMA% and'440            ' %DATABASE%. Users can provide any string with or '441            'without placeholders of their choice. The blank title will be'442            ' revert back to the default title with placeholders.'443        )444    )445 446    ope_new_tab_options = [447        {'label': gettext('Query Tool'), 'value': 'qt'},448        {'label': gettext('Debugger'), 'value': 'debugger'},449        {'label': gettext('Schema Diff'), 'value': 'schema_diff'},450        {'label': gettext('ERD Tool'), 'value': 'erd_tool'}]451 452    # Allow psq tool to open in new browser tab if ENABLE_PSQL is set to True453    if config.ENABLE_PSQL:454        ope_new_tab_options.append(455            {'label': gettext('PSQL Tool'), 'value': 'psql_tool'})456 457    self.open_in_new_tab = self.preference.register(458        'tab_settings', 'new_browser_tab_open',459        gettext("Open in new browser tab"), 'select', None,460        category_label=PREF_LABEL_OPTIONS,461        options=ope_new_tab_options,462        help_str=gettext(463            'Select Query Tool, Debugger, Schema Diff, ERD Tool '464            'or PSQL Tool from the drop-down to set '465            'open in new browser tab for that particular module.'466        ),467        control_props={468            'multiple': True, 'allowClear': False,469            'tags': True, 'first_empty': False,470            'selectOnClose': False, 'emptyOptions': True,471            'tokenSeparators': [','],472            'placeholder': gettext('Select open new tab...')473        }474    )475 476    # Set PSQL tool tab title if ENABLE_PSQL is set to True477    if config.ENABLE_PSQL:478        self.psql_tab_title = self.preference.register(479            'tab_settings', 'psql_tab_title_placeholder',480            gettext("PSQL tool tab title"),481            'text', '%DATABASE%/%USERNAME%@%SERVER%',482            category_label=PREF_LABEL_DISPLAY,483            help_str=gettext(484                'Supported placeholders are %DATABASE%, %USERNAME%, '485                'and %SERVER%. Users can provide any string with or without'486                ' placeholders of their choice. The blank title will be revert'487                ' back to the default title with placeholders.'488            )489        )490 491    self.preference.register(492        'breadcrumbs', 'breadcrumbs_enable',493        gettext("Enable object breadcrumbs?"),494        'boolean',495        True, category_label=PREF_LABEL_BREADCRUMBS,496        help_str=gettext(497            'Enable breadcrumbs to show the complete path of an object in the '498            'object explorer. The breadcrumbs are displayed on object mouse '499            'hover.'500        )501    )502 503    self.preference.register(504        'breadcrumbs', 'breadcrumbs_show_comment',505        gettext("Show comment with object breadcrumbs?"),506        'boolean',507        True, category_label=PREF_LABEL_BREADCRUMBS,508        help_str=gettext(509            'Show object comment along with breadcrumbs.'510        )511    )512 
codekingpro/portable-devtools · Team Ai