Skip to content

Commit

Permalink
Improved preferences and fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Mar 28, 2016
1 parent 9e1fd14 commit c4c779d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package net.sf.jabref.openoffice;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.gui.worker.AbstractWorker;

import javax.swing.*;
Expand Down Expand Up @@ -131,7 +129,7 @@ public String getDescription() {
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.showOpenDialog(parent);
if (fileChooser.getSelectedFile() != null) {
sOffice = fileChooser.getSelectedFile();
sofficeFiles.add(fileChooser.getSelectedFile());
}
}
if (sOffice == null) {
Expand Down Expand Up @@ -247,7 +245,7 @@ private boolean setupPreferencesForOO(String usrRoot, File inUsr, String soffice
}

private boolean setupPreferencesForOO(File rootDir, File inUsr, String sofficeName) {
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inUsr, sofficeName).getPath());
preferences.setExecutablePath(new File(inUsr, sofficeName).getPath());
File jurt = findFileDir(rootDir, "jurt.jar");
if (fileSearchCancelled) {
return false;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import com.jgoodies.forms.builder.ButtonBarBuilder;
import com.jgoodies.forms.builder.FormBuilder;
import com.jgoodies.forms.layout.FormLayout;
import net.sf.jabref.*;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.*;
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
Expand Down Expand Up @@ -322,17 +323,17 @@ private void connect(boolean auto) {
}

ooBaseDirectory = preferences.getJarsPath();
sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH);
sOffice = preferences.getExecutablePath();
} else { // Manual connect

showConnectDialog();
if (!dialogOkPressed) {
return;
}

String ooPath = Globals.prefs.get(JabRefPreferences.OO_PATH);
String ooPath = preferences.getOOPath();
String ooJars = preferences.getJarsPath();
sOffice = Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH);
sOffice = preferences.getExecutablePath();

if (OS.WINDOWS) {
ooBaseDirectory = ooPath + "\\program\\classes";
Expand Down Expand Up @@ -443,12 +444,12 @@ private void showConnectDialog() {
final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
final JTextField ooPath = new JTextField(30);
JButton browseOOPath = new JButton(Localization.lang("Browse"));
ooPath.setText(Globals.prefs.get(JabRefPreferences.OO_PATH));
ooPath.setText(preferences.getOOPath());
browseOOPath.addActionListener(BrowseAction.buildForDir(ooPath));

final JTextField ooExec = new JTextField(30);
JButton browseOOExec = new JButton(Localization.lang("Browse"));
ooExec.setText(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH));
ooExec.setText(preferences.getExecutablePath());
browseOOExec.addActionListener(BrowseAction.buildForFile(ooExec));

final JTextField ooJars = new JTextField(30);
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/net/sf/jabref/openoffice/OpenOfficePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ public void putDefaultPreferences() {
preferences.putDefaultValue(JabRefPreferences.OO_SYNC_WHEN_CITING, false);
preferences.putDefaultValue(JabRefPreferences.OO_SHOW_PANEL, false);
preferences.putDefaultValue(JabRefPreferences.OO_USE_ALL_OPEN_BASES, true);
preferences.putDefaultValue(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE,
StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH);
preferences.putDefaultValue(JabRefPreferences.OO_EXTERNAL_STYLE_FILES, "");
}

public void updateConnectionParams(String ooPath, String execPath, String jarsPath) {
preferences.put(JabRefPreferences.OO_PATH, ooPath);
preferences.put(JabRefPreferences.OO_EXECUTABLE_PATH, execPath);
setOOPath(ooPath);
setExecutablePath(execPath);
setJarsPath(jarsPath);
}

public boolean checkAutoDetectedPaths() {
if (preferences.hasKey(JabRefPreferences.OO_JARS_PATH)
&& preferences.hasKey(JabRefPreferences.OO_EXECUTABLE_PATH)) {
return new File(getJarsPath(), "jurt.jar").exists()
&& new File(preferences.get(JabRefPreferences.OO_EXECUTABLE_PATH)).exists();
return new File(getJarsPath(), "jurt.jar").exists() && new File(getExecutablePath()).exists();
} else {
return false;
}
Expand All @@ -71,6 +73,22 @@ public void setJarsPath(String path) {
preferences.put(JabRefPreferences.OO_JARS_PATH, path);
}

public String getExecutablePath() {
return preferences.get(JabRefPreferences.OO_EXECUTABLE_PATH);
}

public void setExecutablePath(String path) {
preferences.put(JabRefPreferences.OO_EXECUTABLE_PATH, path);
}

public String getOOPath() {
return preferences.get(JabRefPreferences.OO_PATH);
}

public void setOOPath(String path) {
preferences.put(JabRefPreferences.OO_PATH, path);
}

public boolean useAllDatabases() {
return preferences.getBoolean(JabRefPreferences.OO_USE_ALL_OPEN_BASES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void init() {
updateStyles();

// Build dialog
diag = new JDialog(frame, Localization.lang("Styles"), true);
diag = new JDialog(frame, Localization.lang("Select style"), true);

FormBuilder builder = FormBuilder.create();
builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref",
Expand Down

0 comments on commit c4c779d

Please sign in to comment.