2022-12-07 21:41:26 +01:00

55 lines
1.9 KiB
Java

package de.marhali.easyi18n.dialog;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import de.marhali.easyi18n.model.action.TranslationCreate;
import de.marhali.easyi18n.model.KeyPath;
import de.marhali.easyi18n.model.Translation;
import de.marhali.easyi18n.model.TranslationValue;
import de.marhali.easyi18n.model.action.TranslationUpdate;
import de.marhali.easyi18n.settings.ProjectSettingsService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Dialog to create a new translation with all associated locale values.
* Supports optional prefill technique for translation key or locale value.
* @author marhali
*/
public class AddDialog extends TranslationDialog {
/**
* Constructs a new create dialog with prefilled fields
* @param project Opened project
* @param prefillKey Prefill translation key
* @param prefillLocale Prefill preview locale value
*/
public AddDialog(@NotNull Project project, @Nullable KeyPath prefillKey, @Nullable String prefillLocale) {
super(project, new Translation(prefillKey != null ? prefillKey : new KeyPath(),
prefillLocale != null
? new TranslationValue(ProjectSettingsService.get(project).getState().getPreviewLocale(), prefillLocale)
: null)
);
setTitle(bundle.getString("action.add"));
}
/**
* Constructs a new create dialog without prefilled fields.
* @param project Opened project
*/
public AddDialog(@NotNull Project project) {
this(project, new KeyPath(), "");
}
@Override
protected @Nullable TranslationUpdate handleExit(int exitCode) {
if(exitCode == DialogWrapper.OK_EXIT_CODE) {
return new TranslationCreate(getState());
}
return null;
}
}