Skip to content

Commit d4b2173

Browse files
[Feature] Add a setting to allow filter of plugin commands on package.
This commit adds a new setting `filter_plugin_commands_on_package` to allow a user to filter the command list based on the package name.
1 parent e07f79a commit d4b2173

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

resources/CommandsBrowser.sublime-settings

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@
4848
// https://www.sublimetext.com/docs/api_reference.html#type-event_dict
4949
//
5050
// The default value for this setting is "ctrl".
51-
"copy_command_signature_modifier_key": "ctrl"
51+
"copy_command_signature_modifier_key": "ctrl",
52+
53+
"filter_plugin_commands_on_package": "all"
5254
}

src/commands/commands_browser_plugin_commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
)
77

88
from ..settings import commands_browser_settings
9-
from ..utils.miscellaneous_utils import log, filter_command_types
9+
from ..utils.miscellaneous_utils import log, filter_command_types, filter_package_setting
1010

1111

1212
class CommandsBrowserPluginCommandsCommand(sublime_plugin.ApplicationCommand):
@@ -39,6 +39,7 @@ def run(self, cmd_dict = None):
3939
host = "all"
4040

4141
cmd_type_filter_list = filter_command_types("filter_plugin_commands_on_type")
42+
package_filter = filter_package_setting()
4243

4344
for _, details in cmd_dict.items():
4445

@@ -49,6 +50,12 @@ def run(self, cmd_dict = None):
4950
if details["type"] not in cmd_type_filter_list:
5051
continue
5152

53+
if package_filter == "all":
54+
pass
55+
else:
56+
if details["pkg"] not in package_filter:
57+
continue
58+
5259
items.append(
5360
sublime.QuickPanelItem(
5461
trigger = details["name"],

src/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def load_commands_browser_settings():
1616
"filter_plugin_commands_on_host": "all",
1717
"filter_plugin_commands_on_type": ["text", "window", "application"],
1818
"filter_core_commands_on_type": ["text", "window", "application", "find"],
19-
"copy_command_signature_modifier_key": "ctrl"
19+
"copy_command_signature_modifier_key": "ctrl",
20+
"filter_plugin_commands_on_package": "all"
2021
}
2122

2223

src/utils/miscellaneous_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,26 @@ def filter_command_types(setting_name):
6767
cmd_type_filter_list = commands_browser_settings.default.get(f"{setting_name}")
6868

6969
return cmd_type_filter_list
70+
71+
72+
def filter_package_setting():
73+
""" Filters the setting 'filter_plugin_commands_on_package' to get rid of
74+
any invalid values a user may set and sanitize it to sane defaults.
75+
76+
Args:
77+
None
78+
79+
Returns:
80+
package_filter (string | List[str]): The sanitised package filter list.
81+
"""
82+
package_filter = commands_browser_settings("filter_plugin_commands_on_package")
83+
84+
if (
85+
((type(package_filter) != str) and (type(package_filter) != list)) or
86+
(package_filter == "all")
87+
):
88+
log(f"""'{package_filter}' is an invalid value for the setting
89+
'filter_plugin_commands_on_package'. Falling back to default value.""")
90+
package_filter = "all"
91+
92+
return package_filter

0 commit comments

Comments
 (0)