Skip to content

Commit

Permalink
Refactor externalprefs (#6509)
Browse files Browse the repository at this point in the history
* Added validators and some visual changes to ExternalTab

* Added ExternalApplicationsPreferences

* Refactored for reduced complexity

* Refactored for eye-candy
  • Loading branch information
calixtus authored May 23, 2020
1 parent dffcf78 commit 03e3663
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 228 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public JabRefFrame(Stage mainStage) {
this.mainStage = mainStage;
this.dialogService = new JabRefDialogService(mainStage, this, prefs, themeLoader);
this.stateManager = Globals.stateManager;
this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager);
this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager, prefs);
this.undoManager = Globals.undoManager;
this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction());
this.executorService = JabRefExecutorService.INSTANCE;
Expand Down Expand Up @@ -513,7 +513,7 @@ private Node createToolbar() {

final PushToApplicationAction pushToApplicationAction = getPushToApplicationsManager().getPushToApplicationAction();
final Button pushToApplicationButton = factory.createIconButton(pushToApplicationAction.getActionInformation(), pushToApplicationAction);
pushToApplicationsManager.setToolBarButton(pushToApplicationButton);
pushToApplicationsManager.registerReconfigurable(pushToApplicationButton);

HBox rightSide = new HBox(
factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, Globals.prefs, stateManager)),
Expand Down Expand Up @@ -835,7 +835,7 @@ private MenuBar createMenu() {
// PushToApplication
final PushToApplicationAction pushToApplicationAction = pushToApplicationsManager.getPushToApplicationAction();
final MenuItem pushToApplicationMenuItem = factory.createMenuItem(pushToApplicationAction.getActionInformation(), pushToApplicationAction);
pushToApplicationsManager.setMenuItem(pushToApplicationMenuItem);
pushToApplicationsManager.registerReconfigurable(pushToApplicationMenuItem);

tools.getItems().addAll(
factory.createMenuItem(StandardActions.PARSE_LATEX, new ParseLatexAction(stateManager)),
Expand Down
91 changes: 48 additions & 43 deletions src/main/java/org/jabref/gui/preferences/ExternalTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import org.jabref.gui.icon.JabRefIconView?>
<fx:root prefWidth="650.0" spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx/8.0.212" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.preferences.ExternalTabView">
<fx:define>
<ToggleGroup fx:id="openConsole"/>
<ToggleGroup fx:id="openPDF"/>
<ToggleGroup fx:id="openFileBrowser"/>
</fx:define>
<Label styleClass="titleHeader" text="%External programs"/>
<Label styleClass="sectionHeader" text="%Sending of emails"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
Expand All @@ -31,7 +25,7 @@

<Label styleClass="sectionHeader" text="%Push applications"/>
<HBox>
<GridPane alignment="CENTER_LEFT" hgap="10.0">
<GridPane alignment="CENTER_LEFT" hgap="4.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="200.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="200.0"/>
Expand All @@ -45,60 +39,71 @@
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
</rowConstraints>
<Label text="%Application to push entries to"/>
<ComboBox fx:id="pushToApplicationCombo" prefWidth="200.0" GridPane.columnIndex="1"/>
<Button onAction="#pushToApplicationSettings" prefWidth="150.0" text="%Application settings"
GridPane.columnIndex="2"/>
<ComboBox fx:id="pushToApplicationCombo"
prefWidth="200.0" GridPane.columnIndex="1"/>
<Button styleClass="icon-button,narrow" onAction="#pushToApplicationSettings"
prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2">
<graphic>
<JabRefIconView glyph="PREFERENCES"/>
</graphic>
<tooltip>
<Tooltip text="%Application settings"/>
</tooltip>
</Button>

<Label text="%Cite command" GridPane.rowIndex="2"/>
<TextField fx:id="citeCommand" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<Button onAction="#manageExternalFileTypes" prefWidth="200.0" text="%Manage external file types"
GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<TextField fx:id="citeCommand"
prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2"/>

<Button onAction="#manageExternalFileTypes" text="%Manage external file types"
prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
</GridPane>
</HBox>

<Label styleClass="sectionHeader" text="%Open console"/>
<GridPane alignment="CENTER_LEFT" hgap="10.0" vgap="4.0">
<Label styleClass="sectionHeader" text="%Custom applications"/>
<GridPane alignment="CENTER_LEFT" hgap="4.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="200.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="350.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="50" prefWidth="200.0"/>
<ColumnConstraints hgrow="ALWAYS" minWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<RadioButton fx:id="useTerminalDefault" text="%Use default terminal emulator" toggleGroup="$openConsole"/>
<RadioButton fx:id="useTerminalSpecial" text="%Execute command" GridPane.rowIndex="1"
toggleGroup="$openConsole"/>
<TextField fx:id="useTerminalCommand" prefWidth="350.0" GridPane.columnIndex="1" GridPane.rowIndex="1">

<CheckBox fx:id="useCustomTerminal" text="%Use custom terminal emulator"/>
<TextField fx:id="customTerminalCommand" prefWidth="350.0" GridPane.columnIndex="1">
<tooltip>
<Tooltip text="%Note: Use the placeholder %DIR% for the location of the opened library file."/>
</tooltip>
</TextField>
<Button fx:id="useTerminalBrowse" text="%Browse" onAction="#useTerminalCommandBrowse"
GridPane.columnIndex="2" GridPane.rowIndex="1"/>
</GridPane>
<Button fx:id="customTerminalBrowse" onAction="#useTerminalCommandBrowse"
styleClass="icon-button,narrow"
prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2">
<graphic>
<JabRefIconView glyph="OPEN"/>
</graphic>
<tooltip>
<Tooltip text="%Browse"/>
</tooltip>
</Button>

<Label styleClass="sectionHeader" text="%Open File Browser"/>
<GridPane alignment="CENTER_LEFT" hgap="10.0" vgap="4.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="200.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="350.0"/>
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<RadioButton fx:id="useFileBrowserDefault" text="%Use default file browser" toggleGroup="$openFileBrowser"/>
<RadioButton fx:id="useFileBrowserSpecial" text="%Execute command" toggleGroup="$openFileBrowser"
GridPane.rowIndex="1"/>
<TextField fx:id="useFileBrowserSpecialCommand" prefWidth="350.0" GridPane.columnIndex="1"
GridPane.rowIndex="1">
<CheckBox fx:id="useCustomFileBrowser" text="%Use custom file browser" GridPane.rowIndex="1"/>
<TextField fx:id="customFileBrowserCommand" prefWidth="350.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Note: Use the placeholder %DIR% for the location of the opened library file."/>
</tooltip>
</TextField>
<Button fx:id="useFileBrowserSpecialBrowse" onAction="#useFileBrowserSpecialCommandBrowse" text="%Browse"
GridPane.columnIndex="2" GridPane.rowIndex="1"/>
<Button fx:id="customFileBrowserBrowse" onAction="#useFileBrowserSpecialCommandBrowse"
styleClass="icon-button,narrow"
prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
<graphic>
<JabRefIconView glyph="OPEN"/>
</graphic>
<tooltip>
<Tooltip text="%Browse"/>
</tooltip>
</Button>
</GridPane>
</fx:root>
70 changes: 33 additions & 37 deletions src/main/java/org/jabref/gui/preferences/ExternalTabView.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.jabref.gui.preferences;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.push.PushToApplication;
import org.jabref.gui.push.PushToApplicationsManager;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;

public class ExternalTabView extends AbstractPreferenceTabView<ExternalTabViewModel> implements PreferencesTab {

Expand All @@ -23,21 +25,21 @@ public class ExternalTabView extends AbstractPreferenceTabView<ExternalTabViewMo
@FXML private ComboBox<PushToApplication> pushToApplicationCombo;
@FXML private TextField citeCommand;

@FXML private RadioButton useTerminalDefault;
@FXML private RadioButton useTerminalSpecial;
@FXML private TextField useTerminalCommand;
@FXML private Button useTerminalBrowse;
@FXML private CheckBox useCustomTerminal;
@FXML private TextField customTerminalCommand;
@FXML private Button customTerminalBrowse;

@FXML private RadioButton useFileBrowserDefault;
@FXML private RadioButton useFileBrowserSpecial;
@FXML private TextField useFileBrowserSpecialCommand;
@FXML private Button useFileBrowserSpecialBrowse;
@FXML private CheckBox useCustomFileBrowser;
@FXML private TextField customFileBrowserCommand;
@FXML private Button customFileBrowserBrowse;

private final JabRefFrame frame;
private final PushToApplicationsManager pushToApplicationsManager;

public ExternalTabView(JabRefPreferences preferences, JabRefFrame frame) {
private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

public ExternalTabView(JabRefPreferences preferences, PushToApplicationsManager pushToApplicationsManager) {
this.preferences = preferences;
this.frame = frame;
this.pushToApplicationsManager = pushToApplicationsManager;

ViewLoader.view(this)
.root(this)
Expand All @@ -50,7 +52,7 @@ public String getTabName() {
}

public void initialize() {
this.viewModel = new ExternalTabViewModel(dialogService, preferences, frame);
this.viewModel = new ExternalTabViewModel(dialogService, preferences, pushToApplicationsManager);

new ViewModelListCellFactory<PushToApplication>()
.withText(PushToApplication::getApplicationName)
Expand All @@ -64,17 +66,21 @@ public void initialize() {
pushToApplicationCombo.valueProperty().bindBidirectional(viewModel.selectedPushToApplication());
citeCommand.textProperty().bindBidirectional(viewModel.citeCommandProperty());

useTerminalDefault.selectedProperty().bindBidirectional(viewModel.useTerminalDefaultProperty());
useTerminalSpecial.selectedProperty().bindBidirectional(viewModel.useTerminalSpecialProperty());
useTerminalCommand.textProperty().bindBidirectional(viewModel.useTerminalCommandProperty());
useTerminalCommand.disableProperty().bind(useTerminalSpecial.selectedProperty().not());
useTerminalBrowse.disableProperty().bind(useTerminalSpecial.selectedProperty().not());

useFileBrowserDefault.selectedProperty().bindBidirectional(viewModel.useFileBrowserDefaultProperty());
useFileBrowserSpecial.selectedProperty().bindBidirectional(viewModel.useFileBrowserSpecialProperty());
useFileBrowserSpecialCommand.textProperty().bindBidirectional(viewModel.useFileBrowserSpecialCommandProperty());
useFileBrowserSpecialCommand.disableProperty().bind(useFileBrowserSpecial.selectedProperty().not());
useFileBrowserSpecialBrowse.disableProperty().bind(useFileBrowserSpecial.selectedProperty().not());
useCustomTerminal.selectedProperty().bindBidirectional(viewModel.useCustomTerminalProperty());
customTerminalCommand.textProperty().bindBidirectional(viewModel.customTerminalCommandProperty());
customTerminalCommand.disableProperty().bind(useCustomTerminal.selectedProperty().not());
customTerminalBrowse.disableProperty().bind(useCustomTerminal.selectedProperty().not());

useCustomFileBrowser.selectedProperty().bindBidirectional(viewModel.useCustomFileBrowserProperty());
customFileBrowserCommand.textProperty().bindBidirectional(viewModel.customFileBrowserCommandProperty());
customFileBrowserCommand.disableProperty().bind(useCustomFileBrowser.selectedProperty().not());
customFileBrowserBrowse.disableProperty().bind(useCustomFileBrowser.selectedProperty().not());

validationVisualizer.setDecoration(new IconValidationDecorator());
Platform.runLater(() -> {
validationVisualizer.initVisualization(viewModel.terminalCommandValidationStatus(), customTerminalCommand);
validationVisualizer.initVisualization(viewModel.fileBrowserCommandValidationStatus(), customFileBrowserCommand);
});
}

@FXML
Expand All @@ -89,21 +95,11 @@ void manageExternalFileTypes() {

@FXML
void useTerminalCommandBrowse() {
viewModel.useTerminalCommandBrowse();
}

@FXML
void usePDFAcrobatCommandBrowse() {
viewModel.usePDFAcrobatCommandBrowse();
}

@FXML
void usePDFSumatraCommandBrowse() {
viewModel.usePDFSumatraCommandBrowse();
viewModel.customTerminalBrowse();
}

@FXML
void useFileBrowserSpecialCommandBrowse() {
viewModel.useFileBrowserSpecialCommandBrowse();
viewModel.customFileBrowserBrowse();
}
}
Loading

0 comments on commit 03e3663

Please sign in to comment.