Working with Shortcuts
Working with Class Shortcuts.
The Class CalcDoc, Class DrawDoc, Class ImpressDoc and Class WriteDoc
have a shortcuts
property that can be used to add shortcuts to the menu for the given application.
Class MenuApp can create and store shortcuts automatically via ShortCut
key entry.
ShortCut
The ShortCut
can be a string or a dictionary.
String
As a string the value is automatically saved into the registrymodifications.xcu
as a global or local entry.
Example:
"ShortCut": "Shift+Ctrl+Alt+E"
Dictionary
As a dictionary the accepted keys are key
and save
(lower case).
If key
is not present then the shortcut is ignored.
if save
is not present then it defaults to True
.
Example:
"ShortCut": {"key": "Shift+Ctrl+Alt+F", "save": False}
When the shortcut is set to false it will still work in the menu but will not be persisted into registrymodifications.xcu
.
This means it would have to be loaded again after restarting LibreOffice.
Global Shortcut
Create
Manually adding a shortcut to global.
new_menu = {
"Label": "My Menu",
"CommandURL": menu_name,
"Submenu": [
{
"Label": "all Alone",
"CommandURL": ".custom:alone.here",
},
],
}
Create a persistent global shortcut.
from ooodev.gui.menu import Shortcuts
# ...
sc = Shortcuts()
sc.set("Shift+Ctrl+Alt+A", ".custom:alone.here", True)
registrymodifications.xcu
entry.
<item oor:path="/org.openoffice.Office.Accelerators/PrimaryKeys/Global">
<node oor:name="A_SHIFT_MOD1_MOD2" oor:op="replace">
<prop oor:name="Command" oor:op="fuse">
<value xml:lang="en-US">alone.here</value>
</prop>
</node>
</item>
Remove
By Command
Removes shortcut from running instance but does not save so on next load the shortcut is back.
from ooodev.gui.menu import Shortcuts
# ...
sc = Shortcuts()
sc.remove_by_command(".custom:alone.here", False)
Removes shortcut from running instance and persist changes.
from ooodev.gui.menu import Shortcuts
# ...
sc = Shortcuts()
sc.remove_by_command(".custom:alone.here", True)
By Shortcut
Removes shortcut from running instance but does not save so on next load the shortcut is back.
from ooodev.gui.menu import Shortcuts
# ...
sc = Shortcuts()
sc.remove_by_shortcut("Shift+Ctrl+Alt+A", False)
Removes shortcut from running instance and persist changes.
from ooodev.gui.menu import Shortcuts
# ...
sc = Shortcuts()
sc.remove_by_shortcut("Shift+Ctrl+Alt+A", True)
Local Shortcut
Create
Create a persistent local shortcut.
from ooodev.calc import CalcDoc
# ...
doc = CalcDoc.from_current_doc()
doc.shortcuts.set("Shift+Ctrl+Alt+A", ".custom:alone.here", True)
registrymodifications.xcu
entry.
<item oor:path="/org.openoffice.Office.Accelerators/PrimaryKeys/Modules/org.openoffice.Office.Accelerators:Module['com.sun.star.sheet.SpreadsheetDocument']">
<node oor:name="A_SHIFT_MOD1_MOD2" oor:op="replace">
<prop oor:name="Command" oor:op="fuse">
<value xml:lang="en-US">alone.here</value>
</prop>
</node>
</item>
Remove
By Command
Removes shortcut from running instance but does not save so on next load the shortcut is back.
from ooodev.calc import CalcDoc
# ...
doc = CalcDoc.from_current_doc()
doc.shortcuts.remove_by_command(".custom:alone.here", False)
Removes shortcut from running instance and persist changes.
# ...
doc = CalcDoc.from_current_doc()
doc.shortcuts.remove_by_command(".custom:alone.here", True)
By Shortcut
Removes shortcut from running instance but does not save so on next load the shortcut is back.
# ...
doc = CalcDoc.from_current_doc()
doc.shortcuts.remove_by_shortcut("Shift+Ctrl+Alt+A", False)
Removes shortcut from running instance and persist changes.
# ...
doc = CalcDoc.from_current_doc()
doc.shortcuts.remove_by_shortcut("Shift+Ctrl+Alt+A", True)
Reset
Resetting is suppose to cause the component to reset to some default value.
Resetting stores the configuration including any current changes.
# ...
doc = CalcDoc.from_current_doc()
print(doc.shortcuts.set("Shift+Ctrl+Alt+A", ".custom:alone.here", False))
doc.shortcuts.reset()
Calling doc.shortcuts.reset()
causes the changes to be saved and the shortcut persist.