Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fix the Extentions menu sorting in macOS High Sierra in Robofont 1.8
- # (set this up as a start up script and you're good to go)
- # This is just a hack, you should really check out RoboFont 3
- from AppKit import *
- from lib.doodleMenus import BaseMenu
- # ----------------------------------------
- def sort_menu_items(menu):
- controller = BaseMenu()
- # collect the different sub parts
- parts = []
- sub_parts = []
- for i in menu.itemArray():
- if i.hasSubmenu():
- sort_menu_items(i.submenu())
- if i.isSeparatorItem():
- sub_parts.append(i)
- parts.append(sub_parts)
- sub_parts = []
- else:
- sub_parts.append(i)
- parts.append(sub_parts)
- # sort the menu items
- sorted_parts = []
- for sub_parts in parts:
- # get the separator out
- if len(sub_parts) > 0 and sub_parts[-1].isSeparatorItem():
- sep = sub_parts.pop(-1)
- else:
- sep = None
- # keep alternates together with their parent when applicable
- sub_parts_with_alternates = []
- for p in sub_parts:
- if not p.isAlternate():
- sub_parts_with_alternates.append([p])
- else:
- sub_parts_with_alternates[-1].append(p)
- # sort
- sub_parts_with_alternates.sort(key=lambda alts: alts[0].title())
- # flatten the [parent, alternate] couples
- sub_parts_flat = [item for sublist in sub_parts_with_alternates for item in sublist]
- # and put the separator back in
- if sep:
- sub_parts_flat.append(sep)
- sorted_parts += sub_parts_flat
- # rebuild the menu
- menu.removeAllItems()
- controller.buildAdditionContextualMenuItems(menu, sorted_parts)
- # ----------------------------------------
- menuBar = NSApp().mainMenu()
- ExtMenu = menuBar.itemWithTitle_("Extensions")
- menu = ExtMenu.submenu()
- sort_menu_items(menu)
Add Comment
Please, Sign In to add comment