Skip to content

Commit

Permalink
issue JabRef#4763
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakkumar96 committed Mar 19, 2019
1 parent bf4a55c commit 369bf02
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
57 changes: 57 additions & 0 deletions src/main/java/org/jabref/gui/preferences/ExternalTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class ExternalTab extends JPanel implements PrefsTab {
private final TextField adobeAcrobatReaderPath;
private final TextField sumatraReaderPath;
private final GridPane builder = new GridPane();
RadioButton defaultFileBrowser = new RadioButton(Localization.lang("Use default file browser"));
TextField commandText = new TextField();
RadioButton executeFileBrowser = new RadioButton(Localization.lang("Execute Command"));
Button selectFileBrowserButton = new Button(Localization.lang("Browser"));


public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPreferences prefs) {
this.prefs = prefs;
Expand Down Expand Up @@ -86,6 +91,30 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere
adobeAcrobatReader.setToggleGroup(pdfReaderGroup);
pdfOptionPanel.add(browseAdobeAcrobatReader, 3, 1);

/** chnage **/
GridPane fileBrowserPanel = new GridPane();
final ToggleGroup fileBrowserGroup = new ToggleGroup();
executeFileBrowser.setToggleGroup(fileBrowserGroup);
defaultFileBrowser.setToggleGroup(fileBrowserGroup);

//actions
selectFileBrowserButton.setOnAction( e -> showFileBrowserChooser());
defaultFileBrowser.setOnAction(e -> updateDefautFileBrowserButtonAndFieldEnabledState());
executeFileBrowser.setOnAction(e -> updateDefautFileBrowserButtonAndFieldEnabledState());

fileBrowserPanel.add(defaultFileBrowser, 1, 1);
fileBrowserPanel.add(executeFileBrowser, 1, 2);
fileBrowserPanel.add(commandText, 2, 2);
fileBrowserPanel.add(selectFileBrowserButton, 3, 2);

Label fileBrowserDescription = new Label(Localization.lang("Note: Use the placeholder %0 for the location of the opened library file.", "%DIR"));
fileBrowserPanel.add(fileBrowserDescription, 2, 3);


//fileBrowserPanel.add(commandText, 1, 1);

//fileBrowserPanel.add(selectFileBrowserButton, 2, 1);

if (OS.WINDOWS) {
browseSumatraReader.setOnAction(e -> showSumatraChooser());
pdfOptionPanel.add(sumatraReader, 1, 2);
Expand Down Expand Up @@ -135,6 +164,13 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere
builder.add(openPdf, 1, 12);

builder.add(pdfOptionPanel, 1, 13);

Label openFileBrowser = new Label(Localization.lang("Open File Browser"));
openFileBrowser.getStyleClass().add("sectionHeader");
builder.add(openFileBrowser, 1, 14);

builder.add(fileBrowserPanel, 1, 15);

JFXPanel panel = CustomJFXPanel.wrap(new Scene(builder));
setLayout(new BorderLayout());
add(panel, BorderLayout.CENTER);
Expand Down Expand Up @@ -167,6 +203,9 @@ public void setValues() {
defaultConsole.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION));
executeConsole.setSelected(!Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION));

defaultFileBrowser.setSelected(true); //change
commandText.setText(Globals.prefs.get(JabRefPreferences.FILE_BROWSER));

consoleCommand.setText(Globals.prefs.get(JabRefPreferences.CONSOLE_COMMAND));

adobeAcrobatReaderPath.setText(Globals.prefs.get(JabRefPreferences.ADOBE_ACROBAT_COMMAND));
Expand All @@ -181,6 +220,7 @@ public void setValues() {
}

updateExecuteConsoleButtonAndFieldEnabledState();
updateDefautFileBrowserButtonAndFieldEnabledState(); //change
}

@Override
Expand All @@ -191,6 +231,10 @@ public void storeSettings() {
prefs.putBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION, defaultConsole.isSelected());
prefs.put(JabRefPreferences.CONSOLE_COMMAND, consoleCommand.getText());
prefs.put(JabRefPreferences.ADOBE_ACROBAT_COMMAND, adobeAcrobatReaderPath.getText());

//change
prefs.putBoolean(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION, defaultFileBrowser.isSelected());
prefs.put(JabRefPreferences.FILE_BROWSER, commandText.getText());//change
if (OS.WINDOWS) {
prefs.put(JabRefPreferences.SUMATRA_PDF_COMMAND, sumatraReaderPath.getText());
}
Expand All @@ -212,6 +256,11 @@ private void updateExecuteConsoleButtonAndFieldEnabledState() {
consoleCommand.setDisable(!executeConsole.isSelected());
}

private void updateDefautFileBrowserButtonAndFieldEnabledState() { //change
selectFileBrowserButton.setDisable(!executeFileBrowser.isSelected());
commandText.setDisable(!executeFileBrowser.isSelected());
}

private void showConsoleChooser() {
JFileChooser consoleChooser = new JFileChooser();
int answer = consoleChooser.showOpenDialog(ExternalTab.this);
Expand All @@ -220,6 +269,14 @@ private void showConsoleChooser() {
}
}

private void showFileBrowserChooser() { //change
JFileChooser consoleChooser = new JFileChooser();

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Mar 19, 2019

I think your fork is out of sync with the master from upstream cause I recently replaced the JFileChooser with the JavaFX variant.
And create a PR for the changes

int answer = consoleChooser.showOpenDialog(ExternalTab.this);
if (answer == JFileChooser.APPROVE_OPTION) {
commandText.setText(consoleChooser.getSelectedFile().getAbsolutePath());
}
}

private void showAdobeChooser() {
JFileChooser adobeChooser = new JFileChooser();
int answer = adobeChooser.showOpenDialog(ExternalTab.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;

/**
* Preferences dialog. Contains a TabbedPane, and tabs will be defined in separate classes. Tabs MUST implement the
* PrefsTab interface, since this dialog will call the storeSettings() method of all tabs when the user presses ok.
Expand Down Expand Up @@ -218,6 +220,11 @@ private void storeAllSettings() {
GUIGlobals.updateEntryEditorColors();
frame.setupAllTables();
frame.output(Localization.lang("Preferences recorded."));

//change
JOptionPane.showMessageDialog(null, Globals.prefs.get(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION));

This comment has been minimized.

Copy link
@Siedlerchr

Siedlerchr Mar 19, 2019

Please no swing dialog. You can use the ones provided in the DialogService class

JOptionPane.showMessageDialog(null, Globals.prefs.get(JabRefPreferences.FILE_BROWSER));

}

public void setValues() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.model.bibtexkeypattern;

import java.util.List;

public class GlobalBibtexKeyPattern extends AbstractBibtexKeyPattern {

private List<String> defaultBibtexKeyPattern;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public class JabRefPreferences implements PreferencesService {
public static final String ADOBE_ACROBAT_COMMAND = "adobeAcrobatCommand";
public static final String SUMATRA_PDF_COMMAND = "sumatraCommand";
public static final String USE_PDF_READER = "usePDFReader";
public static final String USE_DEFAULT_FILE_BROWSER_APPLICATION = "useDefaultFileBrowserApplication"; //change
public static final String FILE_BROWSER = "fileBrowser"; //change
// Currently, it is not possible to specify defaults for specific entry types
// When this should be made possible, the code to inspect is org.jabref.gui.preferences.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getCiteKeyPattern(); etc
public static final String DEFAULT_BIBTEX_KEY_PATTERN = "defaultBibtexKeyPattern";
Expand Down

0 comments on commit 369bf02

Please sign in to comment.