Skip to content
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

Allow hiding and disabling of menu items with submenus #1859

Open
evandrocoan opened this issue Aug 4, 2017 · 5 comments
Open

Allow hiding and disabling of menu items with submenus #1859

evandrocoan opened this issue Aug 4, 2017 · 5 comments

Comments

@evandrocoan
Copy link

evandrocoan commented Aug 4, 2017

If a package group several of its menu's entries in a sub-menu, we currently cannot hide folder on non-related projects files:

image

I would suggest to hide each folder the same way the menu's entries are hidden.

Context.sublime-menu

[
    {
        "id": "sublimelinter",
        "caption": "SublimeLinter",
        "children":
        [
            {
                "caption": "Toggle Linter...",
                "command": "sublimelinter_toggle_linter", "args":
                {
                    "which": "all"
                }
            },
            {
                "caption": "-"
            },
            {
                "caption": "Lint This View",
                "command": "sublimelinter_lint"
            },
            ...

-->

[
    {
        "id": "sublimelinter",
        "caption": "SublimeLinter",
        "command": "sublimelinter_main_linter_context_menu"
        "children":
        [
            {
                "caption": "Toggle Linter...",
                "command": "sublimelinter_toggle_linter", "args":
                {
                    "which": "all"
                }
            },
            {
                "caption": "-"
            },
            {
                "caption": "Lint This View",
                "command": "sublimelinter_lint"
            },
            ...

Here the sublimelinter_main_linter_context_menu would never be called to run a action, but just to check whether it is visible or not, as in:

class SublimelinterMainLinterContextMenuCommand(sublime_plugin.WindowCommand):

    def is_enabled(self, **args):
        return do_logic()

    def is_checked(self, **args):
        pass

    def run(self, **args):
        pass

Note, if different Context.sublime-menu file define the same folder, they are independent from each other, so hiding the folder from one, should not remove the folder entries from the other folder. For example, the package Anaconda, and its related packages as Anaconda-Rust, both define the folder menu Anaconda, so when the main Anaconda package say to hide the folder, it should not hide the other package's defined folders.


Related issues:

  1. Menus without child menuitems should be hidden #1095 Menus without child menuitems should be hidden
  2. Hide Anaconda context menu entry on non-python projects DamnWidget/anaconda#571 Hide Anaconda context menu entry on non-python projects
evandrocoan added a commit to evandroforks/SublimeLinter that referenced this issue Aug 4, 2017
supported files. Related to:

Allow to hide .sublime-menu folders
sublimehq/sublime_text#1859
@keith-hall
Copy link
Collaborator

@evandrocoan can you clarify why you don't believe this is a duplicate of #1095 please? is the main difference that you want to control the visibility of the parent menu item "folder" explicitly, as opposed to just automatically having the parent hidden when all of it's children are hidden/disabled?

@FichteFoll
Copy link
Collaborator

FichteFoll commented Aug 5, 2017

@keith-hall I think so, yes. I generally prefer this approach over #1095, because this shows clear intent that a parent item should be disabled or hidden rather than implicitly doing it when a sub-menu has no visible or enabled items. Sometimes a user might want to see this specifically.

I vote to close #1095 as a duplicate in favor of this more general suggestion.

@evandrocoan In your code example, I believe your is_checked should be is_enabled instead.

evandrocoan added a commit to evandroforks/Maven that referenced this issue Aug 5, 2017
evandrocoan added a commit to evandroforks/Anaconda that referenced this issue Aug 5, 2017
Hide Anaconda context menu entry on non-python projects
DamnWidget#571

Allow to hide .sublime-menu folders
sublimehq/sublime_text#1859
@evandrocoan
Copy link
Author

evandrocoan commented Aug 5, 2017

You are right @FichteFoll, I updated the issue. @keith-hall, the package SublimeLinter, has menu entries which are not disabled when it is on a non-linted project. Therefore it would also not be enough to just check whether all entries are disabled. Perhaps I could also want to some menu folder only show up on certain projects, other than only its entries are accessible.

evandrocoan added a commit to evandroforks/Anaconda that referenced this issue Aug 5, 2017
Hide Anaconda context menu entry on non-python projects
DamnWidget#571

Allow to hide .sublime-menu folders
sublimehq/sublime_text#1859
@FichteFoll FichteFoll changed the title Allow to hide .sublime-menu folders Allow control of menu items with submenus (hiding, disabling) Aug 6, 2017
@FichteFoll FichteFoll changed the title Allow control of menu items with submenus (hiding, disabling) Allow hiding and disabling of menu items with submenus Aug 6, 2017
@cameronbroe
Copy link

+1 for this feature request

@tjtyrrell
Copy link

tjtyrrell commented Jan 24, 2019

+1 from me as well

Perhaps just add the ability to call specific menu checkers from the JSON object itself. So something like:

{
    "caption": "My Menu",
    "id": "my_menu",
    "children": [],
    "is_visible": "my_is_visible_function", // leverage the "id" to look for the class
    "is_enabled": "my_is_enabled_function", // see "is_visible"
    "args": {"paths": []}
}
class MyMenu(sublime_plugin.WindowCommand):
    def MyIsVisibleFunction( self, paths = [] ):
        return True

    def MyIsEnabledFunction( self, paths = [] ):
        return False

I dunno, just hoping this makes it in somehow someway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants