Lines 53-77
Link Here
|
53 |
import java.io.OutputStreamWriter; |
53 |
import java.io.OutputStreamWriter; |
54 |
import java.io.Writer; |
54 |
import java.io.Writer; |
55 |
import java.util.ArrayList; |
55 |
import java.util.ArrayList; |
|
|
56 |
import java.util.Arrays; |
57 |
import java.util.Collection; |
56 |
import java.util.Collections; |
58 |
import java.util.Collections; |
57 |
import java.util.HashMap; |
59 |
import java.util.HashMap; |
58 |
import java.util.Iterator; |
60 |
import java.util.Iterator; |
59 |
import java.util.List; |
61 |
import java.util.List; |
60 |
import java.util.Map; |
62 |
import java.util.Map; |
61 |
import java.util.Set; |
63 |
import java.util.Set; |
|
|
64 |
import java.util.StringTokenizer; |
62 |
import java.util.TreeMap; |
65 |
import java.util.TreeMap; |
63 |
import javax.swing.AbstractAction; |
66 |
import javax.swing.AbstractAction; |
64 |
import javax.swing.Action; |
67 |
import javax.swing.Action; |
65 |
import javax.swing.JFileChooser; |
68 |
import javax.swing.JFileChooser; |
|
|
69 |
import javax.swing.KeyStroke; |
70 |
import org.netbeans.core.options.keymap.api.KeyStrokeUtils; |
66 |
import org.netbeans.core.options.keymap.api.ShortcutAction; |
71 |
import org.netbeans.core.options.keymap.api.ShortcutAction; |
67 |
import org.netbeans.core.options.keymap.spi.KeymapManager; |
72 |
import org.netbeans.core.options.keymap.spi.KeymapManager; |
68 |
import org.netbeans.modules.options.keymap.XMLStorage.Attribs; |
73 |
import org.netbeans.modules.options.keymap.XMLStorage.Attribs; |
69 |
import org.openide.ErrorManager; |
74 |
import org.openide.ErrorManager; |
|
|
75 |
import org.openide.awt.HtmlBrowser; |
70 |
import org.openide.filesystems.FileLock; |
76 |
import org.openide.filesystems.FileLock; |
71 |
import org.openide.filesystems.FileObject; |
77 |
import org.openide.filesystems.FileObject; |
72 |
import org.openide.filesystems.FileUtil; |
78 |
import org.openide.filesystems.FileUtil; |
73 |
import org.openide.loaders.DataObject; |
79 |
import org.openide.loaders.DataObject; |
74 |
import org.openide.util.NbBundle; |
80 |
import org.openide.util.NbBundle; |
|
|
81 |
import org.openide.util.Utilities; |
75 |
import org.openide.windows.WindowManager; |
82 |
import org.openide.windows.WindowManager; |
76 |
|
83 |
|
77 |
public class ExportShortcutsAction { |
84 |
public class ExportShortcutsAction { |
Lines 157-163
Link Here
|
157 |
{putValue (Action.NAME, loc ("CTL_Export_Shortcuts_to_HTML_Action"));} |
164 |
{putValue (Action.NAME, loc ("CTL_Export_Shortcuts_to_HTML_Action"));} |
158 |
|
165 |
|
159 |
public void actionPerformed (ActionEvent e) { |
166 |
public void actionPerformed (ActionEvent e) { |
160 |
exportShortcutsToHTML (); |
167 |
exportShortcutsOfAllProfilesToHTML (); |
161 |
} |
168 |
} |
162 |
}; |
169 |
}; |
163 |
|
170 |
|
Lines 167-179
Link Here
|
167 |
|
174 |
|
168 |
|
175 |
|
169 |
// helper methods .......................................................... |
176 |
// helper methods .......................................................... |
|
|
177 |
public static void exportShortcutsOfProfileToHTML (String profile) { |
178 |
final boolean showSystemSpecificShortcuts = true; |
179 |
exportShortcutsToHTML(new KeymapModel(), Arrays.asList(profile), showSystemSpecificShortcuts); |
180 |
} |
181 |
|
182 |
private static void exportShortcutsOfAllProfilesToHTML () { |
183 |
KeymapModel keymapModel = new KeymapModel (); |
184 |
List<String> allProfiles = keymapModel.getProfiles (); |
185 |
final boolean showSystemSpecificShortcuts = false; |
186 |
exportShortcutsToHTML(keymapModel, allProfiles, showSystemSpecificShortcuts); |
187 |
} |
170 |
|
188 |
|
171 |
private static void exportShortcutsToHTML () { |
189 |
|
|
|
190 |
private static void exportShortcutsToHTML (KeymapModel keymapModel, Collection<String> profiles, boolean displayHumanReadibleShortcuts) { |
172 |
// read all shortcuts to keymaps |
191 |
// read all shortcuts to keymaps |
173 |
KeymapModel keymapModel = new KeymapModel (); |
|
|
174 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps = |
192 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps = |
175 |
new TreeMap<String, Map<ShortcutAction, Set<String>>> (); |
193 |
new TreeMap<String, Map<ShortcutAction, Set<String>>> (); |
176 |
for (String profile: keymapModel.getProfiles ()) { |
194 |
for (String profile: profiles) { |
177 |
keymaps.put ( |
195 |
keymaps.put ( |
178 |
profile, |
196 |
profile, |
179 |
keymapModel.getKeymap (profile) |
197 |
keymapModel.getKeymap (profile) |
Lines 208-214
Link Here
|
208 |
} |
226 |
} |
209 |
|
227 |
|
210 |
// print body of table |
228 |
// print body of table |
211 |
exportShortcutsToHTML2 (keymapModel, sb, keymaps); |
229 |
exportShortcutsToHTML2 (keymapModel, sb, keymaps, displayHumanReadibleShortcuts); |
212 |
|
230 |
|
213 |
XMLStorage.generateFolderEnd (sb, "table", " "); |
231 |
XMLStorage.generateFolderEnd (sb, "table", " "); |
214 |
XMLStorage.generateFolderEnd (sb, "body", " "); |
232 |
XMLStorage.generateFolderEnd (sb, "body", " "); |
Lines 219-234
Link Here
|
219 |
"shortcuts.html" |
237 |
"shortcuts.html" |
220 |
); |
238 |
); |
221 |
FileLock fileLock = fo.lock (); |
239 |
FileLock fileLock = fo.lock (); |
222 |
try { |
240 |
try (OutputStream outputStream = fo.getOutputStream (fileLock); |
223 |
OutputStream outputStream = fo.getOutputStream (fileLock); |
241 |
OutputStreamWriter writer = new OutputStreamWriter (outputStream)){ |
224 |
OutputStreamWriter writer = new OutputStreamWriter (outputStream); |
|
|
225 |
writer.write (sb.toString ()); |
242 |
writer.write (sb.toString ()); |
226 |
writer.close (); |
243 |
writer.close (); |
227 |
} catch (IOException ex) { |
244 |
|
|
|
245 |
if (fo.canRead() && displayHumanReadibleShortcuts) { |
246 |
//open generated HTML in external browser |
247 |
HtmlBrowser.URLDisplayer.getDefault().showURLExternal(fo.toURL()); |
248 |
} |
249 |
} catch (IOException ex) { |
228 |
ErrorManager.getDefault ().notify (ex); |
250 |
ErrorManager.getDefault ().notify (ex); |
229 |
} finally { |
251 |
} finally { |
230 |
fileLock.releaseLock (); |
252 |
fileLock.releaseLock (); |
231 |
} |
253 |
} |
|
|
254 |
|
232 |
} catch (IOException ex) { |
255 |
} catch (IOException ex) { |
233 |
ErrorManager.getDefault ().notify (ex); |
256 |
ErrorManager.getDefault ().notify (ex); |
234 |
} |
257 |
} |
Lines 240-246
Link Here
|
240 |
private static void exportShortcutsToHTML2 ( |
263 |
private static void exportShortcutsToHTML2 ( |
241 |
KeymapModel keymapModel, |
264 |
KeymapModel keymapModel, |
242 |
StringBuffer sb, |
265 |
StringBuffer sb, |
243 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps |
266 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps, |
|
|
267 |
boolean displayHumanReadibleShortcuts |
244 |
) { |
268 |
) { |
245 |
List<String> categories = new ArrayList<String> (keymapModel.getActionCategories ()); |
269 |
List<String> categories = new ArrayList<String> (keymapModel.getActionCategories ()); |
246 |
Collections.<String>sort (categories); |
270 |
Collections.<String>sort (categories); |
Lines 260-266
Link Here
|
260 |
XMLStorage.generateFolderEnd (sb, "tr", " "); |
284 |
XMLStorage.generateFolderEnd (sb, "tr", " "); |
261 |
|
285 |
|
262 |
// print body of one category |
286 |
// print body of one category |
263 |
exportShortcutsToHTML3 (sb, keymapModel, category, keymaps); |
287 |
exportShortcutsToHTML3 (sb, keymapModel, category, keymaps, displayHumanReadibleShortcuts); |
264 |
} |
288 |
} |
265 |
} |
289 |
} |
266 |
|
290 |
|
Lines 271-277
Link Here
|
271 |
StringBuffer sb, |
295 |
StringBuffer sb, |
272 |
KeymapModel keymapModel, |
296 |
KeymapModel keymapModel, |
273 |
String category, |
297 |
String category, |
274 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps |
298 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps, |
|
|
299 |
boolean displayHumanReadibleShortcuts |
275 |
) { |
300 |
) { |
276 |
Set<ShortcutAction> actions = keymapModel.getActions (category); |
301 |
Set<ShortcutAction> actions = keymapModel.getActions (category); |
277 |
|
302 |
|
Lines 301-307
Link Here
|
301 |
Set<String> shortcuts = keymap.get (action); |
326 |
Set<String> shortcuts = keymap.get (action); |
302 |
|
327 |
|
303 |
XMLStorage.generateFolderStart (sb, "td", attribs, " "); |
328 |
XMLStorage.generateFolderStart (sb, "td", attribs, " "); |
304 |
printShortcuts (shortcuts, sb); |
329 |
printShortcuts (shortcuts, sb, displayHumanReadibleShortcuts); |
305 |
XMLStorage.generateFolderEnd (sb, "td", " "); |
330 |
XMLStorage.generateFolderEnd (sb, "td", " "); |
306 |
} |
331 |
} |
307 |
|
332 |
|
Lines 309-315
Link Here
|
309 |
} |
334 |
} |
310 |
} |
335 |
} |
311 |
|
336 |
|
312 |
private static void printShortcuts (Set<String> shortcuts, StringBuffer sb) { |
337 |
private static void printShortcuts (Set<String> shortcuts, StringBuffer sb, boolean displayHumanReadibleShortcuts) { |
313 |
if (shortcuts == null) { |
338 |
if (shortcuts == null) { |
314 |
sb.append ('-'); |
339 |
sb.append ('-'); |
315 |
return; |
340 |
return; |
Lines 317-327
Link Here
|
317 |
Iterator<String> it = shortcuts.iterator (); |
342 |
Iterator<String> it = shortcuts.iterator (); |
318 |
while (it.hasNext ()) { |
343 |
while (it.hasNext ()) { |
319 |
String shortcut = it.next (); |
344 |
String shortcut = it.next (); |
320 |
sb.append (shortcut); |
345 |
if (displayHumanReadibleShortcuts) { |
|
|
346 |
//show system specific shortcuts like CTRL-SHIFT-ALT |
347 |
sb.append (portableRepresentationToShortcut(shortcut)); |
348 |
} else { |
349 |
//default: show portable shortcuts like D-O |
350 |
sb.append (shortcut); |
351 |
} |
321 |
if (it.hasNext ()) sb.append (", "); |
352 |
if (it.hasNext ()) sb.append (", "); |
322 |
} |
353 |
} |
323 |
} |
354 |
} |
324 |
|
355 |
|
|
|
356 |
/** |
357 |
* Converts the portable shortcut representation to a human-readable shortcut |
358 |
* @param portable portable representation (the storage format for shortcuts) |
359 |
* @return human-readable string |
360 |
*/ |
361 |
static String portableRepresentationToShortcut(String portable) { |
362 |
assert portable != null : "The parameter must not be null"; //NOI18N |
363 |
|
364 |
StringBuilder buf = new StringBuilder(); |
365 |
String delimiter = " "; //NOI18N |
366 |
|
367 |
for(StringTokenizer st = new StringTokenizer(portable, delimiter); st.hasMoreTokens();) { //NOI18N |
368 |
String ks = st.nextToken().trim(); |
369 |
|
370 |
KeyStroke keyStroke = Utilities.stringToKey(ks); |
371 |
|
372 |
if (keyStroke != null) { |
373 |
buf.append(KeyStrokeUtils.getKeyStrokeAsText(keyStroke)); |
374 |
if (st.hasMoreTokens()) |
375 |
buf.append(' '); |
376 |
} else { |
377 |
return null; |
378 |
} |
379 |
} |
380 |
|
381 |
return buf.toString(); |
382 |
} |
383 |
|
325 |
private static void generateLayersXML ( |
384 |
private static void generateLayersXML ( |
326 |
LayersBridge layersBridge, |
385 |
LayersBridge layersBridge, |
327 |
Map<String, Map<String, ShortcutAction>> categoryToActions |
386 |
Map<String, Map<String, ShortcutAction>> categoryToActions |