use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class DeleteSelectionSegmentTranslationsHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg1"));
if (res) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
try {
XLFHandler handler = xliffEditor.getXLFHandler();
int[] selectedRows = xliffEditor.getSelectedRows();
List<Integer> rows = new ArrayList<Integer>();
boolean exitFlag = false;
for (int i = 0; i < selectedRows.length; i++) {
String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
if (null != tgt) {
if (tgt.equals("no")) {
exitFlag = true;
continue;
}
}
rows.add(selectedRows[i]);
}
if (rows.size() != 0) {
int columnIndex = xliffEditor.getTgtColumnIndex();
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
cellEditor.getSegmentViewer().getTextWidget().forceFocus();
}
int[] updateRows = new int[rows.size()];
for (int i = 0; i < rows.size(); i++) {
int ri = rows.get(i);
updateRows[i] = ri;
}
xliffEditor.updateCells(updateRows, columnIndex, "");
if (exitFlag) {
MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class MergeNextHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() < 1) {
return null;
}
String rowId = selectedRowIds.get(selectedRowIds.size() - 1);
XLFHandler handler = xliffEditor.getXLFHandler();
int rowIndex = handler.getRowIndex(rowId);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (rowIndex == handler.countEditableTransUnit() - 1) {
// 是最后一行
MessageDialog.openWarning(window.getShell(), "", "不存在下一文本段,不能合并。");
return null;
}
String rowId2 = handler.getRowId(rowIndex + 1);
if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
return null;
}
String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
return null;
}
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class MergePreviousHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
if (selectedRowIds.size() < 1) {
return null;
}
String rowId = selectedRowIds.get(0);
XLFHandler handler = xliffEditor.getXLFHandler();
int rowIndex = handler.getRowIndex(rowId);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if (rowIndex == 0) {
// 是第一行
MessageDialog.openWarning(window.getShell(), "", "不存在上一文本段,不能合并。");
return null;
}
String rowId2 = handler.getRowId(rowIndex - 1);
if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
return null;
}
String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
return null;
}
// IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
// try {
// operationHistory.execute(new MergeSegmentOperation("Merge Segment", xliffEditor, handler,
// rowIndex - 1), null, null);
// } catch (ExecutionException e) {
// e.printStackTrace();
// }
// 选中上一行
SelectionLayer selectionLayer = LayerUtil.getLayer(xliffEditor.getTable(), SelectionLayer.class);
selectionLayer.selectRow(0, rowIndex - 1, false, false);
return null;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method getFilesByFileEditorInput.
/**
* 通过 FileEditorInput 得到当前要打开的文件
* @param input
* FileEditorInput 对象
* @return ;
* @throws CoreException
*/
private List<File> getFilesByFileEditorInput(FileEditorInput input) throws CoreException {
List<File> files = null;
IFile file = (IFile) input.getAdapter(IFile.class);
if (file == null) {
throw new CoreException(new Status(Status.WARNING, net.heartsome.cat.ts.ui.xliffeditor.nattable.Activator.PLUGIN_ID, Messages.getString("editor.XLIFFEditorImplWithNatTable.msg5")));
} else {
if ("xlp".equals(file.getFileExtension()) && ".TEMP".equals(file.getParent().getName())) {
List<String> multiFiles = new XLFHandler().getMultiFiles(file);
files = new ArrayList<File>();
File mergerFile;
for (String multiFileLC : multiFiles) {
if (CommonFunction.validXlfExtensionByFileName(multiFileLC)) {
mergerFile = new File(multiFileLC);
files.add(mergerFile);
}
}
} else {
files = Arrays.asList(new File(input.getURI()));
}
}
return files;
}
use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.
the class SplitSegmentHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
if (cellEditor == null) {
return null;
}
if (!cellEditor.getCellType().equals(NatTableConstant.SOURCE)) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
int rowIndex = cellEditor.getRowIndex();
// 如果是垂直布局,那么 rowIndex 要除以2 --robert
if (!xliffEditor.isHorizontalLayout()) {
rowIndex = rowIndex / 2;
}
int caretOffset = cellEditor.getRealSplitOffset();
if (caretOffset < 0) {
// 文本框已经关闭时
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
// 不能选择多个字符进行分割
String selText = cellEditor.getSegmentViewer().getTextWidget().getSelectionText();
if (selText.length() != 0) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
return null;
}
XLFHandler handler = xliffEditor.getXLFHandler();
String rowId = handler.getRowId(rowIndex);
/* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 起 */
String tgt = handler.getCaseTgtContent(rowId);
if (null != tgt) {
if (tgt.equals("no")) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg2"));
return null;
}
}
int cellTextLength = ((UpdateDataBean) cellEditor.getCanonicalValue()).getText().length();
if (caretOffset <= 0 || caretOffset >= cellTextLength) {
showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg3"));
return null;
}
/* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 终 */
// 关闭Editor
cellEditor.close();
IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
try {
operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex, caretOffset), null, null);
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
Aggregations