Doc for menus
This commit is contained in:
parent
4a18a7df0d
commit
6dab9ffd5a
|
@ -270,5 +270,11 @@ All methods some the same.
|
||||||
For other applications: `writer`, `draw`, `impress`, `math`
|
For other applications: `writer`, `draw`, `impress`, `math`
|
||||||
|
|
||||||
|
|
||||||
|
Menus
|
||||||
|
-----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands
|
.. _dispatch command: https://wiki.documentfoundation.org/Development/DispatchCommands
|
||||||
.. _support filters: https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html
|
.. _support filters: https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html
|
||||||
|
|
|
@ -2169,25 +2169,35 @@ class LOShortCuts(object):
|
||||||
|
|
||||||
|
|
||||||
class LOMenu(object):
|
class LOMenu(object):
|
||||||
|
|
||||||
|
def __init__(self, app, menu, config):
|
||||||
|
self._app = app
|
||||||
|
self._menu = menu
|
||||||
|
self._config = config
|
||||||
|
|
||||||
|
|
||||||
|
class LOMenuApp(object):
|
||||||
NODE = 'private:resource/menubar/menubar'
|
NODE = 'private:resource/menubar/menubar'
|
||||||
MENUS = {
|
MENUS = {
|
||||||
'file': '.uno:PickList',
|
'file': '.uno:PickList',
|
||||||
|
'picklist': '.uno:PickList',
|
||||||
'tools': '.uno:ToolsMenu',
|
'tools': '.uno:ToolsMenu',
|
||||||
'help': '.uno:HelpMenu',
|
'help': '.uno:HelpMenu',
|
||||||
'windows': '.uno:WindowList',
|
'window': '.uno:WindowList',
|
||||||
'edit': '.uno:EditMenu',
|
'edit': '.uno:EditMenu',
|
||||||
'view': '.uno:ViewMenu',
|
'view': '.uno:ViewMenu',
|
||||||
'insert': '.uno:InsertMenu',
|
'insert': '.uno:InsertMenu',
|
||||||
'format': '.uno:FormatMenu',
|
'format': '.uno:FormatMenu',
|
||||||
'styles': '.uno:FormatStylesMenu',
|
'styles': '.uno:FormatStylesMenu',
|
||||||
|
'formatstyles': '.uno:FormatStylesMenu',
|
||||||
'sheet': '.uno:SheetMenu',
|
'sheet': '.uno:SheetMenu',
|
||||||
'data': '.uno:DataMenu',
|
'data': '.uno:DataMenu',
|
||||||
'table': '.uno:TableMenu',
|
'table': '.uno:TableMenu',
|
||||||
'form': '.uno:FormatFormMenu',
|
'formatform': '.uno:FormatFormMenu',
|
||||||
'page': '.uno:PageMenu',
|
'page': '.uno:PageMenu',
|
||||||
'shape': '.uno:ShapeMenu',
|
'shape': '.uno:ShapeMenu',
|
||||||
'slide': '.uno:SlideMenu',
|
'slide': '.uno:SlideMenu',
|
||||||
'show': '.uno:SlideShowMenu',
|
'slideshow': '.uno:SlideShowMenu',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
|
@ -2202,8 +2212,108 @@ class LOMenu(object):
|
||||||
config = manager.getUIConfigurationManager(type_app)
|
config = manager.getUIConfigurationManager(type_app)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def debug(self):
|
def _get_info(self, menu):
|
||||||
|
line = menu.get('CommandURL', '')
|
||||||
|
line += self._get_submenus(menu['ItemDescriptorContainer'])
|
||||||
|
return line
|
||||||
|
|
||||||
|
def _get_submenus(self, menu, level=1):
|
||||||
|
line = ''
|
||||||
|
for i, v in enumerate(menu):
|
||||||
|
data = data_to_dict(v)
|
||||||
|
cmd = data.get('CommandURL', '----------')
|
||||||
|
line += f'\n{" " * level}├─ ({i}) {cmd}'
|
||||||
|
submenu = data.get('ItemDescriptorContainer', None)
|
||||||
|
if not submenu is None:
|
||||||
|
line += self._get_submenus(submenu, level + 1)
|
||||||
|
return line
|
||||||
|
|
||||||
|
def debug(self):
|
||||||
|
for m in self._menus:
|
||||||
|
menu = data_to_dict(m)
|
||||||
|
print(self._get_info(menu))
|
||||||
|
return
|
||||||
|
|
||||||
|
def __contains__(self, name):
|
||||||
|
exists = False
|
||||||
|
for m in self._menus:
|
||||||
|
menu = data_to_dict(m)
|
||||||
|
cmd = menu.get('CommandURL', '')
|
||||||
|
if name == cmd:
|
||||||
|
exists = True
|
||||||
|
break
|
||||||
|
return exists
|
||||||
|
|
||||||
|
def __getitem__(self, index):
|
||||||
|
if isinstance(index, int):
|
||||||
|
menu = self._menus[index]
|
||||||
|
else:
|
||||||
|
for m in self._menus:
|
||||||
|
menu = data_to_dict(m)
|
||||||
|
cmd = menu.get('CommandURL', '')
|
||||||
|
if self.MENUS[index.lower()] == cmd:
|
||||||
|
break
|
||||||
|
return LOMenu(self._app, m, self._config)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def count(self):
|
||||||
|
return len(self._menus)
|
||||||
|
|
||||||
|
def _get_index(self, name):
|
||||||
|
index = -1
|
||||||
|
for i, m in enumerate(self._menus):
|
||||||
|
menu = data_to_dict(m)
|
||||||
|
if menu['CommandURL'] == self.MENUS[name]:
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
return index
|
||||||
|
|
||||||
|
def _get_command_url(self, menu: dict):
|
||||||
|
shortcut = menu.pop('ShortCut', '')
|
||||||
|
command = menu['CommandURL']
|
||||||
|
url = LOShortCuts.get_url_script(command)
|
||||||
|
if shortcut:
|
||||||
|
LOShortCuts(self._app).set(shortcut, command)
|
||||||
|
return url
|
||||||
|
|
||||||
|
def _insert_submenu(self, parent: Any, menus: list):
|
||||||
|
for i, menu in enumerate(menus):
|
||||||
|
submenu = menu.pop('Submenu', False)
|
||||||
|
if submenu:
|
||||||
|
idc = self._config.createSettings()
|
||||||
|
menu['ItemDescriptorContainer'] = idc
|
||||||
|
menu['Type'] = 0
|
||||||
|
if menu['Label'][0] == '-':
|
||||||
|
menu['Type'] = 1
|
||||||
|
else:
|
||||||
|
menu['CommandURL'] = self._get_command_url(menu)
|
||||||
|
self._save(parent, menu, i)
|
||||||
|
if submenu:
|
||||||
|
self._insert_submenu(idc, submenu)
|
||||||
|
return
|
||||||
|
|
||||||
|
def _save(self, parent: Any, menu: dict, index: int):
|
||||||
|
# ~ Some day
|
||||||
|
# ~ self._menus.insertByIndex(index, new_menu)
|
||||||
|
properties = dict_to_property(menu, True)
|
||||||
|
uno.invoke(parent, 'insertByIndex', (index, properties))
|
||||||
|
self._config.replaceSettings(self.NODE, self._menus)
|
||||||
|
return
|
||||||
|
|
||||||
|
def insert(self, menu, after: str='', save: bool=True):
|
||||||
|
if after:
|
||||||
|
index = self._get_index(after) + 1
|
||||||
|
else:
|
||||||
|
index = self.count
|
||||||
|
|
||||||
|
submenu = menu.pop('Submenu', False)
|
||||||
|
menu['Type'] = menu.get('Type', 0)
|
||||||
|
menu['ItemDescriptorContainer'] = self._config.createSettings()
|
||||||
|
self._save(self._menus, menu, index)
|
||||||
|
self._insert_submenu(menu['ItemDescriptorContainer'], submenu)
|
||||||
|
|
||||||
|
if save:
|
||||||
|
self._config.store()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -2211,7 +2321,7 @@ class LOMenus(object):
|
||||||
"""Classe for manager menus"""
|
"""Classe for manager menus"""
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
return LOMenu(index)
|
return LOMenuApp(index)
|
||||||
|
|
||||||
|
|
||||||
class LOMain():
|
class LOMain():
|
||||||
|
@ -2857,6 +2967,7 @@ def __getattr__(name):
|
||||||
'io': IOStream,
|
'io': IOStream,
|
||||||
'clipboard': ClipBoard,
|
'clipboard': ClipBoard,
|
||||||
'shortcuts': LOShortCuts(),
|
'shortcuts': LOShortCuts(),
|
||||||
|
'menus': LOMenus(),
|
||||||
'lo': LOMain,
|
'lo': LOMain,
|
||||||
'command': LOMain.cmd,
|
'command': LOMain.cmd,
|
||||||
'docs': LODocuments(),
|
'docs': LODocuments(),
|
||||||
|
|
Loading…
Reference in New Issue