Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Implement append glossary text into editor in cursor position
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sl-eng committed Mar 9, 2012
1 parent 7d587e7 commit 8d754b2
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 4 deletions.
Expand Up @@ -529,6 +529,17 @@ public void setText(String text)
}
}

public void insertTextInCursorPosition(String text)
{
if (isEditing())
{
String preCursor = textArea.getText().substring(0, textArea.getCursorPos());
String postCursor = textArea.getText().substring(textArea.getCursorPos(), textArea.getText().length());

textArea.setText(preCursor + text + postCursor);
}
}

@Override
public void editCell(CellEditInfo cellEditInfo, TransUnit cellValue, Callback<TransUnit> callback)
{
Expand Down
Expand Up @@ -43,6 +43,8 @@
import org.zanata.webtrans.client.events.FilterViewEventHandler;
import org.zanata.webtrans.client.events.FindMessageEvent;
import org.zanata.webtrans.client.events.FindMessageHandler;
import org.zanata.webtrans.client.events.InsertStringInEditorEvent;
import org.zanata.webtrans.client.events.InsertStringInEditorHandler;
import org.zanata.webtrans.client.events.NavTransUnitEvent;
import org.zanata.webtrans.client.events.NavTransUnitEvent.NavigationType;
import org.zanata.webtrans.client.events.NavTransUnitHandler;
Expand Down Expand Up @@ -581,6 +583,36 @@ public void onTransMemoryCopy(CopyDataToEditorEvent event)
}
}
}));

registerHandler(eventBus.addHandler(InsertStringInEditorEvent.getType(), new InsertStringInEditorHandler()
{
@Override
public void onInsertString(InsertStringInEditorEvent event)
{
if (selectedTransUnit == null)
{
eventBus.fireEvent(new NotificationEvent(Severity.Error, messages.noTextFlowToCopy()));
}
else
{
if (!display.getTargetCellEditor().isEditing())
{
gotoCurrentRow();
}
if (display.getTargetCellEditor().isEditing())
{
display.getTargetCellEditor().insertTextInCursorPosition(event.getSuggestion());
display.getTargetCellEditor().autoSize();
eventBus.fireEvent(new NotificationEvent(Severity.Info, messages.notifyCopied()));
}
else
{
// Error if failed to open editor
eventBus.fireEvent(new NotificationEvent(Severity.Error, messages.notifyUnopened()));
}
}
}
}));

registerHandler(eventBus.addHandler(CopySourceEvent.getType(), new CopySourceEventHandler()
{
Expand Down
@@ -0,0 +1,56 @@
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.GwtEvent;

public class InsertStringInEditorEvent extends GwtEvent<InsertStringInEditorHandler>
{

/**
* Handler type.
*/
private static Type<InsertStringInEditorHandler> TYPE;

/**
* Gets the type associated with this event.
*
* @return returns the handler type
*/
public static Type<InsertStringInEditorHandler> getType()
{
return TYPE != null ? TYPE : (TYPE = new Type<InsertStringInEditorHandler>());
}

private String valueToReplace, suggestion;

/**
* @param sourceResult
* @param targetResult
*/
public InsertStringInEditorEvent(String valueToReplace, String suggestion)
{
this.valueToReplace = valueToReplace;
this.suggestion = suggestion;
}

@Override
protected void dispatch(InsertStringInEditorHandler handler)
{
handler.onInsertString(this);
}

@Override
public GwtEvent.Type<InsertStringInEditorHandler> getAssociatedType()
{
return getType();
}

public String getValueToReplace()
{
return valueToReplace;
}

public String getSuggestion()
{
return suggestion;
}
}
@@ -0,0 +1,8 @@
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.EventHandler;

public interface InsertStringInEditorHandler extends EventHandler
{
void onInsertString(InsertStringInEditorEvent event);
}
Expand Up @@ -26,7 +26,7 @@
import net.customware.gwt.presenter.client.widget.WidgetDisplay;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import org.zanata.webtrans.client.events.CopyDataToEditorEvent;
import org.zanata.webtrans.client.events.InsertStringInEditorEvent;
import org.zanata.webtrans.client.events.TransUnitSelectionEvent;
import org.zanata.webtrans.client.events.TransUnitSelectionHandler;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void onTransUnitSelected(TransUnitSelectionEvent event)
@Override
public void update(int index, TranslationMemoryGlossaryItem object, String value)
{
eventBus.fireEvent(new CopyDataToEditorEvent(object.getSource(), object.getTarget()));
eventBus.fireEvent(new InsertStringInEditorEvent(object.getSource(), object.getTarget()));
}
});
}
Expand Down
Expand Up @@ -48,6 +48,12 @@ public interface UiMessages extends Messages

@DefaultMessage("Target")
String targetLabel();

@DefaultMessage("Term")
String termLabel();

@DefaultMessage("Suggestion")
String suggestionLabel();

@DefaultMessage("Copy \"{0}\" to the editor")
String copyLinkTooltip(String targetMessage);
Expand Down
Expand Up @@ -156,8 +156,8 @@ public void renderTable()
glossaryTable = new CellTable<TranslationMemoryGlossaryItem>();
glossaryTable.addStyleName("glossaryTable");
glossaryTable.addStyleName("southTable");
glossaryTable.addColumn(sourceColumn, messages.sourceLabel());
glossaryTable.addColumn(targetColumn, messages.targetLabel());
glossaryTable.addColumn(sourceColumn, messages.termLabel());
glossaryTable.addColumn(targetColumn, messages.suggestionLabel());
glossaryTable.addColumn(new SimilarityColumn(), messages.similarityLabel());
glossaryTable.addColumn(copyColumn);

Expand Down

0 comments on commit 8d754b2

Please sign in to comment.