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

Commit

Permalink
rhbz873525 - unsaved indicator is not correct after first save or cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Nov 9, 2012
1 parent e4d2ee2 commit 1b09d45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 13 additions & 4 deletions zanata-war/src/main/java/org/zanata/webtrans/client/ui/Editor.java
Expand Up @@ -8,7 +8,7 @@
import org.zanata.webtrans.client.resources.NavigationMessages;
import org.zanata.webtrans.client.view.TargetContentsDisplay;
import org.zanata.webtrans.shared.model.TransUnitId;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gwt.core.client.GWT;
Expand All @@ -27,9 +27,11 @@
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;

import static org.zanata.webtrans.client.view.TargetContentsDisplay.EditingState.*;

public class Editor extends Composite implements ToggleEditor
{
private final String displayString;
private String originalValue;
private TargetContentsDisplay.Listener listener;

interface EditorUiBinder extends UiBinder<Widget, Editor>
Expand Down Expand Up @@ -82,7 +84,7 @@ interface Styles extends CssResource

public Editor(String displayString, int index, final TargetContentsDisplay.Listener listener, TransUnitId id)
{
this.displayString = displayString;
this.originalValue = displayString;
this.listener = listener;
this.index = index;
this.id = id;
Expand Down Expand Up @@ -111,7 +113,8 @@ private void fireValidationEvent()
public void onValueChange(ValueChangeEvent<String> event)
{
fireValidationEvent();
boolean contentHasChanged = !Objects.equal(textArea.getText(), displayString);
boolean contentHasChanged = !Objects.equal(textArea.getText(), originalValue);
Log.info("value changed? " + contentHasChanged + " new: " + textArea.getText() + " old: " + originalValue);
TargetContentsDisplay.EditingState editingState = contentHasChanged ? UNSAVED : SAVED;
listener.setEditingState(id, editingState);
}
Expand Down Expand Up @@ -266,6 +269,12 @@ public void refresh()
textArea.refresh();
}

@Override
public void updateCachedValue(String displayText)
{
originalValue = displayText;
}

@Override
public void removeTranslator(String name, String color)
{
Expand Down
Expand Up @@ -26,6 +26,8 @@ public interface ToggleEditor extends IsWidget, HasText, HasUpdateValidationWarn

void refresh();

void updateCachedValue(String displayText);

static enum ViewMode
{
VIEW, EDIT
Expand Down
Expand Up @@ -32,7 +32,6 @@
import org.zanata.webtrans.shared.model.TransUnitId;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
Expand Down Expand Up @@ -221,7 +220,10 @@ public EditingState getEditingState()
public void updateCachedTargetsAndVersion(List<String> targets, Integer verNum, ContentState status)
{
cachedValue = TransUnit.Builder.from(cachedValue).setTargets(targets).setVerNum(verNum).setStatus(status).build();

for (int i = 0; i < editors.size(); i++)
{
editors.get(i).updateCachedValue(targets.get(i));
}
editorGrid.setStyleName(resolveStyleName(cachedValue.getStatus()));
}

Expand Down Expand Up @@ -311,6 +313,7 @@ public void revertEditorContents()
{
String target = cachedTargets.get(i);
editors.get(i).setTextAndValidate(target);
editors.get(i).updateCachedValue(target);
}
editorGrid.setStyleName(resolveStyleName(cachedValue.getStatus()));
}
Expand Down

0 comments on commit 1b09d45

Please sign in to comment.