use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ExportAsHtmlHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
String elementName = event.getParameter("elementName");
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
Shell shell = activeEditor.getEditorSite().getShell();
if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
if (xliffEditor.isMultiFile()) {
MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
}
IEditorInput input = xliffEditor.getEditorInput();
URI uri = null;
if (input instanceof FileEditorInput) {
uri = ((FileEditorInput) input).getURI();
} else if (input instanceof FileStoreEditorInput) {
uri = ((FileStoreEditorInput) input).getURI();
} else {
return null;
}
File xliff = new File(uri);
FileDialog fd = new FileDialog(shell, SWT.SAVE);
String[] names = { "HTML Files [*.html]", "All Files [*.*]" };
//$NON-NLS-1$ //$NON-NLS-2$
String[] extensions = { "*.html", "*.*" };
fd.setFilterExtensions(extensions);
fd.setFilterNames(names);
//$NON-NLS-1$
fd.setFileName(xliff.getName() + ".html");
String out = fd.open();
if (out == null) {
return null;
}
XLFHandler handler = xliffEditor.getXLFHandler();
boolean result = handler.saveAsHtml(xliff.getAbsolutePath(), out, elementName);
if (result) {
IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
OpenEditorUtil.OpenFileWithSystemEditor(page, out);
} else {
MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowNextNoteHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectedRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int row = handler.getNextNoteSegmentIndex(lastSelectedRow);
if (row != -1) {
xliffEditor.jumpToRow(row);
} else {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openWarning(window.getShell(), "", "不存在下一个带批注的文本段。");
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowNextSegmentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectedRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int lastRow = handler.countEditableTransUnit() - 1;
if (lastSelectedRow == lastRow) {
lastSelectedRow = lastRow - 1;
}
xliffEditor.jumpToRow(lastSelectedRow + 1);
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowNextUnapprovedHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectedRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int row = handler.getNextUnapprovedSegmentIndex(lastSelectedRow);
if (row != -1) {
xliffEditor.jumpToRow(row);
} else {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openWarning(window.getShell(), "", "不存在下一个未批准文本段。");
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class ShowNextUntranslatableHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
int[] selectedRows = xliffEditor.getSelectedRows();
if (selectedRows.length < 1) {
return null;
}
Arrays.sort(selectedRows);
int lastSelectedRow = selectedRows[selectedRows.length - 1];
XLFHandler handler = xliffEditor.getXLFHandler();
int row = handler.getNextUntranslatableSegmentIndex(lastSelectedRow);
if (row != -1) {
xliffEditor.jumpToRow(row);
} else {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openWarning(window.getShell(), "", "不存在下一不可翻译文本段。");
}
return null;
}
Aggregations