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

Commit

Permalink
rhbz872384 - add spell check support with code mirror
Browse files Browse the repository at this point in the history
- Code mirror 2 does not support browser spell check.
- Add option to toggle between code mirror and plain textarea to have spell check.
  • Loading branch information
Patrick Huang committed Nov 5, 2012
1 parent b53e53f commit 1f06bb0
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 10 deletions.
Expand Up @@ -5,7 +5,14 @@
public class RefreshPageEvent extends GwtEvent<RefreshPageEventHandler>
{
public static Type<RefreshPageEventHandler> TYPE = new Type<RefreshPageEventHandler>();
public static final RefreshPageEvent EVENT = new RefreshPageEvent();
/**
* When firing this event, code mirror instances will be refreshed.
*/
public static final RefreshPageEvent REFRESH_CODEMIRROR_EVENT = new RefreshPageEvent();
/**
* When firing this event, we are switching from code mirror to plain textarea.
*/
public static final RefreshPageEvent REDRAW_PAGE_EVENT = new RefreshPageEvent();

private RefreshPageEvent()
{
Expand Down
Expand Up @@ -251,7 +251,7 @@ public void showView(MainView viewToShow)
currentView = viewToShow;
if (currentView == MainView.Editor)
{
eventBus.fireEvent(RefreshPageEvent.EVENT);
eventBus.fireEvent(RefreshPageEvent.REFRESH_CODEMIRROR_EVENT);
}
}

Expand Down
Expand Up @@ -164,7 +164,7 @@ public void onUseCodeMirrorOptionChanged(Boolean useCodeMirrorChkValue)
if (configHolder.isUseCodeMirrorEditor() != useCodeMirrorChkValue)
{
configHolder.setUseCodeMirrorEditor(useCodeMirrorChkValue);
eventBus.fireEvent(RefreshPageEvent.EVENT);
eventBus.fireEvent(RefreshPageEvent.REDRAW_PAGE_EVENT);
}
}

Expand Down
Expand Up @@ -231,7 +231,16 @@ public void showDataForCurrentPage(List<TransUnit> transUnits)
@Override
public void onRefreshPage(RefreshPageEvent event)
{
display.delayRefresh();
if (event == RefreshPageEvent.REFRESH_CODEMIRROR_EVENT)
{
display.delayRefresh();
}
else if (event == RefreshPageEvent.REDRAW_PAGE_EVENT)
{
List<TransUnit> currentPageValues = navigationService.getCurrentPageValues();
targetContentsPresenter.showData(currentPageValues);
display.buildTable(sourceContentsPresenter.getDisplays(), targetContentsPresenter.getDisplays());
}
}

@Override
Expand Down
Expand Up @@ -94,7 +94,7 @@ public void onPageCountChange(PageCountChangeEvent event)
@Override
public void refreshCurrentPage()
{
eventBus.fireEvent(RefreshPageEvent.EVENT);
eventBus.fireEvent(RefreshPageEvent.REFRESH_CODEMIRROR_EVENT);
}

@Override
Expand Down
Expand Up @@ -410,7 +410,7 @@ public interface WebTransMessages extends Messages
@DefaultMessage("When unexpected error happens, a popup window will display and show it")
String showErrorsTooltip();

@DefaultMessage("Switch between CodeMirror Editor (supports syntax highlight) and plain textarea (no syntax highlight)")
@DefaultMessage("Switch between CodeMirror Editor (supports syntax highlight but no spell check) and plain textarea (no syntax highlight but with spell check)")
String useCodeMirrorEditorTooltip();

@DefaultMessage("Go to row if on current page")
Expand Down
Expand Up @@ -21,7 +21,10 @@
package org.zanata.webtrans.client.ui;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.NativeEvent;
Expand Down Expand Up @@ -50,6 +53,7 @@ public native JavaScriptObject initCodeMirror(Element element) /*-{
var codeMirrorEditor = $wnd.CodeMirror.fromTextArea(element, {
lineNumbers: true,
lineWrapping: true,
disableSpellcheck: false,
mode: "visibleSpace",
value: element.value,
onFocus: function() {
Expand Down Expand Up @@ -77,6 +81,13 @@ public void setText(String text)
{
setCodeMirrorContent(text);
}
else
{
// if we are not using code mirror, we will try to hide text area scroll bar.
Splitter splitter = Splitter.on("\n");
Iterable<String> split = splitter.split(text);
setVisibleLines(Iterables.size(split));
}
}

@Override
Expand Down
Expand Up @@ -78,7 +78,7 @@ public class EditorOptionsView extends Composite implements EditorOptionsDisplay
@UiField
CheckBox showErrorChk;
@UiField
CheckBox useCodeMirrorChk; // TODO this is disabled and invisible to user. If codemirror works fine then remove this option.
CheckBox useCodeMirrorChk;

private Listener listener;

Expand Down
Expand Up @@ -91,7 +91,7 @@
<g:VerticalPanel width="100%">
<g:Label ui:field="otherConfigHeader" styleName="sideMenuHeader"/>
<g:CheckBox ui:field="showErrorChk"><ui:msg>Show System Errors</ui:msg></g:CheckBox>
<g:CheckBox ui:field="useCodeMirrorChk" visible="false" enabled="false"><ui:msg>Use CodeMirror Editor</ui:msg></g:CheckBox>
<g:CheckBox ui:field="useCodeMirrorChk" ><ui:msg>Use CodeMirror Editor</ui:msg></g:CheckBox>
</g:VerticalPanel>
</g:layer>
</g:LayoutPanel>
Expand Down
Expand Up @@ -461,7 +461,7 @@ public void canRefreshViewWithNoSearch()
@Test
public void onRefreshPageEvent()
{
presenter.onRefreshPage(RefreshPageEvent.EVENT);
presenter.onRefreshPage(RefreshPageEvent.REFRESH_CODEMIRROR_EVENT);

verify(display).delayRefresh();
}
Expand Down
Expand Up @@ -140,7 +140,7 @@ public void onRefreshCurrentPage()
{
presenter.refreshCurrentPage();

verify(eventBus).fireEvent(RefreshPageEvent.EVENT);
verify(eventBus).fireEvent(RefreshPageEvent.REFRESH_CODEMIRROR_EVENT);
}

@Test
Expand Down

0 comments on commit 1f06bb0

Please sign in to comment.