How to remove items from Menus of Existing packages


#1

So I have installed quite a few packages and one of the things that really bothers me is that a lot of them include a the option on the context-menu and some even create a new menu on top. For example, the package Pain-Split creates a completely new item in the top bar as “Window” next to “Help”.

So is there a way to remove them without actually changing the packages themselves? I don’t care much about them since I have memorized the shortcuts and it becomes annoying seeing so many of them. One last thing, if it is possible to change them, is there also a way to have them in the order we want? I mean in the context-menu. Like having open in browser second, and maybe correct spelling third? Thanks


Contextual Menu Modification?
Right click menus are HUGE - any way to get them to normal size? (Ubuntu, hi-res screen)
#2

There is an option in settings to auto-hide the menu.


#3

Thanks for the answer! However, I was mostly talking about the right-click menu. See how many options I have, there is too many for my liking. Maybe there is a way to use the init.coffee file to remove those items from there? Or should I just try to remove them with stylesheets? Sorry if it’s a newb question, I know that i have gone into most packages and they don’t have an option to remove the right-click menu command.


#4

I’d go for a two-pronged approach:

  1. File a bug with the packages in question to put their context-menu items behind an application group, like my tabs-to-spaces package you see in the example.
  2. Look into removing menu items through the init.coffee. I think that’s the approach that will work in the short term.

#5

Thanks. Do you know if an author is also able to publish their package with a settings checkbox to simply just hide the menu even if it’s on an application group? If not, then I will make it a bug request like you said.

Also, would you mind pointing me on how I would go about tackling the individual packages in init.coffee. Like what sort of functions I should be looking for to make them disappear, maybe? Thanks.


#6

There is an undocumented remove function on the MenuManager class:

Perhaps the same thing can be implemented for the ContextMenuManager class:


#7

Thanks, i took a shot at it but within only knowing very little Coffeescript, didn’t go far lol. I’ll leave it open in case someone can answer.


#8

This code should remove packages’ menu items from the menu bar:

# remove menus from the menu bar
packages = ['atom-alignment', 'atom-beautify']

for pkg in packages
  pkg = atom.packages.getLoadedPackage pkg
  return unless pkg?
  {menus} = pkg
  for menu in menus
    mainMenu = menu[1].menu
    atom.menu.remove mainMenu

I’m still looking into removing context menus, but it seems there’s not such a nice API for it :frowning:


#9

Ok, it’s ugly but it works :slight_smile: Removes both the menu-bar menus and the context menus from the packages in the packages array.

# remove menus and context menus for packages
# specified in the packages array
packages = ['atom-alignment', 'atom-beautify']

for pkg in packages
  pkg = atom.packages.getLoadedPackage pkg
  continue unless pkg?
  {menus} = pkg
  for menu in menus
    mainMenu = menu[1].menu
    atom.menu.remove mainMenu

    contextMenu = menu[1]['context-menu']
        for selector, items of contextMenu
          for itemSet, i in atom.contextMenu.itemSets
            continue unless itemSet.items is items
            atom.contextMenu.itemSets.splice i, 1
            break

#10

I just made a post about noting the differences between menu and contextmenu: Contextmenu and Atom menu I’m hoping someone can pick the up.


#11

This is what I put on the init.coffee . I’m I doing something wrong? I am on Windows 7, but I dont’ think that should make a difference.


#12

Ah… I think the return should be a continue. I think I tested with the two first packages to load in my setup, so that’s why it worked for me.


#13

I have some similar quiestion. My right click menu is not where is it supposed to be but is always moved to the right and slightly down. I am using dual monitor and ubuntu 15.04. I installed latest atom. I assume there is problem with dual monitor configuration. Thanks.

P.S.: can’t add screenshot because, every time I want to capture it, right click menu disapers


#14

Thank you for the code! I think I’m going to take a stab at expanding the menu-manager package to include toggling menu item visibility, it might end up being very specific to the version of atom, but it will work in the meantime!


#15

It has been requested before: https://github.com/jerone/menu-manager/issues/2. And I’m open for PR.