Skip to content

Commit

Permalink
Extend the OpenConsoleFeature by selection of custom terminal emulator.
Browse files Browse the repository at this point in the history
- Add radio selection to the AdvancedTab
- Add new JabRefPreferences
- Add file check and execution commands
- Add localization keys
- Fix openConsole(...) in Windows.java
  • Loading branch information
obraliar committed Jul 15, 2016
1 parent aa42c16 commit d433310
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- [#462](https://github.com/JabRef/jabref/issues/462) Extend the OpenConsoleFeature by selection of custom terminal emulator.
- [#1026](https://github.com/JabRef/jabref/issues/1026) JabRef does no longer delete user comments outside of BibTeX entries and strings

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ 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 USE_DEFAULT_CONSOLE_APPLICATION = "useDefaultConsoleApplication";

// 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
public static final String DEFAULT_LABEL_PATTERN = "defaultLabelPattern";
Expand Down Expand Up @@ -864,6 +867,9 @@ private JabRefPreferences() {
defaults.put(LINE_LENGTH, 65);
defaults.put(INDENT, 4);

defaults.put(USE_DEFAULT_CONSOLE_APPLICATION, Boolean.TRUE);
defaults.put(CONSOLE_APPLICATION, "");

//versioncheck defaults
defaults.put(VersionPreferences.VERSION_IGNORED_UPDATE, "");
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/net/sf/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.sf.jabref.BibDatabaseContext;
import net.sf.jabref.Globals;
import net.sf.jabref.JabRefGUI;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.external.ExternalFileType;
import net.sf.jabref.external.ExternalFileTypeEntryEditor;
import net.sf.jabref.external.ExternalFileTypes;
Expand Down Expand Up @@ -309,7 +310,13 @@ public static void openConsole(File file) throws IOException {
}

String absolutePath = file.toPath().toAbsolutePath().getParent().toString();
NATIVE_DESKTOP.openConsole(absolutePath);
File console = new File(Globals.prefs.get(JabRefPreferences.CONSOLE_APPLICATION));

if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION)) {
NATIVE_DESKTOP.openConsole(absolutePath);
} else if (console.exists() && console.isFile() && console.isAbsolute()) {
Runtime.getRuntime().exec(console.getAbsolutePath(), null, new File(absolutePath));
}
}

// TODO: Move to OS.java
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/sf/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public void openFolderAndSelectFile(String filePath) throws IOException {

@Override
public void openConsole(String absolutePath) throws IOException {
ProcessBuilder process = new ProcessBuilder("cmd.exe", "/c", "start");
process.directory(new File(absolutePath));
process.start();
Runtime.getRuntime().exec("cmd.exe /c start", null, new File(absolutePath));
}
}
105 changes: 101 additions & 4 deletions src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@
package net.sf.jabref.gui.preftabs;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Optional;

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;

import net.sf.jabref.Globals;
Expand All @@ -49,6 +59,13 @@ class AdvancedTab extends JPanel implements PrefsTab {
private final JCheckBox useUnitFormatterOnSearch;
private final RemotePreferences remotePreferences;

private final JRadioButton defaultConsole;
private final JRadioButton specifiedConsole;
private final ButtonGroup consoleOptions;
private final JTextField consoleEmulatorPath;
private final JFileChooser consoleChooser;
private final JButton browseButton;


public AdvancedTab(JabRefPreferences prefs) {
preferences = prefs;
Expand All @@ -61,6 +78,38 @@ public AdvancedTab(JabRefPreferences prefs) {
useCaseKeeperOnSearch = new JCheckBox(Localization.lang("Add {} to specified title words on search to keep the correct case"));
useUnitFormatterOnSearch = new JCheckBox(Localization.lang("Format units by adding non-breaking separators and keeping the correct case on search"));

defaultConsole = new JRadioButton(Localization.lang("Use default terminal emulator"));
specifiedConsole = new JRadioButton(Localization.lang("Specify terminal emulator:"));
consoleOptions = new ButtonGroup();
consoleEmulatorPath = new JTextField(20);
consoleChooser = new JFileChooser();
browseButton = new JButton(Localization.lang("Browse"));

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

consoleOptions.add(defaultConsole);
consoleOptions.add(specifiedConsole);
defaultConsole.addActionListener(new ConsoleRadioButtonActionListener());
specifiedConsole.addActionListener(new ConsoleRadioButtonActionListener());
browseButton.addActionListener(new BrowseButtonActionListener());

layoutConstraints.fill = GridBagConstraints.HORIZONTAL;

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

layoutConstraints.gridy = 1;
consoleOptionPanel.add(specifiedConsole, layoutConstraints);

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

FormLayout layout = new FormLayout
("1dlu, 8dlu, left:pref, 4dlu, fill:3dlu",//, 4dlu, fill:pref",// 4dlu, left:pref, 4dlu",
"");
Expand Down Expand Up @@ -103,6 +152,12 @@ public AdvancedTab(JabRefPreferences prefs) {
builder.nextLine();
builder.append(pan);
builder.append(useUnitFormatterOnSearch);
builder.nextLine();

builder.appendSeparator(Localization.lang("Open console"));
builder.nextLine();
builder.append(new JPanel());
builder.append(consoleOptionPanel);

pan = builder.getPanel();
pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
Expand All @@ -119,6 +174,11 @@ public void setValues() {
useConvertToEquation.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION));
useCaseKeeperOnSearch.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH));
useUnitFormatterOnSearch.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH));
defaultConsole.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION));
specifiedConsole.setSelected(!Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION));
consoleEmulatorPath.setText(Globals.prefs.get(JabRefPreferences.CONSOLE_APPLICATION));

updateEnableStatus();
}

@Override
Expand All @@ -132,6 +192,8 @@ public void storeSettings() {
preferences.putBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION, useConvertToEquation.isSelected());
preferences.putBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH, useCaseKeeperOnSearch.isSelected());
preferences.putBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH, useUnitFormatterOnSearch.isSelected());
preferences.putBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION, defaultConsole.isSelected());
preferences.put(JabRefPreferences.CONSOLE_APPLICATION, consoleEmulatorPath.getText());
}

private void storeRemoteSettings() {
Expand Down Expand Up @@ -164,22 +226,57 @@ private Optional<Integer> getPortAsInt() {
}
}

private class BrowseButtonActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
int answer = consoleChooser.showOpenDialog(AdvancedTab.this);
if (answer == JFileChooser.APPROVE_OPTION) {
consoleEmulatorPath.setText(consoleChooser.getSelectedFile().getAbsolutePath());
}
}
}

private class ConsoleRadioButtonActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
updateEnableStatus();
}
}

private void updateEnableStatus() {
consoleEmulatorPath.setEnabled(specifiedConsole.isSelected());
browseButton.setEnabled(specifiedConsole.isSelected());
}

@Override
public boolean validateSettings() {
boolean isValid = true;

try {
int portNumber = Integer.parseInt(remoteServerPort.getText());
if (RemoteUtil.isUserPort(portNumber)) {
return true;
} else {
if (!RemoteUtil.isUserPort(portNumber)) {
throw new NumberFormatException();
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null,
Localization.lang("You must enter an integer value in the interval 1025-65535 in the text field for")
+ " '" + Localization.lang("Remote server port") + '\'',
Localization.lang("Remote server port"), JOptionPane.ERROR_MESSAGE);
return false;
isValid = false;
}

if (!consoleEmulatorPath.getText().trim().isEmpty()) {
File file = new File(consoleEmulatorPath.getText());

if (!file.exists() || !file.isFile() || !file.isAbsolute()) {
JOptionPane.showMessageDialog(null,
Localization.lang("Please type in the absolute path to an existing terminal emulator."),
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
isValid = false;
}
}

return isValid;
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1707,3 +1707,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2425,3 +2425,8 @@ Online_help_forum=Online-Hilfeforum
Custom=



Open_console=Terminal_öffnen
Please_type_in_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
7 changes: 6 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2273,4 +2273,9 @@ A_new_version_of_JabRef_has_been_released.=A_new_version_of_JabRef_has_been_rele
JabRef_is_up-to-date.=JabRef_is_up-to-date.
Latest_version=Latest_version
Online_help_forum=Online_help_forum
Custom=Custom
Custom=Custom

Open_console=Open_console
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.
Specify_terminal_emulator\:=Specify_terminal_emulator\:
Use_default_terminal_emulator=Use_default_terminal_emulator
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1609,3 +1609,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2395,3 +2395,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1653,3 +1653,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1628,3 +1628,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1728,3 +1728,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2373,3 +2373,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2404,3 +2404,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2800,3 +2800,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1622,3 +1622,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2372,3 +2372,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1565,3 +1565,8 @@ Online_help_forum=Onlineforum
Custom=Egna



Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1641,3 +1641,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2396,3 +2396,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1635,3 +1635,8 @@ Online_help_forum=
Custom=

Converts_HTML_code_to_Unicode.=

Open_console=
Please_type_in_the_absolute_path_to_an_existing_terminal_emulator.=
Specify_terminal_emulator\:=
Use_default_terminal_emulator=

0 comments on commit d433310

Please sign in to comment.