Skip to content
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

Fixes and cleanup for OpenOffice #601

Merged
merged 1 commit into from
Dec 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 52 additions & 77 deletions src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import net.sf.jabref.gui.worker.AbstractWorker;

import javax.swing.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.awt.*;
import java.awt.event.ActionListener;
Expand All @@ -37,6 +41,8 @@
*/
public class AutoDetectPaths extends AbstractWorker {

private static final Log LOGGER = LogFactory.getLog(AutoDetectPaths.class);

private boolean foundPaths;
private boolean fileSearchCancelled;
private JDialog prog;
Expand All @@ -57,7 +63,7 @@ public boolean runAutodetection() {
update();
return foundPaths;
} catch (Throwable e) {
e.printStackTrace();
LOGGER.warn("Problem when auto-detecting paths", e);
return false;
}
}
Expand Down Expand Up @@ -86,12 +92,12 @@ private boolean autoDetectPaths() {

if (OS.WINDOWS) {
List<File> progFiles = findProgramFilesDir();
if (fileSearchCancelled) {
return false;
}
File sOffice = null;
List<File> sofficeFiles = new ArrayList<>();
for (File dir : progFiles) {
if (fileSearchCancelled) {
return false;
}
sOffice = findFileDir(dir, "soffice.exe");
if (sOffice != null) {
sofficeFiles.add(sOffice);
Expand Down Expand Up @@ -153,20 +159,8 @@ public String getDescription() {
} else {
sOffice = sofficeFiles.get(0);
}
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(sOffice, "soffice.exe").getPath());
File jurt = findFileDir(sOffice.getParentFile(), "jurt.jar");
if (fileSearchCancelled) {
return false;
}
if (jurt != null) {
Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath());
return true;
} else {
return false;
}

}
else if (OS.OS_X) {
return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
} else if (OS.OS_X) {
File rootDir = new File("/Applications");
File[] files = rootDir.listFiles();
if (files != null) {
Expand All @@ -181,23 +175,12 @@ else if (OS.OS_X) {
if (fileSearchCancelled) {
return false;
}
if (sOffice != null) {
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(sOffice, "soffice.bin").getPath());
File jurt = findFileDir(rootDir, "jurt.jar");
if (fileSearchCancelled) {
return false;
}
if (jurt != null) {
Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath());
return true;
} else {
return false;
}
} else {
if (sOffice == null) {
return false;
} else {
return setupPreferencesForOO(rootDir, sOffice, "soffice.bin");
}
}
else {
} else {
// Linux:
String usrRoot = "/usr/lib";
File inUsr = findFileDir(new File(usrRoot), "soffice");
Expand All @@ -219,63 +202,55 @@ else if (OS.OS_X) {
return false;
}
if ((inUsr != null) && (inOpt == null)) {
return setupPreferencesForOO(usrRoot, inUsr);
}
else if ((inOpt != null) && (inUsr == null)) {
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inOpt, "soffice.bin").getPath());
File jurt = findFileDir(new File("/opt"), "jurt.jar");
if (jurt != null) {
Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath());
return true;
} else {
return false;
}
}
else if (inOpt != null) { // Found both
JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
ButtonGroup bg = new ButtonGroup();
bg.add(optRB);
bg.add(usrRB);
FormBuilder b = FormBuilder.create()
.layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
b.add(Localization
.lang("Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
.xy(1, 1);
b.add(optRB).xy(1, 3);
b.add(usrRB).xy(1, 5);
int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
Localization.lang("Choose OpenOffice/LibreOffice executable"),
JOptionPane.OK_CANCEL_OPTION);
if (answer == JOptionPane.CANCEL_OPTION) {
return false;
} else {
if (optRB.isSelected()) {
return setupPreferencesForOO("/opt", inOpt);
return setupPreferencesForOO(usrRoot, inUsr, "soffice.bin");
} else if (inOpt != null) {
if (inUsr == null) {
return setupPreferencesForOO("/opt", inOpt, "soffice.bin");
} else { // Found both
JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
ButtonGroup bg = new ButtonGroup();
bg.add(optRB);
bg.add(usrRB);
FormBuilder b = FormBuilder.create()
.layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
b.add(Localization
.lang("Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
.xy(1, 1);
b.add(optRB).xy(1, 3);
b.add(usrRB).xy(1, 5);
int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
Localization.lang("Choose OpenOffice/LibreOffice executable"),
JOptionPane.OK_CANCEL_OPTION);
if (answer == JOptionPane.CANCEL_OPTION) {
return false;
}
else {
return setupPreferencesForOO(usrRoot, inUsr);
if (optRB.isSelected()) {
return setupPreferencesForOO("/opt", inOpt, "soffice.bin");
} else {
return setupPreferencesForOO(usrRoot, inUsr, "soffice.bin");
}

}
} else {
return false;
}
}
return false;
}

private boolean setupPreferencesForOO(String usrRoot, File inUsr, String sofficeName) {
return setupPreferencesForOO(new File(usrRoot), inUsr, sofficeName);
}

private boolean setupPreferencesForOO(String usrRoot, File inUsr) {
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inUsr, "soffice.bin").getPath());
File jurt = findFileDir(new File(usrRoot), "jurt.jar");
private boolean setupPreferencesForOO(File rootDir, File inUsr, String sofficeName) {
Globals.prefs.put(JabRefPreferences.OO_EXECUTABLE_PATH, new File(inUsr, sofficeName).getPath());
File jurt = findFileDir(rootDir, "jurt.jar");
if (fileSearchCancelled) {
return false;
}
if (jurt != null) {
if (jurt == null) {
return false;
} else {
Globals.prefs.put(JabRefPreferences.OO_JARS_PATH, jurt.getPath());
return true;
} else {
return false;
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/sf/jabref/openoffice/CitationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import net.sf.jabref.logic.l10n.Localization;

import javax.swing.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
Expand All @@ -46,6 +50,8 @@ class CitationManager {
private final JTable table;
private final DefaultEventTableModel<CitEntry> tableModel;

private static final Log LOGGER = LogFactory.getLog(CitationManager.class);


public CitationManager(final JabRefFrame frame, OOBibBase ooBase) throws Exception {
diag = new JDialog(frame, Localization.lang("Manage citations"), true);
Expand Down Expand Up @@ -84,7 +90,7 @@ public void actionPerformed(ActionEvent actionEvent) {
try {
storeSettings();
} catch (Exception ex) {
ex.printStackTrace();
LOGGER.warn("Problem modifying citation", ex);
JOptionPane.showMessageDialog(frame, Localization.lang("Problem modifying citation"));
}
diag.dispose();
Expand Down Expand Up @@ -132,12 +138,10 @@ static class CitEntry implements Comparable<CitEntry> {
private final String keyString;
final String context;
private final String origPageInfo;
private final List<String> keys;


public CitEntry(String refMarkName, List<String> keys, String context, String pageInfo) {
this.refMarkName = refMarkName;
this.keys = keys;
this.context = context;
this.pageInfo = pageInfo;
this.origPageInfo = pageInfo;
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/net/sf/jabref/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ private Point findPosition(XTextViewCursor cursor, XTextRange range) {
* @return The list of bibtex keys encoded in the name.
*/
public List<String> parseRefMarkName(String name) {
ArrayList<String> keys = new ArrayList<>();
List<String> keys = new ArrayList<>();
Matcher m = citePattern.matcher(name);
if (m.find()) {
String[] keystring = m.group(2).split(",");
Expand Down Expand Up @@ -1030,14 +1030,12 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map<BibEntry, BibDa
// If we don't have numbered entries, we need to sort the entries before adding them:
if (!style.isSortByPosition()) {
Map<BibEntry, BibDatabase> newMap = new TreeMap<>(entryComparator);
for (BibEntry entry : entries.keySet()) {
newMap.put(entry, entries.get(entry));
}
newMap.putAll(entries);
entries = newMap;
}
int number = 1;
for (BibEntry entry : entries.keySet()) {
if (entry instanceof UndefinedBibtexEntry) {
for (Map.Entry<BibEntry, BibDatabase> entry : entries.entrySet()) {
if (entry.getKey() instanceof UndefinedBibtexEntry) {
continue;
}
OOUtil.insertParagraphBreak(text, cursor);
Expand All @@ -1047,14 +1045,14 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map<BibEntry, BibDa
style.getNumCitationMarker(new int[] {number++}, minGroupingCount, true),
false, false, false, false, false, false);
}
Layout layout = style.getReferenceFormat(entry.getType().getName());
Layout layout = style.getReferenceFormat(entry.getKey().getType().getName());
try {
layout.setPostFormatter(OOUtil.POSTFORMATTER);
} catch (NoSuchMethodError ignore) {
// Ignored
}
OOUtil.insertFullReferenceAtCurrentLocation(text, cursor, layout, parFormat, entry,
entries.get(entry), uniquefiers.get(entry.getCiteKey()));
OOUtil.insertFullReferenceAtCurrentLocation(text, cursor, layout, parFormat, entry.getKey(),
entry.getValue(), uniquefiers.get(entry.getKey().getCiteKey()));
}

}
Expand Down
Loading