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

Menus without child menuitems should be hidden #1095

Open
titoBouzout opened this issue Feb 10, 2016 · 7 comments
Open

Menus without child menuitems should be hidden #1095

titoBouzout opened this issue Feb 10, 2016 · 7 comments

Comments

@titoBouzout
Copy link
Collaborator

In a couple of situations all child menu-items are not shown due to "is_visible" because simply the context on which these are triggered is not relevant. However the container of these menu-items(the menu) are still shown empty. Which disturbs a bit, and sometimes may cause confusion.

@titoBouzout titoBouzout changed the title Menus without child menu items should be hidden Menus without child menuitems should be hidden Feb 10, 2016
@FichteFoll
Copy link
Collaborator

I think it should be disabled instead.

@titoBouzout
Copy link
Collaborator Author

Well, as the child items are invisible, I think the right thing to do here it to hide it. If the menu was created to be show, then the child menu items will not have "is_visible" returning False.

If all child menu items agree to return False for "is_visible" (therefore the menu is empty) then the menu should be hidden too

@FichteFoll
Copy link
Collaborator

Good point.

There is no way to set the visible or enabled state of a menu item containing child items, thus you can not tell ST which should be preferred. Usually hiding information should very rarely be done because it confuses users as to why things are "not there". Explicitly disabling something has more feedback.

Maybe a new key for .sublime-menu files could be added that specifies if a menu item without visible children should be hidden or disabled.

@duckythescientist
Copy link

duckythescientist commented Jul 8, 2016

I've found a workaround:

EDIT: this doesn't seem to work in Windows. It at least works in Ubuntu 14.04, ST 3114.

Make a command in your plugin whose entire purpose is to check if it should be enabled/visible (either by performing the check directly or by querying all of the children explicitly). For the parent menu item, add a "command" key with a value of your new command.

class CfptTest(sublime_plugin.TextCommand):

    """Return the text in the highlighted region
    """
    def gettext(self):
        region = self.view.sel()[0]
        return self.view.substr(region) 

    """Disable command when no text selected
    """
    def is_enabled(self):
        return self.gettext() is not ""

and

[
    { "caption": "Copy-From" , "command": "cfpt_test", "children": 
        [
            ....
        ]
    }
]

@FichteFoll
Copy link
Collaborator

FichteFoll commented Jul 11, 2016

@duckythescientist, doesn't work for me. Neither is_enabled nor is_visible get called. Windows 10, ST 3118.

It would be a fine solution if it worked however.

@duckythescientist
Copy link

@FichteFoll, interesting. It works with my Ubuntu 14.04, ST 3114, but it doesn't work in my Windows 7 with ST 3114.

@evandrocoan
Copy link

evandrocoan commented Oct 23, 2016

Also hidden them when all its children are invalid. It is necessary for the DamnWidget/anaconda#571.

Well, if there is the is_visible for the children, why not for its parent?

Or allow the is_visible command as:

import sublime
import sublime_plugin

class AnacondaContextMenuVisibilityCommand(sublime_plugin.TextCommand):

    def run(self, edit):

        return False


    def is_visible(self):

        print( ' Calling AnacondaContextMenuVisibilityCommand is_visible...' )
        return False

Which does not work currently work for this menu entry file:

[
    {
        "caption": "Anaconda",
        "command": "anaconda_context_menu_visibility",
        "id": "anaconda_context",
        "children":
        [
            {
                "command": "anaconda_goto",
                "caption": "Goto Definition"
            },
        ]
    }
]

Related threads:

  1. Hide Anaconda context menu entry on non-python projects DamnWidget/anaconda#571
  2. https://forum.sublimetext.com/t/hide-parent-menu-item-in-context-menu/11272
  3. https://forum.sublimetext.com/t/how-to-hide-parent-menu-entry-using-the-is-visible/23913

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

4 participants