|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the writer class for writing an XML shortcuts file. |
|
8 """ |
|
9 |
|
10 import time |
|
11 |
|
12 from E4Gui.E4Application import e4App |
|
13 |
|
14 from .XMLWriterBase import XMLWriterBase |
|
15 from .Config import shortcutsFileFormatVersion |
|
16 |
|
17 import Preferences |
|
18 |
|
19 class ShortcutsWriter(XMLWriterBase): |
|
20 """ |
|
21 Class implementing the writer class for writing an XML shortcuts file. |
|
22 """ |
|
23 def __init__(self, file): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param file open file (like) object for writing |
|
28 """ |
|
29 XMLWriterBase.__init__(self, file) |
|
30 |
|
31 self.email = Preferences.getUser("Email") |
|
32 |
|
33 def writeXML(self): |
|
34 """ |
|
35 Public method to write the XML to the file. |
|
36 """ |
|
37 XMLWriterBase.writeXML(self) |
|
38 |
|
39 self._write('<!DOCTYPE Shortcuts SYSTEM "Shortcuts-%s.dtd">' % \ |
|
40 shortcutsFileFormatVersion) |
|
41 |
|
42 # add some generation comments |
|
43 self._write("<!-- Eric5 keyboard shortcuts -->") |
|
44 self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S')) |
|
45 self._write("<!-- Author: %s -->" % self.escape("%s" % self.email)) |
|
46 |
|
47 # add the main tag |
|
48 self._write('<Shortcuts version="%s">' % shortcutsFileFormatVersion) |
|
49 |
|
50 for act in e4App().getObject("Project").getActions(): |
|
51 self._write(' <Shortcut category="Project">') |
|
52 self._write(' <Name>%s</Name>' % act.objectName()) |
|
53 self._write(' <Accel>%s</Accel>' % \ |
|
54 self.escape("%s" % act.shortcut().toString())) |
|
55 self._write(' <AltAccel>%s</AltAccel>' \ |
|
56 % self.escape("%s" % act.alternateShortcut().toString())) |
|
57 self._write(' </Shortcut>') |
|
58 |
|
59 for act in e4App().getObject("UserInterface").getActions('ui'): |
|
60 self._write(' <Shortcut category="General">') |
|
61 self._write(' <Name>%s</Name>' % act.objectName()) |
|
62 self._write(' <Accel>%s</Accel>' % \ |
|
63 self.escape("%s" % act.shortcut().toString())) |
|
64 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
65 self.escape("%s" % act.alternateShortcut().toString())) |
|
66 self._write(' </Shortcut>') |
|
67 |
|
68 for act in e4App().getObject("UserInterface").getActions('wizards'): |
|
69 self._write(' <Shortcut category="Wizards">') |
|
70 self._write(' <Name>%s</Name>' % act.objectName()) |
|
71 self._write(' <Accel>%s</Accel>' % \ |
|
72 self.escape("%s" % act.shortcut().toString())) |
|
73 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
74 self.escape("%s" % act.alternateShortcut().toString())) |
|
75 self._write(' </Shortcut>') |
|
76 |
|
77 for act in e4App().getObject("DebugUI").getActions(): |
|
78 self._write(' <Shortcut category="Debug">') |
|
79 self._write(' <Name>%s</Name>' % act.objectName()) |
|
80 self._write(' <Accel>%s</Accel>' % \ |
|
81 self.escape("%s" % act.shortcut().toString())) |
|
82 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
83 self.escape("%s" % act.alternateShortcut().toString())) |
|
84 self._write(' </Shortcut>') |
|
85 |
|
86 for act in e4App().getObject("ViewManager").getActions('edit'): |
|
87 self._write(' <Shortcut category="Edit">') |
|
88 self._write(' <Name>%s</Name>' % act.objectName()) |
|
89 self._write(' <Accel>%s</Accel>' % \ |
|
90 self.escape("%s" % act.shortcut().toString())) |
|
91 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
92 self.escape("%s" % act.alternateShortcut().toString())) |
|
93 self._write(' </Shortcut>') |
|
94 |
|
95 for act in e4App().getObject("ViewManager").getActions('file'): |
|
96 self._write(' <Shortcut category="File">') |
|
97 self._write(' <Name>%s</Name>' % act.objectName()) |
|
98 self._write(' <Accel>%s</Accel>' % \ |
|
99 self.escape("%s" % act.shortcut().toString())) |
|
100 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
101 self.escape("%s" % act.alternateShortcut().toString())) |
|
102 self._write(' </Shortcut>') |
|
103 |
|
104 for act in e4App().getObject("ViewManager").getActions('search'): |
|
105 self._write(' <Shortcut category="Search">') |
|
106 self._write(' <Name>%s</Name>' % act.objectName()) |
|
107 self._write(' <Accel>%s</Accel>' % \ |
|
108 self.escape("%s" % act.shortcut().toString())) |
|
109 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
110 self.escape("%s" % act.alternateShortcut().toString())) |
|
111 self._write(' </Shortcut>') |
|
112 |
|
113 for act in e4App().getObject("ViewManager").getActions('view'): |
|
114 self._write(' <Shortcut category="View">') |
|
115 self._write(' <Name>%s</Name>' % act.objectName()) |
|
116 self._write(' <Accel>%s</Accel>' % \ |
|
117 self.escape("%s" % act.shortcut().toString())) |
|
118 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
119 self.escape("%s" % act.alternateShortcut().toString())) |
|
120 self._write(' </Shortcut>') |
|
121 |
|
122 for act in e4App().getObject("ViewManager").getActions('macro'): |
|
123 self._write(' <Shortcut category="Macro">') |
|
124 self._write(' <Name>%s</Name>' % act.objectName()) |
|
125 self._write(' <Accel>%s</Accel>' % \ |
|
126 self.escape("%s" % act.shortcut().toString())) |
|
127 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
128 self.escape("%s" % act.alternateShortcut().toString())) |
|
129 self._write(' </Shortcut>') |
|
130 |
|
131 for act in e4App().getObject("ViewManager").getActions('bookmark'): |
|
132 self._write(' <Shortcut category="Bookmarks">') |
|
133 self._write(' <Name>%s</Name>' % act.objectName()) |
|
134 self._write(' <Accel>%s</Accel>' % \ |
|
135 self.escape("%s" % act.shortcut().toString())) |
|
136 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
137 self.escape("%s" % act.alternateShortcut().toString())) |
|
138 self._write(' </Shortcut>') |
|
139 |
|
140 for act in e4App().getObject("ViewManager").getActions('spelling'): |
|
141 self._write(' <Shortcut category="Spelling">') |
|
142 self._write(' <Name>%s</Name>' % act.objectName()) |
|
143 self._write(' <Accel>%s</Accel>' % \ |
|
144 self.escape("%s" % act.shortcut().toString())) |
|
145 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
146 self.escape("%s" % act.alternateShortcut().toString())) |
|
147 self._write(' </Shortcut>') |
|
148 |
|
149 actions = e4App().getObject("ViewManager").getActions('window') |
|
150 for act in actions: |
|
151 self._write(' <Shortcut category="Window">') |
|
152 self._write(' <Name>%s</Name>' % act.objectName()) |
|
153 self._write(' <Accel>%s</Accel>' % \ |
|
154 self.escape("%s" % act.shortcut().toString())) |
|
155 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
156 self.escape("%s" % act.alternateShortcut().toString())) |
|
157 self._write(' </Shortcut>') |
|
158 |
|
159 for category, ref in e4App().getPluginObjects(): |
|
160 if hasattr(ref, "getActions"): |
|
161 actions = ref.getActions() |
|
162 for act in actions: |
|
163 if act.objectName(): |
|
164 # shortcuts are only exported, if their objectName is set |
|
165 self._write(' <Shortcut category="%s">' % category) |
|
166 self._write(' <Name>%s</Name>' % act.objectName()) |
|
167 self._write(' <Accel>%s</Accel>' % \ |
|
168 self.escape("%s" % act.shortcut().toString())) |
|
169 self._write(' <AltAccel>%s</AltAccel>' % \ |
|
170 self.escape("%s" % act.alternateShortcut().toString())) |
|
171 self._write(' </Shortcut>') |
|
172 |
|
173 for act in e4App().getObject("DummyHelpViewer").getActions(): |
|
174 self._write(' <Shortcut category="HelpViewer">') |
|
175 self._write(' <Name>%s</Name>' % act.objectName()) |
|
176 self._write(' <Accel>%s</Accel>' % \ |
|
177 self.escape("%s" % act.shortcut().toString())) |
|
178 self._write(' <AltAccel>%s</AltAccel>' \ |
|
179 % self.escape("%s" % act.alternateShortcut().toString())) |
|
180 self._write(' </Shortcut>') |
|
181 |
|
182 # add the main end tag |
|
183 self._write("</Shortcuts>", newline = False) |