|
| 1 | +package org.jabref.gui.editmode; |
| 2 | + |
| 3 | +import org.jabref.gui.DialogService; |
| 4 | +import org.jabref.gui.StateManager; |
| 5 | +import org.jabref.gui.actions.SimpleCommand; |
| 6 | +import org.jabref.logic.l10n.Localization; |
| 7 | +import org.jabref.model.database.BibDatabaseContext; |
| 8 | +import org.jabref.model.database.BibDatabaseMode; |
| 9 | + |
| 10 | +import java.util.Optional; |
| 11 | + |
| 12 | +import static org.jabref.gui.actions.ActionHelper.needsDatabase; |
| 13 | + |
| 14 | +public class EditModeAction extends SimpleCommand { |
| 15 | + |
| 16 | + private final DialogService dialogService; |
| 17 | + private StateManager stateManager; |
| 18 | + |
| 19 | + public EditModeAction(DialogService dialogService, StateManager stateManager) { |
| 20 | + this.dialogService = dialogService; |
| 21 | + this.stateManager = stateManager; |
| 22 | + |
| 23 | + this.executable.bind(needsDatabase(stateManager)); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public void execute() { |
| 28 | + Optional<BibDatabaseContext> currentDatabase = stateManager.getActiveDatabase(); |
| 29 | + if (currentDatabase.isEmpty()) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + BibDatabaseMode newMode = currentDatabase.get().getMode() |
| 34 | + .getOppositeMode(); |
| 35 | + |
| 36 | + boolean result = dialogService.showConfirmationDialogAndWait( |
| 37 | + Localization.lang("Library Type Change"), |
| 38 | + Localization.lang("Are you sure you want to change your library type to '%0'?", newMode.getAsString()), |
| 39 | + Localization.lang("Convert")); |
| 40 | + |
| 41 | + if (!result) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + currentDatabase.get().setMode(newMode); |
| 46 | + } |
| 47 | +} |
0 commit comments