|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
|
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
|
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice
|
|
4 |
// Sophia Antipolis, University of Paris 3.
|
|
5 |
//
|
|
6 |
// The TXM platform is free software: you can redistribute it
|
|
7 |
// and/or modify it under the terms of the GNU General Public
|
|
8 |
// License as published by the Free Software Foundation,
|
|
9 |
// either version 2 of the License, or (at your option) any
|
|
10 |
// later version.
|
|
11 |
//
|
|
12 |
// The TXM platform is distributed in the hope that it will be
|
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
15 |
// PURPOSE. See the GNU General Public License for more
|
|
16 |
// details.
|
|
17 |
//
|
|
18 |
// You should have received a copy of the GNU General
|
|
19 |
// Public License along with the TXM platform. If not, see
|
|
20 |
// http://www.gnu.org/licenses.
|
|
21 |
//
|
|
22 |
//
|
|
23 |
//
|
|
24 |
// $LastChangedDate:$
|
|
25 |
// $LastChangedRevision:$
|
|
26 |
// $LastChangedBy:$
|
|
27 |
//
|
|
28 |
package org.txm.rcp.commands.editor;
|
|
29 |
|
|
30 |
import java.math.BigInteger;
|
|
31 |
|
|
32 |
import javax.xml.bind.DatatypeConverter;
|
|
33 |
|
|
34 |
import org.eclipse.core.commands.AbstractHandler;
|
|
35 |
import org.eclipse.core.commands.ExecutionEvent;
|
|
36 |
import org.eclipse.core.commands.ExecutionException;
|
|
37 |
import org.eclipse.jface.dialogs.InputDialog;
|
|
38 |
import org.eclipse.jface.text.TextSelection;
|
|
39 |
import org.eclipse.jface.viewers.ISelection;
|
|
40 |
import org.eclipse.jface.window.Window;
|
|
41 |
import org.eclipse.swt.widgets.Shell;
|
|
42 |
import org.eclipse.ui.IWorkbenchPart;
|
|
43 |
import org.eclipse.ui.editors.text.IEncodingSupport;
|
|
44 |
import org.eclipse.ui.handlers.HandlerUtil;
|
|
45 |
import org.txm.core.messages.TXMCoreMessages;
|
|
46 |
import org.txm.rcp.editors.TxtEditor;
|
|
47 |
import org.txm.rcp.messages.TXMUIMessages;
|
|
48 |
import org.txm.rcp.utils.SWTUtils;
|
|
49 |
import org.txm.utils.logger.Log;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* @author mdecorde
|
|
53 |
* Change the encoding of the currently selected text editor
|
|
54 |
*/
|
|
55 |
public class PrintHexacode extends AbstractHandler {
|
|
56 |
|
|
57 |
/*
|
|
58 |
* (non-Javadoc)
|
|
59 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
|
60 |
*/
|
|
61 |
@Override
|
|
62 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
|
63 |
IWorkbenchPart page = HandlerUtil.getActiveWorkbenchWindow(event)
|
|
64 |
.getActivePage().getActivePart();
|
|
65 |
if (page != null && page instanceof TxtEditor) {
|
|
66 |
TxtEditor te = (TxtEditor) page;
|
|
67 |
printHexacode(te);
|
|
68 |
}
|
|
69 |
|
|
70 |
return null;
|
|
71 |
}
|
|
72 |
|
|
73 |
public static void printHexacode(TxtEditor te) {
|
|
74 |
try {
|
|
75 |
ISelection isel = te.getTextViewer().getSelection();
|
|
76 |
if (isel.isEmpty()) {
|
|
77 |
Log.info("no charracters selected.");
|
|
78 |
return;
|
|
79 |
}
|
|
80 |
|
|
81 |
if (isel instanceof TextSelection) {
|
|
82 |
TextSelection tsel = (TextSelection)isel;
|
|
83 |
String text = tsel.getText();
|
|
84 |
if (text.length() == 0) {
|
|
85 |
Log.info("no charracters selected.");
|
|
86 |
return;
|
|
87 |
}
|
|
88 |
|
|
89 |
for (int i = 0 ; i < text.length() ; i++) {
|
|
90 |
System.out.println("c="+text.charAt(i)+" x="+Integer.toHexString(text.charAt(i)) + " name="+Character.getName(text.charAt(i)));
|
|
91 |
}
|
|
92 |
}
|
|
93 |
}
|
|
94 |
catch (Exception e) {
|
|
95 |
org.txm.utils.logger.Log.printStackTrace(e);
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
0 |
99 |
|