8 |
8 |
import org.eclipse.core.commands.ExecutionException;
|
9 |
9 |
import org.eclipse.core.filesystem.EFS;
|
10 |
10 |
import org.eclipse.core.filesystem.IFileStore;
|
|
11 |
import org.eclipse.core.resources.IResource;
|
|
12 |
import org.eclipse.core.runtime.CoreException;
|
|
13 |
import org.eclipse.core.runtime.FileLocator;
|
11 |
14 |
import org.eclipse.core.runtime.Path;
|
12 |
15 |
import org.eclipse.jface.viewers.ISelection;
|
13 |
16 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
17 |
import org.eclipse.search.ui.ISearchQuery;
|
|
18 |
import org.eclipse.search.ui.NewSearchUI;
|
|
19 |
import org.eclipse.search.ui.text.TextSearchQueryProvider;
|
14 |
20 |
import org.eclipse.swt.SWT;
|
15 |
21 |
import org.eclipse.swt.widgets.FileDialog;
|
16 |
22 |
import org.eclipse.swt.widgets.Shell;
|
|
23 |
import org.eclipse.ui.IEditorInput;
|
|
24 |
import org.eclipse.ui.IEditorPart;
|
17 |
25 |
import org.eclipse.ui.IWorkbenchPage;
|
18 |
26 |
import org.eclipse.ui.IWorkbenchWindow;
|
19 |
27 |
import org.eclipse.ui.PartInitException;
|
20 |
28 |
import org.eclipse.ui.PlatformUI;
|
21 |
29 |
import org.eclipse.ui.handlers.HandlerUtil;
|
22 |
30 |
import org.eclipse.ui.ide.FileStoreEditorInput;
|
|
31 |
import org.eclipse.wst.sse.ui.StructuredTextEditor;
|
|
32 |
import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
|
23 |
33 |
import org.txm.Toolbox;
|
|
34 |
import org.txm.concordance.core.functions.Concordance;
|
|
35 |
import org.txm.concordance.core.functions.Line;
|
|
36 |
import org.txm.concordance.rcp.editors.ConcordanceEditor;
|
|
37 |
import org.txm.edition.rcp.editors.SynopticEditionEditor;
|
|
38 |
import org.txm.objects.Text;
|
24 |
39 |
import org.txm.rcp.StatusLine;
|
25 |
40 |
import org.txm.rcp.swt.dialog.LastOpened;
|
26 |
41 |
import org.txm.utils.logger.Log;
|
... | ... | |
31 |
46 |
public static final String ID = "org.txm.xmleditor.OpenXMLEditor"; //$NON-NLS-1$
|
32 |
47 |
public static String lastopenedfile;
|
33 |
48 |
|
|
49 |
|
34 |
50 |
@Override
|
35 |
51 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
36 |
|
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
|
37 |
|
.getShell();
|
|
52 |
|
|
53 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
|
|
54 |
IEditorPart editor = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage().getActiveEditor();
|
|
55 |
ISelection iselection = HandlerUtil.getCurrentSelection(event);
|
|
56 |
Object selection = null;
|
|
57 |
if (iselection instanceof IStructuredSelection) {
|
|
58 |
selection = ((IStructuredSelection) iselection).getFirstElement();
|
|
59 |
}
|
|
60 |
|
38 |
61 |
String txmhome = Toolbox.getTxmHomePath();
|
39 |
|
String filename = event
|
40 |
|
.getParameter("org.txm.rcp.commands.commandParameter2"); //$NON-NLS-1$
|
41 |
|
if (filename != null && !filename.matches("") && !filename.matches(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
|
|
62 |
String filename = event.getParameter("org.txm.rcp.commands.commandParameter2"); //$NON-NLS-1$
|
|
63 |
IEditorPart reditor = null;
|
|
64 |
if (editor instanceof SynopticEditionEditor) {
|
|
65 |
Text text = ((SynopticEditionEditor)editor).getEditionPanel(0).getEdition().getText();
|
|
66 |
String[] wordSelection = ((SynopticEditionEditor)editor).getEditionPanel(0).getWordSelection();
|
|
67 |
|
|
68 |
File txmFile = text.getXMLTXMFile();
|
|
69 |
if (txmFile != null && txmFile.exists()) {
|
|
70 |
reditor = openfile(txmFile);
|
|
71 |
} else { // wrong link ?
|
|
72 |
txmFile = new File(text.getProject().getProjectDirectory(), "txm/"+text.getProject().getName()+"/"+text.getName()+".xml");
|
|
73 |
reditor = openfile(txmFile);
|
|
74 |
}
|
|
75 |
|
|
76 |
if (wordSelection[0] != null && reditor instanceof XMLMultiPageEditorPart) {
|
|
77 |
XMLMultiPageEditorPart xmlEditor = (XMLMultiPageEditorPart)reditor;
|
|
78 |
System.out.println("xmlEditor="+xmlEditor);
|
|
79 |
System.out.println("word="+wordSelection[0]);
|
|
80 |
Object selectedPage = xmlEditor.getSelectedPage();
|
|
81 |
if (selectedPage != null && selectedPage instanceof StructuredTextEditor) {
|
|
82 |
// StructuredTextEditor textEditor = (StructuredTextEditor) selectedPage;
|
|
83 |
//
|
|
84 |
// String search = "\""+wordSelection[0]+"\"";
|
|
85 |
if (wordSelection[1] == null) {
|
|
86 |
System.out.println("Selected word: "+wordSelection[0]);
|
|
87 |
} else {
|
|
88 |
System.out.println("Selected word: from "+wordSelection[0]+" to "+wordSelection[1]);
|
|
89 |
}
|
|
90 |
}
|
|
91 |
}
|
|
92 |
} else if (selection != null && selection instanceof Line) {
|
|
93 |
Line line = (Line)selection;
|
|
94 |
Concordance conc = line.getConcordance();
|
|
95 |
String text = line.getTextId();
|
|
96 |
|
|
97 |
File txmFile = new File(conc.getProject().getProjectDirectory(), "txm/"+conc.getCorpus().getID()+"/"+text+".xml");
|
|
98 |
reditor = openfile(txmFile);
|
|
99 |
if (reditor != null & reditor instanceof XMLMultiPageEditorPart) {
|
|
100 |
XMLMultiPageEditorPart xmlEditor = (XMLMultiPageEditorPart)reditor;
|
|
101 |
Object selectedPage = xmlEditor.getSelectedPage();
|
|
102 |
if (selectedPage != null && selectedPage instanceof StructuredTextEditor) {
|
|
103 |
System.out.println("Word selection: "+line.getKeywordIds());
|
|
104 |
}
|
|
105 |
}
|
|
106 |
} else if (filename != null && !filename.matches("") && !filename.matches(" ")) { //$NON-NLS-1$ //$NON-NLS-2$
|
42 |
107 |
String filepath = txmhome + "/scripts/" + filename; //$NON-NLS-1$
|
43 |
|
openfile(new File(filepath));
|
44 |
|
return null;
|
|
108 |
return openfile(new File(filepath));
|
45 |
109 |
}
|
46 |
110 |
|
|
111 |
if (reditor != null) return null;
|
|
112 |
|
|
113 |
|
47 |
114 |
File file = null;
|
48 |
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
49 |
|
if (selection != null & selection instanceof IStructuredSelection) {
|
50 |
|
IStructuredSelection strucSelection = (IStructuredSelection) selection;
|
51 |
|
for (Object o : strucSelection.toList()) {
|
|
115 |
if (iselection != null & iselection instanceof IStructuredSelection) {
|
|
116 |
for (Object o : ((IStructuredSelection)iselection).toList()) {
|
52 |
117 |
if(o != null && o instanceof File) {
|
53 |
118 |
file = (File)o;
|
54 |
119 |
break;
|
... | ... | |
87 |
152 |
return null;
|
88 |
153 |
}
|
89 |
154 |
|
90 |
|
private boolean openfile(File file) {
|
|
155 |
private IEditorPart openfile(File file) {
|
91 |
156 |
//XMLMultiPageEditorPart editorInput = new ConcordancesEditorInput(corpus, null);
|
92 |
157 |
Log.fine(XMLEditorMessages.OpenXMLEditor_1);
|
93 |
158 |
IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(
|
... | ... | |
100 |
165 |
String ID = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$
|
101 |
166 |
try {
|
102 |
167 |
StatusLine.setMessage(XMLEditorMessages.OpenXMLEditor_3);
|
103 |
|
page.openEditor(editorInput, ID); //$NON-NLS-1$
|
|
168 |
IEditorPart editor = page.openEditor(editorInput, ID); //$NON-NLS-1$
|
|
169 |
if (editor != null && editor instanceof XMLMultiPageEditorPart) {
|
|
170 |
XMLMultiPageEditorPart xmlEditor = ((XMLMultiPageEditorPart)editor);
|
|
171 |
xmlEditor.removePage(0);
|
|
172 |
return xmlEditor;
|
|
173 |
}
|
|
174 |
|
|
175 |
return editor;
|
104 |
176 |
} catch (PartInitException e) {
|
105 |
177 |
System.out.println(XMLEditorMessages.OpenXMLEditor_4+e);
|
106 |
178 |
}
|
107 |
|
return true;
|
|
179 |
return null;
|
108 |
180 |
}
|
109 |
181 |
}
|