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 150-156
Link Here
|
150 |
{putValue (Action.NAME, loc ("CTL_Export_Shortcuts_to_HTML_Action"));} |
157 |
{putValue (Action.NAME, loc ("CTL_Export_Shortcuts_to_HTML_Action"));} |
151 |
|
158 |
|
152 |
public void actionPerformed (ActionEvent e) { |
159 |
public void actionPerformed (ActionEvent e) { |
153 |
exportShortcutsToHTML (); |
160 |
exportShortcutsOfAllProfilesToHTML (); |
154 |
} |
161 |
} |
155 |
}; |
162 |
}; |
156 |
|
163 |
|
Lines 160-172
Link Here
|
160 |
|
167 |
|
161 |
|
168 |
|
162 |
// helper methods .......................................................... |
169 |
// helper methods .......................................................... |
|
|
170 |
public static void exportShortcutsOfProfileToHTML (String profile) { |
171 |
final boolean showSystemSpecificShortcuts = true; |
172 |
exportShortcutsToHTML(new KeymapModel(), Arrays.asList(profile), showSystemSpecificShortcuts); |
173 |
} |
174 |
|
175 |
private static void exportShortcutsOfAllProfilesToHTML () { |
176 |
KeymapModel keymapModel = new KeymapModel (); |
177 |
List<String> allProfiles = keymapModel.getProfiles (); |
178 |
final boolean showSystemSpecificShortcuts = false; |
179 |
exportShortcutsToHTML(keymapModel, allProfiles, showSystemSpecificShortcuts); |
180 |
} |
163 |
|
181 |
|
164 |
private static void exportShortcutsToHTML () { |
182 |
|
|
|
183 |
private static void exportShortcutsToHTML (KeymapModel keymapModel, Collection<String> profiles, boolean displayHumanReadibleShortcuts) { |
165 |
// read all shortcuts to keymaps |
184 |
// read all shortcuts to keymaps |
166 |
KeymapModel keymapModel = new KeymapModel (); |
|
|
167 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps = |
185 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps = |
168 |
new TreeMap<String, Map<ShortcutAction, Set<String>>> (); |
186 |
new TreeMap<String, Map<ShortcutAction, Set<String>>> (); |
169 |
for (String profile: keymapModel.getProfiles ()) { |
187 |
for (String profile: profiles) { |
170 |
keymaps.put ( |
188 |
keymaps.put ( |
171 |
profile, |
189 |
profile, |
172 |
keymapModel.getKeymap (profile) |
190 |
keymapModel.getKeymap (profile) |
Lines 201-207
Link Here
|
201 |
} |
219 |
} |
202 |
|
220 |
|
203 |
// print body of table |
221 |
// print body of table |
204 |
exportShortcutsToHTML2 (keymapModel, sb, keymaps); |
222 |
exportShortcutsToHTML2 (keymapModel, sb, keymaps, displayHumanReadibleShortcuts); |
205 |
|
223 |
|
206 |
XMLStorage.generateFolderEnd (sb, "table", " "); |
224 |
XMLStorage.generateFolderEnd (sb, "table", " "); |
207 |
XMLStorage.generateFolderEnd (sb, "body", " "); |
225 |
XMLStorage.generateFolderEnd (sb, "body", " "); |
Lines 217-227
Link Here
|
217 |
OutputStreamWriter writer = new OutputStreamWriter (outputStream); |
235 |
OutputStreamWriter writer = new OutputStreamWriter (outputStream); |
218 |
writer.write (sb.toString ()); |
236 |
writer.write (sb.toString ()); |
219 |
writer.close (); |
237 |
writer.close (); |
220 |
} catch (IOException ex) { |
238 |
|
|
|
239 |
if (fo.canRead()) { |
240 |
//open generated HTML in external browser |
241 |
HtmlBrowser.URLDisplayer.getDefault().showURLExternal(fo.toURL()); |
242 |
} |
243 |
|
244 |
} catch (IOException ex) { |
221 |
ErrorManager.getDefault ().notify (ex); |
245 |
ErrorManager.getDefault ().notify (ex); |
222 |
} finally { |
246 |
} finally { |
223 |
fileLock.releaseLock (); |
247 |
fileLock.releaseLock (); |
224 |
} |
248 |
} |
|
|
249 |
|
225 |
} catch (IOException ex) { |
250 |
} catch (IOException ex) { |
226 |
ErrorManager.getDefault ().notify (ex); |
251 |
ErrorManager.getDefault ().notify (ex); |
227 |
} |
252 |
} |
Lines 233-239
Link Here
|
233 |
private static void exportShortcutsToHTML2 ( |
258 |
private static void exportShortcutsToHTML2 ( |
234 |
KeymapModel keymapModel, |
259 |
KeymapModel keymapModel, |
235 |
StringBuffer sb, |
260 |
StringBuffer sb, |
236 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps |
261 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps, |
|
|
262 |
boolean displayHumanReadibleShortcuts |
237 |
) { |
263 |
) { |
238 |
List<String> categories = new ArrayList<String> (keymapModel.getActionCategories ()); |
264 |
List<String> categories = new ArrayList<String> (keymapModel.getActionCategories ()); |
239 |
Collections.<String>sort (categories); |
265 |
Collections.<String>sort (categories); |
Lines 253-259
Link Here
|
253 |
XMLStorage.generateFolderEnd (sb, "tr", " "); |
279 |
XMLStorage.generateFolderEnd (sb, "tr", " "); |
254 |
|
280 |
|
255 |
// print body of one category |
281 |
// print body of one category |
256 |
exportShortcutsToHTML3 (sb, keymapModel, category, keymaps); |
282 |
exportShortcutsToHTML3 (sb, keymapModel, category, keymaps, displayHumanReadibleShortcuts); |
257 |
} |
283 |
} |
258 |
} |
284 |
} |
259 |
|
285 |
|
Lines 264-270
Link Here
|
264 |
StringBuffer sb, |
290 |
StringBuffer sb, |
265 |
KeymapModel keymapModel, |
291 |
KeymapModel keymapModel, |
266 |
String category, |
292 |
String category, |
267 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps |
293 |
Map<String, Map<ShortcutAction, Set<String>>> keymaps, |
|
|
294 |
boolean displayHumanReadibleShortcuts |
268 |
) { |
295 |
) { |
269 |
Set<ShortcutAction> actions = keymapModel.getActions (category); |
296 |
Set<ShortcutAction> actions = keymapModel.getActions (category); |
270 |
|
297 |
|
Lines 294-300
Link Here
|
294 |
Set<String> shortcuts = keymap.get (action); |
321 |
Set<String> shortcuts = keymap.get (action); |
295 |
|
322 |
|
296 |
XMLStorage.generateFolderStart (sb, "td", attribs, " "); |
323 |
XMLStorage.generateFolderStart (sb, "td", attribs, " "); |
297 |
printShortcuts (shortcuts, sb); |
324 |
printShortcuts (shortcuts, sb, displayHumanReadibleShortcuts); |
298 |
XMLStorage.generateFolderEnd (sb, "td", " "); |
325 |
XMLStorage.generateFolderEnd (sb, "td", " "); |
299 |
} |
326 |
} |
300 |
|
327 |
|
Lines 302-308
Link Here
|
302 |
} |
329 |
} |
303 |
} |
330 |
} |
304 |
|
331 |
|
305 |
private static void printShortcuts (Set<String> shortcuts, StringBuffer sb) { |
332 |
private static void printShortcuts (Set<String> shortcuts, StringBuffer sb, boolean displayHumanReadibleShortcuts) { |
306 |
if (shortcuts == null) { |
333 |
if (shortcuts == null) { |
307 |
sb.append ('-'); |
334 |
sb.append ('-'); |
308 |
return; |
335 |
return; |
Lines 310-320
Link Here
|
310 |
Iterator<String> it = shortcuts.iterator (); |
337 |
Iterator<String> it = shortcuts.iterator (); |
311 |
while (it.hasNext ()) { |
338 |
while (it.hasNext ()) { |
312 |
String shortcut = it.next (); |
339 |
String shortcut = it.next (); |
313 |
sb.append (shortcut); |
340 |
if (displayHumanReadibleShortcuts) { |
|
|
341 |
//show system specific shortcuts like CTRL-SHIFT-ALT |
342 |
sb.append (portableRepresentationToShortcut(shortcut)); |
343 |
} else { |
344 |
//default: show portable shortcuts like D-O |
345 |
sb.append (shortcut); |
346 |
} |
314 |
if (it.hasNext ()) sb.append (", "); |
347 |
if (it.hasNext ()) sb.append (", "); |
315 |
} |
348 |
} |
316 |
} |
349 |
} |
317 |
|
350 |
|
|
|
351 |
/** |
352 |
* Copy from org.netbeans.modules.options.keymap.ProfilesPanel.portableRepresentationToShortcut(java.lang.String):java.lang.String |
353 |
* @param portable |
354 |
* @return |
355 |
*/ |
356 |
private static String portableRepresentationToShortcut(String portable) { |
357 |
assert portable != null : "The parameter must not be null"; //NOI18N |
358 |
|
359 |
StringBuilder buf = new StringBuilder(); |
360 |
String delimiter = " "; //NOI18N |
361 |
|
362 |
for(StringTokenizer st = new StringTokenizer(portable, delimiter); st.hasMoreTokens();) { //NOI18N |
363 |
String ks = st.nextToken().trim(); |
364 |
|
365 |
KeyStroke keyStroke = Utilities.stringToKey(ks); |
366 |
|
367 |
if (keyStroke != null) { |
368 |
buf.append(KeyStrokeUtils.getKeyStrokeAsText(keyStroke)); |
369 |
if (st.hasMoreTokens()) |
370 |
buf.append(' '); |
371 |
} else { |
372 |
return null; |
373 |
} |
374 |
} |
375 |
|
376 |
return buf.toString(); |
377 |
} |
378 |
|
318 |
private static void generateLayersXML ( |
379 |
private static void generateLayersXML ( |
319 |
LayersBridge layersBridge, |
380 |
LayersBridge layersBridge, |
320 |
Map<String, Map<String, ShortcutAction>> categoryToActions |
381 |
Map<String, Map<String, ShortcutAction>> categoryToActions |