11 |
11 |
import java.util.Set;
|
12 |
12 |
import java.util.logging.Level;
|
13 |
13 |
|
14 |
|
import org.eclipse.core.commands.Command;
|
15 |
|
import org.eclipse.core.commands.ExecutionException;
|
16 |
|
import org.eclipse.core.commands.IParameter;
|
17 |
|
import org.eclipse.core.commands.NotEnabledException;
|
18 |
|
import org.eclipse.core.commands.NotHandledException;
|
19 |
|
import org.eclipse.core.commands.Parameterization;
|
20 |
|
import org.eclipse.core.commands.ParameterizedCommand;
|
21 |
|
import org.eclipse.core.commands.common.NotDefinedException;
|
22 |
14 |
import org.eclipse.core.runtime.FileLocator;
|
23 |
15 |
import org.eclipse.core.runtime.Platform;
|
24 |
16 |
import org.eclipse.jface.action.MenuManager;
|
... | ... | |
28 |
20 |
import org.eclipse.jface.viewers.ISelectionProvider;
|
29 |
21 |
import org.eclipse.swt.SWT;
|
30 |
22 |
import org.eclipse.swt.browser.Browser;
|
31 |
|
import org.eclipse.swt.browser.BrowserFunction;
|
32 |
23 |
import org.eclipse.swt.browser.ProgressEvent;
|
33 |
24 |
import org.eclipse.swt.browser.ProgressListener;
|
34 |
25 |
import org.eclipse.swt.events.MenuEvent;
|
... | ... | |
38 |
29 |
import org.eclipse.swt.widgets.Composite;
|
39 |
30 |
import org.eclipse.swt.widgets.Menu;
|
40 |
31 |
import org.eclipse.swt.widgets.MenuItem;
|
41 |
|
import org.eclipse.ui.IWorkbenchWindow;
|
42 |
|
import org.eclipse.ui.PlatformUI;
|
43 |
|
import org.eclipse.ui.commands.ICommandService;
|
44 |
|
import org.eclipse.ui.handlers.IHandlerService;
|
45 |
32 |
import org.eclipse.ui.internal.browser.BrowserViewer;
|
46 |
33 |
import org.osgi.framework.Bundle;
|
47 |
|
import org.txm.concordance.rcp.actions.BackToText;
|
48 |
|
import org.txm.core.preferences.TXMPreferences;
|
49 |
34 |
import org.txm.edition.rcp.messages.EditionUIMessages;
|
50 |
|
import org.txm.edition.rcp.preferences.SynopticEditionPreferencePage;
|
51 |
35 |
import org.txm.edition.rcp.preferences.SynopticEditionPreferences;
|
52 |
36 |
import org.txm.objects.CorpusBuild;
|
53 |
37 |
import org.txm.objects.Edition;
|
... | ... | |
77 |
61 |
//HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color
|
78 |
62 |
|
79 |
63 |
HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>(); // background color
|
80 |
|
public static final String STYLE_NORMAL = "normal";
|
81 |
|
public static final String STYLE_ITALIC = "italic";
|
82 |
|
public static final String STYLE_OBLIQUE = "oblique";
|
|
64 |
public static final String STYLE_NORMAL = "normal"; //$NON-NLS-1$
|
|
65 |
public static final String STYLE_ITALIC = "italic"; //$NON-NLS-1$
|
|
66 |
public static final String STYLE_OBLIQUE = "oblique"; //$NON-NLS-1$
|
83 |
67 |
HashMap<String, String> fontStylePerWordIDS = new HashMap<String, String>();
|
84 |
|
public static final String WEIGHT_NORMAL = "normal";
|
85 |
|
public static final String WEIGHT_BOLD = "bold";
|
|
68 |
public static final String WEIGHT_NORMAL = "normal"; //$NON-NLS-1$
|
|
69 |
public static final String WEIGHT_BOLD = "bold"; //$NON-NLS-1$
|
86 |
70 |
HashMap<String, String> fontWeightPerWordIDS = new HashMap<String, String>();
|
87 |
71 |
HashMap<String, ArrayList<RGBA>> fontColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>();
|
88 |
|
public static final String SIZE_SMALL = "small";
|
89 |
|
public static final String SIZE_MEDIUM = "medium";
|
90 |
|
public static final String SIZE_LARGE = "larger";
|
91 |
|
public static final String SIZE_SMALLER = "smaller";
|
92 |
|
public static final String SIZE_LARGER = "larger";
|
|
72 |
public static final String SIZE_SMALL = "small"; //$NON-NLS-1$
|
|
73 |
public static final String SIZE_MEDIUM = "medium"; //$NON-NLS-1$
|
|
74 |
public static final String SIZE_LARGE = "larger"; //$NON-NLS-1$
|
|
75 |
public static final String SIZE_SMALLER = "smaller"; //$NON-NLS-1$
|
|
76 |
public static final String SIZE_LARGER = "larger"; //$NON-NLS-1$
|
93 |
77 |
HashMap<String, String> fontSizePerWordIDS = new HashMap<String, String>();
|
94 |
|
public static final String FAMILLY_TIMES = "\"Times New Roman\", Times";
|
95 |
|
public static final String FAMILLY_ARIAL = "Arial";
|
96 |
|
public static final String FAMILLY_COURIER = "\"Courier New\", Courier";
|
|
78 |
public static final String FAMILLY_TIMES = "\"Times New Roman\", Times"; //$NON-NLS-1$
|
|
79 |
public static final String FAMILLY_ARIAL = "Arial"; //$NON-NLS-1$
|
|
80 |
public static final String FAMILLY_COURIER = "\"Courier New\", Courier"; //$NON-NLS-1$
|
97 |
81 |
HashMap<String, String> fontFamillyPerWordIDS = new HashMap<String, String>();
|
98 |
|
public static final String VARIANT_NORMAL = "normal";
|
99 |
|
public static final String VARIANT_SMALLCAPS = "small-caps";
|
|
82 |
public static final String VARIANT_NORMAL = "normal"; //$NON-NLS-1$
|
|
83 |
public static final String VARIANT_SMALLCAPS = "small-caps"; //$NON-NLS-1$
|
100 |
84 |
HashMap<String, String> fontVariantPerWordIDS = new HashMap<String, String>();
|
101 |
85 |
String focusedWordID = null;
|
102 |
86 |
|
... | ... | |
107 |
91 |
//"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
108 |
92 |
//"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
109 |
93 |
"} catch (e) { };"; //$NON-NLS-1$
|
110 |
|
public static final String highlightscriptRuleFast = "sheet.insertRule(\"#%s {background-color:rgba(%s,%s,%s,%s);}\", 0);";
|
111 |
|
public static final String colorscriptRuleFast = "sheet.insertRule(\"#%s {color:rgba(%s,%s,%s,%s);}\", 0);";
|
112 |
|
public static final String sizescriptRuleFast = "sheet.insertRule(\"#%s {font-size:%s;}\", 0);";
|
113 |
|
public static final String stylescriptRuleFast = "sheet.insertRule(\"#%s {font-style:%s;}\", 0);";
|
114 |
|
public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);";
|
115 |
|
public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);";
|
116 |
|
public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);";
|
|
94 |
public static final String highlightscriptRuleFast = "sheet.insertRule(\"#%s {background-color:rgba(%s,%s,%s,%s);}\", 0);"; //$NON-NLS-1$
|
|
95 |
public static final String colorscriptRuleFast = "sheet.insertRule(\"#%s {color:rgba(%s,%s,%s,%s);}\", 0);"; //$NON-NLS-1$
|
|
96 |
public static final String sizescriptRuleFast = "sheet.insertRule(\"#%s {font-size:%s;}\", 0);"; //$NON-NLS-1$
|
|
97 |
public static final String stylescriptRuleFast = "sheet.insertRule(\"#%s {font-style:%s;}\", 0);"; //$NON-NLS-1$
|
|
98 |
public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);"; //$NON-NLS-1$
|
|
99 |
public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);"; //$NON-NLS-1$
|
|
100 |
public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);"; //$NON-NLS-1$
|
117 |
101 |
|
118 |
|
public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);";
|
|
102 |
public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);"; //$NON-NLS-1$
|
119 |
103 |
|
120 |
104 |
public static final String clearhighlightscript = "try { var elt = document.getElementById(\"%s\"); elt.style.backgroundColor=\"white\";elt.style.fontWeight=\"\";" + //$NON-NLS-1$
|
121 |
105 |
"} catch (e) { };"; //$NON-NLS-1$
|
122 |
106 |
|
123 |
107 |
public String functions =
|
124 |
|
""//"alert(\"loading functions\");"
|
125 |
|
+"\nfunction getNodeText(node) {"
|
126 |
|
+"\n if (typeof node == 'string') return node;"
|
127 |
|
+"\n else if (typeof node.innerText != 'undefined') return node.innerText;"
|
128 |
|
+"\n else if (typeof node.InnerText != 'undefined') return node.InnerText;"
|
129 |
|
+"\n else if (typeof node.textContent != 'undefined') return node.textContent;"
|
130 |
|
+"\n else return null;"
|
131 |
|
+"\n}"
|
132 |
|
+"\nfunction txmGetParent(node) {"
|
133 |
|
+"\n if (typeof node.parentNode != 'undefined') return node.parentNode;"
|
134 |
|
+"\n else return null;"
|
135 |
|
+"\n}"
|
136 |
|
+"\nfunction txmGetChildren(node) {"
|
137 |
|
+"\n if (typeof node == 'string') return 'STRING HTML';"
|
138 |
|
+"\n else if (typeof node.children != 'undefined') return node.children;"
|
139 |
|
+"\n else if (typeof node.ChildNodes != 'undefined') return node.ChildNodes;"
|
140 |
|
+"\n else if (typeof node.childNodes != 'undefined') return node.childNodes;"
|
141 |
|
+"\n else return null;"
|
142 |
|
+"\n}"
|
143 |
|
+"\nfunction txmGetSelection() {"
|
144 |
|
+"\n if (typeof window.getSelection != 'undefined') {return window.getSelection();}"
|
145 |
|
+"\n else if (typeof document.selection != 'undefined') { return document.selection;}"
|
146 |
|
+"\n else return 'NO SELECTION';"
|
147 |
|
+"\n}"
|
148 |
|
+"\nfunction txmGetRangeSize(selection) {"
|
149 |
|
+"\n if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}"
|
150 |
|
+"\n else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection"
|
151 |
|
+"\n}"
|
152 |
|
+"\nfunction txmGetRange(selection, i) {"
|
153 |
|
+"\n if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}"
|
154 |
|
+"\n else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5
|
155 |
|
+"\n else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection"
|
156 |
|
+"\n else return 'NO RANGE';"
|
157 |
|
+"\n}"
|
158 |
|
+"\nfunction txmGetParentElementRange(range) {"
|
159 |
|
+"\n if (typeof range.parentElement != 'undefined') {return range.parentElement();}"
|
160 |
|
+"\n else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}"
|
161 |
|
+"\n else return 'NO PARENT';"
|
162 |
|
+"\n}"
|
163 |
|
+"\nfunction txmGetFragment(range) {"
|
164 |
|
+"\n if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}"
|
165 |
|
+"\n else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; return node;"
|
166 |
|
+"\n } else return 'NO FRAG';"
|
167 |
|
+"\n}"
|
168 |
|
+"\nfunction txmGetTagName(node) {"
|
169 |
|
+"\n if (typeof node.tagName != 'undefined') {return node.tagName;}"
|
170 |
|
+"\n else if (typeof node.nodeName != 'undefined') { return node.nodeName;}"
|
171 |
|
+"\n else if (typeof node.name != 'undefined') { return node.name;}"
|
172 |
|
+"\n else return 'NO TAGNAME';"
|
173 |
|
+"\n}"
|
174 |
|
+"\nfunction findSpans(children, all) {"
|
175 |
|
+"\n for (var i = 0 ; i < children.length ; i++) {"
|
176 |
|
+"\n var node = children.item(i);"
|
177 |
|
+"\n if (node.nodeType == 1) {"
|
178 |
|
+"\n var id = node.getAttribute('id');"
|
179 |
|
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {"
|
180 |
|
+"\n if (id != null) all.push(id);"
|
181 |
|
+"\n } else {"
|
182 |
|
+"\n findSpans(txmGetChildren(node), all)"
|
183 |
|
+"\n }"
|
184 |
|
+"\n }"
|
185 |
|
+"\n }"
|
186 |
|
+"\n}"
|
187 |
|
+"\nfunction findIdsInString(str, all) {"
|
188 |
|
+"\n for (var i = 0 ; i < children.length ; i++) {"
|
189 |
|
+"\n var node = children.item(i);"
|
190 |
|
+"\n if (node.nodeType == 1) {"
|
191 |
|
+"\n var id = node.getAttribute('id');"
|
192 |
|
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {"
|
193 |
|
+"\n if (id != null) all.push(id);"
|
194 |
|
+"\n } else {"
|
195 |
|
+"\n findSpans(txmGetChildren(node), all)"
|
196 |
|
+"\n }"
|
197 |
|
+"\n }"
|
198 |
|
+"\n }"
|
199 |
|
+"\n}"
|
200 |
|
+"\nfunction get_type(thing){if(thing===null)return \"[object Null]\"; return Object.prototype.toString.call(thing);}\n"
|
201 |
|
+"\nfunction getDetailedObject(inputObject) { var detailedObject = {}; var properties; \n do { properties = Object.getOwnPropertyNames( inputObject ); for (var o in properties) {detailedObject[properties[o]] = inputObject[properties[o]];}} while ( inputObject = Object.getPrototypeOf(inputObject) );return detailedObject;}\n"
|
202 |
|
+"\nvar sheet = null;"
|
203 |
|
+"\ntry{"
|
204 |
|
+"\n var style = document.createElement(\"style\");"
|
205 |
|
+"\n style.appendChild(document.createTextNode(\"\"));"//webkit hack
|
206 |
|
+"\n document.head.appendChild(style);"
|
207 |
|
+"\n sheet = style.sheet;"
|
208 |
|
+"\n} catch(e) {sheet='error'}"
|
209 |
|
+"\ntry{"
|
210 |
|
+"\n" // define scrollIntoViewIfNeeded if absent
|
211 |
|
+"\nif (!Element.prototype.scrollIntoViewIfNeeded) {"
|
212 |
|
+"\n Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {"
|
213 |
|
+"\n centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;"
|
214 |
|
+"\n var parent = this.parentNode,"
|
215 |
|
+"\n parentComputedStyle = window.getComputedStyle(parent, null),"
|
216 |
|
+"\n parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width')),"
|
217 |
|
+"\n parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width')),"
|
218 |
|
+"\n overTop = this.offsetTop - parent.offsetTop < parent.scrollTop,"
|
219 |
|
+"\n overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight),"
|
220 |
|
+"\n overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft,"
|
221 |
|
+"\n overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth),"
|
222 |
|
+"\n alignWithTop = overTop && !overBottom;"
|
223 |
|
+"\n if ((overTop || overBottom) && centerIfNeeded) {"
|
224 |
|
+"\n parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;"
|
225 |
|
+"\n }"
|
226 |
|
+"\n if ((overLeft || overRight) && centerIfNeeded) {"
|
227 |
|
+"\n parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;"
|
228 |
|
+"\n }"
|
229 |
|
+"\n if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {"
|
230 |
|
+"\n this.scrollIntoView(alignWithTop);"
|
231 |
|
+"\n }"
|
232 |
|
+"\n };"
|
233 |
|
+"\n}"
|
234 |
|
+"\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}";
|
|
108 |
""//"alert(\"loading functions\");" //$NON-NLS-1$
|
|
109 |
+"\nfunction getNodeText(node) {" //$NON-NLS-1$
|
|
110 |
+"\n if (typeof node == 'string') return node;" //$NON-NLS-1$
|
|
111 |
+"\n else if (typeof node.innerText != 'undefined') return node.innerText;" //$NON-NLS-1$
|
|
112 |
+"\n else if (typeof node.InnerText != 'undefined') return node.InnerText;" //$NON-NLS-1$
|
|
113 |
+"\n else if (typeof node.textContent != 'undefined') return node.textContent;" //$NON-NLS-1$
|
|
114 |
+"\n else return null;" //$NON-NLS-1$
|
|
115 |
+"\n}" //$NON-NLS-1$
|
|
116 |
+"\nfunction txmGetParent(node) {" //$NON-NLS-1$
|
|
117 |
+"\n if (typeof node.parentNode != 'undefined') return node.parentNode;" //$NON-NLS-1$
|
|
118 |
+"\n else return null;" //$NON-NLS-1$
|
|
119 |
+"\n}" //$NON-NLS-1$
|
|
120 |
+"\nfunction txmGetChildren(node) {" //$NON-NLS-1$
|
|
121 |
+"\n if (typeof node == 'string') return 'STRING HTML';" //$NON-NLS-1$
|
|
122 |
+"\n else if (typeof node.children != 'undefined') return node.children;" //$NON-NLS-1$
|
|
123 |
+"\n else if (typeof node.ChildNodes != 'undefined') return node.ChildNodes;" //$NON-NLS-1$
|
|
124 |
+"\n else if (typeof node.childNodes != 'undefined') return node.childNodes;" //$NON-NLS-1$
|
|
125 |
+"\n else return null;" //$NON-NLS-1$
|
|
126 |
+"\n}" //$NON-NLS-1$
|
|
127 |
+"\nfunction txmGetSelection() {" //$NON-NLS-1$
|
|
128 |
+"\n if (typeof window.getSelection != 'undefined') {return window.getSelection();}" //$NON-NLS-1$
|
|
129 |
+"\n else if (typeof document.selection != 'undefined') { return document.selection;}" //$NON-NLS-1$
|
|
130 |
+"\n else return 'NO SELECTION';" //$NON-NLS-1$
|
|
131 |
+"\n}" //$NON-NLS-1$
|
|
132 |
+"\nfunction txmGetRangeSize(selection) {" //$NON-NLS-1$
|
|
133 |
+"\n if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}" //$NON-NLS-1$
|
|
134 |
+"\n else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection" //$NON-NLS-1$
|
|
135 |
+"\n}" //$NON-NLS-1$
|
|
136 |
+"\nfunction txmGetRange(selection, i) {" //$NON-NLS-1$
|
|
137 |
+"\n if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}" //$NON-NLS-1$
|
|
138 |
+"\n else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5 //$NON-NLS-1$
|
|
139 |
+"\n else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection" //$NON-NLS-1$
|
|
140 |
+"\n else return 'NO RANGE';" //$NON-NLS-1$
|
|
141 |
+"\n}" //$NON-NLS-1$
|
|
142 |
+"\nfunction txmGetParentElementRange(range) {" //$NON-NLS-1$
|
|
143 |
+"\n if (typeof range.parentElement != 'undefined') {return range.parentElement();}" //$NON-NLS-1$
|
|
144 |
+"\n else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}" //$NON-NLS-1$
|
|
145 |
+"\n else return 'NO PARENT';" //$NON-NLS-1$
|
|
146 |
+"\n}" //$NON-NLS-1$
|
|
147 |
+"\nfunction txmGetFragment(range) {" //$NON-NLS-1$
|
|
148 |
+"\n if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}" //$NON-NLS-1$
|
|
149 |
+"\n else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; return node;" //$NON-NLS-1$
|
|
150 |
+"\n } else return 'NO FRAG';" //$NON-NLS-1$
|
|
151 |
+"\n}" //$NON-NLS-1$
|
|
152 |
+"\nfunction txmGetTagName(node) {" //$NON-NLS-1$
|
|
153 |
+"\n if (typeof node.tagName != 'undefined') {return node.tagName;}" //$NON-NLS-1$
|
|
154 |
+"\n else if (typeof node.nodeName != 'undefined') { return node.nodeName;}" //$NON-NLS-1$
|
|
155 |
+"\n else if (typeof node.name != 'undefined') { return node.name;}" //$NON-NLS-1$
|
|
156 |
+"\n else return 'NO TAGNAME';" //$NON-NLS-1$
|
|
157 |
+"\n}" //$NON-NLS-1$
|
|
158 |
+"\nfunction findSpans(children, all) {" //$NON-NLS-1$
|
|
159 |
+"\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
|
160 |
+"\n var node = children.item(i);" //$NON-NLS-1$
|
|
161 |
+"\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
|
162 |
+"\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
|
163 |
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
|
164 |
+"\n if (id != null) all.push(id);" //$NON-NLS-1$
|
|
165 |
+"\n } else {" //$NON-NLS-1$
|
|
166 |
+"\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
|
167 |
+"\n }" //$NON-NLS-1$
|
|
168 |
+"\n }" //$NON-NLS-1$
|
|
169 |
+"\n }" //$NON-NLS-1$
|
|
170 |
+"\n}" //$NON-NLS-1$
|
|
171 |
+"\nfunction findIdsInString(str, all) {" //$NON-NLS-1$
|
|
172 |
+"\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
|
173 |
+"\n var node = children.item(i);" //$NON-NLS-1$
|
|
174 |
+"\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
|
175 |
+"\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
|
176 |
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
|
177 |
+"\n if (id != null) all.push(id);" //$NON-NLS-1$
|
|
178 |
+"\n } else {" //$NON-NLS-1$
|
|
179 |
+"\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
|
180 |
+"\n }" //$NON-NLS-1$
|
|
181 |
+"\n }" //$NON-NLS-1$
|
|
182 |
+"\n }" //$NON-NLS-1$
|
|
183 |
+"\n}" //$NON-NLS-1$
|
|
184 |
+"\nfunction get_type(thing){if(thing===null)return \"[object Null]\"; return Object.prototype.toString.call(thing);}\n" //$NON-NLS-1$
|
|
185 |
+"\nfunction getDetailedObject(inputObject) { var detailedObject = {}; var properties; \n do { properties = Object.getOwnPropertyNames( inputObject ); for (var o in properties) {detailedObject[properties[o]] = inputObject[properties[o]];}} while ( inputObject = Object.getPrototypeOf(inputObject) );return detailedObject;}\n" //$NON-NLS-1$
|
|
186 |
+"\nvar sheet = null;" //$NON-NLS-1$
|
|
187 |
+"\ntry{" //$NON-NLS-1$
|
|
188 |
+"\n var style = document.createElement(\"style\");" //$NON-NLS-1$
|
|
189 |
+"\n style.appendChild(document.createTextNode(\"\"));"//webkit hack //$NON-NLS-1$
|
|
190 |
+"\n document.head.appendChild(style);" //$NON-NLS-1$
|
|
191 |
+"\n sheet = style.sheet;" //$NON-NLS-1$
|
|
192 |
+"\n} catch(e) {sheet='error'}" //$NON-NLS-1$
|
|
193 |
+"\ntry{" //$NON-NLS-1$
|
|
194 |
+"\n" // define scrollIntoViewIfNeeded if absent //$NON-NLS-1$
|
|
195 |
+"\nif (!Element.prototype.scrollIntoViewIfNeeded) {" //$NON-NLS-1$
|
|
196 |
+"\n Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {" //$NON-NLS-1$
|
|
197 |
+"\n centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;" //$NON-NLS-1$
|
|
198 |
+"\n var parent = this.parentNode," //$NON-NLS-1$
|
|
199 |
+"\n parentComputedStyle = window.getComputedStyle(parent, null)," //$NON-NLS-1$
|
|
200 |
+"\n parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'))," //$NON-NLS-1$
|
|
201 |
+"\n parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'))," //$NON-NLS-1$
|
|
202 |
+"\n overTop = this.offsetTop - parent.offsetTop < parent.scrollTop," //$NON-NLS-1$
|
|
203 |
+"\n overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight)," //$NON-NLS-1$
|
|
204 |
+"\n overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft," //$NON-NLS-1$
|
|
205 |
+"\n overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth)," //$NON-NLS-1$
|
|
206 |
+"\n alignWithTop = overTop && !overBottom;" //$NON-NLS-1$
|
|
207 |
+"\n if ((overTop || overBottom) && centerIfNeeded) {" //$NON-NLS-1$
|
|
208 |
+"\n parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;" //$NON-NLS-1$
|
|
209 |
+"\n }" //$NON-NLS-1$
|
|
210 |
+"\n if ((overLeft || overRight) && centerIfNeeded) {" //$NON-NLS-1$
|
|
211 |
+"\n parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;" //$NON-NLS-1$
|
|
212 |
+"\n }" //$NON-NLS-1$
|
|
213 |
+"\n if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {" //$NON-NLS-1$
|
|
214 |
+"\n this.scrollIntoView(alignWithTop);" //$NON-NLS-1$
|
|
215 |
+"\n }" //$NON-NLS-1$
|
|
216 |
+"\n };" //$NON-NLS-1$
|
|
217 |
+"\n}" //$NON-NLS-1$
|
|
218 |
+"\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}"; //$NON-NLS-1$
|
235 |
219 |
protected boolean fastWordHighLight = SynopticEditionPreferences.getInstance().getBoolean(SynopticEditionPreferences.FAST_HIGHLIGHT);
|
236 |
220 |
private ArrayList<ProgressListener> beforeHighlighListeners;
|
237 |
221 |
public ArrayList<ProgressListener> getBeforeHighlighListeners() {
|
... | ... | |
258 |
242 |
File functionsFile = null;
|
259 |
243 |
try {
|
260 |
244 |
|
261 |
|
Bundle bundle = Platform.getBundle("org.txm.edition.rcp");
|
262 |
|
URL fileURL = bundle.getEntry("res/js/functions.js");
|
|
245 |
Bundle bundle = Platform.getBundle("org.txm.edition.rcp"); //$NON-NLS-1$
|
|
246 |
URL fileURL = bundle.getEntry("res/js/functions.js"); //$NON-NLS-1$
|
263 |
247 |
URL r = FileLocator.resolve(fileURL);
|
264 |
248 |
Log.info("Load JS functions from: "+r);
|
265 |
|
functions = IOUtils.getText(r, "UTF-8");
|
|
249 |
functions = IOUtils.getText(r, "UTF-8"); //$NON-NLS-1$
|
266 |
250 |
|
267 |
251 |
} catch (Exception e) {
|
268 |
|
System.out.println("Error while reading "+functionsFile+": "+e.getLocalizedMessage());
|
|
252 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.error_while_reading, functionsFile, e.getLocalizedMessage()));
|
269 |
253 |
Log.printStackTrace(e);
|
270 |
254 |
}
|
271 |
255 |
|
... | ... | |
281 |
265 |
public void completed(ProgressEvent event) {
|
282 |
266 |
|
283 |
267 |
// System.out.println("EditionPanel "+currentEdition.getName()+" reload "+getCurrentPage().getName());
|
284 |
|
Object rez = evaluate("return typeof sheet");
|
285 |
|
if ("undefined".equals(rez)) execute(functions); // build the sheet if not present in the HTML DOM
|
|
268 |
Object rez = evaluate("return typeof sheet"); //$NON-NLS-1$
|
|
269 |
if ("undefined".equals(rez)) execute(functions); // build the sheet if not present in the HTML DOM //$NON-NLS-1$
|
286 |
270 |
|
287 |
271 |
// do something before the highlight is done
|
288 |
272 |
for (ProgressListener pl : beforeHighlighListeners) { pl.completed(event);}
|
... | ... | |
295 |
279 |
// buffer.append(String.format(clearhighlightscript, wordid)+"\n");
|
296 |
280 |
// }
|
297 |
281 |
} else {
|
298 |
|
buffer.append("try { while(sheet.cssRules.length > 0) sheet.deleteRule(0); } catch (e) {};\n"); // empty style
|
|
282 |
buffer.append("try { while(sheet.cssRules.length > 0) sheet.deleteRule(0); } catch (e) {};\n"); // empty style //$NON-NLS-1$
|
299 |
283 |
}
|
300 |
284 |
|
301 |
285 |
if (buffer.length() > 0) execute(buffer.toString());
|
... | ... | |
303 |
287 |
|
304 |
288 |
String firstWord = currentPage.getWordId();
|
305 |
289 |
Page nextPage = currentEdition.getNextPage(currentPage);
|
306 |
|
String lastWord = "w_999999999";
|
|
290 |
String lastWord = "w_999999999"; //$NON-NLS-1$
|
307 |
291 |
if (nextPage != null && currentPage != nextPage) lastWord = nextPage.getWordId();
|
308 |
292 |
//System.out.println("firstWord="+firstWord+" lastWord="+lastWord);
|
309 |
293 |
//int n = 0;
|
... | ... | |
334 |
318 |
String s = null;
|
335 |
319 |
if (!fastWordHighLight) {
|
336 |
320 |
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
337 |
|
s = "try { document.getElementById(\"" + wordid + "\").style.backgroundColor=\"rgba("+composite.r+","+composite.g+","+composite.b+","+composite.a+")\";" //$NON-NLS-1$
|
|
321 |
s = "try { document.getElementById(\"" + wordid + "\").style.backgroundColor=\"rgba("+composite.r+","+composite.g+","+composite.b+","+composite.a+")\";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
338 |
322 |
+
|
339 |
323 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
340 |
324 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
... | ... | |
343 |
327 |
"} catch (e) { };"; //$NON-NLS-1$
|
344 |
328 |
} else {
|
345 |
329 |
//TODO: replace this line with the next one for TXM 0.7.9
|
346 |
|
s = String.format(highlightscriptRuleFast, wordid.replace(" ", "\\ "), composite.r, composite.g, composite.b, composite.a);
|
|
330 |
s = String.format(highlightscriptRuleFast, wordid.replace(" ", "\\ "), composite.r, composite.g, composite.b, composite.a); //$NON-NLS-1$ //$NON-NLS-2$
|
347 |
331 |
// s = String.format(highlightscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
348 |
332 |
}
|
349 |
333 |
|
350 |
|
buffer.append(s+"\n");
|
|
334 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
351 |
335 |
}
|
352 |
336 |
|
353 |
337 |
if (buffer.length() > 0) execute(buffer.toString());
|
... | ... | |
389 |
373 |
composite.b /= size;
|
390 |
374 |
|
391 |
375 |
String s = String.format(colorscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
392 |
|
buffer.append(s+"\n");
|
|
376 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
393 |
377 |
}
|
394 |
378 |
|
395 |
379 |
if (buffer.length() > 0) execute(buffer.toString());
|
... | ... | |
397 |
381 |
|
398 |
382 |
for (String wordid : fontSizePerWordIDS.keySet()) {
|
399 |
383 |
String s = String.format(sizescriptRuleFast, wordid, fontSizePerWordIDS.get(wordid));
|
400 |
|
buffer.append(s+"\n");
|
|
384 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
401 |
385 |
}
|
402 |
386 |
|
403 |
387 |
for (String wordid : fontWeightPerWordIDS.keySet()) {
|
404 |
388 |
String s = null;
|
405 |
389 |
if (!fastWordHighLight) {
|
406 |
390 |
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
407 |
|
s = "try { document.getElementById(\"" + wordid + "\").style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" //$NON-NLS-1$
|
|
391 |
s = "try { document.getElementById(\"" + wordid + "\").style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
408 |
392 |
+
|
409 |
393 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
410 |
394 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
... | ... | |
422 |
406 |
} else {
|
423 |
407 |
s = String.format(weightscriptRuleFast, wordid, fontWeightPerWordIDS.get(wordid));
|
424 |
408 |
}
|
425 |
|
buffer.append(s+"\n");
|
|
409 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
426 |
410 |
}
|
427 |
411 |
|
428 |
412 |
for (String wordid : fontFamillyPerWordIDS.keySet()) {
|
429 |
413 |
String s = String.format(famillyscriptRuleFast, wordid, fontFamillyPerWordIDS.get(wordid));
|
430 |
|
buffer.append(s+"\n");
|
|
414 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
431 |
415 |
}
|
432 |
416 |
|
433 |
417 |
if (buffer.length() > 0) execute(buffer.toString());
|
... | ... | |
435 |
419 |
|
436 |
420 |
if (focusedWordID != null) {
|
437 |
421 |
//System.out.println("Focus on: "+focusedWordID);
|
438 |
|
String s = "try { showElementIfNeeded(document.getElementById(\"" + focusedWordID + "\")); } catch (e) {document.getElementById(\"" + focusedWordID + "\").scrollIntoView();};"; //$NON-NLS-1$ //$NON-NLS-2$
|
439 |
|
buffer.append(s+"\n");
|
|
422 |
String s = "try { showElementIfNeeded(document.getElementById(\"" + focusedWordID + "\")); } catch (e) {document.getElementById(\"" + focusedWordID + "\").scrollIntoView();};"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
423 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
440 |
424 |
focusedWordID = null; // focus one time
|
441 |
425 |
}
|
442 |
426 |
|
... | ... | |
444 |
428 |
buffer = new StringBuilder();
|
445 |
429 |
|
446 |
430 |
if (highlightedAreas != null) {
|
447 |
|
for (int[] pos : highlightedAreas ) {
|
|
431 |
for (int[] pos : highlightedAreas) {
|
448 |
432 |
if (pos == null || pos.length != 4) continue;
|
449 |
|
String s = "try {v.setFocusOn("+pos[0]+", "+pos[1]+", "+pos[2]+", "+pos[3]+");} catch (e) { };"; //$NON-NLS-1$
|
450 |
|
buffer.append(s+"\n");
|
|
433 |
String s = "try {v.setFocusOn("+pos[0]+", "+pos[1]+", "+pos[2]+", "+pos[3]+");} catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
|
434 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
451 |
435 |
break;// one word only for now
|
452 |
436 |
}
|
453 |
437 |
}
|
... | ... | |
476 |
460 |
* Bypass BrowserViewer restriction on the getBrowser method
|
477 |
461 |
*/
|
478 |
462 |
public String getDOM() {
|
479 |
|
return "";//execute("return document.innerHTML";
|
|
463 |
return "";//execute("return document.innerHTML"; //$NON-NLS-1$
|
480 |
464 |
}
|
481 |
465 |
|
482 |
466 |
public ISelectionProvider getSelectionProvider() {
|
... | ... | |
520 |
504 |
for (String wordid : wordids) {
|
521 |
505 |
removeHighlightWordsById(color, wordid);
|
522 |
506 |
if (!fastWordHighLight) {
|
523 |
|
buffer.append(String.format(clearhighlightscript, wordid)+"\n");
|
|
507 |
buffer.append(String.format(clearhighlightscript, wordid)+"\n"); //$NON-NLS-1$
|
524 |
508 |
}
|
525 |
509 |
}
|
526 |
510 |
|
... | ... | |
549 |
533 |
Edition edition = text.getEdition(name);
|
550 |
534 |
|
551 |
535 |
if (edition == null) {
|
552 |
|
String s = EditionUIMessages.EditionPanel_0+text+EditionUIMessages.EditionPanel_5+name;
|
|
536 |
String s = EditionUIMessages.bind(EditionUIMessages.warning_no_edition_found, text, name);
|
553 |
537 |
System.out.println(s);
|
554 |
538 |
StatusLine.setMessage(s);
|
555 |
539 |
Log.severe(s);
|
... | ... | |
577 |
561 |
currentPage = currentEdition.getFirstPage();
|
578 |
562 |
currentText = currentEdition.getText();
|
579 |
563 |
if (currentPage == null) {
|
580 |
|
System.out.println(EditionUIMessages.EditionPanel_1+currentEdition.getName()+EditionUIMessages.EditionPanel_2+currentText.getName());
|
|
564 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_no_first_page, currentEdition.getName(), currentText.getName()));
|
581 |
565 |
}
|
582 |
566 |
|
583 |
567 |
this.setURL(currentPage.toURL());
|
... | ... | |
656 |
640 |
String editionName = currentEdition.getName();
|
657 |
641 |
Edition tmp = firstText.getEdition(editionName);
|
658 |
642 |
if (tmp == null) {
|
659 |
|
System.out.println(EditionUIMessages.EditionPanel_6+editionName+EditionUIMessages.EditionPanel_7+firstText.getName());
|
|
643 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_no_edition_with_name, editionName, firstText.getName()));
|
660 |
644 |
return;
|
661 |
645 |
}
|
662 |
646 |
currentEdition = tmp;
|
... | ... | |
682 |
666 |
String editionName = currentEdition.getName();
|
683 |
667 |
Edition tmp = lastText.getEdition(editionName);
|
684 |
668 |
if (tmp == null) {
|
685 |
|
System.out.println(EditionUIMessages.EditionPanel_6+editionName+EditionUIMessages.EditionPanel_7+lastText.getName());
|
|
669 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_no_edition_with_name, editionName, lastText.getName()));
|
686 |
670 |
return;
|
687 |
671 |
}
|
688 |
672 |
|
... | ... | |
715 |
699 |
|
716 |
700 |
Edition tmp = previousText.getEdition(editionName);
|
717 |
701 |
if (tmp == null) {
|
718 |
|
System.out.println(EditionUIMessages.EditionPanel_6+editionName+EditionUIMessages.EditionPanel_7+previousText.getName());
|
|
702 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_no_edition_with_name, editionName, previousText.getName()));
|
719 |
703 |
}
|
720 |
704 |
currentEdition = tmp;
|
721 |
705 |
currentText = previousText;
|
... | ... | |
746 |
730 |
String editionName = currentEdition.getName();
|
747 |
731 |
Edition tmp = nextText.getEdition(editionName);
|
748 |
732 |
if (tmp == null) {
|
749 |
|
System.out.println(EditionUIMessages.EditionPanel_6+editionName+EditionUIMessages.EditionPanel_7+nextText.getName());
|
|
733 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_no_edition_with_name, editionName, nextText.getName()));
|
750 |
734 |
return;
|
751 |
735 |
}
|
752 |
736 |
currentEdition = tmp;
|
... | ... | |
769 |
753 |
String editionName = currentEdition.getName();
|
770 |
754 |
Edition tmp = text.getEdition(editionName);
|
771 |
755 |
if (tmp == null) {
|
772 |
|
System.out.println(EditionUIMessages.EditionPanel_6+editionName+EditionUIMessages.EditionPanel_7+text.getName());
|
|
756 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_no_edition_with_name, editionName, text.getName()));
|
773 |
757 |
return;
|
774 |
758 |
}
|
775 |
759 |
|
... | ... | |
841 |
825 |
// this.currentEdition = edition;
|
842 |
826 |
// }
|
843 |
827 |
|
844 |
|
static String SCRIPT01 = "var html = \"\";"+
|
845 |
|
"if (typeof window.getSelection != \"undefined\") {"+ // modern Web browsers
|
846 |
|
"var sel = window.getSelection();"+
|
847 |
|
"if (sel.rangeCount) {"+
|
848 |
|
"var container = document.createElement(\"div\");"+
|
849 |
|
"for (var i = 0, len = sel.rangeCount; i < len; ++i) {"+
|
850 |
|
"container.appendChild(sel.getRangeAt(i).cloneContents());"+
|
851 |
|
"}"+
|
852 |
|
"html = container.innerHTML;"+
|
853 |
|
"}"+
|
854 |
|
"} else if (typeof document.selection != \"undefined\") {"+ // for IE < 11
|
855 |
|
"if (document.selection.type == \"Text\") {"+
|
856 |
|
"html = document.selection.createRange().htmlText;"+
|
857 |
|
"}" +
|
858 |
|
"}" +
|
859 |
|
"return html";
|
|
828 |
static String SCRIPT01 = "var html = \"\";"+ //$NON-NLS-1$
|
|
829 |
"if (typeof window.getSelection != \"undefined\") {"+ // modern Web browsers //$NON-NLS-1$
|
|
830 |
"var sel = window.getSelection();"+ //$NON-NLS-1$
|
|
831 |
"if (sel.rangeCount) {"+ //$NON-NLS-1$
|
|
832 |
"var container = document.createElement(\"div\");"+ //$NON-NLS-1$
|
|
833 |
"for (var i = 0, len = sel.rangeCount; i < len; ++i) {"+ //$NON-NLS-1$
|
|
834 |
"container.appendChild(sel.getRangeAt(i).cloneContents());"+ //$NON-NLS-1$
|
|
835 |
"}"+ //$NON-NLS-1$
|
|
836 |
"html = container.innerHTML;"+ //$NON-NLS-1$
|
|
837 |
"}"+ //$NON-NLS-1$
|
|
838 |
"} else if (typeof document.selection != \"undefined\") {"+ // for IE < 11 //$NON-NLS-1$
|
|
839 |
"if (document.selection.type == \"Text\") {"+ //$NON-NLS-1$
|
|
840 |
"html = document.selection.createRange().htmlText;"+ //$NON-NLS-1$
|
|
841 |
"}" + //$NON-NLS-1$
|
|
842 |
"}" + //$NON-NLS-1$
|
|
843 |
"return html"; //$NON-NLS-1$
|
860 |
844 |
|
861 |
845 |
public String getTextSelectionDOM() {
|
862 |
846 |
return ((String) evaluate(SCRIPT01));
|
... | ... | |
865 |
849 |
public String[] getWordSelection() {
|
866 |
850 |
|
867 |
851 |
//System.out.println("getWordSelection");
|
868 |
|
String SCRIPT02_getspans = ""//functions
|
869 |
|
+"var all = [];"
|
870 |
|
+"\nvar sel = txmGetSelection();"
|
871 |
|
+"\nif (sel.rangeCount == 0) {return all;}"
|
|
852 |
String SCRIPT02_getspans = ""//functions //$NON-NLS-1$
|
|
853 |
+"var all = [];" //$NON-NLS-1$
|
|
854 |
+"\nvar sel = txmGetSelection();" //$NON-NLS-1$
|
|
855 |
+"\nif (sel.rangeCount == 0) {return all;}" //$NON-NLS-1$
|
872 |
856 |
//+"\nalert('sel='+sel);"
|
873 |
|
+"\nvar range = txmGetRange(sel, 0);"
|
|
857 |
+"\nvar range = txmGetRange(sel, 0);" //$NON-NLS-1$
|
874 |
858 |
//+"\nalert('range='+range);"
|
875 |
|
+"\nvar frag = txmGetFragment(range);"
|
|
859 |
+"\nvar frag = txmGetFragment(range);" //$NON-NLS-1$
|
876 |
860 |
//+"\nalert('frag='+frag);"
|
877 |
|
+"\nvar children = txmGetChildren(frag);"
|
|
861 |
+"\nvar children = txmGetChildren(frag);" //$NON-NLS-1$
|
878 |
862 |
//+"\nalert('children='+children);"
|
879 |
863 |
//+"\nalert('children.length='+children.length);"
|
880 |
|
+"\nif ((children.length == 0) || (children.length == 1 && children.item(0).nodeType == 3)) {"
|
881 |
|
+"\n var parent = txmGetParentElementRange(range);"
|
|
864 |
+"\nif ((children.length == 0) || (children.length == 1 && children.item(0).nodeType == 3)) {" //$NON-NLS-1$
|
|
865 |
+"\n var parent = txmGetParentElementRange(range);" //$NON-NLS-1$
|
882 |
866 |
//+"\n if (parent instanceof HTMLHtmlElement) {alert('HTMLHtmlElement parent='+parent);return findIdsInString(parent, all);}"
|
883 |
|
+"\n if (typeof parent.getAttribute == 'undefined') {return all}"
|
884 |
|
+"\n var id = parent.getAttribute('id');"
|
885 |
|
+"\n var id = parent.getAttribute('id');"
|
886 |
|
+"\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {"
|
887 |
|
+"\n all.push(id);"
|
888 |
|
+"\n } else {" // try with the parent's parent
|
889 |
|
+"\n var parent = txmGetParent(parent);"
|
|
867 |
+"\n if (typeof parent.getAttribute == 'undefined') {return all}" //$NON-NLS-1$
|
|
868 |
+"\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
|
869 |
+"\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
|
870 |
+"\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {" //$NON-NLS-1$
|
|
871 |
+"\n all.push(id);" //$NON-NLS-1$
|
|
872 |
+"\n } else {" // try with the parent's parent //$NON-NLS-1$
|
|
873 |
+"\n var parent = txmGetParent(parent);" //$NON-NLS-1$
|
890 |
874 |
//+"\n alert('text selection, parent='+txmGetTagName(parent))"
|
891 |
|
+"\n if (typeof parent.getAttribute == 'undefined') {return all}"
|
892 |
|
+"\n var id = parent.getAttribute('id');"
|
893 |
|
+"\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {"
|
894 |
|
+"\n all.push(id);"
|
895 |
|
+"\n }"
|
896 |
|
+"\n }"
|
897 |
|
+"\n} else {"
|
898 |
|
+"\n findSpans(children, all);"
|
899 |
|
+"\n}"
|
|
875 |
+"\n if (typeof parent.getAttribute == 'undefined') {return all}" //$NON-NLS-1$
|
|
876 |
+"\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
|
877 |
+"\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {" //$NON-NLS-1$
|
|
878 |
+"\n all.push(id);" //$NON-NLS-1$
|
|
879 |
+"\n }" //$NON-NLS-1$
|
|
880 |
+"\n }" //$NON-NLS-1$
|
|
881 |
+"\n} else {" //$NON-NLS-1$
|
|
882 |
+"\n findSpans(children, all);" //$NON-NLS-1$
|
|
883 |
+"\n}" //$NON-NLS-1$
|
900 |
884 |
//+"alert('result='+all)"
|
901 |
|
+"\nreturn all;";
|
|
885 |
+"\nreturn all;"; //$NON-NLS-1$
|
902 |
886 |
|
903 |
887 |
// System.out.println(functions);
|
904 |
888 |
// System.out.println(SCRIPT02_getspans);
|
905 |
889 |
|
906 |
890 |
Object ret = evaluate(SCRIPT02_getspans);
|
907 |
891 |
if (ret instanceof Object[]) {
|
908 |
|
Log.info("selection word ids="+Arrays.toString((Object[])ret));
|
|
892 |
Log.info("selection word ids="+Arrays.toString((Object[])ret)); //$NON-NLS-1$
|
909 |
893 |
Object[] array = (Object[])ret;
|
910 |
894 |
String[] sel = new String[2];
|
911 |
895 |
if (array.length == 0) {
|
... | ... | |
919 |
903 |
return sel;
|
920 |
904 |
}
|
921 |
905 |
} else {
|
922 |
|
System.out.println("SCRIPT RETURNED="+ret);
|
|
906 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_script_returned, ret));
|
923 |
907 |
return null;
|
924 |
908 |
}
|
925 |
909 |
}
|
926 |
910 |
|
927 |
911 |
public String getTextSelection() {
|
928 |
912 |
//System.out.println("DOM="+getTextSelectionDOM());
|
929 |
|
String rez = getTextSelectionDOM().replaceAll("<[^>]+>", "");
|
|
913 |
String rez = getTextSelectionDOM().replaceAll("<[^>]+>", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
930 |
914 |
//System.out.println("STR="+rez);
|
931 |
915 |
return rez;
|
932 |
916 |
}
|
... | ... | |
985 |
969 |
new MenuItem(menu, SWT.SEPARATOR);
|
986 |
970 |
|
987 |
971 |
MenuItem copyItem = new MenuItem(menu, SWT.NONE);
|
988 |
|
copyItem.setText("Copy text selection");
|
|
972 |
copyItem.setText(EditionUIMessages.menu_copy_text_selection);
|
989 |
973 |
copyItem.addSelectionListener(new SelectionListener() {
|
990 |
974 |
|
991 |
975 |
@Override
|
... | ... | |
1003 |
987 |
copyItem.setEnabled(text != null && text.length() > 0);
|
1004 |
988 |
|
1005 |
989 |
MenuItem reloadItem = new MenuItem(menu, SWT.NONE);
|
1006 |
|
reloadItem.setText("Reload");
|
|
990 |
reloadItem.setText(EditionUIMessages.menu_reload);
|
1007 |
991 |
reloadItem.addSelectionListener(new SelectionListener() {
|
1008 |
992 |
|
1009 |
993 |
@Override
|
... | ... | |
1015 |
999 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
1016 |
1000 |
});
|
1017 |
1001 |
MenuItem backItem = new MenuItem(menu, SWT.NONE);
|
1018 |
|
backItem.setText("Back");
|
|
1002 |
backItem.setText(EditionUIMessages.menu_back);
|
1019 |
1003 |
backItem.addSelectionListener(new SelectionListener() {
|
1020 |
1004 |
|
1021 |
1005 |
@Override
|
... | ... | |
1027 |
1011 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
1028 |
1012 |
});
|
1029 |
1013 |
MenuItem forwardItem = new MenuItem(menu, SWT.NONE);
|
1030 |
|
forwardItem.setText("Forward");
|
|
1014 |
forwardItem.setText(EditionUIMessages.menu_forward);
|
1031 |
1015 |
forwardItem.addSelectionListener(new SelectionListener() {
|
1032 |
1016 |
|
1033 |
1017 |
@Override
|
... | ... | |
1043 |
1027 |
@Override
|
1044 |
1028 |
public void menuHidden(MenuEvent e) {
|
1045 |
1029 |
// TODO Auto-generated method stub
|
1046 |
|
|
1047 |
1030 |
}
|
1048 |
1031 |
});
|
1049 |
1032 |
// // restore old listeners
|
... | ... | |
1105 |
1088 |
currentPage = next;
|
1106 |
1089 |
this.setURL(currentPage.toURL());
|
1107 |
1090 |
} else {
|
1108 |
|
System.out.println("Page not found ("+name+").");
|
|
1091 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.warning_page_not_found, name));
|
1109 |
1092 |
}
|
1110 |
1093 |
}
|
1111 |
1094 |
|
... | ... | |
1130 |
1113 |
String id2 = ids[1];
|
1131 |
1114 |
if (id2 == null) id2 = id1;
|
1132 |
1115 |
String SCRIPT02_expand = ""
|
1133 |
|
+ "var elt = document.getElementById(\""+id1+"\");\n"
|
1134 |
|
+ "var elt2 = document.getElementById(\""+id2+"\");\n"
|
|
1116 |
+ "var elt = document.getElementById(\""+id1+"\");\n" //$NON-NLS-1$ //$NON-NLS-2$
|
|
1117 |
+ "var elt2 = document.getElementById(\""+id2+"\");\n" //$NON-NLS-1$ //$NON-NLS-2$
|
1135 |
1118 |
//+ "alert(\"elt=\"+elt);\n"
|
1136 |
|
+ "var sel = txmGetSelection();\n"
|
|
1119 |
+ "var sel = txmGetSelection();\n" //$NON-NLS-1$
|
1137 |
1120 |
//+ "alert(\"sel=\"+sel.extentNode);\n"
|
1138 |
1121 |
//+ "alert(\"typeof sel=\"+Object.getOwnPropertyNames(sel));\n"
|
1139 |
1122 |
//+ "alert(\"get_type sel=\"+get_type(sel));\n"
|
1140 |
|
+ "var range = txmGetRange(sel, 0);\n"
|
|
1123 |
+ "var range = txmGetRange(sel, 0);\n" //$NON-NLS-1$
|
1141 |
1124 |
//+ "alert(\"range=\"+range);\n"
|
1142 |
1125 |
//+ "alert(\"typeof range=\"+Object.getOwnPropertyNames(range));\n"
|
1143 |
1126 |
//+ "alert(\"get_type range=\"+get_type(range));\n"
|
1144 |
|
+"range.setStart(elt, 0);\n"
|
1145 |
|
+"range.setEndAfter(elt2, 0);\n"
|
1146 |
|
+"sel.removeAllRanges();\n"
|
1147 |
|
+"sel.addRange(range);\n"
|
1148 |
|
+ "\n"
|
1149 |
|
+ "return null;";
|
|
1127 |
+"range.setStart(elt, 0);\n" //$NON-NLS-1$
|
|
1128 |
+"range.setEndAfter(elt2, 0);\n" //$NON-NLS-1$
|
|
1129 |
+"sel.removeAllRanges();\n" //$NON-NLS-1$
|
|
1130 |
+"sel.addRange(range);\n" //$NON-NLS-1$
|
|
1131 |
+ "\n" //$NON-NLS-1$
|
|
1132 |
+ "return null;"; //$NON-NLS-1$
|
1150 |
1133 |
|
1151 |
1134 |
//System.out.println("Eval...\n"+SCRIPT02_expand);
|
1152 |
1135 |
evaluate(SCRIPT02_expand);
|