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

Commit

Permalink
use history properly for source-and-target search, enable 'search in …
Browse files Browse the repository at this point in the history
…document' link from project-wide search
  • Loading branch information
davidmason committed May 17, 2012
1 parent adb4753 commit 8ac5666
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 19 deletions.
Expand Up @@ -25,6 +25,8 @@
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import org.zanata.webtrans.client.events.FindMessageEvent;
import org.zanata.webtrans.client.history.History;
import org.zanata.webtrans.client.history.HistoryToken;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
Expand All @@ -40,10 +42,15 @@ public interface Display extends WidgetDisplay
boolean isFocused();
}

private final History history;
private HistoryToken currentState;

@Inject
public TransFilterPresenter(final Display display, final EventBus eventBus)
public TransFilterPresenter(final Display display, final EventBus eventBus, final History history)
{
super(display, eventBus);
this.history = history;
currentState = new HistoryToken();;
}

@Override
Expand All @@ -55,10 +62,31 @@ protected void onBind()
@Override
public void onValueChange(ValueChangeEvent<String> event)
{
eventBus.fireEvent(new FindMessageEvent(event.getValue()));
if (event.getValue() != currentState.getSearchText())
{
HistoryToken newToken = history.getHistoryToken();
newToken.setSearchText(event.getValue());
history.newItem(newToken);
}
}
});

registerHandler(history.addValueChangeHandler(new ValueChangeHandler<String>()
{

@Override
public void onValueChange(ValueChangeEvent<String> event)
{
HistoryToken token = history.getHistoryToken();
if (token.getSearchText() != currentState.getSearchText())
{
eventBus.fireEvent(new FindMessageEvent(token.getSearchText()));
display.getFilterText().setValue(token.getSearchText(), false);
}
currentState = token;
}
}));

}

@Override
Expand All @@ -75,4 +103,9 @@ public void onRevealDisplay()

}

public boolean isFocused()
{
return display.isFocused();
}

}
Expand Up @@ -22,11 +22,13 @@

import org.zanata.webtrans.client.resources.Resources;
import org.zanata.webtrans.client.resources.UiMessages;
import org.zanata.webtrans.client.ui.ClearableTextBox;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
Expand All @@ -41,15 +43,19 @@ interface TransFilterViewUiBinder extends UiBinder<Widget, TransFilterView>
{
}

// TODO deal with showing greyed-out text

@UiField(provided = true)
ClearableTextBox filterTextBox;
@UiField
TextBox filterTextBox;

private String hintMessage;

private boolean focused = false;

@Inject
public TransFilterView(final Resources resources, final TransFilterMessages messages, final UiMessages uiMessages)
{
this.filterTextBox = new ClearableTextBox(resources, uiMessages);
filterTextBox.setEmptyText(messages.findSourceOrTargetString());
hintMessage = messages.findSourceOrTargetString();
initWidget(uiBinder.createAndBindUi(this));
getElement().setId("TransFilterView");
}
Expand All @@ -63,13 +69,36 @@ public Widget asWidget()
@Override
public TextBox getFilterText()
{
return filterTextBox.getTextBox();
return filterTextBox;
}

@UiHandler("filterTextBox")
public void onFilterTextBoxFocus(FocusEvent event)
{
focused = true;
if (filterTextBox.getStyleName().contains("transFilterTextBoxEmpty"))
{
filterTextBox.setValue("");
filterTextBox.removeStyleName("transFilterTextBoxEmpty");
}
}

@UiHandler("filterTextBox")
public void onFilterTextBoxBlur(BlurEvent event)
{
focused = false;
if (filterTextBox.getText().isEmpty())
{
filterTextBox.setValue("");
filterTextBox.addStyleName("transFilterTextBoxEmpty");
filterTextBox.setValue(hintMessage);
}
}

@Override
public boolean isFocused()
{
return filterTextBox.isFocused();
return focused;
}

}
Expand Up @@ -5,7 +5,7 @@

<g:LayoutPanel>
<g:layer top="0px" height="20px" left="1px" right="3px">
<fui:ClearableTextBox ui:field="filterTextBox" />
<g:TextBox ui:field="filterTextBox" styleName='transFilterTextBox' />
</g:layer>
</g:LayoutPanel>

Expand Down
Expand Up @@ -159,7 +159,7 @@ public void setCancelButtonFocused(boolean isCancelButtonFocused)

public boolean isTransFilterFocused()
{
return transFilterPresenter.getDisplay().isFocused();
return transFilterPresenter.isFocused();
}

public void gotoCurrentRow()
Expand Down
Expand Up @@ -151,6 +151,12 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Show this document in editor view")
String viewDocInEditorDetailed();

@DefaultMessage("Search document in editor")
String searchDocInEditor();

@DefaultMessage("Show this document in the editor with the current search active")
String searchDocInEditorDetailed();

@DefaultMessage("Index")
String rowIndex();

Expand Down
Expand Up @@ -231,14 +231,12 @@ public void addDocumentLabel(String docName, ClickHandler viewDocClickHandler, C
selectWholeDocCheckBox.addValueChangeHandler(selectAllHandler);
docHeading.add(selectWholeDocCheckBox);

// TODO disabled until source-and-target search in editor responds properly to history
// TODO localizable strings
// InlineLabel searchDocLabel = new InlineLabel("Search document in editor");
// searchDocLabel.setTitle("Show this document in the editor with the current search active");
// searchDocLabel.addClickHandler(searchDocClickHandler);
// searchDocLabel.addStyleName("linkLabel");
// searchDocLabel.addStyleName("projectWideSearchResultsDocumentLink");
// docHeading.add(searchDocLabel);
InlineLabel searchDocLabel = new InlineLabel(messages.searchDocInEditor());
searchDocLabel.setTitle(messages.searchDocInEditorDetailed());
searchDocLabel.addClickHandler(searchDocClickHandler);
searchDocLabel.addStyleName("linkLabel");
searchDocLabel.addStyleName("projectWideSearchResultsDocumentLink");
docHeading.add(searchDocLabel);

InlineLabel showDocLabel = new InlineLabel(messages.viewDocInEditor());
showDocLabel.setTitle(messages.viewDocInEditorDetailed());
Expand Down
Expand Up @@ -443,6 +443,22 @@ tr.ApprovedStateDecoration td.TableEditorCell-Target .TableEditorContent-Edit
width: 99%;
}

.transFilterTextBox
{
margin: 0px;
font-size: 1.15em;
border: 2px solid lightgrey;
border-radius: 6px;
-moz-border-radius: 6px;
padding-right: 4px;
}

.transFilterTextBoxEmpty
{
color: grey;
font-style: italic;
}

/* Search-replace page
* TODO arrange for these to share styles with editor table
*/
Expand Down

0 comments on commit 8ac5666

Please sign in to comment.