Skip to content

Commit

Permalink
Remove "Specify terminal emulator" option. Add GUI outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
obraliar committed Jul 17, 2016
1 parent 884a686 commit 4f82d2b
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 138 deletions.
6 changes: 0 additions & 6 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,8 @@ public class JabRefPreferences {
public static final String KEY_PATTERN_REGEX = "KeyPatternRegex";
public static final String KEY_PATTERN_REPLACEMENT = "KeyPatternReplacement";

public static final String CONSOLE_APPLICATION = "consoleApplication";
public static final String CONSOLE_COMMAND = "consoleCommand";
public static final String USE_DEFAULT_CONSOLE_APPLICATION = "useDefaultConsoleApplication";
public static final String USE_SPECIFIED_CONSOLE_APPLICATION = "useSpecifiedConsoleApplication";
public static final String USE_CONSOLE_COMMAND = "useConsoleCommand";

// Currently, it is not possible to specify defaults for specific entry types
// When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.LabelPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getLabelPattern(); etc
Expand Down Expand Up @@ -871,9 +868,6 @@ private JabRefPreferences() {
defaults.put(INDENT, 4);

defaults.put(USE_DEFAULT_CONSOLE_APPLICATION, Boolean.TRUE);
defaults.put(USE_SPECIFIED_CONSOLE_APPLICATION, Boolean.FALSE);
defaults.put(USE_CONSOLE_COMMAND, Boolean.FALSE);
defaults.put(CONSOLE_APPLICATION, "");
defaults.put(CONSOLE_COMMAND, "");

//versioncheck defaults
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -310,7 +307,7 @@ public static void openBrowserShowPopup(String url) {
/**
* Opens a new console starting on the given file location
*
* If no terminal emulator is specified in {@link Globals},
* If no command is specified in {@link Globals},
* the default system console will be executed.
*
* @param file Location the console should be opened at.
Expand All @@ -321,32 +318,42 @@ public static void openConsole(File file) throws IOException {
}

String absolutePath = file.toPath().toAbsolutePath().getParent().toString();
Path path = Paths.get(Globals.prefs.get(JabRefPreferences.CONSOLE_APPLICATION));
boolean usingDefault = Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION);
boolean usingCommand = Globals.prefs.getBoolean(JabRefPreferences.USE_CONSOLE_COMMAND);
boolean usingSpecified = Globals.prefs.getBoolean(JabRefPreferences.USE_SPECIFIED_CONSOLE_APPLICATION);

if (usingDefault) {
NATIVE_DESKTOP.openConsole(absolutePath);
} else if (usingCommand) {
} else {
String command = Globals.prefs.get(JabRefPreferences.CONSOLE_COMMAND);
command = command.trim();

if (!command.isEmpty()) {

command = command.replaceAll("\\s+", " "); // normalize white spaces
String[] subcommands = command.split(" ");
StringBuilder commandLoggingText = new StringBuilder();

for (int i = 0; i < subcommands.length; i++) {
subcommands[i] = subcommands[i].replace("%DIR", absolutePath); // replace the placeholder if used
commandLoggingText.append(subcommands[i]);
if (i < (subcommands.length - 1)) {
commandLoggingText.append(" ");
}
}

new ProcessBuilder(subcommands).start();
JabRefGUI.getMainFrame().output(Localization.lang("Executing the command \"%0\"...", commandLoggingText.toString()));
LOGGER.info(Localization.lang("Executing the command \"%0\"...", commandLoggingText.toString()));

try {
new ProcessBuilder(subcommands).start();
} catch (IOException exception) {
LOGGER.error(Localization.lang("Open console"), exception);

JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(),
Localization.lang("Error_occured_while_executing_the_command_\"%0\".", commandLoggingText.toString()),
Localization.lang("Open console") + " - " + Localization.lang("Error"),
JOptionPane.ERROR_MESSAGE);
JabRefGUI.getMainFrame().output(null);
}
}
} else if (usingSpecified && Files.exists(path) && !Files.isDirectory(path) && path.isAbsolute()) {
ProcessBuilder process = new ProcessBuilder(path.toString());
process.directory(new File(absolutePath));
process.start();
}
}

Expand Down
62 changes: 12 additions & 50 deletions src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
Expand All @@ -59,9 +55,7 @@ class ExternalTab extends JPanel implements PrefsTab {
private final JCheckBox openFoldersOfAttachedFiles;

private final JRadioButton defaultConsole;
private final JRadioButton specifiedConsole;
private final JRadioButton executeConsole;
private final JTextField consoleEmulatorPath;
private final JTextField consoleCommand;
private final JFileChooser consoleChooser;
private final JButton browseButton;
Expand All @@ -78,29 +72,22 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere


defaultConsole = new JRadioButton(Localization.lang("Use default terminal emulator"));
specifiedConsole = new JRadioButton(Localization.lang("Specify terminal emulator") + ":");
executeConsole = new JRadioButton(Localization.lang("Execute command") + ":");
consoleEmulatorPath = new JTextField();
executeConsole = new JRadioButton(Localization.lang("Execute") + ":");
consoleCommand = new JTextField();
consoleChooser = new JFileChooser();
browseButton = new JButton(Localization.lang("Browse"));

JLabel commandDescription = new JLabel(
"<html>" +
Localization.lang("<u>Note</u>: Use the placeholder <i>%0</i>" +
" for the location of the opened database file.", "%DIR") +
"</html>");
JLabel commandDescription = new JLabel(Localization.lang(
"Note: Use the placeholder %0 for the location of the opened database file.", "%DIR"));

ButtonGroup consoleOptions = new ButtonGroup();
consoleOptions.add(defaultConsole);
consoleOptions.add(specifiedConsole);
consoleOptions.add(executeConsole);

JPanel consoleOptionPanel = new JPanel(new GridBagLayout());
GridBagConstraints layoutConstraints = new GridBagConstraints();

defaultConsole.addActionListener(new ConsoleRadioButtonActionListener());
specifiedConsole.addActionListener(new ConsoleRadioButtonActionListener());
executeConsole.addActionListener(new ConsoleRadioButtonActionListener());
browseButton.addActionListener(new BrowseButtonActionListener());

Expand All @@ -112,23 +99,18 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere
consoleOptionPanel.add(defaultConsole, layoutConstraints);

layoutConstraints.gridy = 1;
consoleOptionPanel.add(specifiedConsole, layoutConstraints);
layoutConstraints.insets = new Insets(0, 0, 6, 0);
consoleOptionPanel.add(executeConsole, layoutConstraints);

layoutConstraints.gridx = 1;
consoleOptionPanel.add(consoleEmulatorPath, layoutConstraints);
consoleOptionPanel.add(consoleCommand, layoutConstraints);

layoutConstraints.gridx = 2;
layoutConstraints.insets = new Insets(0, 4, 6, 0);
consoleOptionPanel.add(browseButton, layoutConstraints);

layoutConstraints.gridy = 2;
layoutConstraints.gridx = 0;
layoutConstraints.insets = new Insets(0, 0, 6, 0);
consoleOptionPanel.add(executeConsole, layoutConstraints);

layoutConstraints.gridx = 1;
consoleOptionPanel.add(consoleCommand, layoutConstraints);

layoutConstraints.gridy = 3;
layoutConstraints.gridy = 2;
consoleOptionPanel.add(commandDescription, layoutConstraints);

FormLayout layout = new FormLayout(
Expand Down Expand Up @@ -197,16 +179,10 @@ public void setValues() {

citeCommand.setText(prefs.get(JabRefPreferences.CITE_COMMAND));

if (Globals.prefs.getBoolean(JabRefPreferences.USE_CONSOLE_COMMAND)) {
executeConsole.setSelected(true);
} else if (Globals.prefs.getBoolean(JabRefPreferences.USE_SPECIFIED_CONSOLE_APPLICATION)) {
specifiedConsole.setSelected(true);
} else {
defaultConsole.setSelected(true);
}
defaultConsole.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION));
executeConsole.setSelected(!Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION));

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

updateEnableStatus();
}
Expand All @@ -217,24 +193,11 @@ public void storeSettings() {
prefs.putBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES, openFoldersOfAttachedFiles.isSelected());
prefs.put(JabRefPreferences.CITE_COMMAND, citeCommand.getText());
prefs.putBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION, defaultConsole.isSelected());
prefs.putBoolean(JabRefPreferences.USE_SPECIFIED_CONSOLE_APPLICATION, specifiedConsole.isSelected());
prefs.putBoolean(JabRefPreferences.USE_CONSOLE_COMMAND, executeConsole.isSelected());
prefs.put(JabRefPreferences.CONSOLE_APPLICATION, consoleEmulatorPath.getText());
prefs.put(JabRefPreferences.CONSOLE_COMMAND, consoleCommand.getText());
}

@Override
public boolean validateSettings() {
if (!consoleEmulatorPath.getText().trim().isEmpty()) {
Path path = Paths.get(consoleEmulatorPath.getText());

if (!Files.exists(path) || Files.isDirectory(path) || !path.isAbsolute()) {
JOptionPane.showMessageDialog(null,
Localization.lang("Please enter the absolute path to an existing terminal emulator."),
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
return false;
}
}
return true;
}

Expand All @@ -250,7 +213,7 @@ private class BrowseButtonActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
int answer = consoleChooser.showOpenDialog(ExternalTab.this);
if (answer == JFileChooser.APPROVE_OPTION) {
consoleEmulatorPath.setText(consoleChooser.getSelectedFile().getAbsolutePath());
consoleCommand.setText(consoleChooser.getSelectedFile().getAbsolutePath());
}
}
}
Expand All @@ -265,8 +228,7 @@ public void actionPerformed(ActionEvent e) {


private void updateEnableStatus() {
consoleEmulatorPath.setEnabled(specifiedConsole.isSelected());
browseButton.setEnabled(specifiedConsole.isSelected());
browseButton.setEnabled(executeConsole.isSelected());
consoleCommand.setEnabled(executeConsole.isSelected());
}
}
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1708,10 +1708,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2426,11 +2426,13 @@ Custom=


Open_console=Terminal_öffnen
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=Bitte_geben_Sie_den_absoluten_Pfad_zu_einem_exsistierenden_Terminal-Emulator_ein.
Specify_terminal_emulator=Terminal-Emaultor_spezifizieren
Use_default_terminal_emulator=Standard_Terminal-Emulator_verwenden

Execute_command=Kommando_ausführen
Execute=Kommando_ausführen

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=<u>Hinweis</u>\:_<i>%0</i>_als_Platzhalter_für_den_Speicherort_der_Datenbank_benutzen.


Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=Hinweis\:_%0_als_Platzhalter_für_den_Speicherort_der_Datenbank_benutzen.

Executing_the_command_\"%0\"...=Ausführung_des_Kommandos_\"%0\"...
Error_occured_while_executing_the_command_\"%0\".=Während_der_Ausführung_des_Befehls_\"%0\"_ist_ein_Fehler_aufgetreten.
8 changes: 4 additions & 4 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2275,8 +2275,8 @@ Online_help_forum=Online_help_forum
Custom=Custom

Open_console=Open_console
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=Please_enter_the_absolute_path_to_an_existing_terminal_emulator.
Specify_terminal_emulator=Specify_terminal_emulator
Use_default_terminal_emulator=Use_default_terminal_emulator
Execute_command=Execute_command
<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.
Execute=Execute
Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.
Executing_the_command_\"%0\"...=Executing_the_command_\"%0\"...
Error_occured_while_executing_the_command_\"%0\".=Error_occured_while_executing_the_command_\"%0\".
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1610,10 +1610,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2396,10 +2396,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1654,10 +1654,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1629,10 +1629,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1729,10 +1729,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
10 changes: 6 additions & 4 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2374,10 +2374,12 @@ Custom=
Converts_HTML_code_to_Unicode.=

Open_console=
Please_enter_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator=
Use_default_terminal_emulator=

Execute_command=
Execute=

<u>Note</u>\:_Use_the_placeholder_<i>%0</i>_for_the_location_of_the_opened_database_file.=

Note\:_Use_the_placeholder_%0_for_the_location_of_the_opened_database_file.=

Executing_the_command_\"%0\"...=
Error_occured_while_executing_the_command_\"%0\".=
Loading

0 comments on commit 4f82d2b

Please sign in to comment.