Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package gwt.material.design.addins.client.richeditor;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.BlurEvent;
Expand All @@ -35,6 +36,7 @@
import gwt.material.design.addins.client.richeditor.base.HasPasteHandlers;
import gwt.material.design.addins.client.richeditor.base.ToolBarManager;
import gwt.material.design.addins.client.richeditor.base.constants.RichEditorEvents;
import gwt.material.design.addins.client.richeditor.base.constants.RichEditorLanguage;
import gwt.material.design.addins.client.richeditor.base.constants.ToolbarButton;
import gwt.material.design.addins.client.richeditor.events.PasteEvent;
import gwt.material.design.addins.client.richeditor.js.JsRichEditor;
Expand Down Expand Up @@ -90,8 +92,9 @@ public class MaterialRichEditor extends AbstractValueWidget<String> implements J
private ToolBarManager manager = new ToolBarManager();
private boolean toggleFullScreen = true;
private JsRichEditorOptions options = JsRichEditorOptions.create();
private RichEditorLanguage language;

private HandlerRegistration handlerRegistration;
private HandlerRegistration handlerRegistration, attachHandler;

public MaterialRichEditor() {
super(Document.get().createDivElement(), AddinsCssName.EDITOR);
Expand Down Expand Up @@ -123,6 +126,9 @@ public void load() {
options.toolbar = manager.getToolbars();
options.placeholder = getPlaceholder();
options.height = getHeight();
if (language != null) {
options.lang = language.getCode();
}

jsRichEditor.materialnote(options);

Expand Down Expand Up @@ -244,6 +250,36 @@ public void setHeightOptions(ToolbarButton... heightOptions) {
manager.setHeightOptions(heightOptions);
}

public RichEditorLanguage getLanguage() {
return language;
}

public void setLanguage(RichEditorLanguage language) {
this.language = language;

if (attachHandler != null) {
attachHandler.removeHandler();
attachHandler = null;
}

if (isAttached()) {
setupLanguage(language);
} else {
attachHandler = registerHandler(addAttachHandler(attachEvent -> setupLanguage(language)));
}
}

protected void setupLanguage(RichEditorLanguage language) {
if (language.getJs() != null) {
if (MaterialAddins.isDebug()) {
MaterialDesignBase.injectDebugJs(language.getJs());
} else {
MaterialDesignBase.injectJs(language.getJs());
}
Scheduler.get().scheduleDeferred(() -> reload());
}
}

protected void checkContainer() {
if (getParent() instanceof MaterialDialog) {
MaterialDialog dialog = (MaterialDialog) getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author kevzlou7979
*/
interface MaterialRichEditorClientBundle extends ClientBundle {
public interface MaterialRichEditorClientBundle extends ClientBundle {

MaterialRichEditorClientBundle INSTANCE = GWT.create(MaterialRichEditorClientBundle.class);

Expand All @@ -38,4 +38,130 @@ interface MaterialRichEditorClientBundle extends ClientBundle {
@Source("resources/css/material_note.min.css")
TextResource richEditorCss();

@Source("resources/js/materialnote-ar-AR.js")
TextResource ar_AR();

@Source("resources/js/materialnote-bg-BG.js")
TextResource bg_BG();

@Source("resources/js/materialnote-ca-ES.js")
TextResource ca_ES();

@Source("resources/js/materialnote-cs-CZ.js")
TextResource cs_CZ();

@Source("resources/js/materialnote-da-DK.js")
TextResource da_DK();

@Source("resources/js/materialnote-de-DE.js")
TextResource de_DE();

@Source("resources/js/materialnote-el-GR.js")
TextResource el_GR();

@Source("resources/js/materialnote-en-US.js")
TextResource en_US();

@Source("resources/js/materialnote-es-ES.js")
TextResource es_ES();

@Source("resources/js/materialnote-es-EU.js")
TextResource es_EU();

@Source("resources/js/materialnote-fa-IR.js")
TextResource fa_IR();

@Source("resources/js/materialnote-fi-FI.js")
TextResource fi_FI();

@Source("resources/js/materialnote-fr-FR.js")
TextResource fr_FR();

@Source("resources/js/materialnote-gl-ES.js")
TextResource gl_ES();

@Source("resources/js/materialnote-he-IL.js")
TextResource he_IL();

@Source("resources/js/materialnote-hr-HR.js")
TextResource hr_HR();

@Source("resources/js/materialnote-hu-HU.js")
TextResource hu_HU();

@Source("resources/js/materialnote-id-ID.js")
TextResource id_ID();

@Source("resources/js/materialnote-it-IT.js")
TextResource it_IT();

@Source("resources/js/materialnote-ja-JP.js")
TextResource ja_JP();

@Source("resources/js/materialnote-ko-KR.js")
TextResource ko_KR();

@Source("resources/js/materialnote-lt-LT.js")
TextResource lt_LT();

@Source("resources/js/materialnote-lt-LV.js")
TextResource lt_LV();

@Source("resources/js/materialnote-mn-MN.js")
TextResource mn_MN();

@Source("resources/js/materialnote-nb-NO.js")
TextResource nb_NO();

@Source("resources/js/materialnote-nl-NL.js")
TextResource nl_NL();

@Source("resources/js/materialnote-pl-PL.js")
TextResource pl_PL();

@Source("resources/js/materialnote-pt-BR.js")
TextResource pt_BR();

@Source("resources/js/materialnote-pt-PT.js")
TextResource pt_PT();

@Source("resources/js/materialnote-ro-RO.js")
TextResource ro_RO();

@Source("resources/js/materialnote-ru-RU.js")
TextResource ru_RU();

@Source("resources/js/materialnote-sk-SK.js")
TextResource sk_SK();

@Source("resources/js/materialnote-sl-SI.js")
TextResource sl_SI();

@Source("resources/js/materialnote-sr-RS.js")
TextResource sr_RS();

@Source("resources/js/materialnote-sv-SE.js")
TextResource sv_SE();

@Source("resources/js/materialnote-ta-IN.js")
TextResource ta_IN();

@Source("resources/js/materialnote-th-TH.js")
TextResource th_TH();

@Source("resources/js/materialnote-tr-TR.js")
TextResource tr_TR();

@Source("resources/js/materialnote-uk-UA.js")
TextResource uk_UA();

@Source("resources/js/materialnote-vi-VN.js")
TextResource vi_VN();

@Source("resources/js/materialnote-zh-CN.js")
TextResource zh_CN();

@Source("resources/js/materialnote-zh-TW.js")
TextResource zh_TW();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* #%L
* GwtMaterial
* %%
* Copyright (C) 2015 - 2019 GwtMaterialDesign
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package gwt.material.design.addins.client.richeditor.base.constants;

import com.google.gwt.resources.client.TextResource;
import gwt.material.design.addins.client.richeditor.MaterialRichEditorClientBundle;

public enum RichEditorLanguage {
AR_AR("ar-AR", MaterialRichEditorClientBundle.INSTANCE.ar_AR()),
BG_BG("bg-BG", MaterialRichEditorClientBundle.INSTANCE.bg_BG()),
CA_ES("ca-ES", MaterialRichEditorClientBundle.INSTANCE.ca_ES()),
CS_CZ("cs-CZ", MaterialRichEditorClientBundle.INSTANCE.cs_CZ()),
DA_DK("da-DK", MaterialRichEditorClientBundle.INSTANCE.da_DK()),
DE_DE("de-DE", MaterialRichEditorClientBundle.INSTANCE.de_DE()),
EL_GR("el-GR", MaterialRichEditorClientBundle.INSTANCE.el_GR()),
EN_US("en-US", MaterialRichEditorClientBundle.INSTANCE.en_US()),
ES_ES("es-ES", MaterialRichEditorClientBundle.INSTANCE.es_ES()),
ES_EU("es-EU", MaterialRichEditorClientBundle.INSTANCE.es_EU()),
FA_IR("fa-IR", MaterialRichEditorClientBundle.INSTANCE.fa_IR()),
FI_FI("fi-FI", MaterialRichEditorClientBundle.INSTANCE.fi_FI()),
FR_FR("fr-FR", MaterialRichEditorClientBundle.INSTANCE.fr_FR()),
GL_ES("gl-ES", MaterialRichEditorClientBundle.INSTANCE.gl_ES()),
HE_IL("he-IL", MaterialRichEditorClientBundle.INSTANCE.he_IL()),
HR_HR("hr-HR", MaterialRichEditorClientBundle.INSTANCE.hr_HR()),
HU_HU("hu-HU", MaterialRichEditorClientBundle.INSTANCE.hu_HU()),
ID_ID("id-ID", MaterialRichEditorClientBundle.INSTANCE.id_ID()),
IT_IT("it-IT", MaterialRichEditorClientBundle.INSTANCE.it_IT()),
JA_JP("ja-JP", MaterialRichEditorClientBundle.INSTANCE.ja_JP()),
KO_KR("ko-KR", MaterialRichEditorClientBundle.INSTANCE.ko_KR()),
LT_LT("lt-LT", MaterialRichEditorClientBundle.INSTANCE.lt_LT()),
LT_LV("lt-LV", MaterialRichEditorClientBundle.INSTANCE.lt_LV()),
MN_MN("mn-MN", MaterialRichEditorClientBundle.INSTANCE.mn_MN()),
NB_NO("nb-NO", MaterialRichEditorClientBundle.INSTANCE.nb_NO()),
NL_NL("nl-NL", MaterialRichEditorClientBundle.INSTANCE.nl_NL()),
PL_PL("pl-PL", MaterialRichEditorClientBundle.INSTANCE.pl_PL()),
PT_BR("pt-BR", MaterialRichEditorClientBundle.INSTANCE.pt_BR()),
PT_PT("pt-PT", MaterialRichEditorClientBundle.INSTANCE.pt_PT()),
RO_RO("ro-RO", MaterialRichEditorClientBundle.INSTANCE.ro_RO()),
RU_RU("ru-RU", MaterialRichEditorClientBundle.INSTANCE.ru_RU()),
SK_SK("sk-SK", MaterialRichEditorClientBundle.INSTANCE.sk_SK()),
SL_SI("sl-SI", MaterialRichEditorClientBundle.INSTANCE.sl_SI()),
SR_RS("sr-RS", MaterialRichEditorClientBundle.INSTANCE.sr_RS()),
SV_SE("sv-SE", MaterialRichEditorClientBundle.INSTANCE.sv_SE()),
TA_IN("ta-IN", MaterialRichEditorClientBundle.INSTANCE.ta_IN()),
TH_TH("th-TH", MaterialRichEditorClientBundle.INSTANCE.th_TH()),
TR_TR("tr-TR", MaterialRichEditorClientBundle.INSTANCE.tr_TR()),
UK_UA("uk-UA", MaterialRichEditorClientBundle.INSTANCE.uk_UA()),
VI_VN("vi-VN", MaterialRichEditorClientBundle.INSTANCE.vi_VN()),
ZH_CN("zh-CN", MaterialRichEditorClientBundle.INSTANCE.zh_CN()),
ZH_TW("zh-TW", MaterialRichEditorClientBundle.INSTANCE.zh_TW());

private final String code;
private final TextResource js;

RichEditorLanguage(String code, TextResource js) {
this.code = code;
this.js = js;
}

public String getCode() {
return code;
}

public TextResource getJs() {
return js;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ public final static JsRichEditorOptions create() {

@JsProperty
public String defaultTextColor;

@JsProperty
public String lang;
}
Loading