-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completed General Fields Customizer conversion to JavaFX #4346
Changes from 19 commits
6e5694a
92cddb1
24eb0a6
770a771
6a0b878
4058a70
b3d5238
51712e2
ee919a4
6eabd86
3435997
5133d44
4c6e309
b726a81
0d9a2a8
78c8748
857b9ea
c5ce5b1
4e9d78a
bf1c5d3
5bb9195
a22fcf0
7ae7a0e
fb22955
ae9ff0d
6cd1acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.ButtonType?> | ||
<?import javafx.scene.control.DialogPane?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.layout.VBox?> | ||
<DialogPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" | ||
fx:controller="org.jabref.gui.genfields.GenFieldsCustomizerDialogView"> | ||
<content> | ||
<VBox prefHeight="300.0" prefWidth="650.0"> | ||
<children> | ||
<Label text="%General Fields" /> | ||
<Label text="%Create custom fields for each BibTeX entry" /> | ||
<TextArea fx:id="fieldsTextArea" minHeight="200.0" minWidth="628.0" /> | ||
<Label text="%Format: Tab:field;field;... (e.g. General:url;pdf;note...)" /> | ||
</children> | ||
</VBox> | ||
</content> | ||
<ButtonType fx:id="okButton" fx:constant="OK" /> | ||
<ButtonType fx:id="resetButton" buttonData="LEFT" text="%Default" /> | ||
<ButtonType fx:id="helpButton" text="%Help" /> | ||
<ButtonType fx:constant="CANCEL" /> | ||
</DialogPane> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.jabref.gui.genfields; | ||
|
||
import javax.inject.Inject; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.TextArea; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.help.HelpAction; | ||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.gui.util.ControlHelper; | ||
import org.jabref.logic.help.HelpFile; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
|
||
public class GenFieldsCustomizerDialogView extends BaseDialog<Void> { | ||
|
||
@FXML private ButtonType resetButton; | ||
@FXML private ButtonType helpButton; | ||
@FXML private ButtonType okButton; | ||
@FXML private ButtonType cancelButton; | ||
@FXML private TextArea fieldsTextArea; | ||
|
||
@Inject private DialogService dialogService; | ||
@Inject private PreferencesService preferences; | ||
private GenFieldsCustomizerDialogViewModel viewModel; | ||
|
||
public GenFieldsCustomizerDialogView() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please rename all classes related to the dialog to something like |
||
this.setTitle(Localization.lang("Set General Fields")); | ||
this.setResizable(true); | ||
this.getDialogPane().setPrefSize(300, 650); | ||
|
||
ViewLoader.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
HelpAction helpCommand = new HelpAction(HelpFile.GENERAL_FIELDS); | ||
//HelpAction is written with Swing, not JavaFX, so runCommand() cannot be used normally. Here I am reaching into | ||
//the command and running execute. When HelpAction is converted to JavaFX, | ||
//the following will need to be changed. | ||
ControlHelper.setAction(helpButton, getDialogPane(), event -> helpCommand.getCommand().execute()); | ||
Siedlerchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ControlHelper.setAction(resetButton, getDialogPane(), event -> resetFields()); | ||
ControlHelper.setAction(okButton, getDialogPane(), event -> saveFieldsAndCloseDialog()); | ||
|
||
} | ||
|
||
@FXML | ||
private void initialize() { | ||
viewModel = new GenFieldsCustomizerDialogViewModel(dialogService, preferences); | ||
fieldsTextArea.textProperty().bindBidirectional(viewModel.fieldsTextProperty()); | ||
|
||
} | ||
|
||
@FXML | ||
private void closeDialog() { | ||
close(); | ||
} | ||
|
||
@FXML | ||
private void saveFieldsAndCloseDialog() { | ||
viewModel.saveFields(); | ||
closeDialog(); | ||
} | ||
|
||
private void resetFields() { | ||
viewModel.resetFields(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.jabref.gui.genfields; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.preferences.JabRefPreferences; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
public class GenFieldsCustomizerDialogViewModel { | ||
|
||
private final DialogService dialogService; | ||
private final PreferencesService preferences; | ||
private final StringProperty fieldsText = new SimpleStringProperty(""); | ||
|
||
public GenFieldsCustomizerDialogViewModel(DialogService dialogService, PreferencesService preferences) { | ||
this.dialogService = dialogService; | ||
this.preferences = preferences; | ||
setInitialFieldsText(); | ||
} | ||
|
||
private void setInitialFieldsText() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
for (Map.Entry<String, List<String>> tab : preferences.getEntryEditorTabList().entrySet()) { | ||
sb.append(tab.getKey()); | ||
sb.append(':'); | ||
sb.append(String.join(";", tab.getValue())); | ||
sb.append('\n'); | ||
} | ||
|
||
fieldsText.set(sb.toString()); | ||
} | ||
|
||
public StringProperty fieldsTextProperty() { | ||
return fieldsText; | ||
} | ||
|
||
public void saveFields() { | ||
String[] lines = fieldsText.get().split("\n"); | ||
int i = 0; | ||
for (; i < lines.length; i++) { | ||
String[] parts = lines[i].split(":"); | ||
if (parts.length != 2) { | ||
// Report error and exit. | ||
String field = Localization.lang("field"); | ||
String title = Localization.lang("Error"); | ||
String content = Localization.lang("Each line must be of the following form") + " '" + | ||
Localization.lang("Tabname") + ':' + field + "1;" + field + "2;...;" + field + "N'"; | ||
dialogService.showInformationDialogAndWait(title, content); | ||
return; | ||
} | ||
|
||
String testString = BibtexKeyGenerator.cleanKey(parts[1], preferences.getEnforceLegalKeys()); | ||
if (!testString.equals(parts[1]) || (parts[1].indexOf('&') >= 0)) { | ||
String title = Localization.lang("Error"); | ||
String content = Localization.lang("Field names are not allowed to contain white space or the following " | ||
+ "characters") | ||
+ ": # { } ~ , ^ &"; | ||
dialogService.showInformationDialogAndWait(title, content); | ||
return; | ||
} | ||
preferences.setCustomTabsNameAndFields(parts[0], parts[1], i); | ||
|
||
} | ||
preferences.purgeSeries(JabRefPreferences.CUSTOM_TAB_NAME, i); | ||
preferences.purgeSeries(JabRefPreferences.CUSTOM_TAB_FIELDS, i); | ||
preferences.updateEntryEditorTabList(); | ||
} | ||
|
||
public void resetFields() { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
Map<String,String> customTabNamesFields = preferences.getCustomTabsNamesAndFields(); | ||
for (Map.Entry<String,String>entry : customTabNamesFields.entrySet()) { | ||
sb.append(entry.getKey()); | ||
sb.append(':'); | ||
sb.append(entry.getValue()); | ||
sb.append('\n'); | ||
fieldsText.set(sb.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please align/indent it with the other ones below